让路径为Desktop \ Chem \ test.png 我想打印没有.png的文件名 这是我的代码
def test():
file=pickAFile()
shortFile=getShortPath(file)
end = shortFile.split('\\')[1]
print"this is a",end
所以解决方案是“这是一个测试”,而不是“这是一个test.png”
答案 0 :(得分:1)
首先,您应该使用os.sep而不是显式\(因此这将适用于Windows,Linux,OS-X等,而不仅仅是Windows,但更好的是,在这种情况下,使用操作系统.path.splitext和os.path.basename(如the jython docs which appear to exactly match the python equivalent
中所述)类似的东西:
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamResult;
private String getOuterXml(XMLStreamReader xmlr) throws TransformerConfigurationException,
TransformerFactoryConfigurationError, TransformerException
{
Transformer transformer = TransformerFactory.newInstance().newTransformer();
StringWriter stringWriter = new StringWriter();
transformer.transform(new StAXSource(xmlr), new StreamResult(stringWriter));
return stringWriter.toString();
}