# Using standart Python modules

**URL:** <https://discourse.myhdl.org/t/using-standart-python-modules/337>\
**Category:** Support\
**Created:** [October 9, 2018, 3:18pm UTC](https://discourse.myhdl.org/t/using-standart-python-modules/337 "2018-10-09T15:18:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spindelsinn](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@spindelsinn](https://discourse.myhdl.org/u/spindelsinn)\
**Post date:** [October 9, 2018, 3:18pm UTC](https://discourse.myhdl.org/t/using-standart-python-modules/337/1 "2018-10-09T15:18:41Z")

</div>

Hello,  
I need to write a data filter and it would be perfect if I can use regular expression module for this.

I receive input data, than I should check it and mark as valid.  
I tried to write something like this, but it is wrong:

> from myhdl import \*  
> import re
> 
> def HelloWorld( Clock, valid\_data, input\_data):  
> check = bool()
> 
> ```
> def checker(s):
> return re.match("(^[a-z])", str(s), flags=0)
> 
> check = checker(input_data) 
> 
> @always(Clock.posedge)    
> def top():   
> if check :
> valid_data.next = input_data
> 
> ```
> 
> return top

Can I use “re.” module inside my code?

Thanks

---

<div class="post-metadata">

**Author:** ![josyb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.myhdl.org/josyb/32/5_2.png) [@josyb](https://discourse.myhdl.org/u/josyb)\
**Post date:** [October 10, 2018, 11:16am UTC](https://discourse.myhdl.org/t/using-standart-python-modules/337/2 "2018-10-10T11:16:20Z")

</div>

It depends; inside code used for simulation yes; inside code to be converted no.  
Your code sample is incomplete, but assuming that _input\_data_ is a Signal(intbv()[8:]), thus representing a single character you can rewrite your test as:

```python
    if input_data >= ord('a') and input_data <= ord('z'):
        valid_data.next = input_data

```

Of course this may get tedious for more complicated cases. In that case you may outsource the check to a function, but if it needs to convert this function would still have to use the above code style.

---

<div class="post-metadata">

**Author:** ![spindelsinn](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@spindelsinn](https://discourse.myhdl.org/u/spindelsinn)\
**Post date:** [October 10, 2018, 5:00pm UTC](https://discourse.myhdl.org/t/using-standart-python-modules/337/3 "2018-10-10T17:00:04Z")

</div>

Thank you very much!
