ihave a file containing data in the form of table with 5 columns and 10 rows the columns are separated by spaces . i have a to read the file line by line without reading the first line which is the header line.Please suggest me the code using python technology

Recommended Answers

All 3 Replies


f = open('C:/data.txt', 'rt')
a = f.read().split('\n')
del a[0]
del a[10:]
print a


Not so much to enjoy in that code.
You dont read file line by line as @vimalya mention.
With read() you read all file into memory.
del we almost never need to use in python.


1 2 3
4 5 6
7 8 9


with open('data.txt') as f:
    line = f.next()
    for line in f:
        #print line
        #You can procces data like this 
        print [int(item) for item in line.split()]

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]

Next time vimalya try to post some code,not just a task to solve.

thanks tis was a useful post....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.