Can PyDatagram take a string?

Hello, i’m transitioning from Python 2 to Python 3 with the latest development build and was wondering if there was a way for PyDatagram to take a string or to convert the string into a readable format for PyDatagram. If this is in the wrong place sorry, haven’t actually used this site in a bit lol

It’s not clear what you are trying to do. Yes, you can add a string to a datagram in various ways, as described in the documentation:

As you can see, there are various methods to add a string. To add raw bytes, you can also add a bytes object, either by directly appending it to the raw data or as a length-prefixed blob.

To give more specific guidance I’ll need to have more specific information on what you are trying to do.

i’m upgrading a Toontown source, i found a workaround just a bit ago, but i’m sure its not the best…

            _string = bytes(string, 'utf-8')
            dg = PyDatagram(_string)
            dgi = PyDatagramIterator(dg)
            import codecs
            _string = bytes(codecs.decode(string, 'utf-8'), 'utf-8')
            dg = PyDatagram(_string)
            dgi = PyDatagramIterator(dg)

the weird thing is it works initially, then it stops when i hit the playground. probably something to do with Toontown more than Panda at this point tho since it obviously wasn’t meant to run on Python 3.x. Basically what happens in Python 3.x is the above will return


wheras in Python 2.x it returns something like this

Sorry, we can’t help you with that. If you have a question involving source code you own, feel free to open a new topic.