Python returns string is both str and unicode type
<p>We have a .NET app that can be customized by IronPython (version 2.7.5)</p>

<p>Here is the script code:</p>

<pre><code>stringToPlay = # get it from our .NET app interface toward python here. The method returns .NET string

Log.Write("isinstance(stringToPlay, unicode): ", str(isinstance(stringToPlay, unicode)))

Log.Write("isinstance(stringToPlay, str): ", str(isinstance(stringToPlay, str)))
</code></pre>

<p>Both log lines will return True ??</p>

<p>stringToPlay value is "ÐÐ¸ÑÐ¸Ð»Ð¸ÑÐ°" .</p>

<p>How is this possible when str and unicode should be two separate classes both inheriting from basestring?</p>

<p>Thank you</p>

<p>IronPython makes no difference between <code>str</code> and <code>unicode</code>, which can be very confusing if you are used to the CPython 2 semantics. In fact, <code>basestring</code> and <code>unicode</code> are both aliases for <code>str</code>.</p>

<pre><code>IronPython 2.7.4 (2.7.0.40) on .NET 4.0.30319.42000 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; unicode
&lt;type 'str'&gt;
&gt;&gt;&gt; basestring
&lt;type 'str'&gt;
</code></pre>

<p>Regarding strings, IronPython (2.X) behaves more like Python 3, with the slightly annoying fact that you can't distinguish between <code>unicode</code> and <code>str</code> if you want to decode / encode based on the type (and since it is still Python 2, there is also no <code>bytes</code>).</p>

python .net unicode ironpython