to include python files in an other script in Blender

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

c-leo
Posts: 8
Joined: Tue Jul 01, 2003 10:41 am

to include python files in an other script in Blender

Postby c-leo » Fri Jul 11, 2003 6:10 pm

i would like import a file in a blender plugin, which is in the same directory

so i 've written the import, but when i use a class of the file imported, i have this mistake:
NameError: name 'Md3Frame' is not defined

How to resolve this problem?

theeth
Posts: 1184
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

Postby theeth » Fri Jul 11, 2003 6:33 pm

add the path to this module to the python path variable

Code: Select all

import sys
sys.path.append("c:/blah/blah/blah/")


Martin
Life is what happens to you when you're busy making other plans.
- John Lennon

c-leo
Posts: 8
Joined: Tue Jul 01, 2003 10:41 am

Postby c-leo » Mon Jul 14, 2003 8:39 pm

it doesn't work

Here is an example of what i would like doing

my file "module.py"

class Class:
def __init__ (self):
pass

my file "main.py"
import module
import sys
sys.path.append("/home/info/An-01-02/levimond/blender/plugins")
myClass = Class ()


i want execute "main.py" in Blender but i get this mistake:
Traceback (most recent call last):
File "main.py.001", line 6, in ?
NameError: name 'Class' is not defined

So, how can i resolve this problem ?

theeth
Posts: 1184
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

Postby theeth » Mon Jul 14, 2003 10:25 pm

use either this

Code: Select all

from module import *

...

myClass = Class()


or this

Code: Select all

import module

...

myClass = module.Class()


Martin
Life is what happens to you when you're busy making other plans.

- John Lennon


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest