---恢复内容开始---

模块

一、模块分类:

模块分为三种:

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模块)的更多相关文章

  1. Python入门-import导入模块功能

    1.啥是模块 模块(module):用来实现或者多个功能的Python代码,(包含变量.函数.类),本质就是*.py后缀文件. 包(package):定义了一个由模块和子包组成的Python应用程序执 ...

  2. Python入门 模块

    module 模块 atestmodule.py #!/usr/bin/env python3 # -*- coding: utf-8 -*- 'a test module' def addFunc( ...

  3. day15 十五、模块、from导入、起别名

    一.模块的概念 1.什么是模块:一系列功能的集合体 2.定义模块:创建一个py文件就是一个模块,该py文件名就是模块名 模块的四种存在方式 使用python编写的.py文件 包:一堆py文件的集合体 ...

  4. python 常用模块(一): random , time , sys , os模块部分知识.

    1.常用模块:(1)collectiaons模块 (2)与时间相关  time模块 (3)random模块 (4)os模块 (5)sys模块 (6) 序列化模块: json  ,   pickle 2 ...

  5. python 入门学习---模块导入三种方式及中文凝视

    Python 有三种模块导入函数 1. 使用import 导入模块 import modname : 模块是指一个能够交互使用,或者从还有一Python 程序訪问的代码段.仅仅要导入了一个模块,就能够 ...

  6. python入门20 导入模块(引包)

    1 引包: import module  或  import module.module1  或 from module import module1,module2...等 2 import xx ...

  7. python小白入门之导入指定的模块

    在python中导入模块是通过关键字import进行导入的,下面演示一下,模块的导入,指定模块别名,指定函数别名,调用模块中所有的函数运行结果:  1.模块的导入Study.py文件里面的内容是:形式 ...

  8. Python 入门之 模块

    Python 入门之 模块 1.模块 (1)模块是什么? ​ 将一些常用的功能封装到一个文件中,那么这个存储着很多常用的功能的py文件,就是模块. 模块就是文件,存放一堆常用的函数.模块,就是一些常用 ...

  9. Python入门笔记(23):模块

    一.模块基础 1.模块 自我包含,且有组织的代码片段就是模块 模块是Pyhon最高级别的程序组织单元,它将程序代码和数据封装起来以便重用.实际的角度,模块往往对应Python程序文件. 每个文件都是一 ...

随机推荐

  1. 面试题27:单链表向右旋转k个节点

    Given a list, rotate the list to the right by kplaces, where k is non-negative. For example:Given1-& ...

  2. Pipenv——最好用的python虚拟环境和包管理工具

    pipenv 是Kenneth Reitz大神的作品,能够有效管理Python多个环境,各种包.过去我们一般用virtualenv搭建虚拟环境,管理python版本,但是跨平台的使用不太一致,且有时候 ...

  3. import.html 页面导出execl

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. golang基础--reflect反射

    反射的知识点比较晦涩,后期会对此知识点展开深入的分析及示例代码展示 反射可达大提高程序的灵活性,使得inferface{}有更大的发挥余地 反射使用TypeOf和ValueOf函数从接口中获取目标对象 ...

  5. [android] 手机卫士接收打电话广播显示号码归属地

    使用广播接收者接收打电话的意图,显示号码归属地 新建一个类OutCallReceiver继承系统的BroadcastReceiver 重写onReceive()方法 调用getResultData() ...

  6. 【原】Redis实现生成自增流水号

    场景: 公司内部有个业务场景是后台审核之后需要生成一个流水号,规则是: 201807280001,201807280002,201807280003,后面四位依次递增,前面年月日取当前时间并且转换成y ...

  7. 【读】为什么BIO效率低下

    原因: 假如有10000个连接,4核CPU ,那么bio 就需要一万个线程,而nio大概就需要5个线程(一个接收请求,四个处理请求).如果这10000个连接同时请求,那么bio就有10000个线程抢四 ...

  8. 安装SQL SEVER 2017 express 轻量入门级软件 安装教程

    1. 首先 打开网址   https://www.microsoft.com/zh-tw/sql-server/sql-server-downloads     点击下载 , 下载完成之后, 点开安装 ...

  9. vscode 支持es6语法

    在首选项中 设置: "jshint.enable": false, 在根目录中建立eslintrc.yml parser: babel-eslint parserOptions: ...

  10. Node.js从入门到实战ECMAScript6一页纸总结(很大的一页纸)

    一.ES5/ES6和babel ECMAScript5,即ES5,是ECMAScript的第五次修订,于2009年完成标准化,现在的浏览器已经相当于完全实现了这个标准.ECMAScript6,即ES6 ...