简体   繁体   English

将OS模块与raw_input一起使用时出错

[英]Error using OS module with raw_input

I have wrote the following code: 我写了以下代码:

import os

def a():
    take = raw_input("insert: ")
    os.system("ifconfig eth0 hw ether %d") %take

a()

i get an error that unsupported operand type(s) for %: 'int' and 'str' . 我收到一个错误,指示unsupported operand type(s) for %: 'int' and 'str' how can i make it work and get the string from 'take' that will be with letters, numbers and punctuation..?? 我如何使它工作并从'take'中获取字符串,该字符串将包含字母,数字和标点符号。 (i want to insert a MAC address..). (我想插入一个MAC地址。)。

Thannks 坦克斯

In your code, raw_input returns a string so the variable take is a string. 在您的代码中, raw_input返回一个字符串,因此变量take是一个字符串。

import os

def a():
   take = raw_input("insert: ")
   os.system("ifconfig eth0 hw ether %s" % take)

Your syntax is incorrect Try below code 您的语法不正确尝试以下代码

os.system("ifconfig eth0 hw ether %d"%take)

Use this : 用这个 :

import os

def a():
   take = raw_input("insert: ")
   os.system("ifconfig eth0 hw ether %s" % take)

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

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