[Tutor] how to read a program

Prosenjit Kundu pk.python at gmail.com
Sat Jun 7 04:28:22 CEST 2008


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 <alan.gauld at btinternet.com>
>> wrote:
>>
>>
>>     
>>> "Anthony Parks" <abstractpoetry at gmail.com> 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 at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>>       
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>     
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at 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(100000):
end = 36
else:
end = 37
except:
end = 36
name_matches[z] = '_' + str(re.sub("[\[\`\~\!\@\#\$\%\ 
\^\&\*\(\)\_\+\-\=\{\}\\\:\;\<\>\,\.\?\/\|\'\"\]]",'_',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


More information about the Tutor mailing list