Python Forum
How to print variables in function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print variables in function?
#1
Hi, lets think function
def help():
    a = 0
    b = 1
    c = linear(x)
How to now get these variables of this functions into some kind of list. I mean by that something like this:

thisdict = {
"a": "0",
"b": "1",
"c": linear()
}

It can be also array, doesn't matter. Some kind of way how to print all variables in function and not alphabetically but in order they were created

Thank you.
Reply
#2
I don't understand your question, since you seem to have posted a solution to it: create a dict and return it?

Perhaps explain in more detail what you're really trying to achieve. Why, for instance, does it matter in which order the variables were created?
buran likes this post
Reply
#3
(Dec-31-2022, 11:26 AM)ndc85430 Wrote: I don't understand your question, since you seem to have posted a solution to it: create s dict and return it?

Perhaps explain in more detail what you're really trying to achieve. Why, for instance, does it matter in which order the variables were created?

I got it now, thank you for help
Reply
#4
(Dec-31-2022, 11:54 AM)samuelbachorik Wrote: I got it now, thank you for help

Is the solution a secret? For the benefit of other people reading this question, you should give the answer so everyone can learn from it.

The solution I would use is locals().
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 314 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  How to print the output of a defined function bshoushtarian 4 1,321 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  User-defined function to reset variables? Mark17 3 1,661 May-25-2022, 07:22 PM
Last Post: Gribouillis
  Why does absence of print command outputs quotes in function? Mark17 2 1,393 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  return vs. print in nested function example Mark17 4 1,757 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  output correction using print() function afefDXCTN 3 11,111 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  print function output wrong with strings. mposwal 5 3,137 Feb-12-2021, 09:04 AM
Last Post: DPaul
  Output with none, print(x) in function Vidar567 3 2,524 Nov-24-2020, 05:40 PM
Last Post: deanhystad
  Do I have to pass 85 variables to function? Milfredo 10 4,326 Sep-26-2020, 10:13 PM
Last Post: Milfredo
  Print variable values from a list of variables xnightwingx 3 2,651 Sep-01-2020, 02:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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