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
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: - def formatDict(hdr_str, dd):
-
listCopy = dd.keys()
-
listCopy.sort()
-
maxLen = max([len(i) for i in listCopy])
-
return '%s%s%s' % (hdr_str, "\n", ''.join(["Key = %s %s Value = %s\n" % \
-
(i, " " * (maxLen - len(i)) + " ", dd[i]) for i in listCopy]))
-
-
a = YourClass()
-
print formatDict("\nObject Attributes:", a.__dict__)
HTH :)
This is what I use to check the contents of an instance dictionary: - def formatDict(hdr_str, dd):
-
listCopy = dd.keys()
-
listCopy.sort()
-
maxLen = max([len(i) for i in listCopy])
-
return '%s%s%s' % (hdr_str, "\n", ''.join(["Key = %s %s Value = %s\n" % \
-
(i, " " * (maxLen - len(i)) + " ", dd[i]) for i in listCopy]))
-
-
a = YourClass()
-
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
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: - class Demo:
-
a1 = 1
-
a2 = 2
-
def __init__(self, data={}):
-
self.data = data
-
def chk_att(self):
-
for item in ['a1', 'a2']:
-
print '%s = %s' % (item, eval('Demo.%s' % item))
-
-
-
print '\n'.join(['%s = %s' % (item, eval('Demo.%s' % item)) for item in dir(Demo) if item in ['a1', 'a2']])
-
print
-
a = Demo([1,2,3,4])
-
a.chk_att()
-
-
print
-
-
Demo.a2 = 5000
-
print '\n'.join(['%s = %s' % (item, eval('Demo.%s' % item)) for item in dir(Demo) if item in ['a1', 'a2']])
-
print
-
a.chk_att()
- >>> a1 = 1
-
a2 = 2
-
-
a1 = 1
-
a2 = 2
-
-
a1 = 1
-
a2 = 5000
-
-
a1 = 1
-
a2 = 5000
-
>>>
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: -
>>> import inspect
-
>>> class aClass:
-
... aValue = 1
-
... bValue = 'test'
-
...
-
>>> anInstance = aClass()
-
>>> print [(name, value) for name, value in inspect.getmembers(anInstance) if not name.startswith("_")]
-
[('aValue', 1), ('bValue', 'test')]
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |