[Python] Python: Click Package - Having trouble with non ASCII chars & cmd.exe

Discussão em 'Python' iniciado por Stack, Junho 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am writing a command-line tool using the Click Python Package:

    Which is quite useful, but I can't get one issue fixed with that, which is when I enter non-ASCII chars as a parameter for my Command Line Tool, it will always give me that encoding error:[​IMG]

    And yeah, I know about encode() and decode() in Python, but as you can see in my code, I am not touching this string anywhere.

    Is it the fault of my console? Am I missing any settings here? I am using Windows 7 cmd.exe and know that Windows likes his own encoding for filenames etc. Do I have to use another console? Tried python one with same result.

    The click Documentation states all strings are treated as Unicode...

    I would appreciate your help really much. Installing click is as easy as pip install click

    Kind regards,

    Marcurion

    My Code:

    import click
    from click_shell import shell
    import os



    @shell(prompt='Tool > ', intro='some test...', hist_file=os.path.dirname(os.path.realpath(__file__)))
    def stRec():
    pass



    @stRec.command()
    @click.argument('name', required=True, type=click.STRING)
    def set(name):
    print "nothing"



    if __name__ == '__main__':
    stRec()

    Continue reading...

Compartilhe esta Página