Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.linkpendium.com!news.linkpendium.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: Python #ifdef Date: Tue, 28 May 2013 20:42:34 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 53 Message-ID: References: NNTP-Posting-Host: dsl.comtrol.com X-Trace: reader1.panix.com 1369773754 22620 64.122.56.22 (28 May 2013 20:42:34 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Tue, 28 May 2013 20:42:34 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: csiph.com comp.lang.python:46339 On 2013-05-28, Carlos Nepomuceno wrote: > [...] >> You're trying to make this a lot harder than it really is: >> >> if sys.version_info[0] == 3: >> def original(n): >> m = 0 >> for b in n.to_bytes(6, 'big'): >> m = 256*m + b >> return m >> else: >> def original(n): >> > > Haha! That's it!!! > > Just realized how funny this can be: ;) Here's the important lesson from this thread: Instead of asking "how do I write X in Python" where yoy've assumed X is the solution to your problem, you're usually better off asking how to solve the underlying problem in a Pythonic way. IOW, instead of asking about a Python preprocessor (which you have assumed is the solution to the problem because that's how you would do it in C), ask about the actual problem (how to define a function differently depending on Python version). People on this list are very inventive and will expend a surprising amount of time to figure out often too-clever ways to do X because you asked how to do X -- even if doing X is a lousy way to solve your actual problem... When asking how do I solve a problem, it's OK to illustrate that question with an example X of how you would solve it in C or Java or Ruby or Perl or whatever, but remember 1) Not everybody here knows C or Java or Ruby or Perl or whatever, and the person who _does_ know everyting there is to know about solving some particular underlying problem isn't going to go learn a new language so that they can understand your example and figure out what you're trying to accomplish. 2) Programming languages differ. X may be the best way to solve the problem in one language, but it might be an awful way to do it in another language. -- Grant Edwards grant.b.edwards Yow! I'm ANN LANDERS!! at I can SHOPLIFT!! gmail.com