[Tutor] Advice Please
stephen.m.smith at comcast.net
stephen.m.smith at comcast.net
Mon Jun 15 16:29:02 EDT 2020
Pretty easy to do if I understand your question.
https://note.nkmk.me/en/python-function-return-multiple-values/
or
https://www.geeksforgeeks.org/g-fact-41-multiple-return-values-in-python/
basically
return (temperature, humidity)
or
return temperature, humidity
Positional integrity maintained.
-----Original Message-----
From: Tutor <tutor-bounces+stephen.m.smith=comcast.net at python.org> On Behalf Of John Weller
Sent: Monday, June 15, 2020 10:22 AM
To: tutor at python.org
Subject: [Tutor] Advice Please
I seek advice. I am writing an application to control the humidity in a building. I am new to Python but not programming. I have an external class provided by the hardware supplier which will access the hardware to obtain the temperature and humidity. I will create an instance of the class in the main part of the program then use it in a loop to get the data, process it and display it. Accessing the data and checking it will be done in a function which I want to return the two values and an error count. In the languages I am used to I would pass the parameters to the function by reference so as to be able to access the values outside the function however I understand that this is not available in Python. Can Python return multiple values, (return temperature, humidity)? If not I could make the variables global (not recommended but as these values are fundamental to the whole program then perhaps acceptable) or use a compound data structure such as a dictionary or create a class just to hold the data? My question is – what do you recommend?
Can anyone recommend a book that I can use as a reference to perhaps answer some question without having to bother you guys 😊. I’ve looked at a few books but they all have failings – most I have seen don’t have an index (essential) or their code examples are screenshots from Terminal with coloured text on a black background which I find difficult to read or their style is too jokey, ‘print(“Hello World”) – now you are a programmer’ sort of thing. A bit like the Three Bears, something not too technical but not too easy. 😊
TIA
John
John Weller
01380 723235
07976 393631
_______________________________________________
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list