Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

python - better way of handling nested list -


my_list = [ [1,2,3,4,5,6], [1,3,4],[34,56,56,56]] item in my_list:     var1,var2,var3,var4,var5,var6 = none      if len(item) ==1:           var1 = item[0]      if len(item) == 2:           var1 = item[0]           var2  = item[1]      if len(item) == 3:          var1 = item[0]          var2 = item[1]          var3 = item[2]      if len(item) == 4:         var1 = item[0]         var2 = item[1]         var3 = item[2]         var4 = item[3]     fun(var1,var2,var3,var4,var5,var6) 

i have function

def fun(var1, var2 = none, var3 = none, var4 = none, var5=none, var6= none) 

depending upon values in inner list. passing function. hope made clear.

thanks

see calls , function definitions in python documentation, specifically:

if syntax *expression appears in function call, expression must evaluate sequence. elements sequence treated if additional positional arguments....


if syntax **expression appears in function call, expression must evaluate mapping, contents of treated additional keyword arguments....


...a function call assigns values parameters mentioned in parameter list, either position arguments, keyword arguments, or default values. if form “*identifier” present, initialized tuple receiving excess positional parameters, defaulting empty tuple. if form “**identifier” present, initialized new dictionary receiving excess keyword arguments, defaulting new empty dictionary.

example 1

you need following, since arguments simple integers:

my_list = [[1,2,3,4,5,6],[1,3,4],[34,56,56,56]]  def func(*var):     arg in var:         print arg,     print  args in my_list:     func(*args) 

output 1

1 2 3 4 5 6  1 3 4  34 56 56 56  

example 2

the next example shows can fill in number of arguments function defaults:

my_list = [[1,2,3,4,5,6],[1,3,4],[34,56,56,56]]  def func(var1=none,var2=none,var3=none,var4=none,var5=none,var6=none):     print var1,var2,var3,var4,var5,var6  args in my_list:     func(*args) 

output 2

1 2 3 4 5 6 1 3 4 none none none 34 56 56 56 none none 

example 3

you can fill them in out-of-order ** syntax:

my_list = [dict(var1=1,var5=5,var6=6),dict(var2=2,var4=4)]  def func(var1=none,var2=none,var3=none,var4=none,var5=none,var6=none):     print var1,var2,var3,var4,var5,var6  args in my_list:     func(**args) 

output 3

1 none none none 5 6 none 2 none 4 none none 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -