How to read Windows file in Linux environment?

前端 未结 1 825
一向
一向 2021-01-21 21:02

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 \"<         


        
相关标签:
1条回答
  • 2021-01-21 21:22
    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.

    0 讨论(0)
提交回复
热议问题