Home arrow Python arrow Page 5 - File Management in Python

Creating In-memory Files - Python

File management is a basic function, and an important part of many applications. Python makes file management surprisingly easy, especially when compared to other languages. Peyton McCullough explains the basics.

  1. File Management in Python
  2. Getting Information on Existing Files
  3. Directories
  4. Pickling Data
  5. Creating In-memory Files
By: Peyton McCullough
Rating: starstarstarstarstar / 108
January 31, 2005

print this article




A number of modules you will encounter contain methods that require a file object as an argument. Sometimes, it is inconvenient to create and use a real file, however. Thankfully, you can create files that store themselves in a computer's memory using the "StringIO" module: 

import StringIO

fileHandle = StringIO.StringIO ( "Let freedom ring." )

print fileHandle.read() # "Let freedom ring."


A "cStringIO" module is also availible. It is identical to the "StringIO" module in use, but, just like the "cPickle" module is to the "pickle" module, it is faster: 

import cStringIO

fileHandle = cStringIO.cStringIO ( "To Kill a Mockingbird" )

print fileHandle.read() # "To Kill a Mockingbid"




File management is a task that programmers of many languages will often encounter in their applications. Thankfully, Python makes the task incredibly easy compared to other languages. It offers many modules in its standard library that aid programmers, and its object orientation further simplifies things.


You now have a basic understanding of file management in Python, and you will use it in many future applications.

>>> More Python Articles          >>> More By Peyton McCullough

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: