本文整理汇总了Python中string.capwords方法的典型用法代码示例。如果您正苦于以下问题:Python string.capwords方法的具体用法?Python string.capwords怎么用?Python string.capwords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string
的用法示例。
在下文中一共展示了string.capwords方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _remove_heist
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def _remove_heist(self, ctx, *, target: str):
"""Remove a target from the heist list"""
author = ctx.message.author
guild = ctx.guild
targets = await self.thief.get_guild_targets(guild)
if string.capwords(target) in targets:
await ctx.send("Are you sure you want to remove {} from the list of "
"targets?".format(string.capwords(target)))
response = await self.bot.wait_for('MESSAGE', timeout=15, check=lambda x: x.author == author)
if response is None:
msg = "Canceling removal. You took too long."
elif response.content.title() == "Yes":
targets.pop(string.capwords(target))
await self.thief.save_targets(guild, targets)
msg = "{} was removed from the list of targets.".format(string.capwords(target))
else:
msg = "Canceling target removal."
else:
msg = "That target does not exist."
await ctx.send(msg)
示例2: _extractNVMLErrorsAsClasses
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def _extractNVMLErrorsAsClasses():
'''
Generates a hierarchy of classes on top of NVMLError class.
Each NVML Error gets a new NVMLError subclass. This way try,except blocks can filter appropriate
exceptions more easily.
NVMLError is a parent class. Each NVML_ERROR_* gets it's own subclass.
e.g. NVML_ERROR_ALREADY_INITIALIZED will be turned into NVMLError_AlreadyInitialized
'''
this_module = sys.modules[__name__]
nvmlErrorsNames = filter(lambda x: x.startswith("NVML_ERROR_"), dir(this_module))
for err_name in nvmlErrorsNames:
# e.g. Turn NVML_ERROR_ALREADY_INITIALIZED into NVMLError_AlreadyInitialized
class_name = "NVMLError_" + string.capwords(err_name.replace("NVML_ERROR_", ""), "_").replace("_", "")
err_val = getattr(this_module, err_name)
def gen_new(val):
def new(typ):
obj = NVMLError.__new__(typ, val)
return obj
return new
new_error_class = type(class_name, (NVMLError,), {'__new__': gen_new(err_val)})
new_error_class.__module__ = __name__
setattr(this_module, class_name, new_error_class)
NVMLError._valClassMapping[err_val] = new_error_class
示例3: _get_es_results
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def _get_es_results(query: str, category: str, keyphrase: str, strict: bool) -> Response:
skill_search = es_search
if category:
skill_search = skill_search.query('match',
category=string.capwords(category)
.replace(' And ', ' & ')
.replace('Movies & Tv', 'Movies & TV'))
if keyphrase:
skill_search = skill_search.query('match', keyphrases=keyphrase)
if query:
operator = 'and' if strict else 'or'
skill_search = skill_search.query('multi_match',
query=query,
fields=['name', 'description', 'usages', 'keyphrases'],
minimum_should_match='50%',
operator=operator) \
.highlight('description', order='score', pre_tags=['*'], post_tags=['*']) \
.highlight('title', order='score', pre_tags=['*'], post_tags=['*']) \
.highlight('usages', order='score', pre_tags=['*'], post_tags=['*'])
return skill_search.execute()
示例4: test_names
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def test_names(self):
"""Ensure extractor classes are named CategorySubcategoryExtractor"""
def capitalize(c):
if "-" in c:
return string.capwords(c.replace("-", " ")).replace(" ", "")
return c.capitalize()
for extr in extractor.extractors():
if extr.category not in ("", "oauth"):
expected = "{}{}Extractor".format(
capitalize(extr.category),
capitalize(extr.subcategory),
)
if expected[0].isdigit():
expected = "_" + expected
self.assertEqual(expected, extr.__name__)
示例5: get_embeddings
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def get_embeddings(self, word):
word_list = [word, word.upper(), word.lower(), word.title(), string.capwords(word, '_')]
for w in word_list:
try:
return self.model[w]
except KeyError:
# print('Can not get embedding for ', w)
continue
return None
示例6: name2class
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def name2class(self, name):
return getattr(text_classification, string.capwords(name, '_').replace('_', ''))
示例7: shortf
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def shortf(acronym):
n = int(raw_input("Enter the number of inputs"))
for acronym in range(n):
acronym1 = string.capwords(acronym)
list(acronym1)
print output
示例8: main
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def main():
n = int(raw_input("Enter the number of inputs"))
output = ""
for acronym in range(n):
acronym = raw_input("Enter the input: ")
acronym1 = string.capwords(acronym)
list(acronym1)
print output
示例9: convert_to_cpp_identifier
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def convert_to_cpp_identifier(s, sep):
return string.capwords(s, sep).replace(sep, "")
示例10: format_command_part
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def format_command_part(name):
name = re.sub("[^a-zA-Z]", "-", name)
name = string.capwords(name, "-")
name = name.replace("-", "")
return name
示例11: test_capwords
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def test_capwords(self):
self.assertEqual(string.capwords('abc def ghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('abc\tdef\nghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('abc\t def \nghi'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC DEF GHI'), 'Abc Def Ghi')
self.assertEqual(string.capwords('ABC-DEF-GHI', '-'), 'Abc-Def-Ghi')
self.assertEqual(string.capwords('ABC-def DEF-ghi GHI'), 'Abc-def Def-ghi Ghi')
self.assertEqual(string.capwords(' aBc DeF '), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t'), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t', '\t'), '\tAbc\tDef\t')
示例12: title_filter
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def title_filter(self, result):
title = source_utils.clean_tags(result.title.strip())
title = source_utils.remove_sep(title, self._title)
title = normalize(title).replace('+', ' ')
return capwords(title)
示例13: to_capital_camel_case
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def to_capital_camel_case(s):
"""Converts a string to camel case.
Parameters
----------
s : str
Input string.
Returns
-------
str
Input string `s` converted to camel case.
"""
return s[0].capitalize() + string.capwords(s, sep='_').replace('_', '')[1:] if s else s
示例14: __name__
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def __name__(self):
feat_name = []
for m1 in self.aggregation_mode_prev:
for m in self.aggregation_mode:
n = "WordNet_%s_Similarity_%s_%s"%(
string.capwords(self.metric), string.capwords(m1), string.capwords(m))
feat_name.append(n)
return feat_name
示例15: __name__
# 需要导入模块: import string [as 别名]
# 或者: from string import capwords [as 别名]
def __name__(self):
if isinstance(self.aggregation_mode, str):
feat_name = "FirstIntersectPosition_%s_%s"%(
self.ngram_str, string.capwords(self.aggregation_mode))
elif isinstance(self.aggregation_mode, list):
feat_name = ["FirstIntersectPosition_%s_%s"%(
self.ngram_str, string.capwords(m)) for m in self.aggregation_mode]
return feat_name