D
DaveM
Although I've programmed for fun - on and off - since the mid 70's, I'm
definitely an OO (and specifically Python) beginner.
My first question is about global variables. Are they, as I'm starting to
suspect, a sin against God or just best avoided? Having got my current
application working using them, I'm not sure whether I want to refactor it,
but equally, I'd like to write the best code I can.
Secondly (and this is related), if you have multiple instances of the same
class, but need them all to have access to a dictionary created at run-time,
is there a class way to this without calling the creation method multiple
times? The best thought I've come up with is for the class instance to check
its name and only if it's the first one do the dictionary creation, but I
haven't tried it yet.
My third difficulty is with variables in a class. What's the difference
between the following?:
class Foo:
i = 12345
...
class Foo:
self.i = 12345
...
class Foo:
def __init__(self):
self.i = 12345
...
class Foo:
def __init(self):
i = 12345
...
DaveM
definitely an OO (and specifically Python) beginner.
My first question is about global variables. Are they, as I'm starting to
suspect, a sin against God or just best avoided? Having got my current
application working using them, I'm not sure whether I want to refactor it,
but equally, I'd like to write the best code I can.
Secondly (and this is related), if you have multiple instances of the same
class, but need them all to have access to a dictionary created at run-time,
is there a class way to this without calling the creation method multiple
times? The best thought I've come up with is for the class instance to check
its name and only if it's the first one do the dictionary creation, but I
haven't tried it yet.
My third difficulty is with variables in a class. What's the difference
between the following?:
class Foo:
i = 12345
...
class Foo:
self.i = 12345
...
class Foo:
def __init__(self):
self.i = 12345
...
class Foo:
def __init(self):
i = 12345
...
DaveM