<font color='black' size='2' face='arial'><FONT face="Arial, Helvetica, sans-serif"></FONT><br>
<br>


<div style="CLEAR: both"></div>
<br>
<br>


<div style="FONT-FAMILY: arial,helvetica; COLOR: black; FONT-SIZE: 10pt">-----Original Message-----<br>
From: tutor-request &lt;tutor-request@python.org&gt;<br>
To: tutor &lt;tutor@python.org&gt;<br>
Sent: Fri, Dec 10, 2010 6:33 pm<br>
Subject: Tutor Digest, Vol 82, Issue 45<br>
<br>


<div style="BACKGROUND-COLOR: #fff; MARGIN: 0px; FONT-FAMILY: Tahoma, Verdana, Arial, Sans-Serif; COLOR: #000; FONT-SIZE: 12px" id=AOLMsgPart_0_3e8165ce-a156-4e4e-a526-42db6766f8c7><PRE style="FONT-SIZE: 9pt"><TT>Send Tutor mailing list submissions to
        <A href="mailto:tutor@python.org">tutor@python.org</A>

To subscribe or unsubscribe via the World Wide Web, visit
        <A href="http://mail.python.org/mailman/listinfo/tutor" target=_blank>http://mail.python.org/mailman/listinfo/tutor</A>
or, via email, send a message with subject or body 'help' to
        <A href="mailto:tutor-request@python.org">tutor-request@python.org</A>

You can reach the person managing the list at
        <A href="mailto:tutor-owner@python.org">tutor-owner@python.org</A>

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

   1. Re: role playing game - help needed (ALAN GAULD)
   2. Re: Writing to the terminal? (Alan Gauld)
   3. Re: Globals as variables in a tkinter widget (Alan Gauld)
   4. Re: the "**" operator? (Alex Hall)
   5. Code evaluation inside of string fails with __get_item
      (Tim Johnson)


----------------------------------------------------------------------

Message: 1
Date: Fri, 10 Dec 2010 23:21:22 +0000 (GMT)
From: ALAN GAULD &lt;<A href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</A>&gt;
To: Al Stern &lt;<A href="mailto:albstern@gmail.com">albstern@gmail.com</A>&gt;
Cc: "<A href="mailto:tutor@python.org">tutor@python.org</A>" &lt;<A href="mailto:tutor@python.org">tutor@python.org</A>&gt;
Subject: Re: [Tutor] role playing game - help needed
Message-ID: &lt;<A href="mailto:448643.14907.qm@web86708.mail.ird.yahoo.com">448643.14907.qm@web86708.mail.ird.yahoo.com</A>&gt;
Content-Type: text/plain; charset="utf-8"



Thanks again Alan.  Much clearer now.  One final part I don't understand.
&gt; 
&gt;&gt;&gt;&gt; "%d is the result of %d + %d" % (6+7,6,7)
&gt; 
&gt;I understand (I think) the 6+7 part but why the ,6,7 after that.  I could 
&gt;see how either '6+7' or '6,7' would be the correct format but not both.

The format string has 3 percent markers - all numbers.
It is therefore expecting 3 values, so I have to give it them.
The first marker gets 6+7, ie 13. The second gets 6 
the third 7...

Look at the first example in the loops topic in my tutorial.
It uses variables in the same way rather than literal values, 
that might make it more obvious. Maybe :-)
 HTH,

Alan G.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: &lt;<A href="http://mail.python.org/pipermail/tutor/attachments/20101210/a7647551/attachment-0001.html" target=_blank>http://mail.python.org/pipermail/tutor/attachments/20101210/a7647551/attachment-0001.html</A>&gt;

------------------------------

Message: 2
Date: Fri, 10 Dec 2010 23:42:56 -0000
From: "Alan Gauld" &lt;<A href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</A>&gt;
To: <A href="mailto:tutor@python.org">tutor@python.org</A>
Subject: Re: [Tutor] Writing to the terminal?
Message-ID: &lt;idudu0$n0d$<A href="mailto:1@dough.gmane.org">1@dough.gmane.org</A>&gt;
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
        reply-type=original


"Modulok" &lt;<A href="mailto:modulok@gmail.com">modulok@gmail.com</A>&gt; wrote

&gt; Assume I'm working in a command shell on a terminal. Something like
&gt; tcsh on xterm, for example. I have a program which does *something*.
&gt; Let's say it counts down from 10. How do I print a value, and then
&gt; erase that value, replacing it with another value?

This is one of those things that sounds like it should be easy but is 
in
fact deceptively difficult to get right!

It all  depends on your terminal, and there are dozens of different 
terminal
types and settings. Thats why Unix has a terminfo (or in some Unices
termcap - even they can't agree! :-) library to define the different 
terminal
types and try to bring some sanity to proceedings.But you need to
learn the basic terminal control codes.

In this case you need the backspace code which is Ctrl-H or chr(8).

Try this

&gt;&gt;&gt; print "spam" + "chr(8)*2+"ear"

If your terminal recognises chr(8) as backspace you should
see "spear". If it doesn't you'll see someting like:

spam^h^hear

The only foolproof way to do this kind of thing is to use a library 
like
curses which allows you to positioon the cursor and overwrite whatever
was there. But curses is non-trivial to use - not ridiculously hard, 
but
non trivial.

You can get a basic intro to curses in the event-driven topic
of my tutorial.

BTW there is quite a good writeup on terminfo here:
<A href="http://tldp.org/HOWTO/Text-Terminal-HOWTO-16.html" target=_blank>http://tldp.org/HOWTO/Text-Terminal-HOWTO-16.html</A>
and, as usual, Wikipedia has a fair writeup.

-- 
Alan Gauld
Author of the Learn to Program web site
<A href="http://www.alan-g.me.uk/" target=_blank>http://www.alan-g.me.uk/</A>




------------------------------

Message: 3
Date: Sat, 11 Dec 2010 00:06:19 -0000
From: "Alan Gauld" &lt;<A href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</A>&gt;
To: <A href="mailto:tutor@python.org">tutor@python.org</A>
Subject: Re: [Tutor] Globals as variables in a tkinter widget
Message-ID: &lt;iduf9s$rt9$<A href="mailto:1@dough.gmane.org">1@dough.gmane.org</A>&gt;
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
        reply-type=original


&lt;<A href="mailto:echowit@aol.com">echowit@aol.com</A>&gt; wrote

&gt; This code produces a good run.

Not sure what you mean by that. What is "a good run"?

&gt; from tkinter import *
&gt; root = Tk()
&gt; class Application(Frame):
&gt;     global sv, Ptype, PtypeI, sel_rate_label, label

This is bizarre.
Globals are generally considered evil and to be avoided if possible.
One way to avoid globals is to use classes.
So why on earth are you trying to introduce globals ionto a class?
What do you think you will achieve that using class variables can't?

&gt;     label = Label(root)
&gt;     Ptype = 999
&gt;    PtypeI = IntVar()
&gt;    W = 5
&gt;     Y = 4

And in fact most of these should probably be instance
variables defined within your init() method...


    def sel(self):
        global W
        global Y
        Ptype = PtypeI.get()
        if Ptype &lt;= 333: print('\nResulting Values:', 
PtypeI.get(),Ptype)
        else: print('Ptype Failure:',PtypeI.get())
        print('Ptype Completed',Ptype,'\n')
        V = 2
        X = 3
        Z = X * 2
        W = X + 6
        Y = V ** 2
        U = W * Y
        print("V: ",V," X: ",X," Z: ",Z," W: ",W," Y: ",Y," U: 
",U,'\n')
        return

Mixing print statements and GUIS is valid for debugging,
but these don't look like debnug statements... Are you sure
you want these appearing in the console rather than the GUI?

    def __init__(self,master=None):
        Frame.__init__(self)

You might want to pass the master in to Frame too...

        self.pack()
        sel_rate_label = Label(self)
        sel_rate_label.config(text = '\nSelect Goats Personality 
Type',)
        sel_rate_label.pack(anchor=N)
        MODES = [
            ("1 Below Average", 000), ("2 Average", 111),
            ("3 Above Average", 222), ("4 Super Star", 333),
        ]
        for text, mode in MODES:
            b = Radiobutton(self, text=text,
                        variable=PtypeI, value=mode, command = 
self.sel)
            b.pack(anchor=W)
        label.pack()

Why use the global label here when you use the instance
level labels elsewhere? Especially as you don't appear to use it?

&gt; Resulting Values: 333 333
&gt; Ptype Completed 333
&gt; Exception in Tkinter callback
&gt; Traceback (most recent call last):
&gt;   File "C:\Python31\lib\tkinter\__init__.py", line 1399, in __call__
&gt;     return self.func(*args)
&gt;   File "C:\Larry\FCGCF\GPDB\Dev\EX_OK.py", line 18, in sel
&gt;     U = W * Y
&gt; TypeError: can't multiply sequence by non-int of type 'str'

It seems to think that Y is a string.
Your code suggests Y is V**2 or 4.
Can you insertt a print statement just before the offending
line to find out what W and Y are at that exact point?

&gt; My goal is to I learnto use a global variable as an argument inside 
&gt; a widget function,

Why do you think that will be useful?
What do you think you can do with globals that you can't do with
class or instance variables?

&gt; My Question is: Anybody know of some good on-line documentation
&gt; about using GUIs to do more than say 'Hello World'?

There are a lot of GUI tutorials, some even use Tkinter.
Even my tutorial includes the GUI in the case study and the event 
driven
programming topics as well as the GUI topic itself. They don;t go far
beyond hello world but they do take at least one step further.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
<A href="http://www.alan-g.me.uk/" target=_blank>http://www.alan-g.me.uk/</A>

<FONT size=2></FONT>
<FONT size=2>Thanks for the speedy and thorough response.</FONT></TT></PRE><PRE style="FONT-SIZE: 9pt"><TT><FONT size=2>I'm brand new to Python and was trying old, lazy C+ tricks, I guess.</FONT></TT></PRE><PRE style="FONT-SIZE: 9pt"><TT><FONT size=2>Am going to take your advice, try to do it right and see what happens.</FONT></TT></PRE><PRE style="FONT-SIZE: 9pt"><TT><FONT size=2>'preciate the code examples and the link, checked it out &amp; like its style, anyway.</FONT></TT></PRE><PRE style="FONT-SIZE: 9pt"><TT><FONT size=2>Thanks again,</FONT></TT></PRE><PRE style="FONT-SIZE: 9pt"><TT><FONT size=2>Larry </FONT>
------------------------------

Message: 4
Date: Fri, 10 Dec 2010 19:26:52 -0500
From: Alex Hall &lt;<A href="mailto:mehgcap@gmail.com">mehgcap@gmail.com</A>&gt;
To: Hugo Arts &lt;<A href="mailto:hugo.yoshi@gmail.com">hugo.yoshi@gmail.com</A>&gt;
Cc: <A href="mailto:tutor@python.org">tutor@python.org</A>
Subject: Re: [Tutor] the "**" operator?
Message-ID:
        &lt;<A href="mailto:AANLkTinSxhkmL+yCAVKwBHz8doPaYqb9gq57JQLUo0Wd@mail.gmail.com">AANLkTinSxhkmL+yCAVKwBHz8doPaYqb9gq57JQLUo0Wd@mail.gmail.com</A>&gt;
Content-Type: text/plain; charset=ISO-8859-1

Thanks all! I thought update() would add an item even if it would be a
duplicate, but apparently not. I also now better understand why I am
always passing around *args and **kwargs when calling super(). Very
interesting...

On 12/10/10, Hugo Arts &lt;<A href="mailto:hugo.yoshi@gmail.com">hugo.yoshi@gmail.com</A>&gt; wrote:
&gt; On Fri, Dec 10, 2010 at 8:14 PM, Alex Hall &lt;<A href="mailto:mehgcap@gmail.com">mehgcap@gmail.com</A>&gt; wrote:
&gt;&gt; Hi all,
&gt;&gt; I was googling a way to do something like
&gt;&gt; mydict=mydict.extend(additionaldict)
&gt;&gt;
&gt;
&gt; mydict.update(additionaldict)
&gt;
&gt; see also:
&gt; <A href="http://docs.python.org/library/stdtypes.html#dict.update" target=_blank>http://docs.python.org/library/stdtypes.html#dict.update</A>
&gt;
&gt;&gt; and someone on a forum recommends this:
&gt;&gt; mydict=dict(mydict, **additionaldict)
&gt;&gt; What is the ** doing here? I tried to look it up, but Google seems to
&gt;&gt; ignore it since it is punctuation. The poster on the forum says it
&gt;&gt; will put all elements of additionaldict in mydict that are not already
&gt;&gt; in mydict, which is the behavior I am looking for, but I am not sure
&gt;&gt; why this would be so. TIA.
&gt;&gt;
&gt;
&gt; The * and **, when calling functions, are what's called extended
&gt; calling syntax. It's a bit hard to explain, so I'm going to do a sort
&gt; of clarify by example here:
&gt;
&gt;&gt;&gt;&gt; def f(a, b, c):
&gt; ...     print a, b, c
&gt; ...
&gt;&gt;&gt;&gt; f(1, 2, 3)
&gt; 1 2 3
&gt;&gt;&gt;&gt; a = [1, 2, 3]
&gt;&gt;&gt;&gt; f(*a)
&gt; 1 2 3
&gt;&gt;&gt;&gt; b = {'a': 2, 'b': 1, 'c': 3}
&gt;&gt;&gt;&gt; f(*b)
&gt; a c b
&gt;&gt;&gt;&gt; f(**b)
&gt; 2 1 3
&gt;
&gt; In short, if a = [1, 2, 3], f(*a) is the same as f(1, 2, 3). if b =
&gt; {'a': 2, 'b': 1, 'c': 3}, then f(**b) is the same as f(a=2, b=1, c=3).
&gt;
&gt; The * will iterate over its argument, and supply the resulting values
&gt; as arguments to the function (iterating over a dict will return its
&gt; keys, which is what you see with f(*b) here). ** requires a mapping
&gt; type, and supplies the keys and values to the function as keyword
&gt; arguments.
&gt;
&gt; * and ** are very flexible, and you can use them alongside with
&gt; regular arguments:
&gt;
&gt;&gt;&gt;&gt; f(1, *[2, 3])
&gt; 1 2 3
&gt;&gt;&gt;&gt; f(1, **{'b': 2, 'c': 3})
&gt; 1 2 3
&gt;
&gt; * and ** also have uses in function definition, where they sort of do
&gt; the reverse. They can capture any number of regular or keyword
&gt; arguments in a tuple or dictionary:
&gt;
&gt;&gt;&gt;&gt; def f(*args, **kwargs):
&gt; ...     print args, kwargs
&gt; ...
&gt;&gt;&gt;&gt; f()
&gt; () {}
&gt;&gt;&gt;&gt; f(1, 2, 3)
&gt; (1, 2, 3) {}
&gt;&gt;&gt;&gt; f(1, 2, 3, a=4, b=5)
&gt; (1, 2, 3) {'a': 4, 'b': 5}
&gt;&gt;&gt;&gt; f(a=4, b=5)
&gt; () {'a': 4, 'b': 5}
&gt;
&gt; Like with function calls, you can mix up regular arguments and */**
&gt; arguments, as long as the resulting function is unambiguous:
&gt;
&gt;&gt;&gt;&gt; def f(a, *args, **kwargs):
&gt; ...     print a, args, kwargs
&gt; ...
&gt;&gt;&gt;&gt; f()
&gt; Traceback (most recent call last):
&gt;   File "&lt;stdin&gt;", line 1, in &lt;module&gt;
&gt; TypeError: f() takes at least 1 argument (0 given)
&gt;&gt;&gt;&gt; f(1)
&gt; 1 () {}
&gt;&gt;&gt;&gt; f(1, 2, 3)
&gt; 1 (2, 3) {}
&gt;&gt;&gt;&gt; f(1, 2, 3, b=4, c=5)
&gt; 1 (2, 3) {'c': 5, 'b': 4}
&gt;


-- 
Have a great day,
Alex (msg sent from GMail website)
<A href="mailto:mehgcap@gmail.com">mehgcap@gmail.com</A>; <A href="http://www.facebook.com/mehgcap" target=_blank>http://www.facebook.com/mehgcap</A>


------------------------------

Message: 5
Date: Fri, 10 Dec 2010 15:24:52 -0900
From: Tim Johnson &lt;<A href="mailto:tim@johnsons-web.com">tim@johnsons-web.com</A>&gt;
To: <A href="mailto:tutor@python.org">tutor@python.org</A>
Subject: [Tutor] Code evaluation inside of string fails with
        __get_item
Message-ID: &lt;<A href="mailto:20101211002452.GB3380@johnsons-web.com">20101211002452.GB3380@johnsons-web.com</A>&gt;
Content-Type: text/plain; charset=us-ascii

I'm using Python 2.6.5.
The following problem is coming from inside of a complex code base
and involves an implementation that I have used for years, and is
now failing to execute in certain conditions.
This problem occurs with either of the follow two classes, which are
'lifted' from 'Python Cookbook'. Class code follows:
class Eval:
    def __init__(self, globals=None, locals=None):
        self.globals = globals or {}
        self.locals = locals or None

    def __getitem__(self, key):
        if self.locals is None:
            self.locals = sys._getframe(1).f_locals
        key = key % self
        return eval(key, self.globals, self.locals)
## and this one:
class Evalx: 
        def __init__(self, localvals = None, globalvals = None):
                if localvals is None : 
                        self.locals = sys._getframe(1).f_locals
                else : 
                        self.locals = locals
                if globalvals is None : 
                        self.globals = sys._getframe(1).f_globals
                else : 
                        self.globals = globals
        def __getitem__(self,key):
                return eval(key,self.globals,self.locals)
## either are used the same way: To evaluate code inside of a string
## A larger description can be found at:
## <A href="http://code.activestate.com/recipes/66018-evaluating-code-inside-strings/" target=_blank>http://code.activestate.com/recipes/66018-evaluating-code-inside-strings/</A>
The execution looks like this:
self.content = formatted_string % Evalx()
## where 'self' refers to an object of another class, that uses the
## Eval class 
Under certain circumstances, the embedded is code *not* executed. 
By inserting debugging stubs, I can see that the the Eval/Evalx instantiation
does occur, but the overloaded function call to __get_item does
*not* occur. I have also found that a seemingly unrelated event having
to do with file I/O must be causing a side effect. However, to keep
things simple, I am first asking the following question:
What would cause __get_item__ not to be called? I can confirm by
other testing that the embedded codde is properly composed with
matching keywords.

This is probably the most difficult to resolve problem I've ever run
into in python. My lack of understand of the underlying code in the
Eval classes is probably a contributing factor. 

TIA
-- 
Tim 
tim at johnsons-web.com or akwebsoft.com
<A href="http://www.akwebsoft.com/" target=_blank>http://www.akwebsoft.com</A>


------------------------------

_______________________________________________
Tutor maillist  -  <A href="mailto:Tutor@python.org">Tutor@python.org</A>
<A href="http://mail.python.org/mailman/listinfo/tutor" target=_blank>http://mail.python.org/mailman/listinfo/tutor</A>


End of Tutor Digest, Vol 82, Issue 45
*************************************

</TT></PRE></div>
<!-- end of AOLMsgPart_0_3e8165ce-a156-4e4e-a526-42db6766f8c7 --></div>
</font>