F01.justanswer.com



I'm starting over. After looking at your answer, it is obvious I failed to communicate, with the blame being on me. So I'll give this another try. First, I'm working with a Raspberry Pi, so the system is Linux. I have a script “therm.py” which I have downloaded, not modified, and put in “home/pi/Documents”. Using the "terminal" I cd to "home/pi/Documents", and then enter into the Terminal’s command line the following: "Python2 therm.py -help". This results in the following “help” info being displayed in the terminals window:sys.argv()Cooling: -c temperature –t hold_timeHeating: -h temperature –t hold_timeStatus: -sCancel: -xFan: -f [0=auto|1=on]()Example: Set temperature to cool to 80f for 1 hour: Therm.py –c 80 –t 1()If no –t hold_time is provided, it will default to one hour from command time()pi@raspberrypi:~/Documents $For example now, if I want to get the status of my home’s thermostat, I need to enter the following into my terminal’s command line: “python2 therm.py –s”However, I do not want to type into the terminal window’s command line. Rather, I want a python program which I have created, to enter it. I already understand that this can be accomplished by using either the os.system or the subprocess system, but I am not familiar with either of these modules. Apparently, the os.system is no longer recommended to be used. Looking into the subprocess system: it is obvious to me that I am too much of an amature programmer to use it properly. I don’t have the time now to study it. What I so poorly asked, in the beginning, was what line (or lines) of python code do I need to place in my program for it to communicate with the therm.py script directly rather than me typing into the terminal’s command line. All I asked for was one example: instead of me entering into the terminal’s command line: “python2 therm.py –help”, I want to place a line of code in my python program which would look kind of like this: “subprocess.run (python2 therm.py –help)”.I see that I failed miserably to communicate with you in the chat window, perhaps since I was both unfamiliar with the process, and also under pressure. In any case, do you want to pursue this further, or am I wasting your time?Thanks.3/12/2019/11:00am:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXLogicPro came back with the solution: I needed to include the quotes show in my code: os.system(‘python2 therm.py –help’). This allowed me to run my python program and change my room thermostat temperature setpoint.However, what I really want to do is not “command” the thermostat, but get room temperature data back from it. I can manually do this using the following in the Terminal’s command line: python therm.py –s ….This results in the thermostat’s status data being returned, and the status includes the temperature.The therm.py program was python2.7, but I have now converted the therm.py program to python 3.7 using 2to3, and confirmed it ‘works’. Also, every indication is that I should be using ‘subprocess’ rather than os.system.Therefore, what I want assistance with is python 3 code using the subprocess module that will return data to variable “returned_value” in my slightly modified python program:import osimport sysimport subprocesscmd = “python therm.py –s”returned_value = subprocess.run (cmd)print (returned_value)This produces errors because the line with subprocess is not coded appropriately. Can you help me change the code so it will work?Thanks ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download