Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When printing, use name.title() instead of name.capitalize() #77

Closed
cclauss opened this issue Jul 1, 2017 · 2 comments
Closed

When printing, use name.title() instead of name.capitalize() #77

cclauss opened this issue Jul 1, 2017 · 2 comments

Comments

@cclauss
Copy link
Contributor

cclauss commented Jul 1, 2017

#!/usr/bin/env python3

"""
 id  name        .title()    .capitalize()
 29  nidoran-f   Nidoran-F   Nidoran-f
 32  nidoran-m   Nidoran-M   Nidoran-m
 83  farfetch'd  Farfetch'D  Farfetch'd
122  mr.mime     Mr.Mime     Mr.mime
250  ho-oh       Ho-Oh       Ho-oh
474  porygon-z   Porygon-Z   Porygon-z
"""

import os

f'F-strings requires Python 3.6 of better'
DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Data')


def print_a_pokemon(i, line):
    line = line.strip().split()
    name = line[0]
    if name.title() != name.capitalize():
        print(f'{i + 1:>3}  {name:<11} {name.title():<11} {name.capitalize()}')


print(' id  name        .title()    .capitalize()')
with open(os.path.join(DATA_DIR, 'pokemon.txt')) as in_file:
    for i, line in enumerate(in_file):
        print_a_pokemon(i, line)
@samuelhnrq
Copy link
Collaborator

I think title() is better IMO.

@cclauss
Copy link
Contributor Author

cclauss commented Jul 1, 2017

name.title() it is.

@cclauss cclauss changed the title When printing, should it be name.title() or name.capitalize()? When printing, use name.title() instead of name.capitalize() Jul 1, 2017
cclauss pushed a commit to cclauss/Pokemon-Terminal that referenced this issue Jul 3, 2017
cclauss pushed a commit to cclauss/Pokemon-Terminal that referenced this issue Jul 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants