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
#4
Hi,
Yes, the above could work even without super when having one bridge. So below is more simple. Instance adds its variable and uses local version. when deleted it will use global class variable. But problem is - how to have multiple bridges with different value? So we have port1/2/3/4 created from Bridge1 with class/"global" value of 1 and we want another Bridge with ex value 2 and other ports having that 2 global value.

Let's say scenario: We have hundreds of houses each having different internet speed: 5Mbps/100Mbps/25Mbps (so we have a class for each house). Then we have rooms/people in each house. If that person/room has a faster internet speed (lets say room1 for the house5), that room/person should not use houses internet, it should use it's own faster internet.... (use room variable rather than global house variable)

class bridge:
   var = 1
class port(bridge):
   def update_var(self,v):
       self.var = v
   def delete_var(self):
       del self.var

port1 = port()
port2 = port()
print(port1.var)
print(port2.var)
port2.update_var(3)
print(port2.var)
port2.delete_var()
print(port2.var)
Reply


Messages In This Thread
RE: How to use global value or local value - by sabuzaki - Jan-11-2023, 09:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  It's saying my global variable is a local variable Radical 5 1,319 Oct-02-2023, 12:57 AM
Last Post: deanhystad
  Delete all Excel named ranges (local and global scope) pfdjhfuys 2 1,974 Mar-24-2023, 01:32 PM
Last Post: pfdjhfuys
  Global variables or local accessible caslor 4 1,116 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,402 Dec-17-2020, 06:40 PM
Last Post: Motorhomer14
  from global space to local space Skaperen 4 2,405 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,271 Apr-12-2020, 03:58 PM
Last Post: TomToad
  local/global variables in functions abccba 6 3,547 Apr-08-2020, 06:01 PM
Last Post: jefsummers
  modifying variables in local or global space Skaperen 2 2,299 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