From owner-freebsd-python@FreeBSD.ORG Tue Aug 24 14:47:53 2004 Return-Path: Delivered-To: freebsd-python@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CB59816A4CE for ; Tue, 24 Aug 2004 14:47:53 +0000 (GMT) Received: from web25408.mail.ukl.yahoo.com (web25408.mail.ukl.yahoo.com [217.12.10.142]) by mx1.FreeBSD.org (Postfix) with SMTP id DAB8743D55 for ; Tue, 24 Aug 2004 14:47:52 +0000 (GMT) (envelope-from max_russell2000@yahoo.co.uk) Message-ID: <20040824105814.36955.qmail@web25408.mail.ukl.yahoo.com> Received: from [194.247.82.75] by web25408.mail.ukl.yahoo.com via HTTP; Tue, 24 Aug 2004 11:58:14 BST Date: Tue, 24 Aug 2004 11:58:14 +0100 (BST) From: =?iso-8859-1?q?Max=20Russell?= To: freebsd-python@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Splitting elements on a line? X-BeenThere: freebsd-python@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: FreeBSD-specific Python issues List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Aug 2004 14:47:53 -0000 Hello- If I have a file made up of lines like this: one two three four five six seven eight nine how can I read the individual items into a lit, so that I do not get each list item consisting of something like: "one two three" Currently I have this: import os, os.path, random filename = ("C:\list.txt") file = open(filename,"r") word_list = file.readlines() file.close() print word_list # output from this program has format ['one two three\n', 'four five six'] # therefore- need to split each item into individual compenents # also- need to remove whitespace and newline character So: Would I perform a split after all of the above? Would I be better performing the split before reading the items into the list? thanks Max ___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com