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.
Related
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.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I never went too far into NetLogo, and being a novice in Python I started looking into the turtle module, aiming towards ABM. I have seen some simple implementations of the turtle module (turtledemo and YouTube) but none were comparable to NetLogo library's examples. I went over (once) the mesa tutorials and it seemed interesting but, as it says, more advanced stuff require Javascript. I've also read that NetLogo is fast to pick up.
Considering the above, and adding your own experience, could NetLogo be a better choice than Python? Could you estimate how hard each path would be? Do you have any other suggestions?
I teach ABM. I used to use Python for my course,
using a module that provides some NetLogo-like functionality:
https://raw.githubusercontent.com/alan-isaac/econpy/master/abm/gridworld/gridworld.py
I gave that up. Although Python is a great language for
teaching programming, NetLogo is a much better language for
teaching ABM. (Both started out as teaching languages,
very roughly speaking, and became much more.) It is very
easy to get started with NetLogo. It's builtin facilities
also support very sophisticated model building. These facilities
can be extended when needed.
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.
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 8 years ago.
Improve this question
Since Python itself is written in C, is it theoretically possible to "decompile" any Python program into C, for whatever reason? Not translate, (which would be taking the semantics of the program and writing another program in C that does the same thing) but truly decompile (use a program to find the appropriate C functions for each Python operation and implement them in a syntactically correct manner).
Any programming language can theoretically be translated to any other programming language. This theoretical possibility says nothing about how easy it is, or about whether any existing tools allow you to do it.
It's also ambiguous what counts as "decompiling". For example, I can use boost::python and embed a python program as a string in a C++ program. Now I have a C++ program completely equivalent to that python code. That hardly counts as a proper translation, though.
There are some things no translater will be able to do (well):
if ask_user():
a = 1
else:
a = "hi"
print(a)
Because of the compile-time type ambiguity, any equivalent c program will have to have some elaborate data structures with run-time type information.
Yes. Of course you could translate python to c. Parts of what the interpreter does would end up being in your c program. If you restrict your python to RPython it gets a lot easier. As some things in full python don't translate well. Mostly I don't see much point though.
Check out https://code.google.com/p/py2c/ to convert python to c.
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.