Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Albert-Jan Roskam
Interesting. Can this also be used to make sorting of alphanumerical list items in a 'numerical' way easier? E.g.: >>> x ['var_0', 'var_13', 'var_11', 'var_9', 'var_4', 'var_1', 'var_5', 'var_6', 'var_7', 'var_14', 'var_2', 'var_3', 'var_8', 'var_10', 'var_12'] >>> x.sort() >>> x ['var_0', 'var_1

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Albert-Jan Roskam
Wed, 1/13/10, Sander Sweers wrote: From: Sander Sweers Subject: Re: [Tutor] samples on sort method of sequence object. To: "Albert-Jan Roskam" Cc: "*tutor python" Date: Wednesday, January 13, 2010, 2:14 PM 2010/1/13 Albert-Jan Roskam > > Interesting. Can this also

Re: [Tutor] language aid

2010-02-04 Thread Albert-Jan Roskam
Hi,   A dictionary (associative array of keys and values) seems a good datatype to use. vocab = {} vocab[frenchword] = englishword   For instance: >>> vocab = {"aimer": "love"} >>> vocab {'aimer': 'love'} >>> vocab["parler"] = "speak" >>> vocab {'aimer': 'love', 'parler': 'speak'} >>> for engword,

Re: [Tutor] Coin flip game

2010-02-12 Thread Albert-Jan Roskam
Hi, random.choice offers an intuitive way to write the code: import random for i in range(10):     print random.choice(["head", "tail"]) Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to guess.

Re: [Tutor] Bowing out

2010-03-03 Thread Albert-Jan Roskam
Hi Kent, Thank you very much for sharing your knowledge. Much appreciated! Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to guess. ~~~

Re: [Tutor] Encoding

2010-03-04 Thread Albert-Jan Roskam
Hi,   For everybody who's having trouble understanding encoding, I found this page useful: http://evanjones.ca/python-utf8.html Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to guess. ~~~

Re: [Tutor] Really learn programming

2010-03-08 Thread Albert-Jan Roskam
This very funny cartoon is about learning C++ in 21 days, but it could be about any language: http://high5.net/comic/AG/ars_longa_vita_brevis.PNG Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to gue

Re: [Tutor] How do I find information about a Python object.

2010-03-30 Thread Albert-Jan Roskam
Hi, Are you looking for the inspect module?   import inspect help(inspect) cls = str inspect.classify_class_attrs(cls) Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to guess. ~~~

Re: [Tutor] ask-why I cannot run it, and I am so confused about the traceback

2010-04-07 Thread Albert-Jan Roskam
What's with Pythonistas and colours? http://www.mail-archive.com/python-l...@python.org/msg231447.html ;-))) Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irri

[Tutor] xml question

2010-07-26 Thread Albert-Jan Roskam
Hi, I am making a data processing program that will use a configuration file. The file should contain information about: (1) source files used, (2) (intermediate) output files, (3) used parameters/estimation methods (4) manual data edits + datetime stamp + user name . I'd like to store this con

Re: [Tutor] xml question

2010-07-27 Thread Albert-Jan Roskam
ever done for us? ~~ --- On Tue, 7/27/10, Mac Ryan wrote: From: Mac Ryan Subject: Re: [Tutor] xml question To: tutor@python.org Date: Tuesday, July 27, 2010, 11:46 AM On Mon, 2010-07-26 at 12:09 -0700, Albert-Jan Roskam wro

[Tutor] os.access unreliable?

2010-08-25 Thread Albert-Jan Roskam
Hi, Hi I'm using os.access to do a preliminary check to see if I have RW access, but it seems to be unreliable. In a dir for which I have only read access, os.access also says I have write access. This is under Windows 2000. I could of course use a try-except and catch the IOError, but I'd l

Re: [Tutor] os.access unreliable?

2010-08-25 Thread Albert-Jan Roskam
Hi Tim and Steven, Thanks a lot for your very useful replies!  Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public h

[Tutor] wx to convert Group 4 Tifs to Gifs

2010-08-26 Thread Albert-Jan Roskam
Hi, I have a small application, written in Tkinter. It is supposed to display a tif image, among other things. The problem is, PIL won't decode group 4 Tifs (G4 TIF). The tifs that I have are about 125kb and contain two pages per file. They're scanned, monochrome files. I need the second page o

[Tutor] more on wx and tiff

2010-08-27 Thread Albert-Jan Roskam
Hi again, Some more questions about tiff conversion. First, thanks for your previous replies. I cannot use IrfanView any time soon, nor will my boss switch to Linux. So I'm trying to do the conversion from tiff to png using the wx package (gif would also be fine, but that won't work due to

Re: [Tutor] more on wx and tiff

2010-08-27 Thread Albert-Jan Roskam
public health, what have the Romans ever done for us? ~~ From: Wayne Werner To: Albert-Jan Roskam Cc: Python Mailing List Sent: Fri, August 27, 2010 6:44:04 PM Subject: Re: [Tutor] more on

Re: [Tutor] more on wx and tiff

2010-08-29 Thread Albert-Jan Roskam
health, what have the Romans ever done for us? ~~ ____ From: Albert-Jan Roskam To: Wayne Werner Cc: Python Mailing List Sent: Fri, August 27, 2010 8:00:16 PM Subject: Re: [Tutor] more on wx and tiff Hi Wayne, Yep, I considered using PI

Re: [Tutor] Help with Object Oriented Programming

2010-08-31 Thread Albert-Jan Roskam
I read Head First Design Patterns (http://oreilly.com/catalog/9780596007126). It focuses on Java and it's not only good because of the nice woman on the cover. ;-) Cheers!! Albert-Jan ~~ All right, but apart from the sanitat

Re: [Tutor] Begginer Python Problems - Urgent! Due by tomorrow morning.

2010-09-03 Thread Albert-Jan Roskam
Hi, Just guessing: x = 12 print (2*x) def greetings(no): for i in range (no+1): print ('Hello ') print ('Greetings, earthling') def regreet(no): for j in range(no+1): greetings(no) prompt = "Enter a number: " no = raw_input(prompt) regreet(no) It's not tested beca

[Tutor] design question

2010-09-10 Thread Albert-Jan Roskam
Hi, I've made a small data entry program where a picture of a hand-written, scanned form is shown next to several text entries. The design has been largely 'bottom up', although of course I started with a rough sketch. I started with the following classes: Menu (responsible for the widget creat

Re: [Tutor] design question

2010-09-10 Thread Albert-Jan Roskam
Romans ever done for us? ~~ From: Knacktus To: tutor@python.org Sent: Fri, September 10, 2010 3:38:13 PM Subject: Re: [Tutor] design question Am 10.09.2010 11:23, schrieb Albert-Jan Roskam: > Hi, > > I've made a small data entry program where a picture of a hand-written, >

Re: [Tutor] design question

2010-09-11 Thread Albert-Jan Roskam
n question On Sat, 11 Sep 2010 12:11:37 am Albert-Jan Roskam wrote: > Inside my program I have to keep a list of all the image files that > are scheduled for data entry. Sounds like you need to keep a list of all the image files that are scheduled for data entry then. > The main purp

[Tutor] (de)serialization questions

2010-09-30 Thread Albert-Jan Roskam
Hi, I have data about zip codes, street and city names (and perhaps later also of street numbers). I made a dictionary of the form {zipcode: (street, city)} I dumped the dictionary into a marshal file. I have two questions: The first question is a very basic one: if I deserialize the dictionary

Re: [Tutor] inheritance problem

2010-09-30 Thread Albert-Jan Roskam
>> And so forth. Laborious? Time consuming? Lots of detail? Yes. Most of >> us have gone thru the same thing in our education. ---> You forgot: 'Lots of frowning', 'lots of sixpacks' and 'lots of FUN' ;-))) Cheers!! Albert-Jan

Re: [Tutor] (de)serialization questions

2010-10-01 Thread Albert-Jan Roskam
Hi Lee, Thanks for your response. Maybe my main question is as follows: what permanent object is most suitable to store a large amount of entries (maybe too many to fit into the computer's memory), which can be looked up very fast. Eventually, I want to create two objects: 1-one to look up str

Re: [Tutor] (de)serialization questions

2010-10-03 Thread Albert-Jan Roskam
Hi Lee, Alan and Steven, Thank you very much for your replies! First, Lee: >> That does not seem like it will work. What happens when >> 2 addresses have the same zip code? --> Sorry I didn't answer that before. When the zipcode is known, that's not a problem. The data typist simply has to ente

Re: [Tutor] (de)serialization questions

2010-10-04 Thread Albert-Jan Roskam
ect: Re: [Tutor] (de)serialization questions To: tutor@python.org Date: Monday, October 4, 2010, 1:46 AM "Albert-Jan Roskam" wrote > It makes much more sense to maintain one database table instead of 3 csv files > for the three data typists' output. To be pedantic you will probably

[Tutor] updating a Csv file

2010-10-20 Thread Albert-Jan Roskam
Hi all, How can I update a csv file? I've written the code below, but it does not work ("Error: line contains NULL byte"). I've never tried opening a file in read and write mode (r+) at the same time before, so I suspect that this is the culprit. Should I instead just open one file, write to

Re: [Tutor] updating a Csv file

2010-10-20 Thread Albert-Jan Roskam
, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ --- On Wed, 10/20/10, Dave Angel wrote: From: Dave Angel Subject: Re: [Tutor] updating a Csv file To: "Albert-Jan Roskam" Cc: "Python Mailing List" Dat

Re: [Tutor] List comprehension question

2010-11-09 Thread Albert-Jan Roskam
For larger blocks of code, cProfile may also be useful for speed tests. Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and

[Tutor] smptlib question

2009-06-08 Thread Albert-jan Roskam
(sorry for posting this again, but something might have gone wrong) Hi, I made a very simple program to send everybody I know a change of address I am parsing the .msg files with another function, which returns a set called 'recipients'. The code below works, but it displays all recipients in

[Tutor] smtplib question

2009-06-08 Thread Albert-jan Roskam
Hi, I made a very simple program to send everybody I know a change of address I am parsing the .msg files with another function, which returns a set called 'recipients'. The code below works, but it displays all recipients in the 'to' field. That is, in the Nth iteration, N recipients are sho

Re: [Tutor] smptlib question

2009-06-09 Thread Albert-jan Roskam
tead of letting each function have its own purpose. Cheers!! Albert-Jan --- On Tue, 6/9/09, David wrote: > From: David > Subject: Re: [Tutor] smptlib question > To: "Albert-jan Roskam" > Cc: "*tutor python" > Date: Tuesday, June 9, 2009, 2:13 AM > Alber

Re: [Tutor] Need help solving this problem

2009-06-10 Thread Albert-jan Roskam
hi! This is how I would do it, but I'm still learning this too, so I'm very much open for suggestions. Cheers!! Albert-Jan import random def draw (): return random.sample(["head", "tail"], 1) def toss (): heads, tails = 0, 0 for flip in range(100): if draw() == ["head"]: he

Re: [Tutor] Help Needed

2009-06-16 Thread Albert-jan Roskam
Hi, This is how I would do it, although there might be more readable solutions: s = raw_input("Enter a message: ") print "".join([s[-letter] for letter in range(len(s)+1)]) Cheers!! Albert-Jan --- On Tue, 6/16/09, Alan Gauld wrote: > From: Alan Gauld > Subject: Re: [Tutor] Help Needed > To:

[Tutor] xlwt & xlrd: can I refactor this code better?

2009-07-22 Thread Albert-Jan Roskam
Hi, A while ago I wrote a program to merge xls files. Now I refactored it because before, it was one big chunk of spaghetti code and I wanted to add some functionality. The code below works, but I have the feeling that it could still be simplified. Most functions have many arguments - isn't th

Re: [Tutor] how to get blank value

2009-07-24 Thread Albert-Jan Roskam
Mark Summerfield recently wrote a book called Programming in Python 3 (http://www.qtrac.eu/py3book.html) The chapter on regexes happens to be freely downloadable as a sample chapter: http://ptgmedia.pearsoncmg.com/images/9780137129294/samplepages/0137129297_Sample.pdf I found that chapter (in f

Re: [Tutor] simple text replace

2009-07-27 Thread Albert-Jan Roskam
Hi! Did you consider using a regex? import re re.sub("python\s", "snake ", "python is cool, pythonprogramming...") Cheers!! Albert-Jan --- On Mon, 7/27/09, Dave Angel wrote: > From: Dave Angel > Subject: Re: [Tutor] simple text replace > To: "j booth" > Cc: tutor@python.org > Date: Monday

[Tutor] easy way to pupulate a dict with functions

2009-08-06 Thread Albert-Jan Roskam
Hi, I was playing with the code below, and I was wondering if there was a way to populate the dictionary called 'commands' (in the function 'check_command()'). Suppose I would add another function, which I would also like to store as a value in 'commands', could it simply be programmed, or woul

Re: [Tutor] easy way to populate a dict with functions

2009-08-06 Thread Albert-Jan Roskam
> previous one in email clients that follow threads! > > To avoid that here I am responding in a new email. Also > fixed spelling in subject. > > Albert-Jan Roskam wrote: > > Hi, > > > > I was playing with the code below, and I was wondering > if ther

Re: [Tutor] easy way to populate a dict with functions

2009-08-06 Thread Albert-Jan Roskam
> Date: Thursday, August 6, 2009, 7:28 PM > Please start a new email when > starting a new topic. Otherwise it gets linked to the > previous one in email clients that follow threads! > > To avoid that here I am responding in a new email. Also > fixed spelling in subject. > &g

Re: [Tutor] easy way to populate a dict with functions

2009-08-11 Thread Albert-Jan Roskam
> Subject: Re: [Tutor] easy way to populate a dict with functions > To: "Albert-Jan Roskam" > Cc: "tutorpythonmailinglist Python" > Date: Thursday, August 6, 2009, 10:20 PM > Albert-Jan Roskam wrote: > > Hi Bob, > > > > Very neat solution, than

[Tutor] Input validation

2009-09-03 Thread Albert-Jan Roskam
Hi, I'm wondering what is the most common method of input validation. See the example below. -Is the code below the most common/recognizable way something like this is done? -Which of the options #1 and #2 is the preferred method? Option #2 looks less esoteric, but #1 seems better when you have

[Tutor] (no subject)

2009-10-13 Thread Albert-Jan Roskam
Hi, I'm using Tkinter to program my very frist GUI. Each button grays out after it has been used so the user knows what next steps to take. Now I want to define a Reset button to 'ungray' all buttons (state='normal'). How can I programmatically create a list of all available buttons? Cheers!! A

Re: [Tutor] GUI Buttons

2009-10-14 Thread Albert-Jan Roskam
> Please provide a subject when sending > mail to the list. > And please create a new message so it doesn't get lost in > an old thread... > > "Albert-Jan Roskam" > wrote in message > > > I'm using Tkinter to program my very frist GUI. > >

Re: [Tutor] "if clause" in list comprehensions.

2009-10-21 Thread Albert-Jan Roskam
Is the if-else (esp. 'else') in a list comprehension specific for Python 3.x? Or did I miss something? Cheers!! Albert-Jan ~~ Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're

Re: [Tutor] ifdef in python

2009-10-24 Thread Albert-Jan Roskam
Isn't it better to use if __debug__: I thought such an if statement always evaluated to False when the python program was run in OPTIMIZED (-o) mode? Cheers!! Albert-Jan ~~ Before you criticize someone, walk a mile in their sho

Re: [Tutor] How to load a dict into a dict subclass?

2009-10-27 Thread Albert-Jan Roskam
I thought reimplementing dict was a matter of defining a __dict__ attribute in the Bar class? And isn't the normal dict inherited anyway? (through __super__) Or, if one would want to disable inheritance of the normal dict, one could use __slots__. Right? Or did I misinterpret the New Testament

[Tutor] Apologies for sent spam

2009-11-16 Thread Albert-Jan Roskam
Hi,   I just noticed that a spam message was sent with my email address. Apologies. I have no idea what caused that. I'll check my windows machine for viruses. Or could it have some other cause? Perhaps I should also change my password. Cheers!! Albert-Jan ~~~

Re: [Tutor] Writing code while tired, counterproductive?

2009-11-16 Thread Albert-Jan Roskam
I find that switching to a completely different approach or strategy becomes more difficult when tired. Depending on the context, that could be called persistence of perseverence (begin good or bad, respectively). However, in my opinion, not being able to view things from a different angle is us

[Tutor] elementtree question

2009-11-19 Thread Albert-Jan Roskam
Hi,   I have an elementtree question that probably reflects my inexperience with xml processing (and/or with Python). The xml file is a stream of the Spss Clementine program. Each stream consists of, among others, nodes. Each nodes has properties, among which "tooltiptext" and "label". I want to

Re: [Tutor] Breaking out of loop...

2009-11-20 Thread Albert-Jan Roskam
Hi! Slightly different (extented) than your original question, but here's how I'd do this (although the program doesn't really do very much): import time, random def is_valid_date():     while True:     prompt = 'Enter the date in ISO format (-MM-DD), or 0 to exit: '     date = raw

[Tutor] UnicodeEncodeError

2009-11-25 Thread Albert-Jan Roskam
Hi,   I'm parsing an xml file using elementtree, but it seems to get stuck on certain non-ascii characters (for example: "ê"). I'm using Python 2.4. Here's the relevant code fragment:   # CODE: for element in doc.getiterator():   try: m = re.match(search_text, str(element.text))   except Unic

Re: [Tutor] UnicodeEncodeError

2009-11-26 Thread Albert-Jan Roskam
/09, Kent Johnson wrote: From: Kent Johnson Subject: Re: [Tutor] UnicodeEncodeError To: "Albert-Jan Roskam" Cc: "tutor@python.org tutor@python.org tutor@python.org" Date: Wednesday, November 25, 2009, 5:55 PM On Wed, Nov 25, 2009 at 8:44 AM, Albert-Jan Roskam wrote: Hi,   I'

[Tutor] unicode mapping doesn't work

2009-11-26 Thread Albert-Jan Roskam
Hi, I want to substitute some letters with accents with theire non-accented equivalents. It should be easy, but it doesn't work. What am I doing wrong? trans = {} funnychars = u"éèêëóòôöáàâäÉÈÊËÓÒÔÖÁÀÂÄ" asciichars = "" for f, a in zip(funnychars, asciichars):     trans.u

Re: [Tutor] unicode mapping doesn't work

2009-11-26 Thread Albert-Jan Roskam
he face of ambiguity, refuse the temptation to guess. ~~ --- On Thu, 11/26/09, Lie Ryan wrote: From: Lie Ryan Subject: Re: [Tutor] unicode mapping doesn't work To: tutor@python.org Date: Thursday, November 26, 2009, 5:33 PM Al

Re: [Tutor] Python best practices

2009-11-30 Thread Albert-Jan Roskam
I'm currently reading the book "Code Complete" (I don't know the author name), which gives a lot of useful best practices. It's not specifically about one programming language. The author stresses that the majority of those practices are a matter of consensus/consistency and not a matter of reli

Re: [Tutor] python and kiviat diagrams

2009-12-23 Thread Albert-Jan Roskam
I was studying the code on http://matplotlib.sourceforge.net/examples/api/radar_chart.html. Isn't it very unusual that a class is defined within a function? Why not use a class instance inside the function instead? No methods of the class can currently be inherited outside the scope of the funct

Re: [Tutor] python and kiviat diagrams

2009-12-25 Thread Albert-Jan Roskam
-- On Thu, 12/24/09, Kent Johnson wrote: From: Kent Johnson Subject: Re: [Tutor] python and kiviat diagrams To: "Albert-Jan Roskam" Cc: "dwbarne" , "python tutor" Date: Thursday, December 24, 2009, 2:19 PM On Wed, Dec 23, 2009 at 5:27 PM, Albert-Jan Roskam wr

Re: [Tutor] Listing available variables

2009-12-25 Thread Albert-Jan Roskam
This may also be useful: >>> a = 1 >>> b = 2 >>> c = 3 >>> locals() {'a': 1, 'c': 3, 'b': 2, '__builtins__': , '__name__': '__main__', '__doc__': None} >>> locals().keys() ['a', 'c', 'b', '__builtins__', '__name__', '__doc__'] >>> Cheers!! Albert-Jan

[Tutor] Is there any way I can use named tuples in Python 2.5?

2010-12-02 Thread Albert-Jan Roskam
Hi, Is there any way I can use named tuples in Python 2.5? It's available since 2.6 and I'm not sure if from "__future__" works. I can't try it here. I cannot simply upgrade Python (alas!) http://www.python.org/doc//current/library/collections.html#collections.namedtuple Cheers!! Albert-Jan

Re: [Tutor] Is there any way I can use named tuples in Python 2.5?

2010-12-02 Thread Albert-Jan Roskam
there any way I can use named tuples in Python 2.5? On 12/2/2010 9:52 AM Albert-Jan Roskam said... > Hi, > > Is there any way I can use named tuples in Python 2.5? It's available since 2.6 > and I'm not sure if from "__future__" works. I can't try it he

[Tutor] Question on tkinter event binding

2010-12-03 Thread Albert-Jan Roskam
Hi, I'm trying to make a small improvement on a data entry program and it is literally giving me a headache. I would appreciate your help or suggestions. The actual program uses Autocomplete entry widgets [1], which is a subclass of the Tkinter Entry widget. The sample code below uses a simpl

Re: [Tutor] Question on tkinter event binding

2010-12-03 Thread Albert-Jan Roskam
~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?

Re: [Tutor] Question on tkinter event binding

2010-12-04 Thread Albert-Jan Roskam
nitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~ From: Patty To: Albert-Jan Roskam ; P

Re: [Tutor] Question on tkinter event binding

2010-12-04 Thread Albert-Jan Roskam
tcode", "Adres"]) Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Roman

Re: [Tutor] Question on tkinter event binding

2010-12-04 Thread Albert-Jan Roskam
["CWI", "MIT"])}) ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~

Re: [Tutor] Feedback on coding style

2010-12-09 Thread Albert-Jan Roskam
Hi, Re: coding style, I can *really* recommend the book 'Code Complete' (http://cc2e.com/). It doesn't focus on Python specifically, but it's a wonderful book. You can find a pdf checklist of the book if you Google a bit.  Cheers!! Albert-Jan ~~

Re: [Tutor] Generating a python file

2010-12-14 Thread Albert-Jan Roskam
Hello, If it's specifically about a dictionary, try also the following: import shelve help(shelve) A shelve is a persistent dictionary.  Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education,

[Tutor] pyodbc/date values in MS Access

2010-12-15 Thread Albert-Jan Roskam
Hi, I'm using pyodbc (Python 2.5) to insert records in an MS Access database. For security reasons, question marks should be used for string replacement [*]. The standard %s would make the code vulnerable to sql code injection. Problem is, string replacement in the Good Way somehow doesn't work

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

2010-12-22 Thread Albert-Jan Roskam
ver done for us? ~~ From: Peter Otten <__pete...@web.de> To: tutor@python.org Sent: Wed, December 15, 2010 3:06:19 PM Subject: Re: [Tutor] pyodbc/date values in MS Access Albert-Jan Roskam w

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

2010-12-24 Thread Albert-Jan Roskam
Hi Steven, Doesn't this qualify as 'monkeying with the loop index'? [*] >>> import random >>> weights = [5, 20, 75] >>> counts = {0:0, 1:0, 2:0} >>> for i in xrange(100): ... i = weighted_choice(weights) # <--- monkeying right here (?) ... counts[i] += 1 [*] http://stackoverflow.com/

Re: [Tutor] Help on RE

2011-01-23 Thread Albert-Jan Roskam
http://imgs.xkcd.com/comics/regular_expressions.png ;-) Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public healt

[Tutor] regex questions

2011-02-17 Thread Albert-Jan Roskam
Hello, I have a couple of regex questions: 1 -- In the code below, how can I match the connecting words 'van de' , 'van der', etc. (all quite common in Dutch family names)? 2 -- It is quite hard to make a regex for all surnames, but easier to make regexes for the initials and the connecting wor

Re: [Tutor] regex questions

2011-02-18 Thread Albert-Jan Roskam
~~ From: Steven D'Aprano To: Python Mailing List Sent: Fri, February 18, 2011 4:45:42 AM Subject: Re: [Tutor] regex questions Albert-Jan Roskam wrote: > Hello, > > I have a couple of regex questions: > > 1 -- In the code be

[Tutor] ctypes question

2011-03-07 Thread Albert-Jan Roskam
Hi, I want to use a dll to read Spss data files. But when I use lib = ctypes.cdll.LoadLibary("d:/temp/spssio32.dll") I get a WindowsError (cannot find module), even though the path exists. Why is that? Do I need to extend some environment variable (add another dir)? I am using Python 2.5 on Win

Re: [Tutor] ctypes question

2011-03-08 Thread Albert-Jan Roskam
Hi all, Thanks for your replies. It wasn't a permissions issue. Apparently, not the full path name should be used. When I use os.chdir (by the way: why on earth isn't this called os.setcwd()?? That's consistent with os.getcwd()) and then use the file name only, it works. See the Idle session b

Re: [Tutor] ctypes question

2011-03-08 Thread Albert-Jan Roskam
Hi Joel, I found this on stackoverflow*) os.environ['PATH'] = os.path.dirname(__file__) + ';' + os.environ['PATH'] windll.LoadLibrary('mydll.dll') It extends the directory list of the environment variable 'path'. Now at least I've loaded the dll, but I still need to read up on ctypes an file ha

[Tutor] ctypes and spssio.dll

2011-03-16 Thread Albert-Jan Roskam
Hi, I'm still working on a program that uses a .dll to read SPSS system files. It's getting somewhere already, but I'm still struggling with one thing. When using the C function spssGetVarNames I'm having trouble translating C arrays to Python lists. I want to translate an array that holds the

Re: [Tutor] how to join two text files ?

2011-03-27 Thread Albert-Jan Roskam
Hello, If the files are not too big, you could do something like: with open("/home/me/Desktop/test.csv", "wb") as w: writer = csv.writer(w) for f in glob.glob("/home/me/Desktop/files/*.txt"): rows = open(f, "rb").readlines() writer.writerows(rows) Cheers!! Albert-Jan ~~

[Tutor] how to optimize this code?

2011-03-27 Thread Albert-Jan Roskam
Hello, I made a program that reads spss data files. I ran cProfile to see if I can optimize things (see #1 below). It seems that the function getValueNumeric is a pain spot (see #2 below). This function calls a C function in a dll for each numerical cell value. On the basis of this limited amo

Re: [Tutor] how to optimize this code?

2011-03-28 Thread Albert-Jan Roskam
_ From: Stefan Behnel To: tutor@python.org Sent: Mon, March 28, 2011 7:43:16 AM Subject: Re: [Tutor] how to optimize this code? Albert-Jan Roskam, 27.03.2011 21:57: > I made a program that reads spss data files. I ran cProfile to see if I can > optimize things (see #1 below). Firs

[Tutor] can I walk or glob a website?

2011-05-18 Thread Albert-Jan Roskam
Hello, How can I walk (as in os.walk) or glob a website? I want to download all the pdfs from a website (using urllib.urlretrieve), extract certain figures (using pypdf- is this flexible enough?) and make some statistics/graphs from those figures (using rpy and R). I forgot what the process of

Re: [Tutor] can I walk or glob a website?

2011-05-18 Thread Albert-Jan Roskam
From: Dave Angel To: Alan Gauld Cc: tutor@python.org Sent: Wed, May 18, 2011 11:51:35 AM Subject: Re: [Tutor] can I walk or glob a website? On 01/-10/-28163 02:59 PM, Alan Gauld wrote: > > "Albert-Jan Roskam" wrote >> How can I walk (as in os.walk) or glob a websi

Re: [Tutor] can I walk or glob a website?

2011-05-18 Thread Albert-Jan Roskam
Hi Steven, From: Steven D'Aprano To: tutor@python.org Sent: Wed, May 18, 2011 1:13:17 PM Subject: Re: [Tutor] can I walk or glob a website? On Wed, 18 May 2011 07:06:07 pm Albert-Jan Roskam wrote: > Hello, > > How can I walk (as in os.walk) or glob a website? If you're on

Re: [Tutor] can I walk or glob a website?

2011-05-18 Thread Albert-Jan Roskam
From: Alan Gauld To: tutor@python.org Sent: Wed, May 18, 2011 4:40:19 PM Subject: Re: [Tutor] can I walk or glob a website? "Dave Angel" wrote >> "Albert-Jan Roskam" wrote >>> How can I walk (as in os.walk) or glob a

Re: [Tutor] can I walk or glob a website?

2011-05-19 Thread Albert-Jan Roskam
Thank you, always useful to study other people's code. I wasn't planning to create a Gui for my app. It struck me that the Gui class also contains all the methods that deal with the html parsing. But maybe that's what your warnings were about. ;-)  Cheers!! Albert-Jan

Re: [Tutor] Excited about python

2011-06-12 Thread Albert-Jan Roskam
My all-time favourite is Programming in Python 3 (Mark Summerfield) http://www.qtrac.eu/py3book.html Most of it is not for absolute beginners. Some of the chapters contain stuff I still cannot wrap my brain around. I believe the chapter about regexes (which is VERY good) is freely downloadable

[Tutor] Cython question

2011-07-02 Thread Albert-Jan Roskam
Hi, Some time ago I finished a sav reader for Spss .sav data files (also with the help of some of you!): http://code.activestate.com/recipes/577650-python-reader-for-spss-sav-files/ It works fine, but it is not fast with big files. I am thinking of implementing two of the functions in cython (g

Re: [Tutor] Cython question

2011-07-02 Thread Albert-Jan Roskam
one for us? ~~ --- On Sat, 7/2/11, Stefan Behnel wrote: From: Stefan Behnel Subject: Re: [Tutor] Cython question To: tutor@python.org Date: Saturday, July 2, 2011, 1:29 PM Albert-Jan Roskam, 02.07.2011 11:49: > Some time ago I finished a sav re

Re: [Tutor] Cython question

2011-07-03 Thread Albert-Jan Roskam
ver done for us? ~~ --- On Sat, 7/2/11, Stefan Behnel wrote: From: Stefan Behnel Subject: Re: [Tutor] Cython question To: tutor@python.org Date: Saturday, July 2, 2011, 4:52 PM Alan Gauld, 02.07.2011 15:28: > "Albert-Jan Roskam" wrote >> I used cPr

Re: [Tutor] Algorithm for sequence matching

2011-07-03 Thread Albert-Jan Roskam
Hi, Are you looking for a Longest Common Subsequence (LCS) algorithm? http://code.activestate.com/recipes/576869-longest-common-subsequence-problem-solver/ Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the

[Tutor] what is 'doubleword alignment'?

2011-07-16 Thread Albert-Jan Roskam
Hello, What is 'doubleword alignment'? It is used in the following sentence: "Fill up the buffer with the correctly encoded numeric and string values, taking care of blank padding and doubleword alignment." I know that the buffer is comprised of variables of 8-bytes, or multiples thereof, eac

Re: [Tutor] what is 'doubleword alignment'?

2011-07-16 Thread Albert-Jan Roskam
On Sat, 7/16/11, Albert-Jan Roskam wrote: From: Albert-Jan Roskam Subject: [Tutor] what is 'doubleword alignment'? To: "Python Mailing List" Date: Saturday, July 16, 2011, 8:23 PM Hello, What is 'doubleword alignment'? It is used in the following sentence: "Fill

[Tutor] questions on encoding

2011-07-20 Thread Albert-Jan Roskam
Hi, I am looking for test data with accented and multibyte characters. I have found a good resource that I could use to cobble something together (http://www.inter-locale.com/whitepaper/learn/learn-to-test.html) but I was hoping somebody knows some ready resource. I also have some questions ab

Re: [Tutor] what is 'doubleword alignment'?

2011-07-20 Thread Albert-Jan Roskam
--- On Mon, 7/18/11, Kushal Kumaran wrote: From: Kushal Kumaran Subject: Re: [Tutor] what is 'doubleword alignment'? To: "Walter Prins" Cc: tutor@python.org Date: Monday, July 18, 2011, 8:39 AM On Sun, Jul 17, 2011 at 9:15 PM, Walter Prins wrote: > > > On 17 July 2011 15:26, Lisi wrote: >> >

Re: [Tutor] little/big endian was Re: what is 'doubleword alignment'?

2011-07-21 Thread Albert-Jan Roskam
Thanks a lot for your explanations, that was most helpful! I never realized my mother tongue (Dutch) is Little Endian, whereas English is Big Endian, e.g.: dutch: negen-en-twintig (nine-and-twenty) english: twenty-nine I will improve my program based on what you all have said. I will let the pro

Re: [Tutor] Strange zip syntax

2011-09-16 Thread Albert-Jan Roskam
Hi,   I would write the slightly longer, but more readable (for me at least) code: >>> a = ['a','1','b','2','c','3'] >>> [(a[i], a[i+1]) for i in range(0, len(a), 2)] [('a', '1'), ('b', '2'), ('c', '3')] >>> zip(*[iter(a)]*2) [('a', '1'), ('b', '2'), ('c', '3')]   And it's also faster:   >>> import

[Tutor] ctypes and arrays of pointers

2011-10-13 Thread Albert-Jan Roskam
Hi, I have a question about ctypes. I am trying to call a C function but I am not able to construct the arguments in ctypes. I need to construct two pointers. Each is a pointer to an array of pointers to character values. I did it like this (I tried numerous ways; this seemed the cleanest way):

Re: [Tutor] ctypes and arrays of pointers

2011-10-15 Thread Albert-Jan Roskam
education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ >________ >From: Albert-Jan Roskam >To: Python Mailing List

  1   2   3   4   5   6   >