473,414 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Try except - bug?

Hi,
I have a problem with try except :
example
============
try:
print "bou!"
raise "ha!"
except:
try:
fileDest.close()
except NameError:
print "error"
except:
import traceback
traceback.print_exc(file=sys.stdout)
============
If I run this example alone, I have no problem :
result
============
bou!
error
============

but I can't understand why doesn't work in my program :
http://www.cvm.qc.ca/9974331/Temp/crypte.py
(too long for a copy and paste)
(note : it's at line 353)
(note : the language of this program is in french, sorry)

when I run my program, I have this error :
============
Traceback (most recent call last):
File "C:\Documents and Settings\Assembleur_Man\Bureau\Crypte.py",
line 355, in crypte
fileDest.close()
NameError: global name 'fileDest' is not defined
============

but I know that 'fileDest' is not always defined but I put this line
in a try-except!? :-( :-S
Askari
Jul 18 '05 #1
7 1358
Askari:
but I can't understand why doesn't work in my program :
http://www.cvm.qc.ca/9974331/Temp/crypte.py [...]when I run my program, I have this error :
============
Traceback (most recent call last):
File "C:\Documents and Settings\Assembleur_Man\Bureau\Crypte.py",
line 355, in crypte ^^^ fileDest.close()
NameError: global name 'fileDest' is not defined
============


That's strange, because there is no fileDest.close() on line 355. Are you
sure the message and the code you are showing us correspond?

--
René Pijlman
Jul 18 '05 #2
99*****@cvm.qc.ca (Askari) wrote in
news:10**************************@posting.google.c om:
Hi,
I have a problem with try except :
example
============
try:
print "bou!"
raise "ha!"
except:
try:
fileDest.close()
except NameError:
print "error"
except:
import traceback
traceback.print_exc(file=sys.stdout)
============
If I run this example alone, I have no problem :
result
============
bou!
error
============

but I can't understand why doesn't work in my program :
http://www.cvm.qc.ca/9974331/Temp/crypte.py
(too long for a copy and paste)
(note : it's at line 353)
(note : the language of this program is in french, sorry)

when I run my program, I have this error :
============
Traceback (most recent call last):
File "C:\Documents and Settings\Assembleur_Man\Bureau\Crypte.py",
line 355, in crypte
fileDest.close()
NameError: global name 'fileDest' is not defined
============

but I know that 'fileDest' is not always defined but I put this line
in a try-except!? :-( :-S
Askari

Ops! For test (to do the error), you must click on button "crypter!" with
blank textField

Jul 18 '05 #3
Askari:
Ops! For test (to do the error), you must click on button "crypter!" with
blank textField


The program runs fine and displays a dialogue with "!ERREUR! :: Vous devez
avoir un code pour l'encryption.".

--
René Pijlman
Jul 18 '05 #4
Rene Pijlman <re********************@my.address.is.invalid> wrote in message news:<1n********************************@4ax.com>. ..
Askari:
Ops! For test (to do the error), you must click on button "crypter!" with
blank textField


The program runs fine and displays a dialogue with "!ERREUR! :: Vous devez
avoir un code pour l'encryption.".


It's at 355 or 363 the error...

============
Traceback (most recent call last):
File "C:\Documents and Settings\Assembleur_Man\Bureau\test.py", line 363, in c
rypte
os.remove(destination)
OSError: [Errno 2] No such file or directory: ''
============

at line 355 you have : "fileDest.close()"
and at line 363 you have : "os.remove(destination)"

What is your version of python? (I have 2.3.2)
Do you have "Traceback" message in console (when you see the dialog)?

Askari
Jul 18 '05 #5
Askari:
OSError: [Errno 2] No such file or directory: ''
If I'm not mistaken this is another exception!?
at line 355 you have : "fileDest.close()"
No, line 355 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:

#afficher confirmation
and at line 363 you have : "os.remove(destination)"
No, line 363 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:

pass
What is your version of python? (I have 2.3.2)


I use UltraEdit 8.0 on Windows XP to count the line numbers.

--
René Pijlman
Jul 18 '05 #6
Rene Pijlman <re********************@my.address.is.invalid> wrote in
news:gg********************************@4ax.com:
Askari:
OSError: [Errno 2] No such file or directory: ''


If I'm not mistaken this is another exception!?
at line 355 you have : "fileDest.close()"


No, line 355 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:
#afficher confirmation
and at line 363 you have : "os.remove(destination)"


No, line 363 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:

pass
What is your version of python? (I have 2.3.2)


I use UltraEdit 8.0 on Windows XP to count the line numbers.


euh.... I use UltraEdit 10.10 and "#afficher confirmation" is at line 349
(it's the same numero in IDLE). Are you sure that your UltraEdit is
correct? Check the line in IDLE, it's the same?
Jul 18 '05 #7
Rene Pijlman <re********************@my.address.is.invalid> wrote in
news:gg********************************@4ax.com:
Askari:
OSError: [Errno 2] No such file or directory: ''


If I'm not mistaken this is another exception!?
at line 355 you have : "fileDest.close()"


No, line 355 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:
#afficher confirmation
and at line 363 you have : "os.remove(destination)"


No, line 363 of http://www.cvm.qc.ca/9974331/Temp/crypte.py is:

pass
What is your version of python? (I have 2.3.2)


I use UltraEdit 8.0 on Windows XP to count the line numbers.


Batheme! I didn't know that the exception rest in memory after a "catch".
Finaly, it's my mistake with use of "sys.exc_info()" at line 368.

But for # of line; check your ultraedit. Are you sure that the line 1 is
"#! d:/python23/python" ?
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Erlend Fuglum | last post by:
Hi everyone, I'm having some trouble sorting lists. I suspect this might have something to do with locale settings and/or character encoding/unicode. Consider the following example, text...
3
by: George Young | last post by:
I have a bunch of blanket "except:" clauses like: class DatabaseError(StandardError): pass class OperationalError(StandardError): pass try: stuff except _pg.error, msg: raise...
13
by: KefX | last post by:
This may have been discussed before, but I'm kind of confused as to why Python doesn't support having both an except ~and~ a finally clause, like this: try: raise RuntimeException except:...
7
by: Robert Brewer | last post by:
Alex Martelli wrote in another thread: > One sign that somebody has moved from "Python newbie" to "good Python > programmer" is exactly the moment they realize why it's wrong to code: > > ...
0
by: John J. Lee | last post by:
Bare "except:", with no exception specified, is nasty because it can easily hide bugs. There is a case where it seemed useful to me in the past. Now it seems like a bad idea to me (but I think...
2
by: Thorsten Kampe | last post by:
What is the best way to except two errors, when the except handling in both cases is the same? "except:" would just except every error and not just those I want. except Attribute error:...
4
by: Erwin Leonardi | last post by:
Hi all, I just start using SQL Server for my project. I have some questions related to set operations. Suppose I have two tables, Table A and Table B, as following. TableA ...
20
by: John Salerno | last post by:
I'm starting out with this: try: if int(text) 0: return True else: self.error_message() return False except ValueError: self.error_message()
35
by: Arnaud Delobelle | last post by:
Hi all, Imagine I have three functions a(x), b(x), c(x) that each return something or raise an exception. Imagine I want to define a function that returns a(x) if possible, otherwise b(x),...
2
by: AWasilenko | last post by:
I can't figure out this problem Im having, I just can't understand why it is ignoring the call I put in. First the code (This is a cherrypy website): import sys, cherrypy, html class Root:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.