ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> wxpython-users
wxpython-users
Re: [wxpython-users] Py works, EXE doesn't here is stripped program, someone else verify please.
by Tim Roberts other posts by this author
Jul 18 2008 11:16AM messages near this date
Re: [wxpython-users] Py works, EXE doesn't here is stripped program, someone else verify please. | [wxpython-users] remove image of a tree item
Steve Freedenburg wrote:
> 
>  I will attach the py file, the configuration file that TopiView makes 
>  when the user
>  sets it up, so you can see that too,  the "help" file which is as 
>  close to a __doc__
>  as could be, and a short wav file that will play when TopiView matches a
>  search string.  Small files really, maybe 85kb.

But, can't you see how wasteful this code is?  If you want to add a 7th 
string, you have to make modifications ALL over the file.  Wouldn't it 
be obviously better to make this all a data structure:

SearchStuff = [
    {
        'font': '0;-13;0;0;0;400;0;0;0;0;3;2;1;34;Arial',
        'color': wx.BLACK,
        'label': 'Your Label Here',
        'search': 'Search String',
        'soundpath': 'Not specified',
        'soundfile': Not specified
    },
    {
        'font': '0;-13;0;0;0;400;0;0;0;0;3;2;1;34;Arial',
        'color': wx.BLACK,
        'label': 'Your Label Here',
        'search': 'Search String',
        'soundpath': 'Not specified',
        'soundfile': Not specified
    },
    ...
]

Now, instead of doing everything 6 times, you can do things once, in a loop:
    for stuff in SearchStuff:
        stuff['container'] = wx.MenuItem( Containers, -1, stuff['name'], 
'View or hide', wx.ITEM_CHECK );
        Containers.AppendItem( stuff['container'] )

and so on.

If it were me, I would actually create a new class to hold all of this 
information, and create six instances of the class.  That would make it 
even cleaner.

ANY time you find yourself writing the same code more than once, you 
need to think about how a data structure could help that.

-- 
Tim Roberts, timr@[...].com
Providenza & Boekelheide, Inc.

_______________________________________________
wxpython-users mailing list
wxpython-users@[...].org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Thread:
Steve Freedenburg
Werner F. Bruhin
Steve Freedenburg
Steve Freedenburg
Steve Freedenburg
Werner F. Bruhin
Steve Freedenburg
Werner F. Bruhin
Steve Freedenburg
Tim Roberts

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved