Command Line 3

本文介绍如何创建Python脚本,包括设置文件、添加运行所需的代码,并使用Python 2或Python 3来调用脚本。此外还讨论了在处理多个需要不同Python版本的项目时使用虚拟环境的重要性。

Python Script:

1. Add some lines into a blank file: 

  echo "hello world" >> text.txt.

  Everytime before create a script file. we have some steps:

  a. Create a .script file by using mkdir text.script

  b. add some lines into the script to make sure the file is allowed to run under the shell:

    echo 'if __name__ == "__main__":\n    print("Welcome to a Python script")' > script.py # here we are using single bracket on each side of echo word.Pay attention that there are four space before print.

    

2.  We can use python2 to call the script:

  python text.script 

   Or use python3 to call the script:

  python3 text.script 

  Here, we can use python3 or python2 to call the script. But sometimes, if several project want to call a same library in different version. 

3.  Why we want to use virtual environment:

  

 So if we use virtual environment:

    

 

    

转载于:https://www.cnblogs.com/kingoscar/p/6021627.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值