Coding a simple state machine in python

2014-02-24 Thread Ronaldo
How do I write a state machine in python? I have identified the states and the 
conditions. Is it possible to do simple a if-then-else sort of an algorithm? 
Below is some pseudo code:

if state == "ABC":
   do_something()
   change state to DEF

if state == "DEF"
   perform_the_next_function()
...

I have a class to which certain values are passed from a GUI and the functions 
above have to make use of those variables. How do I go about doing this? I have 
the following algorithm:

class TestClass():
def __init__(self, var1, var2): #var1 and var2 are received from a GUI
   self.var1 = var1
...
if state == "ABC"
   doSomething(var1, var2)
..

Could someone point me in the right direction? Thank you!
   
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python3 package import difference?

2024-08-07 Thread Ronaldo Sc via Python-list
I believe you will need to track the modules in the folder  *dbi  *in the
root file '__init__.py'.

So there's an alternative to use the statement __all__ in the root filet
__init__.py, check the link where I find a use case:

*https://sentry.io/answers/what-is-init-py-for-in-python/#using-__init__py-to-run-code-and-control--imports
<https://sentry.io/answers/what-is-init-py-for-in-python/#using-__init__py-to-run-code-and-control--imports>*


References to take more deep in those issues:
PEP-3147 <https://peps.python.org/pep-3147/>
https://docs.python.org/3/tutorial/modules.html
<https://docs.python.org/3/tutorial/modules.html#intra-package-references>
 in this link above we have some examples of relative imports:
from . import echo
from .. import formats
from ..filters import equalizer


In your code you're using "import *" , this is not a good practice when
using only some features in your module(s) because you'll inject more
garbage into memory if there are features you're not using.

Share with us the updates on your code.

Ronaldo

Em qua., 7 de ago. de 2024 às 14:40, Tobiah via Python-list <
python-list@python.org> escreveu:

> I have an old library from 20 some years ago
> for use with python2, that is structured like this:
>
>  rcs
>  ├── dbi
>  │   ├── __init__.py
>  │   ├── dbi.py
>  │   └── regos.py
>  └── __init__.py  --   *empty*
>
>
> the __init__.py file under 'rcs' is empty.
> The one under rcs.dbi contains:
>
>  from dbi import *
>  from regos import *
>
>
> With python2, I'd go:
>
>  import rcs.dbi
>
> then I'd have access to stuff in regos.py
> as:
>
>  rcs.dbi.feature()  (Where 'feature' is defined in regos.py)
>
>
> When I do the same import with python3, I get:
>
>  Traceback (most recent call last):
>File "/home/toby/me", line 1, in 
>  import rcs.dbi
>File "/usr/regos-1.0/lib/python/rcs/dbi/__init__.py", line 1, in
> 
>  from dbi import *
>  ModuleNotFoundError: No module named 'dbi'
>
>
> What's changed, and how do I fix it?
>
>
> Thanks!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list