loremipsum icon indicating copy to clipboard operation
loremipsum copied to clipboard

Byte literals in front of words with python 3

Open rogg opened this issue 9 years ago • 12 comments

resource_string() from pkg_resources opens dictionary.txt as 'rb', which puts byte literals in front of all the words when using python 3.

>>> get_sentence()
"B'cras' b'mi' b'a' b'vulputate' b'arcu'."

rogg avatar Dec 09 '14 03:12 rogg

This is not the expected output, anyway. Something is messed up. Can't fix at the moment because I'm quite busy relocating.

monkeython avatar Dec 15 '14 22:12 monkeython

This is still happening:

"B'pede' b'mi' b'a' b'lorem' b'a' b'cum'.", "B'amet' b'et' b'a' b'a'.", "B'enim' b'in' b'a' b'a' b'a'.", "B'nunc' b'in'.", "B'nunc' b'ut' b'id' b'nam' b'porta' b'lacinia' b'platea' b'a' b'consectetuer' b'dis' b'hac' b'a' b'a' b'a' b'quis' b'a' b'a'."

Bartvds avatar Jun 18 '15 08:06 Bartvds

I think this is fixed in 1.0.6, but PyPi only has the 1.0.5 version...

https://pypi.python.org/pypi/loremipsum

For convenience, could a new version be pushed?

from loremipsum import generate_paragraph, get_sentences
sentences_list = get_sentences(5)
for s in sentences_list:
    print(type(s), repr(s))

output:

<class 'str'> "B'nibh' b'eu' b'a' b'dui' b'fringilla'."
<class 'str'> "B'eget' b'ac'."
<class 'str'> "B'pede' b'ad' b'a' b'justo' b'odio' b'porttitor' b'vel'."
<class 'str'> "B'eget' b'ad'."
<class 'str'> "B'urna' b'ac'."

protoforge avatar Feb 28 '16 18:02 protoforge

Any chance we can get 1.0.6 pushed to PyPI, @monkeython?

craiglabenz avatar Jul 26 '16 18:07 craiglabenz

+1 @monkeython

axsaucedo avatar Aug 13 '16 14:08 axsaucedo

+1 @monkeython

proinsias avatar Feb 24 '17 03:02 proinsias

+1 @monkeython

DanielSaunders avatar Feb 28 '17 19:02 DanielSaunders

+1 @monkeython

simonatdrg avatar May 22 '17 16:05 simonatdrg

Does this library work with Python 3?

testlabauto avatar Jun 29 '17 23:06 testlabauto

This will fix it:

_DICTIONARY = [bytes.decode(word) for word in _DICTIONARY] (at the same place as the code monkeython mentioned in his code snippet.)

This fork has the change in it: https://github.com/testlabauto/loremipsum I would create a PR but I had to go back to 1.0.5 because the HEAD doesn't seem to work for me.

testlabauto avatar Jun 30 '17 15:06 testlabauto

PyPi version still broken...

toyg avatar May 15 '18 10:05 toyg

If you want to patch the version on pip by hand, these two lines in generator.py do it:

_SAMPLE = resource_string(__name__, 'default/sample.txt').decode('utf-8')
_DICTIONARY = resource_string(__name__, 'default/dictionary.txt').decode('utf-8').split()

If you'd like to install a patched version:

pip install -e git+https://github.com/testlabauto/loremipsum.git@b7bd71a6651207ef88993045cd755f20747f2a1e#egg=loremipsmum

If you'd like the patched version in requirements.txt, add the line:

-e git+https://github.com/testlabauto/loremipsum.git@b7bd71a6651207ef88993045cd755f20747f2a1e#egg=loremipsmum

pmitros avatar May 20 '20 17:05 pmitros