程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Three methods of running script files in Python

編輯:Python

Catalog

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 statement

Write 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 script

Using 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 )

summary

This 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 !



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved