selecting only letters of a string
hi,
I want to store each line of a text file in a list. But lines don't start from the first column. So when I want to compare some other string with them I need only its letter not the whole string with spaces. I know this is quite easy question but I am new to python and I have thousands of questions. thanks |
Moved: More suitable in our Programming forum.
And you might get better or more responses if you actually put what programming language your using in your title or at least in the beginning of your thread. I had no idea you were speaking of Python until I had to read 2/3's of your thread. |
Re: selecting only letters of a string
Quote:
You can store the contents of a file in a list using list comprehension as follows: Code:
file_list = [line[:-1] for line in open('test.txt', 'r').readlines()] Code:
['# Copyright 1999-2005 Gentoo Foundation', '# Distributed under the terms of the GNU General Public License v2', '# $Header:$', '', 'inherit webapp', '', 'DESCRIPTION="Jinzora is a web based media streaming and management system, designed to stream audio and video files to any internet connected computer - anytime, anywhere."', 'HOMEPAGE="http://www.jinzora.org/"', 'SRC_URI="mirror://sourceforge/jinzora/j2.0.1.tar.gz"', '', 'LICENSE="GPL-2"', 'KEYWORDS="~x86"', '', 'RDEPEND="virtual/php"', '', 'S=${WORKDIR}/${PN}2', '', 'src_install() {', '\twebapp_src_preinst', '', '\tdodoc ${S}/docs/*', '\trm -rf ${S}/docs/', '', '\tcp -a * "${D}/${MY_HTDOCSDIR}"', '', '\techo "<?php trigger_error(\'Please use install/install.php to configure phpBB for your system!\', E_USER_ERROR); ?>" > "${D}/${MY_HTDOCSDIR}/config.php"', '\twebapp_serverowned "${MY_HTDOCSDIR}/config.php"', '', '\twebapp_postinst_txt en ${FILESDIR}/2.0.10-postinstall-en.txt', '', '\twebapp_src_install', '}', '', 'http://www.gentoo.org/proj/en/glep/glep-0011.htm'] Code:
line = ' this has spaces in the front' |
Thank you man, you were quite helpful :)
|
All times are GMT -5. The time now is 09:42 AM. |