Skip to content

Commit

Permalink
Update types.nim
Browse files Browse the repository at this point in the history
I'd made a comment in Yardanico/nimpylib#11
But then I found that this types.nim exports a `ascii`
However in Python ascii function doesn't the same as str, see https://docs.python.org/3/library/functions.html#ascii
  • Loading branch information
litlighilit committed Dec 11, 2022
1 parent 9e75198 commit f409f6d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/pylib/types.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import std/strutils
import std/unicode

template str*(a: untyped): string = $a
template unicode*(a: untyped): string = $a
template ascii*(a: untyped): string = $a

from pylib import ord
proc ascii*(us:string):string=
for s in us.utf8:
if s.len == 1: # is ascii char
result.add s.escape(prefix = "",suffix = "")
else:
result.add r"\u" & $ord(s)


template u*(a: string): string = a
template u*(a: char): string = $a
template b*(a: string): string = a
Expand Down

0 comments on commit f409f6d

Please sign in to comment.