LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-10-2003, 10:39 PM   #1
dumpthecore
LQ Newbie
 
Registered: Nov 2003
Distribution: Red Hat 9
Posts: 5

Rep: Reputation: 0
reading fields from files in python without \t \n


PyGurus,

When I do readlines onto a file, with several columns, it returns it with
data\t\n. I would like to have the first column in a array, second one in another
and so on.

First is that I would like to strip these characters \t\n,
Second allocating the column to an array.

finp=open("test1.dat","r")
lines=finp.readlines()

I would appreciate some pointers.

Thanks
DTC.
 
Old 12-11-2003, 04:57 AM   #2
yuray
Member
 
Registered: Apr 2003
Location: Russia, Khotkovo
Distribution: Debian
Posts: 146

Rep: Reputation: 15
read doc on module string
import string
>>> x=open('/etc/passwd','r')
>>> s=x.readlines()
>>> s
['root:x:0:0:root:/root:/bin/bash\n', 'daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n', 'bin:x:2:2:bin:/bin:/bin/sh\n',
>>> string.strip(s[0])
'root:x:0:0:root:/root:/bin/bash'
>>>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to learn programming languages like python reading tutorials? cyto Programming 25 12-25-2004 08:40 PM
Reading files in C++, using *. poeta_boy Programming 4 07-08-2004 01:01 AM
reading PDF files vineet Linux - Newbie 5 06-26-2004 12:10 PM
Reading Files clowns119 Programming 12 09-23-2003 06:06 PM
reading files MrGardenHoseMan Linux - Newbie 2 07-06-2003 05:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration