我想使用我传递给包含文件路径的函数的变量。但是,我没有让它工作。
例如,我有一个像"/samba-test/log_gen/log_gen/log_generator"这样的路径,当我将此路径读取到变量时,它无法按预期工作。请参考我在代码中的解释。我的评论被标记为字符串"VENK"。任何帮助将不胜感激。
/* caller */
config_path = "/samba-test/log_gen/log_gen/log_generator"ReadWrite_Config(config_path(
/*definition*/
def ReadWrite_Timeline(lp_readpath, lp_filterlist(:
current_parent_path = lp_readpath
current_search_list = lp_filterlist
print(current_parent_path) >>>>>> VENK - PATH prints fine here as expected <<<<<<<<.
strings_1 = ("2e88422c-4b61-41d7-9cf9-4650edaa4e56", "2017-11-27 16:1")
for index in range(0,3):
print (current_search_list[index])
files=None
filext=[".txt",".log"]
#outputfile = open(wrsReportFileName, "a")
for ext in filext:
print("Current_Parent_Path",current_parent_path ) <<<<<<VENK - Prints as Expected ""
#VENK - The above line prints as ('Current_Parent_Path', '/samba-test/log_gen/log_gen/log_generator') which is expected
#The actual files are inside the 'varlog' where the 'varlog' folder is inside '/samba-test/log_gen/log_gen/log_generator'
#possible problematic line below.
varlogpath = "(current_parent_path/varlog)/*"+ext >>>>>>>>>>> VENK- Unable to find the files if given in this format <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
print("varlogpath",varlogpath) >>>>>>>>>>>> VENK- varlogpath doesn't print as expected <<<<<<<<<<<<<<<<<<<<
#VENK - The above line prints as ('varlogpath', 'current_parent_path/varlog/*.txt') which I feel is problematic.
#VENK - If I give the absolute path as below it works fine
#varlogpath = "/samba-test/log_gen/log_gen/log_generator/varlog/*"+ext
files = glob.glob(varlogpath)
for file in files:
fname_varlog = open(file, 'r')
outputfile.write("n")
outputfile.write(file)
outputfile.write("n")
for line in fname_varlog:
#if any(s in line for s in strings):
"""
#s1 searches the mandatory arguments
#s2 searches the optional arguments
"""
if all(s1 in line for s1 in strings_1):
#if all(s1 in line for s1 in strings_1) or all(s2 in line for s2 in strings_2):
#print (file, end="")
outputfile.write(line)
fname_varlog.close()
outputfile.write("n")
outputfile.write("10.[##### Summary of the Issue #####] -- Enter Data Manually n")
outputfile.write("n")
outputfile.close()
#print (ext)
变量"current_parent_path"的路径连接有助于解决问题(如下所示(。
varlogpath = os.path.join(current_parent_path, "*"+ext(