[Tutor] Weighted Random Choice - Anyone have an efficient algorithm?

2010-12-22 Thread Modulok
Does anyone know of an efficient way of doing a weighted random choice? (I don't even know what algorithms like this would be called.) Preferably, something that doesn't grow exponentially with the number of elements in the list, or the size of their respective values. For example: Assume I have a

[Tutor] classes for setting 2D envelopes

2010-12-22 Thread Matt Gregory
Hi all, I've been working on creating 2D bounding box (envelope) classes to describe spatial data. Variations of these are available in other spatial libraries (e.g. Shapely), although I haven't found envelopes specific to raster data that also specifies cell size. Could be I just haven't fo

Re: [Tutor] calling setters of superclasses

2010-12-22 Thread Matt Gregory
On 12/18/2010 2:06 AM, Peter Otten wrote: I don't think /how/ you are trying it is stupid though I'm not so sure about /what/ . Thank you all for very helpful suggestions. It took me a while to chew on this before I could respond. I learned a lot about descriptors and their interactions wit

Re: [Tutor] Dictionary Question

2010-12-22 Thread Garry Bettle
On Wed, 22 Dec 2010 23:31:39 +1100, Steven D'Aprano wrote: > In this case, you need to sum the number of races for all the fixtures: > > num_races = sum(len(racetimes) for racetimes in FixtureDict.values()) Many thanks Steven for your explanation and final golden nugget of code. On Wed, 22 Dec 20

Re: [Tutor] xml.etree.ElementTree.parse() against a XMLShema file

2010-12-22 Thread Karim
On 12/22/2010 10:32 PM, Stefan Behnel wrote: Karim, 22.12.2010 22:09: Using lxml (except for the different import) will be fully compliant with the ET code. Do I have to adapt it? There are certain differences. http://codespeak.net/lxml/compatibility.html This page hasn't been changed for a

Re: [Tutor] xml.etree.ElementTree.parse() against a XMLShema file

2010-12-22 Thread Stefan Behnel
Karim, 22.12.2010 22:09: Using lxml (except for the different import) will be fully compliant with the ET code. Do I have to adapt it? There are certain differences. http://codespeak.net/lxml/compatibility.html This page hasn't been changed for ages, but it should still be mostly accurate.

Re: [Tutor] xml.etree.ElementTree.parse() against a XMLShema file

2010-12-22 Thread Karim
Thanks Stefan for answering. That's what I come up with. Using lxml (except for the different import) will be fully compliant with the ET code. Do I have to adapt it? I saw your fantastic benchmarks! Why the hell lxml is not integrated into the stdlib. I thought they put in it things which

Re: [Tutor] xml.etree.ElementTree.parse() against a XMLShema file

2010-12-22 Thread Stefan Behnel
Karim, 22.12.2010 19:28: On 12/22/2010 07:07 PM, Karim wrote: Is somebody has an example of the way to parse an xml file against a "grammary" file.xsd. I found this: http://www.velocityreviews.com/forums/t695106-re-xml-parsing-with-python.html Stefan is it still true the limitation of etree

Re: [Tutor] xml.etree.ElementTree.parse() against a XMLShema file

2010-12-22 Thread Karim
On 12/22/2010 07:07 PM, Karim wrote: Is somebody has an example of the way to parse an xml file against a "grammary" file.xsd. I found this: http://www.velocityreviews.com/forums/t695106-re-xml-parsing-with-python.html Stefan is it still true the limitation of etree in python 2.7.1 ? Regar

Re: [Tutor] Pyserial and invalid handle

2010-12-22 Thread Cheeng Shu Chin
Hi all, Last few days ago, I facing the same issue with my windows 7 64bit... it work well with windows XP 32-bit... FYI, I’m using python 2.6 amd64 bit as my core programming tools currently, I’m start study/learn some arduino robotic and rewrite Python-Arduino API I just do a quick anatomy t

[Tutor] xml.etree.ElementTree.parse() against a XMLShema file

2010-12-22 Thread Karim
Hello all, Is somebody has an example of the way to parse an xml file against a "grammary" file.xsd. The default parser is checking closing tags and attributes but I would like to validate a XSD file. I use the module ElementTree. Regards Karim __

Re: [Tutor] vim as a python editor

2010-12-22 Thread Brett Ritter
On Wed, Dec 15, 2010 at 7:30 PM, Alan Gauld wrote: > I also use split screen view in vim so that within vim I often have > two or three buffers open at once all displayed in a split screen. I know you prefer "default" settings, but one mapping I tend to stick in my .vimrcs whereever I go: nmap

Re: [Tutor] Dictionary Question

2010-12-22 Thread bob gailer
On 12/22/2010 7:31 AM, Steven D'Aprano wrote: Also note: len(dict.keys()) == len(dict.values()) == len(dict) -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.p

Re: [Tutor] Dictionary Question

2010-12-22 Thread Steven D'Aprano
Garry Bettle wrote: Howdy all, Hope this message finds everyone well. I have dictionary of keys and a string of values. i.e. 8 Fixtures: I assume each fixture is a key, e.g. Swin, HGrn, etc. Swin1828 1844 1901 1916 1932 1948 2004 2019 2036 2052 2107 2122 HGrn1148 1204 1218 1232 12

[Tutor] Dictionary Question

2010-12-22 Thread Garry Bettle
Howdy all, Hope this message finds everyone well. I have dictionary of keys and a string of values. i.e. 8 Fixtures: Swin1828 1844 1901 1916 1932 1948 2004 2019 2036 2052 2107 2122 HGrn1148 1204 1218 1232 1247 1304 1319 1333 1351 Newc1142 1157 1212 1227 1242 1258 1312 1327 1344 140

Re: [Tutor] pyodbc/date values in MS Access

2010-12-22 Thread Albert-Jan Roskam
Hi, Sorry for the late reply, but thanks a lot for helping me. It's solved now. Peter, the link you posted in another thread (or should I say 'query') was also relevant AND funny (http://xkcd.com/327/) Merry Christmas and Happy Coding! *) Cheers!! Albert-Jan *) Including those who have to pa

Re: [Tutor] Trying to parse a HUGE(1gb) xml file in python

2010-12-22 Thread Stefan Behnel
Walter Prins, 21.12.2010 22:13: On 21 December 2010 17:57, Alan Gauld wrote: "Stefan Behnel" wrote But I don't understand how uncompressing a file before parsing it can be faster than parsing the original uncompressed file? I didn't say "uncompressing a file *before* parsing it". I meant un