首页 > 解决方案 > 在字符串的基础上给数组一个不同的名称

问题描述

正如您在标题中所读到的,我想在 Python 中的另一个字符串变量的基础上为数组指定一个特定名称。我是 python 新手,但我已经知道 JS

这是我的一段代码:

bot = Bot()
chosenusers = bot.read_list_from_file(args.filepath) #enderlxxvii

if not chosenusers:
    exit()
else:
    print("Found %d users in file." % len(chosenusers))

bot.login(username=args.u, password=args.p, proxy=args.proxy)

bot.follow_users(chosenusers)
for x in chosenusers:
    followers = bot.get_user_followers(x)  #Array

我希望将数组称为 enderlxxviifollowers 或类似的名称,希望您能理解我的意思。

标签: python

解决方案


这种情况的一般答案是:

globals()["new_var_name"] = old_var_name

你可以从任何你想要的地方获得 new_var_name,假设那是你正在寻找的。


推荐阅读