I don't have a lot of experience coding so I'm sorry if this has been answered before; I couldn't find anything that helped.
I just completed a project on a Raspberry Pi that runs some RGB LED strips via PWM. I have a program that runs the lights and works fine with a few different modes (rainbow shifting, strobe, solid color) but with each new mode I add the program get longer and more convoluted. I would like to have each separate mode be its own script that gets started or stopped by a sort of master script. That way I could easily add a new mode by simply writing a separate program and adding it to the list on the master script instead of mucking around inside a giant program with everything in it and hoping I don't break something. I guess what I want is a simple way to start a python script with some specific setting (Determined by variables passed from the master script) and be able to kill that script when the master script receives the command to change modes.
Keeping your code modulable is indeed a good practice ! If your code is not Objet oriented, the best way is to create another python file (let's call it util.py) in the same directory as your "main". You can simply include util.py with the following command at the beginning of your main code :
import util
And then when you want to use a function that you've defined in your util.py file, juste use :
util.myFunction(param1, param2,...)
Related
I have created a program using python which moves goes through each file in my downloads directory, and moves that file to another directory based on the suffix at the end of the file (.mp3, .mp4, .txt, .jpg, ...). How would I go about automating this program so that it runs in the background of my computer every couple of hours?
What you are referring to is often called a "cronjob". Python has a module called python-crontab that can do this type of thing. Here is a tutorial to help you get started.
I do not know much about python, but in nodejs, there is a tool called cronjob. When you set routine, according to the time that you set, it calls scripts. Maybe there is an equivalent version in python.
I am looking for a solution to run a process with input files in python:
in my script I call a process using sub-process:
import subprocess as sp
sp.call(['C:\EnergyPlusV8-8-0\EP-Launch.exe'])
So the program I would like to launch is open, but then I need to choose 2 input files and then press the button "Simulate.." to execute the program(Energy Plus).
***comment:
I mean, after those code lines, the interface of the program(Energy Plus) is open, then I choose in that window which input files the program has to use. After that in the same interface of the program I start the simulation. I want to do these steps just in the python code, without interacte with the EnergyPlus interface. I hope I clearify the ambiguities
I would like to do the last steps automatically(knowing the input files location) in the python code.
How can I do this?
You won't be able to do this unless EnergyPlus is providing some kind of API, or you are prepared to write UI manipulation code, which would really depend on the type of application it is. Without more information I'm going to have to say what you want to do is not possible.
Searching isn't pulling up anything useful so perhaps my verbiage is wrong.
I have a python application that I didn't write that takes user input and performs tasks based on the input. The other script I did write watches the serial traffic for a specific match condition. Both scripts run in different windows. What I want to do is if I get a match condition from my script output a command to the other script. Is there a way to do this with python? I am working in windows and want to send the output to a different window.
Since you can start the script within your script, you can just follow the instructions in this link: Read from the terminal in Python
old answer:
I assume you can modify the code in the application you didn't write. If so, you can tell the code to "print" what it's putting on the window to a file, and your other code could constantly monitor that file.
I need to trace program execution, so I decided to make infinite loop, and read pc register and make step.
Platform: IOS
In such way I want to trace program's execution flow.
Question is - how should i get $pc register through LLDB python API?
Your program will likely have more than one thread, and each thread will have a different PC. So you would start with your SBProcess object, then it has a "threads" property for iterating over threads - represented by the SBThread object. The SBThread has a "frames" property which is an array of all the "SBFrames", and frames[0] is the bottom-most frame. The SBFrame has "pc" property which is the pc. This table of the Python SB API's might help you out:
LLDB Python APIs
However, what you are trying to do won't work under Xcode - which is generally the only way to do debugging on iOS. Xcode and Python currently fight over who gets to control process execution, and at some point the wrong actor wins and execution stalls.
You can do this sort of thing using a stand-alone Python driver, an example of which is:
Process Events Example
But since you can't really attach to an iOS process from stand-alone lldb, this is hard to use for iOS development.
BTW, I've occasionally done what you are describing on Mac OS X, and it is also really really slow. You would only want to do this when you are desperate.
You can sometimes get the same effect by putting breakpoints on every function entry point, which you can do on the lldb command line using:
(lldb) break set -r .
and if you only care about tracing through some given modules, you can add the --shlib option one or more times to the "break set" line to restrict the breakpoints to those libraries. Then write a breakpoint command (which you can do in Python) to gather the requisite information. This will still be slow, but is closer to useable.
I am working in Windows, and just learning to use python (python 2.7).
I have a bunch of script files ("file1.script", "file2.script", "file3.script"....) that are executed in TheProgram.exe. Python has already given me the ability to automatically create these script files, but now I want to successively run each of these script files, back-to-back, in TheProgram.exe.
So far I have figured out how to use the subprocess module in python to start "TheProgram.exe" in a new process (child process?) and load the first script file as follows:
my_process = subprocess.Popen(["Path to TheProgram.exe", "Path to File1.script"])
As seen, simply "opening" the script file in TheProgram.exe, or passing it as an argument in this case, will execute it. Once File1.script is done, TheProgram.exe generates an output file, and then just sits there. It does not terminate. This is I want, because now I would like to load File2.script in the same process without terminating (file2.script is dependent on file1.script completing successfully), then File3.script etc.
Is this possible? And if so how? I cannot seem to find any documentation or anyone else who has had this problem. If I can provide other information please let me know, I am also new to posting to these forums. Thanks so much for any assistance.