Wrapping statements in Python in SPSS

Discussion in 'Python' started by alankrinsky@gmail.com, Dec 28, 2012.

  1. Guest

    I am working with Python looping in SPSS. What are the limits for the

    for var1, var2, var3 in zip(Variable1, Variable2, Variable3):

    statement in the Python looping function within SPSS? I am getting an errormessage, I presume because of wrapping or length. Imagine the above statement, but expanded, as I am working with more than 28 variables in this loop, and even making the names really short is making the statement too long. Is it impossible to wrap and make this work? I know there are ways to wrap strings, including lists of variables, but here I have a statement/function..

    Thank you for any help!

    Alan
    , Dec 28, 2012
    #1
    1. Advertising

  2. On Sat, Dec 29, 2012 at 3:01 AM, <> wrote:
    > I am working with Python looping in SPSS. What are the limits 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. Imagine the above statement, but expanded, as I am working with more than 28 variables in this loop, and even making the names really short is making the statement too long.. Is it impossible to wrap and make this work? I know there are ways to wrap strings, including lists of variables, but here I have a statement/function.


    At what point are you wrapping it? Can you show the wrapped form and
    the error message?

    As a general rule, you can safely wrap anything that's inside parentheses.

    for (
    var1,
    var2,
    var3
    ) in zip(
    Variable1,
    Variable2,
    Variable3
    ):
    pass

    That may be a tad excessive, but you get the idea :)

    ChrisA
    Chris Angelico, Dec 28, 2012
    #2
    1. Advertising

  3. Guest

    Chris,

    I tried placing in the format you suggested and received this error message:

    END PROGRAM.
    Traceback (most recent call last):
    File "<string>", line 396, in <module>
    ValueError: incomplete format key



    ____________________

    On Friday, December 28, 2012 11:10:10 AM UTC-5, Chris Angelico wrote:
    > On Sat, Dec 29, 2012 at 3:01 AM, alan wrote: > I am working with Python looping in SPSS. What are the limits 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. Imagine the above statement, but expanded, as I am working with more than 28 variables in this loop, and even making the names really short is making the statement too long. Is it impossible to wrap and make this work? I know there are ways to wrap strings, including lists of variables, but here I have a statement/function. At what point are you wrapping it?Can you show the wrapped form and the error message? As a general rule, you can safely wrap anything that's inside parentheses. for ( var1, var2, var3 ) in zip( Variable1, Variable2, Variable3 ): pass That may be a tad excessive, but you get the idea :) ChrisA
    , Dec 28, 2012
    #3
  4. Guest

    Chris,

    I tried placing in the format you suggested and received this error message:

    END PROGRAM.
    Traceback (most recent call last):
    File "<string>", line 396, in <module>
    ValueError: incomplete format key



    ____________________

    On Friday, December 28, 2012 11:10:10 AM UTC-5, Chris Angelico wrote:
    > On Sat, Dec 29, 2012 at 3:01 AM, alan wrote: > I am working with Python looping in SPSS. What are the limits 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. Imagine the above statement, but expanded, as I am working with more than 28 variables in this loop, and even making the names really short is making the statement too long. Is it impossible to wrap and make this work? I know there are ways to wrap strings, including lists of variables, but here I have a statement/function. At what point are you wrapping it?Can you show the wrapped form and the error message? As a general rule, you can safely wrap anything that's inside parentheses. for ( var1, var2, var3 ) in zip( Variable1, Variable2, Variable3 ): pass That may be a tad excessive, but you get the idea :) ChrisA
    , Dec 28, 2012
    #4
  5. Peter Otten Guest

    wrote:

    > I tried placing in the format you suggested and received this error
    > message:
    >
    > END PROGRAM.
    > Traceback (most recent call last):
    > File "<string>", line 396, in <module>
    > ValueError: incomplete format key


    You seem to have a malformed format string. Example:

    Correct:

    >>> "Wonderful %(what)s" % dict(what="Spam")

    'Wonderful Spam'

    Broken (not the missing ')'):

    >>> "Wonderful %(whats" % dict(what="Spam")

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: incomplete format key
    Peter Otten, Dec 28, 2012
    #5
  6. On Sat, Dec 29, 2012 at 3:43 AM, <> wrote:
    > Chris,
    >
    > I tried placing in the format you suggested and received this error message:
    >
    > END PROGRAM.
    > Traceback (most recent call last):
    > File "<string>", line 396, in <module>
    > ValueError: incomplete format key


    I don't think the code I gave could produce that. You'll need to show
    a bit more of your code, including at least line 396, possibly some
    context. Unless one of the other members here has a working crystal
    ball - mine's cooling down after excessive use.

    ChrisA
    Chris Angelico, Dec 28, 2012
    #6
  7. Guest

    I think 396 just comes from the end of the Python loop, without indicating which line in the loop is at issue.

    Here is the full code from this section of the loop:


    for (
    msr, brk, dmn, src, dspd1, dspd2, dspd3, dspd4, dspd5, dspd6, dspd7, dspd8, dspd9, dspd10, dspd11, dspd12,
    period1, period2, period3, period4, period5, period6, period7, period8,period9, period10, period11, period12
    ) in zip(
    Measure, BreakVariable, Dimension, Sources, DimensionSourceTimeFrame1, DimensionSourceTimeFrame2, DimensionSourceTimeFrame3, DimensionSourceTimeFrame4,
    DimensionSourceTimeFrame5, DimensionSourceTimeFrame6, DimensionSourceTimeFrame7, DimensionSourceTimeFrame8, DimensionSourceTimeFrame9,
    DimensionSourceTimeFrame10, DimensionSourceTimeFrame11, DimensionSourceTimeFrame12,
    TimeFrame1, TimeFrame2, TimeFrame3, TimeFrame4, TimeFrame5, TimeFrame6,TimeFrame7, TimeFrame8, TimeFrame9, TimeFrame10, TimeFrame11, TimeFrame12
    ):


    spss.Submit(r"""


    Alan


    On Friday, December 28, 2012 12:12:27 PM UTC-5, Chris Angelico wrote:
    > On Sat, Dec 29, 2012 at 3:43 AM, alan wrote: > Chris, > > I tried placingin the format you suggested and received this error message: > > END PROGRAM. > Traceback (most recent call last): > File "<string>", line 396, in <module> > ValueError: incomplete format key I don't think the code I gave could produce that. You'll need to show a bit more of your code, including atleast line 396, possibly some context. Unless one of the other members here has a working crystal ball - mine's cooling down after excessive use. ChrisA
    , Dec 28, 2012
    #7
  8. Guest

    I think 396 just comes from the end of the Python loop, without indicating which line in the loop is at issue.

    Here is the full code from this section of the loop:


    for (
    msr, brk, dmn, src, dspd1, dspd2, dspd3, dspd4, dspd5, dspd6, dspd7, dspd8, dspd9, dspd10, dspd11, dspd12,
    period1, period2, period3, period4, period5, period6, period7, period8,period9, period10, period11, period12
    ) in zip(
    Measure, BreakVariable, Dimension, Sources, DimensionSourceTimeFrame1, DimensionSourceTimeFrame2, DimensionSourceTimeFrame3, DimensionSourceTimeFrame4,
    DimensionSourceTimeFrame5, DimensionSourceTimeFrame6, DimensionSourceTimeFrame7, DimensionSourceTimeFrame8, DimensionSourceTimeFrame9,
    DimensionSourceTimeFrame10, DimensionSourceTimeFrame11, DimensionSourceTimeFrame12,
    TimeFrame1, TimeFrame2, TimeFrame3, TimeFrame4, TimeFrame5, TimeFrame6,TimeFrame7, TimeFrame8, TimeFrame9, TimeFrame10, TimeFrame11, TimeFrame12
    ):


    spss.Submit(r"""


    Alan


    On Friday, December 28, 2012 12:12:27 PM UTC-5, Chris Angelico wrote:
    > On Sat, Dec 29, 2012 at 3:43 AM, alan wrote: > Chris, > > I tried placingin the format you suggested and received this error message: > > END PROGRAM. > Traceback (most recent call last): > File "<string>", line 396, in <module> > ValueError: incomplete format key I don't think the code I gave could produce that. You'll need to show a bit more of your code, including atleast line 396, possibly some context. Unless one of the other members here has a working crystal ball - mine's cooling down after excessive use. ChrisA
    , Dec 28, 2012
    #8
  9. On 12/28/2012 12:33 PM, wrote:
    > I think 396 just comes from the end of the Python loop, without indicating which line in the loop is

    at issue.
    >
    > Here is the full code from this section of the loop:
    >
    >
    > for (
    > msr, brk, dmn, src, dspd1, dspd2, dspd3, dspd4, dspd5, dspd6, dspd7,

    dspd8, dspd9, dspd10, dspd11, dspd12,
    > period1, period2, period3, period4, period5, period6, period7,

    period8, period9, period10, period11, period12
    > ) in zip(
    > Measure, BreakVariable, Dimension, Sources,

    DimensionSourceTimeFrame1, DimensionSourceTimeFrame2,
    DimensionSourceTimeFrame3, DimensionSourceTimeFrame4,
    > DimensionSourceTimeFrame5, DimensionSourceTimeFrame6,

    DimensionSourceTimeFrame7, DimensionSourceTimeFrame8,
    DimensionSourceTimeFrame9,
    > DimensionSourceTimeFrame10, DimensionSourceTimeFrame11,

    DimensionSourceTimeFrame12,
    > TimeFrame1, TimeFrame2, TimeFrame3, TimeFrame4, TimeFrame5,

    TimeFrame6, TimeFrame7, TimeFrame8, TimeFrame9, TimeFrame10,
    TimeFrame11, TimeFrame12
    > ):
    >
    >
    > spss.Submit(r"""
    >
    >
    > Alan
    >
    >


    By the way, when lines run so long they can get hard to manage, edit,
    understand, et cetera. You should consider setting things up cleanly
    before doing the loop and using a list of names for columns like so:


    def main():
    l1, l2 = [1,2], [3,4]
    zipped = zip(l1, l2)
    colnames = "first second".split()

    for columns in zipped:
    coldict = dict(zip(colnames, columns))
    print("coldict", coldict)

    main()


    This produces output:

    coldict {'second': 3, 'first': 1}
    coldict {'second': 4, 'first': 2}

    ... and then you can pass the coldict on to your string.

    - mitya


    --
    Lark's Tongue Guide to Python: http://lightbird.net/larks/
    Mitya Sirenef, Dec 28, 2012
    #9
  10. On 12/28/2012 12:55 PM, Mitya Sirenef wrote:
    > On 12/28/2012 12:33 PM, wrote:
    >> I think 396 just comes from the end of the Python loop, without
    >> indicating which line in the loop is

    > at issue.
    > >
    > > Here is the full code from this section of the loop:
    > >
    > >
    > > for (
    > > msr, brk, dmn, src, dspd1, dspd2, dspd3, dspd4, dspd5, dspd6, dspd7,

    > dspd8, dspd9, dspd10, dspd11, dspd12,
    > > period1, period2, period3, period4, period5, period6, period7,

    > period8, period9, period10, period11, period12
    > > ) in zip(
    > > Measure, BreakVariable, Dimension, Sources,

    > DimensionSourceTimeFrame1, DimensionSourceTimeFrame2,
    > DimensionSourceTimeFrame3, DimensionSourceTimeFrame4,
    > > DimensionSourceTimeFrame5, DimensionSourceTimeFrame6,

    > DimensionSourceTimeFrame7, DimensionSourceTimeFrame8,
    > DimensionSourceTimeFrame9,
    > > DimensionSourceTimeFrame10, DimensionSourceTimeFrame11,

    > DimensionSourceTimeFrame12,
    > > TimeFrame1, TimeFrame2, TimeFrame3, TimeFrame4, TimeFrame5,

    > TimeFrame6, TimeFrame7, TimeFrame8, TimeFrame9, TimeFrame10,
    > TimeFrame11, TimeFrame12
    > > ):
    > >
    > >
    > > spss.Submit(r"""
    > >
    > >
    > > Alan
    > >
    > >

    >
    > By the way, when lines run so long they can get hard to manage, edit,
    > understand, et cetera. You should consider setting things up cleanly
    > before doing the loop and using a list of names for columns like so:
    >
    >
    > def main():
    > l1, l2 = [1,2], [3,4]
    > zipped = zip(l1, l2)
    > colnames = "first second".split()
    >
    > for columns in zipped:
    > coldict = dict(zip(colnames, columns))
    > print("coldict", coldict)
    >



    Should really be 'for column in zipped:' !

    -m

    --
    Lark's Tongue Guide to Python: http://lightbird.net/larks/
    Mitya Sirenef, Dec 28, 2012
    #10
  11. On 12/28/2012 01:05 PM, Mitya Sirenef wrote:
    > On 12/28/2012 12:55 PM, Mitya Sirenef wrote:
    >> On 12/28/2012 12:33 PM, wrote:
    >>> I think 396 just comes from the end of the Python loop, without

    indicating which line in the loop is
    >> at issue.
    >> >
    >> > Here is the full code from this section of the loop:
    >> >
    >> >
    >> > for (
    >> > msr, brk, dmn, src, dspd1, dspd2, dspd3, dspd4, dspd5, dspd6,

    dspd7, dspd8, dspd9, dspd10, dspd11, dspd12,
    >> > period1, period2, period3, period4, period5, period6, period7,

    period8, period9, period10, period11, period12
    >> > ) in zip(
    >> > Measure, BreakVariable, Dimension, Sources,

    DimensionSourceTimeFrame1, DimensionSourceTimeFrame2,
    DimensionSourceTimeFrame3, DimensionSourceTimeFrame4,
    >> > DimensionSourceTimeFrame5, DimensionSourceTimeFrame6,

    DimensionSourceTimeFrame7, DimensionSourceTimeFrame8,
    DimensionSourceTimeFrame9,
    >> > DimensionSourceTimeFrame10, DimensionSourceTimeFrame11,

    DimensionSourceTimeFrame12,
    >> > TimeFrame1, TimeFrame2, TimeFrame3, TimeFrame4, TimeFrame5,

    TimeFrame6, TimeFrame7, TimeFrame8, TimeFrame9, TimeFrame10,
    TimeFrame11, TimeFrame12
    >> > ):
    >> >
    >> >
    >> > spss.Submit(r"""
    >> >
    >> >
    >> > Alan
    >> >
    >> >

    >>
    >> By the way, when lines run so long they can get hard to manage, edit,
    >> understand, et cetera. You should consider setting things up cleanly
    >> before doing the loop and using a list of names for columns like so:
    >>
    >>
    >> def main():
    >> l1, l2 = [1,2], [3,4]
    >> zipped = zip(l1, l2)
    >> colnames = "first second".split()
    >>
    >> for columns in zipped:
    >> coldict = dict(zip(colnames, columns))
    >> print("coldict", coldict)
    >>

    >
    >
    > Should really be 'for column in zipped:' !
    >
    > -m
    >


    Doh - the code is good, but I got a little confused with variable names.
    This should be more like it:

    def main():
    c1, c2 = [1,2], [3,4]
    zipped = zip(c1, c2)
    colnames = "first second".split()

    for values in zipped:
    valdict = dict(zip(colnames, values))
    print("valdict", valdict)

    main()


    -m


    --
    Lark's Tongue Guide to Python: http://lightbird.net/larks/
    Mitya Sirenef, Dec 28, 2012
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil Zanella
    Replies:
    8
    Views:
    1,170
    mfmehdi
    Oct 20, 2006
  2. Mark
    Replies:
    0
    Views:
    705
  3. Silvio Bierman

    SPSS

    Silvio Bierman, Feb 14, 2008, in forum: Java
    Replies:
    0
    Views:
    516
    Silvio Bierman
    Feb 14, 2008
  4. SANCTUARY BIO-LABS
    Replies:
    0
    Views:
    515
    SANCTUARY BIO-LABS
    Jul 25, 2009
  5. Mike Schwab

    SPSS

    Mike Schwab, Dec 2, 2005, in forum: Ruby
    Replies:
    2
    Views:
    117
    Zed A. Shaw
    Dec 3, 2005
Loading...

Share This Page