Difference between Python program block and equivalent command in IDLE

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

Difference between Python program block and equivalent command in IDLE

Ruben Geert van den Berg
Dear all,
 
Does anyone understand the following? If I run
 
begin program.
help(cursor)
end program.
 
in SPSS syntax, I get normal results. However, if I run
 
>>> help(cursor)
 
in IDLE, I only get the following error:
 
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    help(cursor)
NameError: name 'cursor' is not defined

I hope this is not a dumb question, but shouldn't these render the same result?
 
TIA!

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com





New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

Re: Difference between Python program block and equivalent command in IDLE

Albert-Jan Roskam
Hi,

It seems that SPSS already imports some modules "under the hood". I bet Jon can tell you more about that.

if you type
import spss
help(spss.cursor)
It might work (can't test it here)

If the above works,
spss.cursor.__doc__
will also show the docstring.
Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Thu, 7/15/10, Ruben van den Berg <[hidden email]> wrote:

From: Ruben van den Berg <[hidden email]>
Subject: [SPSSX-L] Difference between Python program block and equivalent command in IDLE
To: [hidden email]
Date: Thursday, July 15, 2010, 10:18 AM

Dear all,
 
Does anyone understand the following? If I run
 
begin program.
help(cursor)
end program.
 
in SPSS syntax, I get normal results. However, if I run
 
>>> help(cursor)
 
in IDLE, I only get the following error:
 
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    help(cursor)
NameError: name 'cursor' is not defined

I hope this is not a dumb question, but shouldn't these render the same result?
 
TIA!

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com





New Windows 7: Find the right PC for you. Learn more.

Reply | Threaded
Open this post in threaded view
|

Re: Difference between Python program block and equivalent command in IDLE

Ruben Geert van den Berg
Hi Albert-Jan (and others),
 
Thank you but I think this is even more complicated. If I run
 
begin program.
import spss,spssdata
end program.
 
begin program.
help(cursor)
end program.
 
I get an error. However, by running (some Python 'borrowed' from Jon Peck)
 
dataset close all.
cd'C:\Program Files\SPSSInc\PASWStatistics18\Samples\English'.
get file'1991 U.S. General Social Survey.sav'.
dataset name gss.
 
begin program.
import spss,spssdata
rowvar="life"
colvar="happy"
cursor=spssdata.Spssdata(colvar,omitmissing=True)
allvalues=set([case[0] for case in cursor])
print allvalues
end program.
 
begin program.
help(cursor)
end program.
 
I get help on an spssdata object. I guess it's the program block that 'activates' or invokes the help function.
 
Best,

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com



 

Date: Thu, 15 Jul 2010 01:57:41 -0700
From: [hidden email]
Subject: Re: Difference between Python program block and equivalent command in IDLE
To: [hidden email]

Hi,

It seems that SPSS already imports some modules "under the hood". I bet Jon can tell you more about that.

if you type
import spss
help(spss.cursor)
It might work (can't test it here)

If the above works,
spss.cursor.__doc__
will also show the docstring.
Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Thu, 7/15/10, Ruben van den Berg <[hidden email]> wrote:

From: Ruben van den Berg <[hidden email]>
Subject: [SPSSX-L] Difference between Python program block and equivalent command in IDLE
To: [hidden email]
Date: Thursday, July 15, 2010, 10:18 AM

Dear all,
 
Does anyone understand the following? If I run
 
begin program.
help(cursor)
end program.
 
in SPSS syntax, I get normal results. However, if I run
 
>>> help(cursor)
 
in IDLE, I only get the following error:
 
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    help(cursor)
NameError: name 'cursor' is not defined

I hope this is not a dumb question, but shouldn't these render the same result?
 
TIA!

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com





New Windows 7: Find the right PC for you. Learn more.



New Windows 7: Simplify what you do everyday. Find the right PC for you.
Reply | Threaded
Open this post in threaded view
|

Re: Difference between Python program block and equivalent command in IDLE

Jon K Peck

The argument of the help function must be qualified in the same way as any other object name in Python code.  If you run (capitalizing the function name to match the module definition)

begin program.
help(Cursor)
end program.

you will get an error message, the same as from IDLE.  The difference you are seeing is probably due to the fact that objects are retained between programs within your SPSS Statistics session.  But running

begin program.
import spss
help(Cursor)
end program.

will still give an error.  What would work is

begin program.
import spss
help(spss.Cursor)
end program.

After having done this once in the session, you could run the following successfully

begin program.
help(spss.Cursor)
end program.

No modules are automatically imported.

If you are running in external mode - with IDLE or any other Python IDE, you will see the same behavior as long as your Python job has not terminated.

There is another difference that bears on this discussion.  The examples above are all about programmability.  If you run a Python script, though, with the SCRIPT command, state is not maintained from one script execution to another, so the imports need to be repeated.

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



From: Ruben van den Berg <[hidden email]>
To: [hidden email]
Date: 07/15/2010 04:46 AM
Subject: Re: [SPSSX-L] Difference between Python program block and              equivalent              command in              IDLE
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Hi Albert-Jan (and others),

Thank you but I think this is even more complicated. If I run

begin program.
import spss,spssdata
end program.

begin program.
help(cursor)
end program.

I get an error. However, by running (some Python 'borrowed' from Jon Peck)

dataset close all.
cd'C:\Program Files\SPSSInc\PASWStatistics18\Samples\English'.
get file'1991 U.S. General Social Survey.sav'.
dataset name gss.

begin program.
import spss,spssdata
rowvar="life"
colvar="happy"
cursor=spssdata.Spssdata(colvar,omitmissing=True)
allvalues=set([case[0] for case in cursor])
print allvalues
end program.

begin program.
help(cursor)
end program.

I get help on an spssdata object. I guess it's the program block that 'activates' or invokes the help function.

Best,

Ruben van den Berg

Consultant Models & Methods

TNS NIPO

Email: [hidden email]

Mobiel: +31 6 24641435

Telefoon: +31 20 522 5738

Internet:
www.tns-nipo.com





Date: Thu, 15 Jul 2010 01:57:41 -0700
From: [hidden email]
Subject: Re: Difference between Python program block and equivalent command in IDLE
To: [hidden email]
Hi,

It seems that SPSS already imports some modules "under the hood". I bet Jon can tell you more about that.

if you type
import spss
help(spss.cursor)
It might work (can't test it here)

If the above works,
spss.cursor.__doc__
will also show the docstring.
Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Thu, 7/15/10, Ruben van den Berg <[hidden email]> wrote:


From: Ruben van den Berg <[hidden email]>
Subject: [SPSSX-L] Difference between Python program block and equivalent command in IDLE
To: [hidden email]
Date: Thursday, July 15, 2010, 10:18 AM

Dear all,

Does anyone understand the following? If I run

begin program.
help(cursor)
end program.

in SPSS syntax, I get normal results. However, if I run

>>> help(cursor)

in IDLE, I only get the following error:

Traceback (most recent call last):
 File "<pyshell#2>", line 1, in <module>
   help(cursor)
NameError: name 'cursor' is not defined

I hope this is not a dumb question, but shouldn't these render the same result?

TIA!

Ruben van den Berg

Consultant Models & Methods

TNS NIPO

Email: [hidden email]

Mobiel: +31 6 24641435

Telefoon: +31 20 522 5738

Internet:
www.tns-nipo.com





New Windows 7: Find the right PC for you. Learn more.




New Windows 7: Simplify what you do everyday. Find the right PC for you.