tiangolo / typer

Typer, build great CLIs. Easy to code. Based on Python type hints.

Home Page:https://typer.tiangolo.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

printing f-string returns nothing in terminal (win10)

Krogsager opened this issue · comments

commented

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

import typer

txt_paths = ['foo','bar','baz']
[print(f"[{idx}]  {file}") for (idx, file) in enumerate(txt_paths)]
file_selection = typer.prompt(f"Choose which file(s) to extract: 0-{len(txt_paths)-1}, or 'all'")

Description

Problem:

F-strings are not printet, when my script is launched from a terminal.
It does work when running inside a python console.

What happens

When I run the module from cmd like this python -m my.module, the result is

C:\Users\cheese\python -m my.module
Choose which file(s) to extract: 0--1, or 'all':

What I expected

I expect the f-string to be processed and returned according to my code:

[0] foo
[1] bar
[2] baz
Choose which file(s) to extract: 0-2, or 'all':

Operating System

Windows

Operating System Details

Windows 10

Typer Version

0.7.0

Python Version

Python 3.10.4

Additional Context

Running in Anaconda env.

Not sure if it resolves your issue but list comprehension is not the right tool for printing things. Can you try printing in a normal for loop?

import typer

txt_paths = ["foo", "bar", "baz"]

for idx, file in enumerate(txt_paths):
    print(f"[{idx}]  {file}")

file_selection = typer.prompt(
    f"Choose which file(s) to extract: 0-{len(txt_paths)-1}, or 'all'"
)