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? –