473,624 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Debuging-Finding out the class attributes/member variable values

440 Contributor
Hi,

How to check the class attributes/member variable values while debuging in 'PythonWin'?.

I need to watch all the member varibales values of a class ,given the object or etc.

Thanks
PSB
May 19 '07 #1
4 1752
bvdet
2,851 Recognized Expert Moderator Specialist
Hi,

How to check the class attributes/member variable values while debuging in 'PythonWin'?.

I need to watch all the member varibales values of a class ,given the object or etc.

Thanks
PSB
This is what I use to check the contents of an instance dictionary:
Expand|Select|Wrap|Line Numbers
  1. def formatDict(hdr_str, dd):
  2.     listCopy = dd.keys()
  3.     listCopy.sort()
  4.     maxLen = max([len(i) for i in listCopy])
  5.     return '%s%s%s' % (hdr_str, "\n", ''.join(["Key = %s %s Value = %s\n" % \
  6.            (i, " " * (maxLen - len(i)) + "  ", dd[i]) for i in listCopy]))
  7.  
  8. a = YourClass()
  9. print formatDict("\nObject Attributes:", a.__dict__)
HTH :)
May 19 '07 #2
psbasha
440 Contributor
This is what I use to check the contents of an instance dictionary:
Expand|Select|Wrap|Line Numbers
  1. def formatDict(hdr_str, dd):
  2.     listCopy = dd.keys()
  3.     listCopy.sort()
  4.     maxLen = max([len(i) for i in listCopy])
  5.     return '%s%s%s' % (hdr_str, "\n", ''.join(["Key = %s %s Value = %s\n" % \
  6.            (i, " " * (maxLen - len(i)) + "  ", dd[i]) for i in listCopy]))
  7.  
  8. a = YourClass()
  9. print formatDict("\nObject Attributes:", a.__dict__)
HTH :)
Thanks for the reply,

It is not a dictionary,it is a class attributes.Whic h I would like to watch in the Debug window of the python

-PSB
May 19 '07 #3
bvdet
2,851 Recognized Expert Moderator Specialist
Thanks for the reply,

It is not a dictionary,it is a class attributes.Whic h I would like to watch in the Debug window of the python

-PSB
I always debug with print statements. To check the status of class attributes, you can do something like this:
Expand|Select|Wrap|Line Numbers
  1. class Demo:
  2.     a1 = 1
  3.     a2 = 2
  4.     def __init__(self, data={}):
  5.         self.data = data
  6.     def chk_att(self):
  7.         for item in ['a1', 'a2']:
  8.             print '%s = %s' % (item, eval('Demo.%s' % item))
  9.  
  10.  
  11. print '\n'.join(['%s = %s' % (item, eval('Demo.%s' % item)) for item in dir(Demo) if item in ['a1', 'a2']])
  12. print
  13. a = Demo([1,2,3,4])
  14. a.chk_att()
  15.  
  16. print
  17.  
  18. Demo.a2 = 5000
  19. print '\n'.join(['%s = %s' % (item, eval('Demo.%s' % item)) for item in dir(Demo) if item in ['a1', 'a2']])
  20. print
  21. a.chk_att()
Expand|Select|Wrap|Line Numbers
  1. >>> a1 = 1
  2. a2 = 2
  3.  
  4. a1 = 1
  5. a2 = 2
  6.  
  7. a1 = 1
  8. a2 = 5000
  9.  
  10. a1 = 1
  11. a2 = 5000
  12. >>> 
May 19 '07 #4
bartonc
6,596 Recognized Expert Expert
Hi,

How to check the class attributes/member variable values while debuging in 'PythonWin'?.

I need to watch all the member varibales values of a class ,given the object or etc.

Thanks
PSB
Since I don't use PythonWin (or any other debugger), I use the inspect module:
Expand|Select|Wrap|Line Numbers
  1. >>> import inspect
  2. >>> class aClass:
  3. ...     aValue = 1
  4. ...     bValue = 'test'
  5. ...     
  6. >>> anInstance = aClass()
  7. >>> print [(name, value) for name, value in inspect.getmembers(anInstance) if not name.startswith("_")]
  8. [('aValue', 1), ('bValue', 'test')]
  9. >>>
May 20 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2466
by: mickeyg | last post by:
Is there a way to step thru php application? What tools do I need? I will like to see what lines are being executed and maybe variables values Thanks in advance
0
986
by: Vincent Finn | last post by:
Hi, I have some controls (VB.Net) written be someone else They are loaded using an asp page How can I debug the contol? I have tried attaching the process to IExplorer and aspnet_wp.exe but I get nothing, no breakpoints are hit I assume it is something simple but I can't find it in the MSDN.
0
1218
by: serge calderara | last post by:
Dear all, I try to debug a strore procedure within VS studio server explorer. Problem I have is when selecting my store procedure and then Step into menu I get error message that I have no debug rights on master db or something like that What should I do to make it working Thnaks for your help
2
1334
by: joe | last post by:
Hi when iam writing a console program it is preatty simple to ouput variables to stdout, but how do i do that with a windows app? i am compiling a windows app tha uses cp and cpp libs and i am trying to get the parametes for a function inside the function. is there a way to pop up a window with the value? or do i have to write them to a file?
3
1662
by: bob | last post by:
Hello, I've tried a few testing frameworks with C# but so far haven't found a way to debug into a failing test. I'm used to S Unit (Smalltalk) where when a test fails you just right click on it and say debug and the program halts at the point where the test fails. This makes it very easy to debug the test as you have the stack, locals etc. At them moment I'm having to recompile the main loop to call the failing test and put a break in...
8
3025
by: Jason | last post by:
In the c++ debugger I could give it a memory address of some data and it would break when that data changed. It is very helpful when you have a single value change of a large amount of code and you just want to know what/where/why its changing. I tried to hook it up like I in C++, opening up the new break point window, going to the data tab and supplying a pointer... just for fun I put in the var name ( since there are no pointers in c# )...
0
972
by: FOX User Group | last post by:
Hi, Migh be this is the stupid question, does anyone know the root cause of the following problem: 1. I create project Web Application, say just put label 'Testing" on the page 2. I run the web page by pressing F5 key after that appear error message: "Unable to start debuging on the web server. Server side-error occurred on sending debug HTTP request"
1
1152
by: Rogers | last post by:
When I tried to run an application developed by VB.net in IIS6,This error occured,The error message is "Current credit level setting desn't support Debuging"(in chinese),I dont't know how to translate it,I hope you can undenstand it. I create a website and added two virtual directorys to it,But both two applications doesn't work,The error message is upwards. And the setting of this website is default,I didn't change anything after I...
1
1089
by: Carlos Albert | last post by:
Hello group, I have a weird problem with VS2003 & VS2005 using both ASP.NET 1.1 and 2.0, that is that 90% of the times I hit debug, doesn't debug anything, just runs as I was releasing. Sometimes it works, one or two pages, or even the same page after a postback, just stop debuging. Didn't try debuging a windows app, cause I only do web development. I'm running Win2003, IIS6, .NET framework 1.1 and 2.0, VS 2003 and VS2005.
3
1233
by: Tina | last post by:
How can I debug with a querystring in vs.net? Is there some place to put the querystring? thanks, T
0
8234
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
8172
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
8677
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
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...
0
7158
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...
0
5563
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
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
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
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.