【问题标题】:Python: Convert Name of a Variable or Variable's Property into a StringPython:将变量或变量属性的名称转换为字符串
【发布时间】:2018-02-14 09:17:05
【问题描述】:

我很确定在 Python 中有一种方法可以做到这一点,但我找不到方法。感谢您的帮助。

  • Customer.Name (Variable.Property)

希望直接在代码中使用属性名称,而不是硬编码。

colName = Customer.Name.*toString()*  
dataframe.drop(colName, 1)

【问题讨论】:

标签: python string pandas


【解决方案1】:

如何做到这一点非常简单。只需使用str() 函数。 例如:

vbl = True
print(str(bvl))
True

【讨论】:

  • 感谢您的回复。想知道我如何实现以下目标:vbl = Trueprint(str(vbl))vbl 这意味着我可以打印变量的名称(在这种情况下为“vbl”),而不是打印变量的内容。跨度>
【解决方案2】:
Customer.Name(str(Variable.Property))

【讨论】:

    猜你喜欢
    • 2011-10-31
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 2014-05-01
    相关资源
    最近更新 更多