scopes of local and global variable
Pyenos
pyenos at pyenos.org
Fri Dec 22 20:15:16 EST 2006
James Stroud <jstroud at mbi.ucla.edu> writes:
> >>>#############################CODE##############################
> >>>t_len=0
> >>>class WORK:
> >>> def getwork(self):
> >>> def formattable(table_to_process,type):
> >>>TYPE=["p","t","T","s","i"] #list of types to format
> >>> if type==TYPE[1]:
> >>> def format_t():
> >>> row=[]
> >>> for col in table_to_process:
> >>> #######################
> >>> # ERROR PRONE PART #
> >>> #######################
> >>> if len(str(col))>t_len:
> >>> t_len=len(str(col))
> >>> #######################
> >>># Error message says: #
> >>># UnboundLocalError: local variable 't_len' referenced before assignment#
> >>> row+=col
> >>> if (table_to_process.index(col)+1)%7==0:
> >>> t_temp.append(row)
> >>> row=[]
> >>> format_t()
> >>>#################################################################
based on your advice i will try to answer my own questions:
> > does class WORK inherit t_len=0 from line1?
yes.
> > does def getwork() inherit t_len=0 from line1?
no.
> > does def formattable(table_to_process,type) inherit t_len=0 from
> > line1?
no.
> > does def format_t() inherit t_len=0 from line1?
no.
thank you kindly.
More information about the Python-list
mailing list