[Tutor] (no subject)

Dave Angel d at davea.name
Mon May 14 12:44:44 CEST 2012


On 05/14/2012 05:58 AM, Keitaro Kaoru wrote:
> sorry if i keep missing this up.
>
> hey. Austin here for some reason this command. all it does it produces the
> error message at the bottom.. itll say my name and the persons name im
> trying to send the message to but thats it. heres the command.
I spent some time trying to re-indent this code, and eventually got it
to make sense.  However then I got at least two syntax errors, noted inline.
 
> ################################################################
> # Imports
> ################################################################
> from tools import Html, Error, Text, shared_db, log
> import urllib.request as urlreq
> import urllib.parse as urlpar
> import xml.dom.minidom as xdm
> import random
> import time
> import json
> import re
> import ch
>
> mgr.addCommand("tell", 1, "send a person a message to the rooms he is in",
> tell, unlisted = True)
>
> def tell(mgr, croom, user, msg, args):
>         name = args.lower().split(" ")[0]
>         if not name.isalnum(): return Html("Non-alphanumeric name, seriously?")
>         data = shared_db.get("seen:" + name)
>         if data == None:
>                 return Html("I have no records about this user.")
>         data = json.loads(data)
>         for room in mgr.rooms:
>                 if data[1] == "join":
>                         mgr.sendObject(target,
> Html("<b>%s</b>,<b><font color='#3399CC'>%s</font></b>  wants to tell
> you<b><i>%s</i> </b>", name.title, user.name.title$
That $ at the end is a syntax error.  At a minimum there should be two
right parentheses there, but i can't tell if other stuff got lost there.

>         else:
>                         return Error("<b>%s</b>  I couldn't find %s
> anywhere", user.name.title(), name.title())
>
> i built it off these 2 commands
>
> def broadcast(mgr, croom, user, msg, args):
>         for room in mgr.rooms:
>                 mgr.sendObject(room, Html("Broadcast by<b>%s</b>:%s",
> user.name, args))
>
> def seen(mgr, room, user, msg, args):
> name = args.lower().split(" ")[0]
> if not name.isalnum(): return Html("Non-alphanumeric name, seriously?")
> data = shared_db.get("seen:" + name)
> if data == None:
>         return Html("I have no records about this user.")
> data = json.loads(data)
> ifdata[1] == "join":
Need a space after the 'if'


>         return Html("Last seen<b>%s</b>  join<b>%s</b>,<b>%s</b>
> ago.", name, data[0], tdelta(data[2]))
> elif data[1] == "leave":
>         return Html("Last seen<b>%s</b>  leave<b>%s</b>,<b>%s</b>
> ago.", name, data[0], tdelta(data[2]))
> elif data[1] == "message":
>         return Html("Last seen<b>%s</b>  message in<b>%s</b>,<b>%s</b>
>  ago: <i>\"%s\"</i>", name, data[0], tdelta(data[2]), data[3])
>         return Html("I have no records about this user.")
>
> as you can see i only use some of the command. it doesnt produce an error
> message tho.. just repeats "return Error("<b>%s</b>  I couldn't find %s
> anywhere", user.name.title(), name.title())"
>
>

At this point, I got import errors on four of the nine import
statements.  And then the following:

Traceback (most recent call last):
  File "keitaro.py", line 15, in <module>
    mgr.addCommand("tell", 1, "send a person a message to the rooms he
is in",
NameError: name 'mgr' is not defined

This is with python 2.7 on Linux



-- 

DaveA



More information about the Tutor mailing list