[英]How do I open a directory (folder) then open a file in the directory - discord.py
How do I open a directory (Folder) then open a file in the directory?如何打开目录(文件夹)然后打开目录中的文件?
you can open the file directly with open(path)您可以直接使用open(path)打开文件
For Example(1):例如(1):
file = open('file.txt','r')
print(file.read())
file.close()
Or if you wish to see all files in a current directory you can see with the help of OS module.或者,如果您希望查看当前目录中的所有文件,您可以在OS模块的帮助下查看。
For Example(2):例如(2):
import os
dir_list = os.listdir()#for getting all files n folder in the current path
it will show all the files n folders name in list format.它将以列表格式显示所有文件 n 文件夹名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.