python - 为什么我会收到此错误以及如何修复它?

标签 python c cython sympy

我正在使用 anaconda(python2.7) 并在 cythonizing 程序的过程中得到一个错误。在我的程序写入文件的地方,我收到属性错误。有人可以帮我修复我的代码吗?另外,任何使它运行得更快的提示(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'

最佳答案

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

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

关于python - 为什么我会收到此错误以及如何修复它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24645686/

相关文章:

python - vim 的 Youcompleteme 插件无法为来自 errno.h 的错误代码提供补全

python - GEE不将数据导入数组

python - Cythonize Python 函数以使其更快

c++ - C中的MAX和MIN是什么? #定义函数

c - lixml2 C xpath 失败并显示 "invalid expression"

python - 如何在cython中包含C++所需的路径?

Python,使用多处理进一步加速cython函数

python - 如何使用python连接Microsoft Graph而不需要UI交互?

python - 在 "empty"行处切片 numpy 重新排列

c - C 语法澄清中通过指针访问数组