Simple python script not resulting in correct result

puska

New member
Hi,

I tried to transpile and compile following python script:

Python:
#!/usr/bin/env python3
# -*- coding: utf8 -*-


class Test:
    def __init__(self, number: int):
        self.number: int = number
       
    def num2str(self):
        converted_number: str = str(self.number)
        return(converted_number)

if __name__ == '__main__':
    test = Test(28)
    print(test.number)
    print(test.num2str())
Result of running that script is:
28
28

when I try to transpile and compile and run that script I am getting.
0
0

11l source looks like:

Code:
T Test
   Int number = number
   F (Int number)
   {
   }

   F num2str()
      String converted_number = String(.number)
      R (converted_number)

:start:
V test = Test(28)
print(test.number)
print(test.num2str())
It looks to me that correct 11l code should be:

Code:
T Test
   Int number
   F (Int number)
      .number = number

   F num2str()
      String converted_number = String(.number)
      R (converted_number)

:start:
V test = Test(28)
print(test.number)
print(test.num2str())
When I ran changed and compiled 11l source I get:
28
28

as when running python script.
Is that a Python -> 11l transpiler bug?

Best Regards
 

alextretyak

Administrator
Staff member
Currently, types of class's member variables must be specified inside class definition (not inside __init__!), i.e.:
Python:
class Test:
    number : int

    def __init__(self, number: int):
        self.number = number
      
    ...
 
Top