User Profile

Collapse

Profile Sidebar

Collapse
vishalsethia
vishalsethia
Last Activity: Aug 29 '07, 01:00 AM
Joined: Feb 5 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • vishalsethia
    replied to Instantiating classes on the fly
    Was googling around and found a way to instantiate objects on the fly.

    Script 1 (Arbitrary.py)
    --------------
    Code:
    import string
    class ArbitraryClass:
            def getClass(self, moduleName):
                    return __import__(
                            moduleName,
                            {},
                            {},
                            []
    ...
    See more | Go to post
    Last edited by bartonc; Feb 7 '07, 12:53 AM. Reason: added [code][/code] tags

    Leave a comment:


  • vishalsethia
    replied to Instantiating classes on the fly
    Thanks Barton, That helped me import the module but now how do I instantiate it or access the functions declared within that class.

    Thanks
    --V
    See more | Go to post

    Leave a comment:


  • vishalsethia
    replied to Instantiating classes on the fly
    Sorry for not being clear on the first post. What I meant was

    Script 1
    ---------------
    ./script1.py -f script2.py

    To instantiate script2 , one would normally use in script1

    object = script2.script2 ()
    object.function 1()

    But if the name of script2 is dynamic (which comes from command line), how do I instantiate that object.


    Script 2 (script2.py)...
    See more | Go to post
    Last edited by bartonc; Feb 6 '07, 09:34 PM. Reason: added [code][/code] tags

    Leave a comment:


  • vishalsethia
    started a topic Instantiating classes on the fly

    Instantiating classes on the fly

    Is there a way in which classes can be instantiated on the fly. I would be passed the name of the file to be instantiated through command line which I store in a variable using getopt.

    So the file that needs to be instantiated would be dynamic. How would I achieve that in Python

    Thanks
    --V
    See more | Go to post

  • Thanks .. that helped.
    See more | Go to post

    Leave a comment:


  • I tried to implement based on the previous comment, but it doesn't seem to serve to work. I am not sure what am I missing here ?

    The output I get is

    ['234', '123']
    ['444', '233']
    []

    I am not sure how do I achieve this ?
    If either of the files update that global variable, wherever I print, it should have that updated value. Also I am not sure declaring global variables is a...
    See more | Go to post

    Leave a comment:


  • vishalsethia
    started a topic sharing variables between two scripts

    sharing variables between two scripts

    I was wondering if I declare a variable as global , can I share the same variable in a different file with the updated value. (ie) A global variable value to be used between different files without passing them within functions.


    Say for eg.

    Script 1
    Code:
    global foo = "sample"
    
    def func1
       global foo
       foo = "updated sample"
       print foo
    ...
    See more | Go to post
    Last edited by bartonc; Feb 6 '07, 01:29 AM. Reason: added [code][/code] tags
No activity results to display
Show More
Working...