Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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µÄÊ飬лл
¡¶python¼òÃ÷½Ì³Ì¡·£¬¡¶pythonºËÐıà³Ì¡·

×÷Ϊϵͳ¹ÜÀí·½Ãæ£¬¡¶Python UNIXºÍLinuxϵͳ¹ÜÀíÖ¸ÄÏ¡·ÊDZ¾·Ç³£²»´íµÄÊé¡£
http://club.book.csdn.net/pic3/255142.jpg

ÒýÓÃ
×÷Î ......

IIS 7 python 2.6 cgi ÎļþÉÏ´«ÎÊÌâ

ÎÒÿ´ÎÉÏ´«µÄÎļþ¶Áµ½µÄÊý¾Ý¶¼²»ÕýÈ·¡£2M µÄͼƬ¶ÁµÃ10¶àK ¡£¡£ÄÄλ´óÏÀ¿ÉÒÔ°ï°ïÎÒ°¡¡£
#!D:\ProgrammerTools\python26\python.exe
#encoding=utf-8
import cgitb
import os
cgitb.enable()
import cgi,urllib ......

python 3.xµÄifÓï¾ä

>>> x=-1
>>> if x>0:
print ('11')

>>> else:

SyntaxError: invalid syntax (<pyshell#20>, line 1)
ÍøÉÏËѵÄÒ²ÊÇ£º
>>> x=int(input("Please ent ......

ÓôÃÆ£¬python 0d0a»»ÐÐÎÊÌâ

import os,sys,zipfile
teststr = open('1.txt').read()
zipFile = zipfile.ZipFile('test.zip','w')
zipFile.writestr('test.txt',teststr)
zipFile.close()

É ......

¹ØÓÚ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ºÅ