Re: [BangPypers] Python "Wat"s

2013-09-12 Thread Dhananjay Nene
On Thu, Sep 12, 2013 at 11:22 PM, Shabda Raaj wrote: >> whole qx business than Python programmers are with os and subprocess. > > That because subprocess and os module have a very bad api. I prefer using > envoy whenevr I can. > > https://github.com/kennethreitz/envoy Interesting. Haven't worked

Re: [BangPypers] Python "Wat"s

2013-09-12 Thread Saager Mhatre
On Tue, Sep 10, 2013 at 10:14 AM, Shabda Raaj wrote: > This is a popular talk on quircks of ruby/js > > https://www.destroyallsoftware.com/talks/wat > > What are the quircks/unexpected behavior you find in Python? (Aka Python > "wats"). > Wait a second... wasn't there a talk about just this capt

Re: [BangPypers] Python "Wat"s

2013-09-11 Thread Noufal Ibrahim
Jeffrey Jose writes: [...] > I come from a place where you use *batteries* as much as possible, and > where shelling out is the last resort. [...] I think so too. Perl programmers are much more comfortable with the whole qx business than Python programmers are with os and subprocess. -- C

Re: [BangPypers] Python "Wat"s

2013-09-11 Thread Jeffrey Jose
On Wed, Sep 11, 2013 at 9:02 PM, Vardhan Varma wrote: > On Wed, Sep 11, 2013 at 8:42 PM, Pranjal Mittal < > pranjal.mittal.ec...@iitbhu.ac.in> wrote: > > > Here you go- > > > > import socket > > socket.gethostbyaddr(socket.gethostname())[2] > > > > > > On Wed, Sep 11, 2013 at 8:16 PM, ashish makan

Re: [BangPypers] Python "Wat"s

2013-09-11 Thread Vardhan Varma
On Wed, Sep 11, 2013 at 8:42 PM, Pranjal Mittal < pranjal.mittal.ec...@iitbhu.ac.in> wrote: > Here you go- > > import socket > socket.gethostbyaddr(socket.gethostname())[2] > > > On Wed, Sep 11, 2013 at 8:16 PM, ashish makani >wrote: > > > Found this quick, nifty way to determine the ip address o

Re: [BangPypers] Python "Wat"s

2013-09-11 Thread Pranjal Mittal
Here you go- import socket socket.gethostbyaddr(socket.gethostname())[2] On Wed, Sep 11, 2013 at 8:16 PM, ashish makani wrote: > Found this quick, nifty way to determine the ip address of the machine your > py script is running on > > import commands > commands.getoutput("/sbin/ifconfig").split

Re: [BangPypers] Python "Wat"s

2013-09-11 Thread ashish makani
Found this quick, nifty way to determine the ip address of the machine your py script is running on import commands commands.getoutput("/sbin/ifconfig").split("\n")[1].split()[1][5:] ( via http://stackoverflow.com/a/3177266/559456 ) cheers ashish *The only way to do great work is to love what y

Re: [BangPypers] Python "Wat"s

2013-09-10 Thread Gopalakrishnan Subramani
We must be thankful for the people who invented the keyboard and stopped with single SPACE and TAB keys for column indentation. Every time you edit, mind compile the Python code on production critical time, there could be a landmine hidden in the white space on nano or remote vi. On Tue, Sep

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Anand Chitipothu
On Tue, Sep 10, 2013 at 11:10 AM, Bibhas wrote: > > > Anand Chitipothu wrote: > >On Tue, Sep 10, 2013 at 10:57 AM, Shabda Raaj > >wrote: > > > >> > A variable is either local or global. It is decided at the compile > >time. > >> > >> Erm, compile? > >> > > > >well, you may call it module/script

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Bibhas
Of course it is possible to force byte-compile the Python scripts. You can also use 'pycompile' command for that. I meant python by default byte-compiles the scripts that are imported so that they can be imported faster the next time. Jeffrey Jose wrote: >On Tue, Sep 10, 2013 at 11:10 AM, Bib

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Bibhas
Anand B Pillai wrote: >-BEGIN PGP SIGNED MESSAGE- >Hash: SHA1 > >On Tuesday 10 September 2013 10:57 AM, Shabda Raaj wrote: >>> A variable is either local or global. It is decided at the >>> compile time. >> >> Erm, compile? >> >> >> Python's scoping rules are , erm, interesting: >> >

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Jeffrey Jose
On Tue, Sep 10, 2013 at 11:10 AM, Bibhas wrote: > Only the scripts that have been imported somewhere. Right? > Not necessarily - >>> import py_compile >>> py_compile.compile Byte-compile one Python source file to Python bytecode. Arguments: file:source filename cfile:

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Anand B Pillai
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Tuesday 10 September 2013 10:57 AM, Shabda Raaj wrote: >> A variable is either local or global. It is decided at the >> compile time. > > Erm, compile? > > > Python's scoping rules are , erm, interesting: > > http://me.veekun.com/blog/2011/04/24

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Bibhas
Anand Chitipothu wrote: >On Tue, Sep 10, 2013 at 10:57 AM, Shabda Raaj >wrote: > >> > A variable is either local or global. It is decided at the compile >time. >> >> Erm, compile? >> > >well, you may call it module/script load time. But python compiles the >code >and generates bytecode before e

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Anand Chitipothu
On Tue, Sep 10, 2013 at 10:57 AM, Shabda Raaj wrote: > > A variable is either local or global. It is decided at the compile time. > > Erm, compile? > well, you may call it module/script load time. But python compiles the code and generates bytecode before executing it. $ file a.pyc a.pyc: pytho

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Shabda Raaj
> A variable is either local or global. It is decided at the compile time. Erm, compile? Python's scoping rules are , erm, interesting: http://me.veekun.com/blog/2011/04/24/gotcha-python-scoping-closures/ The mnemonic for scoping is LEGB: http://stackoverflow.com/questions/291978/short-descrip

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Anand Chitipothu
On Tue, Sep 10, 2013 at 10:46 AM, Ramchandra Apte wrote: > I get UnboundLocalError: local variable 'x' referenced before assignment. > That's strange, I'd expect the first print statement to print 10, not > generate an exception. > A variable is either local or global. It is decided at the compil

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Ramchandra Apte
I get UnboundLocalError: local variable 'x' referenced before assignment. That's strange, I'd expect the first print statement to print 10, not generate an exception. On 10 September 2013 10:39, Anand Chitipothu wrote: > On Tue, Sep 10, 2013 at 10:37 AM, Ramchandra Apte >wrote: > > > On 10 Se

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Anand Chitipothu
On Tue, Sep 10, 2013 at 10:37 AM, Ramchandra Apte wrote: > On 10 September 2013 10:21, Anand Chitipothu wrote: > > > On Tue, Sep 10, 2013 at 10:14 AM, Shabda Raaj wrote: > > > > > This is a popular talk on quircks of ruby/js > > > > > > https://www.destroyallsoftware.com/talks/wat > > > > > > Wh

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Ramchandra Apte
On 10 September 2013 10:21, Anand Chitipothu wrote: > On Tue, Sep 10, 2013 at 10:14 AM, Shabda Raaj wrote: > > > This is a popular talk on quircks of ruby/js > > > > https://www.destroyallsoftware.com/talks/wat > > > > What are the quircks/unexpected behavior you find in Python? (Aka Python > >

Re: [BangPypers] Python "Wat"s

2013-09-09 Thread Anand Chitipothu
On Tue, Sep 10, 2013 at 10:14 AM, Shabda Raaj wrote: > This is a popular talk on quircks of ruby/js > > https://www.destroyallsoftware.com/talks/wat > > What are the quircks/unexpected behavior you find in Python? (Aka Python > "wats"). > x = 10 class Foo: print x x = 0 print x