一,time模块学习

 import time

# print(int(time.time()))#时间戳
# res = time.strftime('%Y-%m-%d %H:%M:%S')#取当前格式化好的时间
# print(res) #时间戳转换成时间元组,时间戳转格式化好的时间
#time1 = time.gmtime(int(time.time()))#把时间戳转成时间元组,以标准时间的时间转换的
# time1 = time.localtime(int(time.time()))#把时间戳转成时间元组,以标准时间的时间转换的
# res = time.strftime('%Y-%m-%d %H:%M:%S',time1)
# print(res) #格式化好的时间转时间戳 timep = time.strptime('2018-10-23 15:38:59','%Y-%m-%d %H:%M:%S')
print(timep)
res = time.mktime(timep)#把时间元组转成时间戳
print(res)
#20181023 2323
def timestampToStr(timestamp=None,format='%Y-%m-%d %H:%M:%S'):
#时间戳转格式化好的时间
if timestamp:
time1 = time.localtime(timestamp)
res = time.strftime(format, time1)
else:
res = time.strftime(format)
return res
#20180304153958
def strTotimestamp(str=None,format='%Y%m%d%H%M%S'):
#格式化的时间转时间戳
if str:
timep = time.strptime(str, format)
res = time.mktime(timep)
else:
res = time.time()
return int(res) 二,json模块学习
import json
#解析json的

# json_str = '''
# {"name":"xiaohei","age":18,"sex":"男","age":18}
# '''
# res = json.loads(json_str) #把字符串(json串)转成字典
# print(res)
# print(type(json_str))
# print(type(res)) dic = {
"xiaohei":{
"age":18,
"password":12345,
"sex":"男",
"addr":"北京"
},
"马春波":{
"age":18,
"password":12345,
"sex":"男",
"addr":"北京"
},
"王东泽":{
"age":18,
"password":12345,
"sex":"男",
"addr":"北京"
},
}
# res = json.dumps(dic,ensure_ascii=False,indent=4)#把字典变成字符串
# print(res)
# f = open('user.json','w',encoding='utf-8')
# f.write(res) #load 自己读
# f = open('user.json',encoding='utf-8')
# res = json.loads(f.read())
# print(res)
# res = json.load(f)
# print(res) #dump 自己写的
fw = open('newuser.json','w')
json.dump(dic,fw,indent=4,ensure_ascii=False) 三,os模块学习
import os
res = os.listdir('/Users/nhy/Desktop') #列出某个目录下的所有文件
# os.remove()
# os.rename()
# os.mkdir(r'test/niuhy/haha')#创建文件夹
# os.makedirs(r'test1/lyl/aaa')#会创建父目录
# res = os.path.exists(r'/Users/nhy/Desktop/stu.txt')
# os.path.isfile() #判断是否为文件
# os.path.isdir()#判断是否为文件
# res = os.path.split(r'/Users/nhy/Desktop/stu.txt')
# res = os.path.dirname(r'/Users/nhy/Desktop/stu.txt')#取父目录
# res = os.getcwd() #获取当前的目录
# os.chdir(r'/Users/nhy/Desktop/')#更改当前目录
# res = os.getcwd()
# print(res)
# open('a.txt','w')
# print(os.environ)#看你电脑的环境变量
#
# res = os.path.join('test','hhh','abc','a.txt')#拼接路径
# print(res)
# res= os.path.abspath('..')#根据相对路径取绝对路径
# print(res) # res = os.system('hhhsdf')#执行操作系统命令
# # print(res)
# res = os.popen('ifconfig').read()
# print('res',res)

pythone函数基础(7)第三方模块学习的更多相关文章

  1. Day5 - Python基础5 常用模块学习

    Python 之路 Day5 - 常用模块学习   本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shel ...

  2. python语言(四)关键字参数、内置函数、导入第三方模块、OS模块、时间模块

    一.可变参数 定义函数时,有时候我们不确定调用的时候会传递多少个参数(不传参也可以).此时,可用包裹(packing)位置参数(*args),或者包裹关键字参数(**kwargs),来进行参数传递,会 ...

  3. pythone函数基础(15)接口开发初识

    导入需要的第三方模块 import flaskimport toolsimport json,redisimport random server = flask.Flask(__name__)#新建一 ...

  4. pythone函数基础(8)内置函数学习

    内置函数学习# sorted# map# filter# max# sum# round# chr# ord# dir# bool# eval# exec# zipimport mathres = m ...

  5. Python基础5 常用模块学习

    本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 configpars ...

  6. 《C++ Primer Plus》第7章 函数——C++的编程模块 学习笔记

    函数是C++的编程模块.要使用函数,必须提供定义和原型,并调用该函数.函数定义是实现函数功能的代码:函数原型描述了函数的接口:传递给函数的值的书目和种类以及函数的返回类型.函数调用使得程序将参数传递给 ...

  7. pythone函数基础(14)发送邮件

    导入yagmail模块import yagmailusername='uitestp4p@163.com'password='houyafan123'#生成授权码,qq.163.126都是授权码 ma ...

  8. pythone函数基础(13)发送网络请求

    需要导入urllib模块,request模块发送网络请求有两种方法 第一种方法# from urllib.request import urlopen# from urllib.parse impor ...

  9. pythone函数基础(12)连接Redis,写数据,读数据,修改数据

    需要导入Resdis模块 import redisip = '127.0.0.1'password='123456'r = redis.Redis(host=ip,password=password, ...

随机推荐

  1. session token两种登陆方式

    Session 和 Token 其实Session和Token总体上还是很相似的,但是也有以下区别: 1. 过期时间:Session的过期时间存在cookie的Max-age字段,Token的过期时间 ...

  2. jmeter 关联

    (1)正则表达式提取器 注:正则表达式部分配置说明 案例: 动态值:name=userSession value=119828.306682868zVzDzzipfcfDzQicpAVVVf> ...

  3. Dart 学习资料

    Dart 学习资料: 学习资料 网址 Dart 编程语言中文网 http://dart.goodev.org/ Dart 官方包仓库 https://pub.dartlang.org/ 你想了解的Da ...

  4. 迷宫问题bfs, A Knight's Journey(dfs)

    迷宫问题(bfs) POJ - 3984   #include <iostream> #include <queue> #include <stack> #incl ...

  5. ubuntu彻底卸载opencv

    说正事之前,先啰嗦两句背景,算是拿个小本本记下了. 我本打算下载opencv2.4.在github上找到源码,在Branch处选择切换到2.4,然后复制URL,在terminal里面使用git clo ...

  6. windows time-wait 问题处理记录

    问题描述:有一段时间,服务器启动了好多程序,做的是 obd监听服务,连接好多个服务器,由于程序的本身的问题造成大量的wait-time,一番百度后找到找到方案1 设置一由于wait-time 需要经过 ...

  7. 20165312 实验一 Java开发环境的熟悉

    20165312 实验一 Java开发环境的熟悉 一.实验内容及步骤 (一)使用JDK编译.运行简单的Java程序 Ctrl+Shift+T打开终端 输入cd cxgg20165312/test进入目 ...

  8. 知识点:Mysql 基本用法之视图

    视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的临时 ...

  9. 完整安装always on 集群

    1.  四台已安装windows server 2008 r2 系统的虚拟机,配置如下: CPU : 1核 MEMORY : 2GB DISK : 40GB(未分区) NetAdapter : 2块 ...

  10. java中随机二维数组中寻找最大值并输出坐标

    public static void main(String[] args) { int x=0; int y=0; int a[][]=new int[5][5]; int max=-Integer ...