Python写文件

5年以前  |  阅读数:1621 次  |  编程语言:Python 
# 写文件
>>> with open('new_file.txt',mode='w',encoding='utf-8') as f:
      w = f.write('I love python\n It\'s so simple')
      os.listdir()


['drinksbycountry.csv', 'IMDB-Movie-Data.csv', 'movietweetings', 'new_file.txt', 'test.csv', 'titanic_eda_data.csv', 'titanic_train_data.csv', 'train.csv']
>>> with open('new_file.txt',mode='r',encoding='utf-8') as f:
      o = f.read()
      print(o)

I love python
 It's so simple

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8