python基础操作
模块导入执行系统命令
>>> import os
>>> os.system('df')
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/mapper/centos-root 18307072 6457192 11849880 36% /
devtmpfs 1888204 0 1888204 0% /dev
tmpfs 1898656 140 1898516 1% /dev/shm
tmpfs 1898656 66780 1831876 4% /run
tmpfs 1898656 0 1898656 0% /sys/fs/cgroup
/dev/sda1 508588 136876 371712 27% /boot
tmpfs 379732 32 379700 1% /run/user/0
0
>>> os.system("ss -tln|awk '/22/{print $4}'|awk NR==1")
192.168.122.1:53
0
>>> os.mkdir('/tmp/mark1')
>>> os.system('ls -ld /tmp/mark1')
drwxr-xr-x. 2 root root 6 8月 1 14:54 /tmp/mark1
0
>>>
导入多个模块方法:从sys中之导入argv
>>> from sys import argv
导入多个
>>> from SocketServer import socket,threading
Import别名
>>> import multiprocessing as mul
>>> mul.Pool()
默认python会在默认的地方进行查找文件
>>> import sys
使用sys.path可以看到默认加载文件目录位置
>>> sys.path
Python中注释:注释:
[root@localhost pythonfile]# cat jichu_0801.py
#!/usr/bin/env python
#import os,sys,souesess
''' start
sda
'''
print 'a'
[root@localhost pythonfile]#
注释运行效果:
[root@localhost pythonfile]# python jichu_0801.py
a
[root@localhost pythonfile]#