hey guys please check my pytohn program

Dennis Kaarsemaker dennis at kaarsemaker.net
Sun Jul 17 19:30:04 UTC 2005


On zo, 2005-07-17 at 19:58 +0500, Mustafa Abbasi wrote:


>         while True: #the list making loop
>             a= raw_input('enter items ')
>             if a == 'quit':
>                 break
>             else: 
>                 shoplist.append(a)
>             print shoplist
>         else :
>             print 'shoplist done'

while/else is not valid combination. It's also clearer to use an infinte
loop and simply break when needed.

>         print 'there are %s \nitems in your shoplist' % len(shoplist),

The python built-in string formatting is nice, use it :)

>             if b =='remove':
              try:
>               	    remove()
              except:
                  print 'that item does not exist'

Exception handling, look it up in diveintopython

>             #how do i print this list as a text file.

fd = open('filename','w')
for line in shoplist:
fd.write(line)
fd.close()
-- 
Dennis K.
  - Linux for human beings: http://www.ubuntulinux.org
  - Linux voor normale mensen: http://www.ubuntulinux.nl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20050717/f666f040/attachment.pgp>


More information about the ubuntu-users mailing list