Results 1 to 8 of 8

Thread: Python and PHP question.

  1. #1
    Associate
    Join Date
    Sep 2004
    Posts
    40

    Python and PHP question.

    Anyone does Python and PHP?
    How to clone the get_class() PHP function in Python?

  2. #2

    Python and PHP question.

    hi,

    If you describe what it does, I might be able to tell you how to do it in Python.

    arman

  3. #3
    Associate
    Join Date
    Sep 2004
    Posts
    40

    Python and PHP question.

    I have an instance of a class. I need to find out the class name of the instance. The Python built-in insinstance() function is not what I need, because
    it would return true for an instance of the a class from a hierarchy, not for an instance of a specific class.

    -----------------
    class A:
    pass

    def get_class(a):
    #some code

    a = A()
    print get_class(a)
    -----------------------

    This one should print "A".

  4. #4

    Python and PHP question.

    what is the base class for python classes?
    Object, object, class?

  5. #5
    Associate
    Join Date
    Sep 2004
    Posts
    40

    Python and PHP question.

    Excuse me, I didn't get your question.

  6. #6

    Python and PHP question.

    ok...

    yourobject.__class__ or type(yourobject) -- gives you the type ("class")

    Unless you're doing metaprogramming, you probably don't need that, though. I don't know what PHP's get_clss does or how it's used


    class A(object): pass

    ...

    type(A())

    <class '__main__.A'>


    After you have the type object, you can also do:
    'A'


    Hope it is closed enough....

    ---------------------------------------------
    What do you need this for?
    I'll take a wild guess: prototyping-like programming style?
    prototype even.

    arman

  7. #7
    Associate
    Join Date
    Sep 2004
    Posts
    40

    Python and PHP question.

    The get_class() PHP function returns the class name as string.
    It seems like it should be enough to parse the string
    s = repr(A)
    in case that it is included in some module hierarchy and contains also the modules name.
    It has no practical purpose, I was just thinking about a class that implements the Proxy pattern and that behaves differently for class instances of different classes from the same hierarchy. I've got confused, because I realized that isinstance() won't help me to make difference between instances of two different classes from the same hierarchy. I don't understand even now why isinstance() was implemented like it was and not to return true only for the class passed as argument.
    Probably it's some OOP principle that I'm not understanding yet.

  8. #8

    Python and PHP question.

    suya man ko ninyo..patudlo nya ko ninyo python mga migo.

Similar Threads

  1. Python Help
    By jmn0729 in forum Linux - General Topics
    Replies: 1
    Last Post: 11-02-2008, 11:44 AM
  2. Python or C
    By wmartino in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 01-20-2005, 09:06 PM
  3. Simple Python class question.
    By Smegma in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 10-22-2003, 09:29 AM
  4. Python
    By behnam in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 09-26-2002, 11:34 AM
  5. Writing an IRC bot in python?
    By Twelveguage in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 01-21-2002, 01:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •