Bengt Richter informs Ray St.Marie that...
I sometimes find it handy to leave out underscore items:
[name for name in dir() if not name.startswith('_')]
[name for name in dir() if not name.startswith('_')]
['name', 'x'] <<<_see Below

['__builtins__', '__doc__', '__name__', 'name', 'x']

Bengt Richter
Cool and now I do too ...you ... tip monster you !

Thanks - (giggling with that "you b at stard" grin on my face)
(Why is it the simplest things make ya laugh.)

But this - the true beauty in your example is that...
You didn't enter an iterater 'name' into the dir ( )
before you displayed it. Nice trick.
In fact you never have to in a dir( ) call.
The only reason 'name' <<<_see above
is in the dir( ) now is because
this is your second for loop.
I mean to say that the dir( )
was displayed first the first time
then 'name' was added --- am I right?
Now it's there for the second call.

Yet in the examples that ...

<I've lost the original thread and
don't have the 2 gentilmen's names that started it>

...that they were working on, it was pretty obvious that
you had to have an iterater variable established first for the
vars( ) call.

If I don't put the ' v ' in the dir( ) before
the call to vars( ) first I get the Traceback
because I'm changing the size of the dictionary
for d in dir( ): print d
... __builtins__ # i Know i know ive learned nothing sorry
for v in vars( ): print v
name # okay there's the first variable and then

Traceback (most recent call last):
File "<interactive input>", line 1, in ?
RuntimeError: dictionary changed size during iteration

And the point to the second gentilman in the thread was
that his call to
for v in vars( ).copy( ): print v
only works because the call to copy( ) does this first just
like declaring the ' v ' in my example -- only it a one liner. :>)

When I was new at this and, dir( ) and vars( ) were something
I learned early on, It didn't seam that intuitive to me.

........and so i go on and on and on about something only
I could find intersting, and I shall never more on this subject
Sorry Y'all.

Ray St. Marie
Stating the obvious since birth... Whaaaa.

Search Discussions

Discussion Posts


Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 9 of 9 | next ›
Discussion Overview
grouppython-list @
postedJul 19, '03 at 3:51p
activeJul 22, '03 at 7:07a



site design / logo © 2022 Grokbase