Chinaunix首页 | 论坛 | 博客
  • 博客访问: 129500
  • 博文数量: 37
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 0
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-02 01:04
个人简介

CU

文章分类

全部博文(37)

文章存档

2016年(33)

2015年(4)

我的朋友

分类: Python/Ruby

2016-09-12 14:45:14

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


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