
{"id":16475,"date":"2016-04-18T14:46:40","date_gmt":"2016-04-18T14:46:40","guid":{"rendered":"http:\/\/www.beautifulwork.org\/?p=16475"},"modified":"2016-04-18T14:46:40","modified_gmt":"2016-04-18T14:46:40","slug":"using-the-dir-built-in-function-in-python-programming-language","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2016\/04\/18\/using-the-dir-built-in-function-in-python-programming-language\/","title":{"rendered":"using the dir() Built-in function in Python programming"},"content":{"rendered":"<pre>\n&gt;&gt;&gt; import struct\n&gt;&gt;&gt; dir()   # show the names in the module namespace\n['__builtins__', '__doc__', '__name__', 'struct']\n&gt;&gt;&gt; dir(struct)   # show the names in the struct module\n['Struct', '__builtins__', '__doc__', '__file__', '__name__',\n '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into',\n 'unpack', 'unpack_from']\n&gt;&gt;&gt; class Shape(object):\n        def __dir__(self):\n            return ['area', 'perimeter', 'location']\n&gt;&gt;&gt; s = Shape()\n&gt;&gt;&gt; dir(s)\n['area', 'perimeter', 'location']\n\nhttps:\/\/docs.python.org\/2\/library\/functions.html#dir\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&gt;&gt;&gt; import struct &gt;&gt;&gt; dir() # show the names in the module namespace [&#8216;__builtins__&#8217;, &#8216;__doc__&#8217;, &#8216;__name__&#8217;, &#8216;struct&#8217;] &gt;&gt;&gt; dir(struct) # show the names in the struct module [&#8216;Struct&#8217;, &#8216;__builtins__&#8217;, &#8216;__doc__&#8217;, &#8216;__file__&#8217;, &#8216;__name__&#8217;, &#8216;__package__&#8217;, &#8216;_clearcache&#8217;, &#8216;calcsize&#8217;, &#8216;error&#8217;, &#8216;pack&#8217;, &#8216;pack_into&#8217;, &#8216;unpack&#8217;, &#8216;unpack_from&#8217;] &gt;&gt;&gt; class Shape(object): def __dir__(self): return [&#8216;area&#8217;, &#8216;perimeter&#8217;, &#8216;location&#8217;] &gt;&gt;&gt; s = Shape() &gt;&gt;&gt; dir(s) &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2016\/04\/18\/using-the-dir-built-in-function-in-python-programming-language\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;using the dir() Built-in function in Python programming&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[91,93],"tags":[663],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/16475"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=16475"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/16475\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=16475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=16475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=16475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}