How to convert python code into a simple c haeder? [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
I'm Working on a program that takes in text from the user and then implements functionalities in the backend, kind of like an interpreter, I have the parser working amazingly in python but some of the backend capabilities I feel would do great on c. I have looked into CPython but I don't seem to understand how to do it if it's even possible at all. I'm just a beginner, if someone could guide that will be very helpful.

CPython is just an implementation of Python in the C programming language. If you want to incorporate C code, you can write extension modules documented here.
Check out this StackOverflow post as well.
Alternatively, write a C program, compile it, and then call it via the subprocess module documented here.

Related

How to connect between python code and c code [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I would like to know how can i connect between python file and c file.
I need to connect with them , so i can use functions from both files.
thanks for the help!
Basic stuff that changes across C and Python is data types. I used ctypes python module to achieve conversion. Once data types are converted/formatted properly for C, you may pass these as arguments to C functions. C apis can remain as it is and changes are required in py code.
Consider looking at https://docs.python.org/3/library/ctypes.html
I have an example code here: https://github.com/Vishwajith-K/snippets/tree/py-c/bitwisepy

How to create flowchart with python? Optional: Need to support most Code Languages [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I write course work and now I stops in a progrees of writing, I want to build application based on Python which can drow Flowcharts of any code(maybe not all but main languages is: Python, Pascal, c++).
On Python I know about Graphviz+Pyreverse, but this solution is only for Python code vizualization.
You already have a python solution.
For C++ use clang/llvm.
For pascal, first use a pascal → C translator, then hand it to clang.

how can I translate efficiently a Java code to python? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I would be greatfull if you could tell me how one can translate a code from Java to python.
Should one do it manually ? is there any tool to convert it automatically?
If you want to translate java code to python you have to translate it manually. Automatic conversion generally does not have the appropriate quality. It looks like there are some tools out e.g. java2python but the author states
The generated Python code is not guaranteed to run, nor is guaranteed to be syntactically valid Python.
Converting a library to another programming language is never an easy task.
If you simply want to use a java library in a application that you want to write in python you could give jython a try.

Is it possible to translate a clojure syntax into python syntax? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have been looking around but haven't found an example of this. I'd like to write out a few long/tedious python scripts using Clojure. Just because I happen to enjoy Clojure a bit more and they are not full on programs.
This site makes me think it is possible:
http://jkkramer.com/sudoku.html
For example if I have script.clj, I'd like to be able to convert it to script.py - not by hand of course.
Is it possible to do this? If so, what tool/library/script should I use? If its not possible not, why not?
[Edit] I edited this because the wording mistakenly gave the impression I was looking for a detailed lesson on writing my own solution. I was just curious if the tools were out there to answer my question and if not then why not.
Yes. Write a compiler that takes Clojure syntax and outputs valid Python syntax.
How to do that is well outside of the ability/scope of a StackOverflow answer.
Also note that if you do this for the general case of compiling any piece of Clojure code to Python you will have implemented quite a bit of Clojure in Python (especially when you implement defmacro and generic methods).
You actually don't have to do a source to source translation in order to write Clojure that will interact with python libraries. Just see clojure-py which allows you to write regular Clojure syntax and run it under the Python interpreter and call Python libraries.

parsing C code using python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a huge C file (~100k lines) which I need to be able to parse. Mainly I need to be able to get details about individual fields of every structure (like field name and type for every field in the structure) from its definition. Is there a good(open source, which i can use in my code) way to do this already? Or should I write my own parser for this. If I have to write my own, can anyone suggest a good place to start? I have never worked with python before.
Thanks
Take a look at this link for an extensive list of parsing tools available for Python. Specifically, for parsing c code, try the pycparser
The right way to do this is almost certainly to interface with the front-end of an existing compiler, such as gcc, then work with the intermediate representation, rather than attempting to create your own parser, in any language.
However, pycparser, as suggested by Dhara might well be a good substitute, and definitely better than any attempt to roll your own.

Categories

Resources