实践:
1、
a,b=123,456locals()['a']=1
locals()['b']=2 场景: 画图: 时序图 汽车、轮船 两家公司分别销量
for var in ['car', 'ship']: # 默认橙色 plot_data = data.dropna(subset=[var], inplace=False) locals()['line{}a'.format(var_index)] = axs[var_index].plot(np.array(plot_data['dt']), np.array(plot_data[var]), label=dev_label) locals()['line{}b'.format(var_index)] = axs[var_index].plot(x_axis_time1, s_data[var], label=s_label)
Built-in Functions — Python 3.11.4 documentation https://docs.python.org/3/library/functions.html#locals
locals()
Update and return a dictionary representing the current local symbol table. Free variables are returned by locals()
when it is called in function blocks, but not in class blocks. Note that at the module level, locals()
and globals()
are the same dictionary.
Note
The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter.
locals()
更新并返回表示当前本地符号表的字典。 在函数代码块但不是类代码块中调用 locals()
时将返回自由变量。 请注意在模块层级上,locals()
和 globals()
是同一个字典。
备注
不要更改此字典的内容;更改不会影响解释器使用的局部变量或自由变量的值。
locals()
翻译
搜索
复制
标签:plot,符号表,index,local,symbol,current,var,data,locals From: https://www.cnblogs.com/papering/p/17478699.html