Python Forum
accessing local variable outside class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
accessing local variable outside class
#2
In the title you talk about class, but there is no OOP/class in your code, i.e. it's not very clear what you are asking/what you have problem with....
In your code you use return to pass value from function to outside scope and that is the correct way to do... Maybe elaborate further on what you are struggling with...

Looking closer at your code - on line 47 you need to assign what you return from your function to some variable in order ti use these values further in the code, e.g.
temp_c, temp_f = read_temp() #unpack the tuple returned by the function into two variables. I use the names you use later in the code
Note that you may want to do this first and then print these variables, instead of calling the function twice (on lines 45 and 47)...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: accessing local variable outside class - by buran - Sep-24-2019, 08:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how solve: local variable referenced before assignment ? trix 5 363 Jun-15-2024, 07:15 PM
Last Post: trix
  It's saying my global variable is a local variable Radical 5 1,458 Oct-02-2023, 12:57 AM
Last Post: deanhystad
  Variable Types in a class nafshar 9 2,725 Oct-07-2022, 07:13 PM
Last Post: deanhystad
  can Inner Class reference the Outer Class's static variable? raykuan 6 6,287 Jul-01-2022, 06:34 AM
Last Post: SharonDutton
  accessing value in dict_values class CompleteNewb 14 5,598 Mar-31-2022, 04:02 AM
Last Post: deanhystad
  UnboundLocalError: local variable 'wmi' referenced before assignment ilknurg 2 2,057 Feb-10-2022, 07:36 PM
Last Post: deanhystad
  Calling a base class variable from an inherited class CompleteNewb 3 1,888 Jan-20-2022, 04:50 AM
Last Post: CompleteNewb
  Can we access instance variable of parent class in child class using inheritance akdube 3 14,169 Nov-13-2020, 03:43 AM
Last Post: SalsaBeanDip
  Class variable / instance variable ifigazsi 9 4,583 Jul-28-2020, 11:40 AM
Last Post: buran
  Assignment of non-existing class variable is accepted - Why? DrZ 6 4,486 Jul-13-2020, 03:53 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020