jupyter notebook怎么访问文件下的文件
时间: 2023-08-08 08:09:43 浏览: 106
Jupyter Notebook 中可以使用 Python 的 `os` 模块来访问文件夹中的文件。下面是一个简单的例子,假设你要访问 `./data/` 文件夹下的所有 `.txt` 文件:
```python
import os
# 获取文件夹路径
folder_path = './data/'
# 遍历文件夹中的文件,并打印文件名
for filename in os.listdir(folder_path):
if filename.endswith('.txt'):
# 获取文件路径
file_path = os.path.join(folder_path, filename)
# 打印文件名
print(file_path)
```
这段代码会遍历 `./data/` 文件夹下的所有 `.txt` 文件,并打印出文件路径。你可以根据自己的需要对这些文件进行操作,例如读取文件内容等。
阅读全文
相关推荐
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![ipynb](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)