Using Number.toString() #2218
-
Javascript Number (besides obviously being the Devil's work) has a nifty .toString() method that lets you convert a base-10 integer to any other base. As far as I know, there's nothing like that (build in) in Python, and you have to write something custom that may be slow, recursive and/or import the entire universe. In Brython you can import the javascript Number, but I've no idea how to use it:
Writing a helper function in javascript isn't that hard, but I'd like to avoid the need <script type="text/javascript">
function to_base_n(value, n){
return Number(value).toString(n)
}
</script> Any tips or ideas how this can be achieved using pure Brython? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @shark-in-a-hat , I guess you will have your answer there --> https://python-forum.io/thread-39151-post-166130.html#pid166130 |
Beta Was this translation helpful? Give feedback.
-
Hello @shark-in-a-hat , The error message is misleading so I keep the issue open, but you can use
|
Beta Was this translation helpful? Give feedback.
Hello @shark-in-a-hat ,
The error message is misleading so I keep the issue open, but you can use
.toString()
if you create the number with the Brython equivalent of Javascript'snew Number(128)
: