Python Looping with For...in zip

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

Python Looping with For...in zip

Krinsky, Alan-2
Does anyone know what the limits are for the for var1, var2, var3 in zip(Variable1, Variable2, Variable3): statement in the Python looping function within SPSS? I am getting an error message, I presume because of wrapping or length. Is it impossible to wrap and make this work? I am working with more than 28 variables in this loop, and even making the names really short is making the statement too long.
 
Any suggestions?
 
Thank you, and be well!
 
Alan
 
 
Alan D. Krinsky  PhD, MPH
Senior Data Analyst
Office of Clinical Integration
UMass Memorial Health Care
38 Oak Ave.
Worcester, MA 01605
Phone: 508-334-5854
Fax: 508-793-6086
E-mail: [hidden email]
 
 
 

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, transmission, re-transmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
Reply | Threaded
Open this post in threaded view
|

Automatic reply: Python Looping with For...in zip

Sarraf, Shimon Aaron

I am currently out of the office and will respond to your email, if necessary, on Monday, December 7. If you need immediate assistance, please call 812-856-5824.

Shimon Sarraf

Center for Postsecondary Research

Indiana University Bloomington

 

Reply | Threaded
Open this post in threaded view
|

Re: Python Looping with For...in zip

Jon K Peck
In reply to this post by Krinsky, Alan-2
In a syntax window, the maximum line length is 255 characters whether it is Python syntax or regular Statistics syntax, but you can wrap lines in Python code in many places as well as indicating continuation with \.  Here are a few excepts from the Python doc.

Two or more physical lines may be joined into logical lines using backslash characters (\), as follows: when a physical line ends in a backslash that is not part of a string literal or comment, it is joined with the following forming a single logical line, deleting the backslash and the following end-of-line character. For example:

if 1900 < year < 2100 and 1 <= month <= 12 \
  and 1 <= day <= 31 and 0 <= hour < 24 \
  and 0 <= minute < 60 and 0 <= second < 60:   # Looks like a valid date
       return 1

and

Expressions in parentheses, square brackets or curly braces can be split over more than one physical line without using backslashes. For example:

month_names = ['Januari', 'Februari', 'Maart',      # These are the
              'April',   'Mei',      'Juni',       # Dutch names
              'Juli',    'Augustus', 'September',  # for the months
              'Oktober', 'November', 'December']   # of the year

It is a good idea to break lines well before the maximum allowed length in order to make the code more readable.



Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        "Krinsky, Alan" <[hidden email]>
To:        [hidden email],
Date:        12/28/2012 06:04 PM
Subject:        [SPSSX-L] Python Looping with For...in zip
Sent by:        "SPSSX(r) Discussion" <[hidden email]>





Does anyone know what the limits are for the for var1, var2, var3 in zip(Variable1, Variable2, Variable3): statement in the Python looping function within SPSS? I am getting an error message, I presume because of wrapping or length. Is it impossible to wrap and make this work? I am working with more than 28 variables in this loop, and even making the names really short is making the statement too long.
 
Any suggestions?
 
Thank you, and be well!
 
Alan
 
 
Alan D. Krinsky  PhD, MPH
Senior Data Analyst

Office of Clinical Integration
UMass Memorial Health Care
38 Oak Ave.
Worcester, MA 01605
Phone: 508-334-5854
Fax: 508-793-6086
E-mail: [hidden email]

 
 
 

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, transmission, re-transmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
Reply | Threaded
Open this post in threaded view
|

Re: Python Looping with For...in zip

Albert-Jan Roskam
The PEP8 style convention recommends to "Limit all lines to a maximum of 79 characters." (because it is still legible when you print the code): http://www.python.org/dev/peps/pep-0008/#maximum-line-length

It is not always needed, and sometimes dangerous to use a newline as a statement terminator:

http://docs.python.org/2/howto/doanddont.html (under Using Backslash to Continue Statements)


Regards,
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?



>________________________________
> From: Jon K Peck <[hidden email]>
>To: [hidden email]
>Sent: Saturday, December 29, 2012 2:13 AM
>Subject: Re: [SPSSX-L] Python Looping with For...in zip
>
>
>In a syntax window, the maximum line length
is 255 characters whether it is Python syntax or regular Statistics syntax,
but you can wrap lines in Python code in many places as well as indicating
continuation with \.  Here are a few excepts from the Python doc.
>
>Two or more physical lines may be joined into logical
lines using backslash characters (\),
as follows: when a physical line ends in a backslash that is not part of
a string literal or comment, it is joined with the following forming a
single logical line, deleting the backslash and the following end-of-line
character. For example:
>if 1900 < year < 2100 and 1 <= month <=
12 \
>  and 1 <= day <= 31 and 0 <= hour < 24 \
>  and 0 <= minute < 60 and 0 <= second < 60:   #
Looks like a valid date
>       return 1
>
>and
>
>Expressions in parentheses, square brackets or curly braces
can be split over more than one physical line without using backslashes.
For example:
>month_names = ['Januari', 'Februari', 'Maart',
   # These are the
>              'April',   'Mei',
     'Juni',       # Dutch names
>              'Juli',    'Augustus',
'September',  # for the months
>              'Oktober', 'November',
'December']   # of the year
>
>It is a good idea to break lines well
before the maximum allowed length in order to make the code more readable.

>
>
>Jon Peck (no "h") aka Kim
>Senior Software Engineer, IBM
>[hidden email]
>new phone: 720-342-5621
>
>
>
>
>From:
 "Krinsky, Alan"
<[hidden email]>
>To:
 [hidden email],
>Date:
 12/28/2012 06:04 PM
>Subject:
   [SPSSX-L] Python
Looping with For...in zip
>Sent by:
   "SPSSX(r)
Discussion" <[hidden email]>
>
>________________________________
>
>
>
>Does anyone know what the limits are for
the for var1, var2,
var3 in zip(Variable1, Variable2, Variable3):statement in the Python looping function within SPSS? I am getting an error
message, I presume because of wrapping or length. Is it impossible to wrap
and make this work? I am working with more than 28 variables in this loop,
and even making the names really short is making the statement too long.

>
>Any suggestions?
>
>Thank you, and be well!
>
>Alan
>
>
>Alan D. Krinsky  PhD, MPH
>Senior Data Analyst
>Office of Clinical Integration
>UMass Memorial Health Care
>38 Oak Ave.
>Worcester, MA 01605
>Phone: 508-334-5854
>Fax: 508-793-6086
>E-mail: [hidden email]
>
>
>
>>________________________________
>The information transmitted is intended only for the person
or entity to which it is addressed and may contain confidential and/or
privileged material. Any review, transmission, re-transmission, dissemination
or other use of, or taking of any action in reliance upon this information
by persons or entities other than the intended recipient is prohibited.
If you received this in error, please contact the sender and delete the
material from any computer.
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD