0

Hi all –
I am running Python 2.6.2 in a Windows XP Pro environment. I am trying to write my first python/cgi script combo and they must execute on a Linux websever. After surfing the web I realize that MS-DOS and Unix systems use different methods to identify end-of-line information in text files (CR/LF vs. LF).
Is there a quick and simple way to convert my cgi script so that I can run in on the Linux server? I tried using a dos2unix file but don’t know enough about it to use it properly. Thanks.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by redpython
0

You can try this

def dos2unix(my_string):
    return my_string.replace("\r\n", "\n") # is it \n\r instead ?

if __name__ == "__main__":
    dos_content = "line1\r\nline2\r\nline3\r\n"
    unix_content = dos2unix(dos_content)
    print repr(unix_content)

"""my output --->
'line1\nline2\nline3\n'
"""

Note that there are numerous other potential issues: if your cgi scripts use the win32 api, they will fail on linux, also the file separator differs on windows \ and linux / , etc.

Edited by Gribouillis: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.