第一モジュールday 5の下

6992 ワード

2.29        

1.            
2.     ,   
3.         


1.    f.open(filename)
2.    f.read(50)    50 .. 
    f.read()         ,
    f.write(YOURDATA)


3.    f.close()

----------------


                 
python    ,    、  、   3             ,      。


    


    r     

    w     ,      ,      

    a     ,          



    

f = open(file='D:/    /staff.txt',mode='w')
f.write("Alex  CEO  600
") f.write(" 5000
") f.close() f = open(file=' .txt',mode='r') print(f.readline()) # print('------ -------') data = f.read() # print(data) f.close() f = open(file=' .txt',mode='a') f.write(" 168 48
") # f.close() f = open(file=' .txt',mode='r') for line in f: line = line.split()    split , name,addr,height,weight,phone = line height = int(height) weight = int(weight) if height > 170 and weight <= 50: print(line) f.close() f.seek() .. , , 1 , 3 f.flush() , , , , gg... flush, f.close. . f.close f.tell() f.truncate(100) 0 100 , f = open(' .txt','a',encoding='utf-8') f.seek(9) print(f.tell()) f.truncate() f.truncate() , 9 , seek, , seek , 0 , ----------------------------- f.read , str f.readline str f.readlines ,, ----------------------- 2.33 w+ , , , , , 。 r+ , , , ,, , a+ , , 3 -------------- r+ f = open(' .txt','r+',encoding='utf-8') f.seek(6) f.write(" ") 456789 123456 123456789 123456 2 , 6 , , 123, . 6 , 123 ---------------