Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中使用类返回数据路径_Python_Function_Class_Object_Glob - Fatal编程技术网

如何在python中使用类返回数据路径

如何在python中使用类返回数据路径,python,function,class,object,glob,Python,Function,Class,Object,Glob,我想使用python中的glob包和类将多个文件读入python。我希望我的函数采用两个参数。即,返回函数的路径和参数 这是我的尝试 import glob as g converterPath = r"C:\Users\MyfilePath" class collect_datafiles: def __init__(self,a,b): try: self.a = a self.b = g.glob(a)

我想使用python中的glob包和类将多个文件读入python。我希望我的函数采用两个参数。即,返回函数的路径和参数

这是我的尝试

import glob as g
converterPath = r"C:\Users\MyfilePath"

class collect_datafiles:
    def __init__(self,a,b):
        try:
            self.a = a
            self.b = g.glob(a)
        except:
            print("Error - While collecting InputFiles")
    def file_list(self):
        return self.b

collect_datafiles(converterPath,0)
其中,
a
是保存数据文件路径的参数,
b
是我希望函数返回的参数


但是上面的代码似乎不起作用,抛出
TypeError:collect\u datafiles()不带参数。有人能帮我解决这个问题吗?

如果你把一个类和一个函数混为一谈,你的主要问题是什么。如果要将collect_数据文件作为类保存,可以使用设置变量
a
b

file\u holder=收集数据文件()
文件\u holder.a=转换器路径

您的
\uuuuu init\uuuuu
方法拼写为
\uuuuu initi\uuuu
,因此在初始化时它不会接受任何参数。我认为你不应该为此使用
,除非它是
类DataFileManager
我不认为“b”在你的类中任何地方都使用,也不需要。self.b即使没有b也存在。