handling spaces in variables in Python

1378
4
11-15-2010 09:28 PM
DustinEdge
Occasional Contributor
Greetings All

I'm trying to write a script that takes a dataset from the drop-down option in a tool, extracts the filename and folder path from it, determine whether the folder is a normal folder or a gdb, queries the type of dataset it is (point, line, polygon, raster) and write it all to a text file.

Unfortunately, the way our file system is setup is causing me pain. Here's a typical filepath:
J:\MMPL\60153995\4. Tech Work Area\4.7 GIS\Mike11_data.gdb\DHI_CrossSections

* Note the spaces in the path

My problem is that when trying to run the script in PythonWin I have to insert the whole path in "" "" to get Python to see it as one variable.
If I don't, it thinks that only J:\MMPL\60153995\4. is the variable's contents

But that works as I can use os.path.dirname & os.path.basename to extract the filename & folderpath.
BUT....I can't use the variable in a Describe on that variable. It returns a 999999 RunTimeError.

The goal is to have a script that I can use to populate a data register of sorts. I wasn't expecting to get bogged down on this simple first bit...argh.

Any help would be greatly appreciated.
0 Kudos
4 Replies
ChrisMathers
Occasional Contributor III
Try raw strings. You use an r flag at the begining of the string.

r'string'
0 Kudos
DustinEdge
Occasional Contributor
Hi Chris

It wasn't the raw strings that was causing the problem.... embarrassingly...it was me.

I was using a filepath that didn't exist...

Cheers
0 Kudos
ChrisMathers
Occasional Contributor III
Ha! If I had a dollar for every typo and wrong path Ive had I could hire a programmer to do this stuff for me.
0 Kudos
DaleHoneycutt
Occasional Contributor III
Ha! If I had a dollar for every typo and wrong path Ive had I could hire a programmer to do this stuff for me.


And I'd be retired, living in luxury in some tropical isle, drinking Pina Coloda's a boring everyone with how the Intersect tool works...
0 Kudos