[Tutor] When to use a class
I am still trying to understand when to use a class and when not to. All of the coding that I have done in the past (Python, Perl) has been procedural / functional. I would really like to do more OOP but I am not really sure when I need it. I have the following code. Is there any way that it would benefit from using a class? #!/usr/bin/env python import string import _winreg import sys compName = sys.argv[1] x = _winreg.ConnectRegistry(compName,_winreg.HKEY_LOCAL_MACHINE) y = _winreg.OpenKey(x, r"SOFTWARE\Intel\LANDesk\VirusProtect6\CurrentVersion") avParent = _winreg.QueryValueEx(y,"Parent")[0] _winreg.CloseKey(y) print "Computer: %s \tAV Parent: %s" % (compName,avParent) -- Thanks Eric Lake signature.asc Description: Digital signature ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding all the letters in a string?
On Mon, Sep 17, 2007 at 07:21:09PM -0400, Andrew Nelsen wrote: > >I was wondering, recently, the most expedient way to take a string >with [EMAIL PROTECTED]&*] and alpha-numeric characters [ie. >"[EMAIL PROTECTED]@*$g@)$&^@&^$F"] and place all of the letters in a > string or >list. I thought there could be obvious ways: >A) Find all the letters, put them in a list, one by one. Something >like (I'm not sure yet how I'd do it...): >import string >list = {} >string = "@*&^$&[EMAIL PROTECTED](&@$*(&[EMAIL PROTECTED](*&*(&c^&%&^%" >for x in string: >if x >list = list + [x] >B) Delete all the characters in the string that don't match >string.letters: >No idea...strip()? >Thanks, >Drew > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor This is what I came up with for the first part of the question. #!/usr/bin/env python # -*- coding: iso-8859-15 -*- import string lst = [] chars = '@*&^$&[EMAIL PROTECTED](&@$*(&[EMAIL PROTECTED](*&*(&c^&%&^%' for x in chars: if x in string.ascii_letters: lst.append(x) for n in lst: print n, I am sure that there is probably a better way though. -- Thanks Eric Lake signature.asc Description: Digital signature ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding all the letters in a string?
On Mon, Sep 17, 2007 at 07:48:56PM -0400, Michael Langford wrote: > >Not my night...the second sentence "To get the set of letters, use" >should read "To get the filtered string".time for more Coke Zero. > --Michael >On 9/17/07, Andrew Nelsen <[6] [EMAIL PROTECTED]> wrote: > >I was wondering, recently, the most expedient way to take a string >with [EMAIL PROTECTED]&*] and alpha-numeric characters [ie. >"[EMAIL PROTECTED]@*$g@)$&^@&^$F"] and place all of the letters in a > string or >list. I thought there could be obvious ways: >A) Find all the letters, put them in a list, one by one. Something >like (I'm not sure yet how I'd do it...): >import string >list = {} >string = "@*&^$&[EMAIL PROTECTED](&@$*(&[EMAIL PROTECTED](*&*(&c^&%&^%" >for x in string: >if x >list = list + [x] >B) Delete all the characters in the string that don't match >string.letters: >No idea...strip()? >Thanks, >Drew > > ___ I missed a part too. The original question specified alpha-numeric characters. sting.ascii.letters will only get a - z and A - Z. Would a regular expression work here with \w? -- Thanks Eric Lake signature.asc Description: Digital signature ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding all the letters in a string?
This seems to work to get out the alpha-numeric characters. #!/usr/bin/env python # -*- coding: iso-8859-15 -*- import re pat = re.compile('\w') lst = [] chars = '@*1&^$&[EMAIL PROTECTED](&@2$*(&[EMAIL PROTECTED](*&3*(&c^&%4&^%' lst = pat.findall(chars) for x in lst: print x, -- Thanks Eric Lake signature.asc Description: Digital signature ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Finding a project
What is a good way to find a project to work on? I really want to work on something but I can not think of anything useful to write. I am interested in sysadmin stuff (backups, monitoring, etc). That being said I don't really have experience writing apps like that. But I really want to learn. -- Thanks Eric Lake signature.asc Description: Digital signature ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New Introductory Book
For that price the book better write my code for me. Alex Ezell wrote: > On 11/6/07, Chris Calloway <[EMAIL PROTECTED]> wrote: >> Michael H. Goldwasser wrote: >>>We are pleased to announce the release of a new Python book. >> Why is this book $102? > > Supply and demand aside, I suspect the market for this, based on both > the publisher and the author's employment, is mostly > educational/collegiate. Therefore, this book is likely to be assigned > as a textbook and can command a premium price from buyers who have > little to no choice but to buy it. Additionally, it may not be > marketed on the wider bookstore shelves, so must make the most of the > market which it does reach. > > That's all conjecture. What I do know is fact is that I can't afford it. > > /alex > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor signature.asc Description: OpenPGP digital signature ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor