python之os、sys和random模块】的更多相关文章

import os # print(os.getcwd())#获取当前目录,绝对路径# print(os.chdir('../'))#更改当前目录,../的意思是退回上一级目录# print(os.getcwd())# print(os.curdir)#当前目录,相对路径# print(os.pardir)#当前目录,相对路径# print(os.mkdir('test0117'))#创建文件夹# print(os.rmdir('test0117'))#删除文件夹,只能删除空文件夹# print…
os模块 # os模块可根据带不带path分为两类 # 不带path print(os.getcwd()) # 得到当前工作目录 print(os.name) # 指定你正在使用的操作系统,windows为nt,linux为“posix" os.shell() # 运行shell命令 print(os.environ) # 返回操作系统所有的环境变量 print(os.getenv("home")) # 读取指定环境变量的值 os.environ.setdefault(&qu…
一.random模块(随机模块) 1.random 常用模块介绍 import random print(random.random()) #返回[0,1)之间的随机浮点数 print(random.randint(2, 4)) #返回一个[2,4]内的随机整数 print(random.choice([1, [20, 23], 66, 4])) #返回可迭代对象中的任意一个元素 print(random.sample([1, [20, 23], 66, 4], 2)) #返回可迭代对象中的任意…
python之sys模块详解 原文:http://www.cnblogs.com/cherishry/p/5725184.html sys模块功能多,我们这里介绍一些比较实用的功能,相信你会喜欢的,和我一起走进python的模块吧! sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传递参数. sys.exit([arg]): 程序中间的退出,arg=0为正常退出. sys.getdefaultencoding(): 获取系统当前编码,一般默认为ascii. sys.setdef…
相当实用的一些API: Ref: https://docs.python.org/3/library/os.html from os import listdir from os.path importimport os import sys 一.获取参数 提取参数 sys.argv[idx]len(sys.argv)  参数检测  如果参数有误:logging.error(...) 不能继续执行,return ERROR_NUMBER 二.如果文件夹存在 删除.重建 if os.path.ex…
1.函数的不固定参数: #参数不是必填的.没有限制参数的个数.返回参数组的元组 def syz(*args): #参数组,不限制参数个数 #‘args’参数的名字可以随便命名 print(args) #username = args[0] #返回的参数放在元组中,通过下标来取值 #pwd = args[1] syz() syz('niuhan','sdfsdf',122) >>> () >>> ('niuhan', 'sdfsdf', 122) #元组 2.关键字参数…
==random 模块== "Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin." - John von Neumann, 1951 ``random`` 模块包含许多随机数生成器. 基本随机数生成器(基于 Wichmann 和 Hill , 1982 的数学运算理论) 可以通过很多方法访问, 如 [Example 2-29 #eg-…
# _author: lily # _date: 2019/1/13 import time import datetime print(help(time)) # print(time.time()) # 1547376144.4092453 时间戳 # time.sleep(3) # print(time.clock()) # print(time.gmtime()) # 结构化时间 time.struct_time(tm_year=2019, tm_mon=1, tm_mday=13, t…
time模块 import time print(help(time)) time.time() #return current time in seconds since the Epoch as a float 时间戳:以秒的形式返回当前时间,从1970年算起 time.clock()  #return CPU time since process start as a float 只计算CPU执行的时间 time.sleep() # delay for a number of second…
os:This module provides a portable way of using operating system dependent functionality. sys:This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. platform:T…