Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How do I continue after the error?

Reply
Thread Tools

How do I continue after the error?

 
 
chad
Guest
Posts: n/a
 
      06-05-2009
Let's say I have a list of 5 files. Now lets say that one of the files
reads nude333.txt instead of nude3.txt. When this happens, the program
generates an error and quits. What I want it to do is just skip over
the bad file and continue on with the next one. Below is the actual
code. It only works on the local bbs that I hang out on. Sorry. I
couldn't think of the simple case that could isolate my problem.

#!/usr/bin/python

#The original code was written by Mr.Pardue, which sounds a lot like
#**** you

import telnetlib, os
import time
import glob

my_porn_collection = ["nude.txt", "nude2.txt", "nude333.txt",
"nude4.txt", "nude5.txt"]

path = 'porn/'

#my_porn_collection = []

def get_files():
for infile in glob.glob( os.path.join(path, '*.txt*')):
my_porn_collection.append(infile)

def generate(some_naked_bitches):
try:
f = open(some_naked_bitches, "r")
except:
pass
art = f.read()
f.close()
return art

def get_name():
user = raw_input("\nUsername: ")
password = raw_input("Password: ")
enter_party(user, password)

def enter_party(user, password):
now = telnetlib.Telnet("m-net.arbornet.org")
now.read_until("login: ")
print "\nEntered username.."
now.write(user + "\n")
now.read_until("Password:")
now.write(password + "\n" )
print "Entered pass.."
now.read_until("m-net%")
now.write("party\n")
print "Entered into party.."
scroll_some_porn(now)

def scroll_some_porn(now):
while 1:
for some_titty_porn in my_porn_collection:
now.write(" \n")
bitch_please = generate(some_titty_porn)
now.write(bitch_please)
time.sleep(10)
now.write(" \n")

if __name__ == "__main__":
#get_files()
get_name()
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      06-05-2009
On Thu, 04 Jun 2009 18:26:49 -0700, chad wrote:

> Let's say I have a list of 5 files. Now lets say that one of the files
> reads nude333.txt instead of nude3.txt. When this happens, the program
> generates an error and quits. What I want it to do is just skip over the
> bad file and continue on with the next one.



This should give you some hints.


import errno

for name in list_of_file_names:
try:
f = open(name, 'r')
except IOError, e:
if e.errno == errno.ENOENT: # or just use 2 if you're lazy
# no such file, skip
continue
# some other more serious error, re-raise the exception
raise
do_something_with(f)


[...]
> def scroll_some_porn(now):
> while 1:
> for some_titty_porn in my_porn_collection:
> now.write(" \n")
> bitch_please = generate(some_titty_porn)
> now.write(bitch_please)
> time.sleep(10)
> now.write(" \n")


Shouldn't you have some way of escaping from the infinite loop other than
typing Ctrl-C at the console? I imagine your hands will be busy.



--
Steven
 
Reply With Quote
 
 
 
 
chad
Guest
Posts: n/a
 
      06-05-2009
On Jun 4, 7:36*pm, Steven D'Aprano
<(E-Mail Removed)> wrote:
> On Thu, 04 Jun 2009 18:26:49 -0700, chad wrote:
> > Let's say I have a list of 5 files. Now lets say that one of the files
> > reads nude333.txt instead of nude3.txt. When this happens, the program
> > generates an error and quits. What I want it to do is just skip over the
> > bad file and continue on with the next one.

>
> This should give you some hints.
>
> import errno
>
> for name in list_of_file_names:
> * * try:
> * * * * f = open(name, 'r')
> * * except IOError, e:
> * * * * if e.errno == errno.ENOENT: *# or just use 2 if you're lazy
> * * * * * * # no such file, skip
> * * * * * * continue
> * * * * # some other more serious error, re-raise the exception
> * * * * raise
> * * do_something_with(f)
>
> [...]
>
> > def scroll_some_porn(now):
> > * * while 1:
> > * * * * for some_titty_porn in my_porn_collection:
> > * * * * * * now.write(" \n")
> > * * * * * * bitch_please = generate(some_titty_porn)
> > * * * * * * now.write(bitch_please)
> > * * * * * * time.sleep(10)
> > * * * * * * now.write(" \n")

>
> Shouldn't you have some way of escaping from the infinite loop other than
> typing Ctrl-C at the console? I imagine your hands will be busy.
>


Like what? All the program is meant to do is scroll ASCII art in a
chat room.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: Is there a way to continue after an exception ? Krister Svanlund Python 4 02-21-2010 02:51 AM
Re: Start application & continue after app exits Ivan Shevanski Python 7 06-10-2005 11:49 PM
Start application & continue after app exits Guy Lateur Python 1 06-09-2005 04:07 PM
MN-700 Disconnects continue after Firmware upgrade JR Wireless Networking 0 08-24-2004 03:09 PM



Advertisments