Re: [Tutor] (no subject)

2005-10-31 Thread Andrew P
If I'm not mistaken, that's the Pythonwin debugger spitting messages to the interactive prompt. I just used it to step through your your games framework example :) Being the first time I'd used any Python debugger, it didn't occur to me that the look of it was non-standard. I actually got the sa

Re: [Tutor] (no subject)

2005-10-31 Thread Andrew P
Before you hit the debugger, it might be a good idea to just run the script normally, either at the command line, or inside IDLE/Pythonwin. Doing so will spit out: Traceback (most recent call last): File "", line 1, in ? NameError: name 'ftplib' is not defined Because you imported with: from

Re: [Tutor] Newbie Question - Python vs Perl

2005-10-31 Thread Andrew P
If you are interested in learning another tool, please, start with Python. If you are interested in scripting UNIX, Perl is a fine choice. There prevalence matters, and quite a bit. But sys admins are usually very Perl-centric, and in my experience monolingual, and a bit of an insular community

Re: [Tutor] python myspace module?

2005-10-30 Thread Andrew P
Probably the most useful library from the wwwsearch page Danny pointed you to is the cookielib, which is built into Python as of 2.3 or 2.4. The most useful because you can't scrape by without it on most sites, and cookies are really no fun to handle manually Login and forms can largely be fudged

Re: [Tutor] AJAX resources for Python

2005-10-30 Thread Andrew P
Turbogears seconded. It's a really great collection of tools. As an alternative, you may also want to check out Nevow. From the webpage: "Nevow includes LivePage, a two-way bridge between JavaScript in a browser and Python on the server. For 0.3, LivePage has been updated to operate on Mozilla

Re: [Tutor] Code Readability (was: Recursion and List Comprehensions)

2005-10-29 Thread Andrew P
Sorry. *blush* That was some late Friday night craziness. I just looked at the code being discussed: retList=[word[pos]+item for item in permute3(word[0:pos]+word[pos+1:])] And really didn't want to anybody to confuse that with Python's idea of elegance. List comprehensions can get pretty hor

Re: [Tutor] Code Readability (was: Recursion and List Comprehensions)

2005-10-29 Thread Andrew P
Since when is elegance a dirty word? Elegance is the soul of good programming. A simple and graceful solution to the widest number of cases, efficient and easy to understand in application. Sometimes subtle, but always beautiful. In language design, software architecture, algorithms, it is the

Re: [Tutor] Help(!) with OOP/Composition from "Learning Python"

2005-10-21 Thread Andrew P
On 10/21/05, Kent Johnson <[EMAIL PROTECTED]> wrote: >For simple examples just look at Python's built in string, list and dict >classes. -Using- OOP isn't the problem :) It's impossible to ignore it's usefulness when programming in Python. But getting from there to thinking non-procedurally is,

Re: [Tutor] Help(!) with OOP/Composition from "Learning Python"

2005-10-20 Thread Andrew P
Hi Alan, thanks for taking the time to answer so thoroughly. I've responded to a few things below. But let me say right off I have gone through the OOP section in your excellent tutor. It was one of my main resources learning Python. I actually have Bertand Meyer's book here (and have written

[Tutor] Help(!) with OOP/Composition from "Learning Python"

2005-10-20 Thread Andrew P
I've been reading about composition vs inheritance, and went back to "Learning Python" to look at something I found very confusing a year ago. Turns out I still find it very confusing :) The code at the bottom was taken from the OOP chapter, it's a solution to one of the end-of-chapter problems.

Re: [Tutor] file opening and errors.

2005-10-20 Thread Andrew P
It's not in direct answer to your question, but a real short answer is "Python doesn't need 'or die' here." It throws exceptions gleefully whenever it encounters an error: >>> f = open('no_such_file') Traceback (most recent call last): File "", line 1, in ? IOError: [Errno 2] No such file or d

Re: [Tutor] if-else statements

2005-10-14 Thread Andrew P
Well, on the bright side, at least Python is being taught in schools. My younger sister is a CS major just starting her programming courses, and it's Java/C++ all the way. I am becoming convinced that lines of code are not only related to the number of bugs and development speed, but learning spe

Re: [Tutor] extract plain english words from html

2005-10-14 Thread Andrew P
You could try: http://www.aminus.org/rbre/python/cleanhtml.py YMMV, as the kids say. But I did choose this over BeautifulSoup or Strip-o-gram to do this particular thing. I don't remember -why- I chose it, but there you go. Easy enough to test all three :) Oh, and if you just want a whole page

Re: [Tutor] how to speed up this code?

2005-10-13 Thread Andrew P
It's way past my bedtime, but any use of numpy/numarray that involves two nested for loops to step over each element is the wrong solution :)  You need to figure out how to get rid of that inner for.  That is what is slowing you down.  Compare these two ways to multiply a 1000 element array by 10

Re: [Tutor] Please look at my wordFrequency.py

2005-10-11 Thread Andrew P
Just want to add a little something here, because reading over this thread, I think there may have been some confusion: Kent wrote: for e in saveRemovedForLaterL:    L.append(e)could be L.extend(e) I think he might have meant: for e in saveRemovedForLaterL:    L.append(e)could be L.extend(sav

Re: [Tutor] Please look at my wordFrequency.py

2005-10-11 Thread Andrew P
If it makes you feel any better, this isn't an easy problem to get 100% right, traditionally.  Heck, it might not even be possible.  A series of compromises might be  the best you can hope for. Some things to think about, however.  Can you choose the characters you want, instead of the (many, many

Re: [Tutor] Regex help

2005-10-09 Thread Andrew P
If the format is consistent enough,  you might get away with something like: >>> p = re.compile('MediaBox \[ ?\d+ \d+ (\d+) (\d+) ?\]') >>> print p.search(s).groups() ('612', '792') The important bits being:  ? means "0 or 1 occurences", and you can use parentheses to group matches, and they get

Re: [Tutor] Handling Objects

2005-10-05 Thread Andrew P
To do: $color = "Green"; print "$color apple.\n"; You would want: color = "Green" print "%s apple." % color Both of which would print "Green apple."  That is actually something I like about Perl, but it reinforces some bad habits, at least for me.  Boilerplate coding, as it were, when doing qui

Re: [Tutor] Trying to prevent ftplib from locking my script

2005-10-04 Thread Andrew P
Normally I wouldn't pipe up here because threads really can be very tricky.  But check out: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/435883 I use this recipe, originally from "Python in a Nutshell", all the time, to solve exactly your problem.  Slow network stuff that I don't have

Re: [Tutor] Beautiful soup

2005-10-04 Thread Andrew P
Oops, Paul is probably right.  I thought urllib2 opened local files in the absence of an identifier like "http://".  Bad assumption on my part.  I remembered that behavior from somewhere else, maybe urllib. That path beginning with "\\C:\\" could still bite you, however.  Good luck, Andrew _

Re: [Tutor] Beautiful soup

2005-10-04 Thread Andrew P
With error messages like that, the interesting bits are usually at the end: OSError: [Errno 2] No such file or directory: '\\C:\\Python24\\FRE_word_list.htm That should read "C:\\Python24\\FRE_word_list.htm".  I use UNIX-style paths, which work fine for me under Windows, so it would just be "/Py

Re: [Tutor] Book recommendations

2005-09-30 Thread Andrew P
Thanks Danny.  That outline of How to Solve It  reminded me of an idea that resonated strongly with me in Programming Pearls, and I just looked it up and sure enough,  Bentley was referencing the same Polya book: "Most of the structures exemplify what Polya calls the Inventor's Paradox in his How

Re: [Tutor] find data in html file

2005-09-30 Thread Andrew P
It's free now to use the API.  You just "self-certify" and get 10,000 calls a month. Imac, if you use the API, let me save you some trouble.  REST is useless, SOAP is overly complicated, which leaves XML over HTTP which is really quite nice.  I am not speaking generally, but talking about the ebay

Re: [Tutor] Book recommendations?

2005-09-30 Thread Andrew P
Thanks Mike.  Many a google search has landed me on his site, and I always end up reading more than what I landed on :) All of the above are great picks. I'd also recommend Joel On Software. It's acollection of his articles from his web site. ___ Tutor

Re: [Tutor] Book recommendations?

2005-09-30 Thread Andrew P
Thanks for the recommendations, Kent. Kent wrote: How could I forget the Gang of Four? This is the book that started the Design Patterns movement. Gamma, Helm, Johnson & Vlissides, Design Patternshttp://www.aw-bc.com/catalog/academic/product/0,1144,0201633612,00.html I probably shouldn't forget

[Tutor] Book recommendations?

2005-09-29 Thread Andrew P
I was just thinking about Jon Bentley's Programming Pearls, and how much I really liked it.  Nothing has really changed since 1986, and all the pseudo code translated nicely into Python.  It was by far the most fun I've had reading any book about programming.  Especially solving problems he present

Re: [Tutor] script question

2005-09-28 Thread Andrew P
Have you benchmarked it yet?  4000 lines isn't very many, even for an older machine.  Starting the Python interpreter usually takes most of the time with simple scripts like this.  Honestly, benchmark :) You might find it easier to do:: interface_list = INI.items(section)for i in interface_list:

Re: [Tutor] web development

2005-09-28 Thread Andrew P
I've used CherryPy on a couple of projects now.  I use it with HTMLTemplate (http://freespace.virgin.net/hamish.sanderson/htmltemplate.html) and SQLObject (http://sqlobject.org/). This has the advantage of being about as Pythonic as you can get, since everything you manipulate is represented as a