# Python 文件读写

基本文件读写，写入 "test" 到 "/tmp/test.txt"，再次打开读取

请选出下列能**正确**实现这一功能的选项。

## template

```python
if __name__ == '__main__':
    with open('/tmp/test.txt', 'w') as f:
        f.write("test")
    with open('/tmp/test.txt', 'r') as f:
        print(f.read())
```

## 答案

```python
if __name__ == '__main__':
    with open('/tmp/test.txt', 'w') as f:
        f.write("test")
    with open('/tmp/test.txt', 'r') as f:
        print(f.read())
```

## 选项

### A

```python
if __name__ == '__main__':
    with open('/tmp/test.txt', 'r') as f:
        f.write("test")

    with open('/tmp/test.txt', 'w') as f:
        print(f.read())
```

### B

```python
if __name__ == '__main__':
    with open('/tmp/test.txt', 'r') as f:
        f.write("test")

    with open('/tmp/test.txt', 'r') as f:
        print(f.read())
```

### C

```python
if __name__ == '__main__':
    f = open('/tmp/test.txt', 'w'):
    f.write("test")
        
    f = open('/tmp/test.txt', 'r'):
    print(f.read())
```
