[Tutor] file opening and errors.

2005-10-20 Thread Dan Klose
Hi, I usually use perl but fancy a bit of a change so have started playing with python. using perl to open a file or directory I usually use: open(FILE, $file) or die Error: $!\n; The $! is a perl variable that holds an error should the open fail, example being : No such file or directory.

Re: [Tutor] file opening and errors.

2005-10-20 Thread w chun
On 10/20/05, Dan Klose [EMAIL PROTECTED] wrote: I usually use perl but fancy a bit of a change so have started playing with python. congrats! :-) using perl to open a file or directory I usually use: open(FILE, $file) or die Error: $!\n; The $! is a perl variable that holds an error

Re: [Tutor] file opening and errors.

2005-10-20 Thread Kent Johnson
Dan Klose wrote: Hi, I usually use perl but fancy a bit of a change so have started playing with python. using perl to open a file or directory I usually use: open(FILE, $file) or die Error: $!\n; The $! is a perl variable that holds an error should the open fail, example being : No

Re: [Tutor] file opening and errors.

2005-10-20 Thread Andrew P
It's not in direct answer to your question, but a real short answer is Python doesn't need 'or die' here. It throws exceptions gleefully whenever it encounters an error: f = open('no_such_file') Traceback (most recent call last): File interactive input, line 1, in ? IOError: [Errno 2] No

Re: [Tutor] file opening and errors.

2005-10-20 Thread Danny Yoo
open(FILE, $file) or die Error: $!\n; The $! is a perl variable that holds an error should the open fail, example being : No such file or directory. With python I have use a try except block but I have no idea how I would get the same warning from python as I would from perl (the reason