Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python
#1
I'm new to python and stuck on the concept of command-line arguments.
The variable filename and input filename must both refer to files that exist and can be read by the
program. The output filename must refer to a file that can be opened for writing by the program.
The following operations are performed.
First, the variable file is read and each line is interpreted as the definition of a variable. The text
before = on a line is the name of the variable, and the text after = is its value. Collectively, the data
read in this step are called the templating variables. The variable file is closed. Here is the code that I need to modify to use sys.argv[1] as the variable file, sys.argv[2] as the input file, and sys.argv[3] as the output file.
import sys
import varsub
if len(sys.argv) != 3:
    print("Usage: {} INFILE OUTFILE".format(sys.argv[0]))
    print("The text file INFILE is then converted to an HTML file OUTFILE.")
    sys.exit()

infn = sys.argv[1]
outfn =sys.argv[2]

# open input and output files
fin = open(infn,"r")
fout = open(outfn,"w")
snippsat write Oct-28-2020, 06:24 PM:
Added code tag in your post,look at BBCode on how to use.
Reply
#2
Sorry, but after reading your post, I'm not sure what your question is. Do you have some particular problem with the above that you need assistance with?
Reply
#3
(Oct-28-2020, 07:08 PM)bowlofred Wrote: Sorry, but after reading your post, I'm not sure what your question is. Do you have some particular problem with the above that you need assistance with?

My program doesn't use sys.argv[1] as the variable file, sys.argv[2] as the input file, and sys.argv[3] as the output file. I three files template.py varsub.py and readme.txt
Reply
#4
(Oct-28-2020, 11:30 PM)mluong2 Wrote: My program doesn't use sys.argv[1] as the variable file, sys.argv[2] as the input file, and sys.argv[3] as the output file. I three files template.py varsub.py and readme.txt

your code does not show you expect sys.argv[3] at all. And is not showing how you process your files.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

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