By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,092 Members | 1,597 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,092 IT Pros & Developers. It's quick & easy.

Has apparent 2.4b1 bug been fixed? flatten in Lib\compiler\ast.py overloads 'list' name

P: n/a
What am I missing? (this is from 2.4b1, so probably it has been fixed?)
def flatten(list):
l = []
for elt in list:
^^^^--must be expecting list instance or other sequence
t = type(elt)
if t is tuple or t is list:
^^^^--looks like it expects to refer to the type, not the arg
for elt2 in flatten(elt):
l.append(elt2)
else:
l.append(elt)
return l
Regards,
Bengt Richter
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Wed, 19 Jan 2005 04:55:53 GMT, bo**@oz.net (Bengt Richter) wrote:
What am I missing? (this is from 2.4b1, so probably it has been fixed?)
I googled and found a bug report, but initial report kind of passes on it
saying nested sequences will probably be tuples, so no panic (my paraphrased description).
So I guess it's in the mill. So never mind. I should have googled first ;-/

def flatten(list):
l = []
for elt in list:
^^^^--must be expecting list instance or other sequence
t = type(elt)
if t is tuple or t is list:
^^^^--looks like it expects to refer to the type, not the arg
for elt2 in flatten(elt):
l.append(elt2)
else:
l.append(elt)
return l


Regards,
Bengt Richter
Jul 18 '05 #2

P: n/a
You have name clashing between Python's built in list function
and the variable called list that you pass into the function.
Change the passed in variable name to something else.

Larry Bates

Try something like (not tested):

def flatten(seq):
l = []
for elt in seq:
if isinstance(elt, (list, tuple):
for elt2 in flatten(elt):
l.append(elt2)
else:
l.append(elt)
return l


Bengt Richter wrote:
What am I missing? (this is from 2.4b1, so probably it has been fixed?)
def flatten(list):
l = []
for elt in list:
^^^^--must be expecting list instance or other sequence
t = type(elt)
if t is tuple or t is list:
^^^^--looks like it expects to refer to the type, not the arg
for elt2 in flatten(elt):
l.append(elt2)
else:
l.append(elt)
return l
Regards,
Bengt Richter

Jul 18 '05 #3

P: n/a
Larry Bates wrote:
You have name clashing between Python's built in list function
and the variable called list that you pass into the function.
Change the passed in variable name to something else.

I believe Bengt was merely seeking confirmation that this was indeed a
bug in a distributed library (which he then provided himself by finding
a bug report). Hence his use of the phrase "overloads 'list' name" in
the subject line!

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.