why does this gives error print "module {0}".format(key) , i hope this is nt the python version problem...

Recommended Answers

All 6 Replies

>>> #Python2.x
>>> key = 5
>>> print "module {0}".format(key)
module 5

>>> #Python 3.x
>>> print("module {0}".format(key))
module 5

Always post the traceback when you report such errors! If it is a SyntaxError, use print("module {0}".format(key)). Otherwise, the format() method could cause an error in some cases (unicode encoding, or use of a custom class).

i was tryinng this

    import sys
    for key in sys.modules.keys():
        if "myPackage" in key:
            del sys.modules[key]
            print "Deleting module {0}".format(key)

this gives error

ok so its due to python version , works with 2.6

Thanks for the detailed info ZZucker.

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.