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

printing f-string returns nothing in terminal (win10) #529

Open
7 tasks done
Krogsager opened this issue Jan 9, 2023 · 1 comment
Open
7 tasks done

printing f-string returns nothing in terminal (win10) #529

Krogsager opened this issue Jan 9, 2023 · 1 comment
Labels
question Question or problem

Comments

@Krogsager
Copy link

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.

@Krogsager Krogsager added the question Question or problem label Jan 9, 2023
@heiskane
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
Projects
None yet
Development

No branches or pull requests

2 participants