Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5008
| References | <mailman.1338.1304964624.9059.python-list@python.org> <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2011-05-09 15:09 -0400 |
| Subject | Re: Inconsistency with split() - Script, OS, or Package Problem? |
| From | James Wright <jamfwright@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1342.1304968176.9059.python-list@python.org> (permalink) |
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
<steve+comp.lang.python@pearwood.info> 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. I am finding though, that on
>> some new OS installs the script fails with:
>>
>> Traceback (most recent call last):
>> File "render4.py", line 114, in <module>
>> create_report_index(each_item)
>> File "render4.py", line 25, in create_report_index
>> [clean_name, _] = 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 = "aaa_bbb_ccc"
>>>> clean_name, _ = each_value.split('_', 1)
>>>> clean_name
> 'aaa'
>
>
> However, if your data has no underscore at all:
>
>>>> each_value = "aaa*bbb*ccc"
>>>> clean_name, _ = each_value.split('_', 1)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> 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
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Inconsistency with split() - Script, OS, or Package Problem? James Wright <jamfwright@gmail.com> - 2011-05-09 14:10 -0400
Re: Inconsistency with split() - Script, OS, or Package Problem? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-09 18:43 +0000
Re: Inconsistency with split() - Script, OS, or Package Problem? James Wright <jamfwright@gmail.com> - 2011-05-09 15:09 -0400
Re: Inconsistency with split() - Script, OS, or Package Problem? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-10 00:00 +0000
csiph-web