Re: [Tutor] Sum of Scores

2007-07-27 Thread Tiger12506
Hmmm... interesting tie to another post...

>>> x = timeit.Timer('random.random()','import random')
>>> x.timeit(300)
1.0161026052194018
>>> y = timeit.Timer('random()','from random import random')
>>> y.timeit(460)
1.0004307810070827

Dictionary lookups do take HUGE amounts of time. Interesting.

Anyway... I've got it down to
Your numbers with a little more precision gave me
3.4e5987 yrs.

and mine

3.0e5987 yrs.

That's a hell of a lot of years! Remember that everyone! If you want your 
code to run forever and to eternity, copy variables to the local namespace 
first; you get a lot more accomplished (well... whatever);-)

Anyway, the frivolity aside, I can get it to repeat every ten seconds. ;-)
Set the computer clock. (okay, maybe i'm just in a silly mood. But 
seriously,
that's why the docs say that it is NOT meant for cryptography - not that 
that matters
to the OP, snicker; What have I been drinking)

> Well, I was trying to emphasize that it was, for pretty much all intents 
> and purposes, infinite.

Nope-nope-nope you're wrong :-)~

The daring cracker enters the room, his heart quickening as the door hinge 
creaks with the sound of the smallest ever mouse. His dark clothing masks 
him from the lit room visible through the window on the adjacent wall. A 
woman, working late, sits in a comfortable office chair, her face glowing 
from the reflection of her computer screen. A cup of Java (pun intended) 
indicates to anyone watching that she is overworked, and under-paid.

Each step he takes brings him closer to his target. The big boss gave him a 
pay cut so that this new PC could sit on his boss's desk. The cracker's 
jealously seems to almost permeate the room. Vengeance shouts out louder 
than the compressor of the air conditioner in the north window. The cracker 
intinctively looks up to see if his emotions betrayed his presence. But the 
woman in the other room continues her scrolling through endless lines of 
buggy, hard to read, unmaintainable, bloated, and otherwise ridiculously 
foolish code that could have been so easily fixed if the same 'big boss' had 
ordered the project in Python.

Soon, a floppy disk is pulled out of a black jacket pocket. No one has ever 
run the program on the floppy before. Taking the disk, the cracker inserts 
it into the drive, starts the machine, swears under his breath when he reads 
"Non-System disk or disk error. Replace and strike any."

Striking the 'any' key, he quickly shoves the floppy disk back in. He wants 
this over with. Again, he looks to see if he has been detected; still he is 
safe. Opening the folder containing the floppy drive, he groans silently as 
the annoying Windows Firewall flashes an update notice. "See..." he thinks 
to himself, "Micro$oft *can* actually restrict viruses from entering their 
OS." He fights with the window, impatiently waiting for countless libraries 
to load and free, until the UI responds and he can send it a WM_CLOSE 
message.

Smirking evily, the cracker double-clicks the executable 
'pink_fuzzy_bunny.exe' and resists the urge to laugh maniacally as he 
watches the computer clock freeze and not move. Ingenious--his plan--All it 
takes to freeze time is to contantly set it to the same second in history. 
Time. Forever frozen. He frowns as he realizes that in so doing, he provides 
the only effective means for keeping those pesky Windows notices out of his 
boss's hair. "No matter" --he thinks, "He will have worse troubles in due 
time." Again he suppresses a maniacal laugh.

. . .

Monday morning brings a bright and cheerful man into an office, his office. 
The door creaks a little as he opens it, and the air conditioner buzzing in 
the north wall window is refreshing to him after the heat from outside. The 
man waves cheerfully at a woman through the glass in the adjacent wall, whom 
looks up only for an instant to scowl. The man, who recently bought his new 
PC, smiles proudly as he turns it on. His new python program which he keeps 
on the desktop is his early attempt at a cricket game simulation. He 
lovingly double-clicks the icon, and runs the program several times. Each 
successive time his grin grows smaller and smaller until his face is more 
than troubled. Why is his program producing the same output every time? A 
scream is heard in the office "NOOO"
The boss runs from the building, never to notice the clock in the 
bottom-right hand corner which still shows the caption '10:33 PM'.

Somewhere, someplace a cracker lies in bed, a silly grin on his face. His 
objective, he knows, has been accomplished.

> Because the possibility of my computer even existing after that long is 
> effectively zero, I consider the pattern to never repeat :)

Ahhh...
Your computer ~ sitting on a pedestal in the middle of nowhere in AD 
3.0e5988, the last shrine to the ancient past-- A technological marvel to 
the ape like creatures whom are all that remain of the once all powerful 
race of human beings.


Re: [Tutor] Code like a Pythonista

2007-07-27 Thread Dick Moores
At 05:13 AM 7/26/2007, Kent Johnson wrote:
>For anyone who has wondered, how do I learn to write Python like an
>expert? What do I read after I finish the tutorial? Check out David
>Goodger's "Code Like a Pythonista"
>http://python.net/~goodger/projects/pycon/2007/idiomatic/

Kent,

The handout is excellent! Thanks!

But the slideshow at 
, 
isn't.

Dick Moores


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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Barton David

I mean no offense and lay no blame. It's simply that I feel like I've
been led up a nice gentle beach and suddenly I'm dodging boulders at the
bottom of a cliff.

I've learned to program with Python (and can hardly conceive of a better
language to be honest)- and I still think the core language is great:
elegant, easy to use and brilliantly documented.

But the more I explore the standard library and third party modules, the
more I run into trouble: a chaotic library structure that seems to
conceal capabilities rather than promote them, similar modules that
don't work in similar ways, a whole new level of opaque programming
lingo that makes me feel excluded, behaviours that I don't understand,
don't want, and that I can't find documentation to explain, and so on.

I guess it's not Python's fault: I'm guess I'm just too stupid. But I'm
just getting really disenchanted. Sorry.
 

-Original Message-
From: Kent Johnson [mailto:[EMAIL PROTECTED] 
Sent: 27 July 2007 13:07
To: Barton David
Cc: tutor@python.org
Subject: Re: [Tutor] Shelve del not reducing file size

Barton David wrote:
> *sigh* I'm really going off Python.

In what way is it Python's fault that the dbm database doesn't reclaim
disk space?

Kent

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Kent Johnson
Well, 'carpers' was my word but there is some truth to it. For example 
this recent exchange:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/77285bd20fafbf2b/b0ffd482e925f0c0?hl=en#b0ffd482e925f0c0
which made it into QOTW in Python-URL, inspiring this rejoinder:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/6348bfbb69642a4a/1d7f98c3c82fd64b?hl=en#1d7f98c3c82fd64b

Ultimately it seems to come down to
- Python is open source
- Python developers are largely unpaid volunteers working on what 
interests them
- If you want something to change, you can
-- do it yourself
-- convince someone to volunteer to do it
-- pay someone to do it

So far cleaning up the std lib has not attracted any of these three options.

Kent

Barton David wrote:
> Sadly I can't think of a plan B, hence the frustration! Python, as far
> as I know, is as good as it gets. And I don't have the courage or the
> capability to improve it myself.
> 
> So all I can really do is clasp my hands together and helplessly plead:
> "Won't Somebody, Please, Think of the Children!" 
> 
> (Meaning struggling non-pro users like me, of course)
> 
> As far as I'm concerned, the core language has matured to be elegant and
> terrificly newbie-friendly, but the extended functionality (the standard
> library) absolutely has not. It disappoints me that Guido and many other
> developers *seem* to be more concerned with strategies for revamping the
> former than they are with strategies for improving the latter. If Kay
> Schluehr, Paul Rubin and John Nagle are opposing this trend and being
> dismissed as 'carpers' then I fear Python has lost sight of the
> 'friendliness' it once seemed to aspired to. 
> 
> 
> 
> -Original Message-
> From: Kent Johnson [mailto:[EMAIL PROTECTED] 
> Sent: 27 July 2007 14:11
> To: Barton David
> Cc: tutor@python.org
> Subject: Re: [Tutor] Shelve del not reducing file size
> 
> If it's any solace, there is a small minority of Python users who agree
> with you. There *are* rough edges in the library modules and the library
> docs. The great majority of Python users seem to find them good enough
> and are pleased and amazed at what you can do with the batteries
> included. A minority find the warts, omissions and inconsistencies to be
> very frustrating, and not because they (the users) are dumb. IIRC some
> prominent carpers on comp.lang.python are Kay Schluehr, Paul Rubin and
> John Nagle.
> 
> I'm curious, what is plan B? Do you have something better than Python to
> try? I guess the above-named people are still with Python because the
> benefits outweigh the warts.
> 
> Kent
> 
> 
> This message has been checked for viruses but the contents of an attachment
> may still contain software viruses, which could damage your computer system:
> you are advised to perform your own checks. Email communications with the
> University of Nottingham may be monitored as permitted by UK legislation.
> 
> ___
> 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] Shelve del not reducing file size

2007-07-27 Thread Barton David
Sadly I can't think of a plan B, hence the frustration! Python, as far
as I know, is as good as it gets. And I don't have the courage or the
capability to improve it myself.

So all I can really do is clasp my hands together and helplessly plead:
"Won't Somebody, Please, Think of the Children!" 

(Meaning struggling non-pro users like me, of course)

As far as I'm concerned, the core language has matured to be elegant and
terrificly newbie-friendly, but the extended functionality (the standard
library) absolutely has not. It disappoints me that Guido and many other
developers *seem* to be more concerned with strategies for revamping the
former than they are with strategies for improving the latter. If Kay
Schluehr, Paul Rubin and John Nagle are opposing this trend and being
dismissed as 'carpers' then I fear Python has lost sight of the
'friendliness' it once seemed to aspired to. 



-Original Message-
From: Kent Johnson [mailto:[EMAIL PROTECTED] 
Sent: 27 July 2007 14:11
To: Barton David
Cc: tutor@python.org
Subject: Re: [Tutor] Shelve del not reducing file size

If it's any solace, there is a small minority of Python users who agree
with you. There *are* rough edges in the library modules and the library
docs. The great majority of Python users seem to find them good enough
and are pleased and amazed at what you can do with the batteries
included. A minority find the warts, omissions and inconsistencies to be
very frustrating, and not because they (the users) are dumb. IIRC some
prominent carpers on comp.lang.python are Kay Schluehr, Paul Rubin and
John Nagle.

I'm curious, what is plan B? Do you have something better than Python to
try? I guess the above-named people are still with Python because the
benefits outweigh the warts.

Kent


This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



Barton David wrote:
> I mean no offense and lay no blame. It's simply that I feel like I've
> been led up a nice gentle beach and suddenly I'm dodging boulders at the
> bottom of a cliff.
> 
> I've learned to program with Python (and can hardly conceive of a better
> language to be honest)- and I still think the core language is great:
> elegant, easy to use and brilliantly documented.
> 
> But the more I explore the standard library and third party modules, the
> more I run into trouble: a chaotic library structure that seems to
> conceal capabilities rather than promote them, similar modules that
> don't work in similar ways, a whole new level of opaque programming
> lingo that makes me feel excluded, behaviours that I don't understand,
> don't want, and that I can't find documentation to explain, and so on.
> 
> I guess it's not Python's fault: I'm guess I'm just too stupid. But I'm
> just getting really disenchanted. Sorry.

No, the Python documentation is sometimes brief. And some places are not
really documented (like some dusty corners in the hotshot profiler). But
OTOH, it's also hard on newbies, because it usually documents but does
not explain what a module does, e.g., it often expects the reader to
know the protocols involved, sometimes it expects the reader to know
computer science basics.

Andreas

>  
> 
> -Original Message-
> From: Kent Johnson [mailto:[EMAIL PROTECTED] 
> Sent: 27 July 2007 13:07
> To: Barton David
> Cc: tutor@python.org
> Subject: Re: [Tutor] Shelve del not reducing file size
> 
> Barton David wrote:
>> *sigh* I'm really going off Python.
> 
> In what way is it Python's fault that the dbm database doesn't reclaim
> disk space?
> 
> Kent
> 
> This message has been checked for viruses but the contents of an attachment
> may still contain software viruses, which could damage your computer system:
> you are advised to perform your own checks. Email communications with the
> University of Nottingham may be monitored as permitted by UK legislation.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGqfKEHJdudm4KnO0RArCBAJ9aaV4B4Q1qpl2jivQqX7adcWZ0FQCfY9nF
7SnuvfumY0AlGsYkJ4LgGBE=
=5Chn
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Kent Johnson
If it's any solace, there is a small minority of Python users who agree 
with you. There *are* rough edges in the library modules and the library 
docs. The great majority of Python users seem to find them good enough 
and are pleased and amazed at what you can do with the batteries 
included. A minority find the warts, omissions and inconsistencies to be 
very frustrating, and not because they (the users) are dumb. IIRC some 
prominent carpers on comp.lang.python are Kay Schluehr, Paul Rubin and 
John Nagle.

I'm curious, what is plan B? Do you have something better than Python to 
try? I guess the above-named people are still with Python because the 
benefits outweigh the warts.

Kent

Barton David wrote:
> But the more I explore the standard library and third party modules, the
> more I run into trouble: a chaotic library structure that seems to
> conceal capabilities rather than promote them, similar modules that
> don't work in similar ways, a whole new level of opaque programming
> lingo that makes me feel excluded, behaviours that I don't understand,
> don't want, and that I can't find documentation to explain, and so on.
> 
> I guess it's not Python's fault: I'm guess I'm just too stupid. But I'm
> just getting really disenchanted. Sorry.
>  
> 
> -Original Message-
> From: Kent Johnson [mailto:[EMAIL PROTECTED] 
> Sent: 27 July 2007 13:07
> To: Barton David
> Cc: tutor@python.org
> Subject: Re: [Tutor] Shelve del not reducing file size
> 
> Barton David wrote:
>> *sigh* I'm really going off Python.
> 
> In what way is it Python's fault that the dbm database doesn't reclaim
> disk space?
> 
> Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Eric Brunson
Andreas Kostyrka wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
>
>
> Barton David wrote:
>   
>> I mean no offense and lay no blame. It's simply that I feel like I've
>> been led up a nice gentle beach and suddenly I'm dodging boulders at the
>> bottom of a cliff.
>>
>> I've learned to program with Python (and can hardly conceive of a better
>> language to be honest)- and I still think the core language is great:
>> elegant, easy to use and brilliantly documented.
>>
>> But the more I explore the standard library and third party modules, the
>> more I run into trouble: a chaotic library structure that seems to
>> conceal capabilities rather than promote them, similar modules that
>> don't work in similar ways, a whole new level of opaque programming
>> lingo that makes me feel excluded, behaviours that I don't understand,
>> don't want, and that I can't find documentation to explain, and so on.
>>
>> I guess it's not Python's fault: I'm guess I'm just too stupid. But I'm
>> just getting really disenchanted. Sorry.
>> 
>
> No, the Python documentation is sometimes brief. And some places are not
> really documented (like some dusty corners in the hotshot profiler). But
> OTOH, it's also hard on newbies, because it usually documents but does
> not explain what a module does, e.g., it often expects the reader to
> know the protocols involved, sometimes it expects the reader to know
> computer science basics.
>   

It seems like new programmers today expect to be spoonfed their 
information like they were in grammar school.  They don't know what it 
is to hack a Makefile to get a package to compile or break out an RFC to 
understand a protocol.  If you don't understand something and the 
documentation is lacking, then strap on a pair and read the source, 
write some test cases, dig a little.  In our environment most of the 
code you'd have to read is just more Python, anyway.

Just me being a grouchy old programmer.  In my day we had to program in 
4 feet of snow, uphill... both ways!

> Andreas
>
>   
>>  
>>
>> -Original Message-
>> From: Kent Johnson [mailto:[EMAIL PROTECTED] 
>> Sent: 27 July 2007 13:07
>> To: Barton David
>> Cc: tutor@python.org
>> Subject: Re: [Tutor] Shelve del not reducing file size
>>
>> Barton David wrote:
>> 
>>> *sigh* I'm really going off Python.
>>>   
>> In what way is it Python's fault that the dbm database doesn't reclaim
>> disk space?
>>
>> Kent
>>
>>
>> 

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Barton David
Eric Brunson wrote:

> It seems like new programmers today expect to be spoonfed their 
> information like they were in grammar school.  They don't know what it 
> is to hack a Makefile to get a package to compile or break out an RFC to 
> understand a protocol.  If you don't understand something and the 
> documentation is lacking, then strap on a pair and read the source, 
> write some test cases, dig a little.  In our environment most of the 
> code you'd have to read is just more Python, anyway.
> 
> Just me being a grouchy old programmer.  In my day we had to program in 
> 4 feet of snow, uphill... both ways!


heh. Well give me some credit. I taught myself to program, from scratch, 
without access to (or time for) any courses whatsoever, while doing a PhD in 
genetics. I've been using it for about 5 years now and I know the core language 
and certain standard modules pretty well. I doubt I would have got as far as I 
have if Python wasn't so newbie-friendly. My only complaint is that I'm 
starting to feel like I won't get much further than that without a computer 
science degree.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Barton David
*sigh* I'm really going off Python.

OK, thanks Andreas.
 

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


[Tutor] Shelve del not reducing file size

2007-07-27 Thread Barton David
Hi,
 
I've hit a snag with Python's shelve module. By way of example...
 
_
from shelve import DbfilenameShelf as StoreFile
import os
 
sf=StoreFile("mytest.db",writeback=False) # but same problem if
writeback=True
for i in range(1):
sf[str(i)]="TESTOBJECT"
sf.sync()
print len(sf)
sf.close()
predeletesize=os.path.getsize("mytest.db")
print predeletesize
 
sf=StoreFile("mytest.db",writeback=False) # but same problem if
writeback=True
for i in range(5000):
del sf[str(i)]
sf.sync()
print len(sf)
sf.close()
postdeletesize=os.path.getsize("mytest.db")
print postdeletesize
_
 
So why, when I run this, does predeletesize!=postdeletesize?
I gather that with most database types you have to invoke a special
command like VACUUM to perform cleanups after table deletions etc
so, since shelve uses database backends, is this related to that? Is
there a way to tell (e.g.) a DBfilenameShelf to do this? Or am I stuck
with having to delete the entire file and save it again?
 
 
Running PythonWin 2.5.1 on XP.
 
thanks
Dave

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

That's in the nature of the underlying database library used for the
shelve. Most dbm implemention on Unix are using a sparse file that is
used as hashmap. E.g. compare ls -l versus du of the database file.

Now if this is the case, there is no way (with the exception of
rewriting the whole file cleverly from scratch, e.g. with cp
- --sparse=always) to release the unused space. (I don't think that even
Linux detects 0 byte filled pages and frees them.)

Andreas

Barton David wrote:
> Hi,
>  
> I've hit a snag with Python's shelve module. By way of example...
>  
> _
> from shelve import DbfilenameShelf as StoreFile
> import os
>  
> sf=StoreFile("mytest.db",writeback=False) # but same problem if
> writeback=True
> for i in range(1):
> sf[str(i)]="TESTOBJECT"
> sf.sync()
> print len(sf)
> sf.close()
> predeletesize=os.path.getsize("mytest.db")
> print predeletesize
>  
> sf=StoreFile("mytest.db",writeback=False) # but same problem if
> writeback=True
> for i in range(5000):
> del sf[str(i)]
> sf.sync()
> print len(sf)
> sf.close()
> postdeletesize=os.path.getsize("mytest.db")
> print postdeletesize
> _
>  
> So why, when I run this, does predeletesize!=postdeletesize?
> I gather that with most database types you have to invoke a special
> command like VACUUM to perform cleanups after table deletions etc
> so, since shelve uses database backends, is this related to that? Is
> there a way to tell (e.g.) a DBfilenameShelf to do this? Or am I stuck
> with having to delete the entire file and save it again?
>  
>  
> Running PythonWin 2.5.1 on XP.
>  
> thanks
> Dave
> 
> This message has been checked for viruses but the contents of an
> attachment may still contain software viruses, which could damage your
> computer system: you are advised to perform your own checks. Email
> communications with the University of Nottingham may be monitored as
> permitted by UK legislation.
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGqb+nHJdudm4KnO0RAtxDAKDCcZUJ8uy6bGJ1mL/kUEnswUL3oACg3ihz
iQjQTZFdetdzYME6XmrfXRQ=
=Xxwv
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Barton David
Andreas Kostyrka wrote:
> Additionally, the language core is very very thought out, with glacial
> enhancements. "Fixing" the standard library OTOH would involve
renaming
> and removing names, which would make huge collections of programs
break.
> Not a good thing :(

Yes agreed. My comments there were primarily about the future of python
(i.e. Python 3000).



Kent Johnson wrote:
>  Ultimately it seems to come down to
> - Python is open source
> - Python developers are largely unpaid volunteers working on what
interests them
> - If you want something to change, you can
> -- do it yourself
> -- convince someone to volunteer to do it
> -- pay someone to do it
> 
> So far cleaning up the std lib has not attracted any of these three
options.

Yes of course. But not *all* Python developers are unpaid. And even if
they were- this ship isn't rudderless. It could be steered towards
standard library overhaul (in Py3000) if Guido so decreed (and if he
laid out a nice appealing framework, perhaps). But I guess if everybody
thinks it's ok or nobody thinks it can be improved then that isn't going
to happen.



Andreas Kostyrka wrote:
> Stop.

Somehow that one word just sums it all up!

Yeah I'll stop. It's not like I'm out to upset anybody. But please,
somebody up there, Think of the Children, eh?

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Kent Johnson
Barton David wrote:
> *sigh* I'm really going off Python.

In what way is it Python's fault that the dbm database doesn't reclaim 
disk space?

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



Barton David wrote:
> Sadly I can't think of a plan B, hence the frustration! Python, as far
> as I know, is as good as it gets. And I don't have the courage or the
> capability to improve it myself.
> 
> So all I can really do is clasp my hands together and helplessly plead:
> "Won't Somebody, Please, Think of the Children!" 
> 
> (Meaning struggling non-pro users like me, of course)
> 
> As far as I'm concerned, the core language has matured to be elegant and
> terrificly newbie-friendly, but the extended functionality (the standard
> library) absolutely has not. It disappoints me that Guido and many other
> developers *seem* to be more concerned with strategies for revamping the
> former than they are with strategies for improving the latter. If Kay
> Schluehr, Paul Rubin and John Nagle are opposing this trend and being
> dismissed as 'carpers' then I fear Python has lost sight of the
> 'friendliness' it once seemed to aspired to. 

Stop. The standard library is not perfect, but it's better than what
many other languages come with. Second, you should not fear improving
stuff yourself, that's one of the benefits of Python that it's easy to read.

Furthermore, it's an unsolved problem. IMHO, learning a new language,
even something atypical (nonimperative) like Prolog takes seldom more
than 1-2 days. Learning the runtime environment/standard library/add on
libraries take at least a magnitude longer. Learning the idiomatic way
to do something takes again even longer.

Additionally, the language core is very very thought out, with glacial
enhancements. "Fixing" the standard library OTOH would involve renaming
and removing names, which would make huge collections of programs break.
Not a good thing :(

Andreas

I know no language that beats this pattern.


> 
> 
> 
> -Original Message-
> From: Kent Johnson [mailto:[EMAIL PROTECTED] 
> Sent: 27 July 2007 14:11
> To: Barton David
> Cc: tutor@python.org
> Subject: Re: [Tutor] Shelve del not reducing file size
> 
> If it's any solace, there is a small minority of Python users who agree
> with you. There *are* rough edges in the library modules and the library
> docs. The great majority of Python users seem to find them good enough
> and are pleased and amazed at what you can do with the batteries
> included. A minority find the warts, omissions and inconsistencies to be
> very frustrating, and not because they (the users) are dumb. IIRC some
> prominent carpers on comp.lang.python are Kay Schluehr, Paul Rubin and
> John Nagle.
> 
> I'm curious, what is plan B? Do you have something better than Python to
> try? I guess the above-named people are still with Python because the
> benefits outweigh the warts.
> 
> Kent
> 
> 
> This message has been checked for viruses but the contents of an attachment
> may still contain software viruses, which could damage your computer system:
> you are advised to perform your own checks. Email communications with the
> University of Nottingham may be monitored as permitted by UK legislation.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGqfvcHJdudm4KnO0RAsh7AKCXgnJGwMngrhup6LYFcAf6fRIKwgCcCfCc
UEM+K4XWqNpauhq94WwmXlE=
=1FEE
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running Python on Gentoo

2007-07-27 Thread David Rock
* Greg Lindstrom <[EMAIL PROTECTED]> [2007-07-26 13:44]:
> Hello,
> I am running python 2.4.2 on Gentoo Unix and am having problems running 
> programs.  I have a script, hello.py as such:
> 
> #! /usr/bin/python
> print 'hello, world'
> 
> that I save and add executable permission.  Then at the prompt I type in..
> 
> $ ./hello.py
> -bash: ./hello.py: /usr/bin/python: bad interpreter: Permission denied
> 
> If I type
> $ python hello.py
> I get "hello, world" as expected.
> 
> I was hoping that the "shabang" would have the script execute.  Am I 
> missing something?  Can you help me?  BTW, when I type /usr/bin/python 
> at the prompt I get the python interpreter, so at least that's working.

Are you using any hardened gentoo kernels or anything like that, or is
it a "normal" gentoo build?

I don't think this is a python problem, but rather a permissions problem
at a level OTHER than the filesystem.

I found this in the gentoo forums:
http://forums.gentoo.org/viewtopic-t-549470-highlight-interpreter+permission+denied.html

Are you using any "trusted path execution" in the kernel?  This would
potentially be something that could happen with ANY lniux system, not
just gentoo.

FWIW, I am having the same problem (even though I never actually tried
on this system before) :-)

-- 
David Rock
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running Python on Gentoo

2007-07-27 Thread David Rock
Just to follow up on what _my_ environment looks like (and the probable
cause in my case, anyway)

Security Options ->
GRsecurity ->
Executable Protections ->
Trusted Path Execution (TPE)

CONFIG_GRKERNSEC_TPE:
If you say Y here, you will be able to choose a gid to add to the
supplementary groups of users you want to mark as "untrusted." These
users will not be able to execute any files that are not in root-owned
directories writable only by root.  If the sysctl option is enabled, a
sysctl option with name "tpe" is created.   

Now I just need to find how to turn that off. I did want it more secure :-)

-- 
David Rock
[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Tiger12506
> ...some credit. I taught myself to program, from scratch, without access 
> to (or time for) any courses whatsoever... 5 years now...core 
> language...certain standard modules pretty well... complaint...won't get 
> much further...without a computer science degree.

Wow. I'm so *shocked*.
Most python programmers are self-taught. Usually, the best are self-taught. 
Five years for the core language and some standard modules!?! Are you 
kidding me? If it takes you that long, then you are out of your field, and 
lucky you can handle what you can. Some advice: Never, ever try to learn 
anything like C/C++. Or at least don't leave any knives around to tempt you.

Some people need degrees, most people don't. It all depends on what they are 
capable of understanding. From the sound of it, you are lucky you haven't 
jumped off a bridge yet.
Python is simple. Easy enough for teenagers to focus long enough to follow 
even the source of the standard libraries, not just the interfaces.

JS

PS - I'm somewhat sorry I feel the need to throw in my two bits. This little 
debate has continued for long enough, and should end. Btw, try not to 
complain about one language's characteristics without having a thorough 
understanding of what else is out there. Python's standard library is 
'newbie-friendly'. If you doubt it, try emulating what you can already do in 
python in another language. 

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Eric Brunson
Barton David wrote:
>
> *Eric Brunson* wrote:
>
> > It seems like new programmers today expect to be spoonfed their
> > information like they were in grammar school.  They don't know what it
> > is to hack a Makefile to get a package to compile or break out an 
> RFC to
> > understand a protocol.  If you don't understand something and the
> > documentation is lacking, then strap on a pair and read the source,
> > write some test cases, dig a little.  In our environment most of the
> > code you'd have to read is just more Python, anyway.
> >
> > Just me being a grouchy old programmer.  In my day we had to program in
> > 4 feet of snow, uphill... both ways!
>
> heh. Well give me some credit. I taught myself to program, from 
> scratch, without access to (or time for) any courses whatsoever, while 
> doing a PhD in genetics. I've been using it for about 5 years now and 
> I know the core language and certain standard modules pretty well. I 
> doubt I would have got as far as I have if Python wasn't so 
> newbie-friendly. My only complaint is that I'm starting to feel like I 
> won't get much further than that without a computer science degree.

I'll disagree with you on that, if you can get a PhD in genetics then 
programming should be a snap... with the right attitude.  My BS was in 
Applied Mathematics and I've never taken a formal programming class 
since 11th grade high school.  But, I've been doing it for about 20 
years and there comes a point when you realize that you've read all the 
tutorials you can, internalized all the documentation that has been 
written and you *are* actually the smartest person in the room.  At that 
point you have to look other places for your documentation, like the 
source code or the RFCs.

I keep mentioning RFCs because I answer a lot of questions about using 
this to send mail or that to talk to an HTTP server or another thing to 
pull a file off FTP.  Most of python's protocol libraries are a very 
thin layer over the top of the actual network protocol, so in order to 
use any but the most common operations, you have to understand the 
underlying protocol.  So, what do you do?  Read the RFC for SMTP?  Or 
complain that there's not a single function call that allows you to 
automatically connect to a non-WKS port to send uuencoded emails using 
custom headers?

You seem like a smart guy that's having a bad day, so I'm cutting you 
slack.  You'll get to a point in programming where the only thing left 
before you is the epi-genome and I've got news for you, there's no 
documentation on the dark matter.  Personally, I seldom use the low 
level interfaces provided by the standard libraries except to write high 
level wrapper functions that meet the needs of my environment and the 
task at hand.

So, keep your chin up, you're not alone.  :-)

>
> This message has been checked for viruses but the contents of an 
> attachment may still contain software viruses, which could damage your 
> computer system: you are advised to perform your own checks. Email 
> communications with the University of Nottingham may be monitored as 
> permitted by UK legislation.
>
> 
>
> ___
> 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] Remove certain tags in html files

2007-07-27 Thread Sebastien Noel
Hi,

I'm doing a little script with the help of the BeautifulSoup HTML parser 
and uTidyLib (HTML Tidy warper for python).

Essentially what it does is fetch all the html files in a given 
directory (and it's subdirectories) clean the code with Tidy (removes 
deprecated tags, change the output to be xhtml) and than BeautifulSoup 
removes a couple of things that I don't want in the files (Because I'm 
stripping the files to bare bone, just keeping layout information).

Finally, I want to remove all trace of layout tables (because the new 
layout will be in css for positioning). Now, there is tables to layout 
things on the page and tables to represent tabular data, but I think it 
would be too hard to make a script that finds out the difference.

My question, since I'm quite new to python, is about what tool I should 
use to remove the table, tr and td tags, but not what's enclosed in it. 
I think BeautifulSoup isn't good for that because it removes what's 
enclosed as well.

Is re the good module for that? Basically, if I make an iteration that 
scans the text and tries to match every occurrence of a given regular 
expression, would it be a good idea?

Now, I'm quite new to the concept of regular expressions, but would it 
ressemble something like this: re.compile("")?

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Remove certain tags in html files

2007-07-27 Thread Eric Brunson
Sebastien Noel wrote:
> Hi,
>
> I'm doing a little script with the help of the BeautifulSoup HTML parser 
> and uTidyLib (HTML Tidy warper for python).
>
> Essentially what it does is fetch all the html files in a given 
> directory (and it's subdirectories) clean the code with Tidy (removes 
> deprecated tags, change the output to be xhtml) and than BeautifulSoup 
> removes a couple of things that I don't want in the files (Because I'm 
> stripping the files to bare bone, just keeping layout information).
>
> Finally, I want to remove all trace of layout tables (because the new 
> layout will be in css for positioning). Now, there is tables to layout 
> things on the page and tables to represent tabular data, but I think it 
> would be too hard to make a script that finds out the difference.
>
> My question, since I'm quite new to python, is about what tool I should 
> use to remove the table, tr and td tags, but not what's enclosed in it. 
> I think BeautifulSoup isn't good for that because it removes what's 
> enclosed as well.
>   

You want to look at htmllib:  http://docs.python.org/lib/module-htmllib.html

If you've used a SAX parser for XML, it's similar.  Your parser parses 
the file and every time it hit a tag, it runs a callback which you've 
defined.  You can assign a default callback that simply prints out the 
tag as parsed, then a custom callback for each tag you want to clean up.

It took me a little time to wrap my head around it the first time I used 
it, but once you "get it" it's *really* powerful and really easy to 
implement.

Read the docs and play around a little bit, then if you have questions, 
post back and I'll see if I can dig up some examples I've written.

e.

> Is re the good module for that? Basically, if I make an iteration that 
> scans the text and tries to match every occurrence of a given regular 
> expression, would it be a good idea?
>
> Now, I'm quite new to the concept of regular expressions, but would it 
> ressemble something like this: re.compile("")?
>
> Thanks for the help.
> ___
> 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] shelves behaving badly

2007-07-27 Thread Luke Jordan
i've implemented a database as a shelve of record class instances. some of
the fields in each record are dictionaries.

i needed to parse info from 3 different reports into the dictionary fields
in each record instance. i wrote the code to do this and tinkered it to fit
the different reports (i.e. information being in different columns, etc.).
for 2 of the reports, it runs fine. the required info turns up in the shelve
after i run the code, and i can exit and reenter python, open the shelve,
and it's all still there, where it should be. i've quadruple checked the
code for the third report, and it looks like it should work. in fact it
runs, and reports back that it did everything i told it to do; this includes
checking results as they occur at runtime. however, when i reopen the
shelve, none of that data is there. writeback is set to True, and I didn't
forget to close the shelve at the end of my code.

Now, if I open the shelve in the same shell as the script ran in, right
after I run it, I get the updated shelve. but any other method of opening
the shelve results in the shelve missing the data from the third report.

Any ideas what's going on here?

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


Re: [Tutor] Remove certain tags in html files

2007-07-27 Thread Eric Brunson
Eric Brunson wrote:
> Sebastien Noel wrote:
>   
>> Hi,
>>
>> I'm doing a little script with the help of the BeautifulSoup HTML parser 
>> and uTidyLib (HTML Tidy warper for python).
>>
>> Essentially what it does is fetch all the html files in a given 
>> directory (and it's subdirectories) clean the code with Tidy (removes 
>> deprecated tags, change the output to be xhtml) and than BeautifulSoup 
>> removes a couple of things that I don't want in the files (Because I'm 
>> stripping the files to bare bone, just keeping layout information).
>>
>> Finally, I want to remove all trace of layout tables (because the new 
>> layout will be in css for positioning). Now, there is tables to layout 
>> things on the page and tables to represent tabular data, but I think it 
>> would be too hard to make a script that finds out the difference.
>>
>> My question, since I'm quite new to python, is about what tool I should 
>> use to remove the table, tr and td tags, but not what's enclosed in it. 
>> I think BeautifulSoup isn't good for that because it removes what's 
>> enclosed as well.
>>   
>> 
>
> You want to look at htmllib:  http://docs.python.org/lib/module-htmllib.html
>   

I'm sorry, I should have pointed you to HTMLParser:  
http://docs.python.org/lib/module-HTMLParser.html

It's a bit more straightforward than the HTMLParser defined in htmllib.  
Everything I was talking about below pertains to the HTMLParser module 
and not the htmllib module.

> If you've used a SAX parser for XML, it's similar.  Your parser parses 
> the file and every time it hit a tag, it runs a callback which you've 
> defined.  You can assign a default callback that simply prints out the 
> tag as parsed, then a custom callback for each tag you want to clean up.
>
> It took me a little time to wrap my head around it the first time I used 
> it, but once you "get it" it's *really* powerful and really easy to 
> implement.
>
> Read the docs and play around a little bit, then if you have questions, 
> post back and I'll see if I can dig up some examples I've written.
>
> e.
>
>   
>> Is re the good module for that? Basically, if I make an iteration that 
>> scans the text and tries to match every occurrence of a given regular 
>> expression, would it be a good idea?
>>
>> Now, I'm quite new to the concept of regular expressions, but would it 
>> ressemble something like this: re.compile("")?
>>
>> Thanks for the help.
>> ___
>> 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] Code like a Pythonista

2007-07-27 Thread Terry Carroll
On Fri, 27 Jul 2007, Dick Moores wrote:

> The handout is excellent! Thanks!
> 
> But the slideshow at 
> , 
> isn't.

You have to use the page-up and -down keys; or the spacebar (at least on
Windows under Firefox).  Took me a while to figure that out.

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Alan Gauld
"Barton David" <[EMAIL PROTECTED]> wrote

> I've learned to program with Python (and can hardly conceive of a 
> better
> language to be honest)- and I still think the core language is 
> great:
> elegant, easy to use and brilliantly documented.

Completely agree.

> But the more I explore the standard library and third party modules, 
> the
> more I run into trouble:

And again I completely agree. But its not just python, it's an endemic 
thing
in Open Source projects, Python is far from the worst offender here. 
Lots
of people want to write code but not many want to be librarians and
technical authors! But if you come from the world of serious 
commercial
development tools (ie not the toy compilers etc sold by Borland and
Microsoft for PC development) then the chaos of the libraries and
documentation can be truly shocking. But that's why you pay
$10,000+ for a good C Unix or VAX/VMS compiler, and the same
again for the IDE to drive it... And you wanted a library for
financials/scientific/stats/numeric/graphics? That;ll vbe about the
same again... but the quality of the code and documentation will
be good and on a big project that makes it worth it.

But if you don't have the $50,000(*) or so that it would take to get 
what
Python delivers for free then you learn to put up with the bad
documentation and inconsistent libraries etc - or better still
volunteer to tidy it up! :-)

> I guess it's not Python's fault: I'm guess I'm just too stupid. But 
> I'm
> just getting really disenchanted. Sorry.

No not too stupid just expecting a bit much from something that
is ultimately an essentially "amateur"(**) tool.

(*)I just noticed your domain so you probably pay academic rates for
these things which are a good deal lower! (Although still more than
most univesities are willing to fork out for!)

(*)This is in the literal sense of 'done for fun not profit', it does 
not
suggest that the programmers are any way less skilful than
"professionals", quite the opposite is often the case.

-- 
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] Shelve del not reducing file size

2007-07-27 Thread Alan Gauld
"Eric Brunson" <[EMAIL PROTECTED]> wrote

> It seems like new programmers today expect to be spoonfed their
> information like they were in grammar school.

I think its true they expect a lot of tutorial stuff, probably because
of the number of idiot guides to programming in languages like
VB/PHP etc.

Also relatively few of todays programmers are formally trained
(college or higher) in programming, math, computers, etc. In fact
many seem to consider it surprising that people might expect them
to need University level training to program some so "simple" as
a computer! It's just typing after all... :-)

> is to hack a Makefile to get a package to compile or break out an 
> RFC to
> understand a protocol.

Many try but can't understand the terminology. One of the things I 
tried
to do in my tutorial is teach enough of the jargon that newvbies could
read an RFC or a language reference and understand it!

> If you don't understand something and the
> documentation is lacking, then strap on a pair and read the source,

I admit thats always been a last resort for me. I was brought up in
a mainframe and embedded systems environment where documentation
was almost always excellent, accurate and complete. Similarly designs
were documented such that you rarely needed to refer to the code
to find bugs until you were down to a single procedure/function, and
often a particular segment of that (a case statement say). When I 
moved
to Unix I was initially shocked to discover that most big Unix sites 
had
a copy of the AT&T or BSD code and it was considered normal to resolve
issues by reading it!

Then I got involved with PCs and discovered that not only the OS but 
the
BIOS code came with it (the original IBM PC I mean - the one that cost
$2500 for a single 5.25 floppy disk version!) Reading assembler wasn't
a problem but the idea that I might need to just to get the floppy 
disk
to work was astounding!

> Just me being a grouchy old programmer.  In my day we had to program 
> in
> 4 feet of snow, uphill... both ways!

Actually I often feel that todays programming is like that. And in 
many
ways its much harder with the web - a truly terrible programming 
environment!
and GUIs - how many frameworks do you know? and tools that do their 
best
to hide what's going on - IDEs that don't let you see or modify the 
dependency
tree?

I don't think the problems facing programmers today are, in balance, 
harder
or easier than they were when I started programming 25-30 years ago 
but they
are different.

Alan G.
Scratching his grey beard :-) 


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


Re: [Tutor] Code like a Pythonista

2007-07-27 Thread Terry Carroll
On Fri, 27 Jul 2007, Kent Johnson wrote:

> For navigation I use left and right arrows or mouse-over the 
> bottom-right of the screen to get a nav panel. But when I get to the 
> screen "Whitespace 1" there is nothing but white space under the title. 

Same here, but as I press the PgDn key (or the right arrow -- thanks for 
that) it fills in, a line at a time:

   - 4 spaces per indentation level.

   - No hard tabs.
   
   - Never mix tabs and spaces.

   - One blank line between functions.

   - Two blank lines between classes.

Then on to "Whitespace 2" with similar behavior.

And now I note little navigation icons like << and >> at the bottom 
right, too, which only show up when moused over.

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Eric Brunson

One thing I don't think people realize, or at least don't talk about 
often enough, is that good programming, like good art, takes talent.

I can draw a cat to make my 2yo happy or sketch my house well enough 
that someone could pick it out driving down the street, but if I paint 
every day for the next 100 years, I'll never be a Picasso or a Monet.  I 
remember back when the web was starting to prosper, offices would hand 
their secretary a copy of FrontPage and tell them to make a web page for 
the company and *bam* she's a web designer.  The fact is, good web 
design takes talent. 

You can go to school for math, engineering, architecture, art, music or 
computer science, but that's not going to turn the average student into 
a John Nash, a Gustave Eiffel, a Frank Lloyd-Wright, a Vincent Van Gogh, 
an Eddie van Halen or an Alan Turing.  Of course, there are plenty of 
people that make a living at those occupations that aren't the towering 
persona's of the field, but having talent will get you good faster and 
having no talent means you're going to have to work hard to achieve 
mediocrity.

Now *this* thread has gone seriously philosophical...

Alan Gauld wrote:
> "Eric Brunson" <[EMAIL PROTECTED]> wrote
>
>   
>>> newbie-friendly. My only complaint is that I'm starting to feel 
>>> like I
>>> won't get much further than that without a computer science degree.
>>>   
>> I'll disagree with you on that, if you can get a PhD in genetics 
>> then
>> programming should be a snap...
>> 
>
> I'm not sure I agree. There is a reason that CS is a degree subject,
> and that you can get PhDs in it too. There is a lot of advanced 
> programming
> stuff that does need specialist training to *do it well*. Of course 
> you
> can do virtually anything with a buit of brute force. But without 
> actually
> understanding concepts like boolean algenra, lambda and predicate 
> calculii,
> algorithm design, finite state automata thery etc much will either be 
> inelegant
> or just cut n paste.
>
> I often see comments lie software engineering is different to other
> engineering because theres no mathematical basis. Thats plain false,
> and although the basis is less complete and certainly not a unified
> whole almost every aspect of programming can be validated and proved
> mathemaically. Programs can be designed and specified formally.
> But most programmers aren't trained. And those that are are
> discourageed from doing so because its quicker to "just hack it"
> As an applied mathematics man you probably know most of that
> stuff at some levelk. Not surprising since CS started off as a branch
> of math after all.
>
> BTW This trend has been true in almost every engineering discipline
> and the only thing that corrects it is when companies and programmes
> start getting sued and put in prison for writing faulty software. 
> (Just like
> civil engineers were when bridges started falling down, and Electrical
> engineers were when householders got electrocuted switching on lamps!)
>
>   
>> written and you *are* actually the smartest person in the room.  At 
>> that
>> point you have to look other places for your documentation, like the
>> source code or the RFCs.
>> 
>
> Absolutely true. Not good but its where we are.
> (And continuing the simile, the same is true in electronics, sometimes
> you just have to reverse engineer the circuit board! but you never do 
> it
> for fun!)
>
> (*)BTW My own position is that I majored in Electrical/Electronic 
> engineering
> but early on decided software was my interest so took every CS related
> class going. I also spent a lot of time doing background reading (and 
> still do)
> on the formal math side of CS - formal logic etc being one of those 
> areas where
> I have an almost constant learning curve.
>
>   

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


Re: [Tutor] Remove certain tags in html files

2007-07-27 Thread Sebastien Noel
Thanks a lot for this.

Someone on the comp.lang.python usenet channel also suggested using 
BeautifulSoup with holding the content of a table for example, 
extracting the table, than putting back the content. Also seems like a 
good idea.

I will look at both possibilities.

Eric Brunson wrote:
>
> Man, the docs on the HTMLParser module are really sparse.
>
> Attached is some code I just whipped out that will parse and HTML 
> file, supress the ouput of the tags you mention and spew the html back 
> out.  It's just a rough thing, you'll still have to read the docs and 
> make sure to expand on some of the things it's doing, but I think 
> it'll handle 95% of what it comes across.  Be sure to override  all 
> the "handle_*()" methods I didn't.
>
> My recommendation would be to shove your HTML through BeautifulSoup to 
> ensure it is well formed, then run it through the html parser to do 
> whatever you want to change it, then through tidy to make it look nice.
>
> If you wanted to take the time, you could probably write the entire 
> tidy process in the parser.  I got a fair ways there, but decided it 
> was too long to be instructional, so I pared it back to what I've 
> included.
>
> Hope this gets you started,
> e.
>
> Eric Brunson wrote:
>> Eric Brunson wrote:
>>  
>>> Sebastien Noel wrote:
>>>  
 Hi,

 I'm doing a little script with the help of the BeautifulSoup HTML 
 parser and uTidyLib (HTML Tidy warper for python).

 Essentially what it does is fetch all the html files in a given 
 directory (and it's subdirectories) clean the code with Tidy 
 (removes deprecated tags, change the output to be xhtml) and than 
 BeautifulSoup removes a couple of things that I don't want in the 
 files (Because I'm stripping the files to bare bone, just keeping 
 layout information).

 Finally, I want to remove all trace of layout tables (because the 
 new layout will be in css for positioning). Now, there is tables to 
 layout things on the page and tables to represent tabular data, but 
 I think it would be too hard to make a script that finds out the 
 difference.

 My question, since I'm quite new to python, is about what tool I 
 should use to remove the table, tr and td tags, but not what's 
 enclosed in it. I think BeautifulSoup isn't good for that because 
 it removes what's enclosed as well.
 
>>> You want to look at htmllib:  
>>> http://docs.python.org/lib/module-htmllib.html
>>>   
>>
>> I'm sorry, I should have pointed you to HTMLParser:  
>> http://docs.python.org/lib/module-HTMLParser.html
>>
>> It's a bit more straightforward than the HTMLParser defined in 
>> htmllib.  Everything I was talking about below pertains to the 
>> HTMLParser module and not the htmllib module.
>>
>>  
>>> If you've used a SAX parser for XML, it's similar.  Your parser 
>>> parses the file and every time it hit a tag, it runs a callback 
>>> which you've defined.  You can assign a default callback that simply 
>>> prints out the tag as parsed, then a custom callback for each tag 
>>> you want to clean up.
>>>
>>> It took me a little time to wrap my head around it the first time I 
>>> used it, but once you "get it" it's *really* powerful and really 
>>> easy to implement.
>>>
>>> Read the docs and play around a little bit, then if you have 
>>> questions, post back and I'll see if I can dig up some examples I've 
>>> written.
>>>
>>> e.
>>>
>>>  
 Is re the good module for that? Basically, if I make an iteration 
 that scans the text and tries to match every occurrence of a given 
 regular expression, would it be a good idea?

 Now, I'm quite new to the concept of regular expressions, but would 
 it ressemble something like this: re.compile("")?

 Thanks for the help.
 ___
 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
>>   
>

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


Re: [Tutor] Remove certain tags in html files

2007-07-27 Thread Alan Gauld
"Sebastien Noel" <[EMAIL PROTECTED]> wrote

> My question, since I'm quite new to python, is about what tool I 
> should
> use to remove the table, tr and td tags, but not what's enclosed in 
> it.
> I think BeautifulSoup isn't good for that because it removes what's
> enclosed as well.

BS can do what you want, you must be missing something. One of the
most basic examples of using BS is to print an HTML file as plain text
- ie stripping just the tags. So it must be possible.

Can you put together a short example of the code you are using?

You an use lower level parsers but BS is geneally easier, but until
we know what you are doing its hard to guess what might be wrong.

Alan G. 


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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Alan Gauld
"Eric Brunson" <[EMAIL PROTECTED]> wrote

>> newbie-friendly. My only complaint is that I'm starting to feel 
>> like I
>> won't get much further than that without a computer science degree.
>
> I'll disagree with you on that, if you can get a PhD in genetics 
> then
> programming should be a snap...

I'm not sure I agree. There is a reason that CS is a degree subject,
and that you can get PhDs in it too. There is a lot of advanced 
programming
stuff that does need specialist training to *do it well*. Of course 
you
can do virtually anything with a buit of brute force. But without 
actually
understanding concepts like boolean algenra, lambda and predicate 
calculii,
algorithm design, finite state automata thery etc much will either be 
inelegant
or just cut n paste.

I often see comments lie software engineering is different to other
engineering because theres no mathematical basis. Thats plain false,
and although the basis is less complete and certainly not a unified
whole almost every aspect of programming can be validated and proved
mathemaically. Programs can be designed and specified formally.
But most programmers aren't trained. And those that are are
discourageed from doing so because its quicker to "just hack it"
As an applied mathematics man you probably know most of that
stuff at some levelk. Not surprising since CS started off as a branch
of math after all.

BTW This trend has been true in almost every engineering discipline
and the only thing that corrects it is when companies and programmes
start getting sued and put in prison for writing faulty software. 
(Just like
civil engineers were when bridges started falling down, and Electrical
engineers were when householders got electrocuted switching on lamps!)

> written and you *are* actually the smartest person in the room.  At 
> that
> point you have to look other places for your documentation, like the
> source code or the RFCs.

Absolutely true. Not good but its where we are.
(And continuing the simile, the same is true in electronics, sometimes
you just have to reverse engineer the circuit board! but you never do 
it
for fun!)

(*)BTW My own position is that I majored in Electrical/Electronic 
engineering
but early on decided software was my interest so took every CS related
class going. I also spent a lot of time doing background reading (and 
still do)
on the formal math side of CS - formal logic etc being one of those 
areas where
I have an almost constant learning curve.

-- 
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] Code like a Pythonista

2007-07-27 Thread Kent Johnson
Terry Carroll wrote:
> On Fri, 27 Jul 2007, Dick Moores wrote:
> 
>> The handout is excellent! Thanks!
>>
>> But the slideshow at 
>> ,
>>  
>> isn't.
> 
> You have to use the page-up and -down keys; or the spacebar (at least on
> Windows under Firefox).  Took me a while to figure that out.

For navigation I use left and right arrows or mouse-over the 
bottom-right of the screen to get a nav panel. But when I get to the 
screen "Whitespace 1" there is nothing but white space under the title. 
Appropriate in a way but not very enlightening :-)

I'm on Firefox Mac but I saw this also last night with FF on Linux.

I don't know if it is this particular presentation that has trouble or 
if it is with S5 itself.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Remove certain tags in html files

2007-07-27 Thread Eric Brunson


Man, the docs on the HTMLParser module are really sparse.

Attached is some code I just whipped out that will parse and HTML file, 
supress the ouput of the tags you mention and spew the html back out.  
It's just a rough thing, you'll still have to read the docs and make 
sure to expand on some of the things it's doing, but I think it'll 
handle 95% of what it comes across.  Be sure to override  all the 
"handle_*()" methods I didn't.


My recommendation would be to shove your HTML through BeautifulSoup to 
ensure it is well formed, then run it through the html parser to do 
whatever you want to change it, then through tidy to make it look nice.


If you wanted to take the time, you could probably write the entire tidy 
process in the parser.  I got a fair ways there, but decided it was too 
long to be instructional, so I pared it back to what I've included.


Hope this gets you started,
e.

Eric Brunson wrote:

Eric Brunson wrote:
  

Sebastien Noel wrote:
  


Hi,

I'm doing a little script with the help of the BeautifulSoup HTML parser 
and uTidyLib (HTML Tidy warper for python).


Essentially what it does is fetch all the html files in a given 
directory (and it's subdirectories) clean the code with Tidy (removes 
deprecated tags, change the output to be xhtml) and than BeautifulSoup 
removes a couple of things that I don't want in the files (Because I'm 
stripping the files to bare bone, just keeping layout information).


Finally, I want to remove all trace of layout tables (because the new 
layout will be in css for positioning). Now, there is tables to layout 
things on the page and tables to represent tabular data, but I think it 
would be too hard to make a script that finds out the difference.


My question, since I'm quite new to python, is about what tool I should 
use to remove the table, tr and td tags, but not what's enclosed in it. 
I think BeautifulSoup isn't good for that because it removes what's 
enclosed as well.
  

  

You want to look at htmllib:  http://docs.python.org/lib/module-htmllib.html
  



I'm sorry, I should have pointed you to HTMLParser:  
http://docs.python.org/lib/module-HTMLParser.html


It's a bit more straightforward than the HTMLParser defined in htmllib.  
Everything I was talking about below pertains to the HTMLParser module 
and not the htmllib module.


  
If you've used a SAX parser for XML, it's similar.  Your parser parses 
the file and every time it hit a tag, it runs a callback which you've 
defined.  You can assign a default callback that simply prints out the 
tag as parsed, then a custom callback for each tag you want to clean up.


It took me a little time to wrap my head around it the first time I used 
it, but once you "get it" it's *really* powerful and really easy to 
implement.


Read the docs and play around a little bit, then if you have questions, 
post back and I'll see if I can dig up some examples I've written.


e.

  

Is re the good module for that? Basically, if I make an iteration that 
scans the text and tries to match every occurrence of a given regular 
expression, would it be a good idea?


Now, I'm quite new to the concept of regular expressions, but would it 
ressemble something like this: re.compile("")?


Thanks for the help.
___
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
  


from HTMLParser import HTMLParser

class MyParser( HTMLParser ):
def __init__( self ):
HTMLParser.__init__( self )
self.supress = ( 'table', 'tr', 'td' )

def handle_starttag( self, tag, attrs ):
if tag not in self.supress:
print "<%s%s%s>" % ( tag,
 " " if attrs else "",
 " ".join( "%s='%s'" % pair for pair in attrs ) ),

def handle_data( self, data ):
print data,

def handle_endtag( self, tag ):
if tag not in self.supress:
print "" % ( tag, ),

MyParser().feed( open( 'index.html' ).read() )

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Alan Gauld
"Tiger12506" <[EMAIL PROTECTED]> wrote

> Some people need degrees, most people don't. It all depends on what 
> they are
> capable of understanding.

It also depends what they are doing.
Most programmers don't build  complex state machines, nor do they
build safety critical systems. 90% or more of all programs don't
need a degree, but somecthings do need formal training and the
language is basically irrelevant. degrees dopnm;t teach languages,
they teach the underlying theory.

> understanding of what else is out there. Python's standard library 
> is
> 'newbie-friendly'. If you doubt it, try emulating what you can 
> already do in
> python in another language.

Actually you an do what you do in Python in practically any general 
purpose
language, it just takes a few more lines of code (OK a lot more lines 
in
some cases) But Pythons library is not newbie friendly, sorry. How 
does
a newbie know when to use pickle v cpickle? or urllib v urllib2? And 
which
of the xml parsers? And as for thev mess that is glob/os/path/shutil?
Its not clear to me even after 10 years of using Python which function
sits where and why. And what about the confusion over system(),
popen(),commands(),spawn(), subprocess() etc. or why is there time
and datetime? Sure it makes sense once you've played with Python
for a while it makes some sense and you learn the role of history.
But for a newbie thats not a friendly scenario ad many other languages
are far better organised - Smalltalk being one example! And the C++ 
standard
library is another. Even the Java standard library, much as I dislike 
Java, is
better organised and more consistent!

-- 
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] Livewires questions

2007-07-27 Thread Tonu Mikk
Luke Paireepinart wrote:
>> def place_robot():
>> global robot_x
>> global robot_y
>> global robot_shape
>> robot_y = random_between(0,47)-0.5
>> robot_x = random_between(0,63)-0.5
>>   
> I'm not too clear why you're subtracting 0.5 here.
> Doesn't this make the robot's center on the grid lines, rather than 
> having the robot occupy a full square on the grid?
> I guess that's the intended behavior, huh?
This is particular to Livewires module I believe.  I am dealing with the 
circle (player) whose position is defined by the center of the circle 
and a square (robot) whose position is defined by the first two 
coordinates of the square.  I subtract 0.5 here so that when the random 
numbers picked for both the circle and the the square are the same, then 
visually the square is right on top of the circle. 
>
>> robot_shape = box(10*robot_x, 
>> 10*robot_y,10*robot_x+10,10*robot_y+10)
>> def move_player():
>> while 1:
>> global player_x
>> global player_y
>>   if 't' in keys:
>> place_player()
>> break
>>   
> You can't reuse your place_player function here, because you put the 
> initialization (the creation) of the graphics that represent the 
> player _inside_ of the place_player function.  Well, technically you 
> could, but it would be better instead to use move_to(player_shape, x, 
> y) because this doesn't overwrite the old player_shape circle.
> Also, will this work if the player presses "T"?
Ok, I made some progress on the pressing of the "T" key, but it is still 
not entirely correct.  The reason why pressing the 't' key was not 
working initially was because I had omitted the 't' key in the main 
while loop.  As a result, the code never executed the move_player code 
when I pressed the 't' key.  Now if I execute the code above, I get a 
new player circle placed on the grid, but the old player stays there as 
well.  I somewhat expected this because I am not getting rid of the old 
player by calling place_player() function.  How could I eliminate the 
old player circle from the grid?  When I use the move_to(player_shape, 
player_x*10, player_y*10), then the player just stays in the same 
place.  This too I expect, since by using move_to, I am not calling new 
player_x and player_y coordinates.
>> if '8' in keys:
>> move_to(player_shape,player_x*10 ,player_y*10 + 10)
>> player_y = player_y + 1
>> if player_y > 47:
>> player_y = player_y -1
>> else:
>> pass
>>   
> 'if' statements don't have to have an 'else' clause.
> else:
>pass
> is just a waste of 2 lines.  'pass' does nothing, and since the 'else' 
> is not required, you may as well leave it off.
I thought so too.  Part of the problem I had with testing my code was 
that I was using the PythonWin editor that comes with ActivePython.  
Often the PythonWin editor would crash and I wasn't always sure if it 
was because of my code, or because of the editor itself.  It somehow 
seemed that when I had the else: pass in the code, the editor behaved 
better. I have since then started to use IDLE which works much better.  
Thank you for pointing this out BTW.  It takes some of the guess work 
out :-).
>>
>>  
> This big block of movement code can be shortened into a few lines.
> I am not sure how much python you know, so if any of this doesn't make 
> sense, let me know.
I am just a newbie in Python.  I like the way you were able to think 
about the code to make the code much more succinct.  I will need to 
learn a bit more before I understand it exactly.  For now, I will try to 
stick with my long, ugly, inefficient code, that I have puzzled together 
and understand.  Your example has not gone wasted however, it will be 
used later when I am more familiar with Python and try to improve my code. 
>>  
> Also, I just realized that you're using a while loop inside of your 
> move_player and move_robots function.
> But you only call these functions if you KNOW that a movement key was 
> pressed.
> Basically, this means that one of your 'if' conditions will ALWAYS be 
> true inside of your while: loops, and you'll break out of it.
>
> The only reason why you might want this is that it would immediately 
> exit as soon as it finds the first key that was pressed, but the
> same thing could be performed using an if-elif chain.  But I doubt you 
> want this to happen.
I will experiment with the if statements there.  Is it better to use 
if-elif chain over the while loop when both can work?
>
> Also there are other problems - eg. your keys is assigned to the keys 
> that were currently pressed, so if during the time.sleep(0.5) I might
> press and then release a key, and it would be lost in your code.
Yes, I see this when I run the code.  Unfortunately, I don't know how 
else to do it since it is the only way that they show in the Livewires 
exercise.  I am OK it being imperfect for now.
> The code 

Re: [Tutor] Remove certain tags in html files

2007-07-27 Thread Sebastien Noel
Here is the code to deal with 1 given file (the code to iterate all the 
files as working, and I will glue both together when the second one does 
what I want.):

It's a little long, but I wanted to put it all so you maybe I can get 
some tips to speed things up because it's pretty slow.

import BeautifulSoup, tidy

file = open("index.htm", "r")
soup = BeautifulSoup.BeautifulSoup(file)
file.close()

#remove unnecessary things (scripts, styles, ...)
for script in soup("script"):
soup.script.extract()

for style in soup("style"):
soup.style.extract()
   
#remove comments
comments = soup.findAll(text=lambda text:isinstance(text, 
BeautifulSoup.Comment))
[comment.extract() for comment in comments]

#the following removes things specific to the pages I'm working with, 
don't mind the langcanada things
#I was just too lazy to change the name of this variable each time
#I think this is an area that could be done differently to get more speed

langcanada = soup.findAll("img", src="graphics/button_f.jpg")
[img.parent.parent.extract() for img in langcanada]

langcanada = soup.findAll("img", src="graphics/button_e.jpg")
[img.parent.parent.extract() for img in langcanada]

langcanada = soup.findAll("img", src="http://u1.extreme-dm.com/i.gif";)
[img.parent.parent.extract() for img in langcanada]

langcanada = soup.findAll("a", href="research/disclaimer.htm")
[img.parent.extract() for img in langcanada]

comments = soup.findAll(text=" ")
[comment.extract() for comment in comments]

langcanada = soup.findAll("img", id="logo")
[img.parent.parent.parent.extract() for img in langcanada]

langcanada = soup.findAll("img", id="about")
[img.parent.parent.parent.extract() for img in langcanada]

langcanada = soup.findAll("img", src="images/navbgrbtm.jpg")
[img.parent.parent.parent.parent.extract() for img in langcanada]

langcanada = soup.findAll("img", src="images/navbgrtop.jpg")
[img.parent.parent.parent.parent.extract() for img in langcanada]

#delete class attributes
   
for divs in range(len(soup.findAll("div"))):
le_div = soup.findAll("div")[divs]
del le_div["class"]
   
for paras in range(len(soup.findAll("p"))):
le_par = soup.findAll("p")[paras]
del (le_par["class"])
   
for imgs in range(len(soup.findAll("img"))):
le_img = soup.findAll("img")[imgs]
del (le_img["hspace"])
del (le_img["vspace"])
del (le_img["border"])
   
# Add some class attributes
for h1s in range(len(soup.findAll("h1"))):
le_h1 = soup.findAll("h1")[h1s]
le_h1["class"] = "heading1_main"
   
for h2s in range(len(soup.findAll("h2"))):
le_h2 = soup.findAll("h2")[h2s]
le_h2["class"] = "heading2_main"

for h3s in range(len(soup.findAll("h3"))):
le_h3 = soup.findAll("h3")[h3s]
le_h3["class"] = "heading3_main"
   
for h4s in range(len(soup.findAll("h4"))):
le_h4 = soup.findAll("h4")[h4s]
le_h4["class"] = "heading4_main"
   
for h5s in range(len(soup.findAll("h5"))):
le_h5 = soup.findAll("h5")[h5s]
le_h5["class"] = "heading5_main"
   
# links, makes difference between internal and external ones
for links in range(len(soup.findAll("a"))):
le_link = soup.findAll("a")[links]
le_href = le_link["href"]
if le_href.startswith("""http://caslt.org""";) or 
le_href.startswith("""http://www.caslt.org""";):
le_link["class"] = "caslt_link"
elif le_href.startswith("""http://""";):
le_link["class"] = "external_link"
else:
le_link["class"] = "caslt_link"
   
del (soup.body["onload"])

# This is what needs to be done:
## change tables to divs
## remove all td tags
## remove all tr tags



# Tidying

soup = soup.prettify()
erreurs = ""

tidy_options = {"tidy-mark": 0,
"wrap": 0,
"wrap-attributes": 0,
"indent": "auto",
"output-xhtml": 1,
"doctype": "loose",
"input-encoding": "utf8",
"output-encoding": "utf8",
"break-before-br": 1,
"clean": 1,
"logical-emphasis": 1,
"drop-font-tags": 1,
"enclose-text": 1,
"alt-text": " ",
"write-back": 1,
"error-file": erreurs,
"show-warnings": 0,
"quiet": 1,
"drop-empty-paras": 1,
"drop-proprietary-attributes": 1,
"join-classes": 1,
"join-styles": 1,
"show-body-only": 1,
"word-2000": 1,
"force-output": 1}

soup_tidy = tidy.parseString(soup, **tidy_options)

outputfile = open("index2.htm", "w")
outputfile.write(str(soup_tidy))
outputfile.close()


Alan Gauld wrote:
> "Sebastien Noel" <[EMAIL PROTECTED]> wrote
>
>   
>> My question, since I'm quite new to python, is about what tool I 
>> should
>> use to remove the table, tr and td tags, but not what's enclosed in 
>> it.
>> I think BeautifulSoup isn't good for that because it removes what's
>> enclosed as well.
>> 
>
> BS can do what you want, you must be missing something. One of the
> most basic examples of using BS is to print an HTML file as plain text
> - ie stripping just the tags. So it must be possible.
>
> Can you put together a short example of the code you are using?
>
> You an use lower level parsers but BS is geneally easier, but until
> we know w

Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



Alan Gauld wrote:
> "Tiger12506" <[EMAIL PROTECTED]> wrote
> 
>> Some people need degrees, most people don't. It all depends on what 
>> they are
>> capable of understanding.
> 
> It also depends what they are doing.
> Most programmers don't build  complex state machines, nor do they
> build safety critical systems. 90% or more of all programs don't
> need a degree, but somecthings do need formal training and the
> language is basically irrelevant. degrees dopnm;t teach languages,
> they teach the underlying theory.

Exactly. That's also why CS is not a major for everyone. My university
when I had the priviledge had an awful portion of mathematics. (My motto
was, that the only way to have more math courses would be to study
something with mathematics in the title *g*) Worse from the perspective
of many students that expected to learn "programming" was the fact, that
you were expected to know programming already. Or learn it in your own
spare time. Well, the official party line was that one does not need any
 knowledge beforehand, but the reality was slightly different.

And the reality is that learning a programming language has always been
a trivial thing. (These graphical IDE stuff is hard. Nobody takes away
my emacs/vi :) )

> 
>> understanding of what else is out there. Python's standard library 
>> is
>> 'newbie-friendly'. If you doubt it, try emulating what you can 
>> already do in
>> python in another language.
> 
> Actually you an do what you do in Python in practically any general 
> purpose
> language, it just takes a few more lines of code (OK a lot more lines 
> in
> some cases) But Pythons library is not newbie friendly, sorry. How 
> does
> a newbie know when to use pickle v cpickle? or urllib v urllib2? And 
> which
> of the xml parsers? And as for thev mess that is glob/os/path/shutil?

Well, personally that's where the missing formal training and experience
shows. Ok, don't talk about urllib/urllib2, it's a mess. OTOH, it's
really hard to clean up, because changing/removing names in these old
legacy modules would break existing code. (And the correct answer for
URL retrieval is neither urllib/urllib2, it's pyCurl ;) ). The
cPickle/Pickle question is AFAIR documented, BUT other pitfalls with
Pickles in general are not. And one needs different XML parsers, well,
simple, because parsing XML is not a problem with one single perfect
solution, so one needs to select the perfect one.

OTOH, as a newbie, it really does not matter if one uses urllib or
urllib2. It does not really matter which XML parser one uses, usually.
And the only drawback of choosing Pickle over cPickle might be
performance. Sometimes an issue for newbies, but often not.




> Its not clear to me even after 10 years of using Python which function
> sits where and why. And what about the confusion over system(),
> popen(),commands(),spawn(), subprocess() etc. or why is there time
Mistakes of history. Plus a number of these warts come from the ports to
certain inferior operating systems. And really hard to fix, because it
involves breaking compatibility, in a way that might lead to subtle
runtime bugs.

time versus datetime is easy to understand => time is POSIX time
management functions, while datetime is a generic language specific data
type meant to represent dates, timestamps, etc.

> and datetime? Sure it makes sense once you've played with Python
> for a while it makes some sense and you learn the role of history.
> But for a newbie thats not a friendly scenario ad many other languages
> are far better organised - Smalltalk being one example! And the C++ 
> standard
> library is another. Even the Java standard library, much as I dislike 
> Java, is
> better organised and more consistent!

You think that there are no overlapping APIs in Java? Historic "mistakes"?

Andreas
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGqlAtHJdudm4KnO0RAqdGAKDpljkn5MrKzK6HPqOpQYZQmR3ybQCfRUx1
WSQWeILzgfhpHl0iGBadSss=
=egdH
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Code like a Pythonista

2007-07-27 Thread Kent Johnson
Terry Carroll wrote:
> On Fri, 27 Jul 2007, Kent Johnson wrote:
> 
>> For navigation I use left and right arrows or mouse-over the 
>> bottom-right of the screen to get a nav panel. But when I get to the 
>> screen "Whitespace 1" there is nothing but white space under the title. 
> 
> Same here, but as I press the PgDn key (or the right arrow -- thanks for 
> that) it fills in, a line at a time:

Oh, OK, it's a reveal. AFAICT it doesn't work if you use the mouse 
buttons, only if you navigate with the keyboard.

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


Re: [Tutor] Remove certain tags in html files

2007-07-27 Thread Alan Gauld
Sebastien Noel" <[EMAIL PROTECTED]> wrote

> comments = soup.findAll(text=" ")
> [comment.extract() for comment in comments]

Umm, why comments here and not langcanada?
 Just curious...

> # Add some class attributes
> for h1s in range(len(soup.findAll("h1"))):
>le_h1 = soup.findAll("h1")[h1s]
>le_h1["class"] = "heading1_main"
>
> for h2s in range(len(soup.findAll("h2"))):
>le_h2 = soup.findAll("h2")[h2s]
>le_h2["class"] = "heading2_main"

You could abstract this into a function with a few parametes
and put it into a loop, and thus save a load of typing!

OK, Too much code to go through in detail, can you do a simple example
where you try to remove some tags and it doesn't work? Also did you
look at the ReplaceWith method? That may help you if you use
something like a SPAN or DIV tag...

I didn't see you writing anything back in that code but then I was 
just scanning
it and may have missed it... You extract them from the parse tree but 
do you
ever write the modified tree out?

Alan G


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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Alan Gauld

"Andreas Kostyrka" <[EMAIL PROTECTED]> wrote

> was, that the only way to have more math courses would be to study
> something with mathematics in the title *g*)

Thats true of most engineering courses.
Although I studied Electrical engineering the only compulsory subject
for each of the 5 years(if you took it to Masters) was math! You could
actually drop all of the pure electricaltheory by fifth year but you 
couldn't
drop math... But thats because math is the language of enginering,
regardless of whether its building bridges, oscillators or programs.
You don't need much math to build a garden shed, but you need
a lot to build the Tacoma Narrows bridge... Similarly you don't need
much math to build a GUI friont end to a database, but you need
quite a lot to build the control program for a nuclear reactor. (and 
the
consequences of getting it wrong are usually worse too!)

> of many students that expected to learn "programming" was the fact, 
> that
> you were expected to know programming already.

Really? We had a pretty good basic Pascal course in first year. After
that you knew how to program so after that it was just learning new
languages so no need for extra training. Most of it after that was on
techniques like data structures, parallel processing, graphics, 
relational
data theory,  intrerruipt handling, assembler I/O techniques, 
simulation
and control theory etc etc. The stuff you need to design programs not
write them.

> cPickle/Pickle question is AFAIR documented,

But not in a manner totally clear to a newbie. An experienced
programmer will figure out that a C implementation is faster but
what does that meabn when your only reference is a few weeks
of Python? And why is there two modules if one is better? Why
not just replace the Python one completely?

> simple, because parsing XML is not a problem with one single perfect
> solution, so one needs to select the perfect one.

But how does a newbie know which solution where?
There is little or no guidance about that in the docs

> OTOH, as a newbie, it really does not matter if one uses urllib or
> urllib2.

But its confusing and unsettling that there is a choice.
especially when the zen of python claims there is only ione way
to do it! Not in the library there ain't - even if you are Dutch!

>> sits where and why. And what about the confusion over system(),
>> popen(),commands(),spawn(), subprocess() etc. or why is there time
> Mistakes of history.

Sure but again the newbie just sees a mess.

> Plus a number of these warts come from the ports to
> certain inferior operating systems.

Granted but thats not the main reason, its just history and the
open source culture of contributing modules. Now dopn;t get me wrong,
I'd rather have the batteries than build my own, but we should not 
forget
just how hard this is for a newbie.

> time versus datetime is easy to understand => time is POSIX time

POSIX whassat? Newbies again.

>> library is another. Even the Java standard library, much as I 
>> dislike
>> Java, is better organised and more consistent!
>
> You think that there are no overlapping APIs in Java? Historic 
> "mistakes"?

There are overlaps - Swing v AWT etc being a prime example.
But the organisation of the library into packages is much better
controlled. By separating the old/new Java at least keeps things 
relatively
tidy and can say use the stuff here and not the stuff over there. 
Pythons
essentially flat (and that is improving slowly) structure is just 
messy.

Alan G 


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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1



Alan Gauld wrote:
> "Andreas Kostyrka" <[EMAIL PROTECTED]> wrote
> 
>> was, that the only way to have more math courses would be to study
>> something with mathematics in the title *g*)
> 
> Thats true of most engineering courses.
> Although I studied Electrical engineering the only compulsory subject
> for each of the 5 years(if you took it to Masters) was math! You could
> actually drop all of the pure electricaltheory by fifth year but you 
> couldn't
> drop math... But thats because math is the language of enginering,
> regardless of whether its building bridges, oscillators or programs.
> You don't need much math to build a garden shed, but you need
> a lot to build the Tacoma Narrows bridge... Similarly you don't need
> much math to build a GUI friont end to a database, but you need
> quite a lot to build the control program for a nuclear reactor. (and 
> the
> consequences of getting it wrong are usually worse too!)

I would question even that one can write a good GUI frontend to a
database without the theory behind it. Database design has a number of
important theoretical foundations (relational algebra, normal forms),
and without understanding these, and their implications for your db
model, you might end up with a bad GUI.


> 
>> of many students that expected to learn "programming" was the fact, 
>> that
>> you were expected to know programming already.
> 
> Really? We had a pretty good basic Pascal course in first year. After
> that you knew how to program so after that it was just learning new
> languages so no need for extra training. Most of it after that was on

Well, the advanced stuff was there. But the Modula2 introduction to
programming was a joke, most students did not even understand the
concept of local variables and procedure parameters after one semester.
OTOH, I might be a bad judge on programming progress, at that time I was
young and a C++ tutor in the parallel introduction to programming course
at the second university in town ;)


> techniques like data structures, parallel processing, graphics, 
> relational
> data theory,  intrerruipt handling, assembler I/O techniques, 
> simulation
> and control theory etc etc. The stuff you need to design programs not
> write them.
> 
>> cPickle/Pickle question is AFAIR documented,
> 
> But not in a manner totally clear to a newbie. An experienced
> programmer will figure out that a C implementation is faster but
> what does that meabn when your only reference is a few weeks
> of Python? And why is there two modules if one is better? Why
> not just replace the Python one completely?

Well, here we come to the point where the complexity is higher than what
most newbies can grasp. But that's not really unique to programming or
Python, most high school level math courses do not teach the whole
truth. At least not in the beginning.

Andreas

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGqmPqHJdudm4KnO0RAlyEAKDdwfKqvhh7C+zET8q9MCGBHtg3LACfTmLa
2gDDp5r2ZzU/H0Kwj5UsOPg=
=ypyp
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Which GUI?

2007-07-27 Thread scott
Hi,

now that I have a very basic understanding of Python I would like to 
take a look at programming in a GUI.  Which GUI is generally the easiest 
to learn?

-- 
Your friend,
Scott

Sent to you from a Linux computer using Ubuntu Version 7.04 (Feisty Fawn)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which GUI?

2007-07-27 Thread Eric Brunson
scott wrote:
> Hi,
>
>   now that I have a very basic understanding of Python I would like to 
> take a look at programming in a GUI.  Which GUI is generally the easiest 
> to learn?
>
>   

Easiest depends on your background.  I was a Mac developer back in the 
day, so WXPython was easy for me.  If you're a KDE programmer, then PyQT 
is probably your cup of tee.  Similarly, GTK programmers will probably 
like PyGTK.  I cannot make any statements about Tkinter, since I eschew 
everything TCL related.

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


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Tiger12506
>> cPickle/Pickle question is AFAIR documented,
>
> But not in a manner totally clear to a newbie. An experienced
> programmer will figure out that a C implementation is faster but
> what does that meabn when your only reference is a few weeks
> of Python? And why is there two modules if one is better? Why
> not just replace the Python one completely?

I remember being a newbie. :-)
I read in the docs where cPickle was faster. I also read that Pickle is only 
necessary for subclassing. As I had little idea what subclassing was, i knew 
that using cPickle would be to my advantage. However, seeing that the 
documentation was describing the Pickle module, I used it. No issue.

>> simple, because parsing XML is not a problem with one single perfect
>> solution, so one needs to select the perfect one.

What the hell is XML? If i knew what it was, maybe i would have a reason to 
parse it, as a newbie.

>> OTOH, as a newbie, it really does not matter if one uses urllib or
>> urllib2.
>
> But its confusing and unsettling that there is a choice.
> especially when the zen of python claims there is only ione way
> to do it! Not in the library there ain't - even if you are Dutch!

Why is a choice confusing? Why, why why? That's the problem with these 
clever language descriptions like the zen. It claims that there is only one 
way to do it. So when the average newbie actually finds more than one way, 
it's "total meltdown". They don't have open minds. Why are they trying to 
create? sigh.

At any rate, I remember wondering which to use. Reading the documentation 
(in the capacity of a newbie) I determined which one looked more promising, 
more applicable, less complex. When I had a question, I found resources 
(like this python list). Also, noticing that comp.lang.python was often 
discussing things that i didn't understand, i didn't ask my questions there. 
I used techniques that are used to find information. No, not special 
techniques for surfing the net, just ordinary common sense. Is this a sense 
of talent? Do people (non-programmer-destined) not have this?


>>> sits where and why. And what about the confusion over system(),
>>> popen(),commands(),spawn(), subprocess() etc. or why is there time
>> Mistakes of history.
>
> Sure but again the newbie just sees a mess.

True. Skimming over it long ago, i noticed os.system() which would execute a 
command that i would normally execute on the command line. I was content 
with that. It executed the program. Why would I (the newbie) argue?

>> Plus a number of these warts come from the ports to
>> certain inferior operating systems.
>
> Granted but thats not the main reason, its just history and the
> open source culture of contributing modules. Now dopn;t get me wrong,
> I'd rather have the batteries than build my own, but we should not
> forget
> just how hard this is for a newbie.
>
>> time versus datetime is easy to understand => time is POSIX time
>
> POSIX whassat? Newbies again.

Yeah POSIX  whassat?!? Agreed. But I personally felt that it was stupid to 
put dates and time into the same module, into the same class, so I used 
time.

And it served me. When it didn't, I asked questions, did research~ What do 
they teach in high schools now?

Note to newbies: Ask questions, do research. Google. There. Your whole high 
school career made absolutely useless.

Again, I feel prompted to mention C/C++ (which seemed like a mess of 
computer terms and gibberish), Perl (which seemed useless), Ruby (which I 
could never get to run), etc.
Python is S simple.

JS 

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


Re: [Tutor] [Bulk] Re: Which GUI?

2007-07-27 Thread scott
Eric Brunson wrote:
> Easiest depends on your background.  I was a Mac developer back in the day, 
> so WXPython was easy for me.  If you're a KDE programmer, then PyQT is 
> probably your cup of tee.  Similarly, GTK programmers will probably like 
> PyGTK.  I cannot make any statements about Tkinter, since I eschew everything 
> TCL related. 

I have not done any GUI programming at all using any GUI language.  So, 
I'm not anything, not yet anyway :)  I know I don't want to program 
using PyQT because of the licencing issues; I prefer something that is 
completely open source.

I know I will eventually poke around a couple different GUI languages, 
but, would prefer to start with what is easiest to learn for a new 
programmer.

-- 
Your friend,
Scott

Sent to you from a Linux computer using Ubuntu Version 7.04 (Feisty Fawn)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Code like a Pythonista

2007-07-27 Thread Dick Moores
At 12:02 PM 7/27/2007, Terry Carroll wrote:
>On Fri, 27 Jul 2007, Dick Moores wrote:
>
> > The handout is excellent! Thanks!
> >
> > But the slideshow at
> > 
> ,
> > isn't.
>
>You have to use the page-up and -down keys; or the spacebar (at least on
>Windows under Firefox).  Took me a while to figure that out.

Ah. Thanks.

Dick


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


Re: [Tutor] Which GUI?

2007-07-27 Thread Terry Carroll
On Fri, 27 Jul 2007, scott wrote:

>   now that I have a very basic understanding of Python I would like to 
> take a look at programming in a GUI.  Which GUI is generally the easiest 
> to learn?

As between Tkinter and wxPython, I started on Tkinter, but have been won 
over to wxPython, although I've only played with it so far.  The problem 
with wxPython is that it's poorly documented, but there's a book out on it 
now that you should beg, borrow or steal if you plan on using it.

Lessee: "wxPython in Action," see http://www.wxpython.org/

There's a lot of tutorials on Tkinter, but none worked very well for me, 
probably because it's such a shift in approach to think in a GUI-like way.  
The big advantage of Tkinter is that it's already distributed with Python, 
so you already have it installed.

I've heard good things about PythonCard (which is built on top of 
wxPython) but never tried it.  http://pythoncard.sourceforge.net/

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


Re: [Tutor] Which GUI?

2007-07-27 Thread Tiger12506
> As between Tkinter and wxPython, I started on Tkinter, but have been won
> over to wxPython, although I've only played with it so far.  The problem
> with wxPython is that it's poorly documented, but there's a book out on it
> now that you should beg, borrow or steal if you plan on using it.

Tkinter is easier to program from the start, but I quickly discarded it for 
wxPython. Reasons: The windows looked foreign, and childish, because as a 
newbie at the time I didn't want to take the time making things pretty (padx 
= ...)
wxPython uses 'native looking windows' meaning that windows you create with 
wxPython will look like other windows on your machine. (In XP, for example, 
round edges, blue, thick, 3d looking)

wxPython seems very powerful and thorough. It is also more modern.
I would suggest starting with Tkinter to get a feel for what it takes to 
create a GUI and drive it, then when you become comfortable, switch to 
something more professional looking/powerful.

> The big advantage of Tkinter is that it's already distributed with Python,
> so you already have it installed.

Yep. Definite advantage.

> I've heard good things about PythonCard (which is built on top of
> wxPython) but never tried it.  http://pythoncard.sourceforge.net/

Can be error-prone (the resource editor sometimes freezes) and confusing 
(Uses a technique including importing the same module within itself?!?), but 
if you follow the example programs, you can get running code easily. 
Advantage is graphical control placement, as in a resource editor. The 
disadvantage of that is that an extra file is created to contain the 
resource information. As for being newbie friendly~~ Not as straight-forward 
as Tkinter to code, but easier to visualize because of the graphical control 
placement not available with Tkinter. Perhaps the errors have been fixed 
since I tested it out last.

Cheers,
JS 

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


Re: [Tutor] Which GUI?

2007-07-27 Thread Alan Gauld

"Tiger12506" <[EMAIL PROTECTED]> wrote

>> As between Tkinter and wxPython, I started on Tkinter, but have 
>> been won
>> over to wxPython, although I've only played with it so far.

I'm in transition. The problem I find with wxPython is the two-stage 
create
widget/bind widget style and I find the layout management slightly 
more
cumbersome. But OTOH if i was starting from scratch instead of having
10 years of Tkinter (and Delphi) background I might think differently!

>> with wxPython is that it's poorly documented, but there's a book 
>> out on it
>> now that you should beg, borrow or steal if you plan on using it.

Agreed. Until the book came out I only played with wxPython briefly.

> Tkinter is easier to program from the start, but I quickly discarded 
> it for
> wxPython.

I think Tkinter is easier to throw a quick GUI on top of an existing 
script
- and to be fair thats all Tk was originally designed to do for Tcl...

wxPython has a richer widget set - although the (poorly documented) 
Tix
module closes the gap considerably.

> The windows looked foreign, and childish, because as a newbie at
> the time I didn't want to take the time making things pretty

I've never found the look a problem, but I've seen enough complaints 
to
know it matters a lot to some folk.

Finally wxPython does come with some tools that are genuinely useful
in their own right - ALa Mode is much better than IDLE IMHO!
And PyCrust is now my standard interpreter shell.

If you do want a very quick feel for Tkinter and a comparison with
wxPython take a look at my GUI topic in my tutorial. Its about as
brief as it can get...

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] Which GUI?

2007-07-27 Thread johnf
On Friday 27 July 2007 14:29, scott wrote:
> Hi,
>
>   now that I have a very basic understanding of Python I would like to
> take a look at programming in a GUI.  Which GUI is generally the easiest
> to learn?

You might want to check out Dabo (www.dabodev.com) which uses wxPython but 
provides a much easier user interface (includes data binding if needed).
-- 
John Fabiani
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Barton David
Eric Brunson wrote:
> You seem like a smart guy that's having a bad day, so I'm cutting you
> slack.
 
Thanks Eric. Yes I did indeed have a bad day (and it got much much worse),
and this is most definitely a case of a bad workman blaming his tools. I
apologise to all concerned for voicing my frustrations: it was clearly 
ill-advised.
Still.. call me idealistic but I feel like a good toolmaker should try to 
listen to her
clients.
 
I am not a dedicated programmer. I have other stuff on my plate. I probably
wouldn't be a programmer at all if Python wasn't (in the early stages) so
fabulously friendly.
 
Alan Gauld wrote:
> But Pythons library is not newbie friendly, sorry. How does 
> a newbie know when to use pickle v cpickle? or urllib v urllib2? And 
> which of the xml parsers? And as for thev mess that is glob/os/path/shutil?
> Its not clear to me even after 10 years of using Python which function
> sits where and why. And what about the confusion over system(),
> popen(),commands(),spawn(), subprocess() etc. or why is there time
> and datetime? Sure it makes sense once you've played with Python
> for a while it makes some sense and you learn the role of history.
 
This is very much how this particular 'newbie' has experienced things. I'm
not here to damn Python, but to praise it, for opening my eyes to a whole
bunch of stuff. But you know when I teach biology and genetics, and the
kids don't get it, I feel like the onus is on me to improve my teaching. And
if I code a tool for people in my lab, and they can't use it, then I feel like
I've got some work to do, either in teaching or in making the tool easier to
use.
 
That's just me, Tiger, and I'm sorry it makes you spit venom. Not my
intention at all. But it's Alan's hand that I want to shake, because as
far as I can tell, he's looking to the future, to the next generation, to
the ugly reality and the bright potential, and quite frankly, you're not.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


[Tutor] os.path.exists(path) returns false when the path actually exists!

2007-07-27 Thread Iyer
os.path.exists(path) returns false when the path actually exists!
 
 When I do this:
 
 >>> os.path.exists("c:\\winnt\\file_name")
 
  I get this:
 >>> False
 
 Actually the file exists in c:\winnt, and I can confirm it exists there, but 
os.path.exists isn't returning True, when it should be..
 
 Is this a bug ?
 
 iyer
 
   
-
Park yourself in front of a world of choices in alternative vehicles.
Visit the Yahoo! Auto Green Center.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Eric Brunson

Python is like democracy.  It isn't perfect, but it's the best thing 
come up with so far.  ;-)


Barton David wrote:
> Eric Brunson wrote:
> > You seem like a smart guy that's having a bad day, so I'm cutting you
> > slack.
>  
> Thanks Eric. Yes I did indeed have a bad day (and it got much much worse),
> and this is most definitely a case of a bad workman blaming his tools. I
> apologise to all concerned for voicing my frustrations: it was clearly 
> ill-advised.
> Still.. call me idealistic but I feel like a good toolmaker should try 
> to listen to her
> clients.
>  
> I am not a dedicated programmer. I have other stuff on my plate. I 
> probably
> wouldn't be a programmer at all if Python wasn't (in the early stages) so
> fabulously friendly.
>  
> Alan Gauld wrote:
> > But Pythons library is not newbie friendly, sorry. How does
> > a newbie know when to use pickle v cpickle? or urllib v urllib2? And
> > which of the xml parsers? And as for thev mess that is 
> glob/os/path/shutil?
> > Its not clear to me even after 10 years of using Python which function
> > sits where and why. And what about the confusion over system(),
> > popen(),commands(),spawn(), subprocess() etc. or why is there time
> > and datetime? Sure it makes sense once you've played with Python
> > for a while it makes some sense and you learn the role of history.
>  
> This is very much how this particular 'newbie' has experienced things. I'm
> not here to damn Python, but to praise it, for opening my eyes to a whole
> bunch of stuff. But you know when I teach biology and genetics, and the
> kids don't get it, I feel like the onus is on me to improve my 
> teaching. And
> if I code a tool for people in my lab, and they can't use it, then I 
> feel like
> I've got some work to do, either in teaching or in making the tool 
> easier to
> use.
>  
> That's just me, Tiger, and I'm sorry it makes you spit venom. Not my
> intention at all. But it's Alan's hand that I want to shake, because as
> far as I can tell, he's looking to the future, to the next generation, to
> the ugly reality and the bright potential, and quite frankly, you're not.
>
> This message has been checked for viruses but the contents of an 
> attachment may still contain software viruses, which could damage your 
> computer system: you are advised to perform your own checks. Email 
> communications with the University of Nottingham may be monitored as 
> permitted by UK legislation.
>
> 
>
> ___
> 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] os.path.exists(path) returns false when the path actually exists!

2007-07-27 Thread Iyer

Adam wrote:

>From the library documentation:
Return True if path refers to an existing path. Returns False for
broken symbolic links. On some platforms, this function may return
False if permission is not granted to execute os.stat() on the
requested file, even if the path physically exists.

So the better question is, does is this file a broken symbolic link or
can os.stat() be executed on it?

How do I find if it is a broken symbolic link in Windows 2000 ? 

os.stat(path) returns an OSError saying that there is no such file or directory

   
-
Shape Yahoo! in your own image.  Join our Network Research Panel today!___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] os.path.exists(path) returns false when the path actually exists!

2007-07-27 Thread Adam A. Zajac
> os.path.exists(path) returns false when the path actually exists!
>  
>  When I do this:
>  
>  >>> os.path.exists("c:\\winnt\\file_name")
>  
>   I get this:
>  >>> False
>  
>  Actually the file exists in c:\winnt, and I can confirm it exists
> there, but os.path.exists isn't returning True, when it should be.. 
>  Is this a bug ?

>From the library documentation:
Return True if path refers to an existing path. Returns False for
broken symbolic links. On some platforms, this function may return
False if permission is not granted to execute os.stat() on the
requested file, even if the path physically exists.

So the better question is, does is this file a broken symbolic link or
can os.stat() be executed on it?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor