Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46323 > unrolled thread
| Started by | Matt Graves <tunacubes@gmail.com> |
|---|---|
| First post | 2013-05-28 11:25 -0700 |
| Last post | 2013-05-29 17:54 +1000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
String object has no attribute "append" Matt Graves <tunacubes@gmail.com> - 2013-05-28 11:25 -0700
Re: String object has no attribute "append" "marduk@python.net" <marduk@python.net> - 2013-05-28 14:40 -0400
Re: String object has no attribute "append" Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-28 12:41 -0600
Re: String object has no attribute "append" Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-28 12:43 -0600
Re: String object has no attribute "append" Chris Angelico <rosuav@gmail.com> - 2013-05-29 17:54 +1000
| From | Matt Graves <tunacubes@gmail.com> |
|---|---|
| Date | 2013-05-28 11:25 -0700 |
| Subject | String object has no attribute "append" |
| Message-ID | <8d8143e8-74f3-43a0-9a52-06b60e857984@googlegroups.com> |
I receive this error while toying around with Functions...
def pulldata(speclist,speccolumn):
with open('profiles.csv', 'r') as f:
reader = csv.reader(f)
for column in reader:
(speclist).append(column[('speccolumn')])
pulldata(speclist = 'numbers', speccolumn = "0")
>Traceback (most recent call last):
> File "C:\Desktop\Python\CFI\Devices V2\users.py", line 17, in <module>
> pulldata(speclist = 'numbers', speccolumn = "0")
> File "C:\Desktop\Python\CFI\Devices V2\users.py", line 16, in pulldata
> (speclist).append(column[('speccolumn')])
>AttributeError: 'str' object has no attribute 'append'
I'm getting the error because it should say "numbers.append", but it is reading it as "(speclist).append".
This is my first time playing with functions, so be gentle.
[toc] | [next] | [standalone]
| From | "marduk@python.net" <marduk@python.net> |
|---|---|
| Date | 2013-05-28 14:40 -0400 |
| Message-ID | <mailman.2314.1369766407.3114.python-list@python.org> |
| In reply to | #46323 |
On Tue, May 28, 2013, at 02:25 PM, Matt Graves wrote:
> I receive this error while toying around with Functions...
>
> def pulldata(speclist,speccolumn):
> with open('profiles.csv', 'r') as f:
> reader = csv.reader(f)
> for column in reader:
> (speclist).append(column[('speccolumn')])
>
> pulldata(speclist = 'numbers', speccolumn = "0")
>
>
> >Traceback (most recent call last):
> > File "C:\Desktop\Python\CFI\Devices V2\users.py", line 17, in <module>
> > pulldata(speclist = 'numbers', speccolumn = "0")
> > File "C:\Desktop\Python\CFI\Devices V2\users.py", line 16, in pulldata
> > (speclist).append(column[('speccolumn')])
> >AttributeError: 'str' object has no attribute 'append'
>
> I'm getting the error because it should say "numbers.append", but it is
> reading it as "(speclist).append".
Because it indeed says "(speclist).append"... am I missing something?
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-05-28 12:41 -0600 |
| Message-ID | <mailman.2315.1369766542.3114.python-list@python.org> |
| In reply to | #46323 |
On Tue, May 28, 2013 at 12:25 PM, Matt Graves <tunacubes@gmail.com> wrote:
> I receive this error while toying around with Functions...
>
> def pulldata(speclist,speccolumn):
> with open('profiles.csv', 'r') as f:
> reader = csv.reader(f)
> for column in reader:
> (speclist).append(column[('speccolumn')])
>
> pulldata(speclist = 'numbers', speccolumn = "0")
>
>
>>Traceback (most recent call last):
>> File "C:\Desktop\Python\CFI\Devices V2\users.py", line 17, in <module>
>> pulldata(speclist = 'numbers', speccolumn = "0")
>> File "C:\Desktop\Python\CFI\Devices V2\users.py", line 16, in pulldata
>> (speclist).append(column[('speccolumn')])
>>AttributeError: 'str' object has no attribute 'append'
>
> I'm getting the error because it should say "numbers.append", but it is reading it as "(speclist).append".
>
> This is my first time playing with functions, so be gentle.
It looks like you're trying to pass in a list called 'numbers' into
the pulldata function, but that is not what's happening. Because of
the single quotes you have around numbers, you are passing in the
/string/ 'numbers' and calling it 'speclist' instead. The same goes
for speccolumn as well; I think you mean to pass in the integer 0, but
you're passing in the string "0" instead. Try it without the quotes:
pulldata(speclist = numbers, speccolumn = 0)
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-05-28 12:43 -0600 |
| Message-ID | <mailman.2316.1369766633.3114.python-list@python.org> |
| In reply to | #46323 |
On Tue, May 28, 2013 at 12:41 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Tue, May 28, 2013 at 12:25 PM, Matt Graves <tunacubes@gmail.com> wrote:
>> I receive this error while toying around with Functions...
>>
>> def pulldata(speclist,speccolumn):
>> with open('profiles.csv', 'r') as f:
>> reader = csv.reader(f)
>> for column in reader:
>> (speclist).append(column[('speccolumn')])
>>
>> pulldata(speclist = 'numbers', speccolumn = "0")
>>
>>
>>>Traceback (most recent call last):
>>> File "C:\Desktop\Python\CFI\Devices V2\users.py", line 17, in <module>
>>> pulldata(speclist = 'numbers', speccolumn = "0")
>>> File "C:\Desktop\Python\CFI\Devices V2\users.py", line 16, in pulldata
>>> (speclist).append(column[('speccolumn')])
>>>AttributeError: 'str' object has no attribute 'append'
>>
>> I'm getting the error because it should say "numbers.append", but it is reading it as "(speclist).append".
>>
>> This is my first time playing with functions, so be gentle.
>
> It looks like you're trying to pass in a list called 'numbers' into
> the pulldata function, but that is not what's happening. Because of
> the single quotes you have around numbers, you are passing in the
> /string/ 'numbers' and calling it 'speclist' instead. The same goes
> for speccolumn as well; I think you mean to pass in the integer 0, but
> you're passing in the string "0" instead. Try it without the quotes:
>
> pulldata(speclist = numbers, speccolumn = 0)
And along the same lines, the expression column[('speccolumn')] should
just be column[speccolumn].
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-05-29 17:54 +1000 |
| Message-ID | <mailman.2343.1369814083.3114.python-list@python.org> |
| In reply to | #46323 |
On Wed, May 29, 2013 at 4:25 AM, Matt Graves <tunacubes@gmail.com> wrote:
> I receive this error while toying around with Functions...
>
> def pulldata(speclist,speccolumn):
> (speclist).append(column[('speccolumn')])
>
> pulldata(speclist = 'numbers', speccolumn = "0")
>
> I'm getting the error because it should say "numbers.append", but it is reading it as "(speclist).append".
Others have answered the immediate problem, but you may find this a
worthwhile read:
http://mail.python.org/pipermail/tutor/2010-December/080505.html
It's an excellent explanation of the way Python passes arguments to functions.
ChrisA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web