摘要
列出工作空间中的数据版本。
讨论
可以指定作为函数参数的连接文件的路径,或为连接文件设置工作空间环境并调用不带任何参数的 ListVersions 函数。
语法
ListVersions (sde_workspace)
参数 | 说明 | 数据类型 |
sde_workspace | An enterprise geodatabase workspace. | String |
返回值
数据类型 | 说明 |
Version | 该列表从包含 Version 对象的函数返回结果。 |
代码实例
ListVersions 示例 1
识别上周修改的所有数据库版本。
import arcpy
import datetime
# Use datetime to establish current date/time
#
now = datetime.datetime.now()
sdeConnection = "Database Connections/toolboxDEFAULTVersion.sde"
# Compare lastModified property of each version to current date, and
# print version name if the version was modified in the last 7 days.
#
for version in arcpy.da.ListVersions(sdeConnection):
if (now - version.lastModified).days < 7:
print(version.name)
ListVersions 示例 2
请删除所有属于特定用户、且不具有任何子版本的数据库版本。
import arcpy
sdeConnection = "Database Connections/toolboxDEFAULTVersion.sde"
for version in arcpy.da.ListVersions(sdeConnection):
# Delete any versions owned by "RJones" that don't have any children
#
if version.name.split(".")[0] == "RJones" and not version.children:
print("Deleting version {0}".format(version.name))
arcpy.DeleteVersion_management(sdeConnection, version.name)