Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Byte literals in front of words with python 3 #10

Open
rogg opened this issue Dec 9, 2014 · 12 comments
Open

Byte literals in front of words with python 3 #10

rogg opened this issue Dec 9, 2014 · 12 comments

Comments

@rogg
Copy link

rogg commented Dec 9, 2014

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'."
@monkeython
Copy link
Owner

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

@Bartvds
Copy link

Bartvds commented Jun 18, 2015

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'."

@protoforge
Copy link

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'."

@craiglabenz
Copy link

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

@axsaucedo
Copy link

+1 @monkeython

3 similar comments
@proinsias
Copy link

+1 @monkeython

@DanielSaunders
Copy link

+1 @monkeython

@simonatdrg
Copy link

+1 @monkeython

@testlabauto
Copy link

Does this library work with Python 3?

@testlabauto
Copy link

testlabauto commented Jun 30, 2017

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.

@toyg
Copy link

toyg commented May 15, 2018

PyPi version still broken...

@pmitros
Copy link

pmitros commented May 20, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests