PythonÖеÄOSÄ£¿é
osÄ£¿éÌṩÁ˶àÊý²Ù×÷ϵͳµÄ¹¦Äܽӿں¯Êý.µ±osÄ£¿é±»µ¼Èëºó,Ëü»á×ÔÊÊÓ¦ÓÚ²»Í¬µÄ²Ù×÷ϵͳƽ̨,Èçposix»òNTϵͳƽ̨,osÄ£¿é»á¸ù¾Ý²»Í¬µÄƽ̨½øÐÐÏàÓ¦µÄ²Ù×÷.±¾½ÚÄÚÈݽ«¶ÔosÄ£¿éÌṩµÄº¯Êý½øÐÐÏêϸµÄ½â¶Á.
1.1 Îļþ²Ù×÷º¯Êý
1.1.1 open()º¯ÊýÌṩ´´½¨¡¢´ò¿ª¡¢ÐÞ¸ÄÎļþµÄ¹¦ÄÜ¡£
Example 1-1. Using the os Module to Rename and Remove Files
#Filename: os-example-1.py
import os
import string
def replace(file, search_for, replace_with):
# replace strings in a text file
back = os.path.splitext(file)[0] + ".bak"
temp = os.path.splitext(file)[0] + ".tmp"
try:
# remove old temp file, if any
os.remove(temp)
except os.error:
pass
fi = open(file)
fo = open(temp, "w")
for s in fi.readlines():
fo.write(string.replace(s, search_for, replace_with))
fi.close()
fo.close()
try:
# remove old backup file, if any
os.remove(back)
except os.error:
pass
# rename original to backup...
os.rename(file, back)
# ...and temporary to original
os.rename(temp, file)
# try it out!
file = "samples/sample.txt"
replace(file, "hello", "tjena")
replace(file, "tjena", "hello")
1.1.2 rename()ºÍremove()º¯Êý,¶ÔÎļþ½øÐÐÖØÃüÃûºÍɾ³ý²Ù×÷.Çë²ÎÕÕÀý1-1
1.2 Ŀ¼²Ù×÷
1.2.1 listdir()º¯Êý,·µ»ØÖ¸¶¨Ä¿Â¼ÏÂËùÓÐÎļþÃû,²¢±£´æÓÚÒ»ÁбíÖÐ.µ«µ±Ç°Ä¿Â¼±ê¼Ç(.)ºÍ¸¸Ä¿Â¼±ê¼Ç(..)²»ÔÚÆäÖÐ.
Example 1-2. Using the os Module to List the Files in a Directory
File: os-example-2.py
import os
for file in os.listdir("samples"):
Ïà¹ØÎĵµ£º
import types
type(x) is types.IntType # ÅжÏÊÇ·ñint ÀàÐÍ
type(x) is types.StringType #ÊÇ·ñstringÀàÐÍ
.........
--------------------------------------------------------
³¬¼¶¶ñÐĵÄģʽ£¬²»ÓüÇסtypes.StringType
import types
type(x) == types(1) # ......
[Ô´´]Python´úÂëÄ£¿éÈȸüлúÖÆʵÏÖ(reload)
by AKara 2009-05-17 @ http://blog.csdn.net/akara @ akaras@163.com
---------------------------------------------------------------------
¶ÔÒ»¸öÓÎÏ·À´Ëµ£¬ÎÞÂÛÊÇclient»òserver¶¼·Ç³£ÐèÒªÒ»Ì×´úÂëÈȸüеĻúÖÆ¡£
ËüÄÜ´ó´óÌá¸ß¿ª·¢Ð§ÂÊ£¬ÓÖÄܳ¬ºõÍæ ......
myDict = { 'item1' : [ 7, 1, 9], 'item2' : [8, 2, 3], 'item3' : [ 9, 3, 11 ] }
def sortDic(Dict,valuePostion):
return sorted(Dict.items(),key=lambda e:e[1][valuePostion])
//°´valueµÄµÚ3¸öÖµÅÅÐò
sortDic(myDict,2)
[('item2', [8, 2, 3]), ('item1', [7, 1, 9]), ('item3', [9, 3, 11])]
//°´valueµÄµÚ ......
ÒÔÏÂ"#"¿ªÍ·ÊÇUbuntuÖÕ¶ËÃüÁî
1¡£Ê×ÏÈ°²×°Ubuntu10.04
²Î¿¼ http://wiki.ubuntu.org.cn/
2¡£ÐÞ¸ÄrootÓû§ÃÜÂë
3¡£Ê¹ÓÃrootµÇ½ϵͳ
4¡£UbuntuĬÈÏÒѾ°²×°python2.6.5
5¡£ÏÂÔØstackless
²é¿´ÍøÖ· http://zope.stackless.com/download/sdocument_view
# cd /usr/src
# wget http://www.sta ......
£¨Ò»£© py2exe¼ò½é
py2exeÊÇÒ»¸ö½«python½Å±¾×ª»»³ÉwindowsÉϵĿɶÀÁ¢Ö´ÐеĿÉÖ´ÐгÌÐò(*.exe)µÄ¹¤¾ß£¬ÕâÑù£¬Äã¾Í¿ÉÒÔ²»ÓÃ×°python¶øÔÚ
windowsϵͳÉÏÔËÐÐÕâ¸ö¿ÉÖ´ÐгÌÐò¡£
¡¡¡¡
¡¡¡¡py2exeÒѾ±»ÓÃÓÚ´´½¨
wxPython,Tkinter,Pmw,PyGTK,pygame,win32com
clientºÍserver,ºÍÆäËüµÄ¶ÀÁ¢³ ......