Re: Do any of you recommend Python as a first programming language?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jeff Schwab wrote: > jmDesktop wrote: >> For students 9th - 12th grade, with at least Algebra I. Do you think >> Python is a good first programming language for someone with zero >> programming experience? Using Linux and Python for first exposure to >> programming languages and principles. > > Linux and Python are a nearly ideal combination for this. Be aware that > at some point, you will likely have to dig into C, the primary language > used to implement both Linux and Python. At that level I don't see why they would need to hit 'C' at all. Maybe some of the APIs, but not syntax at all. I would consider Python an ideal language for HS students to learn. The teacher who hosts our KPLUG meetings has had good luck using Python in her classes. Brian - -- - ---[Office 67.9F]--[Outside 49.1F]--[Server 104.7F]--[Coaster 67.1F]--- - ---[ KLAHOWYA WSF (366773110) @ 47 31.2076 -122 27.2249 ]--- Software, Linux, Microcontrollers http://www.brianlane.com AIS Parser SDKhttp://www.aisparser.com Movie Landmarks Search Enginehttp://www.movielandmarks.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (Darwin) Comment: Remember Lexington Green! iD8DBQFH5VWZIftj/pcSws0RAoouAJ45UaRYDxwjwNLC8KblaFfyEKz3kACfeeWV XREAe/+tjyYuTVZOrNtaObE= =9h+S -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: re.search (works)|(doesn't work) depending on for loop order
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 sgharvey wrote: > ... and by works, I mean works like I expect it to. > > I'm writing my own cheesy config.ini parser because ConfigParser > doesn't preserve case or order of sections, or order of options w/in > sections. > > What's confusing me is this: >If I try matching every line to one pattern at a time, all the > patterns that are supposed to match, actually match. >If I try to match every pattern to one line at a time, only one > pattern will match. I don't see that behavior when I try your code. I had to fix your pattern loading: patterns[pattern] = re.compile(pattern_strings[pattern], re.VERBOSE) I would also recommend against using both the plural and singular variable names, its bound to cause confusion eventually. I also changed contents to self.contents so that it would be accessible outside the class. The correct way to do it is run each pattern against each line. This will maintain the order of the config.ini file. If you do it the other way you will end up with everything ordered based on the patterns instead of the file. I tried it with Python2.5 on OSX from within TextMate and it ran as expected. Brian - -- - ---[Office 70.9F]--[Outside 54.5F]--[Server 103.3F]--[Coaster 68.0F]--- - ---[ KLAHOWYA WSF (366773110) @ 47 31.2076 -122 27.2249 ]--- Software, Linux, Microcontrollers http://www.brianlane.com AIS Parser SDKhttp://www.aisparser.com Movie Landmarks Search Enginehttp://www.movielandmarks.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (Darwin) Comment: Remember Lexington Green! iD8DBQFH5ZHaIftj/pcSws0RAigtAJsE+NWTxwV5kO797P6AXhNTEp8dmQCfXL9I y0nD/oOfNw6ZR6UZIOvwkkE= =U+Zo -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for an empty dictionary in Python
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 John Nagle wrote: >What's the cheapest way to test for an empty dictionary in Python? > > if len(dict.keys() > 0) : > > is expensive for large dictionaries, and makes loops O(N^2). > > John Nagle if dict: ... :) - -- - ---[Office 68.7F]--[Outside 42.9F]--[Server 100.4F]--[Coaster 68.0F]--- - ---[ KLAHOWYA WSF (366773110) @ 47 31.2076 -122 27.2249 ]--- Software, Linux, Microcontrollers http://www.brianlane.com AIS Parser SDKhttp://www.aisparser.com Movie Landmarks Search Enginehttp://www.movielandmarks.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (Darwin) Comment: Remember Lexington Green! iD8DBQFH5nz/Iftj/pcSws0RAnnMAJoDX9P0cK+RshuvuRRfkyJ4CPwqxACeMWkF pq7AKr/qzVWyVat0QiTtUfo= =bpei -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Inheritance question
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Gerard Flanagan wrote: > Use the child class when calling super: > > -- > class Foo(object): > def __init__(self): > self.id = 1 > > def getid(self): > return self.id > > class FooSon(Foo): > def __init__(self): > Foo.__init__(self) > self.id = 2 > > def getid(self): > a = super(FooSon, self).getid() > b = self.id > return '%d.%d' % (a,b) > > print FooSon().getid() > -- That still doesn't do what he's trying to do. The problem here is that you only have one instance. self refers to it, so when you set self.id in the super you have set the instance's id to 1. When you set it to 2 after calling the super's __init__ you are now setting the *same* variable to a 2. Basically, you can't do what you are trying to do without using a different variable, or keeping track of a separate instance for the super instead of sub-classing it. Brian - -- - ---[Office 71.7F]--[Outside 33.2F]--[Server 99.5F]--[Coaster 68.7F]--- - ---[ KLAHOWYA WSF (366773110) @ 47 31.2076 -122 27.2249 ]--- Software, Linux, Microcontrollers http://www.brianlane.com AIS Parser SDKhttp://www.aisparser.com Movie Landmarks Search Enginehttp://www.movielandmarks.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (Darwin) Comment: Remember Lexington Green! iD8DBQFH6RwcIftj/pcSws0RArdpAJ9pCMjrkpBarHyQsl6hXEifj52giwCfXfKa Ot/1a+NNOLN5LA4mxBtfpis= =Yacu -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list