Skip to content
Sign upLog in
← Back to Community

sys.argv functionality

Profile icon
Jakman

So in python3 you may want to contact a python file from the inside of that python file. The way you do this is with 'sys.argv' Lets say that you go to the command line and type in "example.py" as your python file. You can access the arguments typed into the command line by using "sys.argv" So in this case typing 'example.py' into the command line is the
same as "sys.argv[0]" or the first thing typed into the command line. To give a visual of this lets say that your file path is "C://Documents/SomeFolder/>" on the command line. When "example.py" is typed into the command line e.g.
"C://Documents/SomeFolder/>example.py" you could access the file name by putting sys.argv[0] in the code. An example of how this can be used is by a self running program. The code is simple. "
import os,sys
print("This program is run by itself.")
os.system(sys.argv[0])
"
This code will print out some text and start the program again by itself. You can stop it by terminating the source.
Thank you for reading and I will be sure to answer any questions that you have for me.

Voters
Profile icon
Jakman
Comments
hotnewtop
Profile icon
ArshadSaqib

A professional should be willing to learn, keep up with current changes, have a high ethical standard, take responsibility of one's actions and respect colleagues. https://www.collegebasics.com/blog/dissertation-writing-services/

Profile icon
HankFried

Examsleader offers you one-stop solution to all your MuleSoft Certified Integration Architect - Level 1 exam worries. No need to cram lengthy notes or buy expensive tutorials. Examsleader’s intuitively designed MuleSoft Certified Architect MCIA-Level-1 exam dumps questions provide you the easiest way to obtain your target MuleSoft Certified Architect certification with the top score!