Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

10
  • $\begingroup$ That's pretty amazing! I tried doing it in Python too (print(line.encode("utf-8"))), but it didn't work out. I'm not sure what kind of magic Mathematica used. $\endgroup$ Commented Sep 30, 2023 at 9:06
  • 1
    $\begingroup$ No magic actually. If we consider s being a raw string(backslashes are to be interpreted as a literal), the same is valid in python line = r'ihC..\@..' G = nx.from_graph6_bytes(line.encode("UTF-8")) . Using the UTF8 Encoding is actually intended to simulate the same behaviour in MMA by reading the string one byte at a time (of course there are definitely better ways to do it). Having a closer look at ToString["\@", CharacterEncoding -> #] & /@ {"Unicode", "UTF8"} // {# -> StringLength@#} & /@ # &; (* {{"\@" -> 1}, {"\\@" -> 2}}*) one can see the difference in applying different encodings $\endgroup$ Commented Sep 30, 2023 at 13:59
  • $\begingroup$ This is not correct, and attempting to do this will lead to errors. The issue has to do with escape sequences and not UTF8. $\endgroup$ Commented Sep 30, 2023 at 16:18
  • $\begingroup$ @Szabolcs But in my Mathematica 13.3, it is well. What happened? Is it because of the version? $\endgroup$ Commented Sep 30, 2023 at 16:28
  • $\begingroup$ It is not well. Try GCf\tw. There is not such thing as an "unescaped string" and "escaped string". A string can contain any sequence of characters, but when you write it as Mathematica code, you need to use the correct notation (i.e. escaping). The problem you see if not with the string, but the way you are trying to enter that string. $\endgroup$ Commented Sep 30, 2023 at 16:49