Firstly, I have very limited experience with programming. So please bear with me.
I am using a custom software, called deformcyto, made for my lab which can only be started via anaconda prompt. I need to call the same program multiple times but with different inputs. Can I write a python script which would keep calling the program with new arguments?
Thanks for any pointers!
You can try something like this, if your program is an executable.
os.system(r"C:\youdir\..\yourprogram.exe")
You can also write a bash script or a powershell script and start the program multiple times with different arguments.
Related
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.
I have a program (let's say program.exe) that can be executed on a command line. After being executed, it asks for some inputs, runs for a while, and gives some outputs. I need to write a python script that interacts with this program so that it can continuously send/receive inputs/outputs.
I have tried the libraries subprocess and Pexpect, but so far I have not managed to implement this functionality. If anyone knows how to do this I would appreciate a working example so I can adapt it.
Thank you very much for your help!
Receive inputs:
to grab some returned values from shell scripts you can use the argument standard input like argv and argc
to invoke cmd command:
Use the system.os and usit as os("<your shell command>")
I'm trying to learn FreeCAD python scripting. Basically I open the python console and do what I want to do in the GUI and then look into the python console to learn the commands. and then read the API for that specific task to learn the correct form of python commands.
Things were going fine till I got stuck in this weird issue where the program (I.E FreeCAD) does not execute parts of my code. For example in this macro I create three boxes and then fuse two toghther, and it works just fine. But in this one I create 3 boxes, fuse two of them together, and then try to cut the fusion out of the bigger box. and it doesn't work. I even tried including some flags using print("flag"), but it does not execute these commands. If I copy and past the exact commands into the python consol and run it works fine!
so my speculations are:
FreeCAD does something in the GUI which does not report in the python console.
FreeCAD python interpreter does not execute some commands such as print("")
there is something in FreeCAD API which I'm not using correctly
I would appreciate if you could help me know:
if this is a bug in FreeCAD/python or it is intentional
how can I solve the issue so the FreeCAD python interpreter runs my macro/script as I expect?
P.S. I posted the exact same question here in FreeCAD forum.
OK, I figured the problem out. you may see the correct macro here in this Github Gist
explanation: Basically the solution is that when we want to run a Boolean operation on two existing objects we should not change their visibility to false (as the default GUI commands do). If we include those commands then none of the commands after them will be executed.
I'm making a drawing program with python and pygame. I am trying to incorporate a script-fu thing in which the program opens a python live interpreter upon startup and allows the user to execute commands in the interpreter alongside the graphical interface.
My current strategy is to run the main loop inside its own thread, then have the application opened using a bash script that does 'python -i main.py'
Is this a safe/effective/ideal way of doing this? How can I use locks to ensure that commands coming in from the interpreter are executed between main loop iterations?
This is my first time using threads, so please explain to me like I am 7.
Thanks :)
The interpreter won't cooperate with locks you set (since it doesn't know about them). Thus, you cannot guarantee when the code entered by the user will execute.
Consider using the code module to build your own interactive console (it's really easy!). Then you can do the locking every time you go to execute user input.
Why are you using a third party live interpreter? Do you realize that pygame comes with one built in? The documentation is here. This will eliminate all of your problems quite easily.
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.