WindowsError:[错误3]系统找不到指定的路径:

2024-09-27 17:55:17 发布

您现在位置:Python中文网/ 问答频道 /正文

WindowsError:[错误3]系统找不到指定的路径: 我正在尝试将文件目录分配给基路径,这样其他代码就可以完成它的工作了。在

Also let me know if you think there should be a : at the end of this line of code-----> 
for file in sorted(os.listdir(path)) 
i think should be ....
for file in sorted(os.listdir(path)):
the book doesnt have the : at the end

import pyprind #INSTALLED IN ANACONDA TERMINAL 
import pandas as pd
import os

# change the 'basepath' to the directory of unzipped movie dataset

#tried:
#basepath = 'C:\\Users\\zacka\\Downloads\\aclImdb_v1.tar.gz'
#basepath = 'C://Users//zacka//Downloads//aclImdb_v1.tar.gz'
#basepath = 'C:/Users/zacka/Downloads/aclImdb_v1.tar.gz'
#basepath = 'C:\Users\zacka\Downloads\aclImdb_v1.tar.gz'
#not sure if im using the back slash or forward slash incorrectly or if i #need to double up....


labels = {'pos': 1, 'neg': 0}
pbar = pyprind.ProgBar(50000)
df = pd.DataFrame()
for s in ('test', 'train'):
    for l in ('pos', 'neg'):
        path = os.path.join(basepath, s, l)
        for file in sorted(os.listdir(path))
            with open(os.path.join(path, file), 
                      'r', encoding='utf-8') as infile:
                txt = infile.read()
            df = df.append([[txt, labels[1]]],
                           ignore_index=True)
            pbar.update()
df.columns = ['review', 'sentiment']

Tags: thepathindfforosdownloadstar
1条回答
网友
1楼 · 发布于 2024-09-27 17:55:17

basepath='C:\\Users\\zacka\\Downloads\\aclImdb'

双反斜杠是必要的,尤其是在“。。。。Downloads\\aclImdb'我尝试了不带双反斜杠的print(basepath),它为aclImdb中的字符a生成0x7。在

我还将basepath=设置为压缩文件夹,而不是解压缩文件夹。在

现在我需要弄清楚: TypeError:“encoding”是此函数的无效关键字参数 用于编码=“utf-8”

相关问题 更多 >

    热门问题