Giter VIP home page Giter VIP logo

Comments (5)

vberlier avatar vberlier commented on August 22, 2024

Unicode escaping works as intended. In this case the extra backslashes are there because the python repl outputs a representation of the string to your terminal rather than the string itself:

>>>  = String('我')
>>> str()
'"\\\\u6211"'
>>> print(repr(str()))  # This is the code that the repl executes
'"\\\\u6211"'

If you want to display the actual nbt literal you just need to print the string directly:

>>> print(str())
"\\u6211"
>>> print()  # The `print` function internally calls `str`
"\\u6211"

from nbtlib.

ch-yx avatar ch-yx commented on August 22, 2024

but,command do not support escapes like \uxxxx.

2019-01-28_13 49 51
🤔

from nbtlib.

vberlier avatar vberlier commented on August 22, 2024

Oh right my mistake I tested it with json text objects so I didn't realize that the reason why the escape sequence worked was because it was interpreted afterwards by the json parsing:

>>> print(Compound({'display': Compound({'Name': String('{"text":"我"}')})}))
{display:{Name:"{\"text\":\"\\u6211\"}"}}

So yeah I tried it out in a command and it worked:

/give @p minecraft:apple{display:{Name:"{\"text\":\"\\u6211\"}"}}

Anyway since bare strings seem to support unicode characters directly I think I'll just get rid of the escaping.

from nbtlib.

vberlier avatar vberlier commented on August 22, 2024

Alright escaping problems should be fixed in 97efa25.

from nbtlib.

vberlier avatar vberlier commented on August 22, 2024

Closing the issue as the fix is now in release 1.3.1.

from nbtlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.