Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: PySFML2 Cython Text under Python 3  (Read 6154 times)

0 Members and 1 Guest are viewing this topic.

lattyware

  • Newbie
  • *
  • Posts: 9
    • View Profile
PySFML2 Cython Text under Python 3
« on: July 22, 2011, 11:42:00 pm »
I'm running PySFML2-Cython under Python 3, appears to work alright, I'm poriting across a project that was using the old library, and the Text class that replaces the old String class is causing trouble.

I try and pass it a python3 str (unicode) and I get this error:

self.text = sf.Text(value)

  File "sf.pyx", line 1591, in sf.Text.__cinit__ (sf.cpp:17293)
TypeError: expected bytes, str found

I was under the impression that the Text class should have supported unicode, unlike everything else, but I tried it the other way, encoding it to bytes:

self.text = sf.Text(bytes(value, "UTF-8"))

  File "sf.pyx", line 1614, in sf.Text.__cinit__ (sf.cpp:17503)
TypeError: Expected str or unicode for string, got <class 'bytes'>

Is this something stupid I'm missing, or a problem with the bindings?

bastien

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • http://bastien-leonard.alwaysdata.net
PySFML2 Cython Text under Python 3
« Reply #1 on: July 23, 2011, 11:01:44 am »
Thanks, it should work now.
Check out pysfml-cython, an up to date Python 2/3 binding for SFML 2: https://github.com/bastienleonard/pysfml-cython

lattyware

  • Newbie
  • *
  • Posts: 9
    • View Profile
PySFML2 Cython Text under Python 3
« Reply #2 on: July 23, 2011, 03:59:19 pm »
Quote from: "bastien"
Thanks, it should work now.


Cheers for the quick fix!

The new bindings are a lot better, I can get rid of a lot of old code I had that was simply wrapping the old methods and stuff to make them more pythonic. It looks like it'll make the game a lot easier to work with in the long run.