Discussion:
[Tutor] About using list in a function
Michelle Meiduo Wu
2015-08-19 16:09:15 UTC
Permalink
Hi there,
I'm trying to use List in a function. But it doesn't work. Here are sample code not work: ---------------------------------------def getResult(): ls = [] ls= ls.append(100) ls= ls.append(200) return ls
reList = []reList = getResult()lsLength = len(reList)print '\n The length of the list is:' + str(lsLength)-----------------------------------------I ran the above code, there is an error message: AttributeError: 'NoneType' object has no attribute 'append'
But the code below not using list in a function works.----------------------------------------------### This works:ls = []ls.append(100)ls.append(200)lsLength = len(ls)print '\n list length is: ' + str(lsLength)----------------------------------------------------- Do you know the reason?
Thank you,Michelle


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Steven D'Aprano
2015-08-19 17:05:53 UTC
Permalink
Hi Michaelle, and welcome.
Hi there, I'm trying to use List in a function. But it doesn't work.
---------------------------------------
ls = []
ls = ls.append(100)
That line above is your problem. The append() method should be thought
of as a procedure that acts in place, not a function which returns a
value. So the line:

ls = ls.append(100)

sets ls to None, a special value that means "no result". Instead, you
should write this:

def getResult():
ls = []
ls.append(100)
ls.append(200)
return ls


Or you can make that even shorter:

def getResult():
ls = [100, 200]
return ls
--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Steven D'Aprano
2015-08-19 17:11:49 UTC
Permalink
Post by Steven D'Aprano
Hi Michaelle, and welcome.
Oops, sorry for the typo, I meant Michelle.
--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-08-19 17:25:56 UTC
Permalink
Post by Michelle Meiduo Wu
Hi there,
I'm trying to use List in a function. But it doesn't work. Here are sample code not work: ---------------------------------------def getResult(): ls = [] ls= ls.append(100) ls= ls.append(200) return ls
reList = []reList = getResult()lsLength = len(reList)print '\n The length of the list is:' + str(lsLength)-----------------------------------------I ran the above code, there is an error message: AttributeError: 'NoneType' object has no attribute 'append'
But the code below not using list in a function works.----------------------------------------------### This works:ls = []ls.append(100)ls.append(200)lsLength = len(ls)print '\n list length is: ' + str(lsLength)----------------------------------------------------- Do you know the reason?
Thank you,Michelle
As you can (hopefully!) see above, this message is completely scrambled.
Normally that means HTML. But the headers suggest it is plain text.
Also, I see that Steve replied with a correctly formatted inclusion.

Did anyone else get the scrambled version?
And does anyone have any clues why I did?

(Using Thunderbird v31.8 and normally not having major issues.)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Laura Creighton
2015-08-19 18:16:23 UTC
Permalink
Post by Alan Gauld
Post by Michelle Meiduo Wu
Hi there,
I'm trying to use List in a function. But it doesn't work. Here are sample code not work: ---------------------------------------def getResult(): ls = [] ls= ls.append(100) ls= ls.append(200) return ls
reList = []reList = getResult()lsLength = len(reList)print '\n The length of the list is:' + str(lsLength)-----------------------------------------I ran the above code, there is an error message: AttributeError: 'NoneType' object has no attribute 'append'
But the code below not using list in a function works.----------------------------------------------### This works:ls = []ls.append(100)ls.append(200)lsLength = len(ls)print '\n list length is: ' + str(lsLength)----------------------------------------------------- Do you know the reason?
Thank you,Michelle
As you can (hopefully!) see above, this message is completely scrambled.
Normally that means HTML. But the headers suggest it is plain text.
Also, I see that Steve replied with a correctly formatted inclusion.
Did anyone else get the scrambled version?
And does anyone have any clues why I did?
(Using Thunderbird v31.8 and normally not having major issues.)
I got scrambled, same as you.

Laura

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Laura Creighton
2015-08-19 18:19:40 UTC
Permalink
Scrambled in the archives, too
https://mail.python.org/pipermail/tutor/2015-August/106528.html
And looks like something thought it would be best as only one line of
text.

Laura
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Marc Tompkins
2015-08-19 18:20:12 UTC
Permalink
Post by Alan Gauld
Post by Michelle Meiduo Wu
Hi there,
I'm trying to use List in a function. But it doesn't work. Here are
sample code not work: ---------------------------------------def
getResult(): ls = [] ls= ls.append(100) ls= ls.append(200)
return ls
reList = []reList = getResult()lsLength = len(reList)print '\n The length
of the list is:' + str(lsLength)-----------------------------------------I
ran the above code, there is an error message: AttributeError: 'NoneType'
object has no attribute 'append'
But the code below not using list in a function
works.----------------------------------------------### This works:ls =
[]ls.append(100)ls.append(200)lsLength = len(ls)print '\n list length is: '
+ str(lsLength)----------------------------------------------------- Do you
know the reason?
Thank you,Michelle
As you can (hopefully!) see above, this message is completely scrambled.
Normally that means HTML. But the headers suggest it is plain text.
Also, I see that Steve replied with a correctly formatted inclusion.
Did anyone else get the scrambled version?
And does anyone have any clues why I did?
(Using Thunderbird v31.8 and normally not having major issues.)
Same here, using Gmail and usually pretty happy with it.
Completely off-topic: why such an old version of TBird? I have some
clients (the local office of a large multinational) who need to communicate
with corporate... but corporate IT hasn't dropped SSL 3.0 yet, so they
can't upgrade past version 33. (Every couple of weeks, despite my repeated
attempts to stop TBird from auto-updating, I find that they've got a new
version and can't connect. Fortunately Mozilla hasn't changed their DB
format, so I can just re-install 33.) Anyway, I know why _they_ are using
an old, less-secure version, but I'm curious why anybody else would be.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Emile van Sebille
2015-08-19 18:36:34 UTC
Permalink
Post by Marc Tompkins
(Every couple of weeks, despite my repeated
attempts to stop TBird from auto-updating, I find that they've got a new
version and can't connect. Fortunately Mozilla hasn't changed their DB
format, so I can just re-install 33.) Anyway, I know why _they_ are using
an old, less-secure version, but I'm curious why anybody else would be.
We're stuck on 29 due to some ECMAScript compatibility issues with
existing internal servers. We keep users from upgrading by configuring
all user workstations to update only from an internal server where we
have only approved compatible sources/packages.

Emile



_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Marc Tompkins
2015-08-19 21:14:55 UTC
Permalink
Post by Emile van Sebille
Post by Marc Tompkins
(Every couple of weeks, despite my repeated
attempts to stop TBird from auto-updating, I find that they've got a new
version and can't connect. Fortunately Mozilla hasn't changed their DB
format, so I can just re-install 33.) Anyway, I know why _they_ are using
an old, less-secure version, but I'm curious why anybody else would be.
We're stuck on 29 due to some ECMAScript compatibility issues with
existing internal servers.
Interesting. There are eight million stories in the naked city; I wonder
how many stories there are behind old software versions? =D
Post by Emile van Sebille
We keep users from upgrading by configuring all user workstations to
update only from an internal server where we have only approved compatible
sources/packages.
I only dream of having that sort of control. Ah well.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-08-19 23:37:17 UTC
Permalink
Post by Alan Gauld
Post by Michelle Meiduo Wu
Hi there,
I'm trying to use List in a function. But it doesn't work. Here are
sample code not work: ---------------------------------------def
As you can (hopefully!) see above, this message is completely scrambled.
OK, Looks like I wasn't alone.

Steven,
if you are still reading this can you confirm whether
you got a formatted version or manually unscrambled it?

Or can anyone explain why an apparently plain-text
message got mangled?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Laura Creighton
2015-08-20 00:10:15 UTC
Permalink
Post by Alan Gauld
Post by Alan Gauld
Post by Michelle Meiduo Wu
Hi there,
I'm trying to use List in a function. But it doesn't work. Here are
sample code not work: ---------------------------------------def
As you can (hopefully!) see above, this message is completely scrambled.
OK, Looks like I wasn't alone.
Steven,
if you are still reading this can you confirm whether
you got a formatted version or manually unscrambled it?
Or can anyone explain why an apparently plain-text
message got mangled?
Her mailer appears to have sent out a plain text message where the
whole message was one line with no newlines/returns. So if her
mailer is set up to automatically remove them ...

Forums do this often but this is the first time I can recall seeing
this in email.

Laura

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Mark Lawrence
2015-08-20 13:49:11 UTC
Permalink
Post by Alan Gauld
Post by Michelle Meiduo Wu
Hi there,
I'm trying to use List in a function. But it doesn't work. Here are
sample code not work: ---------------------------------------def
getResult(): ls = [] ls= ls.append(100) ls=
ls.append(200) return ls
reList = []reList = getResult()lsLength = len(reList)print '\n The
length of the list is:' +
str(lsLength)-----------------------------------------I ran the above
code, there is an error message: AttributeError: 'NoneType' object has
no attribute 'append'
But the code below not using list in a function
works.----------------------------------------------### This works:ls
= []ls.append(100)ls.append(200)lsLength = len(ls)print '\n list
length is: ' +
str(lsLength)----------------------------------------------------- Do
you know the reason?
Thank you,Michelle
As you can (hopefully!) see above, this message is completely scrambled.
Normally that means HTML. But the headers suggest it is plain text.
Also, I see that Steve replied with a correctly formatted inclusion.
Did anyone else get the scrambled version?
And does anyone have any clues why I did?
(Using Thunderbird v31.8 and normally not having major issues.)
Scrambled using Thunderbird 38.2.0 on Windows 10.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
D Wyatt
2015-09-10 22:46:18 UTC
Permalink
Scrambled on gmail here too.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Mark Lawrence
2015-09-12 03:16:20 UTC
Permalink
Post by D Wyatt
Scrambled on gmail here too.
Please provide some context when you reply, thanks.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Loading...