python Script executed 3 Methods :
Method 1 : Interactive mode direct execution statement
Method 2 : Output through script
Method 3 : The script specifies python route , Modify the file to executable
summary
python Script executed 3 Methods :( Find ways you can use , The way you can use is a good way )
Method 1 : Interactive mode direct execution statementWrite and execute directly in interactive mode Python sentence , No more script files
Windows Next :
Open and enter the command prompt --------> Input python And return --------> Enter interactive mode
Linux Next :
Turn on the terminal emulator -------> Input python( Corresponding version number )------> Go into interactive mode ------> Input exit() Exit interactive mode
Method 2 : Output through scriptUsing text editor , Write a script file , Name it xxx.py, Enter in command line mode python xxx.py that will do
( Be careful : To enter the path where the script file is located , Or enter the full path of the script file )
① Enter the path of the script file to execute
C:\Windows\System32>D:
D:\ route >
Input again python xxx.py
② Give the full path of the script file
(windows)C:\Windows\System32>python D:\ route \xxx.py
(Linux) Their slashes are in different directions
Method 3 : The script specifies python route , Modify the file to executable① Add at the first line of script file #!/ route /python3
② Add file executable permissions
$ chmod u+x xxx.py$ ls -la xxx.py-rwxrw-r-- xxx.py
③ function $ ./xxx.py
( Be careful : To specify the interpreter in the script file , Otherwise, you cannot run the script file directly )
summaryThis is about python This is the end of the article on three methods of running script files , More about python Please search the previous articles of the software development network or continue to browse the relevant articles below. I hope you can support the software development network in the future !