[Tutor] suggestions to improve design

2012-06-04 Thread Justin Straube
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello Tutors,

I've written a script to use within XChat (IRC client) and everything is
working without issue. The script is a little tool to give an emote
command and a handful of general pre written actions.

As it is now, the script works. But I've got maybe a dozen emotes in
there, using if/elif loops to check against a list of emotes and
format a string for display in the channel.

But, I also have another dictionary containing duplicate values with
text placeholders where a %s would be substituted.

I feel that, as the list of available emotes grows, the script will
suffer from a poor design. I have thought about pickling or using a file
to store the dict or loops, but that only seems like a bandage and
there may be a performance issue with potentially hundreds of loops to
check through.

Ok, so I have posted my script at
http://www.baked-potato.us/files/2ndthat.py

My question is, would anybody please take a look and offer suggestions
on what I may do to improve this script?

Thank you,
Justin
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPzNYQAAoJEBXz28t2j4R5cmYIAIVIQMJI7HshaV0WqmbUKp1U
+vFdLbD52JHs+x4dUwq6DBWdAllauxkm0GW6PGYhHefQZrzRrplTG37Oj+C6czvT
pHT6mI1AwXdrQIQab6D0JEPkqIw9kuQormNrUynxwZFSU7M/Z1qmBv0twikwDUVD
R3hClBeuVMydLk2DhIuPpgqEO/6ljkN8tK6El5+1vIQFsVRizEX2HVeco7oMz/9x
ePedVpEfW4cGpRcFz2gnthzLawoPPmxKc3fTTq29za/tR8eqvUxXY4vjxWWeOr/+
N97Yfdglo1pa4Kir/Ukd+678R/WHZzrqZVRTa4fRZC17cSOU1Pd96L2cqwOCqzs=
=0zEs
-END PGP SIGNATURE-


0x768F8479.asc
Description: application/pgp-keys
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] suggestions to improve design

2012-06-04 Thread Justin Straube
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 06/04/2012 11:28 AM, Prasad, Ramit wrote:
 Unless the script gets a *very* large list of emotes or you are on 
 an older machine I doubt that you will really see any performance 
 issues. That being said, my comments are below and other tutors

Thank you for your time, Ramit.

 can correct anything I missed or said incorrectly. I like the 
 presence of your documentation, kudos!

As a hobbyist, I can afford the time to document. I also find that
even with code I wrote, the documentation helps me understand better,
and find areas that need more work.

 Why use a class for storing the 'tions' and dict directly from the
 module?
 
 tions = { [snip] }

When I started, I was unsure what else I would be putting in the class
Emo. After I got going, I was unsure about changing that, if the
design needed adjusting and it would be used further. Before I do to
much more for this, I am going to remove the class and just use the
dictionary, with a better name.

Thank you for your other ideas. Ill work over this and also clean up
my comments.

Justin


 I also think get_emote should not be passed the entire argv, it
 should be passed only the arguments it needs so I would change the
 call to
 
 def emote(argv): emote = argv[1] if emote in tions: # look at
 dictionary, no need to pull keys manually emstring =
 get_emote(emote, argv[2:]) # pass only arguments
 
 # print a generic message to the channel displaying the emote
 string #xchat.emit_print(Generic Message, nick, emstring) 
 xchat.command(me %s % (emstring))
 
 def get_emote( e, args ): if e in tions: if '%s' in tions[e]: 
 return tions[e] % tuple(args) # will error here if not the correct
 number of variables # in args; might want to catch and then return
 an error string else return tions[e] else: return 'Not an
 understood emote'
 
 
 def list_em(): print There are %s emotes available. %
 (len(tions)) print Usage: /em \002$emote\002 - user supplied
 values are shown as \002$bold\002.\n
 
 for key,value in tions.iteritems(): print Emote: %s - %s % (key,
 value)
 
 
 As a general note, you should use docstrings instead of comments 
 above the function.
 
 CHANGE
 
 # show function - displays a single requested emote def show(s):
 
 
 TO
 
 def show(s): 'displays a single requested emote' # single line
 docstring
 
 OR
 
 def show(s): ''' multi line docstring '''
 
 
 Ramit
 
 
 Ramit Prasad | JPMorgan Chase Investment Bank | Currencies
 Technology 712 Main Street | Houston, TX 77002 work phone: 713 -
 216 - 5423

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPzYq7AAoJEBXz28t2j4R5MT4H/2ILvS33kQmW5r8sNyeszoir
p5BNJOOEcEpc9Th41+12hXrP1Jir0COUur1HKqoom6Ufx07FuYPhiQ2MOC7W43EZ
I9m8/F0b/DkxLBBwg4CL+tfTAhIZ9R2/rfKxQ8GQSN4Yn29X6WGrP/uK9TRlHERq
ucb3tYPOp8b/zMujILVjndkqozupqNTrGZVBe8F8tphcnlv6ScZHjDRsaK898SbL
mcK/Ua45XVpaGpunIV8Um03hVf+UZwwvat348vOE8fgsOyywXaZc0oHsVr6G41os
zsQXR2/3CJA88ZVqJzRKmwdHJ2xuPsNWnrTuxplsHnsNWuHMHBHmnPj+HC9Gnsw=
=BPDI
-END PGP SIGNATURE-


0x768F8479.asc
Description: application/pgp-keys
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] login window using Tk

2011-11-01 Thread Justin Straube

On 11/1/2011 3:28 PM, Chris Hare wrote:


Good feedback Alan, thanks.

I wasn't using the root window to hold the login form, although I
suppose I could. I guess where I am stuck is the login to control
displaying the login window, and hiding it to display the actual
application window once the user has authenticated.

Chris Hare
ch...@labr.net mailto:ch...@labr.net
http://www.labr.net


Hi Chris,

Have you looked into using a Frame to hold you input fields, and then 
using .destroy() to remove it upon successful login?


This would allow you to not have to worry about hiding windows, as you 
can just reuse the same root window.


Im just a hobbyist, so if there are reasons not to use this approach, 
I'd be interested in why.


Justin
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor