r+: Open for reading and writing. The stream is positioned at the beginning of the file. w+:Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the f
%r用rper()方法处理对象 %s用str()方法处理对象 有些情况下,两者处理的结果是一样的,比如说处理int型对象. 例一: print "I am %d years old." % 22 print "I am %s years old." % 22 print "I am %r years old." % 22 I am 22 years old. I am 22 years old. I am 22 years old. 另外一些情况
# \r 默认表示将输出的内容返回到第一个指针,这样的话,后面的内容会覆盖前面的内容 def main(): for i in range(65,91): s="\r{name:s}".format(name=chr(i)) time.sleep(0.5) sys.stdout.write(s) main() # r 的用法 s="\tt" #如果这样输出的话,则\t会变成制表符号,将有一个table键作用产生 ns=r"\tt" print(s
%r是rper()方法处理的对象 %s是str()方法处理的对象 其实有些情况下,两者处理的结果是一样的,比如说处理数据类型为int型对象: 例如1: print ('I am %d year old.' % 22) print ('I am %s year old.' % 22) print ('I am %r year old.' % 22) 返回的结果: I am 22 year old. I am 22 year old. I am 22 year old. 另外的话有一些情况两者就不同
python中也有文件读写,通过调用内置的读写函数.可以完成文件的打开/关闭.读.写入.追加等功能. open()函数 open()函数为python中的打开文件函数,使用方式为: f = open("[文件绝对路径]",'[文件使用模式') 以 f = open('/home/user/lina/info_lina.txt','r')为例,我们在linux环境中以r(只读模式)打开/home/user/lina/info_lina.txt的文件,此处路径也可以为相对路径,相对于本程序