insert python script in current script

Nick Stinemates nick at stinemates.org
Fri Apr 18 15:16:36 EDT 2008


On Wed, Apr 16, 2008 at 01:41:13PM -0500, Larry Bates wrote:
> Prashant wrote:
> > I was wondering is there any way to do this:
> > 
> > I have written a class in python and __init__ goes like this:
> > 
> > def __init__(self):
> > 
> > self.name = 'jack'
> > self.age = 50
> > 
> > import data
> > 
> > 
> > 
> > 
> > now here there is data.py in the same directory and contents are like:
> > 
> > self.address = 'your address'
> > self.status = 'single'
> > 
> > The problem is 'self' is giving some error here. I need to know if
> > somehow I can do this. It's like inserting the script as it's part of
> > the file itself.
> > 
> > Cheers
> > 
> 
> Can you give a use case for doing this.  You would most likely be better doing:
> 
> class person(object):
>      def __init__(self, name=None, age=None):
>          self.name=name
>          self.age=age
> 
> 
> personInstance=person(name='jack', age='50)
> 
> -Larry
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Could it also be that he would like to have a base class? Cause that's
what It sounds like to me!

class Base:
   def __init__(self):
      self.address = "address"
      self.status = 1 //use numbers instead of strings :)

class Person(Base):
   def __init__(self):
      Base.__init__(self)
      # now you have the self.address, self.status


-- 
Nick Stinemates (nick at stinemates.org)
http://nick.stinemates.org



More information about the Python-list mailing list