Python Forum
Printing the variable from defined function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing the variable from defined function
#6
That is an odd thing to do, and I strongly advise against it. Functions should only care about the values passed, not about the name of some variable that once referenced the value. That is why you could find no information about it.

If you want your dataframes to have a name, give them a name.
df = pandas.DataFrame(...)
df.name = "some name I want associated with this dataframe"
Your "time_plot_a" dataframe might be reference by several variables at different times during its lifetime. Which one should give it a name? You are saying the only important variable is the one that was used to call the function that saves a plot? Making a plot and saving the plot to a file sounds like a useful thing. Something I would want to use over and over. By naming the file after the variable used to reference the dataframe in the function call you have placed severe restrictions on how this function can be used.

Personally, I don't think you should name the file. I would pop up a dialog asking for the user to select/enter a filename, and a file type.
Reply


Messages In This Thread
RE: Printing the variable from defined function - by deanhystad - Sep-02-2023, 10:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Variable not defined even though it is CoderMerv 3 423 Mar-28-2024, 02:13 PM
Last Post: Larz60+
  Variable for the value element in the index function?? Learner1 8 778 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 687 Nov-23-2023, 02:53 PM
Last Post: rob101
  Function parameter not writing to variable Karp 5 1,068 Aug-07-2023, 05:58 PM
Last Post: Karp
  Getting NameError for a function that is defined JonWayn 2 1,190 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 3,090 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  How to print the output of a defined function bshoushtarian 4 1,406 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  Retrieve variable from function labgoggles 2 1,103 Jul-01-2022, 07:23 PM
Last Post: labgoggles
  User-defined function to reset variables? Mark17 3 1,759 May-25-2022, 07:22 PM
Last Post: Gribouillis
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,289 Apr-05-2022, 04:55 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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