Python Forum
User-defined function to reset variables?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User-defined function to reset variables?
#2
(May-25-2022, 02:31 PM)Mark17 Wrote: I'm thinking about creating a user-defined function where the variables common to all three places are reset to 0.
This is why classes were invented: to group in a single entity variables shared by different places. So create a class (or several classes) to hold the variables
class Foo:
    def __init__(self):
        self.reset()

    def reset(self):
        self.baz = 10
        self.bar = 'hello'
        self.spam = 3.14159

foo = Foo()
...
...
if ...:
    ...
    foo.reset()
Reply


Messages In This Thread
RE: User-defined function to reset variables? - by Gribouillis - May-25-2022, 03:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 765 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,689 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  How to print variables in function? samuelbachorik 3 1,073 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,294 Dec-25-2022, 03:00 PM
Last Post: askfriends
  Getting NameError for a function that is defined JonWayn 2 1,247 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 3,278 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  How to print the output of a defined function bshoushtarian 4 1,465 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  Multiple user defined plots with secondary axes using for loop maltp 1 1,652 Apr-30-2022, 10:19 AM
Last Post: maltp
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,649 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  Setting permanent user variables in Windows coder420 2 1,533 Jan-04-2022, 10:42 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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