Misleading wikipedia article on Python 3?

P

Paul Rubin

Istvan Albert said:
apply(), callable(), coerce(), file(), reduce(), reload()

reduce() is really gone????? Maybe itertools can get an ireduce
function or something like that?
 
N

Neil Cerutti

reduce() is really gone????? Maybe itertools can get an
ireduce function or something like that?

I don't see how file() can be "removed", actually, unless the
file type itself is getting axed.
 
?

=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=

I don't see how file() can be "removed", actually, unless the
file type itself is getting axed.

Indeed, that's the case. Py3k won't use stdio for file input and
output, but the io module.

Regards,
Martin
 
G

greg

Istvan said:
A solution would be writing the code with a logging function to begin
with, alas many times that is out of one's hand.

If the code has been written with calls to a builtin
print function, the situation isn't much better. You
could monkeypatch the print function, but that's
probably worse than swapping sys.stdout.

(I agree that print should be a function, simply because
there's no strong reason for it *not* to be. But I
don't think it makes a difference to this particular
problem.)
 
E

Evan Klitzke

If the code has been written with calls to a builtin
print function, the situation isn't much better. You
could monkeypatch the print function, but that's
probably worse than swapping sys.stdout.

You can easily modify print in a safe way. Here's an example, that
will work in any recent version of Python:

import sys

def print_(s):
print s

def logger(method):
def wrapper(s):
sys.stderr.write('Logging: %s\n' % s)
method(s)
return wrapper

print_ = logger(print_)

print_('hello')


Running this code will do a regular print of 'hello', as well as
"logging" it to stderr. As a function, you can convert print wholesale
to another logging function, or wrap it transparently like this to
provide additional logging functionality. What do you find wrong with
this sort of "monkeypatching"?
 
?

=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=

Evan said:
You can easily modify print in a safe way. Here's an example, that
will work in any recent version of Python:

import sys

def print_(s):
print s

def logger(method):
def wrapper(s):
sys.stderr.write('Logging: %s\n' % s)
method(s)
return wrapper

print_ = logger(print_)

print_('hello')


Running this code will do a regular print of 'hello', as well as
"logging" it to stderr. As a function, you can convert print wholesale
to another logging function, or wrap it transparently like this to
provide additional logging functionality. What do you find wrong with
this sort of "monkeypatching"?

foolish question maybe.
Why wouldn't you do it this way ?

def print_(s):
print s

def logger(m):
sys.stderr.write('Logging: %s\n' % m)
method(m)

print_ = logger(print_)

print_('hello')
 
G

greg

Evan said:
You can easily modify print in a safe way.

Yes, but you'd still have to replace the builtin print
function with your own to get it used by non-cooperative
code. That doesn't seem to gain you much over replacing
sys.stdout with something that intercepts and logs
stuff written to it.
> What do you find wrong with this sort of "monkeypatching"?

At least sys.stdout was designed somewhat with the
possibility of replacing it in mind. It's not an
entirely unexpected thing to do. Replacing something
in the builtin namespace seems like a more drastic
step, somehow.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top