[Tutor] name error

ugajin at talktalk.net ugajin at talktalk.net
Tue Jul 15 14:46:13 CEST 2014

Thanks all, for your time and trouble spent on this issue. 
There are other 2D packages around including; Shoebot, which runs 
Python 2.7 and is a rewrite of nodebox 1, and is said to be inspired by 
DrawBot and Shoes. However, its installation is not well documented (or 
straightforward).  nodebox 1 is declared as a fork of DrawBot, and 
Shoes is written in Ruby.  The precursor of all these seem to be a 
language/environment named DBN (design by numbers), which appears also 
to have spawned Processing, a better known (and better supported) Java 
based IDE. I migrated from Processing to nodebox because of a small 
anomaly in how Processing out-processes bitmaps (no pun intended).  One 
really great thing (for me) is the discovery that DrawBot will out-put 
fully compliant native SVG. I do not think Matplotlib is quite the same 
type of thing.

shoebot seems to be the way forward, but as said, its installation on 
OSX is not straightforward. The GitHub repository suggests using 
MacPorts and Python 2.5 with, py25-numpy - atlas, pango + quartz, 
librsvg, py25-pil, py25-cairo, py25-gtk
But it goes on to say 'MacPorts does not have the python-rsvg package, 
so svg output won't work (see above). Perhaps they mean Python 2.5 does 
not have the Python-rsvg package. Not sure.
It goes on to state as a TODO: 'probably installing py27 packages and 
gnome-python-desktop would fix the missing python-rsvg problem.
It is unclear what py27 packages are. How do I check to see what 
packages I have, and e.g. if I have gnome-python-desktop?
I have OSX installed Python 2.5, as well as Python 2.7 via MacPorts

Apologies for any earlier confusion caused. The nodebox IDE is indeed 
messing me up, big time. 
 The function rect(x, y, w, h) is called as it is shown in the nodebox 
IDE (lowercase - see below).
# file named rect_1
rect(0, 0, 100, 100)
To clarify, this produces the expected output, but if I try importing 
this file with a simple import statement I get the name error:
# file named import_rect_1
import rect_1
Traceback (most recent call last):
  File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
  File "/Users/apple/Documents/nodeBox/06_15_2014/import_rect_1.py", 
line 1, in <module>
  File "/Users/apple/Documents/nodeBox/06_15_2014/rect_1.py", line 1, 
in <module>
NameError: name 'rect' is not defined

I can use the exec statement, but this rather defeats my purpose.
f = open('rect_1.py')
code = f.read()
exec code

If I put the following statement in an otherwise empty document
print dir()
I get the following information displayed in the IDE console window:
['BOOLEAN', 'BUTTON', 'BezierPath', 'CENTER', 'CLOSE', 'CMYK', 
'CORNER', 'CURVETO', 'Canvas', 'ClippingPath', 'Color', 'Context', 
'MOUSEY', 'MOVETO', 'NORMAL', 'NUMBER', 'NodeBoxError', 'Oval', 
'PAGENUM', 'PathElement', 'Point', 'RGB', 'RIGHT', 'Rect', 'TEXT', 
'Text', 'Transform', 'Variable', 'WIDTH', '__builtins__', '__class__', 
'__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', 
'__init__', '__magic_var__', '__module__', '__new__', '__reduce__', 
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 
'_align', '_arrow', '_arrow45', '_autoclosepath', '_colormode', 
'_colorrange', '_copy_attr', '_copy_attrs', '_ctx', '_fillcolor', 
'_fontname', '_fontsize', '_get_height', '_get_width', '_imagecache', 
'_lineheight', '_makeInstance', '_noImagesHint', '_ns', '_oldvars', 
'_outputmode', '_path', '_resetContext', '_strokecolor', 
'_strokewidth', '_transform', '_transformmode', '_transformstack', 
'_vars', 'addvar', 'align', 'arrow', 'autoclosepath', 'autotext', 
'background', 'beginclip', 'beginpath', 'canvas', 'choice', 
'closepath', 'cm', 'color', 'colormode', 'colorrange', 'curveto', 
'drawpath', 'endclip', 'endpath', 'files', 'fill', 'findpath', 
'findvar', 'font', 'fontsize', 'grid', 'image', 'imagesize', 'inch', 
'key', 'keycode', 'keydown', 'line', 'lineheight', 'lineto', 'mm', 
'mousedown', 'moveto', 'nofill', 'nostroke', 'outputmode', 'oval', 
'pop', 'push', 'random', 'rect', 'reset', 'rotate', 'save', 'scale', 
'scrollwheel', 'size', 'skew', 'speed', 'star', 'stroke', 
'strokewidth', 'text', 'textheight', 'textmetrics', 'textpath', 
'textwidth', 'transform', 'translate', 'var', 'wheeldelta', 'ximport']

As you see, there is something named 'Rect' (capitalised).

As Steven has suggested it would be more interesting, I have tried the 
print Rect
#prints: <bound method Context.Rect of <nodebox.graphics.Context 
object at 0x1d33b670>>
print Rect.__name__
# prints: Rect

I am still considering this.
Running the following code;
print dir(Context)

['BezierPath', 'ClippingPath', 'Color', 'HEIGHT', 'Image', 
'Rect', 'Text', 'WIDTH', '__class__', '__delattr__', '__dict__', 
'__doc__', '__getattribute__', '__hash__', '__init__', '__module__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__str__', '__weakref__', '_arrow', '_arrow45', '_get_height', 
'_get_width', '_makeInstance', '_resetContext', 'addvar', 'align', 
'arrow', 'autoclosepath', 'background', 'beginclip', 'beginpath', 
'closepath', 'color', 'colormode', 'colorrange', 'curveto', 'drawpath', 
'endclip', 'endpath', 'fill', 'findpath', 'findvar', 'font', 
'fontsize', 'image', 'imagesize', 'line', 'lineheight', 'lineto', 
'moveto', 'nofill', 'nostroke', 'outputmode', 'oval', 'pop', 'push', 
'rect', 'reset', 'rotate', 'save', 'scale', 'size', 'skew', 'speed', 
'star', 'stroke', 'strokewidth', 'text', 'textheight', 'textmetrics', 
'textpath', 'textwidth', 'transform', 'translate', 'var', 'ximport']

I note here that 'rect' is now all in lowercase.

Further, to confirm, the following code does execute correctly:
import nodebox
nodebox.graphics.BezierPath(rect(0, 0, 100, 100))

The suggestions, which I thank you for, of running:
import nodebox
nodebox.graphics.BezierPath.rect(0, 0, 100, 100)
produces the following outputs:
Traceback (most recent call last):
  File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
  File "<untitled>", line 5, in <module>
TypeError: unbound method rect() must be called with BezierPath 
instance as first argument (got int instance instead)
import nodebox
nodebox.graphics.Rect(0, 0, 100, 100)
Traceback (most recent call last):
  File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
  File "<untitled>", line 8, in <module>
TypeError: __init__() takes exactly 6 arguments (5 given)

However, I now find the following code also executes correctly:
import nodebox
nodebox.graphics.Context(BezierPath(rect(0, 0, 100, 100)))

Interesting as it is, I am no closer to finding a solution.
If, I try calling the the above as a module I get:
# file named rect_2
import nodebox
nodebox.graphics.Context(BezierPath(rect(0, 0, 100, 100)))
# file named import_rect_2
import rect_2

I now get:
Traceback (most recent call last):
  File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
  File "/Users/apple/Documents/nodeBox/07_15_2014/import_rect_2.py", 
line 1, in <module>
  File "/Users/apple/Documents/nodeBox/07_15_2014/rect_2.py", line 3, 
in <module>
NameError: name 'BezierPath' is not defined

I hope this helps clear up any confusion.

Kind regards


PS - I use a web-based mail client, which is I think based on AOL's 
client and its takeover by talktalk.

PPS - The comment for v.1.9.7  is not relevant to the issues here, but 
it is something I wanted to note, for future reference. 
I apologise for its inclusion, I was too tired to think where else to 
put it.

PPPS - Re:
> dir: ['__builtins__', '__doc__', '__file__', '__name__', 
'draw_rect', > 'nodebox']

I have tried to repeat this outcome, and I am surprised that it was not 
so easy to do.
I still have the original files, and they produced the same output as 
shown previously.
After some investigation, it seems that 'draw_rect' results from an 
earlier test that had been comment out.
What I had done, was to place the rect(x, y, w, h) function in a def 
I had then abandoned this line of enquiry, and had commented out the 
nodebox 1 does not have a kernel restart command.

I hope this makes sense.


More information about the Tutor mailing list