0

I have been trying to make a script to automate some steps in a process that uses tables from different databases. One of them changes its name every week - name+date eg: "MegaDataBase_16062019.mdb"

How can I make use of the table in it?

I've tried arcpy.ListWorkspaces, something like:

 datain = arcpy.ListWorkspaces("\\hugeserver\mainwork\databases\MegaDataBase_*","Access")
 tableat = datain+".mdb\WorthyTable"

and that got an error, because the result in "datain" was:

u"["\hugeserver\mainwork\databases\MegaDataBase_16062019.mdb"]

I was linking to

u"["\hugeserver\mainwork\databases\MegaDataBase_16062019.mdb"]\WorthyTable

So, the wildcard* works, and I find the MDB I want, but can't make use of it to build the path I need

What I need from that table, is to export it with some fieldmappings to a .GDB on my machine

I used * or ? not quite sure now...tomorrow I can confirm it, and share more info if needed, as well as test your suggestions

1

I think you are close...however

Based on this documentation, ListWorkspaces returns a list. So to use the output,

  1. First call to get the Workspaces list
  2. Then check the length
  3. If the length is > 0 then get the first element which is zero-indexed [0]
  4. Use that element of the list as a string in the concatenation

Sample code (not tested)

datain = arcpy.ListWorkspaces("\\hugeserver\mainwork\databases\MegaDataBase_*","Access")

                    if len(datain) > 0:
                       mymdb = datain[0]
                       tableat = mymdb + ".mdb\WorthyTable"

##edit: after composing the fc source, now make a featurelayer
var myfeaturelayer = arcpy.MakeFeatureLayer_management(tableat, "myfeature_lyr")
  • Hi @JasonInVegas , that seems to work but I'm not quite sure, can I check the result with print? The next step is to MakeFeatureLayer and I can't define the feature for it: codeif len(LCpath) > 0: LCmdb = LCpath[0] LC = LCmdb + "\LISTA_COMPLETA" arcpy.MakeFeatureLayer_management(LC, "LC_lyr")code – FTeixeira Jul 17 at 11:15
  • I updated the solution just like you commented. I suggest you use the python command window inside arcgis 10.2 so you can interrogate the results...including the featurelayer. Remember you can perform these steps manually using tools from default toolboxes, then convert your tool usage into python code! Please also mark whatever answer is correct when you are ready. – JasonInVegas Jul 17 at 17:18
  • @JasoInVegas hi thank you, i'm still stuck, here how it looks – FTeixeira Jul 18 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.