Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5026

Re: Inconsistency with split() - Script, OS, or Package Problem?

Path csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.dougwise.org!news-transit.tcx.org.uk!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'dictionary': 0.07; 'snippet': 0.07; 'terry': 0.07; 'python': 0.07; ':-)': 0.07; 'dict': 0.09; 'investigate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:Problem': 0.09; 'valueerror:': 0.09; 'wrong,': 0.09; 'pm,': 0.11; '>>>': 0.12; '25,': 0.12; 'def': 0.13; 'wrote:': 0.14; "'no": 0.16; "'w')": 0.16; 'coded': 0.16; 'debugging,': 0.16; 'input,': 0.16; 'installs': 0.16; 'keys.': 0.16; 'reedy': 0.16; 'subject:split': 0.16; 'underscore': 0.16; 'unpack': 0.16; 'invalid': 0.16; 'traceback': 0.16; '(most': 0.16; 'source.': 0.19; 'programming': 0.20; 'jan': 0.22; 'code': 0.22; 'header:In- Reply-To:1': 0.22; 'last):': 0.23; 'fix': 0.24; 'index': 0.25; 'creating': 0.26; 'script': 0.26; 'tried': 0.27; 'string': 0.29; 'subject:?': 0.29; 'fine.': 0.29; 'iterating': 0.31; 'offending': 0.31; 'does': 0.31; "skip:' 10": 0.32; 'to:addr:python-list': 0.32; 'source': 0.32; 'skip:e 20': 0.33; 'creates': 0.33; 'several': 0.33; 'using': 0.34; 'header:X-Complaints-To:1': 0.34; 'skip:" 10': 0.34; 'actually': 0.34; 'decide': 0.34; 'file': 0.35; 'print': 0.35; 'question': 0.35; 'finding': 0.35; 'header:User- Agent:1': 0.35; 'point': 0.35; '"",': 0.35; 'fails': 0.35; 'wright': 0.35; 'quite': 0.36; 'hello,': 0.36; 'report': 0.37; 'data': 0.37; 'some': 0.37; 'should': 0.37; 'subject:with': 0.37; 'received:org': 0.38; 'though': 0.38; 'ok,': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'could': 0.39; 'header:Mime- Version:1': 0.39; 'add': 0.39; 'works': 0.40; 'would': 0.40; 'header:Received:5': 0.40; 'might': 0.40; 'split': 0.60; 'simple': 0.60; 'manner': 0.63; 'remember': 0.65; 'here': 0.65; 'believe': 0.66; 'failure': 0.71; 'lucky': 0.74; 'subject:Package': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Inconsistency with split() - Script, OS, or Package Problem?
Date Mon, 09 May 2011 16:46:02 -0400
References <BANLkTi=g2h_BxZDdTdLqyB3nZCukD+Dupw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host rain.gmane.org
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10
In-Reply-To <BANLkTi=g2h_BxZDdTdLqyB3nZCukD+Dupw@mail.gmail.com>
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.1357.1304973976.9059.python-list@python.org> (permalink)
Lines 69
NNTP-Posting-Host 82.94.164.166
X-Trace 1304973977 news.xs4all.nl 81481 [::ffff:82.94.164.166]:39211
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5026

Show key headers only | View raw


On 5/9/2011 2:10 PM, 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

What this means is that at some point you tried to split a string that 
does not have an underscore to print on.

 >>> [s,_] = 'no underscore'.split('_',1)
Traceback (most recent call last):
   File "<pyshell#1>", line 1, in <module>
     [s,_] = 'no underscore'.split('_',1)
ValueError: need more than 1 value to unpack

> The OS's are various OpenSuse installs from 10.3 to 11.4.  It works on
> all the existing ones, which leads me to believe that I have a package
> or configuration inconsistency. It should be noted though that I am
> quite new to python programming and very well could have coded in a
> non-portable manner and was just lucky to get it working in the first
> place :)

Your code is fine. The question is,"How could, or why, would new 
installs result in invalid inputs?"

> Here is the code snippet that generates the failure (  when you look
> at this remember that I am a novice :-)  ):
>
> for each_item in D4:  #D4 is a dictionary
>      create_report_index(each_item)

I might write 'for key in D4:' which makes it obvious that D4 is a dict 
and that you are iterating through its keys. Or 'for report_name...'

> def create_report_index(report):  #Here we are creating a simple
> index.html file from data in a text file
>      newfile = open(report + '.html', 'w') #Create the index file using
> report name
>      for each_value in D4[report]:

For debugging, add
            if '_' not in each_value:
               print(report, D4[report], each_value

>          [clean_name, _] = each_value.split('_', 1)
>          newfile.write('<a href="' + report +'//' + each_value +
> '/index.htm">' + clean_name +'</a><BR>\n')

Once you find the offending input, then investigate its source in the 
code that creates D4. Your other questions are premature. If a 
no_underscore each_value is wrong, fix the source. If you decide that 
such are actually ok, then fix the code above:

     if '_' in each_value:
         clean_name = each_value.split('_', 1)
     else:
         clean_name = each_value

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Inconsistency with split() - Script, OS, or Package Problem? Terry Reedy <tjreedy@udel.edu> - 2011-05-09 16:46 -0400

csiph-web