I keep getting this error local variable 'f' referenced before
assignment in the finally block when I run the following code.
try:
f = file(self.filename, 'rb')
f.seek(DATA_OFFSET)
self.__data = f.read(DATA_SIZE)
self.isDataLoaded = True
On 14 Feb 2007 11:41:29 -0800, redawgts [EMAIL PROTECTED] wrote:
I keep getting this error local variable 'f' referenced before
assignment in the finally block when I run the following code.
try:
f = file(self.filename, 'rb')
f.seek(DATA_OFFSET)
redawgts wrote:
I keep getting this error local variable 'f' referenced before
assignment in the finally block when I run the following code.
try:
f = file(self.filename, 'rb')
f.seek(DATA_OFFSET)
self.__data = f.read(DATA_SIZE)
redawgts [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
I keep getting this error local variable 'f' referenced before
assignment in the finally block when I run the following code.
try:
f = file(self.filename, 'rb')
f.seek(DATA_OFFSET)
redawgts wrote:
I keep getting this error local variable 'f' referenced before
assignment in the finally block when I run the following code.
try:
f = file(self.filename, 'rb')
f.seek(DATA_OFFSET)
self.__data = f.read(DATA_SIZE)
redawgts [EMAIL PROTECTED] writes:
try:
f = file(self.filename, 'rb') ...
Can someone tell me what's wrong with the code?
Various people have explained the error: if the file open attempt
fails, f is never assigned. Doing it the right way (i.e. handling the
potential
Thanks everybody, that helped alot.
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 14 Feb 2007 12:09:34 -0800, Paul Rubin wrote:
redawgts [EMAIL PROTECTED] writes:
try:
f = file(self.filename, 'rb') ...
Can someone tell me what's wrong with the code?
Various people have explained the error: if the file open attempt
fails, f is never
Steven D'Aprano [EMAIL PROTECTED] writes:
self.isDataLoaded = False
try:
f = open(self.filename, 'rb')
f.seek(DATA_OFFSET)
self.__data = f.read(DATA_SIZE)
self.isDataLoaded = True
except:
pass
else:
pass
(apart from being four lines shorter)
Your version never
On Wed, 14 Feb 2007 18:03:19 -0800, Paul Rubin wrote:
Steven D'Aprano [EMAIL PROTECTED] writes:
self.isDataLoaded = False
try:
f = open(self.filename, 'rb')
f.seek(DATA_OFFSET)
self.__data = f.read(DATA_SIZE)
self.isDataLoaded = True
except:
pass
else:
pass
Replying to my own question...
On Thu, 15 Feb 2007 13:17:00 +1100, Steven D'Aprano wrote:
I don't see where the with version closes the file either. How does it
know that I want to call the f's close() method, rather than, say,
f.exit() or f.do_something_else()?
Ah, I *think* I see... file
Steven D'Aprano [EMAIL PROTECTED] writes:
Yes it does. Eventually f goes out of scope and is closed automatically.
Oh right, however you can't really predict when the closure occurs,
unless you're relying on current CPython artifacts.
Re your other post: yes, PEP 363 explains how the with
Paul Rubin http://[EMAIL PROTECTED] writes:
Re your other post: yes, PEP 363 explains how the with statement
Whoops, 343.
--
http://mail.python.org/mailman/listinfo/python-list
13 matches
Mail list logo