python txt文件
时间: 2023-11-08 19:02:06 浏览: 164
python.txt
您好!在Python中,您可以使用以下代码读取和写入文本文件:
1. 读取文本文件:
```python
with open('file.txt', 'r') as file:
content = file.read()
print(content)
```
2. 写入文本文件:
```python
content = "Hello, World!"
with open('file.txt', 'w') as file:
file.write(content)
```
阅读全文