include "apythonscript.py"

M

martijn

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
 
L

Larry Bates

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
 
C

Chris Curvey

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
 
M

martijn

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
 
D

Duncan Booth

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,238
Messages
2,571,193
Members
47,830
Latest member
ZacharySap

Latest Threads

Top