随笔分类 - Python
摘要:1. introductionfrom numpy import *random.rand(4,4)#array to matrixrandMat=mat(randon.rand(4,4))#matrix inverseIvrandMat=randMat.I#indentity matrixeye(...
阅读全文
摘要:1. for root, dirs, filenames in os.walk('.'): ......os.walk: search the entire tree of directories
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要:
阅读全文
摘要:#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...
阅读全文
摘要:Chapter 2 system toolsos.getcwd #current workding directoryos.environ # shell environment variablessys.argv #command-line argumentssys.stdin stdou...
阅读全文
摘要:#tkinter examplefrom tkinter import *Label(text='spm').pack()mainloop()#tkinter showinfo buttonfrom tkinter import *from tkinter.messagebox import sho...
阅读全文
摘要:#peopleinteract_queryimport shelvefieldnames=('name', 'age','job','pay')maxfield=max(len(f) for f in fieldnames)db=shelve.open('class-shelve')while Tr...
阅读全文
摘要:OOP: Structure, Encapsulation, Customization1. Using Classesclass Person: def __init__(self, name, age, pay=0, job=None): self.name=name ...
阅读全文
摘要:1. Using formatted files#test scriptbob={'name': 'bob smith', 'age': 42, 'pay':30000, 'job':'dev'}sue={'name': 'sue jones', 'age':45,'pay':40000,'job'...
阅读全文
摘要: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...
阅读全文
摘要:In interactive mode, the last printed expression is assigned to the variable _>>> price * tax12.5625>>> price + _113.0625>>> round(_, 2) 113.06print("...
阅读全文
摘要:1.在Python中有三种内建的数据结构——列表、元组和字典2.### list begin #!/usr/bin/python# Filename: using_list.py# This is my shopping listshoplist = ['apple', 'mango', 'carr...
阅读全文
摘要:1.##########if beginnumber = 23guess = int(input('Enter an integer : '))if guess == number: print ('Congratulations, you guessed it.') # New block sta...
阅读全文
浙公网安备 33010602011771号