We are about to switch to a new forum software. Until then we have removed the registration on this forum.
The more I use python the more I dislike it. It seems really great at the start. But so many things are so shit.
Anyway, this works great:
class Foo:
def __init__(self):
global BAR
BAR = -1
class Bananas(Foo):
def __init__(self):
Foo.__init__(self)
print str(BAR)
if __name__ == "__main__":
b = Bananas()
But how can I do the same, but having Foo in it's own file?
Answers
Here is a slight varation:
my_lib.py:
main.py:
But I really don't want to type Foo.BAR but just type BAR! Whatever I try, there is always breaking one things.
https://en.Wikipedia.org/wiki/Zen_of_Python
class
Foo.Foo.
in order to affirm it belongs to thatclass
, and it's not a mere variable or something else. :-\"Foo.BAR
too:self.BAR
global
variable doesn't lose its original object's reference when using operators w/=
in your previous post: L-)https://forum.Processing.org/two/discussion/22610/create-a-library-that-can-be-used-global#Item_2
This conflicts with the first one:
Just to clarify: I do not follow Python's "zenness"! >:)
I very much prefer cleverness over puritanism. :ar!
And I love we don't need to prefix everything w/
this.
in Java! ~O)Also I really love curly braces!
Hmm... I don't care about curly braces and semicolons. :>
@GoToLoop How do ppl keep track of function scopes without curly brackets? Even if the IDE does some job for you, if you extends beyond the number of line your display can output, how would you match scopes? Are you tie to use specific IDEs? I wonder how would emacs handle python coding...
Kf
Via indentations! Even simple text editors like NotePad2 keeps the current indentation after an ENTER key press. =P~
Hmmm if you have multiple nested if statements... how do you keep track and ensures you are in the right scope? I should probly check it out but I am not keen in working in python at the moment. Having no curly brackets just make my eyes spin 8-|
Kf
Multiple nested branches are bad.
Big sections can be replaced by function calls though.
For really long 1s,
switch () / case:
is another option.Although I guess
switch () / case:
doesn't exist in Python. 3:-O"I dunno ... whitespace?"