if bytes != str:

Hongyi Zhao hongyi.zhao at gmail.com
Sun Aug 4 10:56:54 EDT 2019


Hi,

I read and learn the the following code now:

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?

Regards
-- 
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.



More information about the Python-list mailing list