Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multiple try expect in a for loop

14 views
Skip to first unread message

Ganesh Pal

unread,
Aug 22, 2017, 1:14:34 PM8/22/17
to
Hello python friends,

I need a suggestion on the below piece of code . I have for loop and I
need to do the below i.e create 100 of queue ,open ,and append some data
to a data structure. Is multiple try except the way to go or any other
idea's.

I feel that there is a better way to write those try except statement or
avoid it . I am a Linux user on python 2.7

def create_queue():
q_name = ""
q_fd = ""
for itr in range(1, 100):
q_name = randomword(100)
print q_name
try:
q.create(q_name)
except OSError as e:
sys.stderr.write('Unable to create Queue %s: %s\n' % (q_name,
str(e)))
return False
try:
q_fd = q.open(q_name); // Can I add multiple statement like
this ?
q.append(q_fd, randomword(100))
except OSError as e:
sys.stderr.write('Unable to open or append Queue %s: %s\n' %
(q_name, str(e)))
return False

return True


Regards,
Ganesh
0 new messages