在将属性设置为函数副本时,我观察到一种奇怪且完全出乎意料的行为:该属性也(隐含地!)设置为复制的函数。
示例:
import numpy as np
import matplotlib.pylab as pl
import matplotlib.gridspec as gridspec
# Create 2x2 sub plots
gs = gridspec.GridSpec(2, 2)
pl.figure()
ax = pl.subplot(gs[0, 0]) # row 0, col 0
pl.plot([0,1])
ax = pl.subplot(gs[0, 1]) # row 0, col 1
pl.plot([0,1])
ax = pl.subplot(gs[1, :]) # row 1, span all columns
pl.plot([0,1])
请注意,在以下情况下不会发生此行为:
v <- is.integer
attr(v, "foo") <- "bar"
attr(is.integer, "foo")
#> "bar" <------------------------- WHY ?