易截截图软件、单文件、免安装、纯绿色、仅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
然后你的两个函数的逻辑


相关问答:

eric4怎么运行python程序?

python和pyqt以及Eric4都已经配置好了,打开Eric4写个python程序比如简单的
print“hello,world”,怎么编译运行了,Start菜单的所有命令都出现和图中差不多的对话框,应当怎么运行了?

求大家指教

没有人用 ......

[提问]Python 如何忽略 whitespace 读入

像 C 的 scanf() 那样
比如读入 1 2 3 a b c
每次读入一个
下面这个应该是你想要的吧:
Python code:

>>> k = raw_input()
0 0123 ds dsl sd
>>> k
'0 0123 ds dsl sd'
>>> ......

python 图像多边形切割

python的PIL库自带的方法只能进行矩形的切割,如果我有了一个多边形各个顶点的坐标,如何对现有的图片按照这个多边形进行切割呢?
不一定要用PIL库,任何能实现这个功能的方法都行。

图片切割的js不是很多吗?
......

各位大侠,Python 编码问题

例子是这样的:

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

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

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

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