I am trying to write a program to write and read files on fictional people for fun, however, something to do with my if statements is preventing it from working.
initAction = open
File Path or other local file? (Choose FP or LF or exit)exit
fileToOpen = ??????? Why here?
File not found
File Path or other local file? (Choose FP or LF or exit)LP
fileToOpen = ??????? Why here?
File not found
File Path or other local file? (Choose FP or LF or exit)exit
fileToOpen =
>>> ================================ RESTART ===================
>>>
initAction = write
File Path or other local file? (Choose FP or LF or exit)
>>> ================================ RESTART ===================
>>>
initAction = exit
File Path or other local file? (Choose FP or LF or exit)>??????
fileToOpen =
I'm not sure why this is happening for this code (It is nowhere near finished, by the way.):
import time
import os
import sys
running = True
while running:
initAction = ''
secAction = ''
fileToOpen = ''
PersonName = ''
PersonSchool = ''
PersonNotes = []
PersonProperties = {}
fileFound = False
exited = False
initAction = raw_input('initAction = ')
#OPENING#
if initAction == 'open' or 'read':
while not fileFound:
secAction = raw_input('File Path or other local file? (Choose FP or LF or exit)')
if secAction == 'exit':
fileFound = False
exited = True
elif secAction == 'FP':
fileToOpen = raw_input('fileToOpen = ')
if not fileToOpen.endswith('.txt'):
fileName = fileToOpen + '.txt'
else:
fileName = fileToOpen
fileToOpen = raw_input('fileToOpen = ')
fileName = fileToOpen + '.txt'
try:
ReadPerson = open(fileName, 'r')
fileFound = True
except:
print 'File not found'
if not exited:
pass
#Add more here for reading file.
#WRITING#
if initAction == 'write' or 'create' or 'new':
PersonName = raw_input('PersonName = ')
if initAction == 'exit' or 'quit':
running = False
else:
print 'Command not recognised'
exit()
Aucun commentaire:
Enregistrer un commentaire