Chinaunix首页 | 论坛 | 博客
  • 博客访问: 82913
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 250
  • 用 户 组: 普通用户
  • 注册时间: 2015-08-12 22:31
文章分类

全部博文(26)

文章存档

2016年(26)

我的朋友

分类: Python/Ruby

2016-11-15 22:35:12

常用模块初识


os.system(‘cmd’)    #可以执行任何linux下的命令,只会返回执行的值,执行正确一般为0
os.popen(‘cmd’).read()  #返回执行的cmd的执行结果
getpass                #如果输入密码不想让别人看到,可以采用这个模块
举例:
>>> os.system('df')
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root  18650424 8162324   9540696  47% /
tmpfs                           375228      72    375156   1% /dev/shm
/dev/sda1                       495844   34878    435366   8% /boot
0
>>> cmd_re = os.popen('df').read()
>>> print (cmd_re)
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root  18650424 8162324   9540696  47% /
tmpfs                           375228      72    375156   1% /dev/shm
/dev/sda1                       495844   34878    435366   8% /boot

>>> 
>>> passwd = getpass.getpass('please input your password:')
please input your password:
>>> print (passwd)
dsflsdgh





break和continue的区别
break 跳出当前整个循环
continue 只跳出当前此次循环
举例:

点击(此处)折叠或打开
#_*_ coding:utf-8 _*_
a = 64
count = 1
while True:
    count += 1
    if 10 < count < 20:
        continue 
        print ("在10-20之间",count)
    elif count >= 30:
        print ("大于 30 次了",count)
        break
    else:
        print ('小于10',count)

  执行结果如下 :(可以看出没有打印出10-20之间的内容)


小于10 2

小于10 3
小于10 4
小于10 5
小于10 6
小于10 7
小于10 8
小于10 9
小于10 10
小于10 20
小于10 21
小于10 22
小于10 23
小于10 24
小于10 25
小于10 26
小于10 27
小于10 28
小于10 29
大于 30 次了 30










阅读(1176) | 评论(0) | 转发(0) |
0

上一篇:day1-三级菜单

下一篇:shooping_car

给主人留下些什么吧!~~