第23講 python的讀操作基礎

2021-09-20 19:19:26 字數 526 閱讀 1101

a=file_obj.read() 預設讀全部

b=file_obj.read(15) 唯讀15個字元

help(file.read)  檢視幫助

eg2:

file_obj=open('test.txt','r')

line1=file_obj.readline()

print 'line1:',line1   #me:print的逗號表示列印在同一行,輸出為空格

line2=file_obj.readline()

print 'line2:',line2

list1=file_obj.readlines()-----返回列表(a list of string)

print 'list1:',list1

readline()讀回來的字串後缺省會有乙個'\n',所以去掉則不會列印多餘的空行了

line1=file_obj.readline() ###讀一行

line1=line1.rstrip('\n') ###去除這行最右端的回車換行符

第24講 python檔案的寫操作基礎

write 寫字串 writelines 寫字串序列 序列 一堆字串,逗號隔開。例如 字典 列表 元組 file obj.write content obj content obj n me 如果不加 n 則寫入的內容不換行 eg1 file obj open test.txt w 檔案存在則開啟,...

第23講 專案五 我的加班費

任務和 檔名稱 main.c 作 者 胡先軍 完成日期 2015年5月3日 版 本 號 v1.0 問題描述 小賀剛上班,按工作時間小時制領取周工資,工資標準是,每小時rate元rmb。每週工作時間40小時,如果要加班,超出部分按正常工資的1.5倍計。這周小賀上班的時間為hour小時,請程式設計序,輸...

python的多執行緒 第24講

author michal date 2019 9 10 from multiprocessing import process import os def obj i print 1111子程序 os.getpid print 會有多個程序執行我 i,os.name if name main li...