Python implementation of "include"
Dustan
DustanGroups at gmail.com
Thu Dec 13 20:17:57 EST 2007
> ll... at paisite.com wrote:
> > Hello,
>
> > I've been using the Python-based Karrigell web application framework.
> > It has the very handy word "include" that inserts a code file into
> > into the stream of execution. E.g. if myFile.py contains the code:
>
> > print "This is a message from myFile.py<br>"
>
> > and my script is:
>
> > print "Something<br>"
> > include "myFile.py"
> > print "Something more<br>"
>
> > The output would be:
>
> > Something
> > This is a message from myFile.py
> > Something more
>
> > Since I'm considering moving my application to a different web
> > application framework, I'd like to replace include with a pure python
> > construct. I've discovered several ways to do it, but they all seem
> > kludgy in one way or another. Is there a simple, elegant way to do this?
No. Python is not C. The closest you can get is:
from myFile import *
print some_variable_from_myFile
But instead, you should probably just import:
import myFile
print myFile.some_variable_from_myFile
More information about the Python-list
mailing list