自动化测试学习 python学习第五天

今天学习的是python中模块的引用也就是 import
主要包括以下模块
sys os time
time

if __name__ == '__main__':
    # 自1970年1月1日零食零分零秒到现在经过的秒数
    # 时间戳
    t = time.time()
    # print time.localtime()[0]
    # 根据本地时区转换成类似元组格式的对象
    lt1 = time.localtime(t)
    lt2 = time.localtime()
    print lt1
    print lt2

    # 返回一个固定格式的表示时间的字符串
    # at = time.asctime(lt2)
    at = time.asctime()
    print type(at)
    print at

    # sleep()  使进程休眠,单位秒
    time.sleep(3.5)

    # strftime(format, p_tuple) 返回一个指定格式的时间字符串
    # format 指定格式
    # p_tuple 指定时间元组(localtime的返回值),默认转换当前时间
    print time.strftime('%a %A %b %B %Y-%m-%d %H:%M:%S', lt2)
    print time.strftime('%a %A %b %B %Y-%m-%d %H:%M:%S')

os

if __name__ == '__main__':
    # operating system
    # getcwd() 获取当前进程的当前进程的工作目录
    print os.getcwd()
    # chdir() 切换进程的工作目录
    os.chdir(r'E:\tmp')
    print os.getcwd()

    # 相对路径   test\abc.txt   .\test\abc.txt  ..\test\abc.txt
    # 绝对路径: 从盘符开始的路径  D:\tmp\test\abc.txt
    # open(r'.\test.txt', 'w').close()
    # open(r'..\test.txt', 'w').close()

    # mkdir() 创建目录
    # os.mkdir(r'E:\tmp\abc')
    # os.mkdir(r'abc')

    # 重命名文件或目录
    # os.rename('abc', 'test123')
    # os.rename('test.txt', 'test123.txt')

    # 删除文件
    # os.remove('test123.txt')
    # 删除空目录
    # os.rmdir('test123')

    # 删除目录
    # shutil.rmtree('test')

    # 判断文件是否存在
    print os.path.isfile(r'D:\123.txt')
    print os.path.isfile(r'D:\tool')
    print '----------------------------'
    # 判断目录是否存在
    print os.path.isdir(r'D:\tool')
    print os.path.isdir(r'D:\tool123')
    print '----------------------------'
    # 判断目录或目录是否存在
    print os.path.exists(r'D:\tool')
    print os.path.exists(r'D:\test.txt')
    print os.path.exists(r'D:\tes')

    # 拼接路径
    print os.path.join(r'D:\tmp', r'test\abc.txt')
    print os.path.join(r'tmp', r'test\abc.txt')

    # 路径分割: D:\tmp\test\abc ---> (D:\tmp\test, abc)
    print os.path.split(r'D:\tmp\test\abc')
    print os.path.basename(r'D:\tmp\test\abc')
    print os.path.dirname(r'D:\tmp\test\abc')
    # 返回绝对路径
    print os.path.abspath(r'..\abc.txt')
    print os.path.abspath(r'.\abc.txt')

    # 操作系统名字
    print os.name

sys

import sys



if __name__ == '__main__':
    # sys.path 路径列表,模块搜索路径(import 时搜索模块的路径)
    # sys.path.append(r'..\day4')
    # import newmod
    paths = sys.path
    print paths
    for path in paths:
        print path


    print '--------------------------'
    print sys.modules
    for m in sys.modules:
        print '%-15s---'%m,sys.modules[m]
import sys
import os

if __name__ == '__main__':
    # 参数列表(在执行程序时给程序传递参数)
    # print sys.argv
    # os.mkdir(sys.argv[1])
    sys.argv.pop(0)
    for arg in sys.argv:
        os.mkdir(arg)

    print "你会看到这行"
    # 结束进程
    # sys.exit(1)
    # sys.exit('异常啦啊啊啊啊啊啊啊啊啊啊啊啊啊啊')
    print "你不会看到这行"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值