Python problem with path string

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

Python problem with path string

la volta statistics

Hi all

I want to use the path of the syntax file I am working with and subsequently use it as a macro value.

Unfortunately the command spss.SetMacroValue gives me a warning (Warning # 206 in column 23.  Text: \  An invalid character has been found on a command).

 

I know this is due the several backlashes in a windows path ('\'). But is there a solution to avoid this warnings?

I am using SPSS 15 on Windows XP.

 

Thanks in advance

Christian

 

 

***** begin code *****.

 

BEGIN PROGRAM.

import os,spss

myPath =  os.getcwd()

#print myPath

spss.SetMacroValue("!Path", myPath)

 

END PROGRAM.

Title !Path.

 

***** end code *****.

 

 

 

**********************************
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 problem with path string

Jon K Peck

You need to use quotes when you define the macro and then use !unquote when you reference it in SPSS code.  There are a few other obscure characters besides \ that will cause this same warning.

An alternative would be to map all your backslash characters to forward slash, since SPSS is happy with either.  I had the same problem with the SPSSINC PROCESS FILES extension command and resorted to quoting the text even though that makes using the macro a little more complicated.

However, unquoted text does not preserve case, so if you are on an os where file names are case sensitive, you could have a problem with that.

Regards,

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



From: la volta statistics <[hidden email]>
To: [hidden email]
Date: 04/08/2010 03:23 AM
Subject: [SPSSX-L] Python problem with path string
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Hi all
I want to use the path of the syntax file I am working with and subsequently use it as a macro value.
Unfortunately the command spss.SetMacroValue gives me a warning (Warning # 206 in column 23.  Text: \  An invalid character has been found on a command).
 
I know this is due the several backlashes in a windows path ('\'). But is there a solution to avoid this warnings?
I am using SPSS 15 on Windows XP.
 
Thanks in advance
Christian
 
 
***** begin code *****.
 
BEGIN PROGRAM.
import os,spss
myPath =  os.getcwd()
#print myPath
spss.SetMacroValue("!Path", myPath)
 
END PROGRAM.
Title !Path.
 
***** end code *****.
 
 
 
**********************************
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
|

AW: Python problem with path string

la volta statistics

Thanks Jon that helped.

 

I ended up with a solution, in which I added the question marks in the SetMacroValue statement and repaksed the backlashes with forward lashes. That worked

 

Christian

BEGIN PROGRAM.
import os,spss
myPath = os.getcwd().replace("\\","/")
#print myPath
spss.SetMacroValue("!Path", "'" + myPath + "'" )
END PROGRAM.

INSERT FILE = !Path + '/myInsert.sps' .

 

 

**********************************
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


Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von Jon K Peck
Gesendet: Donnerstag, 8. April 2010 14:47
An: [hidden email]
Betreff: Re: Python problem with path string

 


You need to use quotes when you define the macro and then use !unquote when you reference it in SPSS code.  There are a few other obscure characters besides \ that will cause this same warning.

An alternative would be to map all your backslash characters to forward slash, since SPSS is happy with either.  I had the same problem with the SPSSINC PROCESS FILES extension command and resorted to quoting the text even though that makes using the macro a little more complicated.

However, unquoted text does not preserve case, so if you are on an os where file names are case sensitive, you could have a problem with that.

Regards,

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


From:

la volta statistics <[hidden email]>

To:

[hidden email]

Date:

04/08/2010 03:23 AM

Subject:

[SPSSX-L] Python problem with path string

Sent by:

"SPSSX(r) Discussion" <[hidden email]>

 





Hi all
I want to use the path of the syntax file I am working with and subsequently use it as a macro value.
Unfortunately the command spss.SetMacroValue gives me a warning (Warning # 206 in column 23.  Text: \  An invalid character has been found on a command).
 
I know this is due the several backlashes in a windows path ('\'). But is there a solution to avoid this warnings?
I am using SPSS 15 on Windows XP.
 
Thanks in advance
Christian
 
 
***** begin code *****.
 
BEGIN PROGRAM.
import os,spss
myPath =  os.getcwd()
#print myPath
spss.SetMacroValue("!Path", myPath)
 
END PROGRAM.
Title !Path.
 
***** end code *****.
 
 
 
**********************************
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