zoukankan      html  css  js  c++  java
  • day17_内置函数_文件处理

    20180729    修改部分代码

    更新:# # 5、max与列表指定参数

    20180728    初次上传
     

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    # ********************day17_内置函数_文件处理 *******************
    # =====>>>>>>内容概览
    # # 1、zip
    # # # 也称之为拉链函数,参数两边匹配==》  元组 ==》列表
    
    # # 2、zip与字典
    # # # zip拉链函数,对“字典”中的key与值进行匹配输出
    
    # # 2、zip与字符串
    
    # # 3、max
    # # # 1、 max函数处理的是可迭代对象,相当于一个for循环取出来每个元素进不行比较,注意不同类型之间是不能进行比较的
    # # # 2、每个元素间进行比较,是从每个元素的第一个位置依次比较,如果这一个位置分出大小,后面的都不需要比较了,直接得
    #   # #  出这俩元素的大小(如下)
    # # # #  对于字典中的max求最大值,比较过程:所有的第一个元素比较-->  找到最大值,结束;否则 -->
    # # # # 所有的第二个元素比较-->找到最大值,结束;否则 -->。。。-->最大值,结束
    # # # # max(字典),默认比价的是字典中的key
    
    # # 4、max 指定方法进行比较
    
    # # 5、max与列表指定参数
    
    
    # # 6、chr  与 ord  正反向编码
    
    
    # # 7、pow
    # # # pow() 方法返回 x^y(x的y次方) 的值。
    # # # 内置的 pow() 方法
    # # # 函数是计算x的y次方,如果z在存在,则再对结果进行取模,其结果等效于pow(x,y) %z
    # # # 注意:pow() 通过内置的方法直接调用,内置方法会把参数作为整型
    
    
    # # 8、repr
    # # # repr() 函数将对象转化为供解释器读取的形式。
    
    # # 8、reverse
    # # # reverse() 函数用于反向列表中元素。
    # # # 该方法没有返回值,但是会对列表的元素进行反向排序。
    
    # # 9、round
    # # # round() 方法返回浮点数x的四舍五入值。
    # # # round( x [, n]  )
    # # # #           x -- 数值表达式。
    # # # #           n -- 数值表达式。
    
    # # 10、set
    # # # set() 函数创建一个无序不重复元素集,可进行关系测试,删除重复数据,还可以计算交集、差集、并集等。
    
    # # 11、slice
    # # # slice() 函数实现切片对象,主要用在切片操作函数里的参数传递。
    
    # # 12、sorted()
    # # # sorted() 函数对所有可迭代的对象进行排序操作。
    # # # sort 与 sorted 区别:
    # # # sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作。
    # # # list 的 sort 方法返回的是对已经存在的列表进行操作,而内建函数 sorted 方法返回的是一个新的 list,而不是在原来的基础上进行的操作。
    
    # # 13、sorted对列表中的字典排序
    # # # 对字典中的的指定位置的参数进行字典排序
    
    # # 14、sorted对字典的排序,       sorted 与 zip 联用
    
    # # 15、eval
    # # # eval() 函数用来执行一个字符串表达式,并返回表达式的值。
    # # # 也应是返回字符的内容,相当于去掉字符中的两边的符号
    # # # x = 7
    # # # >>> eval( '3 * x' )
    # # # 结果  21
    
    # # 16、sum()
    # # # sum() 方法对系列进行求和计算。
    
    # # 17、type
    # # # type() 函数如果你只有第一个参数则返回对象的类型,三个参数返回新的类型对象。
    #
    # # 18、isinstance() 与 type() 区别:
    # # # type()       不会认为子类是一种父类类型,不考虑继承关系。
    # # # isinstance()   会认为子类是一种父类类型,考虑继承关系。
    # # # 如果要判断两个类型是否相同推荐使用 isinstance()。
    
    # # 19、type 的应用
    # # # 数据运算前进行确认类型,以进行同类型处理
    
    # # 20、vars
    # # # 描述
    # # # # vars() 函数返回对象object的属性和属性值的字典对象。
    
    # # 21、import 函数
    # # # 文件的导入
    # # # 系统对import的实现过程:   import------>sys----->__import__()
    # # # import 通常用来实现文件名直接去文件
    # # # __import__()通常用来是先字符串文件名  取  文件
    
    
    # # 22、__import__
    # # # 字符串文件名导入
    # # # __import__() 函数用于动态加载类和函数 。
    # # # 如果一个模块经常变化就可以使用 __import__() 来动态载入。
    # # # 返回值:  返回元组列表。
    
    
    # # 23、关于文件:     所有的文件,都是使用字符串储存的。也就是说,所有的数据类型,最后储存在系统,都是字符串,
    # # #---------------- 最后在通过系统转化为硬件可理解的二进制编码
    # # # 文件处理的常用三种模式:r,w,a,分别是:读、写、追加
    
    # # 24、文件读的3常用函数     read  readline readable
    
    # # 25、read
    # # # 文件读
    
    # # 26、f.readable      f.readline
    # # # f.readable()  # 判断文件是否已r模式打开,是则返回True,否则返回False
    # # # readline  文件中读取一行
    
    # # 27、f.readable() 补充
    
    # # 28、文件写常用函数      write   writeline
    
    # # 29、文件写
    # # # w是直接  清空原文件, 将新的内容写入进去
    # # # 如果文件不存在,那么就会新建一个文件
    
    # # 30、writelines()
    # # # 文件写
    # # # 文件的内容只能是字符串,也只能写字符串
    
    # # 31、a
    # # # a模式追加内容
    # # # 打开一个文件用于追加。如果该文件已存在,文件指针将会放在文件的结尾。
    # # # 也就是说,新的内容将会被写入到已有内容之后。如果该文件不存在,创建新文件进行写入。
    
    # # 32、r+
    # # # 打开一个文件用于读写。文件指针将会放在文件的开头。
    
    # # 33、文件修改的本质就是  文件覆盖
    # # # 根本上就没有修改一说
    
    
    # # 34、with open() as f:
    # # # with open('a.txt','w') as f:
    # # # 以方式“写w”打开文件a.txt,如果没有就创建新的文件,然后文件完成后自动关闭。
    # # # 相对于f.open(),  这种模式只需要打开就可以了,不需要关闭;然而,f.open()模式,需要在文件操作完成后,对
    # # # 文件进行关闭
    
    # # 35、with open() as f:     多行操作
    
    
    # # 36、f.encoding
    # # # 查看文件编码
    
    # print("分割线".center(100,"-"))
    # ------------------------------------------------分割线-------------------------------------------------
    # ------------------------------------------------分割线-------------------------------------------------
    # ------------------------------------------------分割线-------------------------------------------------
    
    # # 1、zip
    # # # 也称之为拉链函数,参数两边匹配==》  元组 ==》列表
    # 描述
    # zip() 函数用于将可迭代的对象作为参数,将对象中对应的元素打包成一个个元组,然后返回由这些元组组成的列表。
    # 如果各个迭代器的元素个数不一致,则返回列表长度与最短的对象相同,利用 * 号操作符,可以将元组解压为列表。
    # zip 方法在 Python 2 和 Python 3 中的不同:在 Python 3.x 中为了减少内存,zip() 返回的是一个对象。如需展示列表,需手动 list
    #
    # print(list(zip(('a','b','c','d',),('1','2','3','4','5',))))
    # print(list(zip(('a','b','c','d',),('1','2','3','4',))))
    # print(list(zip(('a','b','c','d',),('1','2','3',))))
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # [('a', '1'), ('b', '2'), ('c', '3'), ('d', '4')]
    # # [('a', '1'), ('b', '2'), ('c', '3'), ('d', '4')]
    # # [('a', '1'), ('b', '2'), ('c', '3')]
    # #
    # # Process finished with exit code 0
    
    
    
    
    # # 2、zip与字典
    # # # zip拉链函数,对“字典”中的key与值进行匹配输出
    # p = {
    #     "name": "alex",
    #     "age":18,
    #     "gender": "none"
    # }
    # print(list(zip(p.keys(),p.values())))
    # # print(p.keys() )                # dict_keys(['name', 'age', 'gender'])
    # # print( p.values() )             # dict_values(['alex', 18, 'none'])
    # print(list( p.keys() ) )
    # print(list(p.values()) )
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # [('name', 'alex'), ('age', 18), ('gender', 'none')]
    # # ['name', 'age', 'gender']
    # # ['alex', 18, 'none']
    # #
    # # Process finished with exit code 0
    
    
    # # 2、1 zip与字符串
    # a = "hello"
    # b = "12345"
    # print(list(zip(a,b)))
    # #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # [('h', '1'), ('e', '2'), ('l', '3'), ('l', '4'), ('o', '5')]
    # #
    # # Process finished with exit code 0
    
    
    
    
    # # 3、max
    # # # 1、 max函数处理的是可迭代对象,相当于一个for循环取出来每个元素进行比较,注意不同类型之间是不能进行比较的
    # # # 2、每个元素间进行比较,是从每个元素的第一个位置依次比较,如果这一个位置分出大小,后面的都不需要比较了,直接得
    # # # #  出这俩元素的大小(如下)
    # # # #  对于字典中的max求最大值,比较过程:所有的第一个元素比较-->  找到最大值,结束;否则 -->
    # # # # 所有的第二个元素比较-->找到最大值,结束;否则 -->。。。-->最大值,结束
    # # # # max(字典),默认比价的是字典中的key
    
    # age_dic = {
    #     "age1":18 ,
    #     "age4":20,
    #     "age3":100,
    #     "age2":50
    # }
    # print('max(age_dic):            ',max(age_dic))
    # print('max(age_dic.values()):   ',max(age_dic.values()))
    # print('max(age_dic.keys()):     ',max(age_dic.keys()))
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # max(age_dic):             age4
    # # max(age_dic.values()):    100
    # # max(age_dic.keys()):      age4
    # #
    # # Process finished with exit code 0
    
    # # 实例二
    # 明确是max是按照元素的位比较,而不是整体比较;  整体比较:age111大;     元素的位比较:age41大
    # age_dic = {
    #     "age111":18 ,
    #     "age41":20,
    #     "age3":100,
    #     "age2":50
    # }
    # print('max(age_dic):            ',max(age_dic))
    # print('max(age_dic.values()):   ',max(age_dic.values()))
    # print('max(age_dic.keys()):     ',max(age_dic.keys()))
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # max(age_dic):             age41
    # # max(age_dic.values()):    100
    # # max(age_dic.keys()):      age41
    # #
    # # Process finished with exit code 0
    
    
    # # 实例三
    # # 先比较第一个元素,比较出结果后,后面的就不在比较,如下列中,第一个元素中100是最大值
    # 字典求max,默认是对key进行比较大小,比较的方式是从key中的每一位进行比较大小
    # age_dic = {
    #     "alex_age":18 ,
    #     "wuqpei_age":20,
    #     "zsc_age":100,
    #     "lhf_age":50
    #
    # }
    # # print(max(age_dic.values()))                          # 100
    # for item in zip(age_dic.values(),age_dic.keys()):       # [(18,'alex_age')  (20,'wupeiqi_age') () () ()]
    #     print(item)
    #
    # print('=======>',list(max(zip(age_dic.values(),age_dic.keys()))) )
    #
    
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # (18, 'alex_age')
    # # (20, 'wuqpei_age')
    # # (100, 'zsc_age')
    # # (50, 'lhf_age')
    # # =======> [100, 'zsc_age']
    # #
    # # Process finished with exit code 0
    
    
    # # 实例四
    # # 不同类型,不可以进行比较
    #
    # l = [
    #     (5,'e'),
    #     (1, 'b'),
    #     (3, 'a'),
    #
    # ]
    # l1 = ['a19','n23','c11']
    # # l1 = ['a19','n23','c11',100]            # 报错,不同类型之间不能进行比较
    # print( list(max(l)))
    # print( list(max(l1)))                     # 第一个元素"n"最大,返回"n23",结束
    #
    # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # [5, 'e']
    # ['n', '2', '3']
    #
    # Process finished with exit code 0
    
    
    # # 4、max 指定方法进行比较
    # # 列表内的字典比较
    # # 有点难理解
    # people = [
    #     {'name': 'alex', 'age':1000},
    #     {'name': 'wupeiqi', 'age':10000},
    #     {'name': 'yuanhao', 'age': 9000},
    #     {'name': 'linhaifeng', 'age': 18}
    #
    # ]
    #
    # # max(people)          # 报错,直接的字典与字典之间是不可以比较大小的
    #
    # # 比较people中的age 的值的大小
    # # 下面就是把people的每一个元素(字典)取出来,然后,使用指定的方法key对字典的value进行  max 比较大小
    # # 之后返回值所在的索引位置
    # print( max(people, key = lambda dic:dic['age']) )
    #
    # # 等同实现方法
    # ret = []
    # for item in people:
    #     ret.append(item['age'])
    # print("ret:",ret)
    # print("max(ret):", max(ret) )
    # # 其他测试
    # print( "lambda dic:dic['age']:  ",(lambda dic:dic['age'])(people[0])  )
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # {'name': 'wupeiqi', 'age': 10000}
    # # ret: [1000, 10000, 9000, 18]
    # # max(ret): 10000
    # # lambda dic:dic['age']:   1000
    # #
    # # Process finished with exit code 0
    
    # # 5、max与列表指定参数
    # # # 关于列表中的列表这个比较
    # people = [
    #     [11,111],
    #     [22,222],
    #     [33,333],
    #     [44,444]
    #
    # ]
    # print( max(people,key= lambda x: x[0]) )
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # [44, 444]
    # # 11
    # #
    # # Process finished with exit code 0
    
    
    
    
    # # 6、chr  与 ord  正反向编码
    # print(chr(97))
    # print(ord('a'))
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # a
    # # 97
    # #
    # # Process finished with exit code 0
    
    
    # # 7、pow
    # # # pow() 方法返回 x^y(x的y次方) 的值。
    # # # 内置的 pow() 方法
    # # # 函数是计算x的y次方,如果z在存在,则再对结果进行取模,其结果等效于pow(x,y) %z
    # # # 注意:pow() 通过内置的方法直接调用,内置方法会把参数作为整型
    
    
    # pow(x, y[, z])
    # print(pow(3,3))         # 3**3
    # print(pow(3,3,2))       # 3**3%2
    #
    # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # 27
    # 1
    #
    # Process finished with exit code 0
    
    
    
    # # 8、repr
    # # # repr() 函数将对象转化为供解释器读取的形式。
    #
    # 语法
    # 以下是 repr() 方法的语法:
    # repr(object)
    # 返回值
    # 返回一个对象的 string 格式。
    # ====>需要留意到的是,下面的结果都是str类型的,这是因为所有的数据存储最后都是转化为  字符串
    # a= 1
    # s = "aaaaa"
    # l = [1111,2222,33333]
    # se = {"a","b","c",1,9}
    # dic = {'runoob': 'runoob.com', 'google': 'google.com'}
    # print( "a:  ",repr(a) ,type(repr(a)))
    # print( "s:",repr(s) ,type(repr(s)))
    # print( "l:",repr(l) ,type(repr(l)))
    # print( "se:",repr(se) ,type(repr(se)))
    # print( "dict:",repr(dic) ,type(repr(dic)))
    # #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # a:   1 <class 'str'>
    # # s: 'aaaaa' <class 'str'>
    # # l: [1111, 2222, 33333] <class 'str'>
    # # se: {1, 'c', 9, 'b', 'a'} <class 'str'>
    # # dict: {'runoob': 'runoob.com', 'google': 'google.com'} <class 'str'>
    # #
    # # Process finished with exit code 0
    
    
    
    # # 8、reverse
    # # # reverse() 函数用于反向列表中元素。
    # # # 该方法没有返回值,但是会对列表的元素进行反向排序。
    #
    # l  =[1,2,3,4]
    # print(list(reversed(l)))
    # print(l)
    # #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # [4, 3, 2, 1]
    # # [1, 2, 3, 4]
    # #
    # # Process finished with exit code 0
    
    
    
    
    # # 9、round
    # # # round() 方法返回浮点数x的四舍五入值。
    # # # round( x [, n]  )
    # # # #           x -- 数值表达式。
    # # # #           n -- 数值表达式。
    # print("round(3.5):           ",round(3.5))
    # print( "round(80.23456, 2) : ", round(80.23456, 2) )
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # round(3.5):            4
    # # round(80.23456, 2) :  80.23
    # #
    # # Process finished with exit code 0
    
    
    # # 10、set
    # # # set() 函数创建一个无序不重复元素集,可进行关系测试,删除重复数据,还可以计算交集、差集、并集等。
    # print( set("hello") )
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # {'h', 'l', 'e', 'o'}
    # #
    # # Process finished with exit code 0
    
    
    
    # # 11、slice
    # # # slice() 函数实现切片对象,主要用在切片操作函数里的参数传递。
    # # class slice(start, stop[, step])
    # l = "hello123456"
    # #    01234567890
    # s1 = slice(3,9)     # 这种方式进行切片处理,易读性比较高,同时移植性提高
    # s2 = slice(3,9,2)
    # print(l[3:9])
    # print("slice(3,9):    ",l[s1])
    # print("slice(3,9,2):  ",l[s2])
    # print("s2.start :     ",s2.start)
    # print("s2.stop:        ",s2.stop)
    # print("s2.step:        ",s2.step)
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # lo1234
    # # slice(3,9):     lo1234
    # # slice(3,9,2):   l13
    # # s2.start :      3
    # # s2.stop:         9
    # # s2.step:         2
    # #
    # # Process finished with exit code 0
    
    
    
    # # 12、sorted()
    # # # sorted() 函数对所有可迭代的对象进行排序操作。
    # # # sort 与 sorted 区别:
    # # # sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作。
    # # # list 的 sort 方法返回的是对已经存在的列表进行操作,而内建函数 sorted 方法返回的是一个新的 list,而不是在原来的基础上进行的操作。
    # l  = [3,2,1,5,7]
    # l1=  [3,2,'a',1,5,7]
    # print(sorted(l))
    # # print(sorted(l1))     # 排序本质就是在比较大小,不同类型之间不可以比较大小
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # [1, 2, 3, 5, 7]
    # #
    # # Process finished with exit code 0
    
    
    # # 13、sorted对列表中的字典排序
    # # # 对字典中的的指定位置的参数进行字典排序
    # people = [
    #     {'name': 'alex', 'age':1000},
    #     {'name': 'wupeiqi', 'age':10000},
    #     {'name': 'yuanhao', 'age': 9000},
    #     {'name': 'linhaifeng', 'age': 18}
    #
    # ]
    #
    # s = sorted(people,key=lambda dic: dic['age'] )
    # for i in s:
    #     print(i)
    # # print(sorted(people,key=lambda dic: dic['age']))        # 上面的表达方式更加容易观察
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # {'name': 'linhaifeng', 'age': 18}
    # # {'name': 'alex', 'age': 1000}
    # # {'name': 'yuanhao', 'age': 9000}
    # # {'name': 'wupeiqi', 'age': 10000}
    # #
    # # Process finished with exit code 0
    
    
    
    
    
    # # 14、sorted对字典的排序,       sorted 与 zip 联用
    #
    # # 默认是对key关键字进行排序
    # name_dic ={
    #     'yuanhao' : 900,
    #     'alex':     200,
    #     'wupeiqi':  300
    #
    # }
    # print(sorted(name_dic))
    # print(sorted(name_dic,key=lambda key: name_dic[key] ))          # 如果我只要排序的结果是值的大小呢???
    # print(sorted(zip(name_dic.values(), name_dic.keys()) ))
    # print(sorted(zip(name_dic.keys(),name_dic.values() ) ))
    #
    # # D:AnacoD:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # ['alex', 'wupeiqi', 'yuanhao']
    # # ['alex', 'wupeiqi', 'yuanhao']
    # # [(200, 'alex'), (300, 'wupeiqi'), (900, 'yuanhao')]
    # # [('alex', 200), ('wupeiqi', 300), ('yuanhao', 900)]
    # #
    # # Process finished with exit code 0
    
    
    
    # # 15、eval
    # # # eval() 函数用来执行一个字符串表达式,并返回表达式的值。
    # # # 也应是返回字符的内容,相当于去掉字符中的两边的符号
    # # # x = 7
    # # # >>> eval( '3 * x' )
    # # # 结果  21
    #
    # dic_str = str( {'a':1 })
    # print("a:                       ",str('1'), type('1'))
    # print("type (str( {'a':1}) )    ",type (str( {'a':1} )) )
    # print("type( eval(dic_str))     ",type( eval(dic_str)))     # 去掉字符串两边的 ""
    #
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # {'aa', 'abb'}
    # # a:                        1 <class 'str'>
    # # type (str( {'a':1}) )     <class 'str'>
    # # type( eval(dic_str))      <class 'dict'>
    # #
    # # Process finished with exit code 0
    
    # # 16、sum()
    # # # sum() 方法对系列进行求和计算。
    # l = [1,2,3,4]
    # print("sum(l):              ",sum(l))
    # print("sum( range(1,5)):    ",sum( range(1,5)))
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # sum(l):               10
    # # sum( range(1,5)):     10
    # #
    # # Process finished with exit code 0
    
    
    
    # # 17、type
    # # # type() 函数如果你只有第一个参数则返回对象的类型,三个参数返回新的类型对象。
    #
    # # 18、isinstance() 与 type() 区别:
    # # # type()       不会认为子类是一种父类类型,不考虑继承关系。
    # # # isinstance()   会认为子类是一种父类类型,考虑继承关系。
    # # # 如果要判断两个类型是否相同推荐使用 isinstance()。
    #
    # print( type(1) )
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # <class 'int'>
    # #
    # # Process finished with exit code 0
    
    
    # # 19、type 的应用
    # # # 数据运算前进行确认类型,以进行同类型处理
    # # 例:对msg进行+1处理,
    # msg = '123'
    # # print(msg +1 )      #  对msg直接进行+1处理,类型错误==>报错
    # if type(msg) is str:
    #     msg = int(msg)
    #     res = msg +1
    #     print(res)
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # 124
    # #
    # # Process finished with exit code 0
    
    
    
    
    
    # # 20、vars
    # # # 描述
    # # # # vars() 函数返回对象object的属性和属性值的字典对象。
    #
    # 语法
    # vars() 函数语法:
    # vars([object])
    #
    # def test():
    #     msg = '发生大的风飒飒的丰富的是'
    #     print('locals():',locals())
    #     print('vars():',vars())
    # test()
    # print('vars()',vars())
    # print('vars(int)',vars(int))
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # locals(): {'msg': '发生大的风飒飒的丰富的是'}
    # # vars(): {'msg': '发生大的风飒飒的丰富的是'}
    # # vars() {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x0000000001DBD0F0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py', '__cached__': None, 'test': <function test at 0x00000000005B1EA0>}
    # # vars(int) {'__repr__': <slot wrapper '__repr__' of 'int' objects>, '__hash__': <slot wrapper '__hash__' of 'int' objects>, '__str__': <slot wrapper '__str__' of 'int' objects>, '__getattribute__': <slot wrapper '__getattribute__' of 'int' objects>, '__lt__': <slot wrapper '__lt__' of 'int' objects>, '__le__': <slot wrapper '__le__' of 'int' objects>, '__eq__': <slot wrapper '__eq__' of 'int' objects>, '__ne__': <slot wrapper '__ne__' of 'int' objects>, '__gt__': <slot wrapper '__gt__' of 'int' objects>, '__ge__': <slot wrapper '__ge__' of 'int' objects>, '__add__': <slot wrapper '__add__' of 'int' objects>, '__radd__': <slot wrapper '__radd__' of 'int' objects>, '__sub__': <slot wrapper '__sub__' of 'int' objects>, '__rsub__': <slot wrapper '__rsub__' of 'int' objects>, '__mul__': <slot wrapper '__mul__' of 'int' objects>, '__rmul__': <slot wrapper '__rmul__' of 'int' objects>, '__mod__': <slot wrapper '__mod__' of 'int' objects>, '__rmod__': <slot wrapper '__rmod__' of 'int' objects>, '__divmod__': <slot wrapper '__divmod__' of 'int' objects>, '__rdivmod__': <slot wrapper '__rdivmod__' of 'int' objects>, '__pow__': <slot wrapper '__pow__' of 'int' objects>, '__rpow__': <slot wrapper '__rpow__' of 'int' objects>, '__neg__': <slot wrapper '__neg__' of 'int' objects>, '__pos__': <slot wrapper '__pos__' of 'int' objects>, '__abs__': <slot wrapper '__abs__' of 'int' objects>, '__bool__': <slot wrapper '__bool__' of 'int' objects>, '__invert__': <slot wrapper '__invert__' of 'int' objects>, '__lshift__': <slot wrapper '__lshift__' of 'int' objects>, '__rlshift__': <slot wrapper '__rlshift__' of 'int' objects>, '__rshift__': <slot wrapper '__rshift__' of 'int' objects>, '__rrshift__': <slot wrapper '__rrshift__' of 'int' objects>, '__and__': <slot wrapper '__and__' of 'int' objects>, '__rand__': <slot wrapper '__rand__' of 'int' objects>, '__xor__': <slot wrapper '__xor__' of 'int' objects>, '__rxor__': <slot wrapper '__rxor__' of 'int' objects>, '__or__': <slot wrapper '__or__' of 'int' objects>, '__ror__': <slot wrapper '__ror__' of 'int' objects>, '__int__': <slot wrapper '__int__' of 'int' objects>, '__float__': <slot wrapper '__float__' of 'int' objects>, '__floordiv__': <slot wrapper '__floordiv__' of 'int' objects>, '__rfloordiv__': <slot wrapper '__rfloordiv__' of 'int' objects>, '__truediv__': <slot wrapper '__truediv__' of 'int' objects>, '__rtruediv__': <slot wrapper '__rtruediv__' of 'int' objects>, '__index__': <slot wrapper '__index__' of 'int' objects>, '__new__': <built-in method __new__ of type object at 0x00000000503F99A0>, 'conjugate': <method 'conjugate' of 'int' objects>, 'bit_length': <method 'bit_length' of 'int' objects>, 'to_bytes': <method 'to_bytes' of 'int' objects>, 'from_bytes': <method 'from_bytes' of 'int' objects>, '__trunc__': <method '__trunc__' of 'int' objects>, '__floor__': <method '__floor__' of 'int' objects>, '__ceil__': <method '__ceil__' of 'int' objects>, '__round__': <method '__round__' of 'int' objects>, '__getnewargs__': <method '__getnewargs__' of 'int' objects>, '__format__': <method '__format__' of 'int' objects>, '__sizeof__': <method '__sizeof__' of 'int' objects>, 'real': <attribute 'real' of 'int' objects>, 'imag': <attribute 'imag' of 'int' objects>, 'numerator': <attribute 'numerator' of 'int' objects>, 'denominator': <attribute 'denominator' of 'int' objects>, '__doc__': "int(x=0) -> integer
    int(x, base=10) -> integer
    
    Convert a number or string to an integer, or return 0 if no arguments
    are given.  If x is a number, return x.__int__().  For floating point
    numbers, this truncates towards zero.
    
    If x is not a number or if base is given, then x must be a string,
    bytes, or bytearray instance representing an integer literal in the
    given base.  The literal can be preceded by '+' or '-' and be surrounded
    by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
    Base 0 means to interpret the base from the string as an integer literal.
    >>> int('0b100', base=0)
    4"}
    # #
    # # Process finished with exit code 0
    
    
    # ************************************************文件处理************************************************
    # ************************************************文件处理************************************************
    # ************************************************文件处理************************************************
    # print("文件处理".center(100,"*"))
    # 文件的处理
    # 文件的处理
    # 文件的处理
    #
    # # 21、import 函数
    # # # 文件的导入
    # # # 系统对import的实现过程:   import------>sys----->__import__()
    # # # import 通常用来实现文件名直接去文件
    # # # __import__()通常用来是先字符串文件名  取  文件
    # import cache
    # cache.say_hi()
    #
    # """
    # cache.py
    # #!/usr/bin/env python
    # # -*- coding:utf-8 -*-
    # print( "here is cache!! ")
    # def say_hi():
    #     print("hello!! I am say function")
    #
    # """
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # here is cache!!
    # # hello!! I am say function
    # #
    # # Process finished with exit code 0
    
    
    
    
    # # 22、__import__
    # # # 字符串文件名导入
    # # # __import__() 函数用于动态加载类和函数 。
    # # # 如果一个模块经常变化就可以使用 __import__() 来动态载入。
    # # # 返回值:  返回元组列表。
    
    # module_name = 'cache'
    # m = __import__(module_name)
    # m.say_hi()
    # # """
    # #
    # # cache.py
    # # #!/usr/bin/env python
    # # # -*- coding:utf-8 -*-
    # # print( "here is cache!! ")
    # # def say_hi():
    # #     print("hello!! I am say function")
    # #
    # # """
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # here is cache!!
    # # hello!! I am say function
    # #
    # # Process finished with exit code 0
    
    
    # 06
    # 06
    # 06
    # # 23、关于文件:     所有的文件,都是使用字符串储存的。也就是说,所有的数据类型,最后储存在系统,都是字符串,
    # # #---------------- 最后在通过系统转化为硬件可理解的二进制编码
    # # # 文件处理的常用三种模式:r,w,a,分别是:读、写、追加
    
    
    # # 24、文件读的3常用函数     read  readline readable
    #
    # # 25、read
    # # # 文件读
    # # f = open('陈粒',encoding="utf-8")
    # f = open('陈粒',encoding="gbk")
    # data = f.read()
    # print(data)
    # f.close()
    #
    #
    '''
        陈粒文件夹是使用gbk编码储存的
    '''
    #
    # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # 这个是一个叫作陈粒的文件夹
    #
    # Process finished with exit code 0
    
    
    # # 26、f.readable      f.readline
    # # # f.readable()  # 判断文件是否已r模式打开,是则返回True,否则返回False
    # # # readline  文件中读取一行
    
    # #
    # f = open('陈粒1',encoding="utf-8")
    # data = f.readable()
    # print(data)
    # print(f.readline())             # 没有使用end ,  print 默认会使用'
    ' 多空一行结尾
    # print(f.readline(),end= '')
    # print(f.readline(),end= '')
    #
    # f.close()
    #
    # """
    # 1111111
    # 2
    # 3
    # 4
    # 5
    # # """
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # True
    # # 1111111
    # #
    # # 2
    # # 3
    # #
    # # Process finished with exit code 0
    
    
    
    
    # # 27、f.readable() 补充
    #
    # f = open('陈粒1','w',encoding="utf-8")
    # print(f.readable())           # 因为文件是只写模式打开的,因此不可写      返回False
    # f.close()
    #
    # f = open('陈粒1','r',encoding="utf-8")
    # print(f.readable())           # 因为文件是只写模式打开的,因此不可写
    # f.close()
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # False
    # # True
    # #
    # # Process finished with exit code 0
    
    
    
    
    # # 28、文件写常用函数      write   writeline
    # #     write
    # # 29、文件写
    # # # w是直接  清空原文件, 将新的内容写入进去
    # # # 如果文件不存在,那么就会新建一个文件
    #
    # f = open('陈粒2','w',encoding="utf-8")
    # data = f.readable()
    # f.write("111111=====>
    ")
    # f.write("111111
    ")
    # f.write("111111
    ")
    # f.write("111111
    ")
    # f.write("1
    1
    1111
    ")
    # f.close()
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # #
    # # Process finished with exit code 0
    
    
    
    # # 30、writelines()
    # # # 文件写
    # # # 文件的内容只能是字符串,也只能写字符串
    # f = open('陈粒2','w',encoding="utf-8")
    # data = f.readable()
    # f.write("111111=====>
    ")
    # f.write("111111
    ")
    # f.writelines("writelines1
    1
    1111
    ")
    # # f.writelines(["writelines1
    1
    1111
    ",33333])      # 文件的内容只能是字符串,也只能写字符串
    # f.close()
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # #
    # # Process finished with exit code 0
    
    
    
    
    
    # # 31、a
    # # # a模式追加内容
    # # # 打开一个文件用于追加。如果该文件已存在,文件指针将会放在文件的结尾。
    # # # 也就是说,新的内容将会被写入到已有内容之后。如果该文件不存在,创建新文件进行写入。
    # f = open('陈粒2','a',encoding="utf-8")
    # f.write("写到文件追加")
    # f.close()
    
    
    # # 32、r+
    # # # 打开一个文件用于读写。文件指针将会放在文件的开头。
    # f = open('陈粒2','r+',encoding="utf-8")
    # print( f.read())
    # f.write("写到文件追加")
    # # 下面输出是空,但是查看文件的时候,内容是写进去了,说明这里的read时候,光标在文件的最后的位置,因此read的内容
    # # 是空的
    # print("write之后:", f.read())
    # f.close()
    #
    # f = open('陈粒2','r+',encoding="utf-8")
    # print("f.close()之后:
    ", f.read())           # 这里读取到内容了,正确的
    # f.close()
    #
    
    
    
    # # 33、文件修改的本质就是  文件覆盖
    # # # 根本上就没有修改一说
    
    
    
    
    # # 34、with open() as f:
    # # # with open('a.txt','w') as f:
    # # # 以方式“写w”打开文件a.txt,如果没有就创建新的文件,然后文件完成后自动关闭。
    # # # 相对于f.open(),  这种模式只需要打开就可以了,不需要关闭;然而,f.open()模式,需要在文件操作完成后,对
    # # # 文件进行关闭
    
    # with open('a.txt','w') as f:
    #     f.write("sss
    11111
    ")
    
    
    
    # # 35、with open() as f:     多行操作
    
    # with open('xxx','r',encoding='gbk')as src_f,
    #      open('xxx_new','w+',encoding='gbk') as dst_f:
    #     data = src_f.read()
    #     dst_f.write(data+"new xxxx")
    
    
    
    # # 36、f.encoding
    # # # 查看文件编码
    # f=open('a.txt')
    # print(f.encoding) #查看文件编码
    # f.close()
    #
    # f=open('陈粒')
    # print(f.encoding) #查看文件编码
    # f.close()
    #
    #
    # # D:Anaconda3python.exe D:/C_cache/py/python_practice/day17_NeiZhiHanShu.py
    # # cp936
    # # cp936
    # #
    # # Process finished with exit code 0
    
  • 相关阅读:
    数据库事务的四个隔离级别浅析
    Spring事务管理之几种方式实现事务
    SQL调优简介及调优方式
    Spring MVC工作流程图
    java中的垃圾回收机
    iOS 本地化-国际化-(App名字国际化)
    iOS-自建iPa应用分发平台
    稳定App缓存
    iOS-保存图片到(自定义)相册步骤
    iOS -根据网络状态加载图片
  • 原文地址:https://www.cnblogs.com/jyfootprint/p/9409919.html
Copyright © 2011-2022 走看看