易截截图软件、单文件、免安装、纯绿色、仅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 中一个疑惑

return func 与return func()
有什么不同的?
return func返回的是一个函数对象,
return func()返回的是func()函数的返回结果。

楼上正解

一个是返回变量 一个是返回的时候 再调用一下func函数
我觉得是 ......

各位大侠,Python 编码问题

例子是这样的:

>>> str1 = '小狗'
>>> str1
'小狗'
>>> str1.encode('utf-8')
b'\xe5\xb0\x8f\xe7\x8b\x97'
>>> str2 ......

关于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):
......

C# RSA Python - .NET技术 / C#

C#里面用using System.Security.Cryptography; RSACryptoServiceProvider加密过的消息
用Python Crypto中RSA的方法 能直接 解吗?
RSA加密方式不是统一的吗?需要注意些什么?

有帮助。但是没解决问题。。。
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号