Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5000 > unrolled thread
| Started by | James Wright <jamfwright@gmail.com> |
|---|---|
| First post | 2011-05-09 14:10 -0400 |
| Last post | 2011-05-10 00:00 +0000 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.python
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
| From | James Wright <jamfwright@gmail.com> |
|---|---|
| Date | 2011-05-09 14:10 -0400 |
| Subject | Inconsistency with split() - Script, OS, or Package Problem? |
| Message-ID | <mailman.1338.1304964624.9059.python-list@python.org> |
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
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 :)
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)
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]:
[clean_name, _] = each_value.split('_', 1)
newfile.write('<a href="' + report +'//' + each_value +
'/index.htm">' + clean_name + '</a><BR>\n')
I've tried to match packages from a known working install and even
compiled a newer python (one known to work, version 3.1.3 in this
particular case). The only discernible difference is that the new OS
installs are VM's hosted on VMWare ESX. Using the same ISO I can spin
up a VirtualBox VM and the script works just fine. I've tried this
with OpenSuse 11.3 and 11.4, once again, using the exact same ISO's to
install.
Do I have a Python, OS, or package issue?
Many thanks,
James
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2011-05-09 18:43 +0000 |
| Message-ID | <4dc835bd$0$29991$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #5000 |
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
[toc] | [prev] | [next] | [standalone]
| From | James Wright <jamfwright@gmail.com> |
|---|---|
| Date | 2011-05-09 15:09 -0400 |
| Message-ID | <mailman.1342.1304968176.9059.python-list@python.org> |
| In reply to | #5005 |
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
>
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2011-05-10 00:00 +0000 |
| Message-ID | <4dc88022$0$29991$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #5008 |
On Mon, 09 May 2011 15:09:32 -0400, James Wright wrote:
> 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.
In your reply to Ethan, you inserted a print statement in the code and
got this output:
# python render4.py
current each_value is: vsr
Traceback (most recent call last):
File "render4.py", line 115, in <module>
create_report_index(each_item)
File "render4.py", line 26, in create_report_index
[clean_name, _] = each_value.split('_', 1)
ValueError: need more than 1 value to unpack
The current value of each_value is the three letter string "vsr". There
are no underscores in "vsr". Clearly the lack of underscore is the issue.
Now that this has been solved, it has revealed a deeper problem, namely,
how you get an empty key and "vsr" into your data on some machines but
not others.
If your script is behaving differently on different machines with the
same data, it is *far* more likely that there is something non-
deterministic in your code than that it is a bug in either the OS,
Python, or the virtualization environment. Without seeing either your
code or data, it is impossible to know what.
No offense, but are you sure it's not a PEBCAK error? Are you absolutely
sure you're running the same script the same way from the same data on
each virtual machine?
The fact that your script works correctly *once* when you rename it
doesn't strike me with confidence. Renaming the script shouldn't change
its behaviour.
I suppose it is just barely plausible that one of the VMs is reading its
data from faulty sectors on a disk, and hence gets inconsistent results,
but that is stretching the bounds of possibility almost to breaking.
You posted the data and script to Alex off list. Perhaps you could post
it again on-list? As they say, many eyes make bugs shallow.
--
Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web