|
Someone asked me about consulting about macros but I declined because I
am not facile with them. I have been meaning to come up to speed with PYTHON from the view that Python works with many kinds of s/w besides SPSS and is more general. My question is: How worthwhile is it to bother learning macros now that PYTHON is available? Are there any advantages to learning macros/python first? Are there many things that are easier with macros/python? Are there many things that macros can do that Python cannot and vice versa? Art Kendall Social Research Consultants ===================== 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
Art Kendall
Social Research Consultants |
|
Macros do simple text substitutions whereas Python has knowledge of the
dictionary and can read data. Python will do everything that a macro can do and much, much more. Don't even bother to learn macros other than to understand somebody else's code. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art Kendall Sent: Wednesday, November 12, 2008 10:17 AM To: [hidden email] Subject: Macros vs Python Someone asked me about consulting about macros but I declined because I am not facile with them. I have been meaning to come up to speed with PYTHON from the view that Python works with many kinds of s/w besides SPSS and is more general. My question is: How worthwhile is it to bother learning macros now that PYTHON is available? Are there any advantages to learning macros/python first? Are there many things that are easier with macros/python? Are there many things that macros can do that Python cannot and vice versa? Art Kendall Social Research Consultants ===================== 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 ===================== 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 |
|
I would echo ViAnn's advise with two small exceptions.
Macros can still be convenient in communicating simple values between Python code and SPSS syntax. There is, for example, a Python api spss.SetMacroValue that can create a macro value from Python code that can then be referenced later in regular SPSS syntax. Sometimes you have syntax and want to pass something as a parameter to Python code. In the long run, it is probably better to wrap the syntax in Python code so this isn't necessary, but in simple cases, there is a more direct solution. Suppose you want to pass a parameter, call it fred, to Python code and have not set this up as a function. You might do DEFINE fred() <somevalue> !ENDDEFINE. You want to refer to that value in Python code. So change the code above to DEFINE !fred() <somevalue> !ENDDEFINE. DATAFILE ATTRIBUTE ATTRIBUTE=afred(!fred). This creates a custom datafile attribut named afred. (I can't actually run this code at the moment, so bear with me on syntax errors and typos.) Then in your Python code, you can retrieve a dictionary of the datafile attributes using parms = spssaux.GetAttributes() Now in your Python code, you can refer to this value simply as parms["afred"]. Of course, this example doesn't intrinsically require macros, but defining the value as a macro guarantees that the attribute value will match it exactly. HTH, Jon Peck ________________________________ From: SPSSX(r) Discussion on behalf of ViAnn Beadle Sent: Wed 11/12/2008 11:24 AM To: [hidden email] Subject: Re: [SPSSX-L] Macros vs Python Macros do simple text substitutions whereas Python has knowledge of the dictionary and can read data. Python will do everything that a macro can do and much, much more. Don't even bother to learn macros other than to understand somebody else's code. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art Kendall Sent: Wednesday, November 12, 2008 10:17 AM To: [hidden email] Subject: Macros vs Python Someone asked me about consulting about macros but I declined because I am not facile with them. I have been meaning to come up to speed with PYTHON from the view that Python works with many kinds of s/w besides SPSS and is more general. My question is: How worthwhile is it to bother learning macros now that PYTHON is available? Are there any advantages to learning macros/python first? Are there many things that are easier with macros/python? Are there many things that macros can do that Python cannot and vice versa? Art Kendall Social Research Consultants ===================== 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 ===================== 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 ====================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 |
| Free forum by Nabble | Edit this page |
