view raw
Yethrosh Yethrosh - 6 months ago 37
Python Question

How to auto-increment in python

I am new to python. I want to print all available functions in os module as:

1 functionName

2 functionName

3 functionName

and so on.

Currently I am trying to get this kind of output with following code:

import os

cur = dir(os)
for i in cur:
count = 1
count += 1

But it prints as below:

2 functionName

2 functionName

2 functionName

till end.

Please help me generate auto increment list of numbers, Thanks.


Use enumerate

import os

cur = dir(os)
for i, f in enumerate(cur, start=1):
    print("%d: %s" % (i, f))