python命令提示符窗口下如何运行python脚本解析-创新互联

python命令提示符窗口下如何运行python脚本解析?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

成都创新互联是一家专业提供蔚县企业网站建设,专注与成都网站制作、成都做网站、外贸营销网站建设成都h5网站建设、小程序制作等业务。10年已为蔚县众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。

方式一:脚本中指定好相关参数设置

python命令提示符窗口下如何运行python脚本解析

import arcpy
import json
import sys
import os
import argparse
import re

result = ""
jsontext = {'success': {}, 'msg': ''}


def checkSavedAprxDatasource(output_aprx_path, mapName, targetDb):
  check_result = True
  desc = arcpy.Describe(targetDb)

  saved_aprx = arcpy.mp.ArcGISProject(output_aprx_path)
  for saved_map in saved_aprx.listMaps():
    if saved_map.name == mapName:
      for lyr in saved_map.listLayers():
        if lyr.isFeatureLayer:
          # print(lyr.connectionProperties)
          if lyr.connectionProperties['workspace_factory'].upper() == 'SDE'.upper(
          ) and lyr.connectionProperties['connection_info']['instance'] == desc.connectionProperties.instance:
            pass
          else:
            check_result = False

  return check_result


if __name__ == '__main__':
  try:

    # linux
    # aprxPath = str(sys.argv[1])
    # mapName = str(sys.argv[2])
    # sourceDb = str(sys.argv[3])
    # targetDb = str(sys.argv[4])
    # output_aprx_path = str(sys.argv[5])

    # local pc
    aprxPath = r'D:\rvt\testaprx\testaprx.aprx'
    mapName = 'Map'
    sourceDb = r'D:\rvt\testaprx\Data.gdb'
    targetDb = r'D:\rvt\testaprx\testsde.sde'
    output_aprx_path = r'D:\rvt\testaprx\output\export5.aprx'

    aprx = arcpy.mp.ArcGISProject(aprxPath)
    for m in aprx.listMaps():
      if m.name == mapName:
        m.updateConnectionProperties(sourceDb, targetDb)

    if os.path.exists(output_aprx_path):
      os.remove(output_aprx_path)
    aprx.saveACopy(output_aprx_path)

    checkResult = checkSavedAprxDatasource(
      output_aprx_path, mapName, targetDb)
    if checkResult:
      jsontext['success'] = True
      result = json.dumps(jsontext)
      sys.stdout.write(result)
    else:
      jsontext['success'] = False
      jsontext['msg'] = 'Failed to replace data source'
      result = json.dumps(jsontext)
      sys.stdout.write(result)

  except Exception as e:
    jsontext['success'] = False
    jsontext['msg'] = e.args
    result = json.dumps(jsontext)
    sys.stdout.write(result)

当前题目:python命令提示符窗口下如何运行python脚本解析-创新互联
标题来源:http://azwzsj.com/article/ccgjgj.html