undefined undefined undefined

Introduction

Open in new window

Introduction

Импортирование объектов.

mylib.py

GLOBAL_DOMAIN = 'domain.com'

def getDomain():
    print 'My domain is %s' % GLOBAL_DOMAIN

class app():
    typeApp = 'angular+python'
    author = 'Dimitry'
    def getBody(self):
        html = '<body> this is %s application of %s</body>' % (self.typeApp, self.author)
        return html

myapp.py

import mylib
import mypackage.mylib
from mylib import GLOBAL_DOMAIN
from mylib import GLOBAL_DOMAIN as D
from mylib import *
from mypackage.mylib import GLOBAL_DOMAIN

init.py

Files named init.py are used to mark directories on disk as Python package directories. The init.py file is usually empty, but can be used to export selected portions of the package under more convenient name

#__init__.py

from mylib import app
myapp = app()

# test.py

from mypackage import myapp
print myapp.getBody()

Other topics