Reading in a file

M

Maggie

hello,

i have a basic script i need to implement. i need below code to read
in a file and perform operation is it designed to do:

#!/usr/bin/python

import sys

feed = sys.stdin.readlines()

for temp in feed:
line = temp.split()
if len(line) == 3:
if (line[0] == "xmax" or line[0] == "xmin"):
time = line[2]
print str(line[0]) + " " + str(line[1]) + " " +
str(float(time)*2/3)
else:
print temp
else:
print temp

i appreciate your help in advance..
 
C

Chris Rebert

hello,

i have a basic script i need to implement. i need below code to read
in a file and perform operation is it designed to do:

#!/usr/bin/python

import sys

feed = sys.stdin.readlines()

This sounds like homework, so here are some clues:
sys.stdin is a file object.
open('/path/to/file.here', 'r') creates a new readable file object
representing the file at the given path.

You should be able to figure it out from there.

Cheers,
Chris
 
G

Gabriel Genellina

i have a basic script i need to implement. i need below code to read
in a file and perform operation is it designed to do:

#!/usr/bin/python

import sys

feed = sys.stdin.readlines()

for temp in feed:
line = temp.split()
if len(line) == 3:
if (line[0] == "xmax" or line[0] == "xmin"):
time = line[2]
print str(line[0]) + " " + str(line[1]) + " " +
str(float(time)*2/3)
else:
print temp
else:
print temp

i appreciate your help in advance..

You forgot to tell us what's wrong with it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top