python chapter2 数据类型及模块 1 os模块

# -*- coding:utf-8 -*-
# -Author: Paulliam -

import os

cmd_result = os.system("dir")   #执行命令后,并不能保存结果
print("the value is:",cmd_result)  #打印命令执行后的返回结果
print("-----------------------------------------")

cmd_result = os.popen("dir")  #执行命令后,cmd_result的值只是一个对象的地址,这个对象正是一个命令执行的结果
print("the value is:",cmd_result)
print("-----------------------------------------")

cmd_result = os.popen("dir").read()  #执行命令后,能够保存结果,并将结果赋值给cmd_result
print("the value is:",cmd_result)  #打印命令执行后保存的结果

######运行结果:

"D:\Program Files\python-3.6.4\python.exe" C:/Users/Administrator/Desktop/python-prj/sys.py
 ������ C �еľ�û�б�ǩ��
 ������к��� 3C69-84C5


 C:\Users\Administrator\Desktop\python-prj ��Ŀ¼


2018/02/26  21:55    <DIR>          .
2018/02/26  21:55    <DIR>          ..
2018/02/26  21:55    <DIR>          .idea
2018/02/11  18:59               423 coding.py
2018/02/25  14:26               205 continue.py
2018/02/25  13:30               196 for double.py
2018/02/25  14:43               971 guess for.py
2018/02/23  22:05               553 guess.py
2018/02/25  14:36             1,002 guess1.py
2018/02/11  20:04               520 interaction.py
2018/02/22  11:36               839 interaction1.py
2018/02/23  22:24               634 passwd.py
2018/02/26  21:55               888 sys.py
2018/02/23  21:37               231 while.py
2018/02/25  12:43               228 while1-for.py
              12 ���ļ�          6,690 �ֽ�
               3 ��Ŀ¼ 100,031,672,320 �����ֽ�
the value is: 0
-----------------------------------------
the value is: <os._wrap_close object at 0x014024D0>
-----------------------------------------
the value is:  驱动器 C 中的卷没有标签。
 卷的序列号是 3C69-84C5


 C:\Users\Administrator\Desktop\python-prj 的目录


2018/02/26  21:55    <DIR>          .
2018/02/26  21:55    <DIR>          ..
2018/02/26  21:55    <DIR>          .idea
2018/02/11  18:59               423 coding.py
2018/02/25  14:26               205 continue.py
2018/02/25  13:30               196 for double.py
2018/02/25  14:43               971 guess for.py
2018/02/23  22:05               553 guess.py
2018/02/25  14:36             1,002 guess1.py
2018/02/11  20:04               520 interaction.py
2018/02/22  11:36               839 interaction1.py
2018/02/23  22:24               634 passwd.py
2018/02/26  21:55               888 sys.py
2018/02/23  21:37               231 while.py
2018/02/25  12:43               228 while1-for.py
              12 个文件          6,690 字节
               3 个目录 100,031,672,320 可用字节




Process finished with exit code 0


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值