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

if bytes != str:


I read and learn the the following code now:

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?

.: Hongyi Zhao [ hongyi.zhao AT ] Free as in Freedom :.