Python ascii.read tab(?) delimiters -


i trying use ascii.read scan in large number of tabulated data files. column headings not appear have self-consistent delimiters. there range 2 7 spaces between each column header. files looks this:

  k    waveln    neff       geom alb   bond/qfit  bond/geom  q-fitted    1  0.3000000    0.0556723    0.0000000    0.0000000    2.1435934    2.0582306 [...] [...] 

i first suspected treat them tabs, not appear case:

raw = (ascii.read('filename', delimiter='\t') 

will read file returns quite useless single column of data.

now, not problem under normal cases - simple

delimter='\s' 

could have done trick. frustration, 1 column named "geom alb" - complete space in middle. fouls delimiter, thinks 2 column headers, not one:

raw = (ascii.read('filename',delimiter='\s') inconsistenttableerror: number of header columns (8) inconsistent data columns (7) @ data line 0 

this solveable replacing "geom alb" header "geom_alb" in files in question, prefer avoid spending time write script this, particularly if there more simple , elegant solution.

i found workaround problem here. calling ascii.read as

raw = (ascii.read('filename',guess=false,header_start=none,data_start=2,names=('k','waveln','neff','geom alb','bond/qfit','bond/geom','q-fitted'))) 

i able bypass ascii.read's attempts find , apply header names , define them myself. key of course being

header_start=none 

which tells ascii.read there no headers.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -