<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><div><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px; "><div class="yui_3_2_0_34_133553424105480"><div style="font-family: 'times new roman', 'new york', times, serif; "><font size="3">> > type(lambda : 0)</font><br><font size="3">> ></font><br><font size="3">> > is about as simple as you can do it with lambda...</font><br>><br><font size="3">> ...I think there should be a type.function avaliable in python, like str, int, etc. exists. </font></div></div></blockquote><span style="font-family: 'times new roman', 'new york', times, serif;"><br></span>But there are many different function like objects just </div><div>as there are many different types of number. Python
does </div><div>not have a type.number either.<br><div class="yui_3_2_0_34_133553424105480"><div class="yui_3_2_0_34_133553424105482"><font size="3"><br></font></div></div>Instead of<br><span style="font-family: 'times new roman', 'new york', times, serif;"><br></span><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px; "><div class="yui_3_2_0_34_133553424105480"><div class="yui_3_2_0_34_133553424105482"><font size="3">> isinstance(2, function)</font></div></div></blockquote>you can do:<br><br></div><div>callable(2)<br><span style="font-family: 'times new roman', 'new york', times, serif;"><br></span>which will check if 2 is any kind of callable object </div><div>- function, method, class etc.<br><span style="font-family: 'times new roman', 'new york', times, serif;"><br></span>That is usually much more useful that getting the
type.<br><span style="font-family: 'times new roman', 'new york', times, serif;"><br></span>isinstance() does not of course return the type it tells </div><div>you if the object is an instance of the class or any </div><div>of its its subclasses:<br><span style="font-family: 'times new roman', 'new york', times, serif;"><br></span>>>> class C: pass<br>... <br>>>> class B(C):pass<br>... <br>>>> c = C()<br>>>> b = B()<br>>>> isinstance(c,C)<br>True<br>>>> isinstance(b,C)<br>True<br>>>> isinstance(b,B)<br>True<br>>>> isinstance(c,B)<br>False<br>>>> <br><span style="font-family: 'times new roman', 'new york', times, serif;"><br></span>callable works the same way in that it tests whether you </div><div>can call the name. Which is usually all you care about.</div><div><br><blockquote style="border-left-width: 2px; border-left-style: solid;
border-left-color: rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px; "><div class="yui_3_2_0_34_133553424105480"><div class="yui_3_2_0_34_133553424105482"><font size="3">> Yes, I know that the pythonic way is to not define types in variables. </font></div><div class="yui_3_2_0_34_133553424105482"><font size="3">> The variables are free while there is no assign to these. I need type because I want to implement </font></div><div class="yui_3_2_0_34_133553424105482"><font size="3">> Tag as triple of name, type and value. I want to differentiate between a tag with type str and </font></div><div class="yui_3_2_0_34_133553424105482"><font size="3">> value "today" and a tag with tag with type data and value "today".</font></div></div></blockquote><span style="font-family: 'times new roman', 'new york', times, serif;"><br></span>But why? Doing so will greatly reduce the flexibility of your </div><div>class.
Far better to build Tag such that it works with any </div><div>object type.</div><div><br></div><div>Why would you need to know the type?</div><div>There are a very few scenarios where the type is genuinely </div><div>important (serialisation of data is one case) but in many </div><div>cases you just don't need to know.<br><div class="yui_3_2_0_34_133553424105480"><div class="yui_3_2_0_34_133553424105482"><br></div></div><span style="font-family: 'times new roman', 'new york', times, serif;">Alan G</span></div> </div></body></html>