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?
#1
Hi all,

A general outline of my program could be written as something like this:

Variable initiation (reset)

Control branch A

    if...

    elif...

    elif...

    else...
        ...
        Variable reset

Control branch B

    if...

    elif...

    else...
        ...
        Variable reset
Variable initiation and reset simply assign particular variables to 0, empty lists, etc. Because it's done in multiple places, I'm thinking about creating a user-defined function where the variables common to all three places are reset to 0.

If I were to do such a thing, how would I handle variable scope? The variables reset in the function need to be available throughout the main program.

Finally, do you think this is even worth doing?

I have ~50 variables in this program and maybe 30 would be reset as part of the function.
Reply


Messages In This Thread
User-defined function to reset variables? - by Mark17 - May-25-2022, 02:31 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 686 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,524 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  How to print variables in function? samuelbachorik 3 980 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,204 Dec-25-2022, 03:00 PM
Last Post: askfriends
  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,086 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
  Multiple user defined plots with secondary axes using for loop maltp 1 1,577 Apr-30-2022, 10:19 AM
Last Post: maltp
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,586 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  Setting permanent user variables in Windows coder420 2 1,482 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