摘要: # configparser 生成 import configparser config = configparser.ConfigParser() config[DEFUALT] = {'ServerAliveInterval':45, 'Compreassion':'yes', 'Comprea 阅读全文
posted @ 2018-05-23 16:33 python我的最爱 阅读(211) 评论(0) 推荐(0) 编辑
摘要: #创建xml import xml.etree.ElementTree as ET new_xml = ET.Element('namelist') personinfo = ET.SubElement(new_xml, 'personinfo', attrib = {'enroll' :yes}) 阅读全文
posted @ 2018-05-23 14:14 python我的最爱 阅读(207) 评论(0) 推荐(0) 编辑
摘要: import shutil import os f1 = open('本节笔记.txt', encoding = 'utf-8') f2 = open('笔记2', 'w', encoding = 'utf-8') 1.shutil.copyfileobj(f1, f2) #拷贝文件内容 2.shu 阅读全文
posted @ 2018-05-23 13:22 python我的最爱 阅读(614) 评论(0) 推荐(0) 编辑
摘要: 一种字典形式储存数据的方式 import datetime, shelve d = shelve.open('shelve_test.txt') info = {'age':22, 'job':'it') name = ['alex', 'rain', 'test'] d['name'] = nam 阅读全文
posted @ 2018-05-23 12:30 python我的最爱 阅读(129) 评论(0) 推荐(0) 编辑
摘要: import random random.random() #生成0-1的随机浮点数 random.randint(1, 10) #生成1-10的整数 random.randrange(1,10) #生成1-9的整数 random.choice('hello') #随机选择里面的数 ,可以是元组,列 阅读全文
posted @ 2018-05-23 12:18 python我的最爱 阅读(123) 评论(0) 推荐(0) 编辑
摘要: import os 1.os.getcwd() # 获得当前文件路径 2.os.chdir() # 改变当前目录 3.os.curdir # . 表示当前目录 4.os.pardir # 表示上一级目录 5.os.makedirs(r’C:\a\b\c\d‘) #递归的创建文件 6.os.remov 阅读全文
posted @ 2018-05-23 00:05 python我的最爱 阅读(131) 评论(0) 推荐(0) 编辑
摘要: import time print(time.time()) #获得时间戳 1526998642.877814 print(time.sleep(2)) #停止2秒 print(time.gmtime()) # 获得格林尼治时间 time.struct_time(tm_year=2018, tm_m 阅读全文
posted @ 2018-05-22 22:36 python我的最爱 阅读(590) 评论(0) 推荐(0) 编辑
摘要: 1.模块(变量,函数,类,实现一个功能) 包:用来从逻辑上组织模块,本质是一个目录(必须带有__init__.py) 2.导入方法 import module_alex from module_alex import * from modele_alex import logger, running 阅读全文
posted @ 2018-05-22 22:03 python我的最爱 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 1. all([-1, 0, 1]) #判断是否全是不等于0的数 2. any([-1,0,1]) # 有一个数不为0 返回真 any([]) 返回假 3.ascii([1, 2, '开外挂']) #进行ascii 转换 4.bin(1) #十进制转换为二进制 5.bool(1) #判断是否为真 6 阅读全文
posted @ 2018-05-16 22:49 python我的最爱 阅读(141) 评论(0) 推荐(0) 编辑
摘要: json 可以在不同语言中进行使用 下面先介绍一下json的适用方法 pickle 只能在python中使用 json 和 pickle 的语法相同 ,pickle 可以用来传递函数 下面以pickle为例 序列化.py 对于json.dumps 和 json.loads 而言 最好是每次转换只出现 阅读全文
posted @ 2018-05-16 21:48 python我的最爱 阅读(306) 评论(0) 推荐(0) 编辑