Mercurial > pylearn
comparison doc/v2_planning/coding_style.txt @ 1133:9baa47482ccc
coding_style: Added a few more coding guidelines for compatibility with various Python versions
author | Olivier Delalleau <delallea@iro> |
---|---|
date | Wed, 15 Sep 2010 15:20:13 -0400 |
parents | f0a1b88367b0 |
children | 0653a85ff2e8 |
comparison
equal
deleted
inserted
replaced
1132:f0a1b88367b0 | 1133:9baa47482ccc |
---|---|
364 where MyException inherits from Exception. | 364 where MyException inherits from Exception. |
365 | 365 |
366 * Imports should be listed in alphabetical order. It makes it easier to | 366 * Imports should be listed in alphabetical order. It makes it easier to |
367 verify that something is imported, and avoids duplicated imports. | 367 verify that something is imported, and avoids duplicated imports. |
368 | 368 |
369 * Use absolute imports only. This is compatible across a wider range of | |
370 Python versions, and avoids confusion about what is being | |
371 imported. | |
372 | |
369 * Use a leading underscore '_' for internal attributes / methods, | 373 * Use a leading underscore '_' for internal attributes / methods, |
370 but avoid the double underscore '__' unless you know what you are | 374 but avoid the double underscore '__' unless you know what you are |
371 doing. | 375 doing. |
372 | 376 |
373 * A script's only top-level code should be something like: | 377 * A script's only top-level code should be something like: |
374 if __name__ == '__main__': | 378 if __name__ == '__main__': |
375 sys.exit(main()) | 379 sys.exit(main()) |
380 | |
381 * No conditional expression (not supported in Python 2.4). These are | |
382 expressions of the form | |
383 x = y if condition else z | |
384 | |
385 * Use either "try ... except" or "try ... finally", but do not mix | |
386 "except" with "finally" (which is not supported in Python 2.4). | |
387 | |
388 * Do not use the `any` and `all` builtin functions (they are not supported | |
389 in Python 2.4). | |
390 | |
391 * Do not use the `hashlib` module (not supported in Python 2.4). | |
376 | 392 |
377 Mercurial commits | 393 Mercurial commits |
378 ----------------- | 394 ----------------- |
379 | 395 |
380 * How to write good commit messages? | 396 * How to write good commit messages? |