0

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.

1
  • How about you set send_video.py to load what it should do (for example to load the link in your case) from an external file or a database and then have your controller.py script change that file/database entry instead? Commented Jul 21, 2017 at 9:55

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

What i mean is when controller.py is changed, i need the machine to know that it has been updated and changed, normally I have to reboot in order for any and all changes to controller.py to take effect

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.