[BangPypers] Managing variable in small scripts.

Mukesh Yadav mak.gnu at gmail.com
Wed Feb 19 12:27:48 CET 2014


@Rohit thanks for **kwargs example.




On Wed, Feb 19, 2014 at 4:36 PM, Rohit K <rohitk at myparichay.in> wrote:

> How about creating a class object
>
> *Class Params():*
>
> *    def __init__(self, **kwargs):*
>
> *        self.bucket = kwargs['bucket'] *
>
>
> *        self.value = kwargs["value"]*.....
>
> and while you create instance for module class:
>
> # object = module.*Class_name*('value'); instead of this use below
>
>
>
> *p = Params("value"=value, "bucket"=bucket)object = module.*Class_name*(p);
> *
>
> Inside your function you can use
>
> *def some_awesome_function(self):*
>
> *     print self.bucket*
>
> *     print self.value*
>
> And you are good to go with :
>
> *object.*some_awesome_function*() *
>
>
> Thanks,
> Rohit Kumar
>
>
>
>
>
>
> On Wed, Feb 19, 2014 at 4:21 PM, Mukesh Yadav <mak.gnu at gmail.com> wrote:
>
> > > Unless I am missing something, why can't you use:
> > >   object.some_awesome_function( bucket )
> > >
> > > I can but in my case I have 5+ setting variables, which is not feasible
> > to
> > pass it for each method which it is using.
> >
> >  Also,
> > > as you are presumably writing these scripts after the
> > > class code has already been created, how would the
> > > class know where to import from?
> > >
> >
> > I can change the class code and parameter as it is small script.
> >
> >
> > >
> > > Regards,
> > > Gora
> > > _______________________________________________
> > > BangPypers mailing list
> > > BangPypers at python.org
> > > https://mail.python.org/mailman/listinfo/bangpypers
> > >
> >
> >
> >
> > --
> > Regards
> > Mukesh Yadav
> > mukeshyadav.com
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org
> > https://mail.python.org/mailman/listinfo/bangpypers
> >
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
>



-- 
Regards
Mukesh Yadav
mukeshyadav.com


More information about the BangPypers mailing list