[Guido] > This does bring up an interesting question: what's the recommended way > to distinguish a certain platform? There's os.name, sys.platform, the > platform module, and I've also seen code testing for os.sep=='/'. I ask myself that question every time I need to do it. Out of sheer momentum now, I almost always use if sys.platform in ('win32',): I dislike using os.name == 'nt', mostly because if we asked all Windows Python users which OS they use, only a tiny percentage would answer "NT". Since NT is a dying OS, 'nt' is an increasingly odd-looking thing to test agaist. OTOH, I have no idea when or why sys.platform == "win32" would give a different result than os.name == "nt". > I still prefer hasattr(<module>, <attribute>) whenever applicable, > e.g. preferring hasattr(os, 'fork') over os.name=='posix' (or > os.name!='nt' :-), but sometimes that's not possible. Like whether to use time.time or time.clock. > What should be the preferred way? (It may be impossible to say > because there are different use cases, but probably one of the most > important cases is simply distinguishing Windows from the rest -- how > should that be done?) My way <wink> -- unless it's broken in some way I haven't bumped into yet.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4