1 |
-----BEGIN PGP SIGNED MESSAGE----- |
2 |
Hash: SHA256 |
3 |
|
4 |
On 10/11/14 19:21, Zac Medico wrote: |
5 |
> Well, you'll have to clarify what's so "terrible" about it. Note that I didn't |
6 |
> use os.path.isdir or similar because those functions hide all kinds of relevant |
7 |
> exceptions, such as EACCES. |
8 |
I wish there were a more declarative way of expressing this in Python. |
9 |
It's extremely imperative. |
10 |
|
11 |
> If it's the continue and break that upset you, we can do it like this: |
12 |
> |
13 |
> found_dir = False |
14 |
> while current_dir != os.sep and not found_dir: |
15 |
> try: |
16 |
> os.stat(current_dir) |
17 |
> found_dir = True |
18 |
> except OSError: |
19 |
> if errno == errno.ENOENT: |
20 |
> current_dir = \ |
21 |
> os.path.dirname(current_dir) |
22 |
> else: |
23 |
> found_dir = True |
24 |
That's a little better -- I'd prefer that. Thanks. |
25 |
- -- |
26 |
Alexander |
27 |
bernalex@g.o |
28 |
https://secure.plaimi.net/~alexander |
29 |
-----BEGIN PGP SIGNATURE----- |
30 |
Version: GnuPG v2 |
31 |
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ |
32 |
|
33 |
iF4EAREIAAYFAlRhIPkACgkQRtClrXBQc7WTpQD7BYE1+KdV8XG4h0JghIJ/dP4v |
34 |
17isaVatmFdoSQdtwEsA/RXXK33wyWxR4yN0HDENtU5peRJPU/u/eRA/lobm31j9 |
35 |
=jLaK |
36 |
-----END PGP SIGNATURE----- |