Convert MATLAB Codes into Python - Python Help - Discussions on Python.org
Convert MATLAB Codes into Python Python Help Kareem (Kareem) September 30, 2023, 7:32am 1 Is there a way to batch convert a folder of MATLAB files into Python files? ajoino (Jacob Nilsson) September 30, 2023, 8:21am 2 Moving this from ideas to help, as it seems more like asking for help than ideas for improving Python. kknechtel (Karl Knechtel) September 30, 2023, 8:35am 3 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 . JamesParrott (James Parrott) September 30, 2023, 1:38pm 4 Be aware of the issues mentioned in this guide: NumPy for MATLAB users — NumPy v1.26 Manual Good luck, if you try this: GitHub - victorlei/smop: Small Matlab to Python compiler or another idea from this answer A tool to convert MATLAB code to Python - Stack Overflow hansgeunsmeyer (Hans Geuns-Meyer) September 30, 2023, 1:58pm 5 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) ) (followed up by Sly ) Kareem (Kareem) October 1, 2023, 10:06am 6 Thanks @kknechtel Karl. I mean by convert to mainly convert MATLAB codes. kknechtel (Karl Knechtel) October 1, 2023, 10:12am 7 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.
DaveR (david) April 21, 2025, 5:37pm 9 Isn’t this exactly what a complier does (i.e. C to assembly)? onePythonUser (Paul) April 25, 2025, 10:43pm 10 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.