Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 3.x \n显示在文件路径中,即使未给出_Python 3.x - Fatal编程技术网

Python 3.x \n显示在文件路径中,即使未给出

Python 3.x \n显示在文件路径中,即使未给出,python-3.x,Python 3.x,我试图从csv文件中读取文件路径,并将其存储为变量形式。该函数正确读取路径,但当我使用该变量时,它会在文件路径中添加一个额外的“\n”。这是我的密码 `def input_path(input_file): next(input_file) for line in input_file: row_heading = line.split(",") input_path_value = row_hea

我试图从csv文件中读取文件路径,并将其存储为变量形式。该函数正确读取路径,但当我使用该变量时,它会在文件路径中添加一个额外的“\n”。这是我的密码

    `def input_path(input_file):
         next(input_file)

         for line in input_file:
             row_heading = line.split(",")
             input_path_value = row_heading[0]
             weather_file_path = row_heading[1]

         return input_path_value, weather_file_path`

我得到以下错误:

为什么不同的变量名
行标题
行标题
行标题
。这是一个错误还是你想要的方式?对不起,这是我的打字错误。我更正了您可能想查看
strip()
函数,以及
os.path.join()
。您最好使用内置的csv模块;例如,这避免了使用引号逗号的问题;或者新行。