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 12:41:41 CET 2005

  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

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.


More information about the Python-list mailing list