473,804 Members | 4,408 Online
Bytes | Software Development & Data Engineering Community
+ 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 2047
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
2477
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 __init__and defined a __del__ method to clean up resources. I then discovered asimilar problem in the shelve module. This led me to two importantdiscoveries: 1. Attributes defined in __init__ after an error is raised will not be apart of the...
0
2052
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__ = <bound method AttributeError.__getitem__ of <exceptions.AttributeError instance at 0x8187984>> __init__ = <bound method AttributeError.__init__ of <exceptions.AttributeError instance at 0x8187984>> __module__ = 'exceptions'
17
4296
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 time looking up the real names... :) I'm just looking to make my code more readable and self-documenting... --------
2
4977
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# function within the library to alert the user and send focus to the offending control. In VB.NET, I can code something like this (where I just put a runat=server onto the <BODY> tag and named it BodyTag) : DirectCast(Page.FindControl("BodyTag"), _...
2
2849
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 message: "AttributeError: OutputBinary." Here is my code below: Please Help.
2
2566
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 input into the frame at the same time. The saveFile name is autocreated based on the data entered by the user in the first frame. Each frame that is created is a new class, e.g. the first frame that opens is "CharInfo", which opens the frame...
2
5720
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
1115
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 tried to call mothods to set values for IF and gain, such as set_AGC(), get_output_freq(), etc... it seems not able to find those methods/ functions... Could someone be kind enough to give me some pointers for solving such errors?
0
1045
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 am doing. We use a simulator for a microprocessor we are using in our systems. Our simulator allows for extensions that can be loaded as shared libraries. Rather than code the entire extension in C/C++, I would like to make use of Python to...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10320
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9150
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4299
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 we have to send another system

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.