Should I close StringIO instances explicitly?

I'm writing some tests using StringIO class and just wonder: I can close StringIO instance, since it is actually mimicking IO, but should I really bother? Should I close StringIO instances as I actually should close files?

Answers


Well, reads and writes go straight to the underlying string; there's no extra buffers to flush, and no OS-level resources to return.

The only reason you might want to close the StringIO is to make subsequent IOs fail or if you needed to make closed? return true, which could be useful if you gave that StringIO to some other component. On the other hand, if you're just going to discard the StringIO a moment later, it doesn't matter in the slightest; the garbage collector doesn't care if it's marked as open or closed.


Need Your Help

Why are my CoffeeScript/backbone.js events not firing?

javascript jquery coffeescript backbone.js

I'm trying to familiarize myself with CoffeeScript and backbone.js, and I must be missing something.

How to configure embedded jetty to access Jersey resources?

java jersey jetty embedded-jetty

I'm trying to configure embedded jetty to talk to my Jersey resources but I can't figure out how to do it. I've tried a couple of different things but nothing seems to work. The jetty tutorials don't

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.