[BangPypers] Favorite tips/techniques

Amit Sethi amit.pureenergy at gmail.com
Wed Sep 11 15:20:35 CEST 2013


1.
I do like the accessing dict attributes as keys and specifically where they
make more sense as structure by itselfI do use

 class ABC(object):
    a = ''

     def __init__(self, **kwargs):
            self.__dict__.update(**kwargs)

2. When creating a dictionary of constants create it dynamically and
independently on an interpreter and then use pprint and use copy it in my
code







On Wed, Sep 11, 2013 at 5:37 PM, s|s <supr.e.etsethi at gmail.com> wrote:

> There are times when the project requires a large blob of data which needs
> to be loaded with the python code. A general practice is to use pickle and
> json object which is opened using file functions etc.
>
> I tend to convert this kind of data (depending on size) into python file
> using pprint and store it as code included using python standard coding
> convention. Saves hassle of packaging and caring about path convention. Of
> course it is not correct convention for all situations.
>
>
> On Wed, Sep 11, 2013 at 4:55 PM, Anand Chitipothu <anandology at gmail.com
> >wrote:
>
> > Another script I use often is repr.
> >
> > https://github.com/anandology/hacks/blob/master/repr
> >
> > It reads each line from stdin and prints it as python repr. Useful to see
> > hidden/non-alphanumeric characters.
> >
> > $ echo -e "a\bc"
> > c
> > $ echo -e "a\bc" | repr
> > a\x08c\n
> >
> > This is similar to od, but od prints fixed number of characters in each
> > line and sometimes you want to see the lines without breaking.
> >
> > Couple of hours back, I noticed an issue with a row in a mysql dump, and
> > here is how I used it to inspect at that row.
> >
> > $ head -28130 my-table.txt | tail -1 | repr
> > 2006-05-25 00:19:12\t\t1900-01-01 00:00:00\t0000\tMetal1\t
> >
> > Anand
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org
> > https://mail.python.org/mailman/listinfo/bangpypers
> >
>
>
>
> --
> Supreet Sethi
> Ph UK: +447859172473
> Ph IN: +919811143517
> Ph Skype: d_j_i_n_n
> Profile: http://www.google.com/profiles/supreet.sethi
> Twt: http://twitter.com/djinn
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
>



-- 
A-M-I-T S|S


More information about the BangPypers mailing list