Linked Questions

10 votes
1 answer
33k views

After a bit of research I found these questions (1, 2) about variables. Similarly, I would like to know if it is possible to get the name of a list as a string in Python, for example: for a list lst =...
user avatar
0 votes
2 answers
15k views

Here bkd_train, bkd_test are dataframe. I wanted to print dataframe name along with it's shape. for data in [bkd_train, bkd_test]: print("{} : {}".format(?, data.shape)) If i am using "data" ...
Noob's user avatar
  • 174
-2 votes
2 answers
3k views

Im wondering if there is a way to take a variable's name and convert it into a string to print it? for example: myVariable = 1 i want to convert "myVariable" like the name of the variable itself not ...
ManxFox's user avatar
1 vote
0 answers
1k views

I put integers into list and then sort it: a,b,c,d,e,f = 3,6,2,8,1,2 list1=[a,b,c,d,e,f] list5.sort() Now I want to print the sorted list as string, but to see the variables, like: efcabd I can't ...
Matan's user avatar
  • 146
0 votes
0 answers
331 views

Can a Python instance get the name of the variable which is used to access the object? This example code shows what I need: foo=MyClass() foo.get_name() --> 'foo' bar=foo bar.get_name() --> '...
guettli's user avatar
  • 27.7k
2 votes
1 answer
216 views

For Python 2.7 I have a little utility for debugging: def printvar(label, var): print "%s:\n%s" % (label, pformat(var)) Often I call it like printvar("foo", foo). Is it possible to simplify that ...
Philip's user avatar
  • 2,001
0 votes
0 answers
177 views

I have a pandas DataFrame named 'data_by_month' Here is a dummy data: data = {'date' : ['1', '2','3'], 'value1' : ['a', 'b' ,'c'], 'value2' : ['12','24','4']} data_by_month = pd....
Yun Tae Hwang's user avatar
-5 votes
5 answers
275 views

I have a variable fruit = 13, when I print(fruit) I get 13. How do I print out the variable name so I get 'fruit' to print out? I don't want to have to use print('fruit') because I will be using ...
biglemon29's user avatar
0 votes
1 answer
88 views

I am working on a project that uses XML to create a Tkinter GUI and need to know how to convert an object name to a string. For example: # In the actual program, the value of widget variables is set ...
Captain Cucumber's user avatar
0 votes
0 answers
84 views

I am working with mongodb in python and want to define some functions. One function needs a collection object as well as its name represented as string. However for the user its the same name. The ...
Pluxyy's user avatar
  • 105
0 votes
0 answers
55 views

Is there a straight forward way to add a list to a dictionary? For example a = [1,2,3] d = dict(a) I have seen a way (I do not remember exactly how) that add a list to a dictionary making the name ...
Dante's user avatar
  • 1
0 votes
0 answers
32 views

in C# nameof(variable) returns "variable" cant i do something like this in python? class ClassName: someVariable = "im in love with a coco" if its a class, i can use ClassName.__name__ and this ...
softmarshmallow's user avatar
118 votes
8 answers
313k views

How do I get the name of a DataFrame and print it as a string? Example: boston (var name assigned to a csv file) import pandas as pd boston = pd.read_csv('boston.csv') print('The winner is team A ...
leo's user avatar
  • 1,705
70 votes
14 answers
55k views

I have enum and use the variables like myEnum.SomeNameA, myEnum.SomeNameB, etc. When I return one of these variables from a function, can I print their names (such as myEnum.SomeNameA) instead of the ...
user avatar
16 votes
7 answers
98k views

I find myself needing to iterate over a list made of dictionaries and I need, for every iteration, the name of which dictionary I'm iterating on. Here's an MRE (Minimal Reproducible Example). Contents ...
Gabriel's user avatar
  • 43k

15 30 50 per page