I am making a little game thing in Python, I'm still fairly new to this. I am trying to access a variable in another file by using import, but it keeps saying
AttributeError: module 'core temp' has no attribute 'ct'
This is my code I am trying to run:
elif cmd == "temp":
if core.ct < 2000:
print(colored("Core temperature: "+core.ct+"°C", "green"))
elif core.ct < 4000:
print(colored("Core temperature: "+core.ct+"°C", "yellow"))
elif core.ct >= 3000:
print(colored("Core temperature: "+core.ct+"°C", "red"))
I am importing coretemp like this: import coretemp as core
This is the code in coretemp.py:
from time import sleep as wait
import coolant as c
ct = 10
while True:
if c.coolactive == False:
ct = ct + 1
wait(.3)
else:
ct = ct - 1
wait(1)
I've been stuck on this problem for ages!
PS: sorry if things aren't formatted right, I'm on mobile and it's hard.
The only way I can see you would get this error is if the
coolant
module also importscoretemp
. (BTW, I am assuming here the space incore temp
was a copy/paste error)If
coolant
importscoretemp
it will be accessing a copy of the module as it existed whencoretemp
importedcoolant
. That would meanct
is not yet defined.Note that the import in
main
will never complete ascoretemp.py
contains an infinite loop at the top level:main
will simply wait for ever for the module it is importing to finish executing.