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

Error if %s is not present in prompt string format #442

Open
fcollonval opened this issue Apr 21, 2020 · 4 comments
Open

Error if %s is not present in prompt string format #442

fcollonval opened this issue Apr 21, 2020 · 4 comments

Comments

@fcollonval
Copy link
Contributor

Hey,

I was trying to hide the prompt by setting an empty string to nbsphinx_input_prompt. This results in a TypeError on:

prompt = prompt_template % (execution_count,)

The blame is the % format. Would you consider switching to format asking user to set the string as "In [{}]" rather than "In [%s]". This will be more robust, see:

In [6]: "hello" % "dummy"
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-a2bd27e7e4d9> in <module>
----> 1 "hello" % "dummy"

TypeError: not all arguments converted during string formatting

In [7]: "hello".format("dummy")
Out[7]: 'hello'

In [8]: "hello {}".format(12)
Out[8]: 'hello 12'

Another possibility would be to test for %s.

Note: I use that workaround for my initial purpose.

@mgeier
Copy link
Member

mgeier commented Apr 21, 2020

Thanks for the suggestion!

This would be a breaking change though, and would make many users angry, so I would need a really good reason to do it.

I was trying to hide the prompt by setting an empty string to nbsphinx_input_prompt.

I wouldn't recommend hiding the prompts in the first place, but if you insist, you still shouldn't do it with nbsphinx_input_prompt.

For a more reliable method, see https://nbsphinx.readthedocs.io/en/latest/custom-css.html.

@fcollonval
Copy link
Contributor Author

This would be a breaking change though, and would make many users angry, so I would need a really good reason to do it.

Ya I thought so. This is why I suggested testing for %s in the string to make it more robust without breaking change 😉

Thanks for the additional information. You rock at supporting users 🥇

@mgeier
Copy link
Member

mgeier commented Apr 25, 2020

Thanks!

I don't fully understand your proposal.
Do you mean nbsphinx should check whether nbsphinx_input_prompt contains '%s' and then, depending on that use either % or .format()?

Can you please elaborate?

@mgeier
Copy link
Member

mgeier commented Apr 29, 2020

Thanks, #446 clears up what you mean!

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

Successfully merging a pull request may close this issue.

2 participants