Python中引入自定义路径下的用户自定义类
2013-11-06 19:41
267 查看
自定义类如下:
测试类如下:
>>python test_circle.py
运行结果:
('Redius: ', 5)
('Perimeter: ', 31.415926535897931)
('Area: ', 78.539816339744831)
import math class Circle: # Construct a circle object def __init__(self, radius = 1): self.radius = radius def getPerimeter(self): return 2 * self.radius * math.pi def getArea(self): return self.radius * self.radius * math.pi def setRadius(self, radius): self.radius = radius
测试类如下:
import sys sys.path.append(r'/home/MyTrain/Python/Class') from Circle import Circle c = Circle(5) print("Redius: ", c.radius) print("Perimeter: ", c.getPerimeter()) print("Area: ", c.getArea())
>>python test_circle.py
运行结果:
('Redius: ', 5)
('Perimeter: ', 31.415926535897931)
('Area: ', 78.539816339744831)
相关文章推荐
- NumPy学习笔记--入门篇
- Python里安装NumPy模块
- Windows 下 Python easy_install 的安装
- 用Python递归解决阿拉伯数字转为中文财务数字格式的问题(2)--打开思路的一种方法
- Python中time模块详解
- python内置函数
- python 爬虫学习一
- python代码统计大文本文件行数
- Python 遍历目录下的所有文件
- python 中的反射,装饰器,with语句
- python遍历文件夹和文件
- python 跟着鼠标走的火柴人
- Python中的getattr()和__getattr__方法
- python 单元测试工具-Pyunit
- Python使用struct处理二进制
- python抓取汇率
- 安装numpy、scipy、matplotlib
- 修改类属性 分类: divide into python 2013-11-06 16:48 236人阅读 评论(0) 收藏
- 使用Python 控制MS Word
- 安装numpy、scipy、matplotlib