[Tutor] Question Regarding startswith()

Alan Gauld alan.gauld at yahoo.co.uk
Mon Jun 4 13:46:54 EDT 2018


On 04/06/18 16:57, Jeremy Ogorzalek wrote:
> Not sure this is how this is done, but here goes.
> 
> When I try to run the code in the SGP4 module, I get the following error,
> and it originates in the io.py script:

I have no idea what you are talking about and do not know what the SGP4
or io.py files are.
However...

>   File "C:\ProgramData\Anaconda3\lib\site-packages\sgp4\io.py", line 131,
> in twoline2rv
>     assert line.startswith('1 ')
> 
> TypeError: startswith first arg must be bytes or a tuple of bytes, not str
> 
> But as far as I can tell in the documentation online (multiple sources) the
> first argument of startswith() is indeed supposed to be a string! 

It depends on which startswith() method you are looking at.

If line is a string you are correct but... if line is a bytes
object then its startwith() method expects a bytes argument.

So I suspect that line is of type bytes(*) and you must convert
it to a string or use a bytes first argument.

(*)You can check by adding a

print("type of line: ", type(line))

in your code.


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list