Spaces in String Variable

582
6
Jump to solution
12-20-2013 05:15 AM
anTonialcaraz
Occasional Contributor II
Hi,

I have an issue with my script related to the space in the string variable (see below). If "MinNPP" is used instead it works fine.
I've also tried setting the variable as str(arcpy.GetParameterAsText(6)) but it doesn't work either. The variable is set as String data type in the tool; Filter = Value list. Version used is 10.0

Variable:

NPPEquation = arcpy.GetParameterAsText(6)

Process:

if NPPEquation == "Min NPP1":


Thank you

Toni
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
anTonialcaraz
Occasional Contributor II
Thanks a lot guys.

I tried the print NPPEquation and it works fine. "Min NPP1" is one of the values in the filter list.

The thing is that I've set the output raster dataset to include the name of the NPPEquation ("Min NPP" for example).
So I guess is not the right approach to have spaces in the string variable names. Not sure if there is a way round that...

Cheers

Toni

View solution in original post

0 Kudos
6 Replies
NeilAyres
MVP Alum
Have you tried using print NPPEquation just to see exactly what is being returned by the GetParametersAsText.
It should work, but only if NPPEquation is exactly "Min NPP1"
Not much, I know but good luck,
Neil
0 Kudos
GeraldineEGGERMONT
New Contributor II
Hi Toni,

So do you have added "Min NPP1" to your filter value list? Are you sure there's no trailing space or whatsoever?
0 Kudos
anTonialcaraz
Occasional Contributor II
Thanks a lot guys.

I tried the print NPPEquation and it works fine. "Min NPP1" is one of the values in the filter list.

The thing is that I've set the output raster dataset to include the name of the NPPEquation ("Min NPP" for example).
So I guess is not the right approach to have spaces in the string variable names. Not sure if there is a way round that...

Cheers

Toni
0 Kudos
DanPatterson_Retired
MVP Emeritus
rasters don't like spaces in their names if this is indeed an output name
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Thanks a lot guys.

I tried the print NPPEquation and it works fine. "Min NPP1" is one of the values in the filter list.

The thing is that I've set the output raster dataset to include the name of the NPPEquation ("Min NPP" for example).
So I guess is not the right approach to have spaces in the string variable names. Not sure if there is a way round that...

Cheers

Toni


Toni,

You can use an IF statement to replace the space using python's replace method.  Example:

if " " in NPPEquation:
    NPPEquation = NPPEquation.replace(" ", "_")
0 Kudos
anTonialcaraz
Occasional Contributor II
Thanks very much Jake.

That helps a lot.

Toni
0 Kudos