473,480 Members | 1,850 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

AttributeError: How to list existing attributes?

Hi,

how can you list the attributes of an object if you catch an
AttributeError?

I couldn't find a reference in the exception object, which
points to the object.

I want to call dir() on the object to list the user the known
attributes.

Is there a way to find the object by inspecting the stacktrace?

Thomas

--
Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: ni**************@thomas-guettler.de

Sep 19 '07 #1
2 2022
Thomas Guettler wrote:
Hi,

how can you list the attributes of an object if you catch an
AttributeError?

I couldn't find a reference in the exception object, which
points to the object.

I want to call dir() on the object to list the user the known
attributes.

Is there a way to find the object by inspecting the stacktrace?
By looking at the code at the line the stacktrace lists? And at least for
me, there is a type-information as well:

Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
clWelcome to rlcompleter2 0.96
for nice experiences hit <tabmultiple times
>>class Foo(object): pass
....
>>f = Foo()
f.foo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Foo' object has no attribute 'foo'
>>>
You can't possibly know which attributes the object has, though. Because it
might be an attribute dynamically added.

So the best thing is to put a print-statement before the exception-throwing
line or put a

import pdb; pdb.set_trace()

there, and fiddle around with the object.

Diez
Sep 19 '07 #2
Diez B. Roggisch wrote:
Thomas Guettler wrote:
>Hi,

how can you list the attributes of an object if you catch an
AttributeError?

I couldn't find a reference in the exception object, which
points to the object.

I want to call dir() on the object to list the user the known
attributes.

Is there a way to find the object by inspecting the stacktrace?

By looking at the code at the line the stacktrace lists? And at least for
me, there is a type-information as well:
Hello,

I want to customize the debug tracebacks displayed in django.
It is not to find one particular error. That's why changing the
source is not a solution.

Thomas

--
Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: ni**************@thomas-guettler.de

Sep 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2446
by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem stemmed from a class that raised an error inside...
0
2020
by: Erlend Fuglum | last post by:
I have tried and tried, but cannot figure out the source of the following error: AttributeError: 'module' object has no attribute 'menyHMTL' __doc__ = 'Attribute not found.' __getitem__ =...
17
4252
by: Pierre Fortin | last post by:
Hi, Is the following a reasonable generic approach for converting python returned tuples/lists into dicts...? I'm not advocating library functions also return dicts (I'd probably spend more...
2
4958
by: Eric Lemmon | last post by:
Hello C# Gurus, Please excuse my VB mindset. I am writing a class library in C# that is used by a VB ASP.NET app. When SQL Server detects a data validation exception, I want to use a C#...
2
2833
by: kbperry | last post by:
Hi all, I am getting an error message when trying to use the P4 print command via the python api for perforce. Anytime that I run p4c.run("print","-q", eachFile), I keep getting an error...
2
2537
by: crystalattice | last post by:
Not sure how to explain, but I'll try my best. I'm making a GUI with wxGlade. The GUI has windows that open when the "Next Page" button is pushed; the button also pickles the information that is...
2
5683
by: Rahul B | last post by:
Hi. I have created a table CREATE TABLE testschema.player ( country VARCHAR(80) NOT NULL, posn VARCHAR(2) not null ) /
0
1099
by: noroi | last post by:
Hi, I got problems while running Eric Blossom's FM receiver's example codes from the GNURadio tutorial page; the RF front end reads the signal input from daughter board, and when the compiler...
0
1003
by: PlayDough | last post by:
I've embedded Python in an extension for a program we are using here at work. And I'm a bit stumped as to why I am getting an AttributeError only in the embedded Python. First, a bit of what I...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7044
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6739
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4779
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.