looking for way to include many times some .py code from another python code

Martin MOKREJŠ mmokrejs at ribosome.natur.cuni.cz
Tue Mar 8 06:41:41 EST 2005


Hi,
  I'm looking for some easy way to do something like include in c or PHP.
Imagine I would like to have:


cat somefile.py
a = 222
b = 111
c = 9


cat somefile2.py
self.xxx = a
self.zzz = b
self.c = c
self.d = d


cat anotherfile.py

def a():
    include somefile
    postprocess(a)

def b():
    include somefile
    postprocess(a, b, c)

class klass():
    def __init__(self, a, b, c, d):
        include somefile2



  I know about module imports and reloads, but am not sure if this is the right
way to go. Mainly, I want to assign to multiple object instances some self bound
variables. Their values will be different, so I can't use global variables.

Martin



More information about the Python-list mailing list