Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中更改类变量_Python_Oop - Fatal编程技术网

在python中更改类变量

在python中更改类变量,python,oop,Python,Oop,我正在写一个脚本来读取DXF文件并返回形状的长度和面积,这样我就可以自动计算激光切割零件的价格 圆弧应采用dxf文件中的圆弧名称、圆心、半径、起始角度和结束角度。 圆弧应计算圆弧的起点和终点 问题是,角度是任意的,所以起点和终点是任意的, 我很难把弧串在一起形成一个完整的图形, 我需要一个机制来切换起点和终点,如果我注意到它是向后的。 我试图在arc类中编写一个函数,以切换起点和终点 但它不起作用, 我不太擅长OOP,请帮忙 附加代码 class arc: def __in

我正在写一个脚本来读取DXF文件并返回形状的长度和面积,这样我就可以自动计算激光切割零件的价格

圆弧应采用dxf文件中的圆弧名称、圆心、半径、起始角度和结束角度。 圆弧应计算圆弧的起点和终点

问题是,角度是任意的,所以起点和终点是任意的, 我很难把弧串在一起形成一个完整的图形, 我需要一个机制来切换起点和终点,如果我注意到它是向后的。 我试图在arc类中编写一个函数,以切换起点和终点 但它不起作用, 我不太擅长OOP,请帮忙

附加代码

    class arc:
       def __init__(self, name, center_point, radius, angles):
    self.name = name
    self.center_point = center_point
    self.radius = radius
    self.starting_angle = angles[0]
    self.ending_angle = angles[1]

    starting_angle = angles[0]
    ending_angle = angles[1]
    self.starting_point = center_point[0]+radius * math.cos((starting_angle)*((math.pi)/(180))),center_point[1]+radius * math.sin((starting_angle)*((math.pi)/(180)))
    self.ending_point = center_point[0]+radius * math.cos((ending_angle)*((math.pi)/(180))),center_point[1]+radius * math.sin((ending_angle)*((math.pi)/(180)))

    starting_point =center_point[0]+radius * math.cos((starting_angle)*((math.pi)/(180))),center_point[1]+radius * math.sin((starting_angle)*((math.pi)/(180)))
    ending_point = center_point[0]+radius * math.cos((ending_angle)*((math.pi)/(180))),center_point[1]+radius * math.sin((ending_angle)*((math.pi)/(180)))
    self.length = math.sqrt((starting_point[0]-ending_point[0])**2+(starting_point[1]-ending_point[1])**2)
我需要一个名为switch的函数

这就是它的工作原理:

    arc1.starting_point = (0,0)
    arc1.ending_point = (1,1)
    print(arc1.starting_point, arc1.ending_point)
    #Desired Output:
    ((0,0),(1,1))

    arc1.switch()
    print(arc1.starting_point, arc1.ending_point)

    #Desired Output:
    ((1,1),(0,0))

您可以通过同时赋值交换两个变量的值:

>>> x = 0
>>> y = 1
>>> x, y = y, x
>>> x
1
>>> y
0
所以


我应该这样做

在我看来,你可以把这些数据放在一个列表中并使用反向函数为什么你要复制你的点计算?将被调试,这仍然在进行中尝试反向列表,它不起作用我尝试了,切换函数不会永久更改变量,在切换实例变量后保持不变
def switch(self):
    self.starting_point, self.ending_point = self.ending_point, self.starting_point