[Tutor] reading 2nd line

Jayprasad J. Hegde jjhegde@konark.ncst.ernet.in
Mon Jan 27 02:34:01 2003


--sm4nu43k4a2Rpi4c
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

hello Jens, 

On Sun, Jan 26, 2003 at 06:49:22PM +0100, Jens Kubieziel wrote:
> I have here several text files, where I want to read second line of each
> file and no idea how to do it. Those files are csv-files exported from MS
> Excel and have following format:
>     date,open,high,low,close,sales
>     01-01-03,11.23,11.24,10.66,10.87,678537

> Is there a better solution?
I have attached a very simple code which can either extract the "close" field directly for the second line, or 
extract only the second line (you'll have to uncomment the relevant code for that) 
This would work in for CSV docs in the following manner: 
cat inputCSVfile | python tp2.py

Whether this is a good solution or not would probably depend on its usage. 

Hope this helps. 
regards
- JJH
-- 
QOTD:
	If you're looking for trouble, I can offer you a wide selection.
(defun JJHdetails ()
  (format t "~&~A~&~A~&~A"
    "Jayprasad J Hegde, Staff Scientist, KBCS, NCST" "Gulmohar Cross
    Road 9, Juhu, Mumbai 400049." "tel: +91-22-26201606x373"))

--sm4nu43k4a2Rpi4c
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="tp2.py"

import sys
REQUIRED_ENTRY = 2
#0,1,2,3,4,5
POSITION_CLOSE = 4
myfile = sys.stdin
entries = myfile.read ().splitlines ()

### if you want to print only the second line
## then uncomment this line .. and comment the code following it
## print entries [REQUIRED_ENTRY - 1]

## else use this to extract the "close" field directly
req = entries [REQUIRED_ENTRY - 1].split (',')
print req [POSITION_CLOSE]



--sm4nu43k4a2Rpi4c--