REPOST: Re: custom split function

Fernando Pérez fperez528 at yahoo.com
Tue Dec 25 18:44:44 EST 2001


I.J. wrote:

> Hi
> Is there a way to spit file content into list of individual
> bytes/characters.
> I know it could be done with substring manipulation but I hope there is more
> direct way.
> Bye

file = open('filename')
file_as_string = file.read()


Now you have your whole file in a string, which for most purposes can be 
thought of as a list of characters. And you can always do

file_as_list = list(file_as_string)

if you really want it as a list.

hth,

f

========= WAS CANCELLED BY =======:
Path: news.sol.net!spool0-nwblwi.newsops.execpc.com!newsfeeds.sol.net!news-out.visi.com!hermes.visi.com!newsxfer.interpacket.net!news-xfer.nuri.net!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r
From: Fernando =?ISO-8859-1?Q?P=E9rez?= <fperez528 at yahoo.com>
Newsgroups: comp.lang.python
Subject: cmsg cancel <a0ee8a$f39$1 at peabody.colorado.edu>
Control: cancel <a0ee8a$f39$1 at peabody.colorado.edu>
Date: Mon, 31 Dec 2001 02:46:09 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.a0ee8a$f39$1 at peabody.colorado.edu>
NNTP-Posting-Host: 211.57.49.2
X-Trace: news2.kornet.net 1009775901 27193 211.57.49.2 (31 Dec 2001 05:18:21 GMT)
X-Complaints-To: usenet at news2.kornet.net
NNTP-Posting-Date: Mon, 31 Dec 2001 05:18:21 +0000 (UTC)
X-No-Archive: yes
X-Unac4ncel: yes
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)

This message was cancelled from within Mozilla.



More information about the Python-list mailing list