如何在Linux环境下读取Windows文件? [英] How to read Windows file in Linux environment?

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

问题描述

我正在尝试在Windows上首次创建的Linux上执行Python程序,但显示以下错误:

I'm trying to execute a Python program on Linux which I first created on Windows, but the following error is shown:

metadata = eval(metafile.read())
File "< string >", line 1

@
@
@
@
@
@

有什么主意吗?

推荐答案

dos2unix yourfile.py
python yourfile.py

如果您没有dos2unix,则可以使用以下python代码代替.只需将其放入dos2unix.py,然后在上方运行python dos2unix.py 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)

此代码是从 Python dos2unix一个衬里复制的.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆