Select to view content in your preferred language

env.workspace treated as a string?

1355
4
07-30-2012 09:08 AM
ZulyG
by
Emerging Contributor

[/HR]


Every time I try to set the workspace on my script. I get the following error:

'exceptions.AttributeError'>: 'str' object has no attribute 'workspace'

I have tried  running it on the IDE and I get the same error :

import arcpy 
from arcpy import env
arcpy.env.workspace =  "C:/Documents and Settings"



I had previously used it but for some reason now it seems like it is treating the env as a string.  Any ideas as to how to fix this?
Tags (2)
0 Kudos
4 Replies
JasonScheirer
Esri Alum
Did you accidentally do something like

arcpy.env = 'string'

earlier in your script?
0 Kudos
markdenil
Frequent Contributor
can you read the workspace setting?
print arcpy.env.workspace

can you read or write any other arcpy.env property?

Try reading them with
import arcpy
environments = arcpy.ListEnvironments()
for environment in environments:
    envSetting = eval("arcpy.env." + environment)
    print "%-30s: %s" % (environment, envSetting)
print "\nDONE"
0 Kudos
Luke_Pinner
MVP Regular Contributor
You're also importing env separately. I don't think this will make any difference, but it is uneccessary.  Just use:
import arcpy 
arcpy.env.workspace =  "C:/Documents and Settings"
0 Kudos
markdenil
Frequent Contributor
That is right.
Since you imported env separetly, use    
env.workspace = r"C:\spam\a\lot"

you can then read it using     
print arcpy.env.workspace
or
print env.workspace

but setting it with   
arcpy.env.workspace = r"C:\spam\a\lot
will give an error
0 Kudos