Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Sander Sweers
On Sat, Sep 20, 2008 at 00:23, Wayne Watson
<[EMAIL PROTECTED]> wrote:
> Well, it made a difference, and now program and output are in agreement.

Not really the code has an error so it could not have worked.

> updown = +1
> while keyop <> 0:

You forgot to create keyop in this example.

> UnboundLocalError: local variable 'updown' referenced before assignment
> ...
> http://effbot.org/pyfaq/how-do-you-set-a-global-variable-in-a-function.htm

Did you actually read the link Kent provided? It does not look like you did.

Greets
Sander
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Wayne Watson




Yes, I read it and tried the global statement with the same results,
and tried it without the keyop set. It gave a prompt, and died as
before.   Now I've inserted the global statement in the function and
it  works by print out the value of updown inside the function.  Beats
me. (read below) 

I do not think I've made an inaccurate observation. Is it possible the
IDLE shell is leaving something behind that I can't see? Maybe I had
two shell window up at the same time between the real and debug
program. 

I just started from scratch with the debug program minus the keyop set,
and Python discovered it wasn't set. Oh, well. Gads. I just changed the
def function name, and it ran! I now changed the def function name
again, and it ran. Oh, boy. I now have closed all IDLE windows, and
tried the debug again. It catches the misnamed function. Yikes!

I just inserted the global statement in the full program, and it's
working. This was not the case yesterday. I give up trying to explain
this. It works as it should, so I'm going to continue making the mods
before all this happened. 

Sander Sweers wrote:

  On Sat, Sep 20, 2008 at 00:23, Wayne Watson
<[EMAIL PROTECTED]> wrote:
  
  
Well, it made a difference, and now program and output are in agreement.

  
  
Not really the code has an error so it could not have worked.

  
  
updown = +1
while keyop <> 0:

  
  
You forgot to create keyop in this example.

  
  
UnboundLocalError: local variable 'updown' referenced before assignment
...
http://effbot.org/pyfaq/how-do-you-set-a-global-variable-in-a-function.htm

  
  
Did you actually read the link Kent provided? It does not look like you did.

Greets
Sander

  


-- 

Signature.html
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

"Though no one can go back and make a brand new start, 
	 ANYONE can start from now and make a brand new end." 
		-- Anonymous

Web Page: 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] AUTO: James D Mcclatchey is out of the office. (returning 09/29/2008)

2008-09-20 Thread James D Mcclatchey

I am out of the office until 09/29/2008.

I will respond to your message when I return.


Note: This is an automated response to your message  "Tutor Digest, Vol 55,
Issue 63" sent on 9/20/08 3:00:29.

This is the only notification you will receive while this person is away.


*IMPORTANT NOTICE: This communication, including any attachment, contains 
information that may be confidential or privileged, and is intended solely for 
the entity or individual to whom it is addressed.  If you are not the intended 
recipient, you should delete this message and are hereby notified that any 
disclosure, copying, or distribution of this message is strictly prohibited.  
Nothing in this email, including any attachment, is intended to be a legally 
binding signature.
*
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Web programming advice

2008-09-20 Thread Jan Ulrich Hasecke


Am 20.09.2008 um 00:01 schrieb Alan Gauld:



"Patrick" <[EMAIL PROTECTED]> wrote

is of paramount importance. It appears to me that Django is an all- 
in-one monolithic application. Years ago Zope was the number 1 and  
now it's basically gone.


Zope is still around but it has retreated into something of a niche
where it offers its own unique advantages, namely very large,
high volume sites. Zope is, I believe, also the engine underneath
Plone which is in itself something of a niche market content
management system.



Zope has not retreated into a niche, but has heavily evolved from the  
technical point of view in the last years. With the new component  
architecture Zope makes it more easy to develop and maintain huge and  
complex mission-critical webapplications. You can glue your  
applications together either with an explicit configuration language  
called ZCML or within a convention-over-configuration framework  
called Grok. With Grok it is very easy to start Zope development. The  
greates advantage of Zope is beside security, security and security  
the fact that there is a huge library of ready-to-use components to  
develop your custom application. And Zope has an object database,  
with which you can even develop outside Zope.


There are some very huge installations out there and the Zope  
community is still alive.


Plone is not a niche CMS, but the leading Python CMS if not the  
leading Open Source CMS around. This has been stated lately by  
CMSWatch. There is a very vibrant Plone community, which develops and  
maintains Plone. So check it out at http://plone.org


The further development of Zope and Plone is secured and guided by  
the Zope Foundation and the Plone Foundation.


So the answer to the OP is: Try out Grok to start with Zope. It is  
great!


grok.zope.org

Cheers!
juh

--
Business: http://hasecke.com --- Private: http://hasecke.eu --- Blog:  
http://www.sudelbuch.de --- History: www.generationenprojekt.de ---  
Europe: www.wikitution.org


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Alan Gauld



Not really the code has an error so it could not have worked.


updown = +1


Is this meant to be

updown += 1

maybe?

Although as the error message shows you need to set it to a
valid value before incrementing it, so mayber you just meant

updown = 1  # no need for the + sign


while keyop <> 0:


And the <> form of not equal is deprecated in favour of != so
this should probably be

while keyop != 0

Or better still just

while keyop:


You forgot to create keyop in this example.
UnboundLocalError: local variable 'updown' referenced before 
assignment


HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Kent Johnson
On Sat, Sep 20, 2008 at 7:26 AM, Wayne Watson
<[EMAIL PROTECTED]> wrote:

> I do not think I've made an inaccurate observation. Is it possible the IDLE
> shell is leaving something behind that I can't see? Maybe I had two shell
> window up at the same time between the real and debug program.

I'm not too familiar with IDLE but the version I have does have this
behaviour- if I run a program that defines global variables, then the
globals are available in the shell until I run another program. So if
you are switching between running a program and experimenting in the
shell, that may cause you some confusion.

I don't think IDLE preserves variables between runs of a program. When
the shell prints out the "RESTART" line, it is clearing the old
variables.

Whether that is the problem or not, I recommend you find a different
editor or IDE to use; IMO IDLE is quite primitive and there are many
better choices. Check the list archives or the Python wiki for many
suggestions.
http://wiki.python.org/moin/PythonEditors

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Alan Gauld
"Wayne Watson" <[EMAIL PROTECTED]> wrote 

I do not think I've made an inaccurate observation. 
Is it possible the IDLE shell is leaving something 
behind that I can't see? 


That's very possible. The interpreter will remember its 
previous state for as long as its running so if you import 
your module into the shell, say, it will remember it, 
similarly if you try some code out that uses the same 
name as the variable in your script it can confuse the 
interpreter.


That's why, when in doubt, always run your code outside 
of any IDE to find out its true behaviour. IDEs 
(including IDLE) are very useful tools but they can mislead 
as well.



I just inserted the global statement in the full program


I'm not quite sure what you mean by this, but I assume 
you mean you had a simplified version of the problem 
plus the full application code that you were working on?


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pexpect

2008-09-20 Thread James
Folks,

Does anyone here have experience with pexpect? I'm trying to write a
pexpect script which will log into a network device, gather
statistics, and then dump the raw output into a file (or a string so
that I can manipulate it).

I'm not having much luck. Because the connection is telnet I was able
to use wireshark (a sniffer) to see the traffic between my computer
(which is running the pexpect script) and the network device.
Everything seems to go find until I "expect" the network device's
prompt and it just hangs. Eventually pexpect throws an exception and
times out.

I'd be happy to share some code when I get to the computer I've been
testing on. :) In the time being, has anyone seen a problem like this
before?

Thanks!
-j
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Wayne Watson
Title: Signature.html






Alan Gauld wrote:
"Wayne
Watson" <[EMAIL PROTECTED]> wrote 
  I do not think I've made an inaccurate
observation. Is it possible the IDLE shell is leaving something behind
that I can't see? 
  
That's very possible. The interpreter will remember its previous state
for as long as its running so if you import your module into the shell,
say, it will remember it, similarly if you try some code out that uses
the same name as the variable in your script it can confuse the
interpreter.
  
  
That's why, when in doubt, always run your code outside of any IDE to
find out its true behaviour. IDEs (including IDLE) are very useful
tools but they can mislead as well.
  

Good tip. I'll do use as necessary until I complete the program, which
I expect to do today, then move onto something besides IDLE.

  I just inserted the global statement in the
full program

  
  
I'm not quite sure what you mean by this, but I assume you mean you had
a simplified version of the problem plus the full application code that
you were working on?
  

I have the program I'm working on, 600+ lines of code, and the stripped
down version, debug.py, 30 lines, which isolates the problem. The
"full" program is the 600 line keeper. I have had both up in separate
windows trying to figure out what was going on, as I bounced between
them. I don't think it's possible to have both executing. At least, I
hope that wasn't part of the problem. This one sure had me dazed and
confused for ahile. :-) 

HTH,
  
  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

"Though no one can go back and make a brand new start, 
	 ANYONE can start from now and make a brand new end." 
		-- Anonymous

Web Page: 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pexpect

2008-09-20 Thread Steve Poe

James,

I've not used pexpect, but I've done  this on a Cisco switch. I found  
using

time.sleep and read_until of the telnet class to be helpful.

10  tn = telnetlib.Telnet('')
 11 #tn.set_debuglevel(9)
 12 tn.read_until('Username: \xff', 5)
 13 time.sleep(10)
 14 tn.write('\n')
 15 tn.read_until('\r\nPassword: ', 5)
 16 #time.sleep(2)
 17 tn.write('\n')
 18 tn.read_until('#', 5)
 19 tn.write('term len 0 \n')
 20 tn.read_until('#', 5)
 21 tn.write('show version |  i restarted\n')
 22 RouterStartupTimestamp = tn.read_until('#', 2)
 23 tn.read_until('#', 2)
 24 tn.write('show call history voice last 100\n')


HTH,

Steve

On Sep 20, 2008, at 8:43 AM, James wrote:


Folks,

Does anyone here have experience with pexpect? I'm trying to write a
pexpect script which will log into a network device, gather
statistics, and then dump the raw output into a file (or a string so
that I can manipulate it).

I'm not having much luck. Because the connection is telnet I was able
to use wireshark (a sniffer) to see the traffic between my computer
(which is running the pexpect script) and the network device.
Everything seems to go find until I "expect" the network device's
prompt and it just hangs. Eventually pexpect throws an exception and
times out.

I'd be happy to share some code when I get to the computer I've been
testing on. :) In the time being, has anyone seen a problem like this
before?

Thanks!
-j
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Wayne Watson
Title: Signature.html






Kent Johnson wrote:

  On Sat, Sep 20, 2008 at 7:26 AM, Wayne Watson
<[EMAIL PROTECTED]> wrote:

  
  
I do not think I've made an inaccurate observation. Is it possible the IDLE
shell is leaving something behind that I can't see? Maybe I had two shell
window up at the same time between the real and debug program.

  
  
I'm not too familiar with IDLE but the version I have does have this
behaviour- if I run a program that defines global variables, then the
globals are available in the shell until I run another program. So if
you are switching between running a program and experimenting in the
shell, that may cause you some confusion.

I don't think IDLE preserves variables between runs of a program. When
the shell prints out the "RESTART" line, it is clearing the old
variables.
  

I haven't seen that yet, but I should finish the complete program I was
debugging today. After that, I'll look around. Someone suggested, .
Unfortunately, there doesn't seem to be a Consumer Reports of such
programs, complete with consumer (star) ratings, "best buy" choice
[:-)] and rated categories (cars: braking, gas mileage, repair record,
..."). Maybe your link below offers some of that.  

  
Whether that is the problem or not, I recommend you find a different
editor or IDE to use; IMO IDLE is quite primitive and there are many
better choices. Check the list archives or the Python wiki for many
suggestions.
http://wiki.python.org/moin/PythonEditors

Kent

  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

"Though no one can go back and make a brand new start, 
	 ANYONE can start from now and make a brand new end." 
		-- Anonymous

Web Page: 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Wayne Watson
Title: Signature.html




Going back to the idea of just running the program outside of IDLE, I
just tried it, but, once the program ends (or dies?), the DOS-like
window disappears. How does one prevent that? Is there some way to keep
a window open with all that has been entered and the results? My
program has no GUI. The UI is all text prompts.
...

  
while keyop != 0
  
  
Or better still just
  
  
while keyop:
  
  
  You forgot to create keyop in this example.

UnboundLocalError: local variable 'updown'
referenced before assignment
  

  
  
HTH,
  
  
  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

"Though no one can go back and make a brand new start, 
	 ANYONE can start from now and make a brand new end." 
		-- Anonymous

Web Page: 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Wayne Watson
Title: Signature.html




Ah, the +1 is to add clarity to the program. updown is either 1, or -1,
or, better in this case, as +1 or -1. It's quite possible the code will
be read by others eventually. I'm emphasizing the purpose of the
variable by reminding the reader of its significance. Plus is
associated with moving forward along a line, and negative in the order
direction. 

I suppose this is similar to something I did long ago for a program
that I called p, just one letter. A colleague who was working with me
asked why I did that. It takes one key stroke to execute it was my
answer. When it got out of development, I gave it a more fitting name.
It also kept it easily visible from other programs and files in my
folder when I was looking for it. I suspect I really called it a.

Yes, variations on !=, <>, not equal, .ne., ... Just a hold over
from former languages. 

Alan Gauld wrote:

  Not really the code has an error so it could
not have worked.


updown = +1
  

  
  
Is this meant to be
  
  
updown += 1
  
  
maybe?
  
  
Although as the error message shows you need to set it to a
  
valid value before incrementing it, so mayber you just meant
  
  
updown = 1  # no need for the + sign
  
  
  
while keyop <> 0:
  

  
  
And the <> form of not equal is deprecated in favour of != so
  
this should probably be
  
  
while keyop != 0
  
  
Or better still just
  
  
while keyop:
  
  
  You forgot to create keyop in this example.

UnboundLocalError: local variable 'updown'
referenced before assignment
  

  
  
HTH,
  
  
  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

"Though no one can go back and make a brand new start, 
	 ANYONE can start from now and make a brand new end." 
		-- Anonymous

Web Page: 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] __init__ arguments storage

2008-09-20 Thread Rob Kirkpatrick
Hi All,

In between an object's creation and call to __init__, where are the __init__
arguments stored?  Is there a class dictionary that init uses to initialize
the instance?  I tried printing Class.__init__, but they aren't in there.

The reason I ask is that I was trying to track down a bug where it looked
like an argument was being mis-passed and I wanted to use pdb to see how it
was handled pre- and post-init.

Cheers,
Rob
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Alan Gauld


"Wayne Watson" <[EMAIL PROTECTED]> wrote 

tried it, but, once the program ends (or dies?), the DOS-like 
window disappears. How does one prevent that? 


Another newbie gotcha! :-)

You'll find a more detailed discussion within my 
Add some Style topic in my tutorial, but the 
simplest answer is add a line like



raw_input('Hit Enter to Quit')

at the end of the program


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __init__ arguments storage

2008-09-20 Thread Alan Gauld


"Rob Kirkpatrick" <[EMAIL PROTECTED]> wrote

In between an object's creation and call to __init__, where are the 
__init__
arguments stored?  Is there a class dictionary that init uses to 
initialize
the instance?  I tried printing Class.__init__, but they aren't in 
there.


I haven't checked Pythons source code but most languasges
hold the arguments to functions on the stack. So when the
function gets called it just pops them off the stack into local
variables.

The reason I ask is that I was trying to track down a bug where it 
looked
like an argument was being mis-passed and I wanted to use pdb to see 
how it

was handled pre- and post-init.


I think you can safely assume that Python is passing your variables
from the Class creation call to the init method OK. Any such problems
would have been picked up and fixed a long time ago.

However there are some oddities around default values so if thats the
case with your parameters then you might see some behaviour you
don't expect.

Can you write a short puiece of code that reproduces the problem?
Then we might be able to offer more specific help.


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Exiting a PyGTK main loop

2008-09-20 Thread Chris Fuller

Defer the quit until the mainloop is running again.  something like
self.connect('event-after', gtk.main_quit)

Cheers

On Friday 19 September 2008 17:16, Bart Cramer wrote:
> Dear all,
>
> I am a bit stuck in a small project, trying to quit a PyGTK program.
> Here are some relevant snippets:
>
>   def init_gui (self) :
>
>   self.window = gtk.Window (gtk.WINDOW_TOPLEVEL)
>
>   self.window.connect ("delete_event", self.delete_event)
>   self.window.connect ("destroy", self.destroy)
>
>   def delete_event(self, widget, event, data=None) :
>   return False
>
>   def destroy(self, widget, data=None) :
>   gtk.main_quit()
>
> Seems pretty standard so far... Now, I want the following: if a
> certain condition has been met (categories run out...), the program
> should quit, exit status 0.
>
>   if len(categories) == 0 :
>   gtk.main_quit()
>
> The error message I get is the following:
>
> RuntimeError: called outside of a mainloop
>
> So I suppose that I should send a signal or event to the main loop,
> which will terminate it by some magic on its own. But how do I do
> that?
>
> Thanks in advance for your time!
>
> Bart.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __init__ arguments storage

2008-09-20 Thread Kent Johnson
On Sat, Sep 20, 2008 at 1:32 PM, Rob Kirkpatrick
<[EMAIL PROTECTED]> wrote:
> Hi All,
>
> In between an object's creation and call to __init__, where are the __init__
> arguments stored?  Is there a class dictionary that init uses to initialize
> the instance?  I tried printing Class.__init__, but they aren't in there.

No, there is no class dictionary like this. The arguments are stored
as ordinary function call parameters.

This message and the followup give a pretty good overview of what
happens when you create a new class instance:
http://mail.python.org/pipermail/python-list/2005-November/349806.html

The implementation of this is in the __call__() method of the
metaclass of the class being created. Normally this is 'type'. If you
want the gory details, the implementation of type.__call__() is in the
type_call() function of typeobject.c.
http://svn.python.org/view/python/trunk/Objects/typeobject.c?rev=66043&view=auto

> The reason I ask is that I was trying to track down a bug where it looked
> like an argument was being mis-passed and I wanted to use pdb to see how it
> was handled pre- and post-init.

Show us the code...it's unlikely that this is a problem with the interpreter.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Wayne Watson
Title: Signature.html




Thanks. Still much to learn.
Where is your tutorial?

Alan Gauld wrote:

"Wayne Watson" <[EMAIL PROTECTED]>
wrote 
  tried it, but, once the program ends (or
dies?), the DOS-like window disappears. How does one prevent that? 
  
Another newbie gotcha! :-) 
  
You'll find a more detailed discussion within my Add some Style topic
in my tutorial, but the simplest answer is add a line like 
  
  
raw_input('Hit Enter to Quit') 
  
at the end of the program 
  
  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

"Though no one can go back and make a brand new start, 
	 ANYONE can start from now and make a brand new end." 
		-- Anonymous

Web Page: 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] a simple keyboard art,,, gone wrong!

2008-09-20 Thread Johnny




I am a beginner programmer.
I was trying to get this keyboard art to work in Idle

I created it in Script mode, and it looks perfect. When I "copy &
paste" it to 
try it in interactive mode, it is all scrabbled. See below for the mess
up view.
It suspose to say simply, "Game Over"


print \
  """
 _   ___   ___  ___  _
/  ___| /   | /   |/   |    |  ___|
| |    / /| |    / /|   /| |    | |__
| |  _    / __| |   / / |__/ | |    |  __|
| |_| |  / /  | |  / /   | |    | |___   
\_/ /_/   |_| /_/    |_|    |_|

 _   _ __   __    _
/  _  \ | |   / /  |  |  |  _  \
| | | | | |  / /   | |__ | |_| |
| | | | | | / /    |  __|    |  _  /
| |_| | | |/ / | |   | | \ \
\_/ |___/  |__|  |_|  \_\

"""




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __init__ arguments storage

2008-09-20 Thread Rob Kirkpatrick
Thanks Kent!  That really makes it clear now.

The bug I ran into was a while back and I've since ignored it to the point
of forgetting how to invoke it, but I remember the stack trace said
something about "variable received multiple arguments".  I wanted to check
the arguments to see if the same variable was being passed twice, and if so,
which one was being used.

The whole issue of how the class call stored the init args was keeping me up
at night even though I didn't care about the original error anymore.  It
bugged me enough, I posted and true to form got an awesome (and very quick)
reply.

Thanks again!

Rob


On Sat, Sep 20, 2008 at 12:44 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:

> On Sat, Sep 20, 2008 at 1:32 PM, Rob Kirkpatrick
> <[EMAIL PROTECTED]> wrote:
> > Hi All,
> >
> > In between an object's creation and call to __init__, where are the
> __init__
> > arguments stored?  Is there a class dictionary that init uses to
> initialize
> > the instance?  I tried printing Class.__init__, but they aren't in there.
>
> No, there is no class dictionary like this. The arguments are stored
> as ordinary function call parameters.
>
> This message and the followup give a pretty good overview of what
> happens when you create a new class instance:
> http://mail.python.org/pipermail/python-list/2005-November/349806.html
>
> The implementation of this is in the __call__() method of the
> metaclass of the class being created. Normally this is 'type'. If you
> want the gory details, the implementation of type.__call__() is in the
> type_call() function of typeobject.c.
>
> http://svn.python.org/view/python/trunk/Objects/typeobject.c?rev=66043&view=auto
>
> > The reason I ask is that I was trying to track down a bug where it looked
> > like an argument was being mis-passed and I wanted to use pdb to see how
> it
> > was handled pre- and post-init.
>
> Show us the code...it's unlikely that this is a problem with the
> interpreter.
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Web programming advice

2008-09-20 Thread Chris Calloway


On Sep 20, 2008, at 7:51 AM, Jan Ulrich Hasecke wrote:

Am 20.09.2008 um 00:01 schrieb Alan Gauld:

"Patrick" <[EMAIL PROTECTED]> wrote

is of paramount importance. It appears to me that Django is an all- 
in-one monolithic application. Years ago Zope was the number 1 and  
now it's basically gone.


Zope is still around but it has retreated into something of a niche
where it offers its own unique advantages, namely very large,
high volume sites. Zope is, I believe, also the engine underneath
Plone which is in itself something of a niche market content
management system.



Zope has not retreated into a niche, but has heavily evolved from  
the technical point of view in the last years.

[snip]
Plone is not a niche CMS, but the leading Python CMS if not the  
leading Open Source CMS around.

[snip]
So the answer to the OP is: Try out Grok to start with Zope. It is  
great!



I'm so glad Jan wrote that so I didn't have to.

--
Sincerely,

Chris Calloway
http://www.secoora.org
office: 332 Chapman Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Local Unbound Mystery

2008-09-20 Thread Alan Gauld


"Wayne Watson" <[EMAIL PROTECTED]> wrote 


Signature.htmlThanks. Still much to learn.
Where is your tutorial?


see the .sig...

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a simple keyboard art,,, gone wrong!

2008-09-20 Thread Alan Gauld


"Johnny" <[EMAIL PROTECTED]> wrote 


I was trying to get this keyboard art to work in Idle


Remember that keyboard (aka ASCII) art relies on a monospaced font.
Which font are you using to compose? And which in the shell window?

HTH,

Alan G

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] array and dictionary

2008-09-20 Thread Dinesh B Vadhia
Hi!  Say, I've got a numpy array/matrix of the form:

[[1 6 1 2 3]
 [4 5 4 7 0]
 [2 0 8 0 2]
 [8 2 6 3 0]
 [0 7 0 3 5]
 [8 0 3 0 6]
 [8 0 0 2 2]
 [3 1 0 4 0]
 [5 0 8 0 0]
 [2 1 0 5 6]]

And, I want to create a dictionary of rows (as the keys) mapped to lists of 
non-zero numbers in that row ie.

dictionary_non-zeros = {
0: [1 6 1 2 3]
1: [4 5 4 7]
2: [2 8 2]
...
9: [2 1 5 6]
}

How do I do this?

Thanks!

Dinesh
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] array and dictionary

2008-09-20 Thread Shantanoo Mahajan (शंत नू महा जन)

Straight forward method would be...

>>> a=[[1],[2]]
>>> b={}
>>> for x in range(len(a)):
... b[x] = a[x]
...
>>> a
[[1], [2]]
>>> b
{0: [1], 1: [2]}
>>>

regards,
shantanoo

On 21-Sep-08, at 11:36 AM, Dinesh B Vadhia wrote:


Hi!  Say, I've got a numpy array/matrix of the form:

[[1 6 1 2 3]
 [4 5 4 7 0]
 [2 0 8 0 2]
 [8 2 6 3 0]
 [0 7 0 3 5]
 [8 0 3 0 6]
 [8 0 0 2 2]
 [3 1 0 4 0]
 [5 0 8 0 0]
 [2 1 0 5 6]]

And, I want to create a dictionary of rows (as the keys) mapped to  
lists of non-zero numbers in that row ie.


dictionary_non-zeros = {
0: [1 6 1 2 3]
1: [4 5 4 7]
2: [2 8 2]
...
9: [2 1 5 6]
}

How do I do this?

Thanks!

Dinesh

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor