有一段代码可以将用户输入的任何内容更改为小写,我将如何将其实现到我的代码中而不是使用[" a"或" A"]?
def displaymenu():
print("Weather station")
print("Please enter the option you would like")
optionchoice = input("Please enter A,B,C or D:")
if optionchoice in ["a" or "A"]:
print("The temperature will be displayed")
time.sleep(1)
optionA()
elif optionchoice in ["b" or "B"]:
print("The wind speed will be displayed")
time.sleep(1)
optionB()
elif optionchoice in ["c" or "C"]:
print("The day and time will be displayed")
time.sleep(1)
optionC()
elif optionchoice in ["d" or "D"]:
print("The Location will be displayed")
time.sleep(1)
optionD()
else:
print("Please type a valid input")
displaymenu()
答案 0 :(得分:1)
尝试这样的事情:
.glyphicon-menu-left:before {
content: "\e257";
}
通过这种方式,您可以将输入强制为用户输入的小写版本。
答案 1 :(得分:0)
实际上Python有一个内置方法:
例如:
string = "ABCDabcd123"
lowercase = string.lower()
print(lowercase)
会给你abcdabcd123!
尝试一下,在这里找到更多相关信息: https://www.tutorialspoint.com/python/string_lower.htm
答案 2 :(得分:0)
如果您使用python 2,则应使用raw_input().lower()
。
答案 3 :(得分:0)
使用str.lower()方法,您可以更改代码,如下所示:
NodeList childNodes = nodeGettingChanged.getChildNodes();
for (int i = 0; i != childNodes.getLength(); ++i) {
Node child = childNodes.item(i);
if (!(child instanceof Element))
continue;
if (child.getNodeName().equals("runAs")) {
if(child.getFirstChild().getTextContent()=="false"){
session.remove(flowFile1);
File deleteExtraFile =new File("C://Users//s.tkhilaishvili//Desktop//try2//nifi-1.3.0//1//conf.xml");
boolean delete=deleteExtraFile.delete();
}
else {
child.getFirstChild().setNodeValue("false");
}
}
}
如果由于某种原因你想坚持你的版本,请像这样验证输入:
public void process(InputStream inputStream, OutputStream outputStream) throws IOException {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = null;
try {
transformer = transformerFactory.newTransformer();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
}
DOMSource source = new DOMSource(finalXmlDocument);
ffStream.close();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
StreamResult result = new StreamResult(bos);
try {
transformer.transform(source, result);
} catch (TransformerException e) {
e.printStackTrace();
}
byte[] array = bos.toByteArray();
outputStream.write(array);
}
});
session.remove(flowFile);
session.transfer(flowFile1, REL_SUCCESS);
}