Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Following a few online tutorials I have seen, I am trying to create a mapfile from scratch using mapscript. However, when I try to create the layer object, I get an error in the init of; NameError: global name 'args' is not defined.

Does anyone see something obvious? When I use a mapfile that already exists on disk, everything works as expected.

        # create a new mapfile from scratch = mapscript.mapObj()''),256),-90.0,180.0,90.0) mapscript.MS_DD,255,255)

        # create a layer for the raster
        self.layer = mapscript.layerObj( ----> ERROR HAPPENS HERE 'tilesource'
        self.layer.type= mapscript.MS_RASTER
        self.layer.status = mapscript.MS_ON rasterpath
share|improve this question
Was this resolved somehow? I'm getting the same error. – alxx May 24 '11 at 7:58

According to, creating a layer object works differently:

test_map = new mapscript.mapObj()
new_layer = new mapscript.layerObj()
li = test_map.insertLayer(new_layer)
share|improve this answer
Thanks for the suggestion, still get the same error with this approach. – user890 Apr 20 '11 at 11:52
Can you post the whole script? I can't see where it gets "global name 'args'" from. – underdark Apr 20 '11 at 11:53
The error is happening in, the SWIG generated wrapper. Its occurring in the init function at Line 1264. Do you want me to attach the file? – user890 Apr 20 '11 at 13:38
So "new mapscript.layerObj()" produces the same error like "mapscript.layerObj("? (Notice keyword "new".) Which version of Mapserver are you running? – underdark Apr 20 '11 at 17:37
The new keyword isn't required for Python. These seem to be left over from the PHP examples. – geographika Jul 4 '11 at 20:54

I am a mapserver developer and I have just committed a patch that should solve this issue. See changeset r12309 for the details.

share|improve this answer
Thank you @unicoletti. Nice to have you here! – underdark Aug 11 '11 at 12:47

I've been having the same problem when trying to create a new CLASS object. I've logged it as a bug as the SWIG wrappers seem incorrect for both layerObj and classObj. The args variable is defined in neither:

def __init__(self, map = None): 
    this = _mapscript.new_layerObj(map)
    try: self.this.append(this)
    except: self.this = this
    if 1:
          if args and len(args)!=0:

Using MapServer 6.0 and Python SWIG bindings version 1.3.39

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.