Python入门-模块1(模块导入与time模块)
---恢复内容开始---
模块
一、模块分类:
模块分为三种:
1、内置模块:Python自带的标准模块(可使用help('modules’)查看Python自带模块列表)
2、第三方开源模块:可以通过pip install xxxx(或python3 -m pip install xxxx)联网安装
3、自定义模块
二、模块调用:
几种常用的模块调用方式
1、import modules
2、from modules import xx
3、from modules.xx.xx import xx as rename
4、from modules.xx.xx import *
注:模块一旦被调用,相当于执行了另外一个.py文件里的代码
三、包
当模块文件较多时,需要将模块进行划分。比如将相同类型的,如数据库相关的放一个文件夹中,像这种管理多个模块的文件夹,我们称之为包
包就是文件夹,但该文件夹下必须存在一个__init__.py的文件,该文件可以为空,但必须存在。
四、time模块
1、导入模块:
>>> import time
>>> time.time()
1523537181.252901
2、time模块
a time.localtime() #将一个时间戳转换为当前时区的struct_time。secs参数未提供,则以当前时间为准。
>>> time.localtime()
time.struct_time(tm_year=2018, tm_mon=4, tm_mday=12, tm_hour=20, tm_min=48, tm_s
ec=38, tm_wday=3, tm_yday=102, tm_isdst=0)
索引(Inde属性(Attribute) 值(Values)
0 tm_year(年) 比如2011
1 tm_mon(月) 1 - 12
2 tm_mday(日) 1 - 31
3 tm_hour(时) 0 - 23
4 tm_min(分) 0 - 59
5 tm_sec(秒) 0 - 61
6 tm_wday(weekday) 0 - 6(0表示周日)
7 tm_yday(一年中的第几天)1 - 366
8 tm_isdst(是否是夏令时) 默认为-1
b time.time() #可以带时间戳参数 也不带。不带时以当前时间为准
>>> time.time()
1523537181.252901
c time.mktime() #将一个struct_time转化为时间戳
>>> time.localtime()
time.struct_time(tm_year=2018, tm_mon=4, tm_mday=12, tm_hour=20, tm_min=48, tm_s
ec=38, tm_wday=3, tm_yday=102, tm_isdst=0)
>>> a = time.localtime()
>>> time.mktime(a)
1523537567.0
d time.strftime() #将struct_time转为格式化时间格式输出
>>> time.strftime('%Y-%m-%d %H:%M:%S')
'2018-04-12 21:01:40'
字符串转时间格式对应表
Meaning Notes
%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.
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%I Hour (12-hour clock) as a decimal number [01,12].
%j Day of the year as a decimal number [001,366].
%m Month as a decimal number [01,12].
%M Minute as a decimal number [00,59].
%p Locale’s equivalent of either AM or PM. (1)
%S Second as a decimal number [00,61]. (2)
%U Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0. (3)
%w Weekday as a decimal number [0(Sunday),6].
%W Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. (3)
%x Locale’s appropriate date representation.
%X Locale’s appropriate time representation.
%y Year without century as a decimal number [00,99].
%Y Year with century as a decimal number.
%z Time zone offset indicating a positive or negative time difference from UTC/GMT of the form +HHMM or -HHMM, where H represents decimal hour digits and M represents decimal minute digits [-23:59, +23:59].
%Z Time zone name (no characters if no time zone exists).
%% A literal '%' character.
e time.strptime() #time.strftime的逆操作
>>> time.strptime('2018-04-12 21:01:40','%Y-%m-%d %H:%M:%S')
time.struct_time(tm_year=2018, tm_mon=4, tm_mday=12, tm_hour=21, tm_min=1, tm_se
c=40, tm_wday=3, tm_yday=102, tm_isdst=-1)
f 时间戳与格式化日期转换关系图

Python入门-模块1(模块导入与time模块)的更多相关文章
- Python入门-import导入模块功能
1.啥是模块 模块(module):用来实现或者多个功能的Python代码,(包含变量.函数.类),本质就是*.py后缀文件. 包(package):定义了一个由模块和子包组成的Python应用程序执 ...
- Python入门 模块
module 模块 atestmodule.py #!/usr/bin/env python3 # -*- coding: utf-8 -*- 'a test module' def addFunc( ...
- day15 十五、模块、from导入、起别名
一.模块的概念 1.什么是模块:一系列功能的集合体 2.定义模块:创建一个py文件就是一个模块,该py文件名就是模块名 模块的四种存在方式 使用python编写的.py文件 包:一堆py文件的集合体 ...
- python 常用模块(一): random , time , sys , os模块部分知识.
1.常用模块:(1)collectiaons模块 (2)与时间相关 time模块 (3)random模块 (4)os模块 (5)sys模块 (6) 序列化模块: json , pickle 2 ...
- python 入门学习---模块导入三种方式及中文凝视
Python 有三种模块导入函数 1. 使用import 导入模块 import modname : 模块是指一个能够交互使用,或者从还有一Python 程序訪问的代码段.仅仅要导入了一个模块,就能够 ...
- python入门20 导入模块(引包)
1 引包: import module 或 import module.module1 或 from module import module1,module2...等 2 import xx ...
- python小白入门之导入指定的模块
在python中导入模块是通过关键字import进行导入的,下面演示一下,模块的导入,指定模块别名,指定函数别名,调用模块中所有的函数运行结果: 1.模块的导入Study.py文件里面的内容是:形式 ...
- Python 入门之 模块
Python 入门之 模块 1.模块 (1)模块是什么? 将一些常用的功能封装到一个文件中,那么这个存储着很多常用的功能的py文件,就是模块. 模块就是文件,存放一堆常用的函数.模块,就是一些常用 ...
- Python入门笔记(23):模块
一.模块基础 1.模块 自我包含,且有组织的代码片段就是模块 模块是Pyhon最高级别的程序组织单元,它将程序代码和数据封装起来以便重用.实际的角度,模块往往对应Python程序文件. 每个文件都是一 ...
随机推荐
- 术语CDATA,其实可以理解为一种特殊的转移字符
参考:http://www.w3school.com.cn/xml/xml_cdata.asp 常见于XML文档,所有 XML 文档中的文本均会被解析器解析. 只有 CDATA 区段(Charact ...
- px、pt和em的区别
(转载)http://www.1z1b.com/one-blog-a-week/px-em-pt/ 这里引用的是Jorux的“95%的中国网站需要重写CSS”的文章,题目有点吓人,但是确实是现在国内网 ...
- 简单canvas刮刮乐
好久没玩canvas了,随便写点效果玩玩.要开始重新拾起这门牛x的技术了,工作中不一定能用得上,以后说不定就能发挥用处了. <!DOCTYPE html> <html lang=&q ...
- SSL编程(1) 概述
文章来自本园马若望 SSL是TCP/IP环境上的标准的安全加密传输协议.SSL的全称是安全的 Socket层,它具有与Socket类似的客户端/服务器体制.常见的https即http+ssl,从安全的 ...
- 在PHP中使用MySQL Mysqli操作数据库 ,以及类操作方法
先来操作函数部分,普遍的MySQL 函数方法,但随着PHP5的发展,有些函数使用的要求加重了,有些则将废弃不用,有些则参数必填... ================================= ...
- webbrowser在html中写入内容并添加js
在html中写入内容,并添加js private void btnTestJs_Click(object sender, EventArgs e) { this.webBrowser1.Navigat ...
- dev中ASPxListBox单选和多选的设置
只需要设置SelectionMode,为Multiple时是单选,CheckColumn时是多选
- SpringBoot整合mybatis-plus入门
pom.xml中加入如下依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>myba ...
- vue setTimeout--延迟操作
有时候我们在查询后要做某些事情,例如我查询的时候要根据某个值再去查询某些东西并和这些值一起显示的时候,我们可以对渲染数据的操作进行延迟,因为代码执行的速度是很快的而访问数据的操作相对于渲染的速度慢得多 ...
- oracle数据库逐步学习总结【基础二】
原创作品,转载请在文字开头明显位置注明出处:https://www.cnblogs.com/sunshine5683/p/10067872.html 接着上一篇,继续总结! 五.oracle表管理 首 ...