Java to Python conversion

Hi again,

I’m currently trying to port a Java script to Python but I’m stuck on something that goes like this:

class Agent {
  float x, y;
  float t;   
  
  Agent() {
    findStart();
  }
  
  void findStart() {
...

On line 5 it seems the class is calling itself from within (not sure what I’m saying makes sense). How would I translate this to Python ?

class Agent(object):
    def __init__(self):
        self.x = 0.0
        self.y = 0.0
        self.t = 0.0

    ???
    
    def findStart(self):
1 Like

It’s normal to call a class method from within. In Python, it’s like this

class Agent(object):
    def __init__(self):
        self.x = 0.0
        self.y = 0.0
        self.t = 0.0
        self.findStart()
    
    def findStart(self):
        pass
3 Likes

init is consider to be the constructor (I think you know this). For the function, I found the second link:

https://pymbook.readthedocs.io/en/latest/classes.html
https://stackoverflow.com/questions/12646326/calling-a-class-function-inside-of-init

self.findStart()

Kf

2 Likes

Oh my… of course ! It seems so obvious now, I don’t what I was thinking. Thank you.

Thanks for the doc @kfrajer