How to change the timeout on a .NET WebClient object

You can extend the timeout: inherit the original WebClient class and override the webrequest getter to set your own timeout, like in the following example. MyWebClient was a private class in my case: private class MyWebClient : WebClient { protected override WebRequest GetWebRequest(Uri uri) { WebRequest w = base.GetWebRequest(uri); w.Timeout = 20 * 60 * … Read more

In Java, how do I parse XML as a String instead of a file?

I have this function in my code base, this should work for you. public static Document loadXMLFromString(String xml) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(xml)); return builder.parse(is); } also see this similar question

How often does python flush to a file?

For file operations, Python uses the operating system’s default buffering unless you configure it do otherwise. You can specify a buffer size, unbuffered, or line buffered. For example, the open function takes a buffer size argument. http://docs.python.org/library/functions.html#open “The optional buffering argument specifies the file’s desired buffer size:” 0 means unbuffered, 1 means line buffered, any … Read more

Read only the first line of a file?

Use the .readline() method (Python 2 docs, Python 3 docs): with open(‘myfile.txt’) as f: first_line = f.readline() Some notes: As noted in the docs, unless it is the only line in the file, the string returned from f.readline() will contain a trailing newline. You may wish to use f.readline().strip() instead to remove the newline. The … Read more