The dir() Function
The built-in function dir() is used to find out which names a module defines. It returns a sorted list of strings:
I have been listening quite often about python......not from colleagues but on internet...and went through some comparative study between python/perl/ruby. Many a times, I found python is on an edge to other scripting language and I had it in mind that I'll give it a try provided I get chance to do something interesting in a new language. Today, I found myself with good enough time and an activity hence I thought to start python....long pending language to dig upon -
Seems like very interesting and initially I would have got carried away if I wouldn't have found every single thing I stuck at....Google helped [as usual] me in finding whatever I wish to know about python....obviously credit goes to python users world wide who keep putting things here and there....which google fetch smartly for us.
For others, Few trips and tricks I can give is as follows -
-> As usual, interpreter based scripting, hence all the scripts need to have following at the first line of script
#! /usr/bin/env python
-> You can import in-built rich library of functions e.g. -
python>>> import sys
python>>> import os
-> You can find very helpful [help;] doing following -
python>>> import fibo, sys
python>>> dir(fibo)
['__name__', 'fib', 'fib2']
python>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__',
'__stdin__', '__stdout__', '_getframe', 'api_version', 'argv',
'builtin_module_names', 'byteorder', 'callstats', 'copyright',
'displayhook', 'exc_clear', 'exc_info', 'exc_type', 'excepthook',
'exec_prefix', 'executable', 'exit', 'getdefaultencoding', 'getdlopenflags',
'getrecursionlimit', 'getrefcount', 'hexversion', 'maxint', 'maxunicode',
'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache',
'platform', 'prefix', 'ps1', 'ps2', 'setcheckinterval', 'setdlopenflags',
'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout',
'version', 'version_info', 'warnoptions']
Rest will follow soon, happy python[ing]
No comments:
Post a Comment