Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5594
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ethan@stoneleaf.us> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'list)': 0.09; 'message- id:@stoneleaf.us': 0.09; 'okay': 0.09; 'received:gator410.hostgator.com': 0.09; 'subclasses': 0.09; 'this:': 0.11; 'def': 0.13; 'wrote:': 0.14; "'not": 0.16; 'be)': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'input': 0.18; 'cc:2**0': 0.20; 'subject:list': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:addr :python-list': 0.22; '(and': 0.22; 'pass': 0.27; 'function': 0.27; 'looks': 0.28; 'probably': 0.30; 'list': 0.30; 'cc:addr:python.org': 0.31; 'joe': 0.31; "skip:' 10": 0.32; 'change': 0.34; 'print': 0.35; 'header:User-Agent:1': 0.35; 'should': 0.37; 'either': 0.37; 'header:Received:5': 0.40; 'might': 0.40; 'charset:windows-1252': 0.61; 'received:hostgator.com': 0.64; "'you": 0.68; 'received:websitewelcome.com': 0.71; "'and'": 0.84; 'pass:': 0.84; 'received:69.93.164': 0.84; 'received:69.93': 0.91; 'absolutely': 0.98 |
| Date | Tue, 17 May 2011 12:07:44 -0700 |
| From | Ethan Furman <ethan@stoneleaf.us> |
| User-Agent | Thunderbird 1.5.0.10 (Windows/20070221) |
| MIME-Version | 1.0 |
| To | Joe Leonardo <joe.leonardo@datalogix.com> |
| Subject | Re: if statement on lenght of a list |
| References | <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> |
| In-Reply-To | <8F54BE3F56F7A64ABDC3A8164CC83FFA0AB4A096A9@VA3DIAXVS331.RED001.local> |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-AntiAbuse | This header was added to track abuse, please include it with any abuse report |
| X-AntiAbuse | Primary Hostname - gator410.hostgator.com |
| X-AntiAbuse | Original Domain - python.org |
| X-AntiAbuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-AntiAbuse | Sender Address Domain - stoneleaf.us |
| X-Source | |
| X-Source-Args | |
| X-Source-Dir | |
| X-Source-Sender | mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:2790 |
| X-Source-Auth | ethan+stoneleaf.us |
| X-Email-Count | 2 |
| X-Source-Cap | dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== |
| Cc | "python-list@python.org" <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| 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.1694.1305658534.9059.python-list@python.org> (permalink) |
| Lines | 37 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1305658535 news.xs4all.nl 49047 [::ffff:82.94.164.166]:33661 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5594 |
Show key headers only | View raw
Joe Leonardo wrote:
>
> Totally baffled by this…maybe I need a nap. Writing a small function to
> reject input that is not a list of 19 fields.
>
> def breakLine(value):
> if value.__class__() != [] and value.__len__() != 19:
> print 'You must pass a list that contains 19 fields.'
> else:
> print 'YAY!'
>
> If I pass:
>
> breakLine([])
>
> I get:
>
> YAY!
Change your 'and' to an 'or'.
Also, change your 'value.__len__()' to 'len(value)'.
Finally, if you absolutely don't want any iterable that might work (such
as a tuple), change 'value.__class__() != []' to either 'type(value) !=
list' or, if subclasses are okay (and they probably should be) 'not
isinstance(value, list)'.
Incorporating these suggestions looks like this:
def breakLine(value):
if not isinstance(value, list) or len(value) != 19:
print 'You must pass a list that contains 19 fields.'
else:
print 'YAY!'
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: if statement on lenght of a list Ethan Furman <ethan@stoneleaf.us> - 2011-05-17 12:07 -0700
csiph-web