Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How to call 'self.__' outside of 'self'
-
You could add a
get_player_color()
method to your scene:class MyScene(scene.Scene): ... def get_player_color(self): return self.player_color ... the_scene = MyScene() ... print(the_scene.get_player_color())
-
This gives me the error that the player_color isn't there, but it is. :[
-
Did you assign
self.player_color
inside__init__
? If not, it won't exist! -
The problem here is that you're naming attributes/methods starting with two underscores. If the name doesn't also end with two underscores (e. g.
__init__
), the name is "mangled" internally into the form_<CLASSNAME>__<ATTRNAME>
. This name will of course only resolve correctly inside the same class, in other classes or on module level it will refer to a nonexistant name. This functionality is mainly there to avoid naming conflicts with potential subclasses. In 99.9% of all cases this is not necessary, and it is best to not use it at all.If you're trying to make an attribute or method "private" as you would in Java, that's practically impossible in Python (or Java, cough reflection cough) because there are no access modifiers.
TL;DR: Don't start non-special names with two underscores.
-
This post is deleted! -
The .pyui file doesn't seem to be included in the gist.
-
This post is deleted! -
Looks like your problem is that you update the color in an instance on HockeyScene ................
But what you actually run is a new instance without the modified colors. See comment on gist.The other problem is that your players are only defined within setup, which doesn't run until you run the scene. You should define players within
__init__
if you want those attributes to exist. See. Y comment three comments ago!I think it would make more sense to have your scene class take as arguments in
__init__
, the colors, or maybe player objects, rather than trying to modify an existing HockeyScene object from your color picker ui. -
Could you show how I could have the scene class take as arguments in
__init__
? -
When I try to do it, no colors show up at all, and the scene loads quite a bit longer.
-
Some suggestions add to gist comments.
-
This gives me the error:
AttributeError: 'tuple' object has no attribute 'title'
-
That is because a
player_color_name
is a string like 'Red' or 'Gold'. If you pass in a string with one of the color names incolor_dict
that will work better then passing in a tuple. -
This post is deleted!