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

pythonдÎļþʱ³öÎÊÌâ

Òì³£´úÂëÈçÏ£º
write a file error: [Errno 2] No such file or directory: 'C:\x0cile.txt'

Traceback (most recent call last):
  File "C:\Documents and Settings\USER\×ÀÃæ\¸´¼þ test.py", line 84, in <module>
    test()
  File "C:\Documents and Settings\USER\×ÀÃæ\¸´¼þ test.py", line 78, in test
    writefile(s)
  File "C:\Documents and Settings\USER\×ÀÃæ\¸´¼þ test.py", line 59, in writefile
    f.write(str(string))
UnboundLocalError: local variable 'f' referenced before assignment


Python code:

¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£

def writefile(string):
strfile="C:\file.txt"
try:
f = open(strfile,'a')
except IOError,e:
print "write a file error:",e

f.write(str(string))
f.close()



def test():
fname = 'C:\ZLLKDoc.cpp'
#raw_input('Enter filename: ')
try:
fobj = open(fname, 'r')
except IOError, e:
print "*** file open error:", e
strFile=fobj.read()

fobj.close()

s = eraser(strFile)
print s





ʵÔÚ²»ÖªµÀÄÄÀï´íÁË£¬Çë´óÏÀÃǰïæ¿´¿´£¬¸Ð¼¤²»¾¡
test£¨£© º¯ÊýÖеÚÒ»ÐмÓÈë global f
È»ºóÄãµÄÁ½¸öº¯ÊýµÄÂß¼­


Ïà¹ØÎÊ´ð£º

³ÏÕÐPython³ÌÐòÔ±²ÎÓë¼ÆËã»úÊé¼®³ö°æ

ÓźñµÄ¸å³ê£¬³ÏÕÐPython¼¼ÊõÈËÔ±²ÎÓë¸÷ÖÖ¼¼ÊõÊé¼®³ö°æ¡£ 
ͨ¹ý¸ÃÊé¼®£¬×÷Õß¿ÉÒԵõ½Èçϱ¨³ê£º 
1¡¢·áºñµÄ¸å³ê¡£ 
2¡¢Êé¼®Öø×÷µÄÊðÃûȨ¡£ 
3¡¢¶Ô×÷ÕߺÍÊé½øÐÐÐû´«£¬Ìá¸ß×÷ÕßÔÚ¼¼ÊõȦ×ÓÀ ......

python listÖÐÌí¼ÓÀà¶ÔÏóµÄÎÊÌâ

ÔÚlistÖÐÌí¼ÓÒ»¸öÀàµÄ¾Ö²¿±äÁ¿ ÕâÑù×öÊÇ·ñºÏ·¨ Çë¿´ÏÂÃæÀý×Ó:
Python code:

class A():
def __init__( self ):
self.__a = 0
self.__b = 'hello'
def get_a( self ):
ret ......

python urllib urllib2 httplib ·ÃÎÊurlµÄÎÊÌâ

ÎÒÏëÓÃpython½âÎöÍøÒ³ÖеÄurl ÔÚÏÂÔØÖ®Ç°, ÎÒÏëÏÈ·¢Ò»¸öheadÇëÇó ²»ÐèÒªÏÂÔØÕû¸öÍøÒ³, ÏÈ»ñµÃ¸ÃÍøÕ¾µÄheadÐÅÏ¢, ¶ÁȡһЩÐÅÏ¢Ö®ºó ÔÚµ÷ÓÃÕâЩ¿âµÄread·½·¨À´¶ÁÈ¡Õû¸öÍøÒ³ ¸ÃÔõô²Ù×÷ÄØ ¶àл
°ï¶¥ÁË

ÓÐÈËÄÜÖ¸½ÌÒ» ......

python ÖÐÒ»¸öÒÉ»ó

return func Óëreturn func()
ÓÐʲô²»Í¬µÄ£¿
return func·µ»ØµÄÊÇÒ»¸öº¯Êý¶ÔÏó£¬
return func()·µ»ØµÄÊÇfunc()º¯ÊýµÄ·µ»Ø½á¹û¡£

Â¥ÉÏÕý½â

Ò»¸öÊÇ·µ»Ø±äÁ¿ Ò»¸öÊÇ·µ»ØµÄʱºò ÔÙµ÷ÓÃÒ»ÏÂfuncº¯Êý
ÎÒ¾õµÃÊÇ ......

¹ØÓÚpython class£º callerRefµÄÎÊÌâ

Python code:

class A:
def __init__(self):
self.B_Handle = B_Handle
self.VA = "A_init"
print "Class A init"
def __getattr__(self, name):
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ