Hey Ben, I did try that as well, but with the same error. It also still 
returns a BytesIO which still doesn't seem to work.

On Thursday, December 21, 2017 at 7:07:35 AM UTC-6, Benjamin Moran wrote:
>
> Hey Charles,
>
> The resource.file method works a lot like "open", except that it defaults 
> to 'rb' instead of 'r'. You can pass it the 'r' to open in text read mode, 
> which sounds like what the configparser is looking for. In Python2 this 
> difference wouldn't have mattered, but of course in Python 3 bytes and 
> strings are different.
>
> -Ben
>
>
>
> On Tuesday, December 19, 2017 at 8:30:00 AM UTC+9, Charles wrote:
>>
>> I am looking to try porting over my application from Python 2.7 to Python 
>> 3.6 and have run into snags.
>>
>> The first being that Pyglet uses BytesIO for version 3 instead of 
>> StringIO. I am using a ZIPLocation.
>>
>> I can no longer seem to use pyglet.resource.file for things that require 
>> a file-like object.
>>
>> Example:
>>
>> ```
>> #!python
>>
>> cfg = configparser.ConfigParser()
>> file_obj = pyglet.resource.file(filename)
>> cfg.read_file(file_obj)
>> ```
>>
>>
>> Will produce an error: 
>>
>> ```
>> #!python
>>
>> File "c:\python36-32\lib\configparser.py", line 1031, in _read
>>     if line.strip().startswith(prefix):
>> builtins.TypeError: startswith first arg must be bytes or a tuple of 
>> bytes, not
>> str
>> ```
>>
>> However BytesIO should be considered bytes? If I try to convert the 
>> BytesIO to pure bytes like it says it wants, using:
>>
>> ```
>> #!python
>>
>> file_obj = pyglet.resource.file(filename).getvalue()
>> ```
>>
>>
>> I then get the error: 
>>
>> ```
>> #!python
>>
>> File "c:\python36-32\lib\configparser.py", line 1031, in _read
>>     if line.strip().startswith(prefix):
>> ```
>>
>> builtins.AttributeError: 'int' object has no attribute 'strip'
>>
>> I can't seem to get this BytesIO to actually work as a file-like object. 
>> What am I missing?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to