[Tutor] Help me abt this error
Asrarahmed Kadri
ajkadri at googlemail.com
Wed Oct 18 00:37:59 CEST 2006
I changed to append mode and it is working.
But the thing is that I have another problem.
I am trying to insert usernames that are unique. Please look at the code and
help me.
import sys
fd = open('usr.txt','a')
def chk(str):
global fd
fd.seek(0,0)
print fd
done = 0
list1 = []
answer = True
while not done:
aline = fd.readline()
if aline == "":
done = 1
else:
list1.append(aline)
print list1
for i in list1:
print i
j = i.split(':')
if str == j[0]:
answer = False
break
return answer
def make_entry(uname,passwd):
global fd
fd.seek(0,2)
str1 = uname+':'+passwd
fd.write(str1+'\n')
enter_choice()
def die():
sys.exit(0)
def new_user():
uname = raw_input("Enter your desired username")
ans = chk(uname)
print ans
if ans:
passwd = raw_input("Enter your password")
make_entry(uname,passwd)
else:
showerror('Login Error...','Id already taken')
new_user()
def display_menu():
print "-" * 30
print "Select 1 for new user:"
print "Select 2 to exit"
print "-" * 30
def enter_choice():
display_menu()
print
choice = raw_input("Enter your choice")
if choice == '1':
new_user()
else:
die()
enter_choice()
The problem is in the chk() function.. It is not reading the file ....The
file is a txt file with colon (:) as the delimiter between username and
password.
I cannot understand why its not reading???
Please help...
On 10/17/06, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
>
> Asrarahmed Kadri wrote:
> > I am trying to write to a file, but I am getting this errror.
> >
> > IOError: (0, 'Error')
> >
> > Can someone explain what is it and whats the solution??
> No.
> Give us the actual source and the full traceback.
> Cheers,
> -Luke
>
--
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061017/14f8f1e5/attachment-0001.htm
More information about the Tutor
mailing list