- 闭包 https://www.cnblogs.com/Lin-Yi/p/7305364.html
if __name__ == "__py_file_name__"
https://www.cnblogs.com/Emerald/p/4827238.html- 正则表达式 re.search match.group(1) re.search(str)
https://docs.python.org/3/library/re.html - 数据库操作 dbconnector–>cursor–>DML commit–>except rollback
https://stackoverflow.com/questions/19046202/python-how-to-know-if-a-record-inserted-successfully-or-not
“.rowcount This read-only attribute specifies the number of rows that the last .execute**() produced (for DQL statements like SELECT) or affected (for DML statements like UPDATE or INSERT)”
http://www.runoob.com/python3/python3-mysql.html - 一行一行读文本文件 https://stackoverflow.com/questions/11555468/how-should-i-read-a-file-line-by-line-in-python Python小问题(3.6.6) file.tell()返回的不是字节数(https://stackoverflow.com/questions/15934950/python-file-tell-giving-strange-numbers), 但用起来好像又是!它隐藏了底层文件系统中换行处理,统一处理为’\n’,mark然后使用len(str.encode(‘utf-8’)取这一行长度,造成seek后回退不正确,windows下始终差1,没错忽略的就是就是’\r’(0xd),tell()数数时含了它,但返回给一个str时,却不含’\r’,file.tell https://docs.python.org/2/library/stdtypes.html#file.tell
https://docs.python.org/3/library/io.html#io.TextIOBase.tell
e.g.
abc
abcd
python file.seek(3) 再file.read(1)后
file.tell()应该是4,实际显示5,期待字符是”\r”(13),实际是10(\n) - 一行一行读文件的额同时,保留seek:
python with open(log_file_dir, "r") as log_file: for line in iter(log_file.readline, ''):
- 使用
for line in iter(f.readline, '目标行(含\n)'): print f.tell()
iter的第二个参数是目的参数,遇到它就停。
可以获得目标行的下一行 - Python3.6的字典是有序的?是的,python3.6以后的字典是有序的,即按照你输入的顺序,经验证,Ubuntu16.04下自带的python3.52都是无序的,是Hash过的顺序!之前的版本可以通过
imort collections
ord_dic = collections.OrderedDict()
python2.7.6下:
- python dict哈希似乎和时间有关,同一个内容,时间不同,结果不一样!
如何安全获得字典的第一个键值my_dict = {'foo': 'bar'} next(iter(my_dict)) # outputs 'foo'
低版本python字典无序,如何让它有序(按abcd那种顺序)?https://stackoverflow.com/questions/15711755/converting-dict-to-ordereddict;
https://stackoverflow.com/questions/613183/how-do-i-sort-a-dictionary-by-value;
10. 给一个变量赋值一个字典类型,注意到!字典赋值是浅拷贝,目的值只是获得了一个引用,在后面它的还是会随字典值的改变而改变的!这让我想到了什么?西门子S-200 PLC编程,还有js的闭包,js闭包(设想5s定时循环实际连续输出5)和python字典浅拷贝在循环中要特别注意!
11. 一个人类友好的格式转换库:https://humanfriendly.readthedocs.io/en/latest/api.html#module-humanfriendly 可惜很多单位是英文