i looked at the python 3k print module from griboullis
and i want to use it for python 2.5 without having to import it every time, i think it needs to be builtin but how can it do this, i don't mind if the old print is still there but id prefer it if it was gone.

here is the code

# module cbprint
# (C) 2008 Gribouillis at www.daniweb.com

"""This module defines a Print function to use with python 2.x or 3.x.

  from cbprint import Print
  Print("hello", "world")

It's interface is that of python 3.0's print. See
__all__ = ["Print"]
import sys
  Print = eval("print") # python 3.0 case
except SyntaxError:
    D = dict()
    exec("from __future__ import print_function\np=print", D)
    Print = D["p"] # 2.6 case
    del D
  except SyntaxError:
    del D
    def Print(*args, **kwd): # 2.4, 2.5, define our own Print function
      fout = kwd.get("file", sys.stdout)
      w = fout.write
      if args:
        sep = kwd.get("sep", " ")
        for a in args[1:]:
      w(kwd.get("end", "\n"))

In Python < 3.0, print is a keyword and as such cannot be deleted or clobbered, as far as I can tell. So for example, it's not a part of __builtins__ because it isn't a function.

Interesting that on this point, Python is bowing to the wisdom of C.


thanks but do you know how i can make it to always be in python 2.5 without having to import it?

This article has been dead for over six months. Start a new discussion instead.