Jai*_*iah 4 github python-3.x google-colaboratory
我在 github 中有一个文件夹,其中包含文本文件,当我尝试在 Google colab 中阅读下面的代码时,出现错误
FileNotFoundError:[Errno 2]没有这样的文件或目录:' https://github.com/Jainu-s/urldata/tree/master/al?raw=true '
loc = 'https://github.com/Jainu-s/urldata/tree/master/al?raw=true'
#uploaded = files.upload()
os.chdir(loc)
filelist = os.listdir()
#print (len((pd.concat([pd.read_csv(item, names=[item[:-4]]) for item in filelist],axis=1))))
data = []
path = loc
files = [f for f in os.listdir(path) if os.path.isfile(f)]
for f in files:
with open(f,'r') as myfile:
data.append(myfile.read())
df = pd.DataFrame(data,columns=['Data'])
print (df.shape)
Run Code Online (Sandbox Code Playgroud)
import base64
import requests
master = "https://raw.githubusercontent.com/Jainu-s/urldata/master/al/abescoldbeer.com.txt"
req = requests.get(master)
req = req.text
print(req)
Run Code Online (Sandbox Code Playgroud)
通过这种方式,您可以使用 for 循环修改主字符串来读取所有文件
/sf/answers/2694803961/您可以参考此链接了解如何阅读github文件。