typeError about wrong type where type isn't relevant

469
4
Jump to solution
02-14-2012 03:31 AM
MennoNijhuis1
New Contributor III
My script below produces the following output and error:
DLB legger_kanaal.gdb L:\20_Productie\versie 0.3\DLB\data\legger_kanaal.gdb vStuw L:\20_Productie\versie 0.3\DLB\data\legger_kanaal.gdb\vStuw Traceback (most recent call last):   File "<string>", line 248, in run_nodebug   File "C:\Users\nijhm\Desktop\export_kunstwerktabellen.py", line 41, in <module>     for kw in kunstwerklist: TypeError: object of type 'dict' has no len()


I've hashed out all but one of the dict items, this has made no difference, neither did shortening the 'kunstwerklist' to one item. Print statements were only added for clearance when debugging.
I've fiddled around with the script a little. Before I did that it produced the same error (at the line with fgdb = os.path.join(leggermap,rd,'data',db))but traced it also back to ntpath.py (os module) line 96 which does indeed include a len() method, whereas my script doesn't. Also, the input to the os.path.join is in no case a <type 'dict'>, apart from the fact that getting a len() from a dictionary shouldn't be a problem.
Also, when reproducing the script step by step in the Python interpreter window (without dictionary or for loops), no error occurs.

Most important finding thusfar (and reason of posting here and not on www.python-forum.org): when hashing out the gp.TableToDBASE_conversion(), the script simply prints as it is instructed to do and does not produce an error!

Please reply if you have any ideas of why this might go wrong, or have any other idea of exporting a lot of gdb tables to dbf.

import os, arcgisscripting gp = arcgisscripting.create(9.3)  exportmap = r'L:\20_Productie\versie 0.3\Werk\kunstwerktabellen' leggermap = r'L:\20_Productie\versie 0.3'  dictType = { ##              "DIJG":["legger_openwater.gdb"], ##              "DNB":["legger_kanaal.gdb"], ##              "DNH":["legger_openwater.gdb","legger_kanaal.gdb"], ##              "DNN":["legger_openwater.gdb"], ##              "DON":["legger_kanaal.gdb","legger_rivier.gdb"],               "DLB":["legger_kanaal.gdb","legger_rivier.gdb"], ##              "DUT":["legger_kanaal.gdb"], ##              "DZH":["legger_rivier.gdb"], ##              "DZL":["legger_openwater.gdb","legger_kanaal.gdb"]               }  ##kunstwerklist = ['vStuw','vSchutsluis','vInUitwateringSluis','vWaterReguleringsWerk','vGemaal'] kunstwerklist = ['vStuw'] exportlist = []  for rd in dictType:     print rd     for db in dictType[rd]:         print db         fgdb = os.path.join(leggermap,rd,'data',db)         print fgdb         for kw in kunstwerklist: ## THIS IS LINE 41             print kw             geval = os.path.join(fgdb,kw)             print geval             gp.TableToDBASE_conversion(geval,exportmap)             exportlist.append(geval)  print exportlist del gp

-----
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32.
Pyscripter 2.4.3.0 (but also crashes in IDLE 2.6.5)
ArcGIS Desktop 10.0 SP3
Win7 x64
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MennoNijhuis1
New Contributor III
Actually, that isn't necessary with the TableToDBASE tool, as the output table becomes the same name as the input table. However, I now realize that the input table names may have a name which is too long for a dbf table, which might be the cause of the error.
When looking for abilities to specify the output table's name, I found another tool (TableToTable) with which I am able to copy a GDB table to dbf format as well, without errors, and while specifying the table name for each export.

So, still a little strange but I found a workaround. Thanks for your help! 🙂

View solution in original post

0 Kudos
4 Replies
BruceNielsen
Occasional Contributor III
I think what you want is instead of
for rd in dictType:
you should use
for rd in dictType.keys():
That will give the for loop a list of all of the keys (unordered of course) of the dictionary.
0 Kudos
MennoNijhuis1
New Contributor III
Thanks for the reply, but no that doesn't work, as both produce exactly the same list of values for rd.
0 Kudos
BruceNielsen
Occasional Contributor III
I don't see where you declare the export file name. You might need to your script to something like:
gp.TableToDBASE_conversion(geval,os.path.join(exportmap,"name.mdb"))
0 Kudos
MennoNijhuis1
New Contributor III
Actually, that isn't necessary with the TableToDBASE tool, as the output table becomes the same name as the input table. However, I now realize that the input table names may have a name which is too long for a dbf table, which might be the cause of the error.
When looking for abilities to specify the output table's name, I found another tool (TableToTable) with which I am able to copy a GDB table to dbf format as well, without errors, and while specifying the table name for each export.

So, still a little strange but I found a workaround. Thanks for your help! 🙂
0 Kudos