Python string.capwords() Examples

The following are 30 code examples for showing how to use string.capwords(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module string , or try the search function .

Example 1
Project: discord_cogs   Author: Malarne   File: heist.py    License: GNU General Public License v3.0 6 votes vote down vote up
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) 
Example 2
Project: MoePhoto   Author: opteroncx   File: pynvml.py    License: Apache License 2.0 6 votes vote down vote up
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 
Example 3
Project: satori   Author: leancloud   File: pynvml.py    License: Apache License 2.0 6 votes vote down vote up
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 
Example 4
Project: alexafsm   Author: allenai   File: clients.py    License: Apache License 2.0 6 votes vote down vote up
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() 
Example 5
Project: gallery-dl   Author: mikf   File: test_extractor.py    License: GNU General Public License v2.0 6 votes vote down vote up
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__) 
Example 6
Project: nvidia-ml-py   Author: jonsafari   File: pynvml.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example 7
Project: BAMnet   Author: hugochan   File: generic_utils.py    License: Apache License 2.0 5 votes vote down vote up
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 
Example 8
Project: lineflow   Author: tofunlp   File: test_text_classification.py    License: MIT License 5 votes vote down vote up
def name2class(self, name):
        return getattr(text_classification, string.capwords(name, '_').replace('_', '')) 
Example 9
Project: Python-John-Zelle-book   Author: sai29   File: 10.py    License: MIT License 5 votes vote down vote up
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 
Example 10
Project: Python-John-Zelle-book   Author: sai29   File: 5.py    License: MIT License 5 votes vote down vote up
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 
Example 11
Project: probe-scraper   Author: mozilla   File: parse_events.py    License: Mozilla Public License 2.0 5 votes vote down vote up
def convert_to_cpp_identifier(s, sep):
    return string.capwords(s, sep).replace(sep, "") 
Example 12
Project: benchexec   Author: sosy-lab   File: statistics-tex.py    License: Apache License 2.0 5 votes vote down vote up
def format_command_part(name):
    name = re.sub("[^a-zA-Z]", "-", name)
    name = string.capwords(name, "-")
    name = name.replace("-", "")
    return name 
Example 13
Project: ironpython2   Author: IronLanguages   File: test_string.py    License: Apache License 2.0 5 votes vote down vote up
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') 
Example 14
Project: a4kScrapers   Author: a4k-openproject   File: scrapers.py    License: MIT License 5 votes vote down vote up
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) 
Example 15
Project: DeepDIVA   Author: DIVA-DIA   File: misc.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
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 
Example 16
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_wordnet_similarity.py    License: MIT License 5 votes vote down vote up
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 
Example 17
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_first_last_ngram.py    License: MIT License 5 votes vote down vote up
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 
Example 18
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_first_last_ngram.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "LastIntersectPosition_%s_%s"%(
                self.ngram_str, string.capwords(self.aggregation_mode))
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["LastIntersectPosition_%s_%s"%(
                self.ngram_str, string.capwords(m)) for m in self.aggregation_mode]
        return feat_name


# -------------------------- Norm Position ---------------------------------- 
Example 19
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_first_last_ngram.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "FirstIntersectNormPosition_%s_%s"%(
                self.ngram_str, string.capwords(self.aggregation_mode))
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["FirstIntersectNormPosition_%s_%s"%(
                self.ngram_str, string.capwords(m)) for m in self.aggregation_mode]
        return feat_name 
Example 20
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_first_last_ngram.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "LastIntersectNormPosition_%s_%s"%(
                self.ngram_str, string.capwords(self.aggregation_mode))
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["LastIntersectNormPosition_%s_%s"%(
                self.ngram_str, string.capwords(m)) for m in self.aggregation_mode]
        return feat_name


# ---------------------------- Main -------------------------------------- 
Example 21
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_group_relevance.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "GroupRelevance_%s"%string.capwords(self.aggregation_mode)
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["GroupRelevance_%s"%string.capwords(m) for m in self.aggregation_mode]
        return feat_name 
Example 22
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_word2vec.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        feat_name = []
        for m1 in self.aggregation_mode_prev:
            for m in self.aggregation_mode:
                n = "Word2Vec_%s_D%d_CosineSim_%s_%s"%(
                    self.model_prefix, self.vector_size, string.capwords(m1), string.capwords(m))
                feat_name.append(n)
        return feat_name 
Example 23
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_intersect_position.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "IntersectPosition_%s_%s"%(
                self.ngram_str, string.capwords(self.aggregation_mode))
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["IntersectPosition_%s_%s"%(
                self.ngram_str, string.capwords(m)) for m in self.aggregation_mode]
        return feat_name 
Example 24
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_intersect_position.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "IntersectNormPosition_%s_%s"%(
                self.ngram_str, string.capwords(self.aggregation_mode))
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["IntersectNormPosition_%s_%s"%(
                self.ngram_str, string.capwords(m)) for m in self.aggregation_mode]
        return feat_name 
Example 25
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_group_distance_stat.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "GroupDistanceStat_%s_%s_%s"%(
                self.dist_name, self.group_id_name, string.capwords(self.aggregation_mode))
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["GroupDistanceStat_%s_%s_%s"%(
                self.dist_name, self.group_id_name, string.capwords(m)) for m in self.aggregation_mode]
        return feat_name 
Example 26
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_distance.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        feat_name = []
        for m1 in self.aggregation_mode_prev:
            for m in self.aggregation_mode:
                n = "CompressionDistance_%s_%s_%s"%(self.ngram_str, string.capwords(m1), string.capwords(m))
                feat_name.append(n)
        return feat_name 
Example 27
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_stat_cooc_tfidf.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "StatCoocTF_%s_%s"%(
                self.ngram_str, string.capwords(self.aggregation_mode))
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["StatCoocTF_%s_%s"%(
                self.ngram_str, string.capwords(m)) for m in self.aggregation_mode]
        return feat_name 
Example 28
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_stat_cooc_tfidf.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "StatCoocNormTF_%s_%s"%(
                self.ngram_str, string.capwords(self.aggregation_mode))
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["StatCoocNormTF_%s_%s"%(
                self.ngram_str, string.capwords(m)) for m in self.aggregation_mode]
        return feat_name 
Example 29
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_stat_cooc_tfidf.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "StatCoocTFIDF_%s_%s"%(
                self.ngram_str, string.capwords(self.aggregation_mode))
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["StatCoocTFIDF_%s_%s"%(
                self.ngram_str, string.capwords(m)) for m in self.aggregation_mode]
        return feat_name 
Example 30
Project: kaggle-HomeDepot   Author: ChenglongChen   File: feature_stat_cooc_tfidf.py    License: MIT License 5 votes vote down vote up
def __name__(self):
        if isinstance(self.aggregation_mode, str):
            feat_name = "StatCoocNormTFIDF_%s_%s"%(
                self.ngram_str, string.capwords(self.aggregation_mode))
        elif isinstance(self.aggregation_mode, list):
            feat_name = ["StatCoocNormTFIDF_%s_%s"%(
                self.ngram_str, string.capwords(m)) for m in self.aggregation_mode]
        return feat_name