Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65811 > unrolled thread
| Started by | thomas.lehmann@adtech.com |
|---|---|
| First post | 2014-02-10 03:39 -0800 |
| Last post | 2014-02-10 10:36 -0500 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.python
Pylint across Python versions thomas.lehmann@adtech.com - 2014-02-10 03:39 -0800
Re: Pylint across Python versions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-10 13:03 +0000
Re: Pylint across Python versions Chris Angelico <rosuav@gmail.com> - 2014-02-11 00:59 +1100
Re: Pylint across Python versions Ned Batchelder <ned@nedbatchelder.com> - 2014-02-10 10:36 -0500
| From | thomas.lehmann@adtech.com |
|---|---|
| Date | 2014-02-10 03:39 -0800 |
| Subject | Pylint across Python versions |
| Message-ID | <317fd2a4-186b-4b97-ad7f-084609d0a9a4@googlegroups.com> |
Hi,
somebody who can tell me about pylint experiences across
different Python version.
Example:
I'm using a construct like this:
if sys.version.startswith("3."):
unicode = str
The reason is that Python 3 does not have this
function anymore but pylint yells for Python < 3
about redefinition also it does not happen.
How to get forward with this?
Regards,
Thomas
[toc] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-02-10 13:03 +0000 |
| Message-ID | <mailman.6620.1392037432.18130.python-list@python.org> |
| In reply to | #65811 |
On 10/02/2014 11:39, thomas.lehmann@adtech.com wrote:
> Hi,
>
> somebody who can tell me about pylint experiences across
> different Python version.
>
> Example:
> I'm using a construct like this:
>
> if sys.version.startswith("3."):
> unicode = str
>
> The reason is that Python 3 does not have this
> function anymore but pylint yells for Python < 3
> about redefinition also it does not happen.
I've no idea what the above is saying but see below anyway.
>
> How to get forward with this?
>
> Regards,
> Thomas
>
>>> import sys
>>> sys.version
'3.4.0b2 (v3.4.0b2:ba32913eb13e, Jan 5 2014, 16:23:43) [MSC v.1600 32
bit (Intel)]'
>>> sys.version.startswith('3.')
True
>>>
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-02-11 00:59 +1100 |
| Message-ID | <mailman.6621.1392040780.18130.python-list@python.org> |
| In reply to | #65811 |
On Mon, Feb 10, 2014 at 10:39 PM, <thomas.lehmann@adtech.com> wrote:
> Example:
> I'm using a construct like this:
>
> if sys.version.startswith("3."):
> unicode = str
>
> The reason is that Python 3 does not have this
> function anymore but pylint yells for Python < 3
> about redefinition also it does not happen.
>
> How to get forward with this?
It's more common to spell that with a try/except. Does pylint complain
if you use this instead?
try:
unicode
except NameError:
unicode = str
Although it would be better to write your code for Python 3, and have
compatibility code at the top for Python 2. That would mean using
'str' everywhere, and then having this at the top:
try:
str = unicode
except NameError:
pass
That way, when you're ready to drop support for Python 2, you simply
delete the compat code and everything works. Otherwise, you have to
maintain messy code indefinitely.
Alternatively, to avoid redefinition at all, you could use your own
name everywhere:
try:
unicode_string = unicode
except NameError:
unicode_string = str
Use something less unwieldy if you prefer, but this avoids any chance
of collision :)
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-02-10 10:36 -0500 |
| Message-ID | <mailman.6629.1392046619.18130.python-list@python.org> |
| In reply to | #65811 |
On 2/10/14 6:39 AM, thomas.lehmann@adtech.com wrote:
> Hi,
>
> somebody who can tell me about pylint experiences across
> different Python version.
>
> Example:
> I'm using a construct like this:
>
> if sys.version.startswith("3."):
> unicode = str
>
> The reason is that Python 3 does not have this
> function anymore but pylint yells for Python < 3
> about redefinition also it does not happen.
>
> How to get forward with this?
>
> Regards,
> Thomas
>
Pylint may have a difficult time understanding what you are doing here.
You can use pylint comments to tell it to shut up when you know better.
But also, you might find it easier to use the "six" module from PyPI to
handle these sorts of differences. It's easier than doing it ad-hoc
with your own logic.
--
Ned Batchelder, http://nedbatchelder.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web