473,416 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Debuging-Finding out the class attributes/member variable values

440 256MB
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 1745
bvdet
2,851 Expert Mod 2GB
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 256MB
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.Which I would like to watch in the Debug window of the python

-PSB
May 19 '07 #3
bvdet
2,851 Expert Mod 2GB
Thanks for the reply,

It is not a dictionary,it is a class attributes.Which 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 Expert 4TB
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
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
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...
0
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...
2
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...
3
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...
8
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...
0
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...
1
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...
1
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....
3
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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
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
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,...
0
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
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...

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.