Python Forum
How to use global value or local value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use global value or local value
#3
(Jan-10-2023, 08:55 PM)sabuzaki Wrote: This is what I have currently. The class copies value from other class.
You are confusing code that goes in the body of the class with code that must be executed by instances of the class (in the methods of the class). If you write var = Bridge.var in the body of class Port, this code will be executed only once, it will not be executed by every instance of Port.

Learn the difference between classes and instances. Variables defined in the body of the classes are class variables. They are shared by all the instances.
Reply


Messages In This Thread
RE: How to use global value or local value - by Gribouillis - Jan-11-2023, 05:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  It's saying my global variable is a local variable Radical 5 1,315 Oct-02-2023, 12:57 AM
Last Post: deanhystad
  Delete all Excel named ranges (local and global scope) pfdjhfuys 2 1,954 Mar-24-2023, 01:32 PM
Last Post: pfdjhfuys
  Global variables or local accessible caslor 4 1,114 Jan-27-2023, 05:32 PM
Last Post: caslor
  Global vs. Local Variables Davy_Jones_XIV 4 2,732 Jan-06-2021, 10:22 PM
Last Post: Davy_Jones_XIV
  Global - local variables Motorhomer14 11 4,401 Dec-17-2020, 06:40 PM
Last Post: Motorhomer14
  from global space to local space Skaperen 4 2,404 Sep-08-2020, 04:59 PM
Last Post: Skaperen
  local / global lists RedWuff 1 1,929 May-26-2020, 03:11 AM
Last Post: deanhystad
  Question regarding local and global variables donmerch 12 5,270 Apr-12-2020, 03:58 PM
Last Post: TomToad
  local/global variables in functions abccba 6 3,546 Apr-08-2020, 06:01 PM
Last Post: jefsummers
  modifying variables in local or global space Skaperen 2 2,298 Aug-14-2019, 07:13 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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