Re: [BangPypers] Favorite tips/techniques

2013-09-13 Thread Saju M
Saager, As per python module-import semantics, sub-modules don't end up as names in the package-module[*] unless explicitly added. I didn't get it, what you mean by package-module[*] ?. -- One simple test. dir(json) showing the module tool after from json import tool,

Re: [BangPypers] Favorite tips/techniques

2013-09-13 Thread Saager Mhatre
On Sep 9, 2013 8:51 PM, CsquaredinOmaha c2inom...@yahoo.com wrote: For a while I had thought it would be interesting to hear tips/techniques you find yourself often using - or perhaps found useful at one point (and thus would be valuable to newbies). It could be simple snippet, or some

Re: [BangPypers] Favorite tips/techniques

2013-09-13 Thread Saager Mhatre
On Sep 9, 2013 8:51 PM, CsquaredinOmaha c2inom...@yahoo.com wrote: For a while I had thought it would be interesting to hear tips/techniques you find yourself often using - or perhaps found useful at one point (and thus would be valuable to newbies). It could be simple snippet, or some

Re: [BangPypers] Favorite tips/techniques

2013-09-12 Thread Saager Mhatre
On Tue, Sep 10, 2013 at 10:39 AM, Shabda Raaj sha...@agiliq.com wrote: https://github.com/webpy/webpy/blob/master/web/utils.py#L52 Wow, thats better than the bare bunch impl. Gonna use it now. plug type=shamelessIt's just s much nicer when the map/dict in your platform

Re: [BangPypers] Favorite tips/techniques

2013-09-12 Thread Saager Mhatre
On Tue, Sep 10, 2013 at 4:54 PM, Noufal Ibrahim nou...@nibrahim.net.inwrote: Saju M sajup...@gmail.com writes: [...] * Why dir(json) not showing tool ?? Because of the __all__ variable in the module. http://docs.python.org/2/tutorial/modules.html Noufal, Well, not quite, right? I posit

Re: [BangPypers] Favorite tips/techniques

2013-09-12 Thread Noufal Ibrahim
Saager Mhatre saager.mha...@gmail.com writes: On Tue, Sep 10, 2013 at 4:54 PM, Noufal Ibrahim nou...@nibrahim.net.inwrote: Saju M sajup...@gmail.com writes: [...] * Why dir(json) not showing tool ?? Because of the __all__ variable in the module.

Re: [BangPypers] Favorite tips/techniques

2013-09-12 Thread L Radhakrishna Rao
Not so complex, but the technique which I love is the comprehension, it decreases the code size. On Fri, Sep 13, 2013 at 8:25 AM, Noufal Ibrahim nou...@nibrahim.net.inwrote: Saager Mhatre saager.mha...@gmail.com writes: On Tue, Sep 10, 2013 at 4:54 PM, Noufal Ibrahim nou...@nibrahim.net.in

Re: [BangPypers] Favorite tips/techniques

2013-09-12 Thread Noufal Ibrahim
I often type this x = Break this into a list.split() instead of x = [Break, this, into, a, list] The latter is more tedious to type. -- Cordially, Noufal http://nibrahim.net.in ___ BangPypers mailing list BangPypers@python.org

Re: [BangPypers] Favorite tips/techniques

2013-09-11 Thread s|s
This use case where one needs to keep related values together as logical group: Properties, getattr, setattr are quite interesting option but I prefer collections.namedtuple Example EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade') import csvfor emp in

Re: [BangPypers] Favorite tips/techniques

2013-09-11 Thread Anand Chitipothu
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

Re: [BangPypers] Favorite tips/techniques

2013-09-11 Thread s|s
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

Re: [BangPypers] Favorite tips/techniques

2013-09-11 Thread Amit Sethi
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

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Vinayak Hegde
On Tue, Sep 10, 2013 at 10:45 AM, Noufal Ibrahim nou...@nibrahim.net.inwrote: Anand Chitipothu anandol...@gmail.com writes: [...] I use it very often. Here is my random-password script. [...] I use mkpasswd(1) :) What ever you use, please use py-bcrypt or something similar before you

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Lakshman Prasad
My first random password (until it is replaced with SHA, MD5, bCrypt, whatever): str(random.random())[2:] '742557965797' On Tue, Sep 10, 2013 at 11:34 AM, Vinayak Hegde vinay...@gmail.com wrote: On Tue, Sep 10, 2013 at 10:45 AM, Noufal Ibrahim nou...@nibrahim.net.in wrote: Anand

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Mandar Vaze / मंदार वझे
Both Shabda and Nouful used the term prefer Is there a best practice ? http://stackoverflow.com/questions/4984647/accessing-dict-keys-like-an-attribute-in-python This guy asked for pitfalls and caveats - but no one seem to have addressed the question (There are several answers about How to do it

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Me@Bibhas
This thread is awesome. Keep them coming. :) I've also been using random string generator Shabda posted for a long time. Handy. On Tuesday 10 September 2013 12:48 PM, Lakshman Prasad wrote: My first random password (until it is replaced with SHA, MD5, bCrypt, whatever):

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Me@Bibhas
Don't know if I can call it a snippet, But this command on terminal - $ python -m SimpleHTTPServer 8080 is really handy for sharing files(along with the use of `localtunnel` maybe) and testing HTML/CSS. On Tuesday 10 September 2013 12:48 PM, Lakshman Prasad wrote: My first random password

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Noufal Ibrahim
Me@Bibhas m...@bibhas.in writes: Don't know if I can call it a snippet, But this command on terminal - $ python -m SimpleHTTPServer 8080 Similar but less well known. Command line ftp client (similar to ftp(1)) python -m ftplib ftp.gnu.org Command line mail client (similar to mail(1)) but

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Anand B Pillai
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Tuesday 10 September 2013 03:07 PM, Me@Bibhas wrote: This thread is awesome. Keep them coming. :) I've also been using random string generator Shabda posted for a long time. Handy. On Tuesday 10 September 2013 12:48 PM, Lakshman Prasad

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Anand B Pillai
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Tuesday 10 September 2013 03:28 PM, Noufal Ibrahim wrote: Me@Bibhas m...@bibhas.in writes: Don't know if I can call it a snippet, But this command on terminal - $ python -m SimpleHTTPServer 8080 Similar but less well known. Command

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Shabda Raaj
Another tip: Its common to write decorators which clober the docstring and other meta data. If you use functools.wrap this metadata is preserved. http://docs.python.org/2/library/functools.html https://github.com/django/django/blob/master/django/contrib/auth/decorators.py#L19 On Tue, Sep 10,

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Vineet Naik
Command line json formatter $ echo '{name: Bangpypers, location: Bangalore}' | python -m json.tool On Tue, Sep 10, 2013 at 3:28 PM, Noufal Ibrahim nou...@nibrahim.net.inwrote: Me@Bibhas m...@bibhas.in writes: Don't know if I can call it a snippet, But this command on terminal - $ python

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Gopalakrishnan Subramani
Not all keys in the dictionary can be expressed as attributes. Attributes has to follow the naming conventions. I had problems with user generated 'keys', JSON supported keys. On Tue, Sep 10, 2013 at 2:41 PM, Mandar Vaze / मंदार वझे mandarv...@gmail.com wrote: Both Shabda and Nouful

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Me@Bibhas
What would happen for a dictionary like this? d = {'1': 'foo', 1: 'bar'} d {'1': 'foo', 1: 'bar'} On Tuesday 10 September 2013 10:00 AM, Noufal Ibrahim wrote: Shabda Raaj sha...@agiliq.com writes: http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Navin Pai
Date: Tue, 10 Sep 2013 15:39:44 +0530 From: Vineet Naik naik...@gmail.com To: Bangalore Python Users Group - India bangpypers@python.org Message-ID: CADmbCiP8Dq7BroEWovreG2AfB= g1u3z80zgnt6cg3lenrsb...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Command line json

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Saju M
echo '{name: Bangpypers, location: Bangalore}' | python -m json.tool In this command, what is this json.tool ? I could not find tool in dir(json) import json dir(json) ['JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__',

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Noufal Ibrahim
Saju M sajup...@gmail.com writes: echo '{name: Bangpypers, location: Bangalore}' | python -m json.tool In this command, what is this json.tool ? I could not find tool in dir(json) import json dir(json) ['JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__',

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Vineet Naik
On Tue, Sep 10, 2013 at 4:16 PM, Saju M sajup...@gmail.com wrote: echo '{name: Bangpypers, location: Bangalore}' | python -m json.tool In this command, what is this json.tool ? I could not find tool in dir(json) import json dir(json) ['JSONDecoder', 'JSONEncoder', '__all__',

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread BibhasD
On Tuesday 10 September 2013 04:16 PM, Saju M wrote: echo '{name: Bangpypers, location: Bangalore}' | python -m json.tool In this command, what is this json.tool ? I could not find tool in dir(json) import json dir(json) ['JSONDecoder', 'JSONEncoder', '__all__', '__author__',

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Noufal Ibrahim
Vineet Naik naik...@gmail.com writes: [...] If you are using jedi[1] with auto-complete in emacs, C-. takes you to the definition by opening the module file in a write protected buffer. I use jedi mainly for this feature and inline documentation popout rather than for autocomplete :-)

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Saju M
Hi, I have couple of doubts * How do you find json has module named tool ?. * Why dir(json) not showing tool ?? import json dir(json) ['JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__',

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Noufal Ibrahim
Saju M sajup...@gmail.com writes: Hi, I have couple of doubts * How do you find json has module named tool ?. I look at the code/docs. * Why dir(json) not showing tool ?? Because of the __all__ variable in the module. http://docs.python.org/2/tutorial/modules.html import json

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Vineet Naik
On Tue, Sep 10, 2013 at 4:48 PM, Saju M sajup...@gmail.com wrote: Hi, I have couple of doubts * How do you find json has module named tool ?. * Why dir(json) not showing tool ?? import json dir(json) ['JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__',

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Anand Chitipothu
Another utility script that I use very heavily, pyvi. https://github.com/anandology/hacks/blob/master/pyvi $ pyvi json.tool That opens json.tool module (or any other module) in vim. It also changes the current dir to that module directory so that you can easily open other modules in the same

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread kracekumar ramaraju
I personally like to use IPython. To see all variables, constants, modules. n [9]: import requests In [10]: requests. requests.ConnectionError requests.api requests.models requests.HTTPError requests.auth requests.options requests.NullHandler

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Sreekandh Balakrishnan
This thread is awesome. Keep them coming. :) Prettyprint comes very handy when it comes to object debugging. Use it in my logger method always ;) http://docs.python.org/2/library/pprint.html ___ BangPypers mailing list BangPypers@python.org

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Ramchandra Apte
Obligatory comic: https://xkcd.com/936/ On 10 September 2013 10:42, Anand Chitipothu anandol...@gmail.com wrote: On Tue, Sep 10, 2013 at 10:39 AM, Shabda Raaj sha...@agiliq.com wrote: https://github.com/webpy/webpy/blob/master/web/utils.py#L52 Wow, thats better than the bare bunch

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Shabda Raaj
I personally like to use IPython. To see all variables, constants, modules. Ipython is amazing. To see a library code, I jsut tab-out lib_name.__file__ and then !vim paste_the_file_path Going to add something like anand's pyvi to ipy_user_conf.py. Ipython with treat anything after bang(!)

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread CsquaredinOmaha
). Regards, Chris From: Me@Bibhas m...@bibhas.in To: Bangalore Python Users Group - India bangpypers@python.org Sent: Tuesday, September 10, 2013 4:37 AM Subject: Re: [BangPypers] Favorite tips/techniques This thread is awesome. Keep them coming. :) I've also

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Dhananjay Nene
Ignoring classes for the moment, how likely do you think you would have a dict like that :) On a separate note if you are using primitive types, I cannot think of any scenarios, where not coercing keys to be of the same type would be considered inappropriate (except in case of reverse dicts) On

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread BibhasD
I'm just curious. I faced a similar issue before while answering a question about Django on StackOverflow. Django turns context variable dictionaries into objects with attributes in template. So in one question in SO someone posted this question. Had to answer that Django doesn't really support

Re: [BangPypers] Favorite tips/techniques

2013-09-10 Thread Gopalakrishnan Subramani
Attributes are stylish, readable, feel native as object compared to dictionary. Sometimes I use setter methods to override the default assignments, modify getter to format the values and getter for virtual attributes for DSL stuffs. class DictObj(dict): def __getattr__(self, key): if

[BangPypers] Favorite tips/techniques

2013-09-09 Thread CsquaredinOmaha
  For a while I had thought it would be interesting to hear tips/techniques you  find yourself often using  - or perhaps found useful at one point (and thus would be valuable to newbies). It could be simple snippet, or some description of  logic, technique or steps. From simple to sophisticated

[BangPypers] Favorite tips/techniques

2013-09-09 Thread Shabda Raaj
http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/ With api responses after you have parsed the json, you start doing things like: api_response[attribute] I would much prefer to do api_response.attribute Which the bunch pattern can enable. I don't

Re: [BangPypers] Favorite tips/techniques

2013-09-09 Thread Noufal Ibrahim
Shabda Raaj sha...@agiliq.com writes: http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/ With api responses after you have parsed the json, you start doing things like: api_response[attribute] I would much prefer to do api_response.attribute I

[BangPypers] Favorite tips/techniques

2013-09-09 Thread Shabda Raaj
I generally like to use attributes instead of keys. If you are parsing json, aren't you limited to using keys? The bunch pattern can fix this, but its not widely known/used, so I don't use it as frequently as I would like. -- Thanks, Shabda Agiliq.com - Building Amazing Apps agiliq.com/blog/

Re: [BangPypers] Favorite tips/techniques

2013-09-09 Thread Noufal Ibrahim
Shabda Raaj sha...@agiliq.com writes: I generally like to use attributes instead of keys. If you are parsing json, aren't you limited to using keys? Of course. I was making a general statement about attributes vs. keys. The bunch pattern can fix this, but its not widely known/used, so I

Re: [BangPypers] Favorite tips/techniques

2013-09-09 Thread Anand Chitipothu
On Tue, Sep 10, 2013 at 10:09 AM, Noufal Ibrahim nou...@nibrahim.net.inwrote: Shabda Raaj sha...@agiliq.com writes: I generally like to use attributes instead of keys. If you are parsing json, aren't you limited to using keys? Of course. I was making a general statement about attributes

Re: [BangPypers] Favorite tips/techniques

2013-09-09 Thread Shabda Raaj
https://github.com/webpy/webpy/blob/master/web/utils.py#L52 Wow, thats better than the bare bunch impl. Gonna use it now. Unrelated tip: Here is a one liner I use to generate passwords and other random strings. ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))

Re: [BangPypers] Favorite tips/techniques

2013-09-09 Thread Anand Chitipothu
On Tue, Sep 10, 2013 at 10:39 AM, Shabda Raaj sha...@agiliq.com wrote: https://github.com/webpy/webpy/blob/master/web/utils.py#L52 Wow, thats better than the bare bunch impl. Gonna use it now. Unrelated tip: Here is a one liner I use to generate passwords and other random strings.

Re: [BangPypers] Favorite tips/techniques

2013-09-09 Thread Noufal Ibrahim
Anand Chitipothu anandol...@gmail.com writes: [...] I use it very often. Here is my random-password script. [...] I use mkpasswd(1) :) -- Cordially, Noufal http://nibrahim.net.in ___ BangPypers mailing list BangPypers@python.org

Re: [BangPypers] Favorite tips/techniques

2013-09-09 Thread Anand Chitipothu
On Tue, Sep 10, 2013 at 10:45 AM, Noufal Ibrahim nou...@nibrahim.net.inwrote: Anand Chitipothu anandol...@gmail.com writes: [...] I use it very often. Here is my random-password script. [...] I use mkpasswd(1) :) $ sudo apt-cache search mkpasswd libstring-mkpasswd-perl - Perl module

Re: [BangPypers] Favorite tips/techniques

2013-09-09 Thread Shabda Raaj
Real programmers pipe /dev/urandom :) Let me preempt the xkcd: http://xkcd.com/378/ On Tue, Sep 10, 2013 at 10:47 AM, Anand Chitipothu anandol...@gmail.comwrote: On Tue, Sep 10, 2013 at 10:45 AM, Noufal Ibrahim nou...@nibrahim.net.inwrote: Anand Chitipothu anandol...@gmail.com writes:

Re: [BangPypers] Favorite tips/techniques

2013-09-09 Thread Noufal Ibrahim
Anand Chitipothu anandol...@gmail.com writes: [...] $ sudo apt-cache search mkpasswd libstring-mkpasswd-perl - Perl module implementing a random password generator I think that's something else. noufal@sanitarium% dpkg -S =mkpasswd whois: /usr/bin/mkpasswd noufal@sanitarium% file