fname = input ( "请输入要写入的文件: " ) fo = open ( fname , "w+" ) ls = [ "AAA" , "BBB" , "CCC" ] fo . writelines ( ls ) for line in fo : print ( line ) fo . close ()
B.
fo = open ( "price2016bj.csv" , "w" ) ls = [ 'AAA' , 'BBB' , 'CCC' , 'DDD' ] fo . write ( "," . join ( ls ) + "\n" ) fo . close ()
C.
fr = open ( "price2016.csv" , "w" ) ls = [] for line in fo : line = line . replace ( "\n" , "" ) ls . append ( line . split ( "," )) print ( ls ) fo . close ()
D.
fo = open ( "price2016bj.csv" , "r" ) ls = [ 'AAA' , 'BBB' , 'CCC' , 'DDD' ] fo . write ( "," . join ( ls ) + "\n" ) fo . close ()