Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2298501
  • 博文数量: 321
  • 博客积分: 3440
  • 博客等级: 中校
  • 技术积分: 2992
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-24 09:08
个人简介

我就在这里

文章分类

全部博文(321)

文章存档

2015年(9)

2014年(84)

2013年(101)

2012年(25)

2011年(29)

2010年(21)

2009年(6)

2008年(23)

2007年(23)

分类: Python/Ruby

2013-01-27 21:05:10

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'."]


阅读(1429) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~