Hey all,
I've been a C/C# dev for a while and am tackling a fun side project at work for a Slack bot written in Python, which i have basically no experience in. It's been fun so far.
I have a question about classes and how global var's work in them. Psudocode below.
Let's say I have example.py:
And from test.py
On server.printexample() am I going to get 5, or 6? And why?
I've been a C/C# dev for a while and am tackling a fun side project at work for a Slack bot written in Python, which i have basically no experience in. It's been fun so far.
I have a question about classes and how global var's work in them. Psudocode below.
Let's say I have example.py:
Code:
example = 5
class Client(object):
def printexample():
print example
example = example + 1
class Server(object):
def printexample():
print example
example = example + 1
And from test.py
Code:
from example import *
client = Client()
server = Server()
client.printexample()
server.printexample()
On server.printexample() am I going to get 5, or 6? And why?