Hi,
I am a beginner in programming of python , in python to view all the functions and other objects of 'keyword' module,i used the command ,dir results the some objects like __file__,__package__,__doc__ but these are not the functions of keyword module,could u please tell me the reason................. :D

>>> import keyword
>>> dir(keyword)
['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'i
skeyword', 'kwlist', 'main']

Thanks
Mukthyar azam

Recommended Answers

All 2 Replies

from keyword import kwlist

for kw in kwlist:
    print kw

Sometimes it is too easy, no dir (kwlist is suprisingly list):

>>> keyword.kwlist
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 
'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in',
'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while',
'with', 'yield']
>>> print('\n'.join(keyword.kwlist))
and
as
assert
break
class
continue
def
del
elif
else
except
exec
finally
for
from
global
if
import
in
is
lambda
not
or
pass
print
raise
return
try
while
with
yield

Interestingly BBCode does not color as and with

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.