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

模块

一、模块分类:

模块分为三种:

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. java aop做一个接口耗时的计算

    看代码: @Aspect @Component public class TimeCostAspect { private static Logger logger = LoggerFactory.g ...

  2. Go 编译和runtime

    一篇题为:Analysis of the Go runtime scheduler 的论文,其中部分章节介绍到了Go runtime. 先上图,这张图描述了Go语言程序,Runtime和操作系统之间的 ...

  3. docker 创建tomcat镜像

    Dockerfile ############################################ # version : wenbronk/jdkiu121/tomcat8 # desc ...

  4. leetcode 98,判断二叉树为BST

    方法一,记录子树的上界和下界,root的左子树一定小于root的值,root的右子树一定大于root的值,然后递归左子树和右子树 public class Solution { public bool ...

  5. Django请求响应对象

    请求与响应对象 HttpRequest HttpRequest存储了客户请求的相关参数和一些查询方法. path 请求页面的全路径,不包括域名-例如, "/hello/". met ...

  6. [转]How to Import a Text File into SQL Server 2012

    Importing a using the OpenRowSet() Function The OPENROWSET bulk row set provider is accessed by call ...

  7. WPF备忘录(7)WPF图片资源路径介绍

    在项目中增加两张图片Content.jpg和Resource.jpg,分别将其生成操作属性设置为Content和Resource.     在界面中增加两个Image控件ImgContent和ImgR ...

  8. CLR via C# 读书笔记-26.线程基础

    前言 这俩个月没怎么写文章做记录分享,一直在忙项目上线的事情,但是学习这件事情,停下来就感觉难受,clr线程这章也是反复看了好多遍,书读百遍其义自见,今天我们来聊下线程基础 1.进程是什么,以及线程起 ...

  9. 2 字节的 UTF-8 序列的字节 2 无效 解决方法

    2 字节的 UTF-8 序列的字节 2 无效 解决方法: 用记事本打开xml文件,另存为 编码 选择 UTF-8,保存替换掉之前的文件,解决问题

  10. sgsdg

    wrjow we wetwer werwer werwer werqw qweqwrq qwrqwr @ApiOperation("根据条件分页查询试卷") @ApiRespons ...