_winreg newbie question

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue Apr 29 06:19:20 EDT 2003


the_3_project at yahoo.com (Joe Green) wrote in 
news:a5b86892.0304290139.6870fb2b at posting.google.com:

>    if (key is "LOCAL_MACHINE"):

What do you think this line does? It doesn't compare two strings to see if 
they are equal.

Perhaps you meant:

     if key == 'LOCAL_MACHINE':

The 'is' operator checks whether two expressions both result in exactly the 
same object. This is not something you want to do very often.
Usually objects can be equal without being the same object. (You can use 
'is' to check whether an object 'is None' but that is because there is 
guaranteed only to be one None object in the system.)

> 
> -------------
> Doesn't make sense to me, I've been banging my head against the wall
> for several hours now! I can't figure it out.. and I know it's
> something very simple that I'm overlooking. I just don't see staring
> at it any longer to be productive :)
> 
> 
Some other style points (feel free to disagree/ignore):

Never use 'from <module> import *' unless the module documentation insists 
you should (_tkinter does). It is likely to come back and bite you later.

Get rid of the unnecessary parentheses in your 'if' statements. Python is 
not C.

There are several ways to avoid that unsightly list of if...elif 
statements. Perhaps the easiest would be:

    def IterKeys(self, key, subkey=None):
        regkey = getattr(self, key, None)
        ...

and then use regkey in place of 'self.reg[mykey]'.
 
Calling sys.exit when you cannot create the class seems a bit drastic. You 
might prefer to throw a more specific exception instead, or even just 
remove your try...except block and handle the exception at an outer level. 
As a general point an except block that catches every exception should make 
sure it does something useful (such as logging or displaying the error that 
actually occurred).

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list