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

时间:2022-06-03 23:07:47

im using anaconda(python2.7) and im in the process of cythonizing a program and im getting an error. where my program writes to the file, i get an attribute error. can someone please help me fix my code? also, any tips to make it run faster(cythonization, ect.) would be greatly appreciated!

即时通讯使用anaconda(python2.7)和im在程序化cython的过程中,我得到一个错误。我的程序写入文件的地方,我得到一个属性错误。有人可以帮我修改我的代码吗?此外,任何使其运行更快(cythonization等)的提示将不胜感激!

this is my code so far:

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

http://pastebin.com/gmC7rtBB

http://pastebin.com/gmC7rtBB

and this is the error code:

这是错误代码:

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 个解决方案

#1


1  

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

fle is a string denoting the file path.

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

#1


1  

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

fle is a string denoting the file path.

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