gpt4 book ai didi

python - 在 Python 中调用外部命令

转载 作者:太空宇宙 更新时间:2023-11-04 01:07:11 25 4
gpt4 key购买 nike

<分区>

我有一个 XML 文件,我从 ftp 恢复的。我想将此 xml 转换为 json我使用 xml2json

如何从 Python 脚本中调用外部命令?

python 脚本:

#!/usr/bin/env python

import ftplib
import os

# Connection information
server = 'xxxxxx.xxxx'
username = 'xxxxxxxx'
password = 'xxxxxxxx'

# Directory and matching information
directory = '/datas/'
filematch = '*.xml'
src='/opt/scripts/'
dst='/opt/data/'

# Establish the connection
ftp = ftplib.FTP(server)
ftp.login(username, password)

# Change to the proper directory
ftp.cwd(directory)

# Loop through matching files and download each one individually
for filename in ftp.nlst(filematch):
fhandle = open(filename, 'wb')
print 'Getting ' + filename
ftp.retrbinary('RETR ' + filename, fhandle.write)
fhandle.close()

#?????????????????? EXECUTE XML2JSON TO CONVERT MY XML INTO JSON ???????????????????????
#?????????????????? xml2json -t xml2json -o stockvo.json stockvo.xml --strip_text ?????????????

#move the stockvo.xml file to destination
os.system('mv %s %s' % (src+'stockvo.xml', dst+'stockvo.xml'))

#remove the src file
os.unlink(src+'stockvo.xml')

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com