NickName:prashant chhetri Ask DateTime:2019-10-13T19:25:46 How to convert dos2unix csv file with python script I want to convert a csv file into dos2unix format using python in windows. Rightnow I am doing manually by placing csv file in workarea(server) and run command in putty.[Command : dos2unix file_received filename] Copyright Notice:Content Author:「prashant chhetri」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.Link to original article:https://stackoverflow.com/questions/58363093/how-to-convert-dos2unix-csv-file-with-python-script Answers RightmireM 2019-10-13T11:43:45 dos2unix (as I recall) pretty much only strips the trailing linefeeds off each line. So, there's two ways you can do this. \n\nwith open(filename, \"w\") as fout: \n with open(file_received, \"r\") as fin:\n for line in fin:\n line = line.replace('\\r\\n', '\\n')\n fout.write(line)\n\n\nor you can use subprocess to call the UNIX command directly. WARNING: This is bad since you're using a parameter file_received, and people could potentially tag executable commands into it. \n\nimport subprocess\nsubprocess.call([ 'dos2unix', file_received, filename, shell=False])\n\n\nI haven't tested the above. The shell=False (the default) means a UNIX shell won't be called for the process. This is good to avoid someone inserting commands into the parameters, but you may have to have shell=True in order for the command to work right. ",