我正在尝试用Python运行一个程序来运行一个模块来处理smartwatch中的数据。我以前让它工作过,但是我更改了filepath变量,现在不管我怎么做,我都无法让它工作
我是mac用户,当我尝试在终端中运行脚本时,出现以下错误:
Traceback (most recent call last):
File "Descentlog_manual.py", line 53, in <module>
fitfilelist = FitFileList(directory = '/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands')
File "Descentlog_manual.py", line 21, in __init__
for fitfilename in os.listdir(self.directory):
FileNotFoundError: [Errno 2] No such file or directory: '/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands'
(base) Edwards-MBP:FarneIslands edwibberley$ python Descentlog_manual.py
/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands
从这里的其他答案来看,大多数人似乎通过使用绝对文件路径而不是相对文件路径来解决问题,但我看不出这是我的问题。当我使用pwd目录时,我会得到代码中包含的文件路径,这样我就看不出哪里出错了
下面是我的脚本代码
import os
class FitFile:
def __init__(self,name,maxtime=2,nonumber=True,apnea=False):
self.name = name
self.maxtime = maxtime
self.nonumber = nonumber
self.apnea = apnea
class FitFileList:
def __init__(self,directory):
self.fitfilelist = []
self.directory = directory
for fitfilename in os.listdir(self.directory):
if os.path.isfile(fitfilename) == True and fitfilename.endswith('.fit'):
self.fitfilelist.append(fitfilename)
def ProcessFitFiles(fitfilelist):
for files in fitfilelist.fitfilelist:
fit_file = FitFile(name = files)
#currently setup to produce a seperate .xml file for each dive, minimum time threshold will be taken from above
from fit2subsEW_module import settings
settings.fit_files = [fit_file.name]
settings.out_subslog = fit_file.name + '.xml'
settings.min_time = fit_file.maxtime
settings.no_numbering = fit_file.nonumber
settings.apnea = fit_file.apnea
print('fit file settings', settings.fit_files)
print('fit file type',type(settings.fit_files))
settings.check_settings()
from fit2subsEW_module import start_processing
start_processing()
fitfilelist = FitFileList(directory = '/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands')
ProcessFitFiles(fitfilelist)
任何帮助都将不胜感激,因为我一直在这个问题上兜圈子,一无所获
编辑-@Osmann Durdag
当我尝试您的第二个解决方案时,我收到以下错误消息:
(基本)Edwards MacBook Pro:FarneIslands edwibberley$python Descentlog_manual.py回溯(最后一次调用):文件“Descentlog_manual.py”,第54行,在fitfilelist=fitfilelist(directory='/Users/edwibberley/Garmin_dence_FIT_process/FarneIslands)的init文件“Descentlog_manual.py”第23行(self.directory):FileNotFoundError:[Errno 2]没有这样的文件或目录:'/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands(基本)Edwards MacBook Pro:FarneIslands edwibberley$python Descentlog_manual.py/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands Traceback(最后一次调用):文件“Descentlog_manual.py”,第54行,在fitfilelist=fitfilelist(目录='/Users/edwibberley/Garmin_descent_process/FarneIslands')文件“Descentlog_manual.py”中,第22行,在初始打印(os.listdir(self.directory))文件NotFoundError:[Errno 2]没有这样的文件或目录:'/Users/edwibberley/Garmin_descent_FIT_process/FarneIslands'(基本)爱德华兹MacBook Pro:FarneIslands Edwibbelley美元
在该文件中,仅限文件名,必须将此文件名添加到目录中。我想这对你有帮助
如果再次出现任何错误,请执行此操作并再次共享此打印结果:
请尝试一下:
或:
相关问题 更多 >
编程相关推荐