想做一个东西,cli 或者当 library 都可以用。大概是
python main.py data.csv --transform "parser | get='name' | len==10 | original | parser | get='age'"
做的就是遍历所有行,parse 数据,找到“名字”长度为 10 的行,返回“age”
传输的数据:
class Item:
orignial: Any
value: Any
我写了 Parser, Len, GetField, Orignal 这几个 class 。初步计划是事先把 class 放到一个 dict 里,解析字符串为,并把操作符和数值拿来初始化 class
pipe_units = [
Parser(),
Get("=", "name"),
Len("==", "10"),
Original(),
Parser(),
Get("=", "name"),
]
然后 pipe = CompiledPipe(pipe_units)
wrapped_records = CsvReader(f) # 也是个 pipe unit
pipe.set_upstream(wrapped_records) # 或者 wrapped_records >> pipe
for out_record in pipe:
print(out_record)
这样的做法有什么明显缺陷吗?解析 pipe 字符串有什么比较好的方法吗?现在直接用 split 之类的方法来做,感觉很粗糙。这个 parse 动作,在业界有专有名词吗?谢谢各位
python main.py data.csv --transform "parser | get='name' | len==10 | original | parser | get='age'"
做的就是遍历所有行,parse 数据,找到“名字”长度为 10 的行,返回“age”
传输的数据:
class Item:
orignial: Any
value: Any
我写了 Parser, Len, GetField, Orignal 这几个 class 。初步计划是事先把 class 放到一个 dict 里,解析字符串为,并把操作符和数值拿来初始化 class
pipe_units = [
Parser(),
Get("=", "name"),
Len("==", "10"),
Original(),
Parser(),
Get("=", "name"),
]
然后 pipe = CompiledPipe(pipe_units)
wrapped_records = CsvReader(f) # 也是个 pipe unit
pipe.set_upstream(wrapped_records) # 或者 wrapped_records >> pipe
for out_record in pipe:
print(out_record)
这样的做法有什么明显缺陷吗?解析 pipe 字符串有什么比较好的方法吗?现在直接用 split 之类的方法来做,感觉很粗糙。这个 parse 动作,在业界有专有名词吗?谢谢各位
