1
我有一个函数,它接受一个变量作为参数。该变量恰好包含一个目录,也包含一堆txt文件。获取参数名称作为字符串 - Python
我想知道是否有一种方法将该变量视为一个字符串?不是变量内部的内容,只是该变量的名称。 非常感谢!
import glob
import pandas as pd
variable_1 = glob.glob('dir_pathway/*txt')
variable_2 = glob.glob('other_dir_pathway/*txt')
def my_function(variable_arg):
## a bunch of code to get certain things from the directory ##
variable_3 = pd.DataFrame(## stuff taken from directory ##)
variable_3.to_csv(variable_arg + "_add_var_to_me.txt")
所以你基本上要的功能'name_of_var'所以'a = 1; name_of_var(a)'返回'a'? –
http://stackoverflow.com/a/1373185/918959? –