On Mon, Jul 14, 2008 at 9:41 AM, JOLINY <[EMAIL PROTECTED]> wrote:
>  I am a begener of pylons . now I use it to develope a website.
> when i add a object to database, there is an error occured.
>
> the error is this.
> <type 'exceptions.UnboundLocalError'>: local variable 'wh_chapter_sort' 
> referenced before assignment
>
> this is my add object method:
>
>    class Ma003Controller(BaseController):
>
>        def add(self):
>            systemtime=h.getSystemTime()
>            userid=session['USER_KEY'].wh_userid
>
>            wh_chapter_sort = wh_chapter_sort.WHChapterSort(wh_userid=userid,
>                                       wh_chapter_sortid='001',
>                                       
> wh_chapter_sortname=request.params['chaperSortName'],
>                                       del_flg='0',
>                                       update_time=systemtime,
>                                       login_time=systemtime
>                                       )
>            meta.Session.add(wh_chapter_sort)
>            meta.Session.commit()
>
>            return redirect_to('/ma003')

The problem is that your local variable has the same name as the
global variable you're assigning to it (the module 'wh_chapter_sort').
 Change your local variable name to something unique like 'sort'.

When Python compiles a function (or method), it extracts all local
variables into a hidden array, and the bytecode contains subscripts
into that array.  As a result, 'wh_chapter_sort' on the right side of
the assignment statement is seen as  a local variable which hasn't
been initialized, not as the global variable you were expecting
(presumably a module).  Again, just change the local variable name to
something else and the problem will go away.

-- 
Mike Orr <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to