I made a profile creator for a game I'm makeing and it isn't outputting properly. It's supposed to print
default
open
open
open
open
open
open
open
open
open
1
Instead it saves it with space between some lines, i've tried somethings but i can't fix it, can anyone help me save the text file like the example above?
(The code i'm using)
debug = False
def profile_creator():
count2 = 0
u1 = 'Open'
u2 = 'Open'
u3 = 'Open'
u4 = 'Open'
u5 = 'Open'
u6 = 'Open'
u7 = 'Open'
u8 = 'Open'
u9 = 'Open'
u10 = 'Open'
content = ['HS:', '0', 'LS:', '0', 'G:', '0', '', 'LS = Last Score, HS = High Score, G = Games']
print('> Input Save Name')
chosen_u = input('> ')
chosen_u = str.lower(chosen_u)
with open('game_info_' chosen_u '.txt', 'w') as f:
for line in content:
f.write(line)
f.write('\n')
f.close()
with open('game_info_backup_' chosen_u '.txt', 'w') as f:
for line in content:
f.write(line)
f.write('\n')
f.close()
with open('game_users.txt', 'r') as f:
content = f.readlines()
count = 1
for line in content:
if count == 1:
u1 = line
if count == 2:
u2 = line
if count == 3:
u3 = line
if count == 4:
u4 = line
if count == 5:
u5 = line
if count == 6:
u6 = line
if count == 7:
u7 = line
if count == 8:
u8 = line
if count == 9:
u9 = line
if count == 10:
u10 = line
if count == 11:
count2 = line
count = 1
f.close()
u1 = text_quality_control(u1)
u2 = text_quality_control(u2)
u3 = text_quality_control(u3)
u4 = text_quality_control(u4)
u5 = text_quality_control(u5)
u6 = text_quality_control(u6)
u7 = text_quality_control(u7)
u8 = text_quality_control(u8)
u9 = text_quality_control(u9)
u10 = text_quality_control(u10)
count2 = int(count2)
count2 = str(count2)
count2 = int(count2)
count2 = 1
if count2 == 1:
u1 = chosen_u
if count2 == 2:
u2 = chosen_u
if count2 == 3:
u3 = chosen_u
if count2 == 4:
u4 = chosen_u
if count2 == 5:
u5 = chosen_u
if count2 == 6:
u6 = chosen_u
if count2 == 7:
u7 = chosen_u
if count2 == 8:
u8 = chosen_u
if count2 == 9:
u9 = chosen_u
if count2 == 10:
u10 = chosen_u
content = [u1, '', u2, '', u3, '', u4, u5, u6, u7, u8, u9, u10, str(count2)]
with open('game_users.txt', 'w') as f:
for line in content:
f.write(line)
f.write('\n')
f.close()
def text_quality_control(line):
msg = str(line)
stringer = ''
indexer = 0
str_length = len(msg)
for i in range(str_length - 1):
msg2 = msg[indexer]
msg2 = str.lower(msg2)
if '1' in msg2:
stringer = stringer '1'
if '2' in msg2:
stringer = stringer '2'
if '3' in msg2:
stringer = stringer '3'
if '4' in msg2:
stringer = stringer '4'
if '5' in msg2:
stringer = stringer '5'
if '6' in msg2:
stringer = stringer '6'
if '7' in msg2:
stringer = stringer '7'
if '8' in msg2:
stringer = stringer '8'
if '9' in msg2:
stringer = stringer '9'
if '0' in msg2:
stringer = stringer '0'
if 'a' in msg2:
stringer = stringer 'a'
if 'b' in msg2:
stringer = stringer 'b'
if 'c' in msg2:
stringer = stringer 'c'
if 'd' in msg2:
stringer = stringer 'd'
if 'e' in msg2:
stringer = stringer 'e'
if 'f' in msg2:
stringer = stringer 'f'
if 'g' in msg2:
stringer = stringer 'g'
if 'h' in msg2:
stringer = stringer 'h'
if 'i' in msg2:
stringer = stringer 'i'
if 'j' in msg2:
stringer = stringer 'j'
if 'k' in msg2:
stringer = stringer 'k'
if 'l' in msg2:
stringer = stringer 'l'
if 'o' in msg2:
stringer = stringer 'o'
if 'm' in msg2:
stringer = stringer 'm'
if 'n' in msg2:
stringer = stringer 'n'
if 'p' in msg2:
stringer = stringer 'p'
if 'q' in msg2:
stringer = stringer 'q'
if 'r' in msg2:
stringer = stringer 'r'
if 's' in msg2:
stringer = stringer 's'
if 't' in msg2:
stringer = stringer 't'
if 'u' in msg2:
stringer = stringer 'u'
if 'v' in msg2:
stringer = stringer 'v'
if 'w' in msg2:
stringer = stringer 'w'
if 'x' in msg2:
stringer = stringer 'x'
if 'y' in msg2:
stringer = stringer 'y'
if 'z' in msg2:
stringer = stringer 'z'
if debug:
print(stringer)
indexer = 1
if debug:
print(stringer)
return stringer
print('Input Save Name')
CodePudding user response:
You have empty strings ''
in content
. When you write these to the file, you get blank lines. So take them out.
content = [u1, '', u2, '', u3, '', u4, u5, u6, u7, u8, u9, u10, str(count2)]
should be
content = [u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, str(count2)]