Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sys.argv method
#1
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.
Yoriz write Jan-23-2023, 11:36 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

.py   analyzeText.py (Size: 5.31 KB / Downloads: 135)
Reply
#2
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.
Reply
#3
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
Reply
#4
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'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 788 May-02-2023, 08:40 AM
Last Post: Gribouillis
  import argv Scott 3 5,896 Apr-01-2021, 11:03 AM
Last Post: radix018
  use of sys.argv deepakkr3110 3 3,040 Nov-29-2019, 05:41 AM
Last Post: buran
  Not all data returned from sys.argv ecdhyne 2 2,757 Sep-05-2019, 08:27 PM
Last Post: buran
  Pyinstaller with Sys.Argv[] - “Failed to Execute Script”? ironfelix717 0 5,303 Aug-07-2019, 02:29 PM
Last Post: ironfelix717
  I see is that sys.argv contains character strings helenharry 2 2,754 Jan-09-2019, 11:34 AM
Last Post: DeaD_EyE
  How argv works? Philia 7 4,834 Dec-26-2018, 12:20 AM
Last Post: metulburr
  sys.argv correct sintax? enricosx 3 3,203 Jul-25-2018, 09:27 AM
Last Post: buran
  I gotta problem with making argv parameters Bozx 3 4,049 Apr-04-2017, 03:44 AM
Last Post: alicarlos13
  argv IndexError hsunteik 2 4,528 Dec-19-2016, 06:19 AM
Last Post: hsunteik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020