0

I am trying to understand this side of the python where we execute Python from commandline and input a specific file or asking to perform specific task. Presently I wanted to input a file like this

# input a file 
c:>python main_file.py -f input1.txt
# output a file
c:>python main_file.py -o output1.txt
9
  • Are -f and -o standard command line arguments to python or just your main_file.py script? Commented Oct 14, 2021 at 12:36
  • @eugenhu Ok. If there are no such standard command-line arguments, please treat it just for my script. Commented Oct 14, 2021 at 13:01
  • Not quite sure what you're asking then, could you rephrase? Do you mean how to retrieve the arguments in your script, e.g. sys.argv()? Commented Oct 14, 2021 at 13:01
  • @eugenhu My apologies. I have also no idea whether these are standard commands from Python. I just heard them. I was saying, if there are no such Python commands, please treat it just for my script (as If I have to design my script in such a way that it responds to -f or -o commands). Commented Oct 14, 2021 at 13:04
  • 1
    Alright I'm going to take a shot in the dark and say you're looking for help on how to parse command line arguments in python scripts, in this case have a look at What's the best way to parse command line arguments?. The basics is to just look at the elements in sys.argv, for starters just have your main_file.py script be print(sys.argv) to see what it contains. Commented Oct 14, 2021 at 13:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.