For the "workspace" variable, make sure you are specify the entire path. For example:workspace = r"C:\temp\test.gdb"
myFC = workspace + "\\my_fc"
domainList = []
fieldList = arcpy.ListFields(myFC)
for field in fieldList:
if field.domain != '' and field.domain not in domainList:
domainList.append(field.domain)
for domain in domainList:
domainTable = workspace + "\\domain_table_for_" + domain.replace(" ", "_") #replace any blanks with an underscore
arcpy.DomainToTable_management(workspace, domain, domainTable, "code", "description") #assuming cosde and description are the names
If you want to export all the domains in a workspace:workspace = r"C:\temp\test.gdb"
dsc = arcpy.Describe(workspace)
for domain in dsc.domains:
domainTable = workspace + "\\domain_table_for_" + domain.replace(" ", "_") #replace any blanks with an underscore
arcpy.DomainToTable_management(workspace, domain, domainTable, "code", "description") #assuming cosde and description are the name