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,
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
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
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
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
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.
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
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
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
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
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
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
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
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
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
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):
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
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
-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
-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
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,
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
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
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/
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
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__',
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__',
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__',
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__',
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 :-)
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__',
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
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__',
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
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
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
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
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(!)
).
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
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
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
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
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
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
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
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/
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
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
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))
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.
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
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
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:
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
54 matches
Mail list logo