Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print variable name?
#10
As perfringo points out, that's not really possible. Once it's in the function, it's not a and b (or c and d) anymore. It's x and y. If you want the name to be available, you are going to have to store it explicitly. So if a and b are two dimensional points, you might be storing them as tuples: (2, 3) and (4, 5). To get the name out, you need to store it with the tuple. You could do a longer tuple: ('A', 2, 3) and ('B', 4, 5). You could do a dictionary: {'name': 'A', 'coord': (2, 3)} and {'name': 'B', 'coord': (4, 5)}. You could do a named tuple or even a full fledged class. But somehow you need to store the name.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
How to print variable name? - by mayadob - Oct-18-2019, 10:11 AM
RE: How to print variable name? - by mayadob - Oct-18-2019, 10:33 AM
RE: How to print variable name? - by Larz60+ - Oct-18-2019, 11:08 AM
RE: How to print variable name? - by mayadob - Oct-18-2019, 11:23 AM
RE: How to print variable name? - by perfringo - Oct-18-2019, 12:29 PM
RE: How to print variable name? - by mayadob - Oct-20-2019, 01:10 PM
RE: How to print variable name? - by mayadob - Oct-20-2019, 04:07 PM
RE: How to print variable name? - by mayadob - Oct-18-2019, 02:28 PM
RE: How to print variable name? - by ichabod801 - Oct-20-2019, 05:45 PM
RE: How to print variable name? - by ichabod801 - Oct-21-2019, 01:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Print variable without '' and spaces arnonim 1 794 Jan-30-2023, 05:23 PM
Last Post: deanhystad
  Problem with print variable in print.cell (fpdf) muconi 0 725 Dec-25-2022, 02:24 PM
Last Post: muconi
  Remove a space between a string and variable in print sie 5 1,963 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Can you print a string variable to printer hammer 2 2,108 Apr-30-2022, 11:48 PM
Last Post: hammer
  Print variable between " paulo79 5 1,819 Mar-11-2022, 05:16 PM
Last Post: deanhystad
  When I print a key from dict it prints it but when I try to assign it to a variable I stefanvelikov 3 2,460 Nov-27-2020, 01:29 PM
Last Post: stefanvelikov
  Print variable values from a list of variables xnightwingx 3 2,739 Sep-01-2020, 02:56 PM
Last Post: deanhystad
  Print part of a variable rs74 4 2,706 Jul-27-2020, 04:39 PM
Last Post: rs74
  How do I print a returned variable calculated in another function? RedSkeleton007 3 3,675 Jul-10-2018, 12:10 PM
Last Post: buran
  Empty variable when using print before readline fstefanov 3 3,778 Oct-23-2017, 02:22 AM
Last Post: fstefanov

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020