
Python笔记
锤%锤
这个作者很懒,什么都没留下…
展开
-
python读取配置文件
python代码 配置 import ConfigParser class myconf(ConfigParser.ConfigParser): def __init__(self,defaults=None): ConfigParser.ConfigParser.__init__(self,defaults=None) ...原创 2020-04-27 17:43:19 · 274 阅读 · 0 评论 -
python读写文件
1、从文件按行读出,并转为dict格式。注意:下面例子中文件中只有一行。 读 import io import json def FunReadFile(): localDict={} try: with io.open('test.txt', 'r',encoding='utf-8') as f:...原创 2020-04-27 17:23:48 · 248 阅读 · 0 评论 -
Linux下 Python:利用socket.inet_ntoa获取机器网卡IP地址
#!/usr/bin/env python# -*- coding: utf-8 -*-#************************************************************************##Shell Name:#functions:#parameter:#content:#*******************************...原创 2018-07-19 16:50:19 · 1782 阅读 · 0 评论 -
Python:使用MySQLdb.connect出现错误:_mysql_exceptions.OperationalError: (2002,
使用Python脚本连接数据时,遇到以下错误:[root@Joe system]# python test.py File "test.py", line 149, in <module> db=MySQLdb.connect("localhost", "root", "kdc", "nms") File "/usr/lib64/python2.7/原创 2018-07-28 16:35:43 · 4575 阅读 · 0 评论 -
Python学习过程中的问题记录
1、替换文件中的字符串,具体脚本实例(实现目的,将文件中file1中的IP地址改为10.10.10.10)#! /usr/bin/env python# -*- coding: utf-8 -*-import ioimport re,osdef alter(file,old_str,new_str): with io.open(file, "r", encoding="utf-8...原创 2018-09-11 16:19:59 · 195 阅读 · 0 评论 -
python中执行url的两种方法urllib和request
python中使用urllib方法调用url是比较基础的方式,有些环境中没有request时,可以采用此方式。不过个人认为request方式更简单方便一些。import urllibimport urllib2import jsondef fun_post(url, body): headers = {'content-type': 'application/json', 'Acce...原创 2019-09-05 14:40:47 · 2468 阅读 · 0 评论