FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codemode_python_benchmark/debug/debug_fstring.py at main · imran31415/codemode_python_benchmark · GitHub
imran31415
/
codemode_python_benchmark
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
38
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codemode_python_benchmark
/
debug
/
debug_fstring.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (42 loc) · 992 Bytes
Breadcrumbs
codemode_python_benchmark
/
debug
/
debug_fstring.py
Copy path
File metadata and controls
47 lines (42 loc) · 992 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Debug script to isolate the f-string formatting issue in RestrictedPython.
"""
from
sandbox
.
executor
import
CodeExecutor
from
tools
.
business_tools
import
get_tools
executor
=
CodeExecutor
(
get_tools
())
# Test 1: Simple f-string without format specifier
code1
=
'''
import json
total = 100
result = f"Total: ${total}"
'''
print
(
"Test 1 - Simple f-string:"
)
print
(
executor
.
execute
(
code1
))
print
()
# Test 2: F-string with .2f format specifier
code2
=
'''
import json
total = 100.5
result = f"Total: ${total:.2f}"
'''
print
(
"Test 2 - F-string with .2f:"
)
print
(
executor
.
execute
(
code2
))
print
()
# Test 3: Using string format method instead
code3
=
'''
import json
total = 100.5
result = "Total: ${:.2f}".format(total)
'''
print
(
"Test 3 - String format method:"
)
print
(
executor
.
execute
(
code3
))
print
()
# Test 4: Using round()
code4
=
'''
import json
total = 100.567
rounded = round(total, 2)
result = f"Total: ${rounded}"
'''
print
(
"Test 4 - Using round():"
)
print
(
executor
.
execute
(
code4
))
Back
|
FazBrowse Home
|
New Git URL