拆分问题 [英] problem with split

查看:71
本文介绍了拆分问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

道歉,如果我烦恼和间距(谷歌)


def csdInstrumentList(from_file):

"返回.csd工具列表和任何

工具后的注释行

infile = open(from_file,''r'')

temp_number = 0

for infile:

如果''instr''在行:

s = re.split(r'''',line,3)

instr_number = s [1]

返回instr_number


我接近我想要的变化,但是我

似乎无法支付
得到3行拆分和instr_number [array] = s [1]似乎给了我一个错误。

来自我试图分成三行的数据看起来像

这个


instr 83;评论将是这里


我希望在数组中返回注释,并在

数组中返回instr_number。

解决方案

< BLOCKQUOTE> P.S。这是我需要完成的以释放csoundroutines



www.dexrow.com
Er ******** *@msn.com 写道:


道歉,如果我烦恼和间距(谷歌)


def csdInstrumentList(from_file):

"返回

工具后的.csd工具和任何注释行的列表>

infile = open( from_file,''r'')

temp_number = 0

for infile:

if''instr''in line:

s = re.split(r''+'',第3行)

instr_number = s [1]

返回instr_number

我很接近我想要的变化,但是我好像b $ b似乎无法支付
得到3行分割和instr_number [array] = s [ 1]似乎给了我一个错误。

来自我试图分成三行的数据看起来像

这个


instr 83;评论将在这里


我希望在数组中返回注释并在

中返回instr_number阵列。


2006年10月6日21:07:43 -0700, Er ********* @ msn.com < Er ********* @ msn.comwrote:


我希望在数组中返回注释,并在

数组中返回instr_number。



让我看看我是否理解你想要的东西:如果有一行

以instr开头(最好用line.startswith测试) (''instr''):)),你

想要数字和后来的commen。我用这个

目的的正则表达式。在您的情况下:


导入重新


< snip>


如果是line.startswith (''instr''):

p = re.compile(r''(\d +)\s +;(。*)


'' )

m = p.search(line)


return(m.group(1),m.group(2))


我当然返回了一个元组;你可能希望改变它。


BTW,谢谢 - 我刚学会了如何在Python中使用re。


apologies if I annoy and for spacing (google)

def csdInstrumentList(from_file):
"Returns a list of .csd instruments and any comment lines after the
instrument"
infile = open(from_file, ''r'')
temp_number = 0
for line in infile:
if ''instr'' in line:
s = re.split(r'' +'',line,3)
instr_number = s[1]
return instr_number

I am coming pretty close to what I want with variations on theis but I
cant seem to
get 3 lines with the split and instr_number[array] = s[1] seems to give
me an error.
the data from the line I am trying to split in three would look like
this

instr 83 ;comment would be here

I want comment returned in an array and instr_number returned in an
array.

解决方案

p.s. this is the one I need to finish to release the csoundroutines
library

www.dexrow.com
Er*********@msn.com wrote:

apologies if I annoy and for spacing (google)

def csdInstrumentList(from_file):
"Returns a list of .csd instruments and any comment lines after the
instrument"
infile = open(from_file, ''r'')
temp_number = 0
for line in infile:
if ''instr'' in line:
s = re.split(r'' +'',line,3)
instr_number = s[1]
return instr_number

I am coming pretty close to what I want with variations on theis but I
cant seem to
get 3 lines with the split and instr_number[array] = s[1] seems to give
me an error.
the data from the line I am trying to split in three would look like
this

instr 83 ;comment would be here

I want comment returned in an array and instr_number returned in an
array.


On 6 Oct 2006 21:07:43 -0700, Er*********@msn.com <Er*********@msn.comwrote:

I want comment returned in an array and instr_number returned in an
array.

Let me see if I understand what you want: if there is a line that
starts with instr (best tested with line.startswith(''instr'') :)), you
want the number and the commen afterwards. I used regexes for this
purpose. In your case:

import re

<snip>

if line.startswith(''instr''):
p = re.compile(r''(\d+)\s+;(.*)


'')
m = p.search(line)

return (m.group(1), m.group(2))

I returned a tuple of course; you may wish to change that.

BTW, thank you -- I just learned how to use re''s in Python.


这篇关于拆分问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆