Python中引入自定义路径下的用户自定义类

自定义类如下:

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)

 

 

上一篇:objective-c宏定义


下一篇:【整理】Socket编程之非阻塞connect(一)