我的文件包含针对 Windows 格式化的代码。当我尝试在 Linux 机器上运行它们时,我遇到了文件编码问题。任何人都可以为此提出解决方案
在 Windows 上运行时我得到 -
This was return from redis
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/bsingh/python_files/lib/Site.py", line 85, in monitor
self.update1()
File "/home/bsingh/python_files/lib/Site.py", line 78, in update1
for entry in new_pastes[::-1]:
TypeError: 'NoneType' object has no attribute '__getitem__'
最佳答案
你应该试试——
dos2unix <filename>
将在 windows 中创建的文件转换为 unix 格式。 Reference
请注意 dos2unix,不是 python 代码转换,它会将 dos 字符转换为 unix 等效字符。
关于从 Windows 到 Linux 的 Python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30884008/