ipython 学习笔记 1 基础

ref: Learning Ipython for interactive computing and data visualization

code website: http://ipython.rossant.net.

启动:

基础,可以用powershell在window下实现近似linux操作

notepad.exe 可代替vi啦

在shell下ipython notebook 可以启动notebook

chrome里输入http://localhost:8888/tree

就是我的notebook地址

 

一些简单指令:

Quick benchmarking with the %timeit command  

%timeit [x*x for x in range(100000)]

Quick debugging with the %debug command

 

to make the plot work

%matplotlib inline

 

Hot Keys

• Press the Enter key to create a new line in the cell and not execute the cell
• Press Shift + Enter to execute the cell and go to the next cell
• Press Alt + Enter to execute the cell and append a new empty cell right after it
• Press Ctrl + Enter for quick instant experiments when you do not want to
save the output
• Press Ctrl + M and then the H key to display the list of all the keyboard
shortcuts

 

Chapter 2

for python 3.4

from urllib.request import urlopen
html = 'http://ipython.rossant.net/'
filename = 'facebook.zip'
downloaded=urllib.request.urlopen(html+filename)
with open(filename, 'wb') as f: f.write(download.read())
with zipfile.ZipFile(filename) as zip:zip.extractall('.')

bookmark a folder's path

%bookmark fbdata

then
cd fbdata

lambda function

import sys
import os
# we retrieve the folder as the first positional argument
# to the command-line call
if len(sys.argv) > 1:
    folder = sys.argv[1]
# we list all files in the specified folder
files = os.listdir(folder)
# ids contains the sorted list of all unique idenfitiers
ids = sorted(set(map(lambda file: int(file.split('.')[0]), files)))

very cool interperation about this egos.py script

cmd line is:

%run egos.py facebook

 

"

Here is an explanation of what the last line does. The lambda function takes a filename as an argument following the template <egoid>.<extension>, and returns the egoid ID as an integer. It uses the split method of any string, which splits a string with a given character and returns a list of substrings, which are separated by this character. Here, the first element of the list is the <egoid> part. The map built-in Python function applies this lambda function to all filenames. The set function converts this list to a set object, thereby removing all duplicates and keeping only a list of unique identifiers (since any identifier appears twice with two different extensions). Finally, the sorted function converts the set object to a list, and sorts it in an increasing order.

"

 

debug

%run -d

%pdb

 

posted @ 2015-06-03 12:03  世界到处都是小星星  阅读(486)  评论(0编辑  收藏  举报