Python crashes when walking backwards through output items

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Python crashes when walking backwards through output items

la volta statistics

Hi,

if I want to walk through the items in a Outputdoc, I can do that without problems with a range command.

However, walking backwards, that is, starting at the last item, makes python crash.

Is there a way I can access the last pivot table in the output without going through all the items I have in my Outputdoc.

 

I use SPSS 18.1

 

Thanks in advances

Christian

 

**********************

This example works:

**********************

 

import SpssClient

SpssClient.StartClient()

OutputDoc = SpssClient.GetDesignatedOutputDoc()

OutputItems = OutputDoc.GetOutputItems()

i = OutputItems.Size()   #counts the items

 

for index in range(i):

    OutputItem = OutputItems.GetItemAt(index)

    print OutputItem.GetType()

 

SpssClient.StopClient()

 

 

Prints:

SpssClient.OutputItemType.ROOT

SpssClient.OutputItemType.LOG

SpssClient.OutputItemType.HEAD

SpssClient.OutputItemType.TITLE

SpssClient.OutputItemType.NOTE

SpssClient.OutputItemType.WARNING

SpssClient.OutputItemType.PIVOT

 

 

 

**********************

This example crashes:

**********************

 

import SpssClient

SpssClient.StartClient()

OutputDoc = SpssClient.GetDesignatedOutputDoc()

OutputItems = OutputDoc.GetOutputItems()

i = OutputItems.Size()   #counts the items

 

#for index in range(i,0,-1):

    OutputItem = OutputItems.GetItemAt(index)

    print OutputItem.GetType()

 

SpssClient.StopClient()

 

 

 

**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
[hidden email] 
Web: www.lavolta.ch

 

Reply | Threaded
Open this post in threaded view
|

Re: Python crashes when walking backwards through output items

Albert-Jan Roskam
Hi,
 
What traceback do you get when you run this code from within Python?
It's ugly, but does for index in range(i)[::-1] work?

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the face of ambiguity, refuse the temptation to guess.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Wed, 2/10/10, la volta statistics <[hidden email]> wrote:

From: la volta statistics <[hidden email]>
Subject: [SPSSX-L] Python crashes when walking backwards through output items
To: [hidden email]
Date: Wednesday, February 10, 2010, 2:56 PM

Hi,

if I want to walk through the items in a Outputdoc, I can do that without problems with a range command.

However, walking backwards, that is, starting at the last item, makes python crash.

Is there a way I can access the last pivot table in the output without going through all the items I have in my Outputdoc.

 

I use SPSS 18.1

 

Thanks in advances

Christian

 

**********************

This example works:

**********************

 

import SpssClient

SpssClient.StartClient()

OutputDoc = SpssClient.GetDesignatedOutputDoc()

OutputItems = OutputDoc.GetOutputItems()

i = OutputItems.Size()   #counts the items

 

for index in range(i):

    OutputItem = OutputItems.GetItemAt(index)

    print OutputItem.GetType()

 

SpssClient.StopClient()

 

 

Prints:

SpssClient.OutputItemType.ROOT

SpssClient.OutputItemType.LOG

SpssClient.OutputItemType.HEAD

SpssClient.OutputItemType.TITLE

SpssClient.OutputItemType.NOTE

SpssClient.OutputItemType.WARNING

SpssClient.OutputItemType.PIVOT

 

 

 

**********************

This example crashes:

**********************

 

import SpssClient

SpssClient.StartClient()

OutputDoc = SpssClient.GetDesignatedOutputDoc()

OutputItems = OutputDoc.GetOutputItems()

i = OutputItems.Size()   #counts the items

 

#for index in range(i,0,-1):

    OutputItem = OutputItems.GetItemAt(index)

    print OutputItem.GetType()

 

SpssClient.StopClient()

 

 

 

**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
mailto:schmidhauser@... 
Web: www.lavolta.ch

 


Reply | Threaded
Open this post in threaded view
|

Re: Python crashes when walking backwards through output items

Jon K Peck
In reply to this post by la volta statistics

Size() returns the number of items.  They are numbered from zero, though, so this code
i = OutputItems.Size()   #counts the items
 
#for index in range(i,0,-1):
    OutputItem = OutputItems.GetItemAt(index)

is asking for an item 1 beyond the end.
BOOM!


Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: la volta statistics <[hidden email]>
To: [hidden email]
Date: 02/10/2010 07:00 AM
Subject: [SPSSX-L] Python crashes when walking backwards through output              items
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Hi,
if I want to walk through the items in a Outputdoc, I can do that without problems with a range command.
However, walking backwards, that is, starting at the last item, makes python crash.
Is there a way I can access the last pivot table in the output without going through all the items I have in my Outputdoc.
 
I use SPSS 18.1
 
Thanks in advances
Christian
 
**********************
This example works:
**********************
 
import SpssClient
SpssClient.StartClient()
OutputDoc = SpssClient.GetDesignatedOutputDoc()
OutputItems = OutputDoc.GetOutputItems()
i = OutputItems.Size()   #counts the items
 
for index in range(i):
    OutputItem = OutputItems.GetItemAt(index)
    print OutputItem.GetType()
 
SpssClient.StopClient()
 
 
Prints:
SpssClient.OutputItemType.ROOT
SpssClient.OutputItemType.LOG
SpssClient.OutputItemType.HEAD
SpssClient.OutputItemType.TITLE
SpssClient.OutputItemType.NOTE
SpssClient.OutputItemType.WARNING
SpssClient.OutputItemType.PIVOT
 
 
 
**********************
This example crashes:
**********************
 
import SpssClient
SpssClient.StartClient()
OutputDoc = SpssClient.GetDesignatedOutputDoc()
OutputItems = OutputDoc.GetOutputItems()
i = OutputItems.Size()   #counts the items
 
#for index in range(i,0,-1):
    OutputItem = OutputItems.GetItemAt(index)
    print OutputItem.GetType()
 
SpssClient.StopClient()
 
 
 
**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
mailto:schmidhauser@...
Web:
www.lavolta.ch