473,406 Members | 2,619 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,406 software developers and data experts.

Filtering & Getting data out from a object

Hi,
I have written a the following python code to analyse a function or a method. I am having a script which is having a python function (add) and a class (MyClass) with a method (multiply).When I analyse it using the following method(analyze_func) , I get an output like below.
The problem I am having is, I need to get the value 'MyClass.multiply' from the obj. When I do obj.__name__ , I am only getting "multiply" only.So can anyone propose me how to get the value 'MyClass.multiply'.



-----------------------------------------------
# OUTPUT
-----------------------------------------------
object passed to func() is <unbound method MyClass.multiply>
Method: multiply

===testing code===
result is multiply
===testing code===

Method Arguments: var1 var2

object passed to func() is <function add at 0xb65aa7d4>
Function: add

===testing code===
result is add
===testing code===

Method Arguments: var1 var2

------------------------------------------------
# PYTHON SCRIPT
-----------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. def analyze_func(obj, method=False):   
  2.    str1 = ''
  3.    global result   
  4.    print '%s' % obj.__name__
  5.    print 'object passed to func() is ' , obj
  6.  
  7.    if method:
  8.        print 'Method: %s' % obj.__name__
  9.        strme = '%s' % obj.__name__
  10.        str1=strme
  11.  
  12.    else:
  13.        print 'Function: %s' % obj.__name__
  14.        strme = '%s' % obj.__name__
  15.        str1=strme      
  16.  
  17.  
  18.    arginfo = inspect.getargspec(obj)
  19.    args = arginfo[0]
  20.    argsvar = arginfo[1]
  21.  
  22.    print ''
  23.    print '===testing code==='
  24.  
  25.    a = arginfo[0]    
  26.  
  27.    print 'result is ' , str1
  28.    result = result + str1
  29.  
  30.    result = result + '@'
  31.  
  32.    print '===testing code==='
  33.    print ''
  34.  
  35.    if args:
  36.        if args[0] == 'self':
  37.            print '\t%s is an instance method' % obj.__name__
  38.            args.pop(0)
  39.        print '\tMethod Arguments: %s' % ' '.join(args)
  40.        if arginfo[3]:
  41.            dl = len(arginfo[3])
  42.            al = len(args)
  43.            defargs = args[al-dl:al]
  44.            print 'Default arguments:',zip(defargs, arginfo[3])
  45.  
  46.    if arginfo[1]:
  47.        print '\t Positional Args Param: %s' % arginfo[1]
  48.    if arginfo[2]:
  49.        print '\t Keyword Args Param: %s' % arginfo[2]
  50.  
  51.  
Apr 29 '08 #1
0 1004

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

Similar topics

3
by: Alex Ayzin | last post by:
Hi, I have a problem that might be easy to solve(possibly, I've just overlooked an easy solution). Here we go: I have a dataset with 2 datatables in it. Now, I need to do the following: if...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
1
by: Jason | last post by:
I've gathered a bunch of data from Active Directory and placed it into a datatable ("ADTable"). I now need to sort and filter this table based on the selection of a drop down list("ddlCategory"). ...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
1
by: dirk van waes | last post by:
Hello everyone, Being complete newbie in asp.net I am trying to make an example which works with a very simple database. First I made my project in VS- vb.net, draging an oledbconnection and an...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
2
by: Gummy | last post by:
Hello All, I have a webpage that has two dropdown listboxes. Based on what is selected in these dropdown listboxes, it filters a DataGrid . That works fine. In the DataGrid , when I go to edit...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...

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.