Re: [Tutor] Have Python Update Forms

2008-06-06 Thread Alan Gauld


"James" <[EMAIL PROTECTED]> wrote

I want to write a program that will update the 'last updated' field 
on
*every* item. This will require some sort of 'post' to the web 
server


I think I misunderstood your request. I thought you wanted to
add some new web browser functions but it looks like you may
want a batch update facility?

If so why not write directly to the database? Simulating a GUI
or web form is an intrinsicly unreliable way of doing things
and if possible you should go directly to the datyabase.
It will also be much quicker and have less resource hit on
your server. Or is here a reason you cannot talk to the
database?

Alan G 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error-handling for a large modular program

2008-06-06 Thread Alan Gauld

"Shrutarshi Basu" <[EMAIL PROTECTED]> wrote

I'm currently working on a research project where we'll be 
developing

a moderately complex piece of software. We're designing with
extensibility in mind. One of the problems I can see right now is 
that

our program can potentially create a large number of very different
errors, some fatal, some not.


That's not unusual. I have worked on projects with over a  thousand
exception classes (in C++ and Java).


I've only implemented basic error handling through a
number of try/except blocks and if/elses.


Thats the best way to proceed but...


However I feel that the code might become increasingly inelegant
if I keep adding a try/except for every possible error
(and breaking up the code to make it be a specific as possible
about the errors). Is there some more generic,
high-level approach I could use?


How are you using try/except. One of the big advantages of
try/except is that it does not break up your main code flow.
All the excepts sit outside of that.

If you put your main code in a function that raises the errors
then the error handling can come out to a higher level with

try:
  mainprocessingHere()
except error1: ...
except error2: ...
...
except error999:

You can also make things somewhat more manageable by
designing your error heirarchy carefully to use inheritance
to catch superclass errors then in the handlers using if/else
to determine the solution - seeral subclasses may share
a solution. But to be honest I prefer the explicit

except error1,error2,error3:

approach for that.

One approach I have thought of is creating a error handler class 
where

each class method corresponds to a particular error. An instance of
this class would be created at the start of the program and each 
error

would run a method in the class.


But if you extend your program you have to modify your error
handler class to add a new method and your main code will have
dependencies on the class throughout. And if you reuse the class
in other related projects they will be impacted too. By keeping
each exception class distinct its easy to add new error types
without affecting existing code too much and not affecting other
projects at all.


error handling code, without cluttering the actual working code.


I'm concerned at the fact you seeem to be "cluttering" the code.
The point of try/except is to keep the main code as uncluttered
as possible. Of course sometimes you want to handle an error
in-flow and an inline try/except of if/else is unavoidable but those
are usually minority cases.


still need try/catch blocks, but the catches wouldn't be
anything more than method calls.


They can still be that. Or simpler use vanilla functions. I'm not
a believer in writing classes just as a hold-all for a set of
functions. Thats what Python modules are for! But your functions
should probably aim to handle several related error types.


Since we have 3-4 people, each working on a
different part of the program, we could each add to this error 
handler

as needed.


Yes, if its a module it can hold the exception classes and
the handler functions. In fact if you want to be fancy you could
put the handler in the exception class but personally I think
thats a bad idea since the handler might be diffrent in other 
projects.

I prefer to keep the handlers and exceptions separate.


Since this is my first real world application that I'm writing as a
team, I have no idea how error handling is actually done in large
applications.


Its not uncommon in large apps for the error handling to be
more than half the code. When new grads or other inexperienced
programmers join a big project for the first time they are often
amazed at how much error code there is. The key is to keep it
together and as far away from the main flow as possible and
that's what try/except gives you.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Grabbing data from changing website

2008-06-06 Thread Sean Novak
I've recently been writing a web app with libxml2dom (  http://www.boddie.org.uk/python/libxml2dom.html 
 ).  I had a look at BeautifulSoup and found the two very similar.  I  
ended up sticking with libxml2dom because of a quote from its  
website.. "Performance is fairly respectable since libxml2dom  
makes direct use of libxml2mod - the low-level wrapping of libxml2 for  
Python.".  I figured the app might parse through a little faster.   
I guess the only way to tell is to benchmark the two against  
eachother.  Does anyone have input on defining differences?  Reasons  
to use one over the other?  Opinions welcome.

On Jun 5, 2008, at 3:03 PM, Tony Cappellini wrote:




--

Message: 4
Date: Wed, 4 Jun 2008 10:00:46 -0400
From: James <[EMAIL PROTECTED]>
Subject: [Tutor] Grabbing data from changing website
To: tutor@python.org
Message-ID:
   <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1


>>urllib2 will grab the HTML. BeautifulSoup will parse it and allow
>>fairly easy access. My writeup on each:

I'll second Kent's vote for BeautifulSoup.
I had never done any web programming, but using BS I quickly wrote a  
small program that downloads an image from a site.
The image changes daily, and the filename & directory are obviously  
unique. BS made it very easy.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Have Python Update Forms

2008-06-06 Thread James
Thanks for the response.

Ahhh, now we're going to get really off-topic. ;)

The only one that I've been able to scrape up for now was the infamous
DOM Inspector. Using the DOM Inspector, I can see:

- action ('/tool/update/todoUpdate.do')
- method is post
- name is 'todo'

There's a specific input (of type text). In fact, when I look at the
details for this field, I see:
- type (text)
- class (text)
- value (this is what I want to change)
- size
- maxlength
- name (lastUpdate)

Is this all the information I need to actually interact directly with
the webserver using Python to mimic POST functionality?

Also, are there any specific keywords I should be looking for in terms
of Firefox extensions to help me with whipping up a dirty hack like
this? :)

Thanks!

On Thu, Jun 5, 2008 at 8:43 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:
> On Thu, Jun 5, 2008 at 1:56 PM, James <[EMAIL PROTECTED]> wrote:
>> I want to write a program that will update the 'last updated' field on
>> *every* item. This will require some sort of 'post' to the web server
>> and interaction with the existing web tools and its back-end. I can
>> probably whip up a program (using the advice Kent gave yesterday in a
>> thread on this mailing list :)) to gather the entire list of items
>> that needs to be modified (all the to-do list item numbers, that is).
>> I'm not sure, however, how to mimic manually updating the last-updated
>> field.
>
> You have to find out how the browser talks to the backend. Most likely
> it is a POST with the form data. If so, you can simulate this in
> Python. See the section on POST here:
> http://personalpages.tds.net/~kent37/kk/00010.html
>
> There are various complications - authentication, hidden fields and
> JavaScript, for example - but essentially you want to write a Python
> program that mimics the interaction the browser has with the server.
>
> Tools that let you inspect the browser interaction are very helpful
> but I will leave you to ferret those out yourself. There are Firefox
> plugins that will do that.
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Have Python Update Forms

2008-06-06 Thread James
Thanks for the response, Alan. Unfortunately direct access to the
database is not a possibility. ;) It's one of those things where the
folks running the database don't want to share the necessary
credentials. I guess I've resorted to this "POST hack" in an effort to
make life easier, even without the database password.

- james

On Fri, Jun 6, 2008 at 3:51 AM, Alan Gauld <[EMAIL PROTECTED]> wrote:
>
> "James" <[EMAIL PROTECTED]> wrote
>
>> I want to write a program that will update the 'last updated' field on
>> *every* item. This will require some sort of 'post' to the web server
>
> I think I misunderstood your request. I thought you wanted to
> add some new web browser functions but it looks like you may
> want a batch update facility?
>
> If so why not write directly to the database? Simulating a GUI
> or web form is an intrinsicly unreliable way of doing things
> and if possible you should go directly to the datyabase.
> It will also be much quicker and have less resource hit on
> your server. Or is here a reason you cannot talk to the
> database?
>
> Alan G
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Have Python Update Forms

2008-06-06 Thread Kent Johnson
On Fri, Jun 6, 2008 at 8:58 AM, James <[EMAIL PROTECTED]> wrote:
> Thanks for the response.
>
> Ahhh, now we're going to get really off-topic. ;)
>
> The only one that I've been able to scrape up for now was the infamous
> DOM Inspector.

You really want to be looking at the transaction with the server, not
the contents of the web page. Firebug might do this, or Tamper Data,
I'm not sure what I have used in the past.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Have Python Update Forms

2008-06-06 Thread James
Phenomenal, Kent. I'll poke around and see if I can figure out what
kind of communication is going on between the server and the browser
and go from there. :)

I appreciate your and Alan's help, as always!

On Fri, Jun 6, 2008 at 9:37 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:
> On Fri, Jun 6, 2008 at 8:58 AM, James <[EMAIL PROTECTED]> wrote:
>> Thanks for the response.
>>
>> Ahhh, now we're going to get really off-topic. ;)
>>
>> The only one that I've been able to scrape up for now was the infamous
>> DOM Inspector.
>
> You really want to be looking at the transaction with the server, not
> the contents of the web page. Firebug might do this, or Tamper Data,
> I'm not sure what I have used in the past.
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2008-06-06 Thread amit sethi
Hi,
I  am a student new to python . I had a project idea in mind that I want to
implement in my break using python .
Can anyone give me an idea of libraries available in python for transcribing
music and signal processing.
Good tutorials with examples would also help. If any body has experience in
the field it would be nice if you could give me some guidance . And also
direct me to articles , references ,essays on the subject of pattern
recognition and music summary .
Also I would like to look at open source projects related to the above .
Thank you everyone .
-- 
A-M-I-T S|S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error-handling for a large modular program

2008-06-06 Thread bob gailer

Shrutarshi Basu wrote:
the front end of the program is essentially a parser for a moderately complex configuration language, which means that there are a variety of syntax/semantics errors possible. 
In my experience with parsers there is little or no need for try-except 
blocks. Could you give us an example of how you'd use try-except in your 
parser?


Also are you aware that there are a lot of parser programs out there 
(some in Python) that might save you time / effort?


--
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] TurtleWorld Windows issue

2008-06-06 Thread odispam
I am working through _Think Python_ in spare time at work on a Windows
machine (so another OS is not an option).  I can't get TurtleWorld to run
as described in the book
(http://www.greenteapress.com/thinkpython/html/book005.html).

I'm replicating the issue described here:

http://www.gamedev.net/community/forums/topic.asp?topic_id=481091

Using Windows XP, Idle v. 1.2.2, Python 2.5.2, Swampy 1.1.

After adding Swampy to the modules path:

>>> from TurtleWorld import *
>>> TurtleWorld()


No new window appears, or if it appears, it closes nearly instantaneously.

>>> bob = Turtle()
>>>

A new but empty window appears, titled "TurtleWorld (Not Responding)"

Opening and running the TurtleWorld module through the Idle GUI menu
produces a functioning TurtleWorld window, but this is not useful for the
purposes of the exercises.

This is probably more of an Idle/Windows issue than a python issue, but I
won't be able to get through Think Python unless I resolve it. Does anyone
have an answer?

Thanks!

Oliver

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] TurtleWorld Windows issue

2008-06-06 Thread W W
You could always use a linux live cd ;) Heck some of them can even
emulate linux in windows!

That's my best solution in the short time I've got.

HTH,
Wayne

On Fri, Jun 6, 2008 at 1:26 PM,  <[EMAIL PROTECTED]> wrote:
> I am working through _Think Python_ in spare time at work on a Windows
> machine (so another OS is not an option).  I can't get TurtleWorld to run
> as described in the book
> (http://www.greenteapress.com/thinkpython/html/book005.html).
>
> I'm replicating the issue described here:
>
> http://www.gamedev.net/community/forums/topic.asp?topic_id=481091
>
> Using Windows XP, Idle v. 1.2.2, Python 2.5.2, Swampy 1.1.
>
> After adding Swampy to the modules path:
>
 from TurtleWorld import *
 TurtleWorld()
> 
>
> No new window appears, or if it appears, it closes nearly instantaneously.
>
 bob = Turtle()

>
> A new but empty window appears, titled "TurtleWorld (Not Responding)"
>
> Opening and running the TurtleWorld module through the Idle GUI menu
> produces a functioning TurtleWorld window, but this is not useful for the
> purposes of the exercises.
>
> This is probably more of an Idle/Windows issue than a python issue, but I
> won't be able to get through Think Python unless I resolve it. Does anyone
> have an answer?
>
> Thanks!
>
> Oliver
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to read a program

2008-06-06 Thread Anthony Parks
ive been using diveintopython to learn how to write programs but i want to
sink my teeth into reading some bigger programs, to study them and maybe
pick up something new, especially  from programs where the development isn't
well document (unlike something like pidgin's development documentation
which is insanely detailed). are there any specific pieces of software
written in python you would recommend a novice to read? programs that
illustrate python at its finest, beautiful stretches of code? thanks for any
help

anthony
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] TurtleWorld Windows issue

2008-06-06 Thread Kent Johnson
On Fri, Jun 6, 2008 at 2:26 PM,  <[EMAIL PROTECTED]> wrote:
> I am working through _Think Python_ in spare time at work on a Windows
> machine (so another OS is not an option).  I can't get TurtleWorld to run
> as described in the book

Try using TurtleWorld without IDLE. IDLE is a Tkinter program itself
and it doesn't always play well with other Tkinter programs such as
TurtleWorld.

I was able to use TW from a DOS window on WinXP.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Batch insert

2008-06-06 Thread Mohit Jain
Hello all,

I am new to python. I wanted to know how can i do batch insert into Mysql
using python. A code snippet would be really helpful.


Thanks a lot

Mohit
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Fwd: Re: Intercepting methods calls]

2008-06-06 Thread Andreas Kostyrka
On Friday 06 June 2008 18:19:23 you wrote:
> On Thu, June 5, 2008 9:39 am, Andreas Kostyrka wrote:
> > On Thursday 05 June 2008 00:18:55 Marilyn Davis wrote:
> >> You listed __init__ and I'm not sure I know what you mean.
> >
> > Well, __init__ can assign attributes to the instance that are callable.
>
> Oh, well, Python is such a wide-open system.   It keeps blowing my mind.

Well, there is basically nothing that you cannot force the object system of 
Python to do, almost.

E.g. transplanting methods from class A to class B:

B.__dict__["method"] = A.__dict__["method"]

Or deriving a class from itself (although a better name would be "from a class 
that happened to be named the same).

class A:
pass
class A(A):
pass
print A.__bases__

Now, as an observation, you will notice that most experienced Python developers 
usually stay away from all this "magic" stuff. Rules of thumb include "explicit 
is good, implicit is bad", and so on. 
Clearly stuff tagged as "you really should know what you are doing".

>
> I'm thinking that if you can provide an __init__ you can intercept methods
> the regular way, by providing them the regular way, and overriding them.

Nope, I mentioned it, because this has been way back, when Python was 
young and slow, this was a technique to speed up method lookup.

Actually, it seems to work with py2.5 too, for oldstyle classes:

[EMAIL PROTECTED]:~/Videos$ python -m timeit -s 'class A:' -s '   def m(self): 
pass'
1000 loops, best of 3: 0.0675 usec per loop
[EMAIL PROTECTED]:~/Videos$ python -m timeit -s 'class A:' -s '   def m(self): 
pass' -s 'a=A()' 'a.m()'
100 loops, best of 3: 0.747 usec per loop
[EMAIL PROTECTED]:~/Videos$ python -m timeit -s 'class A:' -s '   def m(self): 
pass' -s 'a=A()' -s 'a.m=a.m' 'a.m()'
100 loops, best of 3: 0.575 usec per loop
[EMAIL PROTECTED]:~/Videos$ python -m timeit -s 'class A(object):' -s '   def 
m(self): pass' -s 'a=A()' 'a.m()'
100 loops, best of 3: 0.671 usec per loop
[EMAIL PROTECTED]:~/Videos$ python -m timeit -s 'class A(object):' -s '   def 
m(self): pass' -s 'a=A()' -s 'a.m=a.m' 'a.m()'
100 loops, best of 3: 0.641 usec per loop

The reason for this is, that the instance dictionary is the first place that 
Python looks when looking for a.m.

>
> Thank you Andreas.  This has been really interesting and instructive.

Yeah, but please consider my comment. I think every developer should
have seen the possibilities, but in most cases forget about that ugly stuff. 
You will get a headache, especially 
if you try to use the full "power" that Python provides. One can usually be 
quite productive without relying on
these mechanisms.

Andreas


signature.asc
Description: This is a digitally signed message part.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to read a program

2008-06-06 Thread Alan Gauld


"Anthony Parks" <[EMAIL PROTECTED]> wrote

which is insanely detailed). are there any specific pieces of 
software
written in python you would recommend a novice to read? programs 
that
illustrate python at its finest, beautiful stretches of code? thanks 
for any

help


You could start with the Python standard library. Many of the modules
there are fairly sparecly documented, partly because they are quite
well written!

Then look at the tools that ship with Python.

Then just search SourceForge for python projects.

Alan G 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Batch insert

2008-06-06 Thread Alan Gauld


"Mohit Jain" <[EMAIL PROTECTED]> wrote

I am new to python. I wanted to know how can i do batch insert into 
Mysql

using python. A code snippet would be really helpful.


If you can do it in SQL then it should be possible.
Do you know the SQL commands? Have you tried
using them like any other SQL command?
What happened?

I've never really used MySql much so don;t kniow for sure, but it
seems to me that it should just work.

Alan G. 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] TurtleWorld Windows issue

2008-06-06 Thread Alan Gauld


<[EMAIL PROTECTED]> wrote

machine (so another OS is not an option).  I can't get TurtleWorld 
to run

as described in the book
(http://www.greenteapress.com/thinkpython/html/book005.html).


I know nothing of TurtleWorld but...


from TurtleWorld import *
TurtleWorld()



No new window appears, or if it appears, it closes nearly 
instantaneously.


Thats what I'd expect...


bob = Turtle()


A new but empty window appears, titled "TurtleWorld (Not 
Responding)"


Thats also what I'd expect since you have created a turtle but not
drawn anything yet.

Check the methjods, you may need to make the turtle visible,
put the pen down, and move it around a bit.

If pen down is default(it usually is) try doing

bob.forward(50)

Does that do anything?

Presumably thre are some drawing examples in the book...

Alan G



Opening and running the TurtleWorld module through the Idle GUI menu
produces a functioning TurtleWorld window, but this is not useful 
for the

purposes of the exercises.

This is probably more of an Idle/Windows issue than a python issue, 
but I
won't be able to get through Think Python unless I resolve it. Does 
anyone

have an answer?

Thanks!

Oliver

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Fwd: Re: Intercepting methods calls]

2008-06-06 Thread Marilyn Davis
On Fri, June 6, 2008 3:37 pm, Andreas Kostyrka wrote:

> On Friday 06 June 2008 18:19:23 you wrote:
>
>> On Thu, June 5, 2008 9:39 am, Andreas Kostyrka wrote:
>>
>>> On Thursday 05 June 2008 00:18:55 Marilyn Davis wrote:
>>>
 You listed __init__ and I'm not sure I know what you mean.

>>>
>>> Well, __init__ can assign attributes to the instance that are
>>> callable.
>>
>> Oh, well, Python is such a wide-open system.   It keeps blowing my
>> mind.
>
> Well, there is basically nothing that you cannot force the object system
> of Python to do, almost.
>
> E.g. transplanting methods from class A to class B:
>
>
> B.__dict__["method"] = A.__dict__["method"]

Oh dear.

>
>
> Or deriving a class from itself (although a better name would be "from a
> class that happened to be named the same).
>
> class A: pass class A(A): pass print A.__bases__

Oh dear.

>
> Now, as an observation, you will notice that most experienced Python
> developers usually stay away from all this "magic" stuff. Rules of thumb
> include "explicit is good, implicit is bad", and so on. Clearly stuff
> tagged as "you really should know what you are doing".
>
>>
>> I'm thinking that if you can provide an __init__ you can intercept
>> methods the regular way, by providing them the regular way, and
>> overriding them.
>
> Nope, I mentioned it, because this has been way back, when Python was
> young and slow, this was a technique to speed up method lookup.
>
> Actually, it seems to work with py2.5 too, for oldstyle classes:
>
>
> [EMAIL PROTECTED]:~/Videos$ python -m timeit -s 'class A:' -s '   def
> m(self): pass'
> 1000 loops, best of 3: 0.0675 usec per loop
> [EMAIL PROTECTED]:~/Videos$ python -m timeit -s 'class A:' -s '   def
> m(self): pass' -s 'a=A()' 'a.m()'
> 100 loops, best of 3: 0.747 usec per loop
> [EMAIL PROTECTED]:~/Videos$ python -m timeit -s 'class A:' -s '   def
> m(self): pass' -s 'a=A()' -s 'a.m=a.m' 'a.m()'
> 100 loops, best of 3: 0.575 usec per loop

Wow.

> [EMAIL PROTECTED]:~/Videos$ python -m timeit -s 'class A(object):' -s '
> def m(self): pass' -s 'a=A()' 'a.m()' 100 loops, best of 3: 0.671 usec
> per loop [EMAIL PROTECTED]:~/Videos$ python -m timeit -s 'class A(object):'
> -s '   def m(self): pass' -s 'a=A()' -s 'a.m=a.m' 'a.m()'
> 100 loops, best of 3: 0.641 usec per loop
>
>
> The reason for this is, that the instance dictionary is the first place
> that Python looks when looking for a.m.

I see.  Well, that is interesting.  I'm glad I asked.

>
>>
>> Thank you Andreas.  This has been really interesting and instructive.
>>
>
> Yeah, but please consider my comment. I think every developer should
> have seen the possibilities, but in most cases forget about that ugly
> stuff. You will get a headache, especially if you try to use the full
> "power" that Python provides. One can usually be quite productive without
> relying on these mechanisms.

Yes, and if you consider the poor readers of your code, and/or if speed
isn't so critical, it would be best to forget it.  But, thank you for
showing this to me.

Do you have anything else really interesting to share?

Marilyn Davis

>
> Andreas


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to read a program

2008-06-06 Thread Anthony Parks
that sounds like good advice, but i think what i meant is something along
the lines of:

"what are particularly great programs to *read*. not like great software,
but great source code. somewhat like treating source code as a literature,
what are the classics?

On Fri, Jun 6, 2008 at 7:16 PM, Alan Gauld <[EMAIL PROTECTED]>
wrote:

>
> "Anthony Parks" <[EMAIL PROTECTED]> wrote
>
>  which is insanely detailed). are there any specific pieces of software
>> written in python you would recommend a novice to read? programs that
>> illustrate python at its finest, beautiful stretches of code? thanks for
>> any
>> help
>>
>
> You could start with the Python standard library. Many of the modules
> there are fairly sparecly documented, partly because they are quite
> well written!
>
> Then look at the tools that ship with Python.
>
> Then just search SourceForge for python projects.
>
> Alan G
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to read a program

2008-06-06 Thread Marilyn Davis
This is pretty cool:

http://aspn.activestate.com/ASPN/Python/Cookbook/

Marilyn Davis

On Fri, June 6, 2008 4:34 pm, Anthony Parks wrote:

> that sounds like good advice, but i think what i meant is something along
>  the lines of:
>
> "what are particularly great programs to *read*. not like great software,
>  but great source code. somewhat like treating source code as a
> literature, what are the classics?
>
> On Fri, Jun 6, 2008 at 7:16 PM, Alan Gauld <[EMAIL PROTECTED]>
> wrote:
>
>
>>
>> "Anthony Parks" <[EMAIL PROTECTED]> wrote
>>
>>
>> which is insanely detailed). are there any specific pieces of software
>>> written in python you would recommend a novice to read? programs that
>>>  illustrate python at its finest, beautiful stretches of code? thanks
>>> for any help
>>>
>>
>> You could start with the Python standard library. Many of the modules
>> there are fairly sparecly documented, partly because they are quite well
>> written!
>>
>> Then look at the tools that ship with Python.
>>
>>
>> Then just search SourceForge for python projects.
>>
>>
>> Alan G
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to read a program

2008-06-06 Thread Prosenjit Kundu

Marilyn Davis wrote:

This is pretty cool:

http://aspn.activestate.com/ASPN/Python/Cookbook/

Marilyn Davis

On Fri, June 6, 2008 4:34 pm, Anthony Parks wrote:

  

that sounds like good advice, but i think what i meant is something along
 the lines of:

"what are particularly great programs to *read*. not like great software,
 but great source code. somewhat like treating source code as a
literature, what are the classics?

On Fri, Jun 6, 2008 at 7:16 PM, Alan Gauld <[EMAIL PROTECTED]>
wrote:




"Anthony Parks" <[EMAIL PROTECTED]> wrote


which is insanely detailed). are there any specific pieces of software
  

written in python you would recommend a novice to read? programs that
 illustrate python at its finest, beautiful stretches of code? thanks
for any help



You could start with the Python standard library. Many of the modules
there are fairly sparecly documented, partly because they are quite well
written!

Then look at the tools that ship with Python.


Then just search SourceForge for python projects.


Alan G


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


  

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  

try this to fetch all code :


##
import urllib,re,sys,string
fileInName = raw_input('Enter the drive and the full path name, with 
trailing backslash where the Python .py files will end up-->')

for x in range(1,2206,20):
url = 'http://aspn.activestate.com/ASPN/Cookbook/Python?query_start=' + 
str(x)

f = urllib.urlopen(url)
s = f.read()
f.close()
matches = re.findall("/ASPN/Cookbook/Python/Recipe/(\d*)",s)
pattern = '/ASPN/Cookbook/Python/Recipe/.*.(?=<)'
name_matches = re.findall(pattern,s)
for z in range (len(name_matches)):
try:
if int(matches[z]) < int(10):
end = 36
else:
end = 37
except:
end = 36
name_matches[z] = '_' + str(re.sub("[EMAIL PROTECTED] 
\^\&\*\(\)\_\+\-\=\{\}\\\:\;\<\>\,\.\?\/\|\'\"\]]",'_',name_matches[z][end:]))

name_matches[z] = string.rstrip(name_matches[z],'_a')
while '__' in name_matches[z]:
name_matches[z] = string.replace(name_matches[z], '__', '_')
name_matches[z] = '_' + matches[z] + name_matches[z] + '.py'
name_matches[z] = string.replace(name_matches[z], '_py.py', '.py')
name_matches[z] = string.replace(name_matches[z], '_by.py', '.py')
name_matches[z] = string.replace(name_matches[z], 'quot_', '')
url = 'http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/' + 
str(matches[z]) + '/index_txt'

f = urllib.urlopen(url)
s = f.read()
f.close()
fileOutName = str(fileInName) + str(name_matches[z])
fileOut = open(fileOutName, 'w')
fileOut.write(s)
fileOut.close()
print "I'm finished.";



- Prosenjit
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor