Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '16,': 0.03; 'attribute': 0.07; 'column': 0.07; 'lines,': 0.07; 'string': 0.09; 'function,': 0.09; 'quotes:': 0.09; 'def': 0.12; '"0"': 0.16; 'subject:String': 0.16; 'subject:object': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'passing': 0.19; '>>>': 0.22; 'error': 0.23; 'instead.': 0.24; 'integer': 0.24; 'looks': 0.24; 'skip:" 30': 0.26; 'pass': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; 'skip:( 40': 0.30; 'message-id:@mail.gmail.com': 0.30; 'along': 0.30; "i'm": 0.30; 'getting': 0.31; 'quotes': 0.31; 'file': 0.32; '(most': 0.33; 'reader': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'skip:> 10': 0.36; 'should': 0.36; 'list': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'expression': 0.60; 'ian': 0.60; 'subject:"': 0.60; "you're": 0.61; 'first': 0.61; 'receive': 0.70; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=9PNzrC8ZQDXgRdIvm+sFvJof/usrxEQfurKXQSxVKkQ=; b=QmIuBwZdgnxokfm591D/4rxuV/ra+NnzVX8S4OGCNKVgbnbawUl7WRN0yigQ7b80iW xaNx/YjuNNb1w629Z0SiqmiRXWBajQRhK5tQ6OaKzWXaxqT1zJWCbtsOUUGHHTL74myu 1vXsuS+eEgwauMNRRKcHQAuC+t4CupK2WWxdqizGbfyb0vNdGg0NCWu5ats9eKzYTtxL YV6ThA1Wa2pk6oniijKphjrInVlV/1V5L9xPbPRtc2D64jvoDhHmx+wzOdWQ7pCP8uY+ OD8/qxXnl6rL+58HWuUvzDr0wT3WZxvc7Dyc2tYRw+i/Y4lvJ2pB8fHiohPe25CgXhGv J+4A== X-Received: by 10.68.176.197 with SMTP id ck5mr30504192pbc.165.1369766630077; Tue, 28 May 2013 11:43:50 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <8d8143e8-74f3-43a0-9a52-06b60e857984@googlegroups.com> From: Ian Kelly Date: Tue, 28 May 2013 12:43:10 -0600 Subject: Re: String object has no attribute "append" To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369766633 news.xs4all.nl 15886 [2001:888:2000:d::a6]:43664 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46326 On Tue, May 28, 2013 at 12:41 PM, Ian Kelly wrote: > On Tue, May 28, 2013 at 12: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 >>> 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].