我的脚本依赖于在一分钟内加载大量变量,并在许多函数中全局使用它们。每次我在iPython中调用这个脚本,它都会再次加载它们,这需要时间
我试图通过这些调用从脚本中加载和填充函数,但是这些全局变量对脚本中的函数不可用。
它给出NameError: name 'clf' is not defined
错误消息
有没有最好的方法来重构这些代码,以便将这些全局变量保存在内存中,并让脚本使用它们?脚本加载了许多这样的变量,并将它们作为全局变量在其他函数中使用
vectorizer_title, vectorizer_desc, clf,
df_instance, vocab, all_tokens, df_dist_all,
df_soc2class_proba, dict_p2s,
dict_f2m, token_pattern, cleanup_pattern,
excluded_words = load_data_and_model(lang)
dict_token2idx_all, dict_token2idx_instance,
dist_array, token_dist_to_instance_min,
dict_bigram_by_instance, denominate,
similar_threshold = populate_data(1)
我试过之后问了这个问题
from depended_library import *
它在伊皮顿不起作用。 但与python一起使用,并在flaskwebapi中使用,它可以工作使用“from”语句导入库除了定义函数外,还执行库中函数的代码
(如果有人用iPython解释问题并提出解决方案,我会选择它作为答案。)
相关问题 更多 >
编程相关推荐