executing programs with different languages - python

Am doing my project in raspberry pi. I have written programs in python and also in node.js . I want to run these programs depending upon some conditions. And all these things should be done just by clicking in a single executable file. Can anyone help me out citing how it can be done? Can Shell Scripting satisfy my need?

If you can determine that some conditions from shell script, then shell scripting can satisfy your need. That depends on what will be the condition.
As an alternative solution you can write another short program in node.js or python that will do the job.

Related

Does each IDE needs its own Python?

I have PyCharm, Visual Studio Code and Jupyter Lab installed on my PC, and the PC has Python 3.11 installed?
Would someone please educate me on this topic?
If I want run 3 Python programs simultaneously (each program uses its own IDE). Would each IDE run faster if each IDE has its own Python program? Right now all IDEs are using the same Python 3.11 and things are working fine. Just for my own knowledge, I am just curious of this topic. Thank you in advance for educating me!
You have to discriminate the two following concepts: program and process.
Program
A program is a list of instructions. It's generally written on a file.
It can be a binary text but also an ASCII text.
A program does nothing. It is basically a static text.
Process
A process is the execution of a program by your operating system.
A process has a dedicated memory and execution time. Its role is to "play" your code, instruction by instruction.
In your example, python.exe is a program.
When you execute it, your operating system will create a dedicated process.
So, when you run several IDEs, you simply run several process of your same program.
Thus, there is absolutely no loss in terms of performance.

Does a "terminal" always need to run with python

Hi im a bit new to python but i want to learn more my question is when you build a web application and you are going to use python to do the data handling and calculations does this mean in order for that to be used a terminal,in this case lets say on windows will have to run and that basically listens if and when something was triggered or executed on the python program/script
This article summarizes how different types of Python run. By default, on many systems, CPython is present. When it interprets py files initially, it may create pyc files, which can then run on the CPython virtual machine, described here. The virtual machine and interpreter are also running when you run python on your terminal, if you are using this. As described in the first article however, CPython isn't the only way to run Python.

Run python script with custom unix command? [duplicate]

To be clear, not just "run python scripts"
But to make my python script a "executable" or "callable" program
that can be used in other programming languages or platforms.
More like a API maybe.
The thing is I implemented several algorithms in java and
they're supported by numpy and spipy, but others want to
call my python program in their java program.
Then the numpy and spipy are problems. They can't be in java and
jython...
Is there a solution that I can make this an executable program that others don't need the environment but just to run the program with several parameters accepted?
If you just need to make the python programs executable, then you can add a line to the top like this:
#!/usr/bin/python
Replace /usr/bin/python with the filepath to python, which can be obtained by typing
which python
into the terminal, assuming you're using a unix-based system.
You can then tell the operating system that the program is executable with
chmod +x nameofprogram
If the java programs require something more complicated than just being able to run the python parts as executables, then you'll probably need to provide more information for anyone to be able to help you.

How can I make my program utilize tab completion?

I've noticed that some programs (e.g. hg) allow the user to tab-complete specific parts of the command. For example, if, in an hg repository working directory, I type:
hg qpush --move b8<TAB>
It will try to complete the command with any mercurial patches in my patch queue that start with "b8".
What I'd like to do is imitate this behavior in my program. That is, I have a series of commands that depend on files within a certain directory, and I'd like to be able to provide tab completion in the shell. Is there an API for providing this on Ubuntu Linux (preferably using python, as that's what my script is written in)?
To do this, you need to write tab-completion modules for your shell. The default shell in most Linux distributions is bash, so you should write a completion script (typically a shell script). Once you've written your script, add it to /etc/bash_completion.d/. This should be distributed with your program (for Linux distributions, included in the package).
Debian Administration has a guide for writing your completion scripts. For using completion on a Mac, see https://trac.macports.org/wiki/howto/bash-completion.
For examples of completion files, take a look at the bash-completion project from Debian (also on Github). See also https://unix.stackexchange.com/questions/4738/an-easy-bash-completion-tutorial.
If you use zsh, hack.augusto linked to the documentation for writing completions.
This is what the readline module is for.
Actually, readline is a common C library so it has bindings in many languages. And I can say, I've had tons of fun with it.
Enjoy B)
You might want to try the zsh shell, it has a great completion system with support for tons of applications.
The completion system is written with the shell language, but if you really want to use python you can run the interpreter from inside your completion function. The down side it that if you want to write completion for your own software, you will need to do some reading (user manual and the manpage for instance).
Take a look at the source of the 'cmd' module in the Python library. It supports command completion.

python programming query

I'm new to Python programming.
My question is where to write python programs in linux--
in terminal or
any writing pad like gedit etc
Should we write one program again and again for running or we should call the program and run it.
After you install Python (it's installed by default on most Linux-es), you have two options:
Terminal. Just type python <ENTER> and you will be taken to the Python interpreter interactive prompt. For anything but the most basic stuff, however, you may want to intall IPython - an alternative interactive prompt that's much better than the default one.
In a file. Save your code into a .py file and run it with python myfile.py
But first and foremost, start by learning Python - the official tutorial is a great place to start. Among other useful information, its chapter 2 discusses how to use the Python interpreter for beginners.
Stackoverflow also has a lot of great resources for learning Python. This question, for example, and many others.
If you are learning, or you are evaluating expressions, you could run Python in terminal, or use IDLE.
But if you are writing large chunks of code, then you should consider using an IDE.
You could either use Geany, or use Eclipse with PyDev. I prefer Eclipse myself.
For running, you can run it using the command python program.py, or just add the line
#!/bin/python
to the beginning of your program, grant it execution permission using chmod, and run it with ./program.py command.

Categories

Resources