1. 使用`print`函数:
```python
with open('file.txt', 'r') as file:
content = file.read()
print(content)
2. 使用`write`方法:
```python
with open('file.txt', 'w') as file:
file.write('Hello, Python!')
3. 使用`readlines`方法逐行输出:
```python
with open('file.txt', 'r') as file:
lines = file.readlines()
for line in lines:
print(line, end='')
4. 使用`print`函数将内容输出到指定文件:
```python
with open('output.txt', 'w') as file:
print('Hello, Python!', file=file)
5. 使用`sys.stdout`重定向输出到文件:
```python
import sys
with open('output.txt', 'w') as file:
sys.stdout = file
print('Hello, Python!')
sys.stdout = sys.__stdout__ 恢复默认的标准输出
请根据你的需求选择合适的方法。