Python Forum

Full Version: sys.argv method
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

For my research, I need to run a Python script that can analyze the syntactic complexity of the texts. The script essentially takes an input text file and provides a set of complexity indices in an output text file. It is written to be run through a command line in MAC; however, this option is not working for me, as I keep getting errors. I tried to use IDLE to run the script, but then I take an error message as input and output file names are given as sys.argv[1] and sys.argv[2] in the script. How can I replace these two with the hard-coded version of the input and output file in the script? I attached the script to this post, I would really appreciate it if someone can offer me a solution for this.
You can replace sys.argv[1] by a string '/path/to/input-file.txt' for example and similarly for sys.argv[2]. Note that sys.argv is not a method, it is just a Python list.
Hi,

if you want to hard-code the path, look at lines 66 and 72 and insert your pathes there.

Except this, there would be a lot of things to improve on the quality of the code. However, if you are not familiar with Python and the script does the job for you, you may not want to touch it. However, the function in lines 19 to 22 is wrong from the mathematical point of view. Dividing by 0 is not zero.

Regards, noisefloor
I would provide a default filename. You can leave this in the code and it will not affect running from the command line.
inputFile=sys.argv[1] if len(sys.argv) > 1 else 'default_file'