pythoncmd命令输入去掉空格_如何跳过python命令行参数中的空格和空格?

我有以下代码,我试图以此作为论据。import sys

try:

import xml.etree.cElementTree as ET

except ImportError:

import xml.etree.ElementTree as ET

#location for the xml file where parsing is required

param1 = sys.argv[1]

#parent tag of new tag

param2 = sys.argv[2]

param3 = sys.argv[3]

param4 = sys.argv[4]

print(param3)

#parse the config file

tree = ET.parse(param1)

#get the root of config file

root = tree.getroot()

#add element exactly at particular point

tar = param2

#this will find the root tag

target = tree.find(tar)

#new tag required to be inserted

seq = param3

#taking new tag element in element tree

temp = ET.Element(seq)

#insert the position where you want to enter

i = int(param4)

target.insert(i,temp)

temp.tail = '\n'

tree.write(param1,encoding='utf-8')

和另一个获得参数b.py的文件:-#!/usr/bin/python

import socket

import xmlparser.py

host1 = socket.getfqdn()

print(host1)

param1 = 'config.xml'

param2 = 'Target'

param3 = 'Attribute NAME="A" VALUE="((host={0},ip=123.0.0.0,port=22),(host=

{0}, port=11),(host={0}, port=162))"'.format(host1)

param4 = 3

python xmlparser.py param1 param2 param3 param4

当我运行“pythonb.py”时,我得到错误作为无效的语法,这是为什么?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值