canopy/ipython 运行 脚本 - 没有输出?
canopy/ipython run script - no output?
我对IPython很陌生,但对py本身并不陌生。我正在浏览一本名为 datadrivensecurity 的书中的一些代码示例,并尝试 运行 其中一个代码示例。当我在 IPython 中创建一个新文件(使用 cannopy),然后单击 运行,我在控制台 window 中得到以下输出。
In [9]: %run /Users/myuser/Documents/Notebooks/ch02.py
highvulns int64
name object
os object
dtype: object
In [10]:
当我 copy/paste 将代码输入 In[#]
控制台提示时,我得到了预期的输出。我做错了什么?
#
# name ch02.py
#
# create a new data frame
import numpy as np
import pandas as pd
# create a new data frame of hosts & high vuln counts
assets_df = pd.DataFrame( {
"name" : ["danube","gander","ganges","mekong","orinoco" ],
"os" : [ "W2K8","RHEL5","W2K8","RHEL5","RHEL5" ],
"highvulns" : [ 1,0,2,0,0 ]
} )
# take a look at the data frame structure & contents
print(assets_df.dtypes)
assets_df.head()
# show a "slice" just the operating systmes
assets_df.os.head()
# add a new column
assets_df['ip'] = [ "192.168.1.5","10.2.7.5","192.168.1.7",
"10.2.7.6", "10.2.7.7" ]
# show only nodes with more than one high vulnerabilty
assets_df[assets_df.highvulns>1].head()
# divide nodes into network 'zones' based on IP address
assets_df['zones'] = np.where(
assets_df.ip.str.startswith("192"), "Zone1", "Zone2")
# get one final view
assets_df.head()
highvulns int64
name object
os object
dtype: object
Out[7]:
highvulns
name
os
ip
zones
0
1
danube
W2K8
192.168.1.5
Zone1
1
0
gander
RHEL5
10.2.7.5
Zone2
2
2
ganges
W2K8
192.168.1.7
Zone1
3
0
mekong
RHEL5
10.2.7.6
Zone2
4
0
orinoco
RHEL5
10.2.7.7
Zone2
为方便起见,如果您在提示符下键入表达式,将打印表达式的值。但如果你只是在 python 文件中写入相同的表达式,它会被计算,但不会打印该值。如果你想从文件中打印 x 的值,你应该 print x
运行。
我对IPython很陌生,但对py本身并不陌生。我正在浏览一本名为 datadrivensecurity 的书中的一些代码示例,并尝试 运行 其中一个代码示例。当我在 IPython 中创建一个新文件(使用 cannopy),然后单击 运行,我在控制台 window 中得到以下输出。
In [9]: %run /Users/myuser/Documents/Notebooks/ch02.py
highvulns int64
name object
os object
dtype: object
In [10]:
当我 copy/paste 将代码输入 In[#]
控制台提示时,我得到了预期的输出。我做错了什么?
#
# name ch02.py
#
# create a new data frame
import numpy as np
import pandas as pd
# create a new data frame of hosts & high vuln counts
assets_df = pd.DataFrame( {
"name" : ["danube","gander","ganges","mekong","orinoco" ],
"os" : [ "W2K8","RHEL5","W2K8","RHEL5","RHEL5" ],
"highvulns" : [ 1,0,2,0,0 ]
} )
# take a look at the data frame structure & contents
print(assets_df.dtypes)
assets_df.head()
# show a "slice" just the operating systmes
assets_df.os.head()
# add a new column
assets_df['ip'] = [ "192.168.1.5","10.2.7.5","192.168.1.7",
"10.2.7.6", "10.2.7.7" ]
# show only nodes with more than one high vulnerabilty
assets_df[assets_df.highvulns>1].head()
# divide nodes into network 'zones' based on IP address
assets_df['zones'] = np.where(
assets_df.ip.str.startswith("192"), "Zone1", "Zone2")
# get one final view
assets_df.head()
highvulns int64
name object
os object
dtype: object
Out[7]:
highvulns
name
os
ip
zones
0
1
danube
W2K8
192.168.1.5
Zone1
1
0
gander
RHEL5
10.2.7.5
Zone2
2
2
ganges
W2K8
192.168.1.7
Zone1
3
0
mekong
RHEL5
10.2.7.6
Zone2
4
0
orinoco
RHEL5
10.2.7.7
Zone2
为方便起见,如果您在提示符下键入表达式,将打印表达式的值。但如果你只是在 python 文件中写入相同的表达式,它会被计算,但不会打印该值。如果你想从文件中打印 x 的值,你应该 print x
运行。