Answer the question
In order to leave comments, you need to log in
How to extract data on a specific delimiter?
I originally solved the problem in bash with cut,sed. But this thing works for about an hour. handles bulky files. Decided to convert to Python.
the processed text might look something like this:
слова какие-то 4234 цифры буквы что угодно символы - +
и табличка:
|текст |452 | цифры | пробелы |
#!/usr/bin/python
import sys
import re
import os
towrl = sys.argv[1]
dodestlip = []
destlip = open(towrl, "r")
dodestlip = destlip.readlines()
length1 = len(dodestlip)
destlip.close()
respa = []
for I in range(length1):
mregexp = re.compile( '^\|' )
if len(mregexp.findall( dodestlip[I] )) != 0:
mregexp = re.compile( r"[|]" )
respa.append(mregexp.split( dodestlip[I] ))
print respa
Answer the question
In order to leave comments, you need to log in
Need more examples on your inputs and what should come out.
I think re is redundant here. Try like this:
#coding: utf-8
row = u'|text |452 | digits | |'
cells = [cell.strip() for cell in row.split('|') if cell.strip()]
print cells
['text', '452', 'digits']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question