在Linux命令行执行python命令

时间:2022-04-26 06:13:41

在Linux的命令行执行python的某些命令:

[root@centos7 ~]# echo "import sys ;print(sys.path)"|python3.6
['', '/usr/local/python3.6.6/lib/python36.zip', '/usr/local/python3.6.6/lib/python3.6', '/usr/local/python3.6.6/lib/python3.6/lib-dynload', '/usr/local/python3.6.6/lib/python3.6/site-packages']

获取系统的时间和时区

import time
>>> time.strftime('%Y-%m-%d--%H:%M:%S %Z',time.localtime(time.time()))
'2019-04-23--10:37:13 CST'