470,591 Members | 2,005 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

include "apythonscript.py"

H!

I'm trying to find a python function to use like this:

-- maincode.py

Include "apythonscript_function.py"

-- end

So I can split the maincode.py file in smalle pieces.
Or yust save the function's in other file and include them once.
I really want to use this because else { the maincode.py will be super
super large. }

Thanks,
GC-Martijn

----- if you don't understand what I mean: http://www.php.net/include

Jul 19 '05 #1
4 1712
How about?

put apythonscript_function.py in a separate file

then

inculde apythonscript_function.py at the top of maincode.py

Looks like you probably need to go back and read the tutorial.

-Larry

ma*****@gamecreators.nl wrote:
H!

I'm trying to find a python function to use like this:

-- maincode.py

Include "apythonscript_function.py"

-- end

So I can split the maincode.py file in smalle pieces.
Or yust save the function's in other file and include them once.
I really want to use this because else { the maincode.py will be super
super large. }

Thanks,
GC-Martijn

----- if you don't understand what I mean: http://www.php.net/include

Jul 19 '05 #2
the PHP include doesn't have an exact match in Python, but I think you
can do what you intend.

To follow the first example from php.net, this would work

vars.py
color = 'green'
fruit = 'apple'

test.py
from vars import *
print "A " , color, fruit

HTH

Jul 19 '05 #3
Ah damn , that's the way.

And what if you have a very big class and want to include some class
functions ?

class ThisIsAClass:
def __init__(self):

Here I want to import a class def

Jul 19 '05 #4
wrote:
Ah damn , that's the way.

And what if you have a very big class and want to include some class
functions ?

class ThisIsAClass:
def __init__(self):

Here I want to import a class def


The usual way to handle that would be to not write a 'very big class' at
all: create a lot of comparatively simple classes and use either
inheritance or aggregation as appropriate to combine them.

You will find this makes your life much easier all round.

What you are doing sounds like a classic case of 'The Blob'. See
http://www.antipatterns.com/briefing/sld024.htm
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by marco | last post: by
reply views Thread by Michael Williams | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.