为什么我会收到此错误,我该如何解决?

时间:2014-07-09 04:58:19

标签: python c cython sympy

我正在使用anaconda(python2.7)和im进行cython化一个程序,我得到一个错误。我的程序写入文件的地方,我得到属性错误。有人可以帮我修改我的代码吗?此外,任何提高它运行速度的提示(cythonization等)都将非常感激!

到目前为止,这是我的代码:

http://pastebin.com/gmC7rtBB

这是错误代码:

Traceback (most recent call last):

  File "<ipython-input-1-e95db2234cf8>", line 1, in <module>
    runfile('C:/Users/Jay/Desktop/quantum emulator/qemulatortestt.py', wdir='C:/Users/Jay/Desktop/quantum emulator')

  File "C:\Users\Jay\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 585, in runfile
    execfile(filename, namespace)

  File "C:/Users/Jay/Desktop/quantum emulator/qemulatortestt.py", line 246, in <module>
    rewrite(task, asciivalue)

  File "C:/Users/Jay/Desktop/quantum emulator/qemulatortestt.py", line 77, in rewrite
    fle.write(cnt)

AttributeError: 'str' object has no attribute 'write'

1 个答案:

答案 0 :(得分:1)

with open(fle, 'r+') as f:
    f.write(cnt)
    f.close()
    return f

fle是表示文件路径的字符串。