python之路《模块》
1.time模块
FUNCTIONS
asctime(...)
asctime([tuple]) -> string
Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.
When the time tuple is not present, current time as returned by localtime()
is used.
clock(...)
clock() -> floating point number
Return the CPU time or real time since the start of the process or since
the first call to clock(). This has as much precision as the system
records.
ctime(...)
ctime(seconds) -> string
Convert a time in seconds since the Epoch to a string in local time.
This is equivalent to asctime(localtime(seconds)). When the time tuple is
not present, current time as returned by localtime() is used.
get_clock_info(...)
get_clock_info(name: str) -> dict
Get information of the specified clock.
gmtime(...)
gmtime([seconds]) -> (tm_year, tm_mon, tm_mday, tm_hour, tm_min,
tm_sec, tm_wday, tm_yday, tm_isdst)
Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a.
GMT). When 'seconds' is not passed in, convert the current time instead.
If the platform supports the tm_gmtoff and tm_zone, they are available as
attributes only.
localtime(...)
localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,
tm_sec,tm_wday,tm_yday,tm_isdst)
Convert seconds since the Epoch to a time tuple expressing local time.
When 'seconds' is not passed in, convert the current time instead.
mktime(...)
mktime(tuple) -> floating point number
Convert a time tuple in local time to seconds since the Epoch.
Note that mktime(gmtime(0)) will not generally return zero for most
time zones; instead the returned value will either be equal to that
of the timezone or altzone attributes on the time module.
monotonic(...)
monotonic() -> float
Monotonic clock, cannot go backward.
perf_counter(...)
perf_counter() -> float
Performance counter for benchmarking.
process_time(...)
process_time() -> float
Process time for profiling: sum of the kernel and user-space CPU time.
sleep(...)
sleep(seconds)
Delay execution for a given number of seconds. The argument may be
a floating point number for subsecond precision.
strftime(...)
strftime(format[, tuple]) -> string
Convert a time tuple to a string according to a format specification.
See the library reference manual for formatting codes. When the time tuple
is not present, current time as returned by localtime() is used.
Commonly used format codes:
%Y Year with century as a decimal number.
%m Month as a decimal number [01,12].
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%M Minute as a decimal number [00,59].
%S Second as a decimal number [00,61].
%z Time zone offset from UTC.
%a Locale's abbreviated weekday name.
%A Locale's full weekday name.
%b Locale's abbreviated month name.
%B Locale's full month name.
%c Locale's appropriate date and time representation.
%I Hour (12-hour clock) as a decimal number [01,12].
%p Locale's equivalent of either AM or PM.
Other codes may be available on your platform. See documentation for
the C library strftime function.
strptime(...)
strptime(string, format) -> struct_time
Parse a string to a time tuple according to a format specification.
See the library reference manual for formatting codes (same as
strftime()).
Commonly used format codes:
%Y Year with century as a decimal number.
%m Month as a decimal number [01,12].
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%M Minute as a decimal number [00,59].
%S Second as a decimal number [00,61].
%z Time zone offset from UTC.
%a Locale's abbreviated weekday name.
%A Locale's full weekday name.
%b Locale's abbreviated month name.
%B Locale's full month name.
%c Locale's appropriate date and time representation.
%I Hour (12-hour clock) as a decimal number [01,12].
%p Locale's equivalent of either AM or PM.
Other codes may be available on your platform. See documentation for
the C library strftime function.
time(...)
time() -> floating point number
Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.
2.random
详细信息
1 help(random)
我们先分析几个常见的
# 1.随机数0到1之间取
print(random.random())
# 2.随机整数
print(random.randint(0, 2))
# 3.随机整数左闭右开
print(random.randrange(0, 6))
# 随机选值 字符穿数组元组都行
print(random.choice('hello'))
# 规定长度去浮点数
print(random.uniform(0, 9))
# 洗牌功能
name = [1, 2, 3, 4, 5, 6]
random.shuffle(name)
print(name)
现在我将我们学的内容实现一个现实生活的问题
出现随机验证码
check_code = ''
for i in range(0, 4):
temp = random.randrange(0, 4)
if i == temp:
code1 = random.randint(0, 9) # 当i与temp相同时随机数在0到九之间
else:
code1 = chr(random.randint(97, 122)) # 否则就为字母
check_code += str(code1)
print(check_code)
3.os模块
import os
result = os.getcwd()
print(result)
os.chdir('/home/sy')
result = os.getcwd()
print(result)
open('/home/sy/下载/02.txt','w')
result = os.listdir('/home/sy')
print(result)
#os.mkdir('girls')
#os.mkdir('boys',0o777)
#os.makedirs('/home/sy/a/b/c/d')
#os.rmdir('girls')
#os.removedirs('/home/sy/a/b/c/d')
#os.rename('/home/sy/a','/home/sy/alibaba'
#os.rename('02.txt','002.txt')
#result = os.stat('/home/sy/PycharmProject/Python3/10.27/01.py)
#print(result)
#result = os.system('ls -al') #获取隐藏文件
#print(result)
'''
环境变量就是一些命令的集合
操作系统的环境变量就是操作系统在执行系统命令时搜索命令的目录的集合
'''
#getenv() 获取系统的环境变量
result = os.getenv('PATH')
print(result.split(':'))
#os.putenv('PATH','/home/sy/下载')
#os.system('syls')
#curdir 表示当前文件夹 .表示当前文件夹 一般情况下可以省略
print(os.curdir)
print(os.pardir)
#os.mkdir('/home/sy/man1')#绝对路径 从根目录开始查找
print(os.name) #posix -> linux或者unix系统 nt -> window系统
print(os.sep)
print(os.extsep)
print(repr(os.linesep))
import os
path = './boys'#相对
result = os.path.abspath(path)
print(result)
path = '/home/sy/boys'
result = os.path.dirname(path)
print(result)
print(result)
path = '/home/sy/boys'
result = os.path.split(path)
print(result)
var1 = '/home/sy'
var2 = '000.py'
result = os.path.join(var1,var2)
print(result)
path = '/home/sy/000.py'
result = os.path.splitext(path)
print(result)
#path = '/home/sy/000.py'
#result = os.path.getsize(path)
#print(result)
path = '/home/sy/000.py'
result = os.path.isfile(path)
print(result)
result = os.path.isdir(path)
print(result)
path = '/initrd.img.old'
result = os.path.islink(path)
print(result)
#getmtime() 获取文件的修改时间 get modify time
#getatime() 获取文件的访问时间 get active time
print(time.ctime(result))
print(time.ctime(result))
print(time.ctime(result))
filepath = '/home/sy/下载/chls'
result = os.path.exists(filepath)
print(result)
path = '/boys'
result = os.path.isabs(path)
print(result)
path1 = '/home/sy/下载/001'
path2 = '../../../下载/001'
result = os.path.samefile(path1,path2)
print(result)
#os.environ 用于获取和设置系统环境变量的内置值
import os
#获取系统环境变量 getenv() 效果
print(os.environ['PATH'])
os.environ['PATH'] += ':/home/sy/下载'
os.system('chls')
python之路《模块》的更多相关文章
- Python之路【第一篇】python基础
一.python开发 1.开发: 1)高级语言:python .Java .PHP. C# Go ruby c++ ===>字节码 2)低级语言:c .汇编 2.语言之间的对比: 1)py ...
- Python之路
Python学习之路 第一天 Python之路,Day1 - Python基础1介绍.基本语法.流程控制 第一天作业第二天 Python之路,Day2 - Pytho ...
- python之路 目录
目录 python python_基础总结1 python由来 字符编码 注释 pyc文件 python变量 导入模块 获取用户输入 流程控制if while python 基础2 编码转换 pych ...
- Python之路【第十九篇】:爬虫
Python之路[第十九篇]:爬虫 网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本.另外一些不常使用 ...
- Python之路【第十八篇】:Web框架们
Python之路[第十八篇]:Web框架们 Python的WEB框架 Bottle Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除了Pytho ...
- Python之路【第十七篇】:Django【进阶篇 】
Python之路[第十七篇]:Django[进阶篇 ] Model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接 ...
- Python之路【第十六篇】:Django【基础篇】
Python之路[第十六篇]:Django[基础篇] Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了O ...
- Python之路【第十五篇】:Web框架
Python之路[第十五篇]:Web框架 Web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. 1 2 3 4 5 6 ...
- Python之路【第九篇】:Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy
Python之路[第九篇]:Python操作 RabbitMQ.Redis.Memcache.SQLAlchemy Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用 ...
- Python之路【第八篇】:堡垒机实例以及数据库操作
Python之路[第八篇]:堡垒机实例以及数据库操作 堡垒机前戏 开发堡垒机之前,先来学习Python的paramiko模块,该模块机遇SSH用于连接远程服务器并执行相关操作 SSHClient ...
随机推荐
- 机器学习:集成学习:随机森林.GBDT
集成学习(Ensemble Learning) 集成学习的思想是将若干个学习器(分类器&回归器)组合之后产生一个新学习器.弱分类器(weak learner)指那些分类准确率只稍微好于随机猜测 ...
- Helium文档13-WebUI自动化-helium快速切换到selenium状态并调用其方法
前言 前面说过helium是对Selenium 进行了封装,那么我们如何使用selenium的方法呢,通过下面的介绍,我们能够清楚在helium中能够使用selenium的任何方法 入参介绍 def ...
- vue知识点12
知识点归纳整理如下: 1. 数组用下标改变,或者对象增加属性,这样的改变数据 是不能触发视图更新的,要用 Vue.set(对象,属性,值) 或this.$set(对象,属性,值) 2. this. ...
- CDH+Kylin三部曲之一:准备工作
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- 使用PL/SQL Developer 学习pl/sql
1.创建表并且插入一些数据 (这里表名为test): 2. New 一个SQL Window敲下如下代码(--为注释部分): declare --declare:用于plsql中的声明变量,和be ...
- oracle 1day
1.主流数据库: 2.项目选择数据库的原则: 3.oracle 常用用户sys (sysdba系统管理员),system(sysoper系统操作员),scott(密码tiger) sys login: ...
- abp(net core)+easyui+efcore实现仓储管理系统——出库管理之三(五十二)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统--ABP总体介绍(一) abp(net core)+ ...
- java-try catch中return在finally之前 还是之后执行
finally语句在return语句执行之后return返回之前执行的. finally块中的return语句会覆盖try块中的return返回. 如果finally语句中没有return语句覆盖返回 ...
- Mybatis---02Mybatis执行过程分析
1.在动态代理中,执行MapperMethod类里面的execute方法,这个方法里面最终是调用DefaultSqlSession类中的相关操作方法.接着之前的文章继续,在DefaultSqlSess ...
- 在阿里云Ubuntu 14.04.5 LTS下安装nethogs0.8.5
由于默认安装的nethogs不能使用,提示:Creating socket failed while establishing local IP - are you root? 搜索资料后检查当前版本 ...