0

Introduction

Image you want to describe a combustion process

In order to sort elements, I created

  • classes for the describing the substance (eq. class Fuel)
  • class which describes the combustion (eq. class combustion)
  • main.py to run an example

Python Files

properties.py

class SolidProp:

    def __init__(self,ua):
        self._ultimate = Ultimate(ua)

    @property
    def ultimate(self):
        return self._ultimate

class Ultimate:

    def __init__(self,ua: dict):
        self._comp = ua

    @property
    def comp(self):
        return self._comp

combustion.py

from properties import *

class Combustion:

    def __init__(self,ultimate):

        self.fuel = SolidProp(ua=ultimate)

main.py

from combustion import *

burner = Combustion({'CH4':0.75, 'C2H4':0.25})

Problem Description

ipython console

In the ipython console (in bash) the following is not recognized automatically (but it can be called):

Python 3.7.2 (default, Dec 29 2018, 06:19:36) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: run 'main.py'

In [2]: burner.fuel.ultimate.comp
Out[2]: {'CH4': 0.75, 'C2H4': 0.25}

This has something to do that *.ultimate is defined via a decorator in properties.py (see @property) but I would like to be able to get *.ultimate.comp autocompleted in the ipython console, so people can work with it intuitively.

Example

  • burner.fuel.ultimate is recognized
  • burner.fuel.ultimate.comp is NOT recognized

I can not see any methods or properties beyond burner.fuel.ultimate in the ipython console. This makes it not intuitively for people to work with it when they do not know those methods exist.

Remark: ipython console of IDE pycharm works fine!?

python console

Running it in the python console:

Python 3.7.2 (default, Dec 29 2018, 06:19:36) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exec(open("main.py").read())
>>> burner.fuel.ultimate.comp
{'CH4': 0.75, 'C2H4': 0.25}

Works fine. But why not in the ipython console from a terminal?

maro12
  • 109
  • 7
  • 1
    I don't understand your question. What does "not recognized automatically" mean? How does the result you get differ from what you expect? – Daniel Roseman May 14 '19 at 10:54
  • See the __Eq.__ part. – maro12 May 14 '19 at 10:59
  • Well, you still didn't explain what you mean by "recognized", but never mind. What's the point of the property? Why don't you just do `self.ultimate = Ultimate(s)` in the init? – Daniel Roseman May 14 '19 at 11:07
  • Seems like it is about autocompletion. – sanyassh May 14 '19 at 11:13
  • @Sanyash: yes it is about autocomplete (sometimes it is hard to find the right words) – maro12 May 14 '19 at 11:20
  • @Daniel Roseman: I want to run it through the decorator, because I want to implement some test routines there AND there are more fuels (Solids,LightLiquids,HeavyLiquids,Gas) each should have there unique `@property` definition. – maro12 May 14 '19 at 11:22
  • I found those entries: [link1](https://stackoverflow.com/questions/55039499/autocomplete-with-encapsulation-of-property-decorator),[link2](https://stackoverflow.com/questions/54944533/autocomplete-for-jupyter-notebook-and-ipython-console-for-classes-with-propert) which address the problem and it is an ongoing issue for the ipython developers see [issue](https://github.com/ipython/ipython/issues/11653) – maro12 May 15 '19 at 08:18
  • Update to IPython 7.5.0 no change at this end. – maro12 May 15 '19 at 08:41

0 Answers0