Select to view content in your preferred language

AttributeError: 'str' object has no attribute 'workspace'

5444
5
03-06-2012 03:59 AM
by Anonymous User
Not applicable
When I type my simple testscript in the Python window in ArcGIS it runs fine.
When I try to debug the same script in PythonWin it can not find the workspace property of the arcpy.env object, it sees the env object as a string. Al the methods from a string object pop up in intellisense.

What's wrong?

import arcpy
from arcpy import env
import os

# Set the workspace for the ListFeatureClass function
#
env.workspace = "c:/data"

# Use the ListFeatureClasses function to return a list of 
#  all shapefiles.
#
fcList = arcpy.ListFeatureClasses()

Tags (2)
0 Kudos
5 Replies
JeffBarrette
Esri Regular Contributor
That is odd, it runs fine from IDLE.  Have you tried?

arcpy.env.workspace = "c:/data"


Jeff
0 Kudos
Zeke
by
Honored Contributor
I've found similar problems with PythonWin when running a script. Someone on the forums (sorry, forget who) posted that you first have to do an import arcpy in the Idle window before it's available in the script window. That's new to me, but it appears to work.
0 Kudos
GuyDuke
Deactivated User
This is nuts!  I was having the same issue but importing the module in IDLE then running the script in PythonWin worked.  This has to be a bug.  The help files for version 9.3 included PythonWin instructions, but with issues like this how could anyone promote PythonWin?  Thank you Greg!
0 Kudos
MathewCoyle
Honored Contributor
This is what you are looking for.

http://code.google.com/p/pyscripter/

Ten thumbs down for PythonWin. At least in relation to arcpy.
0 Kudos
GuyDuke
Deactivated User
I will never use PythonWin again...Thank you Mathew!
0 Kudos