Forums

Instance external class python

In fileA.py

I have the following: ( I simplified the code)

class ControlArmPositional():
def __init__(self):
    self.xml_trayectory_right=[]
    self.xml_trayectory_left=[]
    self.user_storedpoints_left=0
    self.user_storedpoints_right=0
def ApplyTrajectoryPointsRight(self):
 print("ApplyTraject Right Inside")         
 for i in range(self.user_storedpoints_right):
     self.hiro.setTargetPose('rarm',[self.xml_point_right[i][0],self.xml_point_right[i][1],self.xml_point_right[i][2]],[self.xml_point_right[i][3],self.xml_point_right[i][4],self.xml_point_right[i][5]], 2)


if __name__=='__main__':
    arm_positional =ControlArmPositional()
    arm_positional.main()
else:
    print 'I am being imported from another module'

In fileB.py

from folder1.fileA import *

global arm_positional
arm_positional =ControlArmPositional()
class MyPlugin(Plugin):
...


def push_button_dotrayectoryright(self):
    if (self.status_start== True):            
     arm_positional.ApplyTrajectoryPointsRight()

All files running same time. If I change something on fileA I want change it in fileB and same if change something on fileB see that change on fileA.

My problem is when I save points on fileA, for example 5 points , when I call in fileB the method that belongs to fileA the number of points is 0.
I also tried to use set and get functions but no work.

Any idea? Can I use same object on an external class?

Thanks a lot

How are you running the program?

With ROS

rosrun [package] [name_node]

I don't know anything about ROS, except that it's a robot operating system. My guess, based on that, is that there's a compilation step that you may be missing.

Forget about ROS,I think my problem is concept about Python. When I instance class ControlArmPositional() on fileB.py the object that i created always access to init variables and "can't see" modifications (multithread real time) i made on fileA.py.

Anyway, thank you for your time.

Then the issue isn't with you file layout or your imports, it's about how you're running the threads and sharing information between them.