About 472,000 results
Open links in new tab
  1. Getting the name of a variable as a string - Stack Overflow

    Aug 25, 2013 · I already read How to get a function name as a string?. How can I do the same for a variable? As opposed to functions, Python variables do not have the __name__ attribute. In …

  2. How to get the value of a variable given its name in a string?

    Oct 23, 2015 · And if you want to use this method to get a value in the same module that you are calling getattr(), use import sys; sys.modules[__name__] to get a reference to the current module.

  3. Getting name of a variable in Python - Stack Overflow

    Oct 3, 2020 · There's .__name__ property for getting name of a function or a type object that variable holds value of, but is there anything like this for getting name of a variable itself?

  4. python - Using a string variable as a variable name - Stack Overflow

    Jul 19, 2012 · I have a variable with a string assigned to it and I want to define a new variable based on that string.

  5. python - Convert Variable Name to String? - Stack Overflow

    I checked this question because, using RPy2, I want to pass a Python variable with an eponymous R name. A useless (but close to my application) example: def to_R( py_var ): …

  6. python - How to get the variable name as string from an array of ...

    Dec 6, 2021 · It is actually quite tricky to get variable name of an object in python. name->object mapping is strictly one-way. What makes it worse, multiple names can refer to the same object …

  7. python - How to get the original variable name of variable passed …

    May 1, 2010 · Since you can have multiple variables with the same content, instead of passing the variable (content), it might be safer (and will be simpler) to pass it's name in a string and …

  8. How do I get a substring of a string in Python? - Stack Overflow

    Aug 31, 2016 · And just for completeness, Java is like Python in that the String.substring () method takes start and one-past-end. This one just bit me hard, I had assumed it was length …

  9. python - How can I get the name of an object? - Stack Overflow

    61 Objects do not necessarily have names in Python, so you can't get the name. When you create a variable, like the x, y, z above then those names just act as "pointers" or "references" to the …

  10. Variable name to string in Python - Stack Overflow

    Oct 2, 2012 · I have written some code in Python and I would like to save some of the variables into files having the name of the variable. The following code: variableName1 = 3.14 …