[Tutor] Advice Please

Joel Goldstick joel.goldstick at gmail.com
Mon Jun 15 16:19:56 EDT 2020


On Mon, Jun 15, 2020 at 4:10 PM John Weller <john at johnweller.co.uk> wrote:

> 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?
>
>
> python can return multiple values:

>>> def myfunc():
...   a = 5
...   b = 1
...   return a, b
...
>>> print (myfunc())
(5, 1)
>>>

In this case python returns a tuple.

you could also do something like

x, y = myfunc()

print(x, y)



> 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
>


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays


More information about the Tutor mailing list