[wxPython-users] Re: "Pushing" Data to Modules -- SOLVED!

Werner F. Bruhin werner.bruhin at free.fr
Mon Dec 4 07:43:18 PST 2006


Hi Chris,

Chris Mellon wrote:
> On 12/4/06, Werner F. Bruhin <werner.bruhin at free.fr> wrote:
>
>> Or use strings everywhere and forget to predefine them in your 
>> configdata.
>
> I agree with this one - it's especially common for people coming from
> C/C++ (I did this too for a long time) to feel the need to define
> "constants" for values. That's because you have to use integers as
> constants and magic-numbers are a bad idea, for lots of good reasons.
> In Python, you can use anything you want as a constant, and I prefer
> to just take the name I'd use as a symbolic constant and use it as a
> string instead. So instead of defining a PropertyChanged constant and
> pubsubbing that, I'd just use the string "PropertyChanged".
>
> The exception case is when I need an enumerated type. For example,
> I've got a class shows itself as being in one of 3 states. In that
> case, the 3 possible states are constants defined as class attributes
> - but they're string values, so if you need to display the state in
> the UI, you just print the state - no fancy mappings needed.
I just wanted to say that one has to stay consistent.  I for one prefer 
constants for the use with pubsub, just because I make to many typing 
mistakes.

With pubsub doing this:
   Publisher().sendMessage('projopen', data=None)

Note the case, it will kind of work, except that the subscriber will 
never see it and it might take some time for me to catch on.

But doing:
   Publisher().sendMessage(configData.projopen, data=None)

Will cause an exception when this line is hit, as "projopen" is not defined.

Werner
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
>
>






More information about the wxpython-users mailing list