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.
The sys.argv functionallities.
Cool I think this would better fit on learn board tho.
@Codemonkey51 alright thanks for the suggestion.
Your welcome also I think learn doesn't requires a repl @Jakman
@Codemonkey51 bruh
Wat @Jakman
@Codemonkey51 what? got a question?
Why bruh? @Jakman
@Codemonkey51 oh yeah this wont work on repl.it since you have to type into the command line.
@Codemonkey51 i could have left this file out and use less storage lol.
No it will work, you can achieve this by using the following code:
{command} as in any bash command (bash to open terminal)
@Jakman
@Codemonkey51 ok ill try that.
Well u can re-use it for other replless share posts @Jakman
@Codemonkey51 after i open the bash terminal the program just stops.
Hrmm mine works just type bash when it says:
command:
@Jakman https://repl.it/@Codemonkey51/Bash-terminal@Codemonkey51 thanks but my head hurts. Im glad i could at least share documentation.
Ok sorry your head hurts hope it feels better soon :-) @Jakman