0

I am using a Temper1F sensor, the code base I am using is at https://github.com/urwen/temper. The temper.py code returns an out put as seen below.

$ python3 temper.py
Bus 001 Dev 006 413d:2107 TEMPerX_V3.3 22.6C 72.7F - - - -

I would like to take that output and put it as a string variable in a different python script. I have tried using os. How can I invoke the other python script and store the output to variable?

I have tried the following methods:

from subprocess import call
var = str(call(["python", "temper.py"]))
var2 = call(["python", "temper.py"])

import os 
os.system('python temper.py')

import temper
var = temper

The call method returns a 0.

2

1 Answer 1

1

Do you have no way of accessing the methods from the sensor script? That would simplify things a lot...

If not, You can use sys.stdin in your script:

import fileinput
import sys

while True:
  line = sys.stdin.readline().strip()
  if line: print "[received]: ", line

and pipe the output of the sensor script into yours:

python sensorscript.py | python yourscript.py

[edit] I've checked out the temper script, and it looks like it's pretty easy to use it as a module directly:

from temper import Temper
temper = Temper()
value = temper.read() # call this every time you want to read the sensor
Sign up to request clarification or add additional context in comments.

Comments

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.