typer icon indicating copy to clipboard operation
typer copied to clipboard

printing f-string returns nothing in terminal (win10)

Open Krogsager opened this issue 3 years ago • 1 comments

First Check

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

Commit to Help

  • [X] 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.

Krogsager avatar Jan 09 '23 18:01 Krogsager

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'"
)

heiskane avatar Sep 21 '23 16:09 heiskane