Python 使用不同的参数多次调用函数
我有这个csv文件(原始文件更大,有更多的开始和结束部分): 现在我想通过一个函数调用它几次。参数始终具有不同的名称,并且返回名称也应始终不同Python 使用不同的参数多次调用函数,python,Python,我有这个csv文件(原始文件更大,有更多的开始和结束部分): 现在我想通过一个函数调用它几次。参数始终具有不同的名称,并且返回名称也应始终不同 def function1(begin, end): with open ('test3a.csv', encoding="latin-1") as csvfile: func_dict = dict() for line in csvfile: line = line.rstrip().r
def function1(begin, end):
with open ('test3a.csv', encoding="latin-1") as csvfile:
func_dict = dict()
for line in csvfile:
line = line.rstrip().rstrip(";")
if line.endswith(begin):
pass
elif line.endswith(end):
break
else:
key, value = line.split(";")
func_dict[key] = value
#print(value)
return func_dict
global_dict = function1('global_begin', 'global_end')
source_dict = function1('src_db_begin', 'src_db_end')
交车和/或通话有什么问题?这看起来不像csv文件。当你说你想多次“调用”它时,你不清楚你的意思。是的,这个文件不是逗号分隔的。我的意思是,我用不同的参数多次调用这个函数。在我的帖子中,使用全局和源代码调用函数
def function1(begin, end):
with open ('test3a.csv', encoding="latin-1") as csvfile:
func_dict = dict()
for line in csvfile:
line = line.rstrip().rstrip(";")
if line.endswith(begin):
pass
elif line.endswith(end):
break
else:
key, value = line.split(";")
func_dict[key] = value
#print(value)
return func_dict
global_dict = function1('global_begin', 'global_end')
source_dict = function1('src_db_begin', 'src_db_end')