Python: import Module and Class
2013-11-29 21:09
549 查看
Module: function_set.py
Class: Person.py
import:
Note:
http://www.learnpython.org/Modules_and_Packages
def print_function( name ): print "hello, %s" % name; return
Class: Person.py
class Person: ''' classdocs ''' name = ""; age = 0; gender = "Unknown"; def __init__(self, name, age, gender): ''' Constructor ''' self.name = name; self.age = age; self.gender = gender; def print_info(self): print "Name: %s, Age: %d, Gender: %s" % (self.name, self.age, self.gender);
import:
from function_set import print_function from Person import Person print_function("tes1t"); p = Person("John Smith", 28, "Male"); p.print_info();
Note:
Each package in Python is a directory which MUST contain a special file called __init__.py. This file can be empty, and it indicates that the directory it contains is a Python package, so it can be imported the same way a module can be imported.
http://www.learnpython.org/Modules_and_Packages
相关文章推荐
- Python Module and Class
- Use Module and Function instead of Class in Python
- 【Python】import class/import module
- 解决java调用python的Cannot import site module and its dependencies: No module named site问题
- python import error no module named google.protobuf
- Error:Unable to make the module:***, related gradle configuration was not found. Please, re-import the Gradle project and try again.
- What is the difference between @staticmethod and @classmethod in Python?
- python2.7 import error no module named yaml ·问题
- python - the first class example and method inv...
- python错误:ImportError: No module named setuptools解决办法
- Python的点点滴滴(Dynamic Module Import)
- Python 之 ImportError: No module named ***
- Python---class and iter
- python如何import 文件名存在字符串变量里的module
- Python's datetime module, numpy's datetime64/timedelta64 and pandas' Timestamp/Timedelta objects
- python 动态加载module、class、function
- Bluemix上Python应用启动ERR import MySQLdb ImportError: No module named MySQLdb
- python+selenium安装过程出现ImportError: No module named selenium问题
- python import site failed/no module named site
- Python ImportError: No module named Tkinter