This is the part of my code that I'm running that is not doing exactly what I want:
#!/usr/bin/python3
class FanControl:
def __init__(self):
try:
open('settings.txt', 'r')
except IOError:
CreateSettings.MinTemp()
class CreateSettings:
mintemp = 0
maxtemp = 0
def MinTemp():
SettingsFile = open('settings.txt', 'w')
CreateSettings.mintemp = int(input('Minimum temperature for temperature range: '))
minspeed = int(input('Fan speed for temperature range "*C <= {0}*C": '.format(CreateSettings.mintemp)))
save = str((0, CreateSettings.mintemp, minspeed))
SettingsFile.write(save)
print('~~~~~~')
CreateSettings.AvgTemp()
def AvgTemp():
loop = 'yes'
SettingsFile = open('settings.txt', 'w') #####
while loop == 'yes':
CreateSettings.mintemp = CreateSettings.mintemp+1
CreateSettings.maxtemp = int(input('Maximum temperature for next temperature range: '))
speed = int(input('Fan speed for temperature range "{0}*C <= *C <= {1}*C": '.format(CreateSettings.mintemp, CreateSettings.maxtemp)))
save = str((CreateSettings.mintemp, CreateSettings.maxtemp, speed))
SettingsFile.write(save)
print(save)
CreateSettings.mintemp = CreateSettings.maxtemp
loop = str(input('Add another temperature range? (yes/no): '))
while loop != 'yes' and loop != 'no':
loop = str(input('Add another temperature range? (yes/no): '))
print('~~~~~')
SettingsFile.close() #####
I'm wanting it to print the three numbers as a tuple (converted to strings) to a settings file. The MinTemp function prints to the file correctly but when it goes to the AvgTemp function and runs through the loop the first time it only prints a ")" to the file. After the it runs the loop once it does start printing the tuples to the file correctly.
This is what I get when I run the program:
Minimum temperature for temperature range: 10 Fan speed for temperature range "*C <= 10*C": 10 ~~~~~~ Maximum temperature for next temperature range: 20 Fan speed for temperature range "11*C <= *C <= 20*C": 20 (11, 20, 20) Add another temperature range? (yes/no): yes ~~~~~ Maximum temperature for next temperature range: 30 Fan speed for temperature range "21*C <= *C <= 30*C": 30 (21, 30, 30) Add another temperature range? (yes/no): yes ~~~~~ Maximum temperature for next temperature range: 40 Fan speed for temperature range "31*C <= *C <= 40*C": 40 (31, 40, 40) Add another temperature range? (yes/no): yes ~~~~~ Maximum temperature for next temperature range: 50 Fan speed for temperature range "41*C <= *C <= 50*C": 50 (41, 50, 50) Add another temperature range? (yes/no): no ~~~~~
This is what the settings file looks like:
(0, 10, 10))(21, 30, 30)(31, 40, 40)(41, 50, 50)
Why is it printing ")" when it runs through the loop in the AvgTemp function for the first time?
I'm not really wanting advice on how to make my program better or smaller yet because I want to try and figure that out on my own at first.
Thanks!
Edited by Shadow21, 02 March 2011 - 09:17 PM.


Sign In
Create Account


Back to top









