简体   繁体   English

有没有办法在python中的telnet命令中放置一个变量?

[英]Is there any way to put a variable inside telnet command in python?

is there any way to put the variable posorprom inside the telnet command in python?有没有办法将变量posorprom放在python中的telnet命令中? Here is a peace of my code:这是我的代码的和平:

posorprom = prom

tn.write(b"ls /mnt/flash/prom | wc -l\n")

i want to put the variable posorprom inside the command, so i already tried this:我想把变量 posorprom 放在命令中,所以我已经试过了:

tn.write(b"ls /mnt/flash/" + posorprom + " | wc -l\n")

but it doesnt work.但它不起作用。 please help me.请帮我。

Well you seem to concatenate different kinds of strings, since you use raw byte strings for one string, then all the strings must be that:好吧,您似乎连接了不同类型的字符串,因为您对一个字符串使用原始字节字符串,那么所有字符串都必须是:

posorprom = b"prom"
tn.write(b"ls /mnt/flash/" + posorprom + b" | wc -l\n")

posorprom = prom does not set the variable posoprom to "prom", but to the value of the variable prom. posorprom = prom不会将变量 posoprom 设置为“prom”,而是设置为变量 prom 的值。

Try posorprom = "prom" instead.尝试posorprom = "prom"代替。

posorprom = "prom" tn.write("ls /mnt/flash/" + posorprom + " | wc -l\\n")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM