[Tutor] empty delimiters, and None

2013-11-29 Thread ugajin
I run Inkscape (an Open Source vector drawing application) on OSX (Snow 
leopard)  installed via .dmg pkg. The application ships with a collection of 
Python extensions, one of which Measure Path, failed to execute. 

I could not find a reference for this issue in the Inkscape archives, and I 
tried and worked with other workarounds including a javascript (outside 
Inkscape) to find the length of Bézier paths, but eventually I raised the issue 
and contacted launchpad/inkscape (question #239599) but to limited avail. After 
much continued searching I then found this Bug #803791 report which describes 
(as an aside) the exact same issue together with a solution. 

I know next to nothing about Python and I shall be glad if any Python guru can 
make clear (in layman's terms where possible) what the problem is/was and how 
the fix works. 

I remembered an alternative posting that I had read, which reported that Python 
dislikes empty delimiters. So I took a slightly different approach to the one 
mentioned in the above bug report. Instead of removing line 35 from the Measure 
Path script I replaced the empty delimiters with the Python constant None. To 
my great delight as well as my own amazement the 'fix' worked. 

The problem may or may not be limited to OSX. 

On trying to run the script (before the fix) I had the following traceback 
message: 
File "measure.py", line 35, in 
locale.setlocale(locale.LC_ALL, '')
File 
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/locale.py",
 line 494, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting

If I booted from the Unix file I received the following feedback:
Setting Language: .UTF-8
(process:82224): Gtk-WARNING **: Locale not supported by C library.
Using the 
fallback 'C' locale.

Line 35 (above) shows the empty delimiter. The fix that I applied was to 
replace line 35 in the Measure.py script with:
locale.setlocale(locale.LC_ALL, None). The Measure Path script then executes 
correctly. No other action is/was required.

I note also the Python 2 library entry for Built-in Constants as:
None
The sole value of types.NoneType. None is frequently used to represent the 
absence of a value, as when default arguments are not passed to a function.
Changed in version 2.4: Assignments to None are illegal and raise a SyntaxError.

And under standard type hierarchy as:
None
This type has a single value. There is a single object with this value. This 
object is accessed through the built-in name None. It is used to signify the 
absence of a value in many situations, e.g., it is returned from functions that 
don’t explicitly return anything. Its truth value is false.
I have run the various scripts in a Python Validator, and line 35 (both 
versions) pass unremarked, although there are a few other code errors and 
warnings and many pep8 warnings. 

I have also looked at locale.py Line 494 of which is the last line of a def 
(def function?) I include this below, hopefully this may save you searching for 
locale.py (Pyhon 2.6) should you need it and wish to answer the above 
questions, it may help.

def setlocale(category, locale=None):

""" Set the locale for the given category.  The locale can be
a string, a locale tuple (language code, encoding), or None.

Locale tuples are converted to strings the locale aliasing
engine.  Locale strings are passed directly to the C lib.

category may be given as one of the LC_* values.

"""
if locale and type(locale) is not type(""):
# convert to string
locale = normalize(_build_localename(locale))
return _setlocale(category, locale)


Many, many thanks for your interest and considering matters.

-A
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] empty delimiters, and None

2013-11-30 Thread ugajin
Thanks for the helpful comments Eryksun/Steve

Mis-configured environment (see below)?
I rather felt that setting the 2nd parameter to None, was side stepping an 
underlying issue.
However I experimented further and find; locale.setlocale(locale.LC_ALL, 
'en_GB') also works OK. Perhaps this is a better fix than 
locale.setlocale(locale.LC_ALL, None) but again it may be side stepping the 
underlying issue.

Here is link: https://answers.launchpad.net/inkscape/+question/239599. I think 
you need to register to access the both the question and Bug #803791 report. 
You may not want to do this.

I believe the system locale is set correctly:

Apples-iMac-4:~ apple$ locale
LANG="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_CTYPE="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_ALL=

The underlying problem appears to be with the application launcher script (see 
below).

To explain 'booted from Unix file' is difficult for me, especially if you are 
unfamiliar with OSX, It is a way of running the application together with a 
Terminal window.

Inkscape is an Open Source SVG editor with some 'proprietary' features that are 
not part of the SVG standard.
The Measure Path script, can calculate either the length of, or the area 
enclosed by a path. 
The value is displayed as text, which is added and anchored to the path that is 
measured. 
Variables include precision (no. of significant places) and unit type (px, mm & 
etc.), as well as offset & font size (for text output).

I did try contacting one of its authors, and I have raised the matter as a 
question, (see link above). The initial response was; "A workaround is to edit 
the launcher script (to force a valid UTF-8 language settings)."  The fix 
provided (shown below) caused Inkscape to crash immediately after the launch 
routine completed:

Quit all running instances of Inkscape. Then
1) Select Inkscape (the 
application) in the Finder
2) Choose 'Show Package Contents' from the context 
menu
3) Browse to 'Contents > Resources > bin'
4) Open the file 'inkscape' in a 
plain-text editor (e.g. TextWrangler)
5) Scroll down to line 127
6) Insert a 
new line before line 127 with this content:
export LANG="en_US.UTF-8"
7) Save & close file (make sure that your text editor does _not_ add a
hidden 
suffix to the file, else the application won't launch anymore)
8) Relaunch 
Inkscape
If you prefer a different UI language, adjust the string "en_US.UTF-8"
as 
needed.

Lines 123 to 127 of the launcher script read:

# NOTE: Have to add ".UTF-8" to the LANG since omitting causes Inkscape
#   to crash on startup in locale_from_utf8().
export LANG="`grep \"\`echo $LANGSTR\`_\" /usr/share/locale/locale.alias | \
tail -n1 | sed 's/\./ /' | awk '{print $2}'`.UTF-8"
echo "Setting Language: $LANG" 1>&2

I am told this 'fix' works for OSX v10.5.8 (Leopard) and OSX 10.7.5 (Lion).  
However, I run OSX v10.6.8 (Snow Leopard).

I am also interested in identifying the underlying issue, although I am far out 
of my comfort zone, and which seems to be with the launcher script. From the 
various postings and comments read, this seems to be something of an old 
chestnut. Maybe you can't suggest an alternative fix to the above, but maybe 
you can comment to help explain lines 123 - 127.

Many many thanks, once more.

-A

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: empty delimiters, and None

2013-12-01 Thread ugajin

 The answer is , yes (to both questions)
locale -a does report availability of en_US (and en_US.UTF), C is supported, 
but C.UTF-8 does not appear in the list.
I have tried inserting export LANG="en_GB.UTF.8" as a new line 127.

Thanks.


-A


-Original Message-
From: eryksun 
To: uga...@talktalk.net
CC: Tutor@python.org
Sent: Sat, 30 Nov 2013 23:56
Subject: Re: empty delimiters, and None


On Sat, Nov 30, 2013 at 7:04 AM,   wrote:
> believe the system locale is set correctly:
>
> Apples-iMac-4:~ apple$ locale
> LANG="en_GB.UTF-8"

Does `locale -a` report that en_US is available?

> 127
6) Insert a new line before line 127 with this content:
> export LANG="en_US.UTF-8"

Did you try en_GB.UTF-8 here?

> Lines 123 to 127 of the launcher script read:
>
> # NOTE: Have to add ".UTF-8" to the LANG since omitting causes Inkscape
> #   to crash on startup in locale_from_utf8().
> export LANG="`grep \"\`echo $LANGSTR\`_\" /usr/share/locale/locale.alias | \
> tail -n1 | sed 's/\./ /' | awk '{print $2}'`.UTF-8"
> echo "Setting Language: $LANG" 1>&2

The current version uses the value of AppleCollationOrder or
AppleLocale (e.g. defaults read .GlobalPreferences AppleLocale) to
find the locale in the locale.alias file, and defaults to
"en_US.UTF-8". I don't know if "en_US" is always available in OS X,
but surely "C.UTF-8" would be. I don't know why it can't modify the
existing LANG to use the UTF-8 codeset. Finally, I can't speak for OS
X, but the glibc locale.alias on Linux is obsolete and doesn't have an
alias for English.

 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] empty delimiters, and None

2013-12-01 Thread ugajin

 Well, yes.
I find can indeed use;locale.setlocale(locale.LC_ALL) thanks!
In addition to locale.setlocale(locale.LC_ALL, None)
I found I can also use; locale.setlocale(locale.LC_ALL, 'en_GB')
The question remains, why does; locale.setlocale(locale.LC_ALL, '') fail, 
especially if it is good practice?

 
-A


 

-Original Message-
From: spir 
To: tutor@python.org
Sent: Sun, 1 Dec 2013 0:56
Subject: Re: [Tutor] empty delimiters, and None


On 11/29/2013 02:19 PM, uga...@talktalk.net wrote: 
> I have also looked at locale.py Line 494 of which is the last line of a def 
> (def function?) I include this below, hopefully this may save you searching 
> for locale.py (Pyhon 2.6) should you need it and wish to answer the above 
> questions, it may help. 
> 
> def setlocale(category, locale=None): 
> 
>  """ Set the locale for the given category.  The locale can be 
>  a string, a locale tuple (language code, encoding), or None. 
> 
>  Locale tuples are converted to strings the locale aliasing 
>  engine.  Locale strings are passed directly to the C lib. 
> 
>  category may be given as one of the LC_* values. 
> 
>  """ 
>  if locale and type(locale) is not type(""): 
>  # convert to string 
>  locale = normalize(_build_localename(locale)) 
>  return _setlocale(category, locale) 
 
As a side-note, in addition to what other have said, the headline of the 
function def 
 
def setlocale(category, locale=None) 
 
says that None is the default (standard) value for the parameter 'locale'. This 
means that, if ever you provide no value for it when calling setlocale, then 
the value None is used in standard. So, you could as well call it like: 
 
locale.setlocale(locale.LC_ALL) # no value at all for param 'locale' 
 
instead of you correction 
 
locale.setlocale(locale.LC_ALL, None) 
 
for the initial version 
 
locale.setlocale(locale.LC_ALL, '') 
 
This is actually good coding practice (in all language which have default 
values). 
 
Denis 
___ 
Tutor maillist  -  Tutor@python.org 
To unsubscribe or change subscription options: 
https://mail.python.org/mailman/listinfo/tutor 

 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] running modules as scripts

2013-12-05 Thread ugajin
I have some difficulty with the abovet. I succeeded after a fashion, but only 
after some experiment, and I am not satisfied that all is well. 
Here is the script code (as per the Python tutorial 6.1.1.):

def fib(n):# write Fibonacci series up to n
a, b = 0, 1
while b < n:
print b,
a, b = b, a+b

def fib2(n): # return Fibonacci series up to n
result = []
a, b = 0, 1
while b < n:
result.append(b)
a, b = b, a+b
return result

if __name__ == "__main__":
import sys
fib(int(sys.argv[1]))

It is saved in the current directory as fibo.py with the current directory 
being: 
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/

The module executes ok when imported but not as a script. 
Terminal returns: 
Apples-iMac-4:~ apple$ python fibo.py 50
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:
 can't open file 'fibo.py': [Errno 2] No such file or directory
Apples-iMac-4:~ apple$ 

However, Python appears to be searching the correct directories:

>>> import sys
>>> sys.path
['', 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gtk-2.0']

And. . .  if I open the same script with: right click > Open with > Python 
Launcher.app (2.7.6) I get:
Last login: Wed Dec  4 20:52:15 on ttys002
Apples-iMac-4:~ apple$ cd 
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/' && 
'/usr/bin/pythonw'  
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/fibo.py'
  && echo Exit status: $? && exit 1
Traceback (most recent call last):
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/fibo.py",
 line 21, in 
fib(int(sys.argv[1]))
IndexError: list index out of range

Then . . . if I then use this same window to call the script it runs:
Apples-iMac-4:python2.7 apple$ python fibo.py 50
1 1 2 3 5 8 13 21 34
Apples-iMac-4:python2.7 apple$ 

Je suis perplexed!

-A
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] running modules as scripts

2013-12-07 Thread ugajin
Thanks for your answers!

Hmm!

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] recursive function example

2013-12-10 Thread ugajin
I am looking at a simple recursive function, and oxymoron aside, I am having 
difficulty in seeing what occurs. I have tried adding some debug print commands 
to help break the thing down. This helps a lot, but I still have a question 
that I need help with.

Here is original code:
def mult(a, b):
if b == 0:
return 0
rest = mult(a, b - 1)
value = a + rest
return value
print "3 * 2 = ", mult(3, 2)

I see how python outputs the string "mult(3,2)" before running the function, 
and then adds the return value to the output, 
and I see how the 'if' condition is met, 
but I do not see how the variable 'rest' is assigned a value, and a single 
value at that. 
'rest' must have a value of 3 (for this example) for the function to return the 
correct 
value, and 'rest' must be assigned the value of '3' but when, prior, to b == 0?
When 'b' == 0 (zero) the 'if' condition is escaped.
In the first iteration, 'rest' is shown with the value '0' (zero), 
and in the second it is '3'.
1st, run rest = mult(3, 1)
2nd. run rest = mult(3, 0) and the 'if' condition is met
Is there some inherent multiplication e.g. 3*1 = 3 and 3*0 = 0, 
and even if so, it seems backwards?

I am once again perplexed!
Help please. . . if you can.

-A

Here is my debugging code:

#! /usr/bin/env python

def mult(a, b):
if b == 0:
return 0
print
print 'a =', a
print 'b =', b
rest = mult(a, b - 1)
print
print 'rest =', rest
value = a + rest
print 'value =', value, '(a + rest ==',a, '+', rest,')'
return value
print
print 'mult(3,2) value = ', '\n', '\nreturn = ' + str(mult(3, 2))


Here is the output from the debugging code:

mult(3,2) value =  

a = 3
b = 2

a = 3
b = 1

rest = 0
value = 3 (a + rest == 3 + 0 )

rest = 3
value = 6 (a + rest == 3 + 3 )

return = 6



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] recursive function example

2013-12-11 Thread ugajin


 

 

 

-Original Message-
From: Alan Gauld 
To: tutor@python.org
Sent: Wed, 11 Dec 2013 0:29
Subject: Re: [Tutor] recursive function example


On 10/12/13 14:48, uga...@talktalk.net wrote: 
 
>> Here is original code: 
>> def mult(a, b): 
>>  if b == 0: 
>>  return 0 
>>  rest = mult(a, b - 1) 
>>  value = a + rest 
>>  return value 
>> print "3 * 2 = ", mult(3, 2) 
>> 
>> I see how python outputs the string "mult(3,2)" before running the 
>> function, 
 
>No it doesn't. 
>It outputs the string "3 * 2 - " before running the function! 
 
Yes, my mistake.

>> and then adds the return value to the output, 
 
>Again no. It adds the first parameter to the return value of the recursive 
>call to mult() 
 

I meant that the printed output is in two parts; the string and the return 
value. 
The function call is made part way through outputting/executing the print 
command.


>> and I see how the 'if' condition is met, 
 
>> but I do not see how the variable 'rest' is assigned a value, and a 
>> single value at that. 
 
>Because it calls mult with a new set of arguments (a, b-1) instead of the 
>original (a,b). Each call to mult calls mult with a new (a, b-1) until 
>eventually b is equal to >zero and the if test returns zero. 

Again, I am not making myself clear.


>> 'rest' must have a value of 3 (for this example) for the function to 
>> return the correct value, and 'rest' must be assigned the value 
>> of '3' but when, prior, to b == 0? 
 
>No after b=0. the first return from mult is the b-0 case of zero. 
>the next return value will be a + 0 = 3 and the final return value 
>is 3 + 3 which is 6, the correct result. 

Lost me here!, "The first return after b=0 is b-0"?
"a + 0 = 3", yes
I don't see where the second 3 comes from.
 
>> When 'b' == 0 (zero) the 'if' condition is escaped. 
 
>By escaped you mean the functions returns zero. 

Yes.
 
>> In the first iteration, 'rest' is shown with the value '0' (zero), 
>> and in the second it is '3'. 
 
>That's correct, zero + a where a=3. So value = 3 
 
>> 1st, run rest = mult(3, 1) 
>> 2nd. run rest = mult(3, 0) and the 'if' condition is met 
>> Is there some inherent multiplication e.g. 3*1 = 3 and 3*0 = 0, 
 
>There is no multiplication at all. The function works on the basis that 
>multiplication is equivalent to repeated addition. 
>So 3 * 2 = 0+2+2+2 or 0+3+3 

I would have thought so, too. Where is the 0 (zero) in yours from? There is no 
0 (zero) in 3 * 2
 
>Try reversing the arguments to see the first case at work... 
 
>> and even if so, it seems backwards? 
 
>It is backwards in so far as the recursion has to drill down 
>to the zero case then unwind back up to the initial case. 
>That's often the case with recursion. 
 
>It often helps to do it on paper rather than using the computer. 
>Try drawing a table like 
 
>a  b   b==0   b-1  return 
>--- 
>3  2   False   1 
>3  1   False   0 
>3  0   True-10 # I get it this far, but then ask where 
>does -1 and second 0 (zero) come from?
Why does the function not stop here? 
b is never equal to -1, if b == 0 then b -1 would 
be equal to -1, but 
when b == 0, the if condition is met and return is 0
>3  1   3+0=3# I don't get this, where does the 
>second 3 and the 0 come from?
>3  2   3+3=6   # or this, it looks like the function 
>has added a + a, but I do not see how, or when it is told to do this.
 
>Work your way through it line by line. 


I do not understand how a function that begins with two parameters can end with 
one unless an operation is performed on the two parameters to combine them. 
I do not see an instruction in the function mult(a, b) that says to do this
As you say 3 * 2 has to be 3+3 or 2+2+2
Where a = 3 and b = 2 (initial), b = 1 (1st run) and b = 0 (2nd run)
One might add a + b (initial) + b (1st run) + b (2nd run) to return 6, but
there is a slight of hand at work here or something. Where is 'b' stored and 
where is the instruction to add together these values, if indeed this is what 
is done?
Thanks, for trying to explain. Perhaps you will try again?

HTH 
-- Alan G 
Author of the Learn to Program web site 
http://www.alan-g.me.uk/ 
http://www.flickr.com/photos/alangauldphotos 
 
___ 
Tutor maillist  -  Tutor@python.org 
To unsubscribe or change subscription options: 
https://mail.python.org/mailman/listinfo/tutor 

 
 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] recursive function example

2013-12-11 Thread ugajin
It is kind of you to take the trouble of trying to explain.
I see the value assigned to rest on each iteration from the debugging script 
that I made, 
What I do not see is how?

Clearly, a = 3, it is constant throughout each iteration, and 
if rest is equal to 3, then a + rest must be equal to 6.

You spoke of drilling down, and I see that mult(3, 2) drills down until b == 0, 
I am less clear
how it then begins to ascend, and if it does, why? But, my question is how is 
rest assigned 
a single argument/value?

I agree, rest equals 0 (zero) on the first iteration and 3 on the second, but 
as I don't see how,
I cannot understand how value = a + rest  => 3+0 => 3 although I get:
value = a + rest, and I get (where rest = 0) a + rest => 3+0 and I get 3+0 => 3


What am I missing? Is it something that isn't explicit?
It seems to me that rest has two arguments, not one.
I do not understand "+>", is it a typo perhaps?

Many thanks.

 
-A

 

-Original Message-
From: Alan Gauld 
To: tutor@python.org
Sent: Wed, 11 Dec 2013 9:05
Subject: Re: [Tutor] recursive function example


On 10/12/13 14:48, uga...@talktalk.net wrote: 
 
OK, I'll try again, this time just walking through the code from the top. 
 
> def mult(a, b): 
>  if b == 0: 
>  return 0 
>  rest = mult(a, b - 1) 
>  value = a + rest 
>  return value 
 > 
> print "3 * 2 = ", mult(3, 2) 
 
We print "3 * 2 = " and then call mult(3,2) 
b does not equal zero so we move to the line rest = mult(a,b-1) 
This calls mult(3,1) 
 
Now in the new invocation of mult() 
b does not equal zero so we move to the line rest = mult(a,b-1) 
This calls mult(3,0) 
 
Now in the new invocation of mult() 
b does equal zero so we return zero 
 
Now back in the mult(3,1) version of mult() 
rest now equals zero 
value = a + rest  => 3+0 => 3 
we return 3 
 
Now back in the original invocation of mult() 
rest = 3 
value = a+rest +> 3+3 => 6 
we return 6 
 
we print 6. 
End of program 
 
Remember that each time mult() is called it creates 
its own mini-world of variables independent of the 
previous calls. 
 
HTH 
-- Alan G 
Author of the Learn to Program web site 
http://www.alan-g.me.uk/ 
http://www.flickr.com/photos/alangauldphotos 
 
___ 
Tutor maillist  -  Tutor@python.org 
To unsubscribe or change subscription options: 
https://mail.python.org/mailman/listinfo/tutor 

 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] recursive function example

2013-12-11 Thread ugajin
Yes, it does :)

The indents get messed up in my mail programme, but/and 
issue running first example, it returns 1:

 def sum_up_to(n): 
# 'res' for result because 'sum' is a Python builtin symbol 
res = 0
for i in range(1, n+1):
res += i
return res 
print(sum_up_to(9)) 

But the following worked:
if n == 1:
return 1
else:
return sum_up_to_rec1(n-1) + n
print(sum_up_to_rec1(9)) 

Interesting debug output comparing rec1 and rec2
There is I think a typo in line:
print("start of func ; n : %d" % n, end=" | ") 
I changed this to:
print("start of func ; n : %d" % n, "end= | ")


Cab now see the 'hidden' object sub_res, and the hidden sum operation, thanks! 
I am guessing, it is possible to save each sub_res object as it is generated as 
a variable perhaps, or grouped together as a list?

 Self-similar (fractal) recursion, sounds complex, I am guessing this is like 
linear recursion but simultaneously in more than one dimension?
Curious business really. Wonders, if I may be a closet programmer, or something,

Your explanation has helped, thanks. I shall look again at how the sub_res 
outcomes are printed :)

-A


 

-Original Message-
From: spir 
To: tutor@python.org
Sent: Wed, 11 Dec 2013 13:15
Subject: Re: [Tutor] recursive function example


On 12/10/2013 03:48 PM, uga...@talktalk.net wrote: 
> [...] 
 
Recursivity is hard to get really, meaning intuitively with your guts 
so-to-say. Maybe using another example may help. Lets us say you want a 
function that sums numbers from 1 up to n, the only input variable. (The result 
should thus be n(n+1)/2.) 
 
def sum_up_to (n): 
# 'res' for result because 'sum' is a Python builtin symbol 
res = 0 
for i in range(1, n+1): 
res += i 
return res 
print(sum_up_to(9)) 
 
Now, how to make this recursive? There are multiple ways, all based on: 
# intuitive def: 
sum_up_to(n) = 1 + 2 + ... + n 
# recurrence def: 
sum_up_to(n) = sum_up_to(n-1) + n 
sum_up_to(1) =  1 
We want to just reproduce this second def stupidly in code: 
 
def sum_up_to_rec1 (n): 
if n == 1: 
return 1 
else: 
return n + sum_up_to_rec1(n-1) 
print(sum_up_to_rec1(9)) 
 
This does not help much and understand the recursion procedure yet, si let use 
add some debug output rightly placed: 
 
def sum_up_to_rec1 (n): 
print("start of func ; n : %d" % n, end=" | ") 
if n == 1: 
return 1 
else: 
sub_res = sum_up_to_rec1(n-1) 
print("n : %d ; sub_res : %d" % (n, sub_res)) 
return n + sub_res 
print(sum_up_to_rec1(9)) 
 
Run it. 
 
The surprising point, maybe, is that all "start of func..." outputs get written 
in a row with all "sub_res..." outputs coming on lines one under the other. 
This is the core of the recurrent logic: starting from 9, we call the func for 
8; nothing is yet computed, no result (thus nothing to print as sub_res). From 
8, we call the func for 7; nothing is yet computed, still. Etc... until 1, our 
stop value, which finally returns a result. This result for 1 permits the call 
for 2 to (write the sub_res for 1 *at the end of the big row* and) complete, 
which permits the call for 3 to (write the sub_res for 2 and) complete... etc 
until 9. The call for 9 is out initial run, when it returns with its product, 
this is the final result. 
 
Thus, the logic is such: the execution cascade falls here top-down; but the 
computation cascade inverts gravity and climbs down-up. 
 
Does this help? 
 
Now, why do we execute top-down? After all, the definition by recurrence allows 
us very well to start from 1 and go up to n, it would work as well, so why not? 
The reason is that we would need to keep n aside, since in this case it becomes 
our stop value; but we still need some index, here going up from 1 to n. Thus, 
we need another parameter to the recurrent func, say like in the easy func 
above. And in fact we need yet a third parameter, namely the partial result: 
how else would the next call know the partial result? This gives something 
like: 
 
def sum_up_to_rec2 (n, i=1, sub_res=0): 
# 'res' for result because 'sum' is a Python builtin symbol 
print("start of func ; i : %d ; sub_res : %d" % (i, sub_res), end=" | ") 
if i == n: 
return i + sub_res 
else: 
sub_res += i 
print("sub_call ; sub_res : %d" % sub_res) 
return sum_up_to_rec2(n, i+1, sub_res) 
print(sum_up_to_rec2(9)) 
 
Needless to say, this is more complicated (but strangely far easier to 
understand for me). Another solution is to _define_ a new function, recursive, 
inside the outer one which thus keeps a simple interface (no 'i' or 'sub_res'). 
This is very often needed in recursion in functional programming, because we 
need to pass partial data anyway (state of partial execution). In fact, your 
case and mine are not typical. 
 
Thus, if we must define a new function anyway, we have the choice of running 
upwards or 

Re: [Tutor] recursive function example

2013-12-11 Thread ugajin

 
No, not really.
mutl(3, 2) has two arguments
  rest = mult(a, b - 1)  also has two arguments 
but it is passed to value as one argument.
value = a + rest 

But, thanks anyway.

-A

 

 

-Original Message-
From: Mark Lawrence 
To: tutor@python.org
Sent: Wed, 11 Dec 2013 17:38
Subject: Re: [Tutor] recursive function example


On 10/12/2013 14:48, uga...@talktalk.net wrote: 
 
[snipped] 
 
As you're clearly struggling here's my attempt at showing you what is 
happening. 
 
c:\Users\Mark\MyPython>type mytest.py 
level = 0 
 
def mult(a, b): 
global level 
level += 1 
print('level now', level, 'a =', a, 'b =', b) 
if b == 0: 
print('immediate return as b == 0') 
return 0 
print('call mult again') 
rest = mult(a, b - 1) 
print('rest =', rest) 
value = a + rest 
print('value =', value, '(a + rest ==',a, '+', rest,')') 
return value 
mult(3, 2) 
 
c:\Users\Mark\MyPython>mytest.py 
level now 1 a = 3 b = 2 
call mult again 
level now 2 a = 3 b = 1 
call mult again 
level now 3 a = 3 b = 0 
immediate return as b == 0 
rest = 0 
value = 3 (a + rest == 3 + 0 ) 
rest = 3 
value = 6 (a + rest == 3 + 3 ) 
 
c:\Users\Mark\MyPython> 
 
Does this help clarify things for you? 
 
-- My fellow Pythonistas, ask not what our language can do for you, ask what 
you can do for our language. 
 
Mark Lawrence 
 
___ 
Tutor maillist  -  Tutor@python.org 
To unsubscribe or change subscription options: 
https://mail.python.org/mailman/listinfo/tutor 

 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] recursive function example

2013-12-12 Thread ugajin

In a way, it may help to identify the issue
def multiply(a,b) 

 return a*b
clearly returns the product of the two arguments, a and b
I presume it returns a+a rather than b+b+b

mult(a, b-1) also has two arguments.
and rest takes the value of the two arguments, but
I do not see an instruction to multiply the arguments
How in the original def mult(a, b) . . ., 
does mult(a, b-1)  say return the product of a and b-1?





 

 

-Original Message-
From: Alan Gauld 
To: tutor@python.org
Sent: Thu, 12 Dec 2013 0:27
Subject: Re: [Tutor] recursive function example


On 11/12/13 18:09, uga...@talktalk.net wrote: 
> 
> No, not really. 
> mutl(3, 2) has two arguments 
> rest = mult(a, b - 1) also has two arguments 
 
rest does not have any arguments. 
arguments are the values you pass *into* a function. 
The function in turn passes back a return value. 
 
In this case rest is assigned the return value 
from mult(a, b-1) Note that this is an entirely 
*separate* call to mult() from the one in whose 
code it appears. The fact that mult() is calling 
(another copy) of mult() is what makes it recursive. 
 
But the function call is just like any other. 
The first call to mult(3,2) results in another 
call to mult(3,1) but there is no communication 
or connection between those two calls to mult() 
except the arguments passed in (3,1 and the 
value returned, 3. 
 
The outer, calling, mult simply waits for the 
inner call to mult to complete and return its 
value, just like any other function, 
 
Let me put it this way. Lets ignore the fact 
that mult calls mult and define a new function 
called multiply: 
 
def multiply(a,b): 
   return a*b 
 
def mult(a,b): 
   if b == 0: 
 return 0 
   rest = multiply(a, b-1) 
   value = a + rest 
   return value 
 
Can you understand that? 
 
The recursive function works *exactly* like 
that except that instead of calling multiply 
it calls itself. 
 
-- Alan G 
Author of the Learn to Program web site 
http://www.alan-g.me.uk/ 
http://www.flickr.com/photos/alangauldphotos 
 
___ 
Tutor maillist  -  Tutor@python.org 
To unsubscribe or change subscription options: 
https://mail.python.org/mailman/listinfo/tutor 

 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: for: how to skip items

2014-02-17 Thread ugajin

 0, 9, 19, 29, 39, is not every 10th index

If you want to output every 10th. index try:

a100 = list(range(0,100,10))

for a in a100:
 print(a)



 

 

-Original Message-
From: Gabriele Brambilla 
To: python tutor 
Sent: Mon, 17 Feb 2014 16:06
Subject: [Tutor] for: how to skip items


Hi,


I'm wondering how I can (if I can) make a for loop in which I don't use all the 
elements.


for example


a100 = list(range(100))


for a in a100:
 print(a)


it print out to me all the numbers from 0 to 99
But if I want to display only the numbers 0, 9, 19, 29, 39, ...(one every 10 
elements) how can I do it WITHOUT defining a new list (my real case is not so 
simple) and WITHOUT building a list of indexes?


thank you


Gabriele

 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] masking library files

2014-04-09 Thread ugajin

Is it common for files saved to a working directory to 'mask' library files 
located in the Python framework?

-A

 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] masking library files

2014-04-09 Thread ugajin

 Please write in plain English if you want to be understood.

 

 

-Original Message-
From: Dave Angel 
To: tutor@python.org
Sent: Thu, 10 Apr 2014 2:00
Subject: Re: [Tutor] masking library files


uga...@talktalk.net Wrote in message:
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 

A message left in invisible ink.  Please post in text form, not
 html, as html offers too many ways to mess up the message.
 

-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] masking library files

2014-04-10 Thread ugajin


 

-Original Message-
From: Mark Lawrence 
To: tutor@python.org
Sent: Thu, 10 Apr 2014 9:36
Subject: Re: [Tutor] masking library files


On 10/04/2014 02:20, uga...@talktalk.net wrote: 
> Please write in plain English if you want to be understood. 
> 
> 
> -Original Message- 
> From: Dave Angel  
> To: tutor@python.org 
> Sent: Thu, 10 Apr 2014 2:00 
> Subject: Re: [Tutor] masking library files 
> 
> uga...@talktalk.net  Wrote in message: 
 
>> 
> 
> A message left in invisible ink.  Please post in text form, not 
>   html, as html offers too many ways to mess up the message. 
> 
> 
> -- 
> DaveA 
> 
 
Please don't top post on this list.  And don't use language like that if you 
want answers, especially when replying to a highly respected member of this 
community such as Dave. 
 
-- My fellow Pythonistas, ask not what our language can do for you, ask what 
you can do for our language. 
 
Mark Lawrence 
 
--- 
This email is free from viruses and malware because avast! Antivirus protection 
is active. 
http://www.avast.com 
 
___ 
Tutor maillist  -  Tutor@python.org 
To unsubscribe or change subscription options: 
https://mail.python.org/mailman/listinfo/tutor 

Like this?

 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] masking library files

2014-04-10 Thread ugajin




-Original Message-
From: uga...@talktalk.net
To: tutor@python.org
Sent: Thu, 10 Apr 2014 10:17
Subject: Re: [Tutor] masking library files






-Original Message-
From: Mark Lawrence 
To: tutor@python.org
Sent: Thu, 10 Apr 2014 9:36
Subject: Re: [Tutor] masking library files


On 10/04/2014 02:20, uga...@talktalk.net wrote: 

Please write in plain English if you want to be understood. 
 
 
-Original Message- 
From: Dave Angel  
To: tutor@python.org 
Sent: Thu, 10 Apr 2014 2:00 
Subject: Re: [Tutor] masking library files 
 
uga...@talktalk.net  Wrote in message: 

 

 

 
A message left in invisible ink.  Please post in text form, not 
  html, as html offers too many ways to mess up the message. 
 
 
-- 
DaveA 
 

 
Please don't top post on this list.  And don't use language like that
if you want answers, especially when replying to a highly respected
member of this community such as Dave. 
 
-- My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language. 
 
Mark Lawrence 
 
--- 
This email is free from viruses and malware because avast! Antivirus
protection is active. 
http://www.avast.com 
 
___ 
Tutor maillist  -  Tutor@python.org 
To unsubscribe or change subscription options: 
https://mail.python.org/mailman/listinfo/tutor

Like this?



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Sorry, but posting this way does not make sense. The header appears on
top, the message at the foot, buried in multiple footers. It is a mess.

   
___

Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: masking library files

2014-04-10 Thread ugajin

 But I must remember to cc tutor@python.org when replying to you.

 

 

-Original Message-
From: uga...@talktalk.net
To: alan.ga...@btinternet.com
Sent: Thu, 10 Apr 2014 13:15
Subject: Re: [Tutor] masking library files


 
It is off, and I don't appear have an option to turn it on in plain text. I 
have this option, but but only in rich text/html, and as you see it top posts, 
which I quite like.
 


Yes, but delete all the junk such as extraneous headers/footers as 
I did above. It does actually make the conversation much easier to follow than 
top posting. 
 
I appreciate many modern mail tools do top posting as default 
(thanks Microsoft! :-(  ) but for conversations its much easier 
to use inline comments. 
 
For a good, fairly short, balanced, explanation of how it helps, 
see this: 
 
http://en.wikipedia.org/wiki/Posting_style 
 
It helps if you have quoting turned on in your mail tool too - yours doesn't 
seem to be using quotes at present (Quoting means the >>> 
bits in the message above - the number of > characters tells you how far back 
in the conversation it was) 
 
-- Alan G 
Author of the Learn to Program web site 
http://www.alan-g.me.uk/ 
http://www.flickr.com/photos/alangauldphotos 

 

 

 

-Original Message-
From: Alan Gauld 
To: tutor@python.org
Sent: Thu, 10 Apr 2014 12:23
Subject: Re: [Tutor] masking library files


On 10/04/14 10:30, uga...@talktalk.net wrote: 
 
> On 10/04/2014 02:20, uga...@talktalk.net wrote: 
>> Please write in plain English if you want to be understood. 
>> 
>> 
>> -Original Message- 
>> From: Dave Angel  
>> To: tutor@python.org 
>>> 
>> 
>> A message left in invisible ink.  Please post in text form, not 
>>   html, as html offers too many ways to mess up the message. 
>> 
>> 
>> 
> 
> Please don't top post on this list.  And don't use language like that 
> if you want answers, especially when replying to a highly respected 
> member of this community such as Dave. 
> 
> Mark Lawrence 
> 
> 
> Like this? 
 
Yes, but delete all the junk such as extraneous headers/footers as 
I did above. It does actually make the conversation much easier to follow than 
top posting. 
 
I appreciate many modern mail tools do top posting as default 
(thanks Microsoft! :-(  ) but for conversations its much easier 
to use inline comments. 
 
For a good, fairly short, balanced, explanation of how it helps, 
see this: 
 
http://en.wikipedia.org/wiki/Posting_style 
 
It helps if you have quoting turned on in your mail tool too - yours doesn't 
seem to be using quotes at present (Quoting means the >>> 
bits in the message above - the number of > characters tells you how far back 
in the conversation it was) 
 
-- Alan G 
Author of the Learn to Program web site 
http://www.alan-g.me.uk/ 
http://www.flickr.com/photos/alangauldphotos 
 
___ 
Tutor maillist  -  Tutor@python.org 
To unsubscribe or change subscription options: 
https://mail.python.org/mailman/listinfo/tutor 

 
 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] masking library files

2014-04-10 Thread ugajin

I do have a Reply All command, but as in this case, there is no recipient other 
than myself to be included. Also, hitting the Reply All command seems to 
generate an alert warning message, when recipients include a mail-list address, 
and some mail list replies go to the mail-list as recipient rather than the 
sender by default. 
 


I don't know which mail tool you are using but you should have a ReplyAll 
command that does that automatically. 


 

 

 

-Original Message-
From: Alan Gauld 
To: uga...@talktalk.net
Sent: Thu, 10 Apr 2014 16:41
Subject: Re: Fwd: masking library files


On 10/04/14 13:17, uga...@talktalk.net wrote: 
> But I must remember to cc tutor@python.org when replying to you. 
 
I don't know which mail tool you are using but you should have a ReplyAll 
command that does that automatically. 
 
If you are using a Desktop mail tool it may even have a mailing 
list mode that detects lists (or allows you to specify them) 
and auto uses replyall... 
 
Alan g. 
 
> -Original Message- 
> From: uga...@talktalk.net 
> To: alan.ga...@btinternet.com 
> Sent: Thu, 10 Apr 2014 13:15 
> Subject: Re: [Tutor] masking library files 
> 
> 
> It is off, and I don't appear have an option to turn it on in plain 
> text. I have this option, but but only in rich text/html, and as you see 
> it top posts, which I quite like. 
> 
> Yes, but delete all the junk such as extraneous headers/footers as 
> I did above. It does actually make the conversation much easier to 
> follow than top posting. 
> 
> I appreciate many modern mail tools do top posting as default 
> (thanks Microsoft! :-( ) but for conversations its much easier 
> to use inline comments. 
> 
> For a good, fairly short, balanced, explanation of how it helps, 
> see this: 
> 
> http://en.wikipedia.org/wiki/Posting_style 
> 
> It helps if you have quoting turned on in your mail tool too - yours 
> doesn't seem to be using quotes at present (Quoting means the >>> 
> bits in the message above - the number of > characters tells you how 
> far back in the conversation it was) 
> 
> -- Alan G 
> Author of the Learn to Program web site 
> http://www.alan-g.me.uk/ 
> http://www.flickr.com/photos/alangauldphotos 
> 
> 
> 
> 
> -Original Message- 
> From: Alan Gauld  > 
> To: tutor@python.org  
> Sent: Thu, 10 Apr 2014 12:23 
> Subject: Re: [Tutor] masking library files 
> 
> On 10/04/14 10:30, uga...@talktalk.net wrote: 
> 
>  > On 10/04/2014 02:20, uga...@talktalk.net wrote: 
>  >> Please write in plain English if you want to be understood. 
>  >> 
>  >> 
>  >> -Original Message- 
>  >> From: Dave Angel  
>  >> To: tutor@python.org 
>  >>> 
>  >> 
>  >> A message left in invisible ink. Please post in text form, not 
>  >> html, as html offers too many ways to mess up the message. 
>  >> 
>  >> 
>  >> 
>  > 
>  > Please don't top post on this list. And don't use language like that 
>  > if you want answers, especially when replying to a highly respected 
>  > member of this community such as Dave. 
>  > 
>  > Mark Lawrence 
>  > 
>  > 
>  > Like this? 
> 
> Yes, but delete all the junk such as extraneous headers/footers as 
> I did above. It does actually make the conversation much easier to 
> follow than top posting. 
> 
> I appreciate many modern mail tools do top posting as default 
> (thanks Microsoft! :-( ) but for conversations its much easier 
> to use inline comments. 
> 
> For a good, fairly short, balanced, explanation of how it helps, 
> see this: 
> 
> http://en.wikipedia.org/wiki/Posting_style 
> 
> It helps if you have quoting turned on in your mail tool too - yours 
> doesn't seem to be using quotes at present (Quoting means the >>> 
> bits in the message above - the number of > characters tells you how far 
> back in the conversation it was) 
> 
> -- Alan G 
> Author of the Learn to Program web site 
> http://www.alan-g.me.uk/ 
> http://www.flickr.com/photos/alangauldphotos 
> 
> ___ 
> Tutor maillist - Tutor@python.org 
> To unsubscribe or change subscription options: 
> https://mail.python.org/mailman/listinfo/tutor 
> 
> 
> ___ 
> Tutor maillist  -  Tutor@python.org 
> To unsubscribe or change subscription options: 
> https://mail.python.org/mailman/listinfo/tutor 
> 
 
-- Alan G 
Author of the Learn To Program web site 
http://www.alan-g.me.uk 
http://www.flickr.com/photos/alangauldphotos 

 
 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] name error

2014-07-14 Thread ugajin
I am running nodebox 1 on OSX v10.6.8, which is an open source OSX 
Python, 2D data visualiser, and although not legacy, the software it 
isn't well supported. (see http://nodebox.net/code/index.php/Home for 
further info).  I believe nodebox 1, runs with Python 2.5 

 
This may be too specialised a question for the tutor forum, but . . .  
I have posted several e-mails to the nodebox author the first of which 
was almost 3 weeks ago, and although I received an initial  positive 
response, saying he would provide a screen cast to help,  the said 
screencast has not arrived. After, I sent a polite reminder, I received 
a curt if incomplete reply telling me he was now on holiday. 

 
Sometimes it can help, to describe a problem to a 3rd person (real or 
imagined), so here goes (it may have helped a bit, but not enough). 

 
To draw a default rectangle using the nodebox 1, IDE you would simply 
write: rect(0, 0, 100, 100) to a .py file.  When run in nodebox 1, IDE 
it does what you might expect. It renders a 100 x 100 (px) rectangle 
shape, with the top left vertex at the canvas x, y coordinate 0, 0 

 
However, when I try to call the .py file as a module (using the nodebox 
IDE) which is what I am trying to acheive, I get a traceback error 
message e.g. 

# import_test_1.py 
rect(0, 0, 100, 100) 
 
#importer_test_1.py 
import_test_1 
Traceback (most recent call last): 
 File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript 
  File "/Users/apple/Documents/nodeBox/07_10_2014/importer_2.py", line 
2, in  
  File "/Users/apple/Documents/nodeBox/07_10_2014/import_test_2.py", 
line 22, in  

NameError: name 'rect' is not defined 
 
This begins to look like a scope issue. 
 
However, when I execute/run the following command, I get the following 
output 

# import_test_2.py 
print 'dir:', dir() 
 
dir: ['BOOLEAN', 'BUTTON', 'BezierPath', 'CENTER', 'CLOSE', 'CMYK', 
'CORNER', 'CURVETO', 'Canvas', 'ClippingPath', 'Color', 'Context', 
'DEFAULT_HEIGHT', 'DEFAULT_WIDTH', 'FORTYFIVE', 'FRAME', 'Grob', 
'HEIGHT', 'HSB', 'Image', 'JUSTIFY', 'KEY_BACKSPACE', 'KEY_DOWN', 
'KEY_LEFT', 'KEY_RIGHT', 'KEY_UP', 'LEFT', 'LINETO', 'MOUSEX', 
'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'] 

 
This seems to suggest (to me) that there is a class object named Rect 
in the default dir() 
I may not have the correct nomenclature here, is there as default IDE 
dir() module? 

 
Also, when I execute or run the following command, I get: 
print 'dir(Rect):', dir(Rect) 
dir(Rect): ['__call__', '__class__', '__cmp__', '__delattr__', 
'__doc__', '__get__', '__getattribute__', '__hash__', '__init__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__str__', 'im_class', 'im_func', 'im_self'] 

 
Now, I am not sure if this helps, but if I put those two lines of code 
into a file and call the module with the import command, I now get the 
following output:: 

# importer_test_2 
import_test_2 
print 'dir:', dir() 
print 'dir(Rect):', dir(Rect) 
 
dir: ['__builtins__', '__doc__', '__file__', '__name__', 'draw_rect', 
'nodebox'] 

 
dir(Rect):Traceback (most recent call last): 
 File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript 
  File "/Users/apple/Documents/nodeBox/07_10_2014/importer_2.py", line 
2, in  
  File "/Users/apple/Documents/nodeBox/07_10_2014/import_test_2.py", 
line 18, in  

NameError: name 'Rect' is not defined 

Perhaps someone wiser than me, can suggest an approach, or something 
that I might

[Tutor] name error

2014-07-15 Thread ugajin

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
Outputs:
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 
  File "/Users/apple/Documents/nodeBox/06_15_2014/rect_1.py", line 1, 
in 

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', 
'DEFAULT_HEIGHT', 'DEFAULT_WIDTH', 'FORTYFIVE', 'FRAME', 'Grob', 
'HEIGHT', 'HSB', 'Image', 'JUSTIFY', 'KEY_BACKSPACE', 'KEY_DOWN', 
'KEY_LEFT', 'KEY_RIGHT', 'KEY_UP', 'LEFT', 'LINETO', 'MOUSEX', 
'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 
same:

print Rect
#prints: >

print Rect.__name__
# prints: Rect

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

produces:
['BezierPath', 'ClippingPath', 'Color', 'HEIGHT', 'Image', 
'KEY_BACKSPACE', 'KEY_DOWN', 'KEY_LEFT', 'KEY_RIGHT', 'KEY_UP', 'Oval', 
'Rect', '

[Tutor] accessing code for built in min()

2014-07-31 Thread ugajin

How do I look at the code for a python built in function e.g. min()?

Thanks

I am running 2.7.8 on OSX
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing code for built in min()

2014-07-31 Thread ugajin
Thanks Raúl,

T'was the latter two. 

-u

 

 

 

-Original Message-
From: Raúl Cumplido 
To: uga...@talktalk.net
CC: tutor 
Sent: Thu, 31 Jul 2014 10:36
Subject: Re: [Tutor] accessing code for built in min()


Are you asking for the source code? For the CPython implementation, PyPy, 
IronPython, Jhyton?


For the CPython implementation you can go to the repository:
http://hg.python.org/cpython/branches




Builtin implementations in C (for 2.7 version) are in the file:

http://hg.python.org/cpython/file/818989a48e96/Python/bltinmodule.c



If you want to take a look on the min builtin:
http://hg.python.org/cpython/file/818989a48e96/Python/bltinmodule.c#l1435



Thanks,
Raúl




On Thu, Jul 31, 2014 at 9:51 AM,   wrote:

How do I look at the code for a python built in function e.g. min()?

Thanks

I am running 2.7.8 on OSX
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor