On 12/14/2015 11:38 PM, Vincent Davis wrote:
In the code below try is used to check if handle has the attribute name. It
seems an if statement could be used. Is there reason one way would be
better than another?
def write_header(self):
handle = self.handle
try:
On Tue, Dec 15, 2015 at 10:48 AM, Vincent Davis
wrote:
> try:
> write = handel.write
> except AttributeError:
> raise
Just "write = handel.write" :)
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
On Mon, Dec 14, 2015 at 4:14 PM, Cameron Simpson wrote:
> First, notice that the code inside the try/except _only_ fetches the
> attribute. Your version calls the "write" attribute, and also accesses
> handle.name. Either of those might also emit AttributeError, and should
>
On Mon, Dec 14, 2015 at 4:48 PM, Vincent Davis wrote:
> On Mon, Dec 14, 2015 at 4:14 PM, Cameron Simpson wrote:
>
>> First, notice that the code inside the try/except _only_ fetches the
>> attribute. Your version calls the "write" attribute, and also
On Mon, Dec 14, 2015 at 4:53 PM, Ian Kelly wrote:
>
> Except that catching an exception just to immediately re-raise it is
> silly. This would be better:
>
> try:
> name = handle.name
> except AttributeError:
> pass
> else:
> handle.write("# Report_file: %s\n"
On 15Dec2015 17:11, Cameron Simpson wrote:
On 14Dec2015 16:48, Vincent Davis wrote:
[...]
I think the intent of the original code was to check if handle had the
attribute "name", I don't think the attribute "write" was the issue.
[...]
Secondly,
On 14Dec2015 16:48, Vincent Davis wrote:
On Mon, Dec 14, 2015 at 4:14 PM, Cameron Simpson wrote:
First, notice that the code inside the try/except _only_ fetches the
attribute. Your version calls the "write" attribute, and also accesses
In the code below try is used to check if handle has the attribute name. It
seems an if statement could be used. Is there reason one way would be
better than another?
def write_header(self):
handle = self.handle
try:
handle.write("# Report_file: %s\n" % handle.name)
except
On Mon, Dec 14, 2015 at 3:38 PM, Vincent Davis wrote:
> In the code below try is used to check if handle has the attribute name. It
> seems an if statement could be used. Is there reason one way would be
> better than another?
http://www.oranlooney.com/lbyl-vs-eafp/
--
On 14Dec2015 15:38, Vincent Davis wrote:
In the code below try is used to check if handle has the attribute name. It
seems an if statement could be used.
Only by using hasattr(), which IIRC does a try/except internally.
Is there reason one way would be
better than
Vincent Davis writes:
> In the code below try is used to check if handle has the attribute name. It
> seems an if statement could be used. Is there reason one way would be
> better than another?
The Python community refers to the difference by contrasting “look
before
11 matches
Mail list logo