Python

Moderators: None (Apply to moderate this forum)
Number of threads: 473
Number of posts: 1172

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with dir() Posted by Navic on 1 Jul 2008 at 1:00 AM
I'm new to Python and have the Python Reference Manual Release 2.5.2 as my only guide so far, but here's my problem:

I've got a custom class 'Foo' with two functions - 'hello' and 'goodbye' that just print a string.

I'm assigning the output of the dir() function to a variable and want to then perform a dir() on each index value of the first variable and Python doesn't like it. Here's what I've got:

a = dir()
print dir(a[0])


When I execute this the output is the generic classes and does not include the functions of my custom Foo class at all. Now when I forget about assigning the output of the dir() to an array and just hard code dir(Foo) it works fine, returning my two functions. I've noticed that the problem is related to the compiler reading it as a string or a 'literal' I guess it's called, because the output of these two commands is completely different:

dir(Foo)


and

dir('Foo')


The first output without the quotes being the one I'm trying to get by an array variable of the entire generic dir() function alone.

I've printed out the array for testing purposes and sure enough, index 0 is Foo so it should in theory work.

Is there some kind of pickle method or function I need to perform to make dir(a[0]) work???

Thanks!
Navic



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.