Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2293382
  • 博文数量: 276
  • 博客积分: 5998
  • 博客等级: 大校
  • 技术积分: 5175
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 14:43
文章分类

全部博文(276)

文章存档

2014年(25)

2013年(11)

2012年(69)

2011年(167)

2010年(4)

分类: Python/Ruby

2013-01-24 17:10:36

python 以逗号分割,忽略引号内的逗号

加posix=True 和不加posix=True 有区别

前两个是加和不加posix=True的对比,最后一个例子是以空格分割语句的例子lex.quotes = '"' 去掉效果一样



import shlex
str=shlex.shlex("ab,'cdsfd,sfsd',ewewq,5654",posix=True)
str.whitespace=','
str.whitesapce_split=True
b=list(str)
print  b


['ab', 'cdsfd,sfsd', 'ewewq', '5654']


import shlex
str=shlex.shlex("ab,'cdsfd,sfsd',ewewq,5654")
str.whitespace=','
str.whitesapce_split=True
b=list(str)
print b

['ab', "'cdsfd,sfsd'", 'ewewq', '5654']


import shlex
lex = shlex.shlex('''This string has "some double quotes" and 'some single quotes'.''')
lex.quotes = '"'
lex.whitespace_split = True
b=list(lex)

['This', 'string', 'has', '"some double quotes"', 'and', "'some", 'single', "quotes'."]


阅读(6253) | 评论(0) | 转发(2) |
0

上一篇:磁盘报警信息

下一篇:修改mysql时区

给主人留下些什么吧!~~