Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Inline Python is bad because

  • Your source code files cannot be understood by Python source code editors and you will miss syntax highlighting

  • All other tools, like pylint, which can be used to lint and validate source code will fail also

Alternative

In element <CustomComponent index="DamageCalculatorComponent">

... add parameter script:

<CustomComponent index="DamageCalculatorComponent" script="damager.py">

Then add file damager.py somewhere along the file system.

Load it as described here: What alternative is there to execfile in Python 3? / How to include a Python file?What alternative is there to execfile in Python 3? / How to include a Python file?

In your main game engine code construct the class out of loaded system module like:

 damager_class = sys.modules["mymodulename"].my_factory_function() 

All Python modules must share some kind of agreed class names / entry point functions.

If you want to have really pluggable architecture, use Python eggs and setup.py entry points

Example

Inline Python is bad because

  • Your source code files cannot be understood by Python source code editors and you will miss syntax highlighting

  • All other tools, like pylint, which can be used to lint and validate source code will fail also

Alternative

In element <CustomComponent index="DamageCalculatorComponent">

... add parameter script:

<CustomComponent index="DamageCalculatorComponent" script="damager.py">

Then add file damager.py somewhere along the file system.

Load it as described here: What alternative is there to execfile in Python 3? / How to include a Python file?

In your main game engine code construct the class out of loaded system module like:

 damager_class = sys.modules["mymodulename"].my_factory_function() 

All Python modules must share some kind of agreed class names / entry point functions.

If you want to have really pluggable architecture, use Python eggs and setup.py entry points

Example

Inline Python is bad because

  • Your source code files cannot be understood by Python source code editors and you will miss syntax highlighting

  • All other tools, like pylint, which can be used to lint and validate source code will fail also

Alternative

In element <CustomComponent index="DamageCalculatorComponent">

... add parameter script:

<CustomComponent index="DamageCalculatorComponent" script="damager.py">

Then add file damager.py somewhere along the file system.

Load it as described here: What alternative is there to execfile in Python 3? / How to include a Python file?

In your main game engine code construct the class out of loaded system module like:

 damager_class = sys.modules["mymodulename"].my_factory_function() 

All Python modules must share some kind of agreed class names / entry point functions.

If you want to have really pluggable architecture, use Python eggs and setup.py entry points

Example

Source Link
Mikko Ohtamaa
  • 85k
  • 63
  • 296
  • 479

Inline Python is bad because

  • Your source code files cannot be understood by Python source code editors and you will miss syntax highlighting

  • All other tools, like pylint, which can be used to lint and validate source code will fail also

Alternative

In element <CustomComponent index="DamageCalculatorComponent">

... add parameter script:

<CustomComponent index="DamageCalculatorComponent" script="damager.py">

Then add file damager.py somewhere along the file system.

Load it as described here: What alternative is there to execfile in Python 3? / How to include a Python file?

In your main game engine code construct the class out of loaded system module like:

 damager_class = sys.modules["mymodulename"].my_factory_function() 

All Python modules must share some kind of agreed class names / entry point functions.

If you want to have really pluggable architecture, use Python eggs and setup.py entry points

Example