ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
RE: [Tutor] Help with the technique "Menu Processing"
by Andrew Wilkins other posts by this author
Apr 29 2001 9:05PM messages near this date
[Tutor] Help with the technique "Menu Processing" | [Tutor] determining whether a set is a group
Hi Juno,

What you need to do is set up the class so...

1) Each method's first argument is self. self refers to the instance itself,
if you don't know.

eg.
>  	def send_priv_msg(connection, nick, text):
>  		... send code ..
should be:
def send_priv_msg(self,connection,nick,text):
	blah blah blah

2) The msgtype dictionary's values should have self before the variables, to
tell python to look in the instance's own namespace.

eg.
>  		self.msgtype = {"priv":send_priv_msg,
should be:
self.msgtype={"priv":self.send_priv_msg, #and so on...

Now when you call them, it should be fine and dandy!

def send_msg_by(connection, nick, text, type):
>  		self.msgtype[type](connection, nick, text)

*looks puzzled*
You had it right in that one! =)

Hope you can understand my badly written attempt at helping...

Andrew

>  -----Original Message-----
>  From: tutor-admin@[...].org [mailto:tutor-admin@[...].org]On Behalf Of
>  juno@[...].com
>  Sent: Sunday, 29 April 2001 4:31 PM
>  To: tutor@[...].org
>  Subject: [Tutor] Help with the technique "Menu Processing"
> 
> 
>  Hi Everyone,
>  I was wondering if I might be able to get some help with "Menu
>  Processing".
>  What I'm looking for is an example of how it might be done within
>  an object.
>  I've been trying myself, but I keep getting an error.
> 
>  Here's an example of what I'm trying to do:
> 
>  Class msg:
>  	def __init__(self):
>  		self.msgtype = {"priv":send_priv_msg,
>  				"pub":send_pub_msg,
>  				"action":send_action_msg,
>  				"notice":send_notice_msg,
>  				"ctcp":send_ctcp_msg}
>  		...more stuff...
> 
>  	def send_priv_msg(connection, nick, text):
>  		... send code ..
>  	def send_pub_msg(connection, nick, text):
>  		... send code ..
>  	def send_action_msg(connection, nick, text):
>  		... send code ..
>  	def send_notice_msg(connection, nick, text):
>  		... send code ..
>  	def send_ctcp_msg(connection, nick, text):
>  		... send code ..
> 
>  	def send_msg_by(connection, nick, text, type):
>  		self.msgtype[type](connection, nick, text)
> 
> 
>  Thanks,
> 
>  Juno
> 
> 
> 
>  _______________________________________________
>  Tutor maillist  -  Tutor@[...].org
>  http://mail.python.org/mailman/listinfo/tutor
> 



_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:

Andrew Wilkins

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved