python 類,python筆記03_IO編程

 2023-10-20 阅读 24 评论 0

摘要:? with open('/path/to/file', 'r') as f: print(f.read()) f.write('Hello, world!') f.close() StringIO() f = BytesIO() f.write('中文'.encode('utf-8')) print(f.getvalue()) >>> import os >>> os.name

?

with open('/path/to/file', 'r') as f:  print(f.read())  f.write('Hello, world!')  f.close()  
StringIO()  
f = BytesIO()  
f.write('中文'.encode('utf-8'))  
print(f.getvalue())  >>> import os  
>>> os.name # 操作系統類型  
>>> os.uname()  
>>> os.environ  
>>> os.environ.get('PATH')  
os.path.abspath('.')  
os.path.join('/Users/michael', 'testdir')  
os.mkdir('/Users/michael/testdir')  
os.rmdir('/Users/michael/testdir')  
os.path.split('/Users/michael/testdir/file.txt')  
os.path.splitext()  
os.rename('test.txt', 'test.py')  
os.remove('test.py')  
[x for x in os.listdir('.') if os.path.isdir(x)]  
[x for x in os.listdir('.') if os.path.isfile(x) and os.path.splitext(x)[1]=='.py']  pickle.dumps(d)  
>>> f = open('dump.txt', 'wb')  
>>> pickle.dump(d, f)  d = pickle.load(f)  
>>> f.close()  
>
print(json.dumps(s, default=lambda obj: obj.__dict__))  

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/150749.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息