Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed5.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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '>>>>': 0.09; 'subject:Problem': 0.09; 'valueerror:': 0.09; 'pm,': 0.11; '25,': 0.12; 'wrote:': 0.14; 'brackets,': 0.16; 'installs': 0.16; 'subject:split': 0.16; 'underscore': 0.16; 'underscore.': 0.16; 'unpack': 0.16; 'traceback': 0.16; '(most': 0.16; 'thanks,': 0.17; 'wrap': 0.19; 'header:In-Reply-To:1': 0.22; 'issue.': 0.22; 'mon,': 0.22; 'issue,': 0.23; 'last):': 0.23; 'script': 0.26; 'url:mailman': 0.27; 'message-id:@mail.gmail.com': 0.28; 'subject:?': 0.29; 'fine.': 0.29; 'least': 0.30; 'all:': 0.31; 'however,': 0.31; 'to:addr:python-list': 0.32; 'thank': 0.32; 'url:listinfo': 0.33; 'skip:e 20': 0.33; 'several': 0.33; 'using': 0.34; 'skip:" 10': 0.34; 'there': 0.35; 'file': 0.35; 'finding': 0.35; '"",': 0.35; 'fails': 0.35; 'wright': 0.35; 'allow': 0.36; 'hello,': 0.36; 'possibility': 0.36; 'think': 0.36; 'problem.': 0.36; 'data': 0.37; 'some': 0.37; 'case': 0.37; 'url:python': 0.37; 'subject:with': 0.37; 'steven': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'though,': 0.39; 'to:addr:python.org': 0.39; 'works': 0.40; "it's": 0.40; 'header:Received:5': 0.40; 'hand': 0.61; 'reply': 0.61; '2011': 0.62; 'received:74.125.83': 0.69; 'subject:Package': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=ebspKEZvhPtz+VQiBeVXvOxZ/0hHNZMe8LVHpPQYjVs=; b=vbiRaZEfBEbEvXl1ybh/xG2KS1NRiY0IRfLX8L8HZ0/olqo/ev+/Q1qSu88Lf0N8u5 3ybszbKTVhfkHhErJOdK2q3s5QkUQJ2qvv2xZ7sWizCwnnpVpzQXAlVvi2SkVAP/zEFx 5O8a7ldfITwA5MdBPnrOVHH/ALJwafD7J7F04= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=yGrVt24/vlk9wGvsfzJAaBtYNnTWcpGJe080bAiC32NfZ/9bwZjMDbCqQJcJyCGrAU wTzJJKLrFeKtGyLYfxWX4dVCkotSl34f68WS8K9jmeR2RLvW6Olou884yROozKf2mywF W+5rLhXp2NL/MVkU6WWOKcvsyL4lGavgVq1VI= MIME-Version: 1.0 In-Reply-To: <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> References: <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 9 May 2011 15:09:32 -0400 Subject: Re: Inconsistency with split() - Script, OS, or Package Problem? From: James Wright To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 59 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1304968176 news.xs4all.nl 81482 [::ffff:82.94.164.166]:51000 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5008 Thank you Steven, I will take your advice :) In this particular case though, I do not think a lack of underscore is the issue, at least as far as I can understand the issue. Please see my reply to Ethan. Thanks, James On Mon, May 9, 2011 at 2:43 PM, Steven D'Aprano wrote: > On Mon, 09 May 2011 14:10:21 -0400, James Wright wrote: > >> Hello, >> >> I have been using a script on several boxes that have been around for a >> while, and everything works just fine. =A0I am finding though, that on >> some new OS installs the script fails with: >> >> Traceback (most recent call last): >> =A0 File "render4.py", line 114, in >> =A0 =A0 create_report_index(each_item) >> =A0 File "render4.py", line 25, in create_report_index >> =A0 =A0 [clean_name, _] =3D each_value.split('_', 1) >> ValueError: need more than 1 value to unpack > > It's a data issue, not an OS or package problem. > > Firstly, you don't have to wrap the left hand side in brackets, this > works fine: > >>>> each_value =3D "aaa_bbb_ccc" >>>> clean_name, _ =3D each_value.split('_', 1) >>>> clean_name > 'aaa' > > > However, if your data has no underscore at all: > >>>> each_value =3D "aaa*bbb*ccc" >>>> clean_name, _ =3D each_value.split('_', 1) > Traceback (most recent call last): > =A0File "", line 1, in > ValueError: need more than 1 value to unpack > > > > So you need to allow for the possibility that there is no underscore. > > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list >