You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
File "[...]/pylatex/base_classes/latex_object.py", line 168, in generate_tex
with open(filepath + '.tex', 'w', encoding='utf-8') as newf:
~~~~~~~~~^~~~~~~~
TypeError: can't concat str to bytes
This isn't a pylatex issue, you're trying to concatanate filepath, which presumably isn't a string, to '.tex', which is a string. You need to first cast filepath to a str
I disagree. not all bytestrings can be casted to str. some filesystems (ie. xfs, zfs) accept bytes that cannot be encoded in human-readable strings (ie. ascii, utf)
the code should read sth like
try:
with open(filepath + '.tex', 'w', encoding='utf-8') as newf:
...
except TypeError:
with open(filepath + b'.tex', 'w', encoding='utf-8') as newf:
...
Activity
SG420 commentedon Oct 4, 2024
This isn't a pylatex issue, you're trying to concatanate
filepath, which presumably isn't a string, to '.tex', which is a string. You need to first castfilepathto astrpetaflot commentedon Oct 4, 2024
I disagree. not all bytestrings can be casted to str. some filesystems (ie. xfs, zfs) accept bytes that cannot be encoded in human-readable strings (ie. ascii, utf)
the code should read sth like
petaflot commentedon Oct 4, 2024
better still:
you get the point. one can also check on the type of
filepath. however you prefer, there are a number of somewhat equivalent way to do it.