list of dots Digital Research Alliance of Canada logo  NSERC logo  University of Ottawa logo / UniversitĂ© d'Ottawa

User Manual    [Previous]   [Next]   

Python

The Python generator in Umple allows you to embed Python methods in Umple. Almost everything that can be generated by the Umple Java generator can also be generated by the Umple Python generator. So, for example, your Umple code can be used to create associations and state machines in generated Python.

 

Embedding Python methods:To insert Python methods in Umple, you specify the method signature followed by the keyword Python followed by an open curly bracket, then any number of lines of Python code, and finally a closing curly bracket.

To create a main Pyhon function in a class use the same method signature as for Java, except tag the code as Python. So a main function first line would look like the following public static void main(String [ ] args) Python { . This would be followed by Python code, and ends with a closing curly bracket }.

 

Take a look the the last two Hello World examples for some tips. UmpleOnline examples marked with an asterisk already have Python main programs, as well as Java main programs.

 

Python in UmpleOnline: Python code can be executed in UmpleOnline as of April 2024. To get methods to execute as Python methods, you need to tag them with the keyword Python before the opening curly bracket, as described above. You need at least one main method. When your code is ready, select Python Code from the Generate menu, and then click Execute It. If you make syntax errors or have runtime errors in your embedded Python, UmpleOnline will point you to the line you need to fix.

 

Command line use: TXL transformation technology is used to convert generated Java to Python.

The Python generator also works on the command line. So you can use Umple to create large and complex systems. However if you are generating Python on the command line you need to install version 10.8b of FreeTXL first. This can also be downloaded from our own server for Linux, Mac or Windows.

After downloading and uncompressing, run the install script.



Currently Partially supported features:

  • In each Python method embedded in Umple you need to add and import statement for any other classes you reference in the method. We intend to automate this later.
  • Aspect oriented code Injection (before and after methods).



Currently unsupported features:

  • Tracing: This is very Java-specific.
  • Any Umple code that see creates synchronized methods in Java: See issue #2070 and #2071 for more information

If any of the features that are supported appear to function incorrectly, please submit a new issue here.