solub
1
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:
Class — Python for you and me 0.5.beta1 documentation
python - Calling a class function inside of __init__ - Stack Overflow
self.findStart()
Kf
2 Likes
solub
4
Oh my… of course ! It seems so obvious now, I don’t what I was thinking. Thank you.
solub
5
Thanks for the doc @kfrajer