1.有关配置的读取
import configparser
import codecs
#配置文件格式
[config] #自定义的配置
key=value
key2=value2
读取配置
conf = configparser.ConfigParser()
conf.add_section('config') # 添加section
try:
conf.readfp(codecs.open(path, "r", "utf-8-sig"))
except IOError as e:
print("配置文件读取出错")
conf.get('config', 'key') #读取配置
2.查找字符串的里面所有的子字符串的方法
def findAllPosByChar(strText, ch):
posList = []
count = 0
strList = list(strText)
for item in strList:
count += 1
if item == ch:
posList.append(count - 1)
return posList
3.OSX的回车符是
from collections import OrderedDict #把字典变成有序的 dict= OrderedDict()
4.字典转json
import json
jsonStr = json.dumps(dict_List, ensure_ascii=False) #把字典的List转换成json数组字符串
import codecs #读取文件的时候可以用这个防止乱码
codecs.open(path).read() 读取文件返回字符串