随笔分类 -  Python

摘要:概念: · 面向过程:根据业务逻辑从上到下写垒代码 · 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 · 面向对象:对函数进行分类和封装,让开发“更快更好更强...” 面向过程编程最易被初学者接受,其往往用一长段代码来实现指定功能,开发过程中最常见的操作就是粘贴复制,即:将之 阅读全文
posted @ 2018-02-11 22:27 hhjwqh 阅读(240) 评论(0) 推荐(0) 编辑
摘要:#!/usr/bin/env python# -*- coding: utf-8 -*-import logging#创建日志对像logger=logging.getLogger("TEST-LOG")logger.setLevel(logging.ERROR) #日志级别#创建日志输出到屏幕及设置 阅读全文
posted @ 2018-02-11 08:09 hhjwqh 阅读(364) 评论(0) 推荐(0) 编辑
摘要:基本用法下面的代码展示了logging最基本的用法。 # -*- coding: utf-8 -*- import logging import sys # 获取logger实例,如果参数为空则返回root logger logger = logging.getLogger("AppName") # 阅读全文
posted @ 2018-02-10 23:38 hhjwqh 阅读(206) 评论(0) 推荐(0) 编辑
摘要:subprocess – 创建附加进程 subprocess模块提供了一种一致的方法来创建和处理附加进程,与标准库中的其它模块相比,提供了一个更高级的接口。用于替换如下模块: os.system() , os.spawnv() , os和popen2模块中的popen()函数,以及 commands 阅读全文
posted @ 2018-02-10 23:10 hhjwqh 阅读(239) 评论(0) 推荐(0) 编辑
摘要:简介: 用于加密相关的操作,代替了md5模块和sha模块,主要提供SHA1,SHA224,SHA256,SHA384,SHA512,MD5算法。 在python3中已经废弃了md5和sha模块,简单说明下md5和sha的使用。 什么是摘要算法呢? 摘要算法又称为哈希算法,散列算法。它通过一个函数,把 阅读全文
posted @ 2018-02-10 22:03 hhjwqh 阅读(339) 评论(0) 推荐(0) 编辑
摘要:#!/usr/bin/env python# -*- coding: utf-8 -*-import refile= open("cs.py","r",encoding = 'utf-8')lines=file.readlines()file.close()strinfo = re.compile( 阅读全文
posted @ 2018-02-10 20:08 hhjwqh 阅读(137) 评论(0) 推荐(0) 编辑
摘要:以下代码以Python3.6.1为例 Less is more! configparser 可以读写和解析注释文件, 但是没有写入注释的功能 1 #!/usr/bin/env python 2 # coding=utf-8 3 __author__ = 'Luzhuo' 4 __date__ = ' 阅读全文
posted @ 2018-02-10 17:58 hhjwqh 阅读(200) 评论(0) 推荐(0) 编辑
摘要:XML 例子: # -*- encoding:utf-8 -*- import requests from xml.etree import ElementTree as ET f = requests.get('http://www.webxml.com.cn/WebServices/Weathe 阅读全文
posted @ 2018-02-09 20:32 hhjwqh 阅读(267) 评论(0) 推荐(0) 编辑
摘要:在Python中Shelve模块提供了基本的存储操作,Shelve中的open函数在调用的时候返回一个shelf对象,通过该对象可以存储内容,即像操作字典一样进行存储操作。当在该对象中查找元素时,对象会根据已经存储的版本进行重新构建,当给某个键赋值的时候,元素会被存储。如下: >>> import 阅读全文
posted @ 2018-02-08 22:25 hhjwqh 阅读(142) 评论(0) 推荐(0) 编辑
摘要:一. 简介 shutil 是高级的文件,文件夹,压缩包处理模块。 二. 使用 shutil.copyfileobj(fsrc, fdst[, length])将文件内容拷贝到另一个文件中 123import shutil shutil.copyfileobj(open('old.xml','r'), 阅读全文
posted @ 2018-02-07 20:13 hhjwqh 阅读(149) 评论(0) 推荐(0) 编辑
摘要:sys模块功能多,我们这里介绍一些比较实用的功能,相信你会喜欢的,和我一起走进python的模块吧! sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传递参数。 sys.exit([arg]): 程序中间的退出,arg=0为正常退出。 sys.getdefaultencoding( 阅读全文
posted @ 2018-02-07 20:06 hhjwqh 阅读(141) 评论(0) 推荐(0) 编辑
摘要:在使用os模块时需要先 import os 引入模块 os.getcwd()模块函数 功能:获取当前工作目录,即当前python脚本工作的目录路径【无参】 使用方法:os.getcwd() 格式如:a = os.getcwd() #!/usr/bin/env python # -*- coding: 阅读全文
posted @ 2018-02-07 20:01 hhjwqh 阅读(209) 评论(0) 推荐(0) 编辑
摘要:#!/usr/bin/env python# -*- coding: utf-8 -*-import json,pickle#pickle写入# f=open("user.txt","wb")# info={# "hhj":"123",# "wqh":"345",# "wqh1":"5552"# } 阅读全文
posted @ 2018-02-06 23:53 hhjwqh 阅读(143) 评论(0) 推荐(0) 编辑
摘要:#!/usr/bin/env python # -*- coding: utf-8 -*- data=[25,18,20,90,74,76,79,80,95,150,192,144]#方法一# j=1# while j<len(data):# for i in range(len(data)-j): 阅读全文
posted @ 2018-02-05 21:10 hhjwqh 阅读(122) 评论(0) 推荐(0) 编辑
摘要:一、简介 正则表达式本身是一种小型的、高度专业化的编程语言,而在python中,通过内嵌集成re模块,程序媛们可以直接调用来实现正则匹配。正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引擎执行。 二、正则表达式中常用的字符含义 1、普通字符和11个元字符: 匹配自身 abc abc . 阅读全文
posted @ 2018-02-04 22:57 hhjwqh 阅读(169) 评论(0) 推荐(0) 编辑
摘要:#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2018-01-15 20:40# @Author : hhj# @Site :一、计算器一import redef operator_update(formula): # 对formula公 阅读全文
posted @ 2018-02-04 18:50 hhjwqh 阅读(290) 评论(0) 推荐(0) 编辑
摘要:#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2018-01-15 20:40# @Author : hhj# @Site :## [0, 1, 2, 3, 4]# [0, 1, 2, 3, 4]# [0, 1, 2, 3, 4]# [0 阅读全文
posted @ 2018-02-01 23:29 hhjwqh 阅读(344) 评论(0) 推荐(0) 编辑
摘要:通过递归实现斐波那契数列 阅读全文
posted @ 2018-01-31 21:22 hhjwqh 阅读(264) 评论(0) 推荐(0) 编辑
摘要:1、必备 #### 第一波 #### def foo(): print 'foo' foo #表示是函数 foo() #表示执行foo函数 #### 第二波 #### def foo(): print 'foo' foo = lambda x: x + 1 foo() # 执行下面的lambda表达 阅读全文
posted @ 2018-01-29 20:45 hhjwqh 阅读(123) 评论(0) 推荐(0) 编辑
摘要:#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018-01-22 22:09 # @Author : hhj# @Site : # @File : def cash_money(amount): while amount>0 amo 阅读全文
posted @ 2018-01-22 22:37 hhjwqh 阅读(108) 评论(0) 推荐(0) 编辑

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