随笔 - 480  文章 - 0 评论 - 45 阅读 - 73万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

05 2018 档案
socket 网络连接基础
摘要:socket 客户端 import socket 1.client = socket.socket() # socket.TCP/IP 选择连接的类型,默认为本地连接 2.client.connect(('localhost', 6000)) # connect(a.ip, a.port) a.ip 阅读全文
posted @ 2018-05-29 11:25 python我的最爱 阅读(210) 评论(0) 推荐(0) 编辑
异常处理(基本语法)
摘要:异常处理中常见的语法 try 尝试运行 except 接受错误 else 正确时执行 finally 不管对错都执行这一步 举例 阅读全文
posted @ 2018-05-28 22:48 python我的最爱 阅读(193) 评论(0) 推荐(0) 编辑
反射(hasattr , getattr, setattr) 输入的字符串用来运行程序
摘要:当用户输入字符串时,不能够用来运行程序 1.使用 hasattr 找出输入的字符串是否在程序内 2.使用 getattr 返回找出字符串对应的函数的内存地址或者变量 3. 使用setattr 添加新的函数,或者改变已有的程序的实例变量或类变量 阅读全文
posted @ 2018-05-28 22:34 python我的最爱 阅读(173) 评论(0) 推荐(0) 编辑
创建类type (底层代码)
摘要:类的创建时是用type 实现的 阅读全文
posted @ 2018-05-28 21:16 python我的最爱 阅读(176) 评论(0) 推荐(0) 编辑
getitem, setitem, delitem (把类实例化成字典的类型)
摘要:class Foo(object): def __init__(self): self.data = {} def __getitem__(self, key): print('__getitem__', key) return self.data.get(key) #返回查找的结果,如果没有返回n 阅读全文
posted @ 2018-05-28 20:56 python我的最爱 阅读(216) 评论(0) 推荐(0) 编辑
类的三种方法(静态方法,类方法,属性方法)
摘要:1.(静态方法) class Dog(object): def __init__(self, name): self.name = name @staticmethod def name(obj): print('%s is name'%obj) Dog.name('ronghua') @stati 阅读全文
posted @ 2018-05-28 19:49 python我的最爱 阅读(1175) 评论(0) 推荐(0) 编辑
class(类的使用说明)
摘要:class 的三大特性 封装:内部调用对于外部用户是透明的 继承: 在分类里的属性,方法被自动继承 多态:调用这个功能,可以使多个类同时执行 r1 = Role(r1, 'Alex', 'Police', '15000') #实际上把r1赋给了self self.name = 'Alex' # r1 阅读全文
posted @ 2018-05-26 17:28 python我的最爱 阅读(1673) 评论(0) 推荐(0) 编辑
re(正则)模块
摘要:import re # re 存在5种使用方式 #1. macth #2.search #3.findall #4.split #5 sub re.match('^chen', 'chenhua123').group() #加.group() 查看查找的内容 re.search('chen+a$', 阅读全文
posted @ 2018-05-23 20:33 python我的最爱 阅读(207) 评论(0) 推荐(0) 编辑
hashlib 加密模块使用说明
摘要:import hashlib #hashilib 模块 m = hashlib.md5() m.update('hello 天王盖地虎'.encode(encoding = 'utf-8)) m.hexdigest() # 显示密码 m = hashlib.sha256() m.update(b'1 阅读全文
posted @ 2018-05-23 17:07 python我的最爱 阅读(151) 评论(0) 推荐(0) 编辑
configparser 文件的生成和读写
摘要:# configparser 生成 import configparser config = configparser.ConfigParser() config[DEFUALT] = {'ServerAliveInterval':45, 'Compreassion':'yes', 'Comprea 阅读全文
posted @ 2018-05-23 16:33 python我的最爱 阅读(211) 评论(0) 推荐(0) 编辑
xml 创建 和 处理 及其修改
摘要:#创建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我的最爱 阅读(210) 评论(0) 推荐(0) 编辑
shutil模块(高级的文件copy)
摘要: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我的最爱 阅读(617) 评论(0) 推荐(0) 编辑
shelve模块使用说明
摘要:一种字典形式储存数据的方式 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我的最爱 阅读(133) 评论(0) 推荐(0) 编辑
random内置模块
摘要: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我的最爱 阅读(124) 评论(0) 推荐(0) 编辑
os内置模块
摘要: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我的最爱 阅读(133) 评论(0) 推荐(0) 编辑
time 时间内置模块3种形态的转化
摘要: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我的最爱 阅读(592) 评论(0) 推荐(0) 编辑
python模块说明
摘要:1.模块(变量,函数,类,实现一个功能) 包:用来从逻辑上组织模块,本质是一个目录(必须带有__init__.py) 2.导入方法 import module_alex from module_alex import * from modele_alex import logger, running 阅读全文
posted @ 2018-05-22 22:03 python我的最爱 阅读(200) 评论(0) 推荐(0) 编辑
python 内置函数
摘要: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我的最爱 阅读(142) 评论(0) 推荐(0) 编辑
序列化和反序列化(json 和pickle)dumps 为序列化, json为反序列化
摘要:json 可以在不同语言中进行使用 下面先介绍一下json的适用方法 pickle 只能在python中使用 json 和 pickle 的语法相同 ,pickle 可以用来传递函数 下面以pickle为例 序列化.py 对于json.dumps 和 json.loads 而言 最好是每次转换只出现 阅读全文
posted @ 2018-05-16 21:48 python我的最爱 阅读(306) 评论(0) 推荐(0) 编辑
迭代器iter()
摘要:from collections import Iterable print(isinstance({},iterable)) # 判断是否可迭代 from collections import Iterator #判断是否是迭代器 instance((x for x in range(5)),It 阅读全文
posted @ 2018-05-16 21:31 python我的最爱 阅读(170) 评论(0) 推荐(0) 编辑
生成器 yield
摘要:1. 生成器 只有在调用时才会生成相应的数据 2 . 只记录当前的位置3 . 只有一个__next__() f = (x for x in range(10)) #一个简单的生成器 print(f.__next__()) 费波纳生成器(举例1) def fib(max): n,a,b = 0, 0, 阅读全文
posted @ 2018-05-16 20:47 python我的最爱 阅读(185) 评论(0) 推荐(0) 编辑
装饰器的解释说明
摘要:高阶函数 + 嵌套函数 =》装饰器 import timedef timer(func): def wrapper(*args, **kwargs): start_time = time.time() func(*args, **kwargs) end_time = time.time() prin 阅读全文
posted @ 2018-05-16 17:56 python我的最爱 阅读(124) 评论(0) 推荐(0) 编辑
面向过程中的局部变量(global)
摘要:1.school = 'oldboy.edu' def change_name(name): school = " Mage Linux" # 局部变量只在函数里生效 print(name, school) name = 'Alex' change_name(name) #先调用 print(sch 阅读全文
posted @ 2018-05-14 16:50 python我的最爱 阅读(144) 评论(0) 推荐(0) 编辑
函数的参数设定
摘要:1.def test(x, y): print(x, y) test(y=1, x=2) test(2 , y=1) #位置参数一定要在关键字参数的前面 def test(x, y, z): print(x, y, z) test(2, z=1, y=2) 2.默认参数 def test(x, y= 阅读全文
posted @ 2018-05-14 16:37 python我的最爱 阅读(172) 评论(0) 推荐(0) 编辑
集合的基本操作
摘要:1. 集合的去重作用 list_1 = [1, 4, 5, 7, 3, 6, 7, 9] list_1 = set(list_1) list2 = set([2, 6, 0, 66, 22, 8, 4]) 2.#交集 intersection list_1.intersection(list_2) 阅读全文
posted @ 2018-05-14 16:06 python我的最爱 阅读(182) 评论(0) 推荐(0) 编辑
文件的基本操作(python)
摘要:文件打开: 1. f = open('yesterday,‘r+’,encoding = ‘utf-8’) 读取的方式加载为Utf-8 r 打开文件并写, 只适用于文字类 r+ 打开文件并读写,文件的指针定位在文件的开始位置;文件不存在就报错 w 打开文件只读操作, 如果文件存在就清空文件,文件不存 阅读全文
posted @ 2018-05-14 14:28 python我的最爱 阅读(215) 评论(0) 推荐(0) 编辑
字典(dictionary) 的基本操作
摘要:info = { ’stu1101‘ : ’xiaoming’, ‘stu1102 : xiahong‘, ’stu1103 : ‘xiaozhi', } 1. 字典的获取 info.get('stu1104',None) # 有就获取,没有就返回None 2. 字典的跟新 b = {'stu110 阅读全文
posted @ 2018-05-11 11:26 python我的最爱 阅读(317) 评论(0) 推荐(0) 编辑
字符串(string) 的基本操作
摘要:name = "my \tname is alex" #\t 空格 1. name.capitalize() #首字母大写 2.name.count('a') # 对字母a计数 3.name.center(50,'-') # 把name 写在中心,不够补齐 4.name.encode('uft-8' 阅读全文
posted @ 2018-05-10 22:29 python我的最爱 阅读(228) 评论(0) 推荐(0) 编辑
列表(list) 的 基本操作
摘要:举例说明:names = ["zhangyang", "guyun", 'xiangpeng', ['alex','jack'], "xuliangcheng"] print(type(names)) 1. list 切片: extract_name = names[0:3] # 切片 顾头不顾尾 阅读全文
posted @ 2018-05-10 21:19 python我的最爱 阅读(284) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示