Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

pythonÎļþºÍ·¾¶²Ù×÷½éÉÜ

from http://blog.alexa-pro.cn/?p=189
1: os.listdir(path) //pathΪĿ¼
¹¦ÄÜÏ൱ÓÚÔÚpathĿ¼ÏÂÖ´ÐÐdirÃüÁ·µ»ØÎªlistÀàÐÍ
print os.listdir('..')
Êä³ö£º
[a,b,c,d]
2: os.path.walk(path,visit,arg)
path £ºÊǽ«Òª±éÀúµÄĿ¼
visit £ºÊÇÒ»¸öº¯ÊýÖ¸Õ룬º¯ÊýÔ²ÐÎΪ£º
callback(arg,dir,fileList)
ÆäÖÐargΪΪ´«¸øwalkµÄarg £¬ dirÊÇpathϵÄÒ»¸öĿ¼£¬fileListΪdirϵÄÎļþºÍĿ¼×é³ÉµÄlist
arg£º´«¸øvisitÓõ쬶ÔwalkûÓÐʲô×÷ÓÃ
¾ÙÀý£º
def callback(arg,directory, files):
print directory,
print files,
print arg
print '——————–'
os.path.walk('.',callback, '123456′)
Êä³ö£º
. ['path0704.py', 'temp', '\xc2\xb7\xbe\xb6\xcf\xe0\xb9\xd8\xd1\xa7\xcf\xb0.txt'] 123456
——————–
.\temp ['temp.h', 'temp1'] 123456
——————–
.\temp\temp1 ['abc.bmp'] 123456
Èç¹ûÏëÕÒµ½Ä³¸öĿ¼ÏÂËùÓÐÎļþ£¬Ö»ÐèÒªÔÚcallbackÀïÃæ£¬ÔÚfileListÖÐÕÒ³öÎļþ£¬¼´¿É³ý´ËÖ®Í⣬»¹ÓÐÒ»¸öº¯Êý¿ÉÒÔÓÃÄǾÍÊÇos.walk£¬¿´10
3£ºos.path.split(path)
path Ϊһ¸ö·¾¶£¬
Êä³ö£¬°Ñpath·Ö³ÉÁ½²¿·Ö£¬¾ßÌ忴ʵÀý£º
print os.path.split("abc/de.txt")
('abc', 'de.txt')
os.path.split("abc")
(", 'abc')
print os.path.split("de/abc/de")
('de/abc', 'de')
4: os.path.splitext(filename)
°ÑÎļþÃû·Ö³ÉÎļþÃû³ÆºÍÀ©Õ¹Ãû
os.path.splitext(abc/abcd.txt)
('abc/abcd', '.txt')
5: os.path.dirname(path)
°ÑĿ¼ÃûÌá³öÀ´
print os.path.dirname("abc")
#Êä³öΪ¿Õ
print os.path.dirname('abc\def')
abc
6£º os.path.basename(filename)
È¡µÃÖ÷ÎļþÃû
print os.path.basename('abc')
abc
print os.path.basename('abc.txt')
abc
print os.path.basename('bcd/abc')
abc #Õâ¸öÐèҪעÒâ²»°üÀ¨Ä¿Â¼Ãû³Æ
print os.path.basename('.')
.
7£ºos.mkdir(path, [mode])
pathΪĿ¼Ãû£º ÕâÀïÓиöÒªÇó£¬Ö»ÄÜ´´½¨Ò»¼¶Ä¿Â¼
±ÈÈçpathΪ abc/def Ôòµ±Ç°Ä¿Â¼Ï±ØÐë´æÔÚabc ·ñÔòʧ°Ü
8£º os.makedirs(path [,mode])
¿ÉÒÔ´´½¨¶à¼¶Ä¿Â¼
9£ºos.remove(path)ɾ³ýÒ»¸öÎļþ£¬Ò»¶¨ÊÇÒ»¸öÎļþ
os.removedirs(path) ɾ³ýÒ»¸öĿ¼ÏÂËùÓж«Î÷
os.rmdir(path) ɾ³ýÒ»¸öĿ¼£¬¶øÇÒÒ»¶¨Òª¿Õ£¬·ñÔ


Ïà¹ØÎĵµ£º

Python×Ö·û´®²Ù×÷[ת]


Python×Ö·û´®²Ù×÷
pythonÈçºÎÅжÏÒ»¸ö×Ö·û´®Ö»°üº¬Êý×Ö×Ö·û 
python ×Ö·û´®±È½Ï 
ÏÂÃæÁгöÁ˳£ÓõÄpythonʵÏÖµÄ×Ö·û´®²Ù×÷
1.¸´ÖÆ×Ö·û´®
#strcpy(sStr1,sStr2)
sStr1 = 'strcpy'
sStr2 = sStr1
sStr1 = 'strcpy2'
print sStr2
2.Á¬½Ó×Ö·û´®
#strcat(sStr1,sStr2)
sStr1 = 'strcat'
sStr2 = 'appen ......

PythonµÄbug

PythonÌ«»ðÁË£¬²»Ñ§µã¶¼¸Ð¾õ×Ô¼º²»ÊÇѧ¼ÆËã»úµÄ£¬½ñÌì¿´Á˸ö²»´íµÄ¡¶¼òÃ÷python½Ì³Ì¡·£¬ºÜ²»´í¡£²»¹ýÔÚѧϰ¹ý³ÌÖУ¬¾ÓÈ»·¢ÏÖÁËÒ»¸öPythonµÄbug£¬
#!/usr/bin/python
#coding=UTF-8
class Person:
'''Represents a person.'''
population = 0
def __init__(self, name):
'''Initializes the person's data.'''
......

ÔÚpythonÖд¦ÀíXML×ܽá

±¾ÎÄ×ܽáÁËÔÚPythonÖÐÖ÷ÒªµÄ¼¸ÖÖ´¦ÀíXMLµÄ·½·¨£º
Element Tree
SAX
Dom
ʹÓõÚÈý·½Àà¿âÈçAmara 2.x£¬ libxml2dom µÈ
Element Tree
Element TreeÊÇPython 2.5ÒýÈëµÄʹÓüòµ¥£¬¿ì½ÝµÄ´¦Àí·½·¨£¬ Ò²ÊÇPython±ê×¼Àà¿âÍÆ¼öµÄ´¦ÀíXMLµÄ·½·¨¡£
ËüʹÓÃÊ÷ÐνڵãµÄÐÎʽÀ´¶ÁдXML¡£Element TreeÊÇÇáÁ¿¼¶µÄDOM£¬ ËùÒÔÊ ......

PythonÖ®HTMLParser

"""A parser for HTML and XHTML."""
# This file is based on sgmllib.py, but the API is slightly different.
# XXX There should be a way to distinguish between PCDATA (parsed
# character data -- the normal case), RCDATA (replaceable character
# data -- only char and entity references and end tags a ......

ʹÓÃpdbµ÷ÊÔPython³ÌÐò

ʹÓÃpdbµ÷ÊÔPython³ÌÐò
 
±¾ÎÄÌÖÂÛÔÚûÓз½±ãµÄIDE¹¤¾ß¿ÉÓõÄÇé¿öÏ£¬Ê¹ÓÃpdbµ÷ÊÔpython³ÌÐò
 
Ô´ÂëÀý×Ó
ÀýÈ磬ÓÐÄ£Äâ˰ÊÕ¼ÆËãµÄ³ÌÐò£º
 
#!/usr/bin/python
def debug_demo(val):
                if val &l ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ