Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

9.7. Input/Output

An IO object is a stream: a readable source of bytes or characters or a writable sink for bytes or characters. The File class is a subclass of IO. IO objects also represent the “standard input” and “standard output” streams used to read from and write to the console. The stringio module in the standard library allows us to create a stream wrapper around a string object. Finally, the socket objects used in networking (described later in this chapter) are also IO objects.

9.7.1. Opening Streams

Before we can perform input or output, we must have an IO object to read from or write to. The IO class defines factory methods new, open, popen, and pipe, but these are low-level methods with operating system dependencies, and they are not documented here. The subsections that follow describe more common ways to obtain IO objects. (And Section 9.8 includes examples that create IO objects that communicate across the network.)


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial