python 指定 lib目录

node2:/django/mysite/home#cat /django/mysite/test.py
class Person(object):  
    def __init__(self, name, gender):  
        self.name = name  
        self.gender = gender  
    def query(self,friend):  
        print self.name  
        print self.gender  
        self.friend=friend  
        print self.friend 
node2:/django/mysite/home#
node2:/django/mysite/home#cat a1.py 
import os
import sys
projectpath = '/django'
if projectpath not in sys.path:   sys.path.append(projectpath)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from mysite.test import *
h=Person('aa','bb')
h.query('cc')
node2:/django/mysite/home#python a1.py 
aa
bb
cc

你可能感兴趣的:(Django1.8文档)