[Tutor] RE: Tutor digest, Vol 1 #1532 - 13 msgs

marsha_sheridan@agilent.com marsha_sheridan@agilent.com
Mon, 1 Apr 2002 06:54:24 -0700


Teach Yourself Python in 24 Hours Website

To access the downloadable examples for each chapter you need to go to the
following site:
 http://www.pauahtun.org/TYPython/

The files are under Chapter Links.



-----Original Message-----
From: tutor-request@python.org [mailto:tutor-request@python.org]
Sent: Sunday, March 31, 2002 4:20 PM
To: tutor@python.org
Subject: Tutor digest, Vol 1 #1532 - 13 msgs


Send Tutor mailing list submissions to
	tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
	tutor-request@python.org

You can reach the person managing the list at
	tutor-admin@python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

   1. Teach Yourself Python in 24 Hours Website (Brian W. Carver)
   2. RE: simple problem (alan.gauld@bt.com)
   3. RE: importing a subprocess in dos (alan.gauld@bt.com)
   4. Re: hacking 101 (Paul Sidorsky)
   5. Re: Teach Yourself Python in 24 Hours Website (Brian W. Carver)
   6. RE: command line (alan.gauld@bt.com)
   7. RE: command line (alan.gauld@bt.com)
   8. RE: command line (alan.gauld@bt.com)
   9. Re: hacking 101 (Blake Winton)
  10. Re: command line (Blake Winton)
  11. RE: command line (alan.gauld@bt.com)
  12. RE: hacking 101 (alan.gauld@bt.com)
  13. RE: idle - namespaces (was idle) (alan.gauld@bt.com)

--__--__--

Message: 1
Date: Sun, 31 Mar 2002 14:05:19 -0800
From: "Brian W. Carver" <bwcarver@earthlink.net>
To: tutor@python.org
Subject: [Tutor] Teach Yourself Python in 24 Hours Website

Hi,

I recently bought Ivan Van Laningham's book: Teach Yourself Python in 24
Hours.
Throughout the book he makes reference to a website for the book that
includes
files to download.  When I go to the website indicated (
http://www.pauahtun.org
) I find his personal pages but nothing related to the book, and very little
related to Python.  Anyone else used this book, had this problem, and
eventually
found the files?  If so, can you point me in the right direction?  I've sent
a
similar e-mail to what appears to be the author's address, but didn't know
whether I'd get a response.  Thanks for any help.

Brian W. Carver




--__--__--

Message: 2
From: alan.gauld@bt.com
To: hysterix240@yahoo.com, tutor@python.org
Subject: RE: [Tutor] simple problem
Date: Sun, 31 Mar 2002 23:08:06 +0100

> for on mac os 10, and i am using it through terminal

MacOS X is catching on...

> i try to put a line of code and and then try to put
> another underneath it, i have to hit return, and
> python runs through the code, so what happens if i
> want to put more than 1 line of code 

You can put your code in a file. Use textedit to create 
a file with a .py extension(by convention). Then in terminal type:

$ python foo.py

where $ is the unix prompt
python is the interpreter
foo.py is the file you created.

Yu can also use vi or emacs within terminal which is how real 
unix heads do it, but textedit will suffice - just make 
sure you save as plain text.

> python GUI, or the IDLE, 

I'm sure someone will have pointed you to Danny's IDLE tutor 
by now. Just remember you need to run an Xserver like XonX 
to use IDLE on MacOS X.

Alan g



--__--__--

Message: 3
From: alan.gauld@bt.com
To: bwgolling@attbi.com, tutor@python.org
Subject: RE: [Tutor] importing a subprocess in dos
Date: Sun, 31 Mar 2002 23:12:04 +0100

> do I run a process in dos (btw my os is win98) and import the 
> result to my python interpreter?

Use popen() or one of its variants - look min os module.

BUT it used to be on DOS that you had to use the one 
from the winall package(or ActiveState's python).
Does anyone know if this is still true in V2.xx?

Alan G



--__--__--

Message: 4
Date: Sun, 31 Mar 2002 15:14:03 -0700
From: Paul Sidorsky <paulsid@shaw.ca>
Subject: Re: [Tutor] hacking 101
To: tutor <tutor@python.org>

Remco Gerlich wrote:

> At every place where you get user input, *in any form*, try to think of
the
> weirdest form it could take, the syntax you don't expect. Question your
> assumptions - if it's user input, they're not held to your assumptions.

Better yet, have somebody else do the questioning.  I never had the
cracker mentality but I knew a guy who did and the holes he found in my
software were rather remarkable to me.  I just never would have thought
to do the things he did.  Most of the time they weren't even
unconscionable or devious things, they were just fairly routine things
that ordinary programmers wouldn't think anybody would do.

--
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/



--__--__--

Message: 5
Date: Sun, 31 Mar 2002 14:16:09 -0800
From: "Brian W. Carver" <bwcarver@earthlink.net>
To: tutor@python.org
Subject: [Tutor] Re: Teach Yourself Python in 24 Hours Website

I thought I'd answer my own question, since the author responded with
lightning
speed.

The files are at: http://www.pauahtun.org/TYPython/

Sorry for the wasted bandwidth.  Next time I write, I'll have a good Python
question for the group.

Brian W. Carver

> Hi,
>
> I recently bought Ivan Van Laningham's book: Teach Yourself Python in 24
Hours.
> Throughout the book he makes reference to a website for the book that
includes
> files to download.  When I go to the website indicated (
http://www.pauahtun.org
> ) I find his personal pages but nothing related to the book, and very
little
> related to Python.  Anyone else used this book, had this problem, and
eventually
> found the files?  If so, can you point me in the right direction?  I've
sent a
> similar e-mail to what appears to be the author's address, but didn't know
> whether I'd get a response.  Thanks for any help.
>
> Brian W. Carver
>




--__--__--

Message: 6
From: alan.gauld@bt.com
To: wolf_binary@hotmail.com, tutor@python.org
Subject: RE: [Tutor] command line
Date: Sun, 31 Mar 2002 23:21:20 +0100

------_=_NextPart_001_01C1D902.62330F80
Content-type: text/plain; charset="iso-8859-1"

 >  Why would you use the command line Python instead of the IDLE? 
 
1) It uses less machine resources
 
2) It starts faster
 
3) My text editor is better than IDLE's so edit run 
   is better than edit, switch program, run
 
 4) IDLE sets up its own environment python at 
    the command prompt python executes like the 
    production environment so less spurious errors
 
5) Tkinter does strange things in IDLE, not at the 
   python prompt.
 
Some of that relates to using the interpreter from the 
OS prompt, some to the cython interpreter prompt. 
The latter assumes as a minimum NT level editing 
functions and getline by preference.
 
Alan G

------_=_NextPart_001_01C1D902.62330F80
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&gt; &nbsp;</FONT></SPAN>Why would
you 
use the command line Python instead of the IDLE?<SPAN 
class=830241622-31032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>1) It uses less machine 
resources</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>2) It starts 
faster</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff></FONT></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>3) My text editor is better than IDLE's so
edit 
run </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&nbsp; is better than edit, switch 
program, run</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN
class=830241622-31032002>&nbsp;<FONT 
face="Courier New" color=#0000ff>4) IDLE sets up its own environment python
at 
</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&nbsp;&nbsp; the command prompt
python 
executes like the </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&nbsp;&nbsp; production environment
so 
less spurious errors</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>5) Tkinter does strange things in IDLE, not at the 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>&nbsp;&nbsp; python
prompt.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>Some of that relates to using the interpreter from
the 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>OS prompt, some to the cython interpreter prompt. 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>The latter assumes as a minimum NT level editing 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>functions and getline by 
preference.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>Alan G</SPAN></FONT></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C1D902.62330F80--



--__--__--

Message: 7
From: alan.gauld@bt.com
To: dman@dman.ddts.net, tutor@python.org
Subject: RE: [Tutor] command line
Date: Sun, 31 Mar 2002 23:26:58 +0100

Wayyyy off topic but...

> After you install Microsoft Windows XP, you have the option to create
> user accounts.  If you create user accounts, by default, they 
> will have an account type of administrator with no password.

<RANT>
True on XP Home and a really terrible decision by MS.
Why not a single administrator and new users either 
Poweruser or restricted user? The latter is too restricted 
for most users but admin is simply insane! Bang goes much
of XPs security protection! I am seriously considering 
upgrading from Home to Pro just because of this issue.
</RANT>

Otherwise its not bad....

Alan G.



--__--__--

Message: 8
From: alan.gauld@bt.com
To: urnerk@qwest.net, dman@dman.ddts.net
Cc: tutor@python.org
Subject: RE: [Tutor] command line
Date: Sun, 31 Mar 2002 23:32:23 +0100

> environment.  Maybe it's different in Win2k, where uparrow
> history is somehow available.

Yes, you get the minimal up arrow functions in Win2000 and XP

But a better option is to install cygwin which provides 
full getline() functionality.

IDLE still has advantages and if I'm doing a big session 
I use it:

function hints as mentioned, 
color coding(!)
Save a session

But for quick tests and all Tkinter work I use the command 
line version

Alan g.



--__--__--

Message: 9
Date: Sun, 31 Mar 2002 17:29:16 -0500
From: Blake Winton <bwinton@tor.dhs.org>
To: tutor <tutor@python.org>
Subject: Re: [Tutor] hacking 101

* Remco Gerlich <scarblac@pino.selwerd.nl> [020331 16:54]:
> At every place where you get user input, *in any form*, try to think of
the
> weirdest form it could take, the syntax you don't expect. Question your
> assumptions - if it's user input, they're not held to your assumptions.
> 
> Focus at user input. Everything that comes from outside is suspect. Trace
> the path of this data through your code.

For web-based applications, change your username to "<!--" and see if
the rest of the page gets displayed correctly.  If you suspect it's
using a SQL backend, change your name to "name' OR name='aaa" and see if
that breaks anything.  On most of the projects I work on, I test for
stuff like that, and even though it's a PITA to handle it, you've got
to, cause people will mess you up (not even on purpose) if they can.
Heck, that isn't even hacking or cracking, it's just good testing.

Try subscribing to a mailing list as "foo@bar.com\nyahoo@bad.com" (even
better would be if the \n was the actual new-line character, perhaps
copied into the clipboard and pasted into the app).  Or maybe make your
name "test@bad.com;print 'This isnt good!!!'"  Stuff like that.  You
know better than the rest of us what you do with your input, so take
that knowledge, and see if you can create input that breaks your code.

(And email me a link to the code, and I'll look it over, and see what I
can come up with.  *grin*  ;)

Later,
Blake.
-- 
  5:28pm  up 18 days, 21:17,  2 users,  load average: 0.00, 0.01, 0.04



--__--__--

Message: 10
Date: Sun, 31 Mar 2002 17:34:48 -0500
From: Blake Winton <bwinton@tor.dhs.org>
To: alan.gauld@bt.com
Cc: wolf_binary@hotmail.com, tutor@python.org
Subject: Re: [Tutor] command line

* alan.gauld@bt.com <alan.gauld@bt.com> [020331 17:23]:
>  >  Why would you use the command line Python instead of the IDLE? 
> 1)
[...]  
> 5) 

6)

[~ bwinton] /opt/python/src/Tools/idle/idle.py
Traceback (most recent call last):
  File "/opt/python/src/Tools/idle/idle.py", line 4, in ?
    PyShell.main()
  File "/opt/python/src/Tools/idle/PyShell.py", line 747, in main
    root = Tk(className="Idle")
  File "/opt/python/lib/python2.2/lib-tk/Tkinter.py", line 1480, in
__init__
    self.tk = _tkinter.create(screenName, baseName, className)
TclError: no display name and no $DISPLAY environment variable


[~ bwinton] /opt/python/bin/python
Python 2.2a3 (#1, Sep 16 2001, 12:18:17)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

(I can't run idle, but the command line works just fine...
 I don't run X by default.  Just cause.)

Later,
Blake.
-- 
9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07



--__--__--

Message: 11
From: alan.gauld@bt.com
To: dman@dman.ddts.net, tutor@python.org
Subject: RE: [Tutor] command line
Date: Sun, 31 Mar 2002 23:46:00 +0100

> Do you know of any non-windows IDEs that have these features?  

Depending on the language there are lot of them in Unix 
but they tend to cost megeabucks. (HP SoftBench, 
Sun WorkBench, ObjectCenter, Sniff++ etc etc)

There are some new ones coming along for Linux etc 
too Kdevelop, Blackadder, and some others(Activestates tool?)

> New converts to *nix often ask (in deb-user at least) where the IDEs
> usual answer is "unix _is_ an IDE -- 

And that is the correct answer. Most of our windows programmers 
do their development on Unix and then move the code to Windows 
(VC++ or JBuilder) for final build & test. but the tools on 
Unix surpass any of the Windows tools commercial or otherwise.
(trace, gdb, tcov, [g]prof, ctags, xref, gplot, cflow, etc etc)

> | In my experience, pro programmers appreciate time-saving
> | and productivity-enhancing features,

Not in my experience, most long term pros stick by the tools 
they know really well, editor and debugger mainly and just 
carve out the code. They know the language etc so well they 
hardly ever use the "toys". There's nothing so productive 
as just typing the code in and it works first time! Many 
experienced pros reach that level of quality after 10 years 
or so...

> | >The important lesson to walk away with is this: if you are not
> | >using an interactive python interpreter while coding and
> | >experimenting you are missing out on one of the key benefits
> | >python offers.

This is true and is where Python development differs from 
traditional style coding.

Alan G



--__--__--

Message: 12
From: alan.gauld@bt.com
To: i812@iname.com, tutor@python.org
Subject: RE: [Tutor] hacking 101
Date: Mon, 1 Apr 2002 00:03:28 +0100 

Rob,

> On Sun, Mar 31, 2002 at 04:03:08PM -0500, kirk Bailey wrote:
> > FreeBSD
> 
> Oh, that's probably a pretty good choice. I'm sure they have 
> a security mailing list which you could join 

I think the thing Kirk is interested in is how to make the 
mailing list registration form he has written in Python 
secure, not how to make his BSD box secure. That's why he 
needs to know how crackers operate so he can guard against 
it in his code.

Kirk,

There are some sites around covering secure code techniques 
but many are biased to C/C++ in my experience. Things like 
buffer overruns etc are not such an issue in Python because 
we can't read a string into a fixed length byte array etc.

But there are plenty other things to look out for I'm sure, 
and I'd be interested if you do find a good source of info.

Alan g.



--__--__--

Message: 13
From: alan.gauld@bt.com
To: glingl@aon.at, apython101@yahoo.com, tutor@python.org
Subject: RE: [Tutor] idle - namespaces (was idle)
Date: Mon, 1 Apr 2002 00:16:39 +0100 

------_=_NextPart_001_01C1D90A.1CCDBC30
Content-type: text/plain; charset="iso-8859-1"

I may have missed the answer to this but here goes anyway...
 
>  away code. However I just noticed something, when I delete all the code  
>  to write some more throw away code the variables and I think also other  
>  things do not get deleted. How do I delete them?  
 
With great difficulty.
 
When you import names from a module they get stored 
in a dictionary. When you reload a module it simply 
adds the names - which is why reload doesn't work 
for the "from f import x" form.
 
The only reliable way to do this is to exit and restart
(Cameron another reason I use the OS command line...)
 
Of course avoiding the from f inmoprt x style helps a lot.
 

>>> dir()
['__builtins__', '__doc__', '__name__']
 

dir() returns a list but its built up from the underlying 
dictionary. deleting from the list doesn't affect the 
dictionary underneath.
 

>>> del a


This deletes the name from the underlying dictionary...

 >>> dir()
['__builtins__', '__doc__', '__name__', 'foo']

 so its gone from dir() too... 


But if you try to delete several items from a list, this doesn't work,
because of the difference between the string 'a' and the name a, I think:
 
>>> dir()
['__builtins__', '__doc__', '__name__', 'a', 'foo']
>>> dir()[3:]  
['a', 'foo']
>>> for name in dir()[3:]:
     del name 
 

This deletes the string that was in the list (I think, 
I admit I'm getting more shaky here...)

>>> for name in dir()[3:]:
    del eval(name) 

This uses the string to eval which returns the alue of 
the variable named by the string - ie 3 in this case.
 
 >  So how do I get acces to the Variable a via dir() ? 
 
I don't think you can. You have to go to the Builtins 
dictionary and grub about in the innards - not recommended! 
 
Alan G.
 

------_=_NextPart_001_01C1D90A.1CCDBC30
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>I may have missed the answer to this but here goes 
anyway...</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002></SPAN><SPAN
class=050230623-31032002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>away code. However I just noticed something,

when I delete all the code&nbsp;<SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>to write some more throw away code the
variables 
and I think also other&nbsp;<SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>things do not get deleted. How do I delete 
them?&nbsp;<SPAN class=050230623-31032002><FONT face="Courier New"
color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>With great difficulty.</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>When you import names from a module they get stored
</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>in a dictionary. When you reload a module it simply
</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>adds the names - which is why reload doesn't work
</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>for the "from f import x" form.</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>The only reliable way to do this is to exit and 
restart</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>(Cameron another reason I use the OS command
line...)</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>Of course avoiding the from f inmoprt x style helps a 
lot.</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid;
MARGIN-RIGHT: 0px">
  <DIV><FONT face="Courier New" size=2>&gt;&gt;&gt;
dir()<BR>['__builtins__', 
  '__doc__', '__name__']<BR><SPAN class=050230623-31032002><FONT 
  color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face="Courier New" size=2><SPAN 
class=050230623-31032002>dir() returns a list but its built up from the 
underlying </SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2><SPAN 
class=050230623-31032002>dictionary. deleting from the list doesn't affect
the 
</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2><SPAN 
class=050230623-31032002>dictionary underneath.</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2><SPAN 
class=050230623-31032002></SPAN></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid;
MARGIN-RIGHT: 0px">
  <DIV><FONT face=Arial><FONT face="Courier New" size=2>&gt;&gt;&gt; del 
  a<BR><SPAN class=050230623-31032002><FONT 
  color=#0000ff></FONT></SPAN></FONT></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face=Arial><FONT face="Courier New" size=2><SPAN 
class=050230623-31032002><FONT color=#0000ff>This deletes the name from the 
underlying dictionary...</FONT></SPAN></FONT></FONT></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid;
MARGIN-RIGHT: 0px">
  <DIV><FONT face=Arial><FONT face="Courier New"><FONT size=2><SPAN 
  class=050230623-31032002>&nbsp;</SPAN>&gt;&gt;&gt;
dir()<BR>['__builtins__', 
  '__doc__', '__name__', 'foo']</FONT></FONT></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face=Arial><FONT face="Courier New"><FONT size=2><SPAN 
class=050230623-31032002>&nbsp;</SPAN><SPAN class=050230623-31032002><FONT 
color=#0000ff>so its&nbsp;gone from dir() 
too...&nbsp;</FONT></SPAN></FONT><BR></DIV><FONT size=2></FONT></FONT>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid;
MARGIN-RIGHT: 0px"></FONT>
  <DIV><FONT size=2>But if you try to delete several items from a list, this

  doesn't work,</FONT></DIV>
  <DIV><FONT size=2>because of the difference between the&nbsp;string 'a'
and 
  the name a, I think:</FONT></DIV>
  <DIV><FONT size=2></FONT>&nbsp;</DIV>
  <DIV><FONT size=2>&gt;&gt;&gt; dir()<BR>['__builtins__', '__doc__', 
  '__name__', 'a', 'foo']<BR>&gt;&gt;&gt; dir()[3:]<SPAN 
  class=050230623-31032002><FONT face="Courier New" 
  color=#0000ff>&nbsp;</FONT></SPAN><SPAN 
  class=050230623-31032002>&nbsp;</SPAN><BR>['a', 'foo']<BR>&gt;&gt;&gt; for

  name in dir()[3:]:<BR>&nbsp;&nbsp;&nbsp;&nbsp; del name<SPAN 
  class=050230623-31032002><FONT face="Courier New" 
  color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV>
  <DIV><FONT size=2><SPAN 
class=050230623-31032002>&nbsp;</SPAN></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=050230623-31032002>This deletes the string that was in the list (I
think, 
</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=050230623-31032002>I admit I'm getting more shaky 
here...)</SPAN></FONT></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid;
MARGIN-RIGHT: 0px">
  <DIV><FONT size=2>&gt;&gt;&gt; for name in
dir()[3:]:<BR>&nbsp;&nbsp;&nbsp; 
  del eval(name)<SPAN class=050230623-31032002><FONT face="Courier New" 
  color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT size=2><SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff>This uses the string to eval which returns
the 
alue of </FONT></SPAN></FONT></DIV>
<DIV dir=ltr><FONT size=2><SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff>the variable named by the string - ie 3 in
this 
case.</FONT></SPAN></FONT></DIV>
<DIV dir=ltr><FONT size=2><SPAN
class=050230623-31032002>&nbsp;</SPAN><BR><SPAN 
class=050230623-31032002><FONT face="Courier New" color=#0000ff>&nbsp;<FONT 
face="Times New Roman" color=#000000>&gt; </FONT>&nbsp;</FONT></SPAN>So how
do I 
get acces to the Variable a via dir() ?<SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV>
<DIV dir=ltr><FONT size=2><SPAN 
class=050230623-31032002></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT size=2><SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff>I don't think you can. You have to go to
the 
Builtins </FONT></SPAN></FONT></DIV>
<DIV dir=ltr><FONT size=2><SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff>dictionary and grub about in the innards -
not 
recommended!</FONT>&nbsp;</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=050230623-31032002></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=050230623-31032002>Alan G.</SPAN></FONT></DIV>
<DIV dir=ltr><FONT size=2><SPAN 
class=050230623-31032002></SPAN></FONT>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01C1D90A.1CCDBC30--




--__--__--

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


End of Tutor Digest