472,338 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,338 software developers and data experts.

pylint: What's wrong with the builtin map()

#!/usr/bin/python
"""test pydev_0.9.3/../pylint"""
__revision__ = "test_mod 0.1 by TV 06/10/22"

lst = ['aaa', ' bbb', '\tccc\n']
lst = map(lambda x: x.strip(), lst)

result = """
No config file found, using default configuration
************* Module test_mod
W: 6: Used builtin function 'map'
E: 6: Using variable 'x' before assigment
....
"""
Oct 22 '06 #1
5 11028
Tuomas wrote:
#!/usr/bin/python
"""test pydev_0.9.3/../pylint"""
__revision__ = "test_mod 0.1 by TV 06/10/22"

lst = ['aaa', ' bbb', '\tccc\n']
lst = map(lambda x: x.strip(), lst)

result = """
No config file found, using default configuration
************* Module test_mod
W: 6: Used builtin function 'map'
E: 6: Using variable 'x' before assigment
Some people think that all occurences of map() must be replaced
by list comprehensions. The designer of pylint seems to be
one of those.

Georg
Oct 22 '06 #2
Tuomas wrote:
lst = map(lambda x: x.strip(), lst)
list comprehensions are more efficient than map/lambda combinations;
the above is better written as:

lst = [x.strip() for x in lst]

in general, map() works best when the callable is an existing function
(especially if it's a built-in). not sure if pylist is smart enough to
tell the difference, though.

</F>

Oct 22 '06 #3
Georg Brandl wrote:
Some people think that all occurences of map() must be replaced
by list comprehensions. The designer of pylint seems to be
one of those.
So it seems, but why? Formally spoken we ase "using variable 'x' before
assigment" in the comprehension too.

#!/usr/bin/python
"""test pydev_0.9.3/../pylint"""
__revision__ = "test_mod 0.2 by TV 06/10/22"

lst = ['aaa', ' bbb', '\tccc\n']
# lst = (lambda x: x.strip(), lst) # revision 0.1
lst = [x.strip() for x in lst]

result = """revision 0.1:
No config file found, using default configuration
************* Module test_mod
W: 6: Used builtin function 'map'
E: 6: Using variable 'x' before assigment
....

revision 0.2:
....
Your code has been rated at 10.00/10 (previous run: -10.00/10)
"""
Oct 22 '06 #4
Tuomas wrote:
Georg Brandl wrote:
>Some people think that all occurences of map() must be replaced
by list comprehensions. The designer of pylint seems to be
one of those.

So it seems, but why?
See Fredrik's post. There's no error in the expression with map(),
it's just less effective than a LC, but only if used with a
lambda.
Formally spoken we ase "using variable 'x' before
assigment" in the comprehension too.
That's another issue. I'd suggest a bug in pylint. (You probably
have a variable called "x" later in the file.

My version of pylint (0.12.1) doesn't show this "error".

Georg
Oct 22 '06 #5
Tuomas wrote:
#!/usr/bin/python
"""test pydev_0.9.3/../pylint"""
__revision__ = "test_mod 0.1 by TV 06/10/22"

lst = ['aaa', ' bbb', '\tccc\n']
lst = map(lambda x: x.strip(), lst)

result = """
No config file found, using default configuration
************* Module test_mod
W: 6: Used builtin function 'map'
E: 6: Using variable 'x' before assigment
...
"""
In addition to what the others said, note that pylint is entirely configurable.
If you don't want to be bothered with warnings about map() which you are going
to ignore, a simple modification to the pylint configuration file will prevent
it from doing that check.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python...
4
by: Michael Yanowitz | last post by:
Hello: I ran the new pylint and my code and I had a few questions on why those are warnings or what I can do to fix them: 1) W: 0: Too many...
7
by: montyphyton | last post by:
Some recent posts about Python programming style got me thinking. Since we have the PEP 8 which gives some guidelines about the style to be used,...
2
by: lgfang | last post by:
Hi, I think this is a bug of pylint.el. But I failed finding a way to submit the bug neither in its official site nor in google. So I post it...
2
by: Mick Charles Beaver | last post by:
Hello, I've been looking into using PyLint on some of my programs, just as a best practices kind of thing. Here's a snippet:...
2
by: dmitrey | last post by:
Hi all, I have Eric 4.1.1, pylint and Eric pylint plugin installed, but I cannot find how to use pylint from Eric IDE GUI. Does anyone know? ...
1
by: Stefan Rank | last post by:
on 31.07.2008 11:29 Diez B. Roggisch said the following: <snip> <snip> Three installations of pylint 0.14.0 that I have access to from here: ...
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected...
2
by: GHUM | last post by:
Hello, I am pylinting some software of mine. Now pylint throws messages, and I know of pylint --help-msg to get some more text. What is...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.