New to Python need on advice on this script
python at mrabarnett.plus.com
Tue Nov 10 21:09:41 CET 2009
Jim Valenza wrote:
> Hello all - I'm new to the world of Python as I am a GIS guy who would
> like to broaden his horizons. I have a question about a script that
> we've been working on: The purpose of the code is to *Syncronize SDE
> DropBox with Regulatory Project working files. *
> I am looking for where the script dumps the domain list to a table and
> loops through the table? Is It necessary? Seems like you should be able
> to simply loop through the domain list. I was just trying to see if
> there was a more straitforward way. Thanks
> The script is as follows:
I've spotted a bug:
P_Value = (P.strip(".mdb"))
The .strip() method DOESN'T strip off a string, it strips CHARACTERS off
P_Value will be P but with any number of the characters ".", "m", "d" or
"b" stripped off both ends, for example, if P == "my_database.mdb" then
P_Value will be "y_database".
You should do something like:
P_Value = P[ : -4]
P_Value = P
Another point: you're recording the valid domains in a list and then
if P_Value in domainList:
This will perform a linear search of the list, which can be slow if the
list is long.
It would be much more efficient to put the domains in a set instead.
Checking for the presence of an item in a set is fast.
More information about the Python-list