question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

String Formatting

See original GitHub issue

I think string formatting will be a very big issue for pyscript in the next months/years. Maybe a generic solution similar to <pre> </pre> could be possible? I’ve seen a similar solution in a syntax highlighting library some time ago (<code> </code>). For now, the following code returns an error(in both Firefox and Chrome):

for r in range(0xff):
	color="#%02x29%02x" % (r,r)
	printdata = "<font color=\"%s\">sodjf</font>" % color
	print(printdata)

JsException(PythonError: Traceback (most recent call last): File “/lib/python3.10/site-packages/_pyodide/_base.py”, line 429, in eval_code .run(globals, locals) File “/lib/python3.10/site-packages/_pyodide/_base.py”, line 300, in run coroutine = eval(self.code, globals, locals) File “”, line 5, in TypeError: not all arguments converted during string formatting )

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
animaonecommented, May 4, 2022

same

print('<font color="red">should be red</font>')

for r in range(0xff):
	color=f"#{r:02x}29{r:02x}"
	printdata = f"<font color=\"{color}\">should be some color</font>"
	print(printdata) 

0reactions
JeffersGlasscommented, Sep 28, 2022

I believe this is fixed by #684 - at least, the final example posted above does correctly work.

Conversations around escaping HTML-relevant characters in PyScript source are ongoing in #735 - but this specific issue is resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python String Formatting Best Practices
Formatted string literals are a Python parser feature that converts f-strings into a series of string constants and expressions. They then get joined...
Read more >
Python String format() Method - W3Schools
The format() method formats the specified value(s) and insert them inside the string's placeholder. The placeholder is defined using curly brackets: {}.
Read more >
String formatting in Python - GeeksforGeeks
String formatting is the process of infusing things in the string dynamically and presenting the string. There are four different ways to ...
Read more >
7. Input and Output — Python 3.11.1 documentation
Formatted string literals (also called f-strings for short) let you include the value of Python expressions inside a string by prefixing the string...
Read more >
Standard numeric format strings | Microsoft Learn
In this article. Standard format specifiers; Use standard numeric format strings; Currency format specifier (C); Decimal format specifier (D) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found