随笔分类 -  Python

摘要:1. introductionfrom numpy import *random.rand(4,4)#array to matrixrandMat=mat(randon.rand(4,4))#matrix inverseIvrandMat=randMat.I#indentity matrixeye(... 阅读全文
posted @ 2014-05-03 09:38 yjjsdu 阅读(258) 评论(0) 推荐(0)
摘要:1. for root, dirs, filenames in os.walk('.'): ......os.walk: search the entire tree of directories 阅读全文
posted @ 2014-03-29 19:06 yjjsdu 阅读(152) 评论(0) 推荐(0)
摘要:import os, glob,sysdirname= r'C:\Python33\Lib' if len(sys.argv)==1 else sys.argv[1]allsize=[]allpy=glob.glob(dirname +os.sep+'*.py')for filename in al... 阅读全文
posted @ 2014-03-23 23:48 yjjsdu 阅读(139) 评论(0) 推荐(0)
摘要:Forking isbased on the notion of copying programs: when a program calls the fork routine, theoperating system makes a new copy of that program and its... 阅读全文
posted @ 2014-03-23 23:34 yjjsdu 阅读(149) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2014-03-02 14:56 yjjsdu 阅读(137) 评论(0) 推荐(0)
摘要:#whereami.pyimport os, sysprint('my os.getcwd =>', os.getcwd())print('my sys.path =>', sys.path) # show the first 6 import paths, no brace after sys.p... 阅读全文
posted @ 2014-03-02 13:08 yjjsdu 阅读(243) 评论(0) 推荐(0)
摘要:Chapter 2 system toolsos.getcwd #current workding directoryos.environ # shell environment variablessys.argv #command-line argumentssys.stdin stdou... 阅读全文
posted @ 2014-02-26 23:48 yjjsdu 阅读(230) 评论(0) 推荐(0)
摘要:#tkinter examplefrom tkinter import *Label(text='spm').pack()mainloop()#tkinter showinfo buttonfrom tkinter import *from tkinter.messagebox import sho... 阅读全文
posted @ 2014-02-23 17:21 yjjsdu 阅读(183) 评论(0) 推荐(0)
摘要:#peopleinteract_queryimport shelvefieldnames=('name', 'age','job','pay')maxfield=max(len(f) for f in fieldnames)db=shelve.open('class-shelve')while Tr... 阅读全文
posted @ 2014-02-23 15:55 yjjsdu 阅读(228) 评论(0) 推荐(0)
摘要:OOP: Structure, Encapsulation, Customization1. Using Classesclass Person: def __init__(self, name, age, pay=0, job=None): self.name=name ... 阅读全文
posted @ 2014-02-22 15:51 yjjsdu 阅读(183) 评论(0) 推荐(0)
摘要:1. Using formatted files#test scriptbob={'name': 'bob smith', 'age': 42, 'pay':30000, 'job':'dev'}sue={'name': 'sue jones', 'age':45,'pay':40000,'job'... 阅读全文
posted @ 2014-02-22 14:41 yjjsdu 阅读(380) 评论(0) 推荐(0)
摘要:1. using listbob=['bob smith', 42, 3000, 'software']sue=['sue jones', 45, 4000, 'hardware']bob[0], sue[2]bob[0].split()[-1]split 默认以空格分隔sue[2]*=1.25p... 阅读全文
posted @ 2014-02-22 10:58 yjjsdu 阅读(248) 评论(0) 推荐(0)
摘要:In interactive mode, the last printed expression is assigned to the variable _>>> price * tax12.5625>>> price + _113.0625>>> round(_, 2) 113.06print("... 阅读全文
posted @ 2013-09-15 13:29 yjjsdu 阅读(142) 评论(0) 推荐(0)
摘要:1.在Python中有三种内建的数据结构——列表、元组和字典2.### list begin #!/usr/bin/python# Filename: using_list.py# This is my shopping listshoplist = ['apple', 'mango', 'carr... 阅读全文
posted @ 2013-07-13 16:24 yjjsdu 阅读(197) 评论(0) 推荐(0)
摘要:1.##########if beginnumber = 23guess = int(input('Enter an integer : '))if guess == number: print ('Congratulations, you guessed it.') # New block sta... 阅读全文
posted @ 2013-07-13 13:18 yjjsdu 阅读(219) 评论(0) 推荐(0)