Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28274
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <d@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'attribute': 0.05; "subject:' ": 0.07; 'python': 0.09; 'follows.': 0.09; 'subject:method': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; "'in',": 0.16; "'no',": 0.16; "'of',": 0.16; "'that',": 0.16; "'the',": 0.16; 'subject:object': 0.16; 'wrote:': 0.17; "shouldn't": 0.17; 'working.': 0.17; 'tells': 0.22; 'help.': 0.22; 'cc:2**0': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'tried': 0.25; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'first,': 0.27; "doesn't": 0.28; '>>>>': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; "skip:' 10": 0.30; 'function': 0.30; 'figure': 0.30; 'code': 0.31; 'implement': 0.32; 'more,': 0.32; "skip:' 20": 0.32; 'doubt': 0.33; "can't": 0.34; 'text': 0.34; 'thanks': 0.34; 'list': 0.35; 'follows:': 0.35; 'there': 0.35; 'add': 0.36; 'subject:with': 0.36; 'test': 0.36; 'subject:: ': 0.38; 'object': 0.38; 'received:192': 0.39; 'list,': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'your': 0.60; 'john': 0.60; 'kind': 0.61; 'more': 0.63; 'header:Reply-To:1': 0.68; 'skip:n 30': 0.69; 'subject:The': 0.71; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'special': 0.73; 'subject:skip:A 10': 0.75 |
| Date | Sun, 02 Sep 2012 09:51:15 -0400 |
| From | Dave Angel <d@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 |
| MIME-Version | 1.0 |
| To | "John H. Li" <typetoken@gmail.com> |
| Subject | Re: Fwd: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' |
| References | <58dd6730-9c37-4b90-9dbc-2724300ff5f4@googlegroups.com> <50433EA5.9090302@davea.name> <CAE5RzX=C7x-BXagCwANf+4wqb25eXKMkGs7TwMgSzciNFLDjew@mail.gmail.com> <CAE5RzXmbbOVd8ghoozrgAmQk1sgqVLAS=EVqpwvHPp-Tdiv3Cg@mail.gmail.com> |
| In-Reply-To | <CAE5RzXmbbOVd8ghoozrgAmQk1sgqVLAS=EVqpwvHPp-Tdiv3Cg@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:+gvKVOouUDpyqTFfwH7VSzPzwRDaWAysjFW1U2650rT dxDsf7ZhmyjbpvePIWa0DQMVYHUGXoZuBF8hLsqsySQCWsvgl8 xzrlhsuhYaBNz2unZXtgr5F10IyEz03HO+NP/ARrYjXfMOnJqy NTMYI6ebf+FrK9bO+KT2vtzn91p5v6kgLed23lh1Cbu73sX1V9 cKWvutvJ58/4g43phha/B0BW6rABF5XkbaRMiDCkxjkDQBwp6h vjBzjLbB3BWgCSSQZMFAXzWNOrpdLSuthX39LOiLZRZj7O07a/ /Fg48vRWg8oCFKNY9TbmWl2n4gz9OtEcRCG25+PXPcb1HCdCXB pJ0SqopL5nJz5q+Q1j00= |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | d@davea.name |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.88.1346593882.27098.python-list@python.org> (permalink) |
| Lines | 52 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1346593882 news.xs4all.nl 6970 [2001:888:2000:d::a6]:38615 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:28274 |
Show key headers only | View raw
On 09/02/2012 09:06 AM, John H. Li wrote: > First, thanks very much for your kind help. > > 1)Further more, I test the function of insert. It did work as follows: > >>>> text = ['The', 'Fulton', 'County', 'Grand'] >>>> text.insert(3,'like') >>>> text > ['The', 'Fulton', 'County', 'like', 'Grand'] > 2) I tested the text from nltk. It is list actually. See the following: >>>> text = nltk.corpus.brown.words(categories = 'news') >>>> text[:10] > ['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an', > 'investigation', 'of'] > > How come python tells me that it is not a list by prompting "AttributeError: > 'ConcatenatedCorpusView' object has no attribute 'insert'"? I am confused. > > Since we doubt text is not a list, I have to add one more line of code > there as follows. Then it seems working. >>>> text = nltk.corpus.brown.words(categories = 'news') >>>> def hedge(text): > text = list(text) > for i in range(3,len(text),4): > text.insert(i, 'like') > return text[:50] > >>>> hedge(text) > ['The', 'Fulton', 'County', 'like', 'Grand', 'Jury', 'said', 'like', > 'Friday', 'an', 'investigation', 'like', 'of', "Atlanta's", 'recent', > 'like', 'primary', 'election', 'produced', 'like', '``', 'no', 'evidence', > 'like', "''", 'that', 'any', 'like', 'irregularities', 'took', 'place', > 'like', '.', 'The', 'jury', 'like', 'further', 'said', 'in', 'like', > 'term-end', 'presentments', 'that', 'like', 'the', 'City', 'Executive', > 'like', 'Committee', ','] > > Isn't it odd? > > Without reading the documentation, or at least the help(), I can't figure it to be odd. If a class wants to support slicing semantics, all it has to do is implement special methods like __getslice__ and __setslice__. If it doesn't document .insert(), then you shouldn't try to call it. Duck-typing. What did you get when you tried type(), dir() and help() ? Did they help. -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' Token Type <typetoken@gmail.com> - 2012-09-02 02:39 -0700 Re: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' Dave Angel <d@davea.name> - 2012-09-02 07:10 -0400 Re: Fwd: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' Dave Angel <d@davea.name> - 2012-09-02 09:51 -0400 Re: The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert' Peter Otten <__peter__@web.de> - 2012-09-02 16:12 +0200
csiph-web