# Java to Python conversion

**URL:** https://discourse.processing.org/t/java-to-python-conversion/2723
**Category:** Processing.py
**Created:** [August 17, 2018, 1:31pm UTC](https://discourse.processing.org/t/java-to-python-conversion/2723 "2018-08-17T13:31:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)
#### Post date: [August 17, 2018, 1:31pm UTC](https://discourse.processing.org/t/java-to-python-conversion/2723/1 "2018-08-17T13:31:13Z")

</div>

Hi again,

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

```auto
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 ?

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

    ???
    
    def findStart(self):

```

---

<div class="post-metadata">

### Author: ![WakeMeAtThree](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/wakemeatthree/32/38_2.png) [@WakeMeAtThree](https://discourse.processing.org/u/WakeMeAtThree)
#### Post date: [August 17, 2018, 2:36pm UTC](https://discourse.processing.org/t/java-to-python-conversion/2723/2 "2018-08-17T14:36:57Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [August 17, 2018, 2:40pm UTC](https://discourse.processing.org/t/java-to-python-conversion/2723/3 "2018-08-17T14:40:01Z")

</div>

`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](https://pymbook.readthedocs.io/en/latest/classes.html)  
> [python - Calling a class function inside of \_\_init\_\_ - Stack Overflow](https://stackoverflow.com/questions/12646326/calling-a-class-function-inside-of-init)

`self.findStart()`

Kf

---

<div class="post-metadata">

### Author: ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)
#### Post date: [August 17, 2018, 4:34pm UTC](https://discourse.processing.org/t/java-to-python-conversion/2723/4 "2018-08-17T16:34:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)
#### Post date: [August 17, 2018, 4:35pm UTC](https://discourse.processing.org/t/java-to-python-conversion/2723/5 "2018-08-17T16:35:20Z")

</div>

Thanks for the doc @kfrajer
