![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
chpllp
这个作者很懒,什么都没留下…
展开
-
有关Python线程、函数、锁相关的一个程序
#!/usr/bin/python#coding=utf-8#####################################################import requestsimport threadingimport timelist_url = []g_mutex = 0text = "D://127.txt"#f = text.readlines(原创 2017-01-13 15:40:53 · 731 阅读 · 0 评论 -
Python .pyc的编译和反编译
1. 由Python文件编译为.pyc文件python -m compileall test.py 2. .pyc的反编译,使用uncompyle最方便的就是使用pip安装 uncompyle:pip install uncompyleuncompyle6 --help 查看帮助 uncompyle6 models.pyc > models原创 2017-07-28 14:32:22 · 10822 阅读 · 0 评论 -
pdb通过Python调试的一点心得
运行:Python -m pdb test.py(Pdb) 会自动停在第一行,等待调试,这时你可以看看帮助(Pdb) h几个关键命令断点设置(Pdb)b 10 #断点设置在本py的第10行或(Pdb)b ots.py:20 #断点设置到 ots.py第20行删除断点(Pdb)b #查看断点编号(Pdb)cl 2 #删除第2个断点原创 2017-06-29 15:51:57 · 2477 阅读 · 0 评论 -
Python json dumps() && loads()
>>> s={"username":"admin","password":"password","tenantid":""}>>> print s{'username': 'admin', 'password': 'password', 'tenantid': ''}而json是不支持单引号的。可以用下面的方法转换json_string=json.d原创 2017-05-22 17:19:32 · 367 阅读 · 0 评论 -
同一目录下的Python A文件调用Python Bwenjai
hello.py代码如下:# -*- coding: utf-8 -*-#!/usr/bin/env pythondef AA(arg): print (arg)test.py调用hello.py代码如下:# -*- coding: utf-8 -*-#!/usr/bin/env pythonimport helloif __name__ == '__main__':原创 2017-05-18 09:18:38 · 1614 阅读 · 0 评论 -
Python 2.7.13 import urllib.request ImportError: No module named request
import urllib.request提示ImportError: No module named request,我是Python 2.7.13 from urllib import request,提示ImportError: cannot import name requestPython urllib中没有request 这个模块,可以使用 dir(urllib)来原创 2017-05-14 18:26:27 · 3758 阅读 · 1 评论 -
python logging类库中RotatingFileHandler的使用
日志级别大小关系为:CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET,当然也可以自己定义日志级别。日志回滚的意思为:比如日志文件是chat.log,当chat.log达到指定的大小之后,RotatingFileHandler自动把文件改名为chat.log.1。不过,如果chat.log.1已经存在,会先把chat.log.1重命名为chat原创 2017-05-23 16:51:39 · 9065 阅读 · 0 评论 -
python dict.get()和dict['key']的使用
dict['key']只能获取存在的值,如果不存在则触发KeyErrordict.get(key, default=None)则如果不存在则返回一个默认值,如果设置了则是设置的,否则就是None原创 2017-05-23 10:51:06 · 3495 阅读 · 0 评论 -
Python解析IP地址CIDR的形式
方法一: >>> from IPy import IP >>> ip = IP('127.0.0.0/30') >>> for x in ip: ... print(x) ... ##此处回车即可 127.0.0.0 127.0.0.1 127.0.0.2 127.0.0.3方法二:原创 2017-05-12 09:38:20 · 9489 阅读 · 0 评论 -
python第三方库的安装
1. 下载安装包(如beautifulsoup4-4.5.1.tar.gz)DOS下进入解压后的目录beautifulsoup4-4.5.1运行pythonsetup.py build运行pythonsetup.py install原创 2017-05-12 09:22:55 · 409 阅读 · 0 评论 -
c程序调用python脚本,python脚本中的危险分子global变量
情况说明:当c程序循环调用某一特定脚本时,若python脚本中有global变量;例如:脚本中存在global变量,如:global retValue=""脚本中有对retValue的赋值,如:reValue=retValue+result(其中result是有其它函数返回获取到的);问题:在多次调用该python脚本时,每一次得到的结果都是前几次结果的连接;原创 2017-04-01 18:04:58 · 800 阅读 · 0 评论 -
c程序多次调用python脚本的正确打开模式
问题描述:c程序中需要多次调用python脚步;初始做法:每次调用python脚步时,开始初始化python环境(Py_Initialize),调用完之后结束python环境(Py_Finalize();)问题:程序偶然会出现崩溃的现象;c程序多次调用python脚本的正确打开模式如下:1. 在主线程中这样处理 // 初始化 Py_Initia原创 2017-04-01 17:00:19 · 6272 阅读 · 0 评论 -
关于urllib2.urlopen(url)打印长度的问题
无解的两种对比第一种表达request = urllib2.Request(url)urllib2.urlopen(request)print response.read() ###有结果print len(response.read()) ###长度为0第二种表达原创 2017-03-10 16:41:28 · 780 阅读 · 0 评论 -
Python PyImport_ImportModule() 或者 PyImport_Import()失败问题
通过Python PyImport_ImportModule() 或者 PyImport_Import()导入自定义模块时,若不成功有可能是该自定义文件中其实位置import第三方的库没有安装,如requests;原创 2017-02-23 14:37:17 · 15712 阅读 · 1 评论 -
python多线程模块:threading使用方法(参数传递)
转自:http://www.mianfeidianhua.net/threading.html先来看这段代码:import threadingimport timedef worker(): print “worker” time.sleep(1) returnfor i in xrange(5): t = threading.Thr...原创 2017-01-12 19:51:58 · 110739 阅读 · 2 评论 -
python多线程模块:threading使用方法
转自:http://www.mianfeidianhua.net/threading.html先来看这段代码:import threadingimport timedef worker(): print “worker” time.sleep(1) return for i in xrange(5): t = threading.Thread(target=wor转载 2017-01-13 15:58:34 · 463 阅读 · 0 评论 -
Python ---match
print "--------------------------"file = open("html.txt", 'rb')a = reversed(file.readlines())for line in a: ret = re.match('\S\S\S\S\S\S\s\S\s\S\S\s',line,re.I) if ret: print line...原创 2018-11-25 22:40:08 · 773 阅读 · 0 评论