5
Contributors
6
Replies
73
Views
3 Years
Discussion Span
Last Post by vegaseat
Featured Replies
  • 1

    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 Even with Python33 you can still use the % specifier: import sys for key in sys.modules.keys(): print("hello from %s" % key) Read More

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

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

Edited by snippsat

0

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).

Edited by Gribouillis

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.