git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

if bytes != str:


On Sun, Aug 4, 2019, 9:02 AM Hongyi Zhao <hongyi.zhao at gmail.com> wrote:

> Hi,
>
> I read and learn the the following code now:
>
> https://github.com/shadowsocksr-backup/shadowsocksr-libev/blob/master/src/
> ssrlink.py
> <https://github.com/shadowsocksr-backup/shadowsocksr-libev/blob/master/src/ssrlink.py>
>
> In this script, there are the following two customized functions:
>
>
> ----------
> def to_bytes(s):
>         if bytes != str:
>                 if type(s) == str:
>                         return s.encode('utf-8')
>         return s
>
> def to_str(s):
>         if bytes != str:
>                 if type(s) == bytes:
>                         return s.decode('utf-8')
>         return s
> ----------
>
> I've the following confusion on the above code:
>
> Why should use `if bytes != str:' here?  I mean, this will always return
> True, IMO.
>
> See my following test in ipython:
>
> In[20]: bytes != str
> Out[20]: True
>
>
> Any hints on this?
>

In Python 2.7, bytes and str are the same type.

>