简体   繁体   中英

Change python script with command temporarily

So I have a script called controller.py that has commands that interface with a front end on a website. I am looking for a way that when a command is run, for example:

               if command == 'F':
                drivingSpeed = drivingSpeedActuallyUsed
                for motorIndex in range(2):
                    runMotor(motorIndex, forward[motorIndex])
                time.sleep(straightDelay)

in controller.py, it changes a line in another script called send_video.py for a few seconds then change back to the original

overlayCommand = '-vf transpose=2,transpose=2,dynoverlay=overlayfile=/home/pi/runmyrobot/images/hud.png:check_interval=500'

I need the line in send_video.py to change the directory of the image. Another issue I am having is that the send_video.py only updates on reboot, I need to tell it to update automatically.

Changing a line in code automatically is very unusual and far from what we call "best practice". This is called self-modifying code and was the topic of research done several decades ago. Since then it has been dropped almost completely and is now regarded an ugly hack in all but the very strangest circumstances.

What is typically done to achieve your goal is to pass parameters and use them in the other code.

Your wording is a bit unclear (I don't understand that part about updating a file, for example), so I'm not sure if I address your issue correctly, but I'll give it a try in a general approach:

When your code in controller.py calls the code in send_video.py it will call a function. To this function is should pass an argument which is the line. The function in send_video.py should use the passed parameter to determine which line it should use (the default one or the special one).

Feel free to improve your question by showing us more of your code or ask further questions if this does not help enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM