# Convert MATLAB Codes into Python

**URL:** <https://discuss.python.org/t/convert-matlab-codes-into-python/35010>\
**Category:** Python Help\
**Created:** [September 30, 2023, 7:32am UTC](https://discuss.python.org/t/convert-matlab-codes-into-python/35010 "2023-09-30T07:32:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kareem](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@Kareem](https://discuss.python.org/u/Kareem)\
**Post date:** [September 30, 2023, 7:32am UTC](https://discuss.python.org/t/convert-matlab-codes-into-python/35010/1 "2023-09-30T07:32:18Z")

</div>

Is there a way to batch convert a folder of MATLAB files into Python files?

---

<div class="post-metadata">

**Author:** ![ajoino](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ajoino/32/6907_2.png) [@ajoino](https://discuss.python.org/u/ajoino)\
**Post date:** [September 30, 2023, 8:21am UTC](https://discuss.python.org/t/convert-matlab-codes-into-python/35010/2 "2023-09-30T08:21:51Z")

</div>

Moving this from ideas to help, as it seems more like asking for help than ideas for improving Python.

---

<div class="post-metadata">

**Author:** ![kknechtel](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kknechtel](https://discuss.python.org/u/kknechtel)\
**Post date:** [September 30, 2023, 8:35am UTC](https://discuss.python.org/t/convert-matlab-codes-into-python/35010/3 "2023-09-30T08:35:32Z")

</div>

What do you mean by “convert”? What should happen when you do this? By “matlab file”, do you mean code, data or something else?

No, you cannot expect the computer to convert from code written in one programming language to another. If that were possible for a machine, and if the result were of any value, _one of those two programming languages would not exist_.

---

<div class="post-metadata">

**Author:** ![JamesParrott](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamesparrott/32/10534_2.png) [@JamesParrott](https://discuss.python.org/u/JamesParrott)\
**Post date:** [September 30, 2023, 1:38pm UTC](https://discuss.python.org/t/convert-matlab-codes-into-python/35010/4 "2023-09-30T13:38:27Z")

</div>

Be aware of the issues mentioned in this guide: [NumPy for MATLAB users — NumPy v1.26 Manual](https://numpy.org/doc/stable/user/numpy-for-matlab-users.html)

Good luck, if you try this: [GitHub - victorlei/smop: Small Matlab to Python compiler](https://github.com/victorlei/smop) or another idea from this answer [A tool to convert MATLAB code to Python - Stack Overflow](https://stackoverflow.com/a/17535694)

---

<div class="post-metadata">

**Author:** ![hansgeunsmeyer](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/hansgeunsmeyer/32/15188_2.png) [@hansgeunsmeyer](https://discuss.python.org/u/hansgeunsmeyer)\
**Post date:** [September 30, 2023, 1:58pm UTC](https://discuss.python.org/t/convert-matlab-codes-into-python/35010/5 "2023-09-30T13:58:09Z")

</div>

> [@JamesParrott](#):
>
> Good luck, if you try this: [GitHub - victorlei/smop: Small Matlab to Python compiler](https://github.com/victorlei/smop) or another idea from t

Interesting project - I took a very quick look and saw that a main underlying library is `ply`, a Lex/Yacc implementation in Python by David Beazley. It’s a a really nice compiler-creation library in pure Python.  
([PLY (Python Lex-Yacc)](http://www.dabeaz.com/ply/)) (followed up by [Sly](https://github.com/dabeaz/sly))

---

<div class="post-metadata">

**Author:** ![Kareem](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@Kareem](https://discuss.python.org/u/Kareem)\
**Post date:** [October 1, 2023, 10:06am UTC](https://discuss.python.org/t/convert-matlab-codes-into-python/35010/6 "2023-10-01T10:06:26Z")

</div>

Thanks @kknechtel Karl. I mean by convert to mainly convert MATLAB codes.

---

<div class="post-metadata">

**Author:** ![kknechtel](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kknechtel](https://discuss.python.org/u/kknechtel)\
**Post date:** [October 1, 2023, 10:12am UTC](https://discuss.python.org/t/convert-matlab-codes-into-python/35010/7 "2023-10-01T10:12:04Z")

</div>

That doesn’t even remotely answer the question. It simply tells me again the one thing I already understood, and ignores everything I was asking about.

---

<div class="post-metadata">

**Author:** ![DaveR](https://avatars.discourse-cdn.com/v4/letter/d/ccd318/32.png) [@DaveR](https://discuss.python.org/u/DaveR)\
**Post date:** [April 21, 2025, 5:37pm UTC](https://discuss.python.org/t/convert-matlab-codes-into-python/35010/9 "2025-04-21T17:37:52Z")

</div>

Isn’t this exactly what a complier does (i.e. C to assembly)?

---

<div class="post-metadata">

**Author:** ![onePythonUser](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/onepythonuser/32/19158_2.png) [@onePythonUser](https://discuss.python.org/u/onePythonUser)\
**Post date:** [April 25, 2025, 10:43pm UTC](https://discuss.python.org/t/convert-matlab-codes-into-python/35010/10 "2025-04-25T22:43:43Z")

</div>

Yes, `C` is converted to `assembly` by the compiler as you stated (this is how you then get `HEX` files). But `C` to `assembly` conversion is one step in a needed process of converting a high-level English language program to machine useable code (usually you can get the assembly code by selecting the `Dissasembly` option in an `IDE`). But this comparison does not directly apply to what the `OP` was asking (`MATLAB` to `Python`).

First note that `assembly` (instruction set) tends to be manufacturer specific (though the general idea holds). If you reference programming manuals for different manufactures for their respected microcontroller product lines, and compare them, you’ll see that there exists slight differences in their naming conventions for many instructions. That is, `assembly` may vary from one `mfg.` to another and thus is not a general language per se (`Python` does not vary from user to user). It is generally tied to actual hardware (i.e., a particular `mfg.` and microcontroller family).

So, yes, `C` is converted to `assembly`, but with some nuances.
