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

Recommended Answers

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

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

The Python3 str.format() method has been backported to Python 2.6.

See
http://docs.python.org/2.6/library/stdtypes.html
http://docs.python.org/2.6/whatsnew/2.6.html
and
PEP 3101

Jump to Post

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 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.