loremipsum
loremipsum copied to clipboard
Byte literals in front of words with python 3
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'."
This is not the expected output, anyway. Something is messed up. Can't fix at the moment because I'm quite busy relocating.
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'."
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'."
Any chance we can get 1.0.6
pushed to PyPI, @monkeython?
+1 @monkeython
+1 @monkeython
+1 @monkeython
+1 @monkeython
Does this library work with Python 3?
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.
PyPi version still broken...
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