本文介绍了如何在linux环境中读取windows文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在linux上执行一个python程序,我首先在windows上创建它,但是显示以下错误:
metadata = eval(metafile.read())
文件< ; string>,第1行

  @ 
@
@
@ $ b b @
@

任何想法?感谢!

解决方案
  dos2unix yourfile.py 
python yourfile.py

如果您没有 dos2unix 一些python代码可以改用。只需将它放在dos2unix.py中,并运行 python dos2unix.py yourfile.py

  import sys 
filename = sys.argv [1]
text = open(filename,'rb')read()。replace('\r\\\
' '\\\
')
open(filename,'wb')。write(text)

此代码从复制而来。


I'm trying to execute a python program on linux which i first created it on windows, but the following error is shown: metadata = eval(metafile.read()) File "< string >", line 1

@
@
@
@
@
@

Any idea? thanks!

解决方案
dos2unix yourfile.py
python yourfile.py

If you don't have dos2unix, here is some python code you can use instead. Just put this in dos2unix.py, and run python dos2unix.py yourfile.py above:

import sys
filename = sys.argv[1]
text = open(filename, 'rb').read().replace('\r\n', '\n')
open(filename, 'wb').write(text)

This code was copied from Python dos2unix one liner.

这篇关于如何在linux环境中读取windows文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:20