On Sat, Aug 1, 2009 at 5:00 AM, Fran <francisb...@googlemail.com> wrote:
>
> On Aug 1, 3:32 am, Alastair Medford <alastairmedf...@gmail.com> wrote:
> > > db.student.student_id.requires=IS_NOT_IN_DB(db,'student.student_id')
> > > db.tasks.student.requires=IS_IN_DB(db,'student.id','%(student_id)s')
> > > db.tasks.student.represent=lambda id: db.student[id].student_id
> > This seems to accomplish what I was trying to do, thanks. However, I'm
> > in the dark as to what some of the syntax is. In the second line, I
> > know that the third argument has something to do with how the drop
> > down box chooses it's contents, but I do not understand the syntax of
> > '%(student_id)s'. Also, in the 3rd line I do not know what "lambda id:
> > " is doing. If this is standard python fare, then I apologise as I'm
> > still learning python and all it's syntax tricks. Thanks again.
>
> These are both std Python.
>
> '%(student_id)s' => replace '' with the value of student_id


you can google "python string substitution - it is based on the C
language's  printf % codes,
so where in a C string you would have:

printf(" this is my name: %s %s\n",  first_name, last_name)

where %s is a string, replaced by the first argument (in this case a
variable called 'name')

Python string substitution, there are a few ways to accomplish something
similar:

"this is my name: %s %s"  % first_name, last_name

will replace the %s with the contents of name;  if you have a form email.
for example, you would could have a preformatted template, and load it with
different variables at each use.

If you wanted to load a template with the same variables each time (and let
the variable contents change), then you could equivalently write this as:

"this is my name: %(first_name)s %(last_name)s"


lambda functions allow you to use a little program to fill in the
> value
> so lambda id: db.student[id].student_id
> says 'use the value of this cell within the formula db.student
> [value].student_id'
> http://diveintopython.org/power_of_introspection/lambda_functions.html


That is a good link - think of lambda functions as anaonymous, or inline
functions (functions without a name)


>
>
> F
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to