2

I am using python to read the shapefile, however I meet some problems, this is the core code:

value="#code"
print 'value:',value
if '#' in value:
    v=value.replace('#','');
    print 'replaced:',v
    fixed_value=str(feature.GetFieldAsString(v))

It worked as expected if I run the script directly, but it will throw error once I run it in a web environment, I will get error like this:

  File "/home/kk/gis/codes/tilestache/map/__init__.py", line 162, in _get_features
    fixed_value=str(feature.GetFieldAsString(v))
  File "/usr/local/lib/python2.7/dist-packages/GDAL-1.10.1-py2.7-linux-x86_64.egg/osgeo/ogr.py", line 2233, in GetFieldAsString
    return _ogr.Feature_GetFieldAsString(self, *args)
NotImplementedError: Wrong number of arguments for overloaded function 'Feature_GetFieldAsString'.

And if I change the line to :

fixed_value=str(feature.GetFieldAsString('code'))

It worked.

What's going on?

It seems that the replace function in python make things strange.


UPDATE

Seems I get the point,this is caused by the replace function in python which return a different rather than str:

value='#code'
type(value) ==> str
v=value.replace('#','')
type(v) ==>unicode

Then I use:

 fixed_value=str(feature.GetFieldAsString(str(v)))

It worked.

But I am not sure why it work in a shell environment but not in a web environment. I hope someone can explain this.

hguser
  • 35,079
  • 54
  • 159
  • 293

0 Answers0