Python-0.2-正则|数据库|文件IO|字典有无序和拷贝|humanfriendly

  1. 闭包 https://www.cnblogs.com/Lin-Yi/p/7305364.html
  2. if __name__ == "__py_file_name__" https://www.cnblogs.com/Emerald/p/4827238.html
  3. 正则表达式 re.search match.group(1) re.search(str)
    https://docs.python.org/3/library/re.html
  4. 数据库操作 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
  5. 一行一行读文本文件 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)
  6. 一行一行读文件的额同时,保留seek: python with open(log_file_dir, "r") as log_file: for line in iter(log_file.readline, ''):
  7. 使用
    for line in iter(f.readline, '目标行(含\n)'): print f.tell() iter的第二个参数是目的参数,遇到它就停。
    可以获得目标行的下一行
  8. Python3.6的字典是有序的?是的,python3.6以后的字典是有序的,即按照你输入的顺序,经验证,Ubuntu16.04下自带的python3.52都是无序的,是Hash过的顺序!之前的版本可以通过
    imort collections
    ord_dic = collections.OrderedDict()
    python2.7.6下:
    在这里插入图片描述
    在这里插入图片描述
  9. 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 可惜很多单位是英文

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值