本文整理汇总了Python中string.splitlines函数的典型用法代码示例。如果您正苦于以下问题:Python splitlines函数的具体用法?Python splitlines怎么用?Python splitlines使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了splitlines函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: strip_string
def strip_string(string):
if len(string.splitlines()) > 1:
new_string = '\n'.join([i.strip() for i in string.splitlines()])
new_string = new_string[1:] # remove \n at the beginning of the string
if string[len(string) - 1] != '\n':
new_string = new_string[:len(new_string) - 1]
#remove \n at the end of the string if wasn't present before
return new_string
else:
return string.strip()
开发者ID:ltsavar,项目名称:prittag,代码行数:11,代码来源:prittag.py
示例2: readClustal
def readClustal(string, alphabet):
""" Read a ClustalW2 alignment in the given string and return as an
Alignment object. """
seqs = {} # sequence data
for line in string.splitlines():
if line.startswith('CLUSTAL') or line.startswith('STOCKHOLM') \
or line.startswith('#'):
continue
if len(line.strip()) == 0:
continue
if line[0] == ' ' or '*' in line or ':' in line:
continue
sections = line.split()
name, seqstr = sections[0:2]
index = name.find('/')
if index >= 0:
name = name[0:index]
if seqs.has_key(name):
seqs[name] += seqstr
else:
seqs[name] = seqstr
sequences = []
for name, seqstr in seqs.items():
sequences.append(Sequence(seqstr, alphabet, name, gappy = True))
return Alignment(sequences)
开发者ID:jacekrad,项目名称:biol3014,代码行数:25,代码来源:sequence.py
示例3: parse_symbols_string
def parse_symbols_string(string):
# Remove all comments from the source.
string = ' '.join(line.split('//')[0] for line in string.splitlines())
string = ' '.join(re.split(r'\/\*.*\*\/', string))
# Extract all enumeration declarations from the source.
enumerations = [
text.split('{')[1].split('}')[0]
for text in re.split(r'\benum\b', string)[1:]
]
# Load the symbols.
symbols = {}
masked_symbols = []
for enum in enumerations:
last_value = -1
for name in enum.split(','):
if '=' in name:
name, value = name.split('=')
value = int(value)
else:
value = last_value + 1
name = name.strip()
if name:
if name in symbols and symbols[name] != value:
masked_symbols.append((name, symbols[name]))
last_value = value
if not name.startswith('_'):
symbols[name] = value
return (symbols, masked_symbols)
开发者ID:nr-plugins,项目名称:c4ddev,代码行数:32,代码来源:resource.py
示例4: create_request
def create_request(cls, string, endpoint, meta_vars=None):
"""Parse the HTTP request template into its components
:param str string: HTTP request template
:param str endpoint: URL of the target to be tested
:param dict meta_vars: Default None, dict parsed from meta.json
:rtype: :class:`syntribos.clients.http.parser.RequestObject`
:returns: RequestObject with method, url, params, etc. for use by
runner
"""
if meta_vars:
cls.meta_vars = meta_vars
string = cls.call_external_functions(string)
action_field = str(uuid.uuid4()).replace("-", "")
string = string.replace(cls.ACTION_FIELD, action_field)
lines = string.splitlines()
for index, line in enumerate(lines):
if line == "":
break
if lines[index] != "":
index = index + 1
method, url, params, version = cls._parse_url_line(lines[0], endpoint)
headers = cls._parse_headers(lines[1:index])
data = cls._parse_data(lines[index + 1:])
return RequestObject(
method=method, url=url, headers=headers, params=params, data=data,
action_field=action_field)
开发者ID:knangia,项目名称:syntribos,代码行数:27,代码来源:parser.py
示例5: innerTrim
def innerTrim(string):
if isinstance(string, (unicode, str)):
# remove tab and white space
string = re.sub(TABSSPACE, ' ',string)
string = ''.join(string.splitlines())
return string.strip()
return ''
开发者ID:SalesLoft,项目名称:python-goose,代码行数:7,代码来源:text.py
示例6: dickfilm
def dickfilm():
if random.randint(1000,2000) == 1337:
return "The twilight saga"
f = open('film.txt', 'r+')
string = ''
string2 = ''
for linje in f:
if (' ' in linje):
string+=linje
filmer = string.splitlines()
string = filmer[random.randint(0, len(filmer)-1)]
words = string.split(' ')
tall = random.randint(0, len(words)-1)
if (words[tall] == 'The' or words[tall] == 'the'):
tall=tall+1
if (tall == 0 or words[tall][0] in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
if (words[tall][-1]=='s'):
words[tall] = 'Dicks'
else:
words[tall] = 'Dick'
else:
if (words[tall][-1]=='s'):
words[tall] = 'dicks'
else:
words[tall] = 'dick'
for i in range(0, len(words)):
string2+= words[i]
if (i < len(words)-1):
string2 += ' '
return "\""+string2+"\""
开发者ID:sigvef,项目名称:fyllebot,代码行数:31,代码来源:bot.py
示例7: get_grammar
def get_grammar(string):
grammar = set()
for line in string.splitlines():
head, symbols_str = line.split(' -> ')
for symbols_str in symbols_str.split(' | '):
symbols = tuple(symbols_str.split())
grammar.add(Rule(head, symbols))
return grammar
开发者ID:astrokatherine,项目名称:CKY_parser,代码行数:8,代码来源:example_cky.py
示例8: __init__
def __init__(self, scenario, filename, string, language):
self.file = fs.relpath(filename)
self.line = None
for pline, part in enumerate(string.splitlines()):
part = part.strip()
if re.match(u"%s: " % language.scenario_separator + re.escape(scenario.name), part):
self.line = pline + 1
break
开发者ID:iserko,项目名称:lettuce,代码行数:9,代码来源:core.py
示例9: youtube
def youtube():
f = open('youtube.txt', 'r+')
string = ''
for linje in f:
string+=linje
reply = string.splitlines()
tall = random.randint(0, len(reply)-1)
string = reply[tall]
return string
开发者ID:sigvef,项目名称:fyllebot,代码行数:9,代码来源:bot.py
示例10: sjekketriks
def sjekketriks():
f = open('sjekketriks.txt', 'r+')
string = ''
for linje in f:
string+=linje
sjekketriks = string.splitlines()
tall = random.randint(0, len(sjekketriks)-1)
string = sjekketriks[tall]
return string
开发者ID:sigvef,项目名称:fyllebot,代码行数:9,代码来源:bot.py
示例11: strip_lines
def strip_lines(string):
'''Strips each individual line in a string.'''
s = []
for line in string.splitlines():
s.append(line.strip())
return '\n'.join(s)
开发者ID:jacobjoaquin,项目名称:csd,代码行数:9,代码来源:pyorc_prototype.py
示例12: rhapsody
def rhapsody():
f = open('lyrics.txt', 'r+')
string=''
for linje in f:
string+=linje
lyrics = string.splitlines()
for i in range(len(lyrics)):
if (lyrics[i].lower() in message):
irc.send ( 'PRIVMSG ' + channel + ' :'+lyrics[i+1]+'\r\n' )
开发者ID:sigvef,项目名称:fyllebot,代码行数:9,代码来源:bot.py
示例13: film
def film():
f = open('film.txt', 'r+')
string = ''
for linje in f:
string+=linje
filmer = string.splitlines()
nr = random.randint(0, len(filmer)-1)
string = filmer[nr]
return "\""+string+"\""
开发者ID:sigvef,项目名称:fyllebot,代码行数:9,代码来源:bot.py
示例14: rune
def rune():
f = open('rune.txt', 'r+')
string = ''
for linje in f:
string+=linje
filmer = string.splitlines()
nr = random.randint(0, len(filmer)-1)
string = filmer[nr]
return string
开发者ID:sigvef,项目名称:fyllebot,代码行数:9,代码来源:bot.py
示例15: greet
def greet():
f = open('greetings.txt', 'r+')
string = ''
for linje in f:
string+=linje
greetings = string.splitlines()
for i in range(0, len(greetings)):
if (greetings[i] in message):
return True
return False
开发者ID:sigvef,项目名称:fyllebot,代码行数:10,代码来源:bot.py
示例16: admins
def admins():
f = open('adminz.txt', 'r+')
string = ''
for linje in f:
string+= linje
admin = string.splitlines()
for i in range(0, len(admin)):
if (admin[i].lower() == user.lower()):
return True
return False
开发者ID:sigvef,项目名称:fyllebot,代码行数:10,代码来源:bot.py
示例17: filmz
def filmz():
f = open('film.txt', 'r+')
string = ''
for linje in f:
string+=linje
filmerz = string.splitlines()
for i in range(0, len(filmerz)):
if (filmerz[i].lower() in message):
return True
return False
开发者ID:sigvef,项目名称:fyllebot,代码行数:10,代码来源:bot.py
示例18: clean_newlines
def clean_newlines(string):
"""Strip newlines and any trailing/following whitespace; rejoin
with a single space where the newlines were.
Bug: This routine will completely butcher any whitespace-formatted
text."""
if not string: return ''
lines = string.splitlines()
return ' '.join( [line.strip() for line in lines] )
开发者ID:funature,项目名称:EnergyParser,代码行数:10,代码来源:utilities_base.py
示例19: no
def no():
f = open('no.txt', 'r+')
string = ''
for linje in f:
string+=linje
nei = string.splitlines()
for i in range(0, len(nei)):
if (nei[i] in message):
return True
return False
开发者ID:sigvef,项目名称:fyllebot,代码行数:10,代码来源:bot.py
示例20: yes
def yes():
f = open('yes.txt', 'r+')
string = ''
for linje in f:
string+=linje
ja = string.splitlines()
for i in range(0, len(ja)):
if (ja[i] in message):
return True
return False
开发者ID:sigvef,项目名称:fyllebot,代码行数:10,代码来源:bot.py
注:本文中的string.splitlines函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论