命令行参数是通过sys.argv[]来获取的,sys.argv[0]是代码文件本身的路径,因此参数是从1开始的。比如设置参数为: spe
Python代码:
Python天天美味(20) - 命令行参数sys.argvimport os, sys
Python天天美味(20) - 命令行参数sys.argvos.system(sys.argv[
1])
带参数执行 python xxx.py spe
os.system 是用来执行命令行的。因此该程序会接收到第一个参数spe,然后在命令行里执行spe,这样,spe(Python IDE)就打开了。

Python 天天美味系列(总)

Python 天天美味(18) - linecache.getline()读取文件中特定一行  

Python 天天美味(19) - 时间处理datetime  

Python 天天美味(20) - 命令行参数sys.argv   

Python 天天美味(21) - httplib,smtplib  

Python 天天美味(22) - 拷贝对象(深拷贝deepcopy与浅拷贝copy)  

...

相关文章:

  • 2021-08-15
  • 2022-01-15
  • 2021-08-03
  • 2021-12-27
  • 2021-06-13
  • 2021-10-07
  • 2022-01-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2021-10-11
  • 2021-08-17
相关资源
相似解决方案