In MRAB
writes:
>kj wrote:
>> In MRAB
>> writes:
>>
>>> If, for example, you're
>>> going to copy a file, it's a good idea to check beforehand that there's
>>> enough space available for the copy.
>>
>> How do you do that?
>>
>There's os.statvfs(...), although that's Unix only.
Thanks!
On Sep 19, 9:22 pm, MRAB wrote:
> The point is that it's sometimes a good idea to do a cheap check first
> before attempting an operation that's 'expensive' even when it fails.
Strongly agree. Furthermore, with LBYL it's often easier to give a
user clearer error messages for common usage errors,
On 2009-09-20, MRAB wrote:
> kj wrote:
>> In MRAB
>> writes:
>>
>>> If, for example, you're going to copy a file, it's a good idea
>>> to check beforehand that there's enough space available for
>>> the copy.
>>
>> How do you do that?
>>
> There's os.statvfs(...), although that's Unix only.
kj wrote:
In MRAB
writes:
If, for example, you're
going to copy a file, it's a good idea to check beforehand that there's
enough space available for the copy.
How do you do that?
There's os.statvfs(...), although that's Unix only.
The point is that it's sometimes a good idea to do a che
In MRAB
writes:
>If, for example, you're
>going to copy a file, it's a good idea to check beforehand that there's
>enough space available for the copy.
How do you do that?
TIA,
kynn
--
http://mail.python.org/mailman/listinfo/python-list
Grant Edwards wrote:
On 2009-09-19, Christian Heimes wrote:
kj wrote:
For example, LBYL would look like this:
if os.path.isfile(some_file):
os.unlink(some_file)
In contrast, EAFP would look like this:
try:
os.unlink(some_file)
except OSError:
pass
The two version aren't equal.
On 2009-09-19, Christian Heimes wrote:
> kj wrote:
>> For example, LBYL would look like this:
>>
>> if os.path.isfile(some_file):
>> os.unlink(some_file)
>>
>> In contrast, EAFP would look like this:
>>
>> try:
>> os.unlink(some_file)
>> except OSError:
>> pass
>
>
> The two version
On Sep 18, 5:23 pm, Christian Heimes wrote:
> kj wrote:
> > For example, LBYL would look like this:
>
> > if os.path.isfile(some_file):
> > os.unlink(some_file)
>
> > In contrast, EAFP would look like this:
>
> > try:
> > os.unlink(some_file)
> > except OSError:
> > pass
>
> The two ve
kj wrote:
> For example, LBYL would look like this:
>
> if os.path.isfile(some_file):
> os.unlink(some_file)
>
> In contrast, EAFP would look like this:
>
> try:
> os.unlink(some_file)
> except OSError:
> pass
The two version aren't equal. The first one suffers from a race
conditio
> > You can access the exception object which gives you greater detail.
> >
> > try:
> > os.unlink(some_file)
> > except OSError, e:
> > print e.errno
> > print e.strerror
> >
> > if e.errno == 2:
> > pass
> > else:
> > raise
>
> I do this myself in a lot of plac
In <254eac4d-ce19-4af9-8c6a-5be8e7b0f...@u16g2000pru.googlegroups.com> Sean
DiZazzo writes:
>On Sep 18, 11:54=A0am, kj wrote:
>> I've often come across the idea that good Python style deals with
>> potential errors using an EAFP ("easier to ask forgiveness than
>> permission") strategy rather t
On Sep 18, 3:05 pm, Sean DiZazzo wrote:
> On Sep 18, 11:54 am, kj wrote:
>
>
>
>
>
> > I've often come across the idea that good Python style deals with
> > potential errors using an EAFP ("easier to ask forgiveness than
> > permission") strategy rather than a LBYL ("look before you leap")
> > st
On Sep 18, 11:54 am, kj wrote:
> I've often come across the idea that good Python style deals with
> potential errors using an EAFP ("easier to ask forgiveness than
> permission") strategy rather than a LBYL ("look before you leap")
> strategy.
>
> For example, LBYL would look like this:
>
> if os
13 matches
Mail list logo