python - How to return a data path using class in python
问题描述
I want to read in multiple files into python using a glob package and class in python. I want my function to take two parameters. Namely, a path and a parameter that the function that returns.
Here is my attempt.
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)
Where a
is an argument that holds a path of the data files and b
is an argument that I want the function to return.
But the above code doesn't seem to work and throwing TypeError: collect_datafiles() takes no arguments
. Can anyone help me with how to solve this problem?
解决方案
如果您将一个类与一个函数混淆,那么您的主要问题是。如果您想将您的 collect_datafiles 保留为一个类,您可以设置变量a
并b
使用
file_holder = collect_datafiles()
file_holder.a = converterPath
推荐阅读
- shell - 如何在嵌套在 sed 命令中的 echo 命令中转义 $
- javascript - 如何从数据表中获取选定的行数据并以 JSON 格式发送?
- python - 在 VS Code 调试模式下获取不正确的环境变量?
- python - 如何根据 B 列中的特定值找到 A 列中一组记录的最小值?
- ios - iOS:来自 Photoshop 的不同 HUE 颜色
- angular - Angular Flex & Material:根据屏幕大小隐藏按钮属性
- matlab - 如何使用非标量大小的变量预先分配表?
- sql - 格式化百分比 SQL - EXCEL ssis
- c# - TableLayoutPanel 的行索引顺序与显示的内容有误吗?
- r - R语言中方程的敏感性分析