Re: [pygame] Testing if a File Exists

2007-07-10 Thread Flávio Ribeiro

Here[1] you will find full explanation about try\except\finally\else:

[1] http://docs.python.org/tut/node10.html

2007/7/9, Richard Jones <[EMAIL PROTECTED]>:


On Mon, 9 Jul 2007, Ian Mallett wrote:
> So, how exactly do try/except things work?  I've seen them in various
> programs but I dn't know what they really do.  I was just about to ask,
and
> this seemed the perfect opportunity...

You might find some value in running through the tutorial at
. General python programming questions may
also
be asked on the python mailing list found via



HTH,

Richard





--
Flávio Ribeiro
[EMAIL PROTECTED]
www.flavioribeiro.com
(83) 9981.4441


Re: [pygame] Testing if a File Exists

2007-07-09 Thread Richard Jones
On Mon, 9 Jul 2007, Ian Mallett wrote:
> So, how exactly do try/except things work?  I've seen them in various
> programs but I dn't know what they really do.  I was just about to ask, and
> this seemed the perfect opportunity...

You might find some value in running through the tutorial at 
. General python programming questions may also 
be asked on the python mailing list found via 



HTH,

Richard


Re: [pygame] Testing if a File Exists

2007-07-08 Thread Ian Mallett

Alright, got it.  Thanks!

On 7/8/07, Charles Joseph Christie II <[EMAIL PROTECTED]> wrote:


On Sunday 08 July 2007 10:17:06 pm Ian Mallett wrote:
> So, how exactly do try/except things work?  I've seen them in various
> programs but I dn't know what they really do.  I was just about to ask,
and
> this seemed the perfect opportunity...
>
> On 7/8/07, Dave LeCompte (really) <[EMAIL PROTECTED]> wrote:
> > "John Eikenberry" <[EMAIL PROTECTED]> wrote:
> > > Ian Mallett wrote:
> > >> Hi,
> > >> Exactly what it sounds like.  Using pygame.image.load("[file]")
will
> > >> return
> > >> an error if the file doesn't exist.  How do you test if it exists
> > >> without
> > >> actually loading it, and without crashing?  Thanks.
> > >
> > > os.path.exists(path)
> > >
> > > http://docs.python.org/lib/module-os.path.html
> >
> > Some consider it "more pythonic" to just try the call and deal with
the
> > exception:
> >
> > try:
> >   pygame.image.load(imagefile)
> > except pygame.error:
> >   # handle the error here
> >
> >
> > -Dave LeCompte

Try and except: Try to execute the command. If it works, it works. If an
exception is raised, instead execute the command in the except block.



Re: [pygame] Testing if a File Exists

2007-07-08 Thread Charles Joseph Christie II
On Sunday 08 July 2007 10:17:06 pm Ian Mallett wrote:
> So, how exactly do try/except things work?  I've seen them in various
> programs but I dn't know what they really do.  I was just about to ask, and
> this seemed the perfect opportunity...
>
> On 7/8/07, Dave LeCompte (really) <[EMAIL PROTECTED]> wrote:
> > "John Eikenberry" <[EMAIL PROTECTED]> wrote:
> > > Ian Mallett wrote:
> > >> Hi,
> > >> Exactly what it sounds like.  Using pygame.image.load("[file]") will
> > >> return
> > >> an error if the file doesn't exist.  How do you test if it exists
> > >> without
> > >> actually loading it, and without crashing?  Thanks.
> > >
> > > os.path.exists(path)
> > >
> > > http://docs.python.org/lib/module-os.path.html
> >
> > Some consider it "more pythonic" to just try the call and deal with the
> > exception:
> >
> > try:
> >   pygame.image.load(imagefile)
> > except pygame.error:
> >   # handle the error here
> >
> >
> > -Dave LeCompte

Try and except: Try to execute the command. If it works, it works. If an 
exception is raised, instead execute the command in the except block.


Re: [pygame] Testing if a File Exists

2007-07-08 Thread Ian Mallett

So, how exactly do try/except things work?  I've seen them in various
programs but I dn't know what they really do.  I was just about to ask, and
this seemed the perfect opportunity...

On 7/8/07, Dave LeCompte (really) <[EMAIL PROTECTED]> wrote:


"John Eikenberry" <[EMAIL PROTECTED]> wrote:
> Ian Mallett wrote:
>
>> Hi,
>> Exactly what it sounds like.  Using pygame.image.load("[file]") will
>> return
>> an error if the file doesn't exist.  How do you test if it exists
>> without
>> actually loading it, and without crashing?  Thanks.
>
> os.path.exists(path)
>
> http://docs.python.org/lib/module-os.path.html

Some consider it "more pythonic" to just try the call and deal with the
exception:

try:
  pygame.image.load(imagefile)
except pygame.error:
  # handle the error here


-Dave LeCompte



Re: [pygame] Testing if a File Exists

2007-07-08 Thread Dave LeCompte (really)
"John Eikenberry" <[EMAIL PROTECTED]> wrote:
> Ian Mallett wrote:
>
>> Hi,
>> Exactly what it sounds like.  Using pygame.image.load("[file]") will
>> return
>> an error if the file doesn't exist.  How do you test if it exists
>> without
>> actually loading it, and without crashing?  Thanks.
>
> os.path.exists(path)
>
> http://docs.python.org/lib/module-os.path.html

Some consider it "more pythonic" to just try the call and deal with the
exception:

try:
  pygame.image.load(imagefile)
except pygame.error:
  # handle the error here


-Dave LeCompte


Re: [pygame] Testing if a File Exists

2007-07-08 Thread Ian Mallett

That sounds familiar.  Thanks!

On 7/8/07, John Eikenberry <[EMAIL PROTECTED]> wrote:


Ian Mallett wrote:

> Hi,
> Exactly what it sounds like.  Using pygame.image.load("[file]") will
return
> an error if the file doesn't exist.  How do you test if it exists
without
> actually loading it, and without crashing?  Thanks.

os.path.exists(path)

http://docs.python.org/lib/module-os.path.html

--

John Eikenberry
[EMAIL PROTECTED] - http://zhar.net]
__
"It is difficult to produce a television documentary that is both incisive
and probing when every twelve minutes one is interrupted by twelve dancing
rabbits singing about toilet paper." - Rod Serling




Re: [pygame] Testing if a File Exists

2007-07-08 Thread John Eikenberry
Ian Mallett wrote:

> Hi,
> Exactly what it sounds like.  Using pygame.image.load("[file]") will return
> an error if the file doesn't exist.  How do you test if it exists without
> actually loading it, and without crashing?  Thanks.

os.path.exists(path)

http://docs.python.org/lib/module-os.path.html

-- 

John Eikenberry
[EMAIL PROTECTED] - http://zhar.net]
__
"It is difficult to produce a television documentary that is both incisive
and probing when every twelve minutes one is interrupted by twelve dancing
rabbits singing about toilet paper." - Rod Serling



[pygame] Testing if a File Exists

2007-07-08 Thread Ian Mallett

Hi,
Exactly what it sounds like.  Using pygame.image.load("[file]") will return
an error if the file doesn't exist.  How do you test if it exists without
actually loading it, and without crashing?  Thanks.
Ian