open() and EOFError
breamoreboy at yahoo.co.uk
Mon Jul 7 15:06:33 CEST 2014
On 07/07/2014 09:09, Chris Angelico wrote:
> On Mon, Jul 7, 2014 at 6:00 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> How do people feel about code like this?
>> name = input("Enter file name, or Ctrl-D to exit")
>> # On Windows, use Ctrl-Z [enter] instead.
>> fp = open(name)
>> except EOFError:
>> except IOError:
> It seems trivial in this example to break it into two try blocks:
> name = input("Enter file name, or Ctrl-D to exit")
> # On Windows, use Ctrl-Z [enter] instead.
> except EOFError:
> fp = open(name)
> except IOError:
All those extra lines to type, not on your life. Surely it would be
better written as a one liner?
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
This email is free from viruses and malware because avast! Antivirus protection is active.
More information about the Python-list