how to repeat function definitions less

alex goretoy aleksandr.goretoy at gmail.com
Sun Mar 15 23:37:26 CET 2009


ok now for the final result, i decided to split options out to a separate
dict of lists, does this look right to every one, I currently have error
somewhere else in my code so can't test this right now, Is this a good
method to do this? or is there another option?

        self.opt={}
        self.opt['arg_opts_options']={
            "imp_src":['ss',"src","source","sources"],
            "imp_mod":['m',"mod",'mods',"module","modules"],
            "imp_opt":['o',"oo","opt",'opts',"option","options"],
            "imp_set":['s','ss',"sss","set","setting","settings"],

"imp_files":["f","fn",'file','files','filename','filenames','file_name','file_names'],
            "imp_flavors":["fff","flav","flavor","flavors"],

"imp_funcs":["ff","finfun",'fin_fun',"final_func",'final_funct',"final_funcs",

'final_functs',"final_function","final_functions"],

"imp_downloads":["d",'df',"down",'down_file','down_files',"download",

"downloads",'download_file','download_files'],

"imp_colors":["c","cl","col","colo","color","colors",'reaper','reapers'],
            "imp_properties":["p","prop","property","properties"]
        }
        self.opt['arg_opts']={
            "site_name":["s","sn","site",'sites','site_name','site_names'],
            "jar_name":["j","jn","jar",'jars','jar_name','jar_names'],

"file_name":["f","fn",'file','files','filename','filenames','file_name','file_names'],
            "verbose":["v","vv","vvv",'verbose','verbosity'],
            "flavors":["fff","flav","flavor","flavors"],

"final_funcs":["ff","finfun",'fin_fun',"final_func",'final_funct',"final_funcs",

'final_functs',"final_function","final_functions"],

"download_files":["d",'df',"down",'down_file','down_files',"download",
                            "downloads",'download_file','download_files'],

"colors":["c","cl","col","colo","color","colors",'reaper','reapers'],
            "options":['o','opt','option',"options"],
            "properties":["p","prop","property","properties"]
        }

    def main(self):
        def _set_arg(a,b):
            for k,v in self.opt['arg_opts']:

                if a in v:
                    if a in ["colors","flavors",'final_funcs']:
                        if b is not "":
                            _b=b.split(',')
                            for c in range(len(_b)):
                                _c=_b[c].split(":")
                                if _c[1] is not "":
                                    setattr(self,
opt['properties']['flavors'][_c[0]], _c[1])
                                    self.soc.debug("%s"%("args "+k+":
",self.opt['properties'][k]))
                    elif a is "download_files":
                        if b is not "":
                            if bool(b):
                                print ("\nDOWNLOAD FILES",b)
                                self.opt['properties']['settings'][a] = 1
                                self.soc.debug( "%s"%("args "+a+":
",self.opt['properties']['settings'][a]) )
                            if b.find("://") > -1:
                                _b=b.split(";")
                                if _b[1] is not "":

self.opt['properties']['file_downloads'][_b[0]]=_b[1]
                                    self.soc.debug( "%s"%("args
file_downloads: ",self.opt['properties']['file_downloads'][_b[0]]) )
                    elif a is "options":
                        _b=b.split(",")
                        for c in range(len(_b)):
                            _c=_b[c].split(':')
                            for i,j in self.opt['arg_opts_options']:
                                if _c[0] in j:
                                    if _c[1] is not "":
                                        self.opt['properties'][j] = _c[1]
                                        self.soc.debug( "%s"%("args imp_src:
",self.opt['properties']['imp_src']) )
                    else:
                        if b is not "":
                            setattr(self, opt['properties'][a], b)
                            self.soc.debug("%s"%("args "+k+":
",self.opt['properties'][k]))


        for _argsi in range(len("".join(self.args).split('='))-1):
            _args=self.args[_argsi].split("=")
            print ("printing A:",_args)
            _set_arg(_arg[0],_arg[1])
-Alex Goretoy
http://www.goretoy.com



On Sun, Mar 15, 2009 at 3:56 PM, alex goretoy
<aleksandr.goretoy at gmail.com>wrote:

> this is the final result of the args i will be parsing for now
>
>         d={
>             "site_name":["s","sn","site",'sites','site_name','site_names'],
>             "jar_name":["j","jn","jar",'jars','jar_name','jar_names'],
>
> "file_name":["f","fn",'file','files','filename','filenames','file_name','file_names'],
>             "verbose":["v","vv","vvv",'verbose','verbosity'],
>             "flavors":["fff","flav","flavor","flavors"],
>
> "final_funcs":["ff","finfun",'fin_fun',"final_func",'final_funct',"final_funcs",
>
> 'final_functs',"final_function","final_functions"],
>
> "download_files":["d",'df',"down",'down_file','down_files',"download",
>                             "downloads",'download_file','download_files'],
>
> "colors":["c","cl","col","colo","color","colors",'reaper','reapers'],
>             "options":{
>                         "imp_src":['ss',"src","source","sources"],
>                         "imp_mod":['m',"mod",'mods',"module","modules"],
>
> "imp_opt":['o',"oo","opt",'opts',"option","options"],
>
> "imp_set":['s','ss',"sss","set","setting","settings"],
>
> "imp_files":["f","fn",'file','files','filename','filenames','file_name','file_names'],
>                         "imp_flavors":["fff","flav","flavor","flavors"],
>
> "imp_funcs":["ff","finfun",'fin_fun',"final_func",'final_funct',"final_funcs",
>
> 'final_functs',"final_function","final_functions"],
>
> "imp_downloads":["d",'df',"down",'down_file','down_files',"download",
>
> "downloads",'download_file','download_files'],
>
> "imp_colors":["c","cl","col","colo","color","colors",'reaper','reapers'],
>
> "imp_properties":["p","prop","property","properties"]
>
>             },
>             "properties":["p","prop","property","properties"]
>         }
>
> pynutbutter will be really good soon, thx for your help :) I'm glad to be
> doing this in python
>
> -Alex Goretoy
> http://www.goretoy.com
>
>
>
> On Sun, Mar 15, 2009 at 3:30 PM, alex goretoy <aleksandr.goretoy at gmail.com
> > wrote:
>
>> Michele I tried your way but I dont seem to have a good grasp on the
>> concept yet, will read up more
>>
>> for now I think I will try to make it work same way as colors only with
>> decorator as def inside def instead of @, that doesn't make sense quite yet
>>
>> -Alex Goretoy
>> http://www.goretoy.com
>>
>>
>>
>> On Sun, Mar 15, 2009 at 3:12 PM, alex goretoy <
>> aleksandr.goretoy at gmail.com> wrote:
>>
>>> this is what I did to define all my color functions by color name, but I
>>> am still going to need a good solution for args
>>>
>>>         #import functions by color name into current namespace
>>>>         for color in self.colors.keys():
>>>>             setattr(self, color,lambda x,y=color,z="INFO":
>>>> self._hero(x,y,z) )
>>>>
>>>
>>> Thanks to all of you for helping me learn python
>>>
>>> -Alex Goretoy
>>> http://www.goretoy.com
>>>
>>>
>>>
>>> On Sun, Mar 15, 2009 at 1:05 PM, alex goretoy <
>>> aleksandr.goretoy at gmail.com> wrote:
>>>
>>>> this means i have to check if d[i] is list or dict and iterate over
>>>> properties
>>>> -Alex Goretoy
>>>> http://www.goretoy.com
>>>>
>>>>
>>>>
>>>> On Sun, Mar 15, 2009 at 1:03 PM, alex goretoy <
>>>> aleksandr.goretoy at gmail.com> wrote:
>>>>
>>>>> I will also actually need to nest it like so
>>>>>
>>>>> d={
>>>>>    "site_name":["s","site",'
>>>>>>
>>>>>> sites','site_name','site_names'],
>>>>>>    "jar_name":["j","jar",'jars','jar_name','jar_names'],
>>>>>
>>>>>     "options":{
>>>>>         "src_name":["ss","src","source"],
>>>>>         "mod_name":['m',"mod",'mods',"module","modules"],
>>>>> }
>>>>>
>>>>> -Alex Goretoy
>>>>> http://www.goretoy.com
>>>>>
>>>>>
>>>>>
>>>>> On Sun, Mar 15, 2009 at 10:51 AM, MRAB <google at mrabarnett.plus.com>wrote:
>>>>>
>>>>>> d={
>>>>>>>    "site_name":["s","site",'sites','site_name','site_names'],
>>>>>>>    "jar_name":["j","jar",'jars','jar_name','jar_names'],
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090315/56299df7/attachment.html>


More information about the Python-list mailing list