Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm started programming not too long ago. I use a little of Python, Lua, and Ruby. Is it possible to compile all three scripts into one executable using py2exe, py2app, or py2deb?
If not, which one should I use for game development, and if anyone has any type of resources to study off of, I really would mind learning more.
Combining them all into one executable is hard. Combining them into one application, not so hard.
Let's take py2app as an example. It builds an OS X application bundle—a directory full of files. There's a complete Python interpreter with a custom standard library in the Frameworks subdirectory. And your application's Python source code (and/or .pyc bytecode) and all of your data files are in the Resources subdirectory. Finally, in the MacOS subdirectory, there are two things: a standard python stub executable, which runs Python with your custom standard library, and another stub executable with the name of your app, which runs Python with your custom standard library and executes your main script.
Imagine you had an identical tool for Ruby and Lua.
You could very easily build an application bundle that puts each framework in the Frameworks directory, puts all your source code in all three languages, and all of your data files, into the Resources directory, and puts all three stub executables in the MacOS directory. Whichever one of your scripts is the main program, you'd keep just the stub executable for that one.
As long as your scripts know how to find the python, lua, and ruby stub executables to launch other scripts (which you can do by, e.g., modifying the PATH in the environment at the start of your main script), everything works.
And there's an even simpler solution: py2app (and ruby2app and lua2app) up each application separately, and then just package the complete applications inside the bundle (e.g., in an Applications directory under the Library directory) and just run them that way. The down side is that if you have 20 different Python scripts, you're going to end up with 20 complete Python installations, which gets to be a pretty big download.
But you can go half-way in between: merge all the Python apps into one bundle, all the Ruby apps into another, and all the Lua apps into another.
The problem with doing this in practice are that you don't actually have an identical tool for Ruby and Lua; you have different tools, which build different structures. And you don't have an identical tool for Windows (py2exe builds a very differently-shaped structure, and uses very different configuration settings). So you need to understand (up to) the cartesian product of N*M different structures if you have N languages and M platforms.
And you really do need all the separate tools. py2app can't be used on Ruby or Lua code, or Windows code, because it needs to understand Python modules—including Python C extension modules, which it has to understand at the Mach-O level as well as at the Python API level—in order to figure out the dependencies and get the right files, and figure out the right places to put them in the bundle so the interpreter can find them, and so on.
Still, it's definitely doable—I've worked on two projects that bundled up multiple scripts written in two or three different scripting languages in exactly the way I described above.
No. It might be possible to use the JVM versions of the languages to create JVM classes, then JAR them up. I have never used any of them besides jRuby.
Why use three similar scripting languages at the same time? It's like eating pasta with mashed potatoes and bread.
Related
I need to integrate a body of Python code into an existing OSGi (Apache Felix) deployment.
I assume, or at least hope, that packages exist to help with this effort.
If it helps, the Python code is still relatively new and small, so can probably re re-architected to meet whatever constraints are needed. However, it must remain in Python, because of dependencies on third-party libraries.
What are suggested best practices?
The trick is to make this an extender, see 1 and 2. You want your Python code to be separate from the code that handles the interaction with the interpreter. So what you do is wrap the Python code and any native libraries in a bundle. This is trivial since it is just a zip file.
You then develop a bundle that listens to starting bundle (see the BundleTracker) that have python code. A manifest is often used but you can also look in a directory in the JAR. If you detect this code, you extract any native libraries and run the code in the interpeter of your choice.
If can use JYthon then that would be highly recommended. You can then carry the interpreter as an OSGi bundle that runs on the VM. If you need to use a native compiler your life is less rosy. You can rely on the environment to provide you with an interpreter but then why use OSGi in the first place. You basically lose the write once run anywhere advantage. You could go the full monty by creating bundles that contain Python installers for all platforms you support. Can be done, not even that hard, but a maintenance nightmare. Believe me, native code suck, it only does it a bit faster than Java.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Anyone has any python simulator to recommend? am new to python programming. is there any program similar to codeblocks for C++ programming? Thanks
I think you might be slightly confused over terminology.
The term "simulator" doesn't really mean much in the context of programming. A simulator is something which pretends to be some other platform so you can test code on it. For example, I might use an Android simulator or a Gameboy simulator on my computer so I can test code without having to transfer it all the time.
You might mean "IDE" instead. Codeblocks is an example of an IDE. It stands for "Integrated Development System". It combines a "compiler" (something which turns what you write into executable code) and a specialized "text editor" (a program which lets you write text). It also includes a wide variety of convenient features to make programming in C++ more easy.
Note that you technically don't need an IDE to write code. An IDE combines a compiler (or an interpreter, in the case of Python) with a text editor, and a bunch of extra features for convenience, but this is by no means "necessary", strictly speaking. All you need in order to write code is a text editor of some sort, and a compiler or interpreter.
For example, I typically use either Notepad++ or Vim to write my Python code, and run it directly from the command line.
Regardless, Python has a wide variety of IDEs you can look at. Here is a comparison of the most popular ones.
However, you don't necessarily need a fancy IDE to program in Python! If you just directly install Python, it comes with a simple IDE called "IDLE" which you can use to write and run Python code. If you're new to Python, I recommend you use IDLE for now, until you get the hang of things.
tl;dr
To summarize:
A simulator is a program that pretends to be some other kind of computer/platform. Simulators are used to test code.
An IDE stands for "Integrated Development System" and is used to write and run code.
It combines a compiler or interpreter with a text editor.
There are many IDES for Python. Here is a list.
However, I recommend you use IDLE, which is included by default when you install Python.
Codeblocks does have a plugin for Python: http://wiki.codeblocks.org/index.php?title=Python_plugin . Though, I am not sure, how popular that is!
There was a similar discussion on SO: What IDE to use for Python?
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
What exactly is the sole purpose of python being an interpreter.
It doesn't provide executable files (how a commercial software developer use it?)
If any part of the code had bugs, it doesn't show up unless python
goes to that line at run it. In large projects, all parts of code
doesn't get interpreted every time, so, there would be a lot of
hidden bugs inside project
Every system should have a python installed in it to run those software's...
I am using py2exe, and I find myself puzzled to just look at the executable file size (too large).
First, answers to your questions.
They can use it for parts of their system for which they don't mind the source being visible (e.g. extensions) or they can Open Source their application. They can also use it to develop backend services for something which they're providing as a service (e.g. Youtube). They can also use it for internal tools which they don't plan to release(e.g. with Google).
That's why you need to write tests, exercise discipline and measure test coverage regularly. You sacrifice the compilers ability to check for things and some speed for advantages which I've detailed below.
Yes but it's not too hard to bundle Python along with your app. The entire interpreter + libraries is not that big. Python is pretty much a standard on most UNIX environments today. This is usually not a practical problem. The same issue is there with (say) Java (you need the JVM installed).
py2exe bundles all the modules into a single executable. It will be big. If you want to do compiled programs that are lean, don't use Python. Wrong fit.
Now, a few reasons on why "interpreted".
Faster development time. Programmer time is costlier than computer time so we should optimise for that.
No compilation cycle. Very easy to make incremental changes and check. Quick turnaround.
Introspection and dynamic typing allows certain kinds of coding not possible with some compiled languages like C.
Cross platform. If you have an interpreter for your platform, the program will run there even if it was written on a different platform.
You bring up a few different issues, here are some responses:
1) Technically, Python isn't interpreted (usually) - it is compiled to bytecode and that bytecode is run on a virtual machine.
So Python doesn't provide executables because it runs bytecode, not machine code.
You could just as well ask why Java doesn't produce executables.
The standard advantages of virtual machines apply: A big one being a simplified cross-platform development experience.
You could distribute just the .pyc (compiled bytecode) files if you don't want your source to be available. See this reference.
2) Here, you are talking about dynamic vs. static languages. There are tradeoffs, of course. One disadvantage of dynamic languages, as you mention, is that you get more run-time errors rather than compile-time errors.
There are, of course, corresponding advantages. I'll point you to some resources discussing both sides:
Dynamic type languages versus static type languages
What do people find so appealing about dynamic languages?
http://research.microsoft.com/en-us/um/people/emeijer/Papers/RDL04Meijer.pdf
3) Quite right. Just as you need the Java VM installed to run Java, perl to run Perl, etc.
Regarding your last point:
The whole idea of running in a VM is that you can install that VM once, then run many different apps. By bundlig the whole VM with every app (such as with py2exe), you are going against that concept. So yes, you have to pay the cost in terms of size.
Sole purpose of python is to provide a beautiful language to program in.
Your point #1 and #3 are similar and answer is that professional programmers use py2exe/pyinstaller etc to bundle their programs and distribute, in cases of frameworks/libraries they even don't need to do that.
Your point number #2 is also valid for statically compiled languages, something compiles correctly in C++ doesn't mean it will not crash at run-time or business logic is correct, you anyway need to test each part of your code, so with good unittests and functional tests python is at par with other languages in finding bugs, and as it doesn't need to be comiled and being dynamic means better productivity.
IMO
Python is not an interpreter, but an interpreted language.
This question is more about interpreted language VS compiled languages which has actually no other answer that the usual "it depends of your need".
See Noufal Ibrahim for details, but I'm not sure this question is a good fit for SO.
(1) You can provide installers for Python code (which may install the Python environment). This doesn't prevent you from having commercial code. Note that you can also have Java (also "interpreted" or JIT-compiled) commercial or desktop code and require your users to install a JRE.
(2) Any language, even compiled and strongly type, may produce errors that only show up when you get to that given code (e.g. division by zero). I guess you may be referring to strongly v.s. loosely typed languages. It's not just a matter of compilation, but the fact that strongly-typed languages generally make it easier to find "structural" bugs (e.g. trying to use a string as a number) during the compilation process. In contrast, loosely-typed language often lead to shorter code, which may be easier to manage. What to use really depends on the goal of your application.
Interactivity is good. I find it encourages making small, easily testable functions that build together to make an application.
Unless you are writing simple, statically linked applications, you will usually have some run-time baggage that must be included or installed (mfc, dot net, etc.) for compiled languages. Look at the winsxs folder. Sure, you get to "share" that stuff most of the time, but there is still a lot of space taken up by "needed", if hidden, requirements.
And as far as bugs, run-time bugs will be the same no matter what. Any good programmer would test as much as possible when making changes. This should catch what would be compile time bugs in other languages as well as testing run-time behavior.
A python .exe has to necessarily include a complete copy of the python interpreter. As you say, since it's interpreted it won't touch every line of code until that line is actually run. Some parts may actually invoke a python parse/compile sequence (e.g. eval(), some regexes, etc...). These would fail in a compiled .exe unless the full interpreter was available.
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 9 years ago.
Improve this question
I am looking for a good scripting language to link to my program.
I am looking for 2 important attributes:
Scripting language should be hard linked into the executable (not requiring 3rd party
installations). This is important to me to simplify distribution.
Scripting should allow some run-time debugging option (When running a script inside my program I would like to easily run it inside a debugger while it is running in the context of my program)
Can python,lua or some other language supply me with this?
Both Lua and Python can provide the features you mention, so choosing one of them will depend on other criteria.
Lua is a lighter weight solution, it will have a much smaller disk footprint and likely a smaller memory overhead than Python too. For some uses it may be faster. Python has a much richer standard library, more mature third party libraries and a more expressive language.
Both have been embedded into major applications. Python can be found in Blender, OpenOffice and Civilization 4. Lua can be found in World of Warcraft and Adobe Lightroom. I'd recommend looking at a few tutorials for each and the facilities available to embed them in your application and just choose the one that fits your brain best.
Lua is designed for this:
static linking? check!
debugging? check!
Typically, Lua is the better choice for embedding into another project. Python is better as a standalone platform because the library support is so much broader. See Lua Versus Python for more details.
Personally, I use both very frequently depending on the job at hand. I always use Lua for embedding into C/C++ applications or scripting functionality that is imported from C/C++ shared libraries (i.e. a DLL). Python is always my first choice for standalone tasks that do not require low-level C/C++ code.
I'd put my two cents in for python. I don't know a lot of the details, but the computer graphics suite blender does a wonderful job of implementing python scripting.
As far as I can tell in blender 2.5 the interpreter is run from inside the executable,
import sys
sys.executable
shows /blender/blender.exe
and there is good debugging support, it even has a full interactive interpreter inside.
For more info check out: http://www.blender.org/
I really like Lua for embedding, but just as another alternative, JavaScript is easily embeddable in C, C++ (SpiderMonkey and V8) and Java (Rhino) programs.
In addition to Tcl, Lua, and Javascript (all already mentioned), Guile is another language designed explicitly for this.
I'll add Tcl to the mix. It's designed to be easily embedded into other programs.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
A specific example: becoming familiar with django's project source code (core, contrib, utils, etc.). Example of a useful tool: ctags - it allows you to "jump" to the file+location where a function/method is defined. Wondering about other tools that developers use (example: is there a tool that given a function x(), lists the functions that call x() and that are called by x()?). Thanks.
Edit: added an answer with an aggregate of tools mentioned so far in other answers
The following is an aggregate of tools mentioned in other answers...
cscope
http://cscope.sourceforge.net/
wikipedia entry: http://en.wikipedia.org/wiki/Cscope
cscope is a console mode or text-based graphical interface ... It is often used on very large projects to find source code, functions, declarations, definitions and regular expressions given a text string.
pycscope
http://pypi.python.org/pypi/pycscope/
generates a cscope index of Python source trees
ctags and exuberant ctags
http://ctags.sourceforge.net/
http://ctags.sourceforge.net/ctags.html
wikipedia entry: http://en.wikipedia.org/wiki/Ctags
Ctags is a program that generates an index (or tag) file of names found in source and header files of various programming languages. Depending on the language, functions, variables, class members, macros and so on may be indexed. These tags allow definitions to be quickly and easily located by a text editor or other utility.
Eclipse:
http://www.eclipse.org/
wikipedia entry: http://en.wikipedia.org/wiki/Eclipse_%28software%29
Eclipse is a multi-language software development platform comprising an IDE and a plug-in system to extend it. It is written primarily in Java and can be used to develop applications in Java and, by means of the various plug-ins, in other languages as well, including C, C++, COBOL, Python, Perl, PHP, and others.
PyDev
http://pydev.sourceforge.net/
"Pydev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE"
Komodo Edit
http://www.activestate.com/komodo_edit/
wikipedia entry: http://en.wikipedia.org/wiki/ActiveState_Komodo
Komodo Edit is a free text editor for dynamic programming languages introduced in January 2007. With the release of version 4.3, Komodo Edit is built on top of the Open Komodo project.
It was developed for programmers who need a multi-language editor with broad functionality, but not the features of an IDE, like debugging, DOM viewer, interactive shells, and source code control integration.
Prashanth's call graph (visualization) tool
http://blog.prashanthellina.com/2007/11/14/generating-call-graphs-for-understanding-and-refactoring-python-code/
Just thought I'd share a link to an interesting small fun script I've found long time ago, that draws a graph of function calls. It works only for simple cases, so "as is" it's more fun than useful.
rope/ropemacs
http://rope.sourceforge.net/ropemacs.html
Ropemacs is a plugin for performing python refactorings in emacs. It uses rope library and pymacs.
http://www.enigmacurry.com/2008/05/09/emacs-as-a-powerful-python-ide/
Wing IDE
http://www.wingware.com/
Wing IDE has goto-definition, find uses, a source browser, refactoring, and other code intelligence features that should help. Another good way to understand unfamiliar Python code is to set a breakpoint, run to it in the debugger, and then go up and down the stack. In Wing Professional you can also use the Debug Probe to interact with and try out things in the debug runtime state (it's a Python shell that runs in the context of the current debug stack frame).
You can maybe try cscope! Wikipedia says that
cscope is often used to search content within C or C++ files, but it can be used to search for content in other languages such as Java, Python, PHP and Perl.[citation needed]
And you can also dig in this project.
Many (or even most, I should say) IDE's help you in this by enabling you do go to variable and function definitions, often by just Ctrl+click, or showing you class overviews where you can see all methods and attributes a class has including those inherited, and letting you go to their definition, etc, etc, etc. I can't recommend such a tool highly enough, it's very time-saving for development.
I personally use WingIDE, which is excellent and has all these features, but you should also check out KomodoEdit and Eclipse+PyDev. There maybe more that I don't know of, and it's fully possible that vim and emacs have some sort of plugins for this.
I think Komodo Edit and PyDev allows you to jump to python function defs.
is there a tool that given a function x(), lists the functions that call x() and that are called by x()?
Just thought I'd share a link to an interesting small fun script I've found long time ago, that draws a graph of function calls. It works only for simple cases, so "as is" it's more fun than useful.
For normal Python development personally I use GNU Emacs with rope/ropemacs (found a video showing the features) and sometimes Eclipse with PyDev.
This is subjective so I think it should probably be a community wiki. That said, the best thing you can probably do to make browsing large projects is to be familiar with hotkeys provided in your favourite IDE. Using the keyboard to browse through large source code is much easier than manually scrolling through text, highlighting text and fumbling through an IDE with a mouse.
Document it as you go. Leave trails, improve the structure, and keep notes. By the time you've found you way around the enter codebase, you'll have a good map.
I like Eclipse and the PyDev plugin. This combination has been very useful to me.
You should notice that cscope targets only the UNIX, Linux OSs.