Re: IDLE being too clever checking nonlocal declarations?

2013-10-22 Thread Steven D'Aprano
On Mon, 21 Oct 2013 23:26:28 -0400, Terry Reedy wrote:

 On 10/21/2013 7:52 PM, Steven D'Aprano wrote:
 On Mon, 21 Oct 2013 15:51:56 -0400, Terry Reedy wrote:

 On 10/21/2013 11:06 AM, Chris Angelico wrote:
 Try typing this into IDLE:

 def a():
   def b():
   nonlocal q
 SyntaxError: no binding for nonlocal 'q' found

 If you submit those three lines to Python from the command line, that
 is what you see.

 Arguably, that's also too strict,
 
 As I quoted from the doc, it is an error for a program to contain a
 nonlocal with no referent. The reason is one only needs nonlocal to bind
 and unlike with 'global newname', it would be undefined where to do the
 binding.

Yep, I got that, but what I'm saying is that it is too strict to raise 
the exception at the point where it sees nonlocal q. The CPython 
interpreter allows q to be defined inside function a but after function 
b, e.g. this is allowed:

def a():
def b():
nonlocal q
q += 1
q = 2  # ===


If IDLE and the code.py module requires q to be strictly defined before 
function b, then it is too strict. Your analysis of the bug as being in 
code.py seems plausible.



 [steve@ando ~]$ python3.3 -c def a():
  def b():
  nonlocal q
  q = 1
 
 
 What system lets you do that? (See other thread about Windows not
 allowing that, because newline terminates the command even after .) Is
 '' a line continuation marker (like '...' in Python)?

Yes, sorry I should have said. That's bash, under Linux.

Here's another way:


steve@runes:~$ python3.3 -c def a():^M  def b():^Mnonlocal q^M  
q=1^Mprint(a() is None)
True


Still bash under Linux (a different machine), the ^M is *not* a pair of 
characters ^ followed by M but an actually newline, generated by typing 
Ctrl-V Enter (that's the ENTER key, not the letters E n t e r).

In theory I should be able to get something working with \n escapes 
instead of ^M, but I can't get it working. But I'm not an expect at bash's 
arcane rules for quoting and escaping special characters.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-22 Thread Chris Angelico
On Tue, Oct 22, 2013 at 2:19 PM, rusi rustompm...@gmail.com wrote:
 On Tuesday, October 22, 2013 8:25:58 AM UTC+5:30, Peter Cacioppi wrote:

 Guess-who said:

 but it's ugly, by which I mean it is hard to use, error prone, and not
 easily maintained.

 OK, I see the problem. What you call ugly is really just objectively bad.

 You continue to not attribute quotes.

 What user agent/group are you using?

I don't know what headers come through on comp.lang.python, but on the
mailing list, I can see some clear fingerprints that it's the one so
many of us hate...

Message-ID: 6f511c0b-c5fa-4307-9a2a-cb73a1768...@googlegroups.com
Complaints-To: groups-ab...@google.com

Though I don't think the abuse address would do much with complaints
regarding citation courtesy :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDLE being too clever checking nonlocal declarations?

2013-10-22 Thread Chris Angelico
On Tue, Oct 22, 2013 at 4:57 PM, Steven D'Aprano st...@pearwood.info wrote:
 Yep, I got that, but what I'm saying is that it is too strict to raise
 the exception at the point where it sees nonlocal q. The CPython
 interpreter allows q to be defined inside function a but after function
 b, e.g. this is allowed:

 def a():
 def b():
 nonlocal q
 q += 1
 q = 2  # ===


 If IDLE and the code.py module requires q to be strictly defined before
 function b, then it is too strict. Your analysis of the bug as being in
 code.py seems plausible.

Yeah. I came across this as I was knocking together a test for
something else, and my work-around was to define the inner function as
just pass, and then go back and edit in the nonlocal declaration
after adding the assignment outside. The only problem is that it's
syntax-checking something that's only half-entered, and is bombing on
it - thus stopping you from typing in the bit that would make it
valid.

Thanks Terry for the extra info on the tracker issue.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Animated PNG Vs Gif: 120fr 3D Python Powered Logo

2013-10-22 Thread Terry Reedy

On 10/22/2013 1:28 AM, Metallicow wrote:

Here is links to the apng/gif on ImageShack uploaded with the Do Not Resize 
option.
Checked/Views fine with default Firefox/Opera browsers.

Animated 3D Python Powered Logo
apng - 120frames 1/60 sec
http://img34.imageshack.us/img34/4717/f4l4.png


Neat: I would actually have the rotation slower, but still smoothed.


gif - 120frames about 1/10sec or as fast as it can go...
http://img35.imageshack.us/img35/4231/j29.gif


I can see the jerking.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Newline in bash, was Re: IDLE being too clever checking nonlocal declarations?

2013-10-22 Thread Peter Otten
Steven D'Aprano wrote:

 On Mon, 21 Oct 2013 23:26:28 -0400, Terry Reedy wrote:
 
 On 10/21/2013 7:52 PM, Steven D'Aprano wrote:
 On Mon, 21 Oct 2013 15:51:56 -0400, Terry Reedy wrote:

 On 10/21/2013 11:06 AM, Chris Angelico wrote:
 Try typing this into IDLE:

 def a():
   def b():
   nonlocal q
 SyntaxError: no binding for nonlocal 'q' found

 If you submit those three lines to Python from the command line, that
 is what you see.

 Arguably, that's also too strict,
 
 As I quoted from the doc, it is an error for a program to contain a
 nonlocal with no referent. The reason is one only needs nonlocal to bind
 and unlike with 'global newname', it would be undefined where to do the
 binding.
 
 Yep, I got that, but what I'm saying is that it is too strict to raise
 the exception at the point where it sees nonlocal q. The CPython
 interpreter allows q to be defined inside function a but after function
 b, e.g. this is allowed:
 
 def a():
 def b():
 nonlocal q
 q += 1
 q = 2  # ===
 
 
 If IDLE and the code.py module requires q to be strictly defined before
 function b, then it is too strict. Your analysis of the bug as being in
 code.py seems plausible.
 
 
 
 [steve@ando ~]$ python3.3 -c def a():
  def b():
  nonlocal q
  q = 1
 
 
 What system lets you do that? (See other thread about Windows not
 allowing that, because newline terminates the command even after .) Is
 '' a line continuation marker (like '...' in Python)?
 
 Yes, sorry I should have said. That's bash, under Linux.
 
 Here's another way:
 
 
 steve@runes:~$ python3.3 -c def a():^M  def b():^Mnonlocal q^M
 q=1^Mprint(a() is None)
 True
 
 
 Still bash under Linux (a different machine), the ^M is *not* a pair of
 characters ^ followed by M but an actually newline, generated by typing
 Ctrl-V Enter (that's the ENTER key, not the letters E n t e r).
 
 In theory I should be able to get something working with \n escapes
 instead of ^M, but I can't get it working. But I'm not an expect at bash's
 arcane rules for quoting and escaping special characters.

I usually just hit Return...

$ python3.3 -c def a():
   def b():
 nonlocal q
   q = 1
 print(a() is None)
True

but you prompted me to google:

$ python3.3 -c $'def a():\n def b():\n  nonlocal q\n q = 1\nprint(a() is None)'
True


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python -c commands on windows.

2013-10-22 Thread Peter Otten
Terry Reedy wrote:

 Manual says -c command
  Execute the Python code in command. command can be one or more
 statements separated by newlines, with significant leading whitespace as
 in normal module code.
 
 In Windows Command Prompt I get:
 C:\Programs\Python33python -c a=1\nprint(a)
File string, line 1
  a=1\nprint(a)
  ^
 SyntaxError: unexpected character after line continuation character
 (Same if I remove quotes.)
 
 How do I get this to work?

From the odd workarounds department (not tested on Windows):
 
$ python3 -c exec('a=1\nprint(a)')
1


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-22 Thread Lele Gaifax
Roy Smith r...@panix.com writes:

 You missed the ever-so-special Objective C syntax:

 [object method arg1 withSomething arg2 withSomethingElse arg3]

 I'm sure I got that slightly wrong.  I don't do Objective C, and my eyes 
 glaze over every time I have to read it.

The actual syntax would be

  [object method: arg1 withSomething: arg2 withSomethingElse: arg3]

and IMHO once you train your eyes the result is very readable, and
closely resembles Python's keywords (and I took advantage of the
similarity when I enjoyed developing PyObjC :)

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-22 Thread Peter Cacioppi
rusi said :

You continue to not attribute quotes. 

Sorry, I'll try to be better about this all-important aspect of sharing 
knowledge.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Animated PNG Vs Gif: 120fr 3D Python Powered Logo

2013-10-22 Thread Ian Kelly
On Mon, Oct 21, 2013 at 11:28 PM, Metallicow metaliobovi...@gmail.com wrote:
 Here is links to the apng/gif on ImageShack uploaded with the Do Not Resize 
 option.
 Checked/Views fine with default Firefox/Opera browsers.

 Animated 3D Python Powered Logo
 apng - 120frames 1/60 sec
 http://img34.imageshack.us/img34/4717/f4l4.png

 gif - 120frames about 1/10sec or as fast as it can go...
 http://img35.imageshack.us/img35/4231/j29.gif

This is not entirely true.  The minimum specifiable delay for a frame
in an animated gif (other than 0, which just means as fast as
possible) is 0.01 second, which is the setting in the gif linked
above.  However, most browsers that encounter this will automatically
increase the delay to 0.1 second.  This is done for compatibility with
old versions of Netscape.  According to [1], Firefox, Opera and Chrome
will accurately display delays as small as 0.02 seconds.  Safari and
IE will accurately display delays as small as 0.06 seconds.

Here is an alternate version of the above gif that displays the
animation at 50 fps in the first three browsers listed above:
http://i216.photobucket.com/albums/cc41/Peristarkawan/j29-2.gif

And here it is at 17 fps with 2/3 of the frames removed, for the
benefit of IE and Safari:
http://i216.photobucket.com/albums/cc41/Peristarkawan/j29-6.gif

[1] 
http://nullsleep.tumblr.com/post/16524517190/animated-gif-minimum-frame-delay-browser-compatibility
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Antoine Pitrou
Philip Herron herron.philip at googlemail.com writes:
 
 Its interesting a few things come up what about:
 
 exec and eval. I didn't really have a good answer for this at my talk at
PYCon IE 2013 but i am going to say no. I am
 not going to implement these. Partly because eval and exec at least to me
are mostly from developing
 interpreters as a debugging exercise so the test doesn't have to invoke
the program properly and feed in
 strings to interpret at least thats what i have done in the past with an
virtual machine i wrote before gccpy.

If you don't implement exec() and eval() then people won't be able to use
namedtuples, which are a common datatype factory.

As for the rest: well, good luck writing an AOT compiler producing
interesting results on average *pure* Python code. It's already been tried
a number of times, and has generally failed. Cython mitigates the issue by
exposing a superset of Python (including type hints, etc.).

Regards

Antoine.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Philip Herron
On Tuesday, 22 October 2013 09:55:15 UTC+1, Antoine Pitrou  wrote:
 Philip Herron herron.philip at googlemail.com writes:
 
  
 
  Its interesting a few things come up what about:
 
  
 
  exec and eval. I didn't really have a good answer for this at my talk at
 
 PYCon IE 2013 but i am going to say no. I am
 
  not going to implement these. Partly because eval and exec at least to me
 
 are mostly from developing
 
  interpreters as a debugging exercise so the test doesn't have to invoke
 
 the program properly and feed in
 
  strings to interpret at least thats what i have done in the past with an
 
 virtual machine i wrote before gccpy.
 
 
 
 If you don't implement exec() and eval() then people won't be able to use
 
 namedtuples, which are a common datatype factory.
 
 
 
 As for the rest: well, good luck writing an AOT compiler producing
 
 interesting results on average *pure* Python code. It's already been tried
 
 a number of times, and has generally failed. Cython mitigates the issue by
 
 exposing a superset of Python (including type hints, etc.).
 
 
 
 Regards
 
 
 
 Antoine.
Thanks for that interesting example, i haven't looked into how its implemented 
but on initially looking at this is am nearly sure i can implement this without 
using exec or eval. I've found this a lot in implementing my run time. Exec and 
eval at least to me in the past I've used them as debug hooks into a toy 
virtual machine i wrote i don't particularly think they are part of a language 
nor should people really use them.

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Oscar Benjamin
On 22 October 2013 00:41, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 On Mon, 21 Oct 2013 10:55:10 +0100, Oscar Benjamin wrote:

 On 21 October 2013 08:46, Steven D'Aprano st...@pearwood.info wrote:

 On the contrary, you have that backwards. An optimizing JIT compiler
 can often produce much more efficient, heavily optimized code than a
 static AOT compiler, and at the very least they can optimize different
 things than a static compiler can. This is why very few people think
 that, in the long run, Nuitka can be as fast as PyPy, and why PyPy's
 ultimate aim to be faster than C is not moonbeams:

 That may be true but both the examples below are spurious at best. A
 decent AOT compiler would reduce both programs to the NULL program as
 noted by haypo:
 http://morepypy.blogspot.co.uk/2011/02/pypy-faster-than-c-on-carefully-
 crafted.html?showComment=1297205903746#c2530451800553246683

 Are you suggesting that gcc is not a decent compiler?

No.

 If optimize away
 to the null program is such an obvious thing to do, why doesn't the most
 popular C compiler in the [FOSS] world do it?

It does if you pass the appropriate optimisation setting (as shown in
haypo's comment). I should have been clearer.

gcc compiles programs in two phases: compilation and linking.
Compilation creates the object files x.o and y.o from x.c and y.c.
Linking creates the output binary a.exe from x.o and y.o. The -O3
optimisation setting used in the blog post enables optimisation in the
compilation phase. However each .c file is compiled independently so
because the add() function is defined in x.c and called in y.c the
compiler is unable to inline it. It also can't remove it as dead code
because although it knows that the return value isn't used it doesn't
know if the call has side effects.

You might think it's silly that gcc can't optimise across source files
and if so you're right because actually it can if you enable link time
optimisation with the -flto flag as described by haypo. So if I do
that with the code from the blog post I get (using mingw gcc 4.7.2 on
Windows):

$ cat x.c
double add(double a, double b)
{
  return a + b;
}
$ cat y.c
double add(double a, double b);

int main()
{
  int i = 0;
  double a = 0;
  while (i  10) {
a += 1.0;
add(a, a);
i++;
  }
}
$ gcc -O3 -flto x.c y.c
$ time ./a.exe

real0m0.063s
user0m0.015s
sys 0m0.000s
$ time ./a.exe  # warm cache

real0m0.016s
user0m0.015s
sys 0m0.015s

So gcc can optimise this all the way to the null program which takes
15ms to run (that's 600 times faster than pypy).

Note that even if pypy could optimise it all the way to the null
program it would still be 10 times slower than C's null program:

$ touch null.py
$ time pypy null.py

real0m0.188s
user0m0.076s
sys 0m0.046s
$ time pypy null.py  # warm cache

real0m0.157s
user0m0.060s
sys 0m0.030s

 [...]
 So the pypy version takes twice as long to run this. That's impressive
 but it's not faster than C.

(Actually if I enable -flts with that example the C version runs 6-7
times faster due to inlining.)

 Nobody is saying that PyPy is *generally* capable of making any arbitrary
 piece of code run as fast as hand-written C code. You'll notice that the
 PyPy posts are described as *carefully crafted* examples.

They are more than carefully crafted. They are useless and misleading.
It's reasonable to contrive of a simple CPU-intensive programming
problem for benchmarking. But the program should do *something* even
if it is contrived. Both programs here consist *entirely* of dead
code. Yes it's reasonable for the pypy devs to test things like this
during development. No it's not reasonable to showcase this as an
example of the potential for pypy to speed up any useful computation.

 I believe that, realistically, PyPy has potential to bring Python into
 Java and .Net territories, namely to run typical benchmarks within an
 order of magnitude of C speeds on the same benchmarks. C is a very hard
 target to beat, because vanilla C code does *so little* compared to other
 languages: no garbage collection, no runtime dynamism, very little
 polymorphism. So benchmarking simple algorithms plays to C's strengths,
 while ignoring C's weaknesses.

As I said I don't want to criticise PyPy. I've just started using it
and I it is impressive. However both of those blog posts are
misleading. Not only that but the authors must know exactly why they
are misleading. Because of that I will take any other claims with a
big pinch of salt in future.


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Philip Herron
On Tuesday, 22 October 2013 10:14:16 UTC+1, Oscar Benjamin  wrote:
 On 22 October 2013 00:41, Steven D'Aprano
 
  On the contrary, you have that backwards. An optimizing JIT compiler
 
  can often produce much more efficient, heavily optimized code than a
 
  static AOT compiler, and at the very least they can optimize different
 
  things than a static compiler can. This is why very few people think
 
  that, in the long run, Nuitka can be as fast as PyPy, and why PyPy's
 
  ultimate aim to be faster than C is not moonbeams:
 
 
 
  That may be true but both the examples below are spurious at best. A
 
  decent AOT compiler would reduce both programs to the NULL program as
 
  noted by haypo:
 
  http://morepypy.blogspot.co.uk/2011/02/pypy-faster-than-c-on-carefully-
 
  crafted.html?showComment=1297205903746#c2530451800553246683
 
 
 
  Are you suggesting that gcc is not a decent compiler?
 
 
 
 No.
 
 
 
  If optimize away
 
  to the null program is such an obvious thing to do, why doesn't the most
 
  popular C compiler in the [FOSS] world do it?
 
 
 
 It does if you pass the appropriate optimisation setting (as shown in
 
 haypo's comment). I should have been clearer.
 
 
 
 gcc compiles programs in two phases: compilation and linking.
 
 Compilation creates the object files x.o and y.o from x.c and y.c.
 
 Linking creates the output binary a.exe from x.o and y.o. The -O3
 
 optimisation setting used in the blog post enables optimisation in the
 
 compilation phase. However each .c file is compiled independently so
 
 because the add() function is defined in x.c and called in y.c the
 
 compiler is unable to inline it. It also can't remove it as dead code
 
 because although it knows that the return value isn't used it doesn't
 
 know if the call has side effects.
 
 
 
 You might think it's silly that gcc can't optimise across source files
 
 and if so you're right because actually it can if you enable link time
 
 optimisation with the -flto flag as described by haypo. So if I do
 
 that with the code from the blog post I get (using mingw gcc 4.7.2 on
 
 Windows):
 
 
 
 $ cat x.c
 
 double add(double a, double b)
 
 {
 
   return a + b;
 
 }
 
 $ cat y.c
 
 double add(double a, double b);
 
 
 
 int main()
 
 {
 
   int i = 0;
 
   double a = 0;
 
   while (i  10) {
 
 a += 1.0;
 
 add(a, a);
 
 i++;
 
   }
 
 }
 
 $ gcc -O3 -flto x.c y.c
 
 $ time ./a.exe
 
 
 
 real0m0.063s
 
 user0m0.015s
 
 sys 0m0.000s
 
 $ time ./a.exe  # warm cache
 
 
 
 real0m0.016s
 
 user0m0.015s
 
 sys 0m0.015s
 
 
 
 So gcc can optimise this all the way to the null program which takes
 
 15ms to run (that's 600 times faster than pypy).
 
 
 
 Note that even if pypy could optimise it all the way to the null
 
 program it would still be 10 times slower than C's null program:
 
 
 
 $ touch null.py
 
 $ time pypy null.py
 
 
 
 real0m0.188s
 
 user0m0.076s
 
 sys 0m0.046s
 
 $ time pypy null.py  # warm cache
 
 
 
 real0m0.157s
 
 user0m0.060s
 
 sys 0m0.030s
 
 
 
  [...]
 
  So the pypy version takes twice as long to run this. That's impressive
 
  but it's not faster than C.
 
 
 
 (Actually if I enable -flts with that example the C version runs 6-7
 
 times faster due to inlining.)
 
 
 
  Nobody is saying that PyPy is *generally* capable of making any arbitrary
 
  piece of code run as fast as hand-written C code. You'll notice that the
 
  PyPy posts are described as *carefully crafted* examples.
 
 
 
 They are more than carefully crafted. They are useless and misleading.
 
 It's reasonable to contrive of a simple CPU-intensive programming
 
 problem for benchmarking. But the program should do *something* even
 
 if it is contrived. Both programs here consist *entirely* of dead
 
 code. Yes it's reasonable for the pypy devs to test things like this
 
 during development. No it's not reasonable to showcase this as an
 
 example of the potential for pypy to speed up any useful computation.
 
 
 
  I believe that, realistically, PyPy has potential to bring Python into
 
  Java and .Net territories, namely to run typical benchmarks within an
 
  order of magnitude of C speeds on the same benchmarks. C is a very hard
 
  target to beat, because vanilla C code does *so little* compared to other
 
  languages: no garbage collection, no runtime dynamism, very little
 
  polymorphism. So benchmarking simple algorithms plays to C's strengths,
 
  while ignoring C's weaknesses.
 
 
 
 As I said I don't want to criticise PyPy. I've just started using it
 
 and I it is impressive. However both of those blog posts are
 
 misleading. Not only that but the authors must know exactly why they
 
 are misleading. Because of that I will take any other claims with a
 
 big pinch of salt in future.
 
 
 
 
 
 Oscar

You sir deserve a medal! I think alot of people are taking these sorts of 
benchmarks completely out of context and its great to see such a well rounded 

Re: Python Front-end to GCC

2013-10-22 Thread Steven D'Aprano
On Tue, 22 Oct 2013 08:55:15 +, Antoine Pitrou wrote:

 If you don't implement exec() and eval() then people won't be able to
 use namedtuples, which are a common datatype factory.


Philip could always supply his own implementation of namedtuple that 
doesn't use exec.

But either way, if he doesn't implement eval and exec, what he has is not 
Python, but a subset of Python. Perhaps an interesting and useful subset.

-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python -c commands on windows.

2013-10-22 Thread Oscar Benjamin
On 21 October 2013 21:47, Terry Reedy tjre...@udel.edu wrote:
 Manual says -c command
 Execute the Python code in command. command can be one or more
 statements separated by newlines, with significant leading whitespace as in
 normal module code.

 In Windows Command Prompt I get:
 C:\Programs\Python33python -c a=1\nprint(a)
   File string, line 1
 a=1\nprint(a)
 ^
 SyntaxError: unexpected character after line continuation character
 (Same if I remove quotes.)

 How do I get this to work?

By not using cmd.exe.

On Windows I use git bash which I think is just bash from msys. If
you find yourself spending any time using cmd.exe you'll appreciate
why. I also use console2 as the GUI part of the terminal.

In bash it's a simple matter of opening a single quote and then typing
what you want including hitting enter (don't use single quotes in the
Python code):

$ python -c '
 a = 1
 if a:
   print(a was true)
 '
a was true


Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python -c commands on windows.

2013-10-22 Thread Chris Angelico
On Tue, Oct 22, 2013 at 9:42 PM, Oscar Benjamin
oscar.j.benja...@gmail.com wrote:
 On Windows I use git bash which I think is just bash from msys. If
 you find yourself spending any time using cmd.exe you'll appreciate
 why. I also use console2 as the GUI part of the terminal.

Heh, me too. According to its title bar, it's a MINGW32 build (or at
least, the one I have is). I installed nano into it, and I can
basically run my git repos the same way I do under Linux.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-22 Thread Skip Montanaro
Steven wrote:

 The world is much bigger than just the C family of languages.

And even within that space, the original authors of C left plenty of
room for debate/improvement. In at least two dimensions (object
oriented programming, and memory management), various C descendants
have tried multiple different approaches to solve those problems.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Steven D'Aprano
On Tue, 22 Oct 2013 10:14:16 +0100, Oscar Benjamin wrote:

 On 22 October 2013 00:41, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
 On Mon, 21 Oct 2013 10:55:10 +0100, Oscar Benjamin wrote:

 On 21 October 2013 08:46, Steven D'Aprano st...@pearwood.info wrote:

 On the contrary, you have that backwards. An optimizing JIT compiler
 can often produce much more efficient, heavily optimized code than a
 static AOT compiler, and at the very least they can optimize
 different things than a static compiler can. This is why very few
 people think that, in the long run, Nuitka can be as fast as PyPy,
 and why PyPy's ultimate aim to be faster than C is not moonbeams:

 That may be true but both the examples below are spurious at best. A
 decent AOT compiler would reduce both programs to the NULL program as
 noted by haypo:
 http://morepypy.blogspot.co.uk/2011/02/pypy-faster-than-c-on-
carefully-
 crafted.html?showComment=1297205903746#c2530451800553246683

Keep in mind that the post's author, Maciej Fijalkowski, is not a native 
English speaker (to the best of my knowledge). You or I would probably 
have called the post a *contrived* example, not a carefully crafted one 
-- the meaning is the same, but the connotations are different.

Micro-benchmarks are mostly of theoretical interest, and contrived ones 
even more so, but still of interest. One needs to be careful not to read 
too much into them, but also not to read too little into them.


 Are you suggesting that gcc is not a decent compiler?
 
 No.
 
 If optimize away
 to the null program is such an obvious thing to do, why doesn't the
 most popular C compiler in the [FOSS] world do it?
 
 It does if you pass the appropriate optimisation setting (as shown in
 haypo's comment). I should have been clearer.

C can do nothing 10 times faster than Python! -- well, okay, but what 
does that tell you about my long-running web server app? Benchmarks at 
the best of time are only suggestive, benchmarks for null programs are 
even less useful.

The very next comment after Haypo is an answer to his observation: 

[quote]
@haypo print the result so the loop don't get removed as dead 
code. Besides, the problem is really the fact that's -flto is 
unfair since python imports more resemble shared libraries 
than statically-compiled files.


I'll be honest, I don't know enough C to really judge that claim, but I 
have noticed that benchmarks rarely compare apples and oranges, 
especially when C is involved. You can't eliminate all the differences 
between the code being generated, or at least not easily, since different 
languages have deep-seated differences in semantics that can't be 
entirely eliminated. But you should at least make some effort to compare 
code that does the same thing the same way.

Here's an example: responding to a benchmark showing a Haskell compiler 
generating faster code than a C compiler, somebody re-wrote the C code 
and got the opposite result:

http://jacquesmattheij.com/when-haskell-is-not-faster-than-c

Again, I can't judge the validity of all of the changes he made, but one 
stood out like a sore thumb:

[quote]
C does not require you to set static global arrays to ‘0’, so the 
for loop in the main function can go...

Wait a minute... Haskell, I'm pretty sure, zeroes memory. C doesn't. So 
the C code is now doing less work. Yes, your C compiler will allow you to 
avoid zeroing memory before using it, and you'll save some time 
initially. But eventually[1] you will need to fix the security 
vulnerability by adding code to zero the memory, exactly as Haskell and 
other more secure languages already do. So *not* zeroing the memory is 
cheating. It's not something you'd do in real code, not if you care about 
security and correctness. Even if you don't care about security, you 
should care about benchmarking both languages performing the same amount 
of work.

Now, I may be completely off-base here. Some Haskell expert may chime up 
to say that Haskell does not, in fact, zero memory. But it does 
*something*, I'm sure, perhaps it tracks what memory is undefined and 
prevents reads from it, or something. Whatever it does, if it does it at 
runtime, the C benchmark better do the same thing, or it's an unfair 
comparison:

Safely drive to the mall obeying all speed limits and traffic signals in 
a Chevy Volt, versus speed down the road running red lights and stop 
signs in a Ford Taurus -- would it be any surprise that the Taurus is 
faster?

[...]
 They are more than carefully crafted. They are useless and misleading.
 It's reasonable to contrive of a simple CPU-intensive programming
 problem for benchmarking. But the program should do *something* even if
 it is contrived. Both programs here consist *entirely* of dead code.

But since the dead code is *not* eliminated, it is actually executed. If 
it's executed, it's not really dead, is it? Does it really matter that 
you don't do anything with the 

Re: Python Front-end to GCC

2013-10-22 Thread Chris Angelico
On Tue, Oct 22, 2013 at 11:00 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Given a sufficiently advanced static analyser, PyPy could probably
 special-case programs that do nothing. Then you're in a race to compare
 the speed at which the PyPy runtime environment can start up and do
 nothing, versus a stand-alone executable that has to start up and do
 nothing. If this is a benchmark that people care about, I suggest they
 need to get out more :-)

Like every benchmark, it has its uses. Just last week I was tinkering
with several high level languages in order to see which one would
start, do a fairly trivial task, and shut down, in the shortest space
of time. Why? Because I wanted that trivial task to be added to our
rapid-deployment sequence at a point where a human would be waiting on
it, and the task itself wasn't critical (it was an early-catcher for a
particular type of bug). Delaying my fellow developers by even one
second at that point would be unacceptable; the various options at my
disposal took anywhere from 250 to 750 ms (cold cache, which is what
matters) to run. Yes, I know a second isn't long. But I was trying to
sell a concept, and if I can say that it adds practically no time to
an interactive action, that's a lot better than even one second.
Considering that rapiding took about 1200ms (ish - again, cold cache)
previously, adding even just 250ms is noticeable. Benchmarking an
empty program would get very close to this actual real-world scenario.

(Eventually I merged the functionality into an unrelated script just
for the sake of saving on interpreter startup time.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


PY QT

2013-10-22 Thread Forsgren
I'm really embarrassed to be asking this, I feel that there is a really
simple answer to this, but I cant for the life of me find it. 
So, I have this app, which loads a ui, which has a scrollarea that is a
parent to a gridlayout.

So in QT designer it looks like this:

/someParentWidgets
scrollArea
 myGridLayout/


I then want to add a couple of Qtool buttons to  the GridLayout within my
python code, so i run a forloop:

/for name in mylist:   
btn =QtGui.QToolButton()   
btn.setText(str(name))

cols = self.myGridLayout.count()%6
rows = int(self.myGridLayout.count()/6)
self.myGridLayout.addWidget(btn,rows,cols)/

No errors, no complaining what so ever, but the buttons isn't showing in the
layout.
The thing is if I change my ui file to

/someParentWidgets
   myGridLayout
/

The buttons show perfectly fine! What am I missing? I've tried changing the
GridLayout to a verticalLayout, but same thing there...







--
View this message in context: http://python.6.x6.nabble.com/PY-QT-tp5036684.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
https://mail.python.org/mailman/listinfo/python-list


pip won't ignore system-installed files

2013-10-22 Thread Neal Becker
IIUC, it is perfectly legitimate to do install into --user to override system-
wide installed modules.  Thus, I should be able to do:

pip install --user --up blah

even though there is already a package blah in 
/usr/lib/pythonxxx/site_packages/...

But even with -I (ignore installed) switch, pip fails:

pip install --user --up -I matplotlib
...
 Installing collected packages: matplotlib, numpy, python-dateutil, tornado, 
pyparsing, nose, six
  Found existing installation: matplotlib 1.2.0
Uninstalling matplotlib:
Exception:
Traceback (most recent call last):
  File /usr/lib/python2.7/site-packages/pip-1.2.1-
py2.7.egg/pip/basecommand.py, line 107, in main
status = self.run(options, args)
  File /usr/lib/python2.7/site-packages/pip-1.2.1-
py2.7.egg/pip/commands/install.py, line 261, in run
requirement_set.install(install_options, global_options)
  File /usr/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py, line 
1162, in install
requirement.uninstall(auto_confirm=True)
  File /usr/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py, line 
495, in uninstall
paths_to_remove.remove(auto_confirm)
  File /usr/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py, line 
1492, in remove
renames(path, new_path)
  File /usr/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/util.py, line 
273, in renames
shutil.move(old, new)
  File /usr/lib64/python2.7/shutil.py, line 302, in move
os.unlink(src)
OSError: [Errno 13] Permission denied: '/usr/lib64/python2.7/site-
packages/matplotlib-1.2.0-py2.7.egg-info'

Can we please fix this?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pip won't ignore system-installed files

2013-10-22 Thread Skip Montanaro
On Tue, Oct 22, 2013 at 8:11 AM, Neal Becker ndbeck...@gmail.com wrote:
 IIUC, it is perfectly legitimate to do install into --user to override system-
 wide installed modules.  Thus, I should be able to do:

 pip install --user --up blah

 even though there is already a package blah in
 /usr/lib/pythonxxx/site_packages/...
...
 Can we please fix this?

Sounds like a job for a bug report (for pip, most likely), not so much
a post to comp.lang.python.

What happens if you omit --upgrade?

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PY QT

2013-10-22 Thread Vincent Vande Vyvre

Le 22/10/2013 15:01, Forsgren a écrit :

I'm really embarrassed to be asking this, I feel that there is a really
simple answer to this, but I cant for the life of me find it.
So, I have this app, which loads a ui, which has a scrollarea that is a
parent to a gridlayout.

So in QT designer it looks like this:

/someParentWidgets

scrollArea
 myGridLayout/


I then want to add a couple of Qtool buttons to  the GridLayout within my
python code, so i run a forloop:

/for name in mylist:

btn =QtGui.QToolButton()
btn.setText(str(name))

cols = self.myGridLayout.count()%6

rows = int(self.myGridLayout.count()/6)
self.myGridLayout.addWidget(btn,rows,cols)/

No errors, no complaining what so ever, but the buttons isn't showing in the
layout.
The thing is if I change my ui file to

/someParentWidgets

   myGridLayout

/

The buttons show perfectly fine! What am I missing? I've tried changing the
GridLayout to a verticalLayout, but same thing there...







--
View this message in context: http://python.6.x6.nabble.com/PY-QT-tp5036684.html
Sent from the Python - python-list mailing list archive at Nabble.com.


Why are you using % 6 on QLayout.count() ?

QLayout.count() returns the number of the items into the layout but not 
where are is.


If you want to know the number of rows and columns, you have rowCount() 
and columnCount().


Cheers

--
Vincent V.V.
Oqapy https://launchpad.net/oqapy . Qarte 
https://launchpad.net/qarte . PaQager https://launchpad.net/paqager

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Dave Angel
On 22/10/2013 08:00, Steven D'Aprano wrote:

 On Tue, 22 Oct 2013 10:14:16 +0100, Oscar Benjamin wrote:

   snip
 Here's an example: responding to a benchmark showing a Haskell compiler 
 generating faster code than a C compiler, somebody re-wrote the C code 
 and got the opposite result:

 http://jacquesmattheij.com/when-haskell-is-not-faster-than-c

 Again, I can't judge the validity of all of the changes he made, but one 
 stood out like a sore thumb:

 [quote]
 C does not require you to set static global arrays to ‘0’, so the 
 for loop in the main function can go...

 Wait a minute... Haskell, I'm pretty sure, zeroes memory. C doesn't. So 

Static int variables are in fact zeroed.  However, most C compilers do
it by putting four bytes (or whatever) into the image of the
executable so it has no runtime cost.

snip
 But eventually[1] you will need to fix the security
 vulnerability by adding code to zero the memory, exactly as Haskell and 
 other more secure languages already do. So *not* zeroing the memory is
 cheating. It's not something you'd do in real code, not if you care
 about security and correctness.

I agree with most of what you say in the message, but here you go on to
say the C code is unsafely skipping initialization, which is not the
case.

By the way, a C compiler typically handles any initialization of a
static variable the same way.  So if you declare and initialize a static
variable as

int  myvar = 34 * 768;

it'll put the product directly in the executable image, and no runtime
code is generated.

Perhaps you were thinking of an automatic variable, which is not
initialized unless the programmer says so, and is then initialized with
code.

-- 
DaveA


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Oscar Benjamin
On 22 October 2013 13:00, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 On Tue, 22 Oct 2013 10:14:16 +0100, Oscar Benjamin wrote:

 On 22 October 2013 00:41, Steven D'Aprano 
 steve+comp.lang.pyt...@pearwood.info wrote:

 Are you suggesting that gcc is not a decent compiler?

 No.

 If optimize away
 to the null program is such an obvious thing to do, why doesn't the
 most popular C compiler in the [FOSS] world do it?

 It does if you pass the appropriate optimisation setting (as shown in
 haypo's comment). I should have been clearer.

 C can do nothing 10 times faster than Python! -- well, okay, but what
 does that tell you about my long-running web server app? Benchmarks at
 the best of time are only suggestive, benchmarks for null programs are
 even less useful.

This is precisely my point. They should show a benchmark that is not
semantically equivalent to the null program. I modified their example
to do that so that it wasn't simply a case of removing dead code and
then found that the C version performed 6-7 times faster than the PyPy
version. Had they simply stated that I would have been impressed.

At the bottom of this post I show a much better benchmark that shows
how PyPy can come very close to C performance for intensive floating
point computation. Note that although it is simple the benchmark
actually produces a result and none of the computation can be skipped
as dead code (why would I put that in?). Also note that both the C
binary and the script produce exactly the same numeric output. It's
also a simple example of numerical integration - something that is
often a bottleneck in scientific computation.

For the benchmark I find that the gcc -O3 binary runs in 4.6s and PyPy
runs the script in 6.9s (CPython 2.7 takes 600 seconds). That is
impressive and makes me think that there may be no need for me to use
C for things like that. To be sure I'd have to scale it up a bit to
see what happens when I break it apart into many functions and use
lists in PyPy vs arrays in C.

 [...]
 They are more than carefully crafted. They are useless and misleading.
 It's reasonable to contrive of a simple CPU-intensive programming
 problem for benchmarking. But the program should do *something* even if
 it is contrived. Both programs here consist *entirely* of dead code.

 But since the dead code is *not* eliminated, it is actually executed. If
 it's executed, it's not really dead, is it? Does it really matter that
 you don't do anything with the result? I'm with Maciej on this one --
 *executing* the code given is faster in PyPy than in C, at least for this
 C compiler. Maybe C is faster to not execute it. Is that really an
 interesting benchmark? C does nothing ten times faster than PyPy does
 something!

I don't think it is reasonable to compare those things and I was
joking when I said that the optimised C version was 600 times faster
because this is an absurd benchmark - see the much better one below.

 Given a sufficiently advanced static analyser, PyPy could probably
 special-case programs that do nothing. Then you're in a race to compare
 the speed at which the PyPy runtime environment can start up and do
 nothing, versus a stand-alone executable that has to start up and do
 nothing. If this is a benchmark that people care about, I suggest they
 need to get out more :-)

Like Chris I have also had situations where startup time mattered and
it can vary substantially between different interpreters and binaries.
I have GNU Octave on Windows and it literally takes 20 seconds to
start up. Matlab is worse: it takes about 1 minute so I don't tend to
use it for CLI scripts much.


Oscar


The benchmark:

$ cat euler.py
#!/usr/bin/env pypy

import math

def main():
x = 1
v = 0
t = 0
T = 1
dt = 2**-30
while t  T:
dxdt = v
dvdt = - x
x += dt * dxdt
v += dt * dvdt
t += dt
print('t = %.2e' % t)
print('x = %.2e' % x)
print('v = %.2e' % v)
print('x_err = %.e' % (x - math.cos(t)))
print('x_err = %.2e' % (v + math.sin(t)))

main()
$ time pypy euler.py
t = 1.00e+00
x = 5.40e-01
v = -8.41e-01
x_err = 3e-10
x_err = -3.92e-10

real0m6.907s
user0m0.076s
sys 0m0.045s
$ cat euler.c
#include stdio.h
#include math.h

int main()
{
double x = 1;
double v = 0;
double t = 0;
double T = 1;
double dt = pow(2, -30);
double dxdt, dvdt;
while (t  T)
{
dxdt = v;
dvdt = - x;
x += dt * dxdt;
v += dt * dvdt;
t += dt;
}
printf(t = %.2e\n, t);
printf(x = %.2e\n, x);
printf(v = %.2e\n, v);
printf(x_err = %.e\n, x - cos(t));
printf(x_err = %.2e\n, v + sin(t));

return 0;
}
$ gcc -O3 euler.c
$ time ./a.exe
t = 1.00e+000
x = 5.40e-001
v = -8.41e-001
x_err = 3e-010
x_err = -3.92e-010

real0m4.609s
user0m0.015s
sys 0m0.000s

$ time python euler.py  # CPython 2.7
t = 1.00e+00
x = 5.40e-01
v = -8.41e-01
x_err = 3e-10
x_err = 

Re: Animated PNG Vs Gif: 120fr 3D Python Powered Logo

2013-10-22 Thread Metallicow
On Tuesday, October 22, 2013 2:56:33 AM UTC-5, Ian wrote:
 This is not entirely true.  The minimum specifiable delay for a frame
 in an animated gif (other than 0, which just means as fast as
 possible) is 0.01 second, which is the setting in the gif linked
 above.  However, most browsers that encounter this will automatically
 increase the delay to 0.1 second.  This is done for compatibility with
 old versions of Netscape.  According to [1], Firefox, Opera and Chrome
 will accurately display delays as small as 0.02 seconds.  Safari and
 IE will accurately display delays as small as 0.06 seconds.
 
 Here is an alternate version of the above gif that displays the
 animation at 50 fps in the first three browsers listed above:
 http://i216.photobucket.com/albums/cc41/Peristarkawan/j29-2.gif
 
 And here it is at 17 fps with 2/3 of the frames removed, for the
 benefit of IE and Safari:
 http://i216.photobucket.com/albums/cc41/Peristarkawan/j29-6.gif
 
 [1] 
 http://nullsleep.tumblr.com/post/16524517190/animated-gif-minimum-frame-delay-browser-compatibility

Thanks, I was having a bit of trouble trying to figure it out exactly myself in 
blender by eye-sight. 
Interesting Test link.

When I originally rendered the animation it was transparent background, but 
when giffed it looked rather sick with gifs limited transparency and colors 
specs, so I rerendered and modded the text back into it on white which is what 
the other PSF logos have.
After looking at Firefox's spinning fox APNG on transparent, I think I will 
rerender the images again with transparency for the apng, so background color 
can be easily changed.
It seems the delays are not altered on the apngs also, which is a good thing.
Maybe there is an option with the browsers to disable gif 0 delay mangling...?
 
So What did you use to increase the speed of the gif? ...Errm Program or 
whatever used to mod it? I made the gif with gimp, since I find 
importing/exporting as layers a bit easier than using imageready. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Mark Janssen
I love it.  Watch this...

[context]
 A language specification in BNF is just syntax. It doesn't say anything
 about semantics. So how could this be used to produce executable C code
 for a program? BNF is used to produce parsers. But a parser isn't
 sufficient.

 A C program is just syntax also.  How does the compiler generate
 executable machine code?  Extrapolate into a Python front-end to C.

[Dave Angel responds:]
 Did you even read the paragraph you quoted above?  The BNF specification
 does NOT completely describe a language, it only defines its syntax.

[Steven D'Aprano responds:]
 Like every other language, C programs are certainly not *just* syntax.
 Here is some syntax:

 foo bar^ :=

Now, I don't know where y'all were taught Computer Science, but BNF
specifies not only syntax (which would be the *tokens* of a language),
but also its *grammar*;  how syntax relates to linguistic categories
like keywords, and tokens relate to each other.

Dave is claiming that BNF only defines the syntax of a language, but
then Stephen goes on to supply some syntax that a BNF specification of
the language would not allow (even though Steven calls it syntax
which is what BNF in Dave's claim parses).

So which of you is confused?  I ask that in the inclusive (not
exclusive OR) sense ;^)  -- face says both.

Mark Janssen
Tacoma, Washington.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Steven D'Aprano
On Tue, 22 Oct 2013 14:04:57 +, Dave Angel wrote:

[...]
 I agree with most of what you say in the message, 

Glad to hear I wasn't completely full of it. As a non-C developer, I'm 
very conscious that a lot of what I know about C is second hand.


 but here you go on to
 say the C code is unsafely skipping initialization, which is not the
 case.

Are you talking generically, or specifically about the C code referenced 
in the link I gave?

Memory is always zeroed is one of the advantages of Go over C and C++, 
at least according to Rob Pike:

http://commandcenter.blogspot.com.au/2012/06/less-is-exponentially-
more.html



 By the way, a C compiler typically handles any initialization of a
 static variable the same way.  So if you declare and initialize a static
 variable as
 
 int  myvar = 34 * 768;
 
 it'll put the product directly in the executable image, and no runtime
 code is generated.

Yes, that's a keyhole optimization, CPython does the same sort of thing:

py import dis
py dis.dis(compile(myvar = 34 * 768, , exec))
  1   0 LOAD_CONST   3 (26112)
  3 STORE_NAME   0 (myvar)
  6 LOAD_CONST   2 (None)
  9 RETURN_VALUE



 Perhaps you were thinking of an automatic variable, which is not
 initialized unless the programmer says so, and is then initialized with
 code.

No, I was thinking of an array. Arrays aren't automatically initialised 
in C.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Grant Edwards
On 2013-10-22, Dave Angel da...@davea.name wrote:
 On 22/10/2013 08:00, Steven D'Aprano wrote:

 [quote]
 C does not require you to set static global arrays to ?0?, so the 
 for loop in the main function can go...

 Wait a minute... Haskell, I'm pretty sure, zeroes memory. C doesn't. So 

 Static int variables are in fact zeroed.  However, most C compilers
 do it by putting four bytes (or whatever) into the image of the
 executable so it has no runtime cost.

No, that's not how gcc works (nor is it how any other C compiler I've
ever seen works).  Static variables get located in a bss section[1],
which is zeroed out at run-time by startup code that gets executed
before main() is called.  The ELF executable contains headers that
describe the size/location of bss section, but the object file
contains no actual _data_. 

[1] IIRC, the name bss is a historical hold-over from the PDP-11
assembler directive that is used to declare a section of memory
that is to be filled with zeros.  Not all compilers use that
section name, but they all use the same mechanism.

 int  myvar = 34 * 768;

 it'll put the product directly in the executable image, and no
 runtime code is generated.

That is true.

-- 
Grant Edwards   grant.b.edwardsYow! My EARS are GONE!!
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Grant Edwards
On 2013-10-22, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 On Tue, 22 Oct 2013 14:04:57 +, Dave Angel wrote:

 [...]
 I agree with most of what you say in the message, 

 Glad to hear I wasn't completely full of it. As a non-C developer, I'm 
 very conscious that a lot of what I know about C is second hand.


 but here you go on to
 say the C code is unsafely skipping initialization, which is not the
 case.

 Are you talking generically, or specifically about the C code
 referenced in the link I gave?

In C, static/global variables are always zeroed.

 Memory is always zeroed is one of the advantages of Go over C and C++, 
 at least according to Rob Pike:

 http://commandcenter.blogspot.com.au/2012/06/less-is-exponentially-more.html

Perhaps he's talking about automatic variables or malloc()ed memory?

You'd have to ask him.

 Perhaps you were thinking of an automatic variable, which is not
 initialized unless the programmer says so, and is then initialized with
 code.

 No, I was thinking of an array. Arrays aren't automatically initialised 
 in C.

If they are static or global, then _yes_they_are_.  They are zeroed.

-- 
Grant Edwards   grant.b.edwardsYow! I selected E5 ... but
  at   I didn't hear Sam the Sham
  gmail.comand the Pharoahs!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Ned Batchelder

On 10/22/13 11:04 AM, Mark Janssen wrote:

I love it.  Watch this...

[context]

A language specification in BNF is just syntax. It doesn't say anything
about semantics. So how could this be used to produce executable C code
for a program? BNF is used to produce parsers. But a parser isn't
sufficient.

A C program is just syntax also.  How does the compiler generate
executable machine code?  Extrapolate into a Python front-end to C.

[Dave Angel responds:]

Did you even read the paragraph you quoted above?  The BNF specification
does NOT completely describe a language, it only defines its syntax.

[Steven D'Aprano responds:]

Like every other language, C programs are certainly not *just* syntax.
Here is some syntax:

foo bar^ :=

Now, I don't know where y'all were taught Computer Science, but BNF
specifies not only syntax (which would be the *tokens* of a language),
but also its *grammar*;  how syntax relates to linguistic categories
like keywords, and tokens relate to each other.


Mark, you had expressed interest in an app that will take a language 
specification in BNF (complete with keywords and all) and output C code 
which is then compiled to an executable.   I'm interested in how that 
app might work.


Here's a BNF for a (very!) simple language:

program ::= number op number
op ::=  *!? | --+ | ..:

That means these are three valid programs:

123 *!? 456
2 --+ 2
1001 ..: 4

What will the app output as C code for each of these?



Dave is claiming that BNF only defines the syntax of a language, but
then Stephen goes on to supply some syntax that a BNF specification of
the language would not allow (even though Steven calls it syntax
which is what BNF in Dave's claim parses).

So which of you is confused?  I ask that in the inclusive (not
exclusive OR) sense ;^)  -- face says both.


Could you please be less snarky?  We're trying to communicate here, and 
it is not at all clear yet who is confused and who is not.  If you are 
interested in discussing technical topics, then discuss them.


--Ned.



Mark Janssen
Tacoma, Washington.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Class construction

2013-10-22 Thread Neil Cerutti
On 2013-10-21, Marcin Szamotulski msza...@gmail.com wrote:
 So the process (with some simplifications) goes like this:

 1. get metaclass: meta
 2. call meta.__prepare__ to get namespace (class __dict__)
 3. evaluate the class body in the namespace
 4. call meta with arguemnts: name, bases, namespace
   (when you instantiate any class in Python, metaclass is just
   a class, first its __new__ method is called, and then its __init__) 

 All this is in builtin__build_class__.

In addition, the Python manual describes the process in detail.
See The Python Language Reference 8.7 Class definitions.

Here's a link to the 3.3 version of those docs:

http://docs.python.org/3.3/reference/compound_stmts.html#class-definitions

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Antoine Pitrou
Steven D'Aprano steve+comp.lang.python at pearwood.info writes:
 
 On Tue, 22 Oct 2013 08:55:15 +, Antoine Pitrou wrote:
 
  If you don't implement exec() and eval() then people won't be able to
  use namedtuples, which are a common datatype factory.
 
 Philip could always supply his own implementation of namedtuple that 
 doesn't use exec.
 
 But either way, if he doesn't implement eval and exec, what he has is not 
 Python, but a subset of Python. Perhaps an interesting and useful subset.

If you go that way, we already have Cython (which is both a subset and
superset of Python, although I don't know if it's still a strict subset these
days).

Regards

Antoine.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Mark Lawrence

On 22/10/2013 16:46, Ned Batchelder wrote:


Could you please be less snarky?  We're trying to communicate here, and
it is not at all clear yet who is confused and who is not.  If you are
interested in discussing technical topics, then discuss them.

--Ned.



Well put, particularly when considering that both Dave Angel and Steven 
D'Aprano, the targets of the snarkiness, have been regular, helpful 
contributors over many years.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Benjamin Kaplan
On Tue, Oct 22, 2013 at 8:04 AM, Mark Janssen dreamingforw...@gmail.com wrote:
 I love it.  Watch this...

 [context]
 A language specification in BNF is just syntax. It doesn't say anything
 about semantics. So how could this be used to produce executable C code
 for a program? BNF is used to produce parsers. But a parser isn't
 sufficient.

 A C program is just syntax also.  How does the compiler generate
 executable machine code?  Extrapolate into a Python front-end to C.

 [Dave Angel responds:]
 Did you even read the paragraph you quoted above?  The BNF specification
 does NOT completely describe a language, it only defines its syntax.

 [Steven D'Aprano responds:]
 Like every other language, C programs are certainly not *just* syntax.
 Here is some syntax:

 foo bar^ :=

 Now, I don't know where y'all were taught Computer Science, but BNF
 specifies not only syntax (which would be the *tokens* of a language),
 but also its *grammar*;  how syntax relates to linguistic categories
 like keywords, and tokens relate to each other.

 Dave is claiming that BNF only defines the syntax of a language, but
 then Stephen goes on to supply some syntax that a BNF specification of
 the language would not allow (even though Steven calls it syntax
 which is what BNF in Dave's claim parses).

 So which of you is confused?  I ask that in the inclusive (not
 exclusive OR) sense ;^)  -- face says both.


I don't know where you were taught English, but syntax is  the way in
which linguistic elements (as words) are put together to form
constituents (as phrases or clauses) , not the set of valid words
(tokens) in a language. A grammar, such as those grammars written in
BNF, describe the rules for the syntax of a language. And, as Steven
said, it still doesn't describe the semantics of a language, which is
the set of instructions described by the syntax.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Steven D'Aprano
On Tue, 22 Oct 2013 15:39:42 +, Grant Edwards wrote:

 No, I was thinking of an array. Arrays aren't automatically initialised
 in C.
 
 If they are static or global, then _yes_they_are_.  They are zeroed.

Not that I don't believe you, but do you have a reference for this? 
Because I keep finding references to uninitialised C arrays filled with 
garbage if you don't initialise them.

Wait... hang on a second...

/fires up the ol' trusty gcc


[steve@ando c]$ cat array_init.c
#includestdio.h

int main()
{
  int i;
  int arr[10];
  for (i = 0; i  10; i++) {
printf(arr[%d] = %d\n, i, arr[i]);
}
printf(\n);
return 0;
}

[steve@ando c]$ gcc array_init.c
[steve@ando c]$ ./a.out
arr[0] = -1082002360
arr[1] = 134513317
arr[2] = 2527220
arr[3] = 2519564
arr[4] = -1082002312
arr[5] = 134513753
arr[6] = 1294213
arr[7] = -1082002164
arr[8] = -1082002312
arr[9] = 2527220


What am I missing here?


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Mark Lawrence

On 22/10/2013 17:40, Steven D'Aprano wrote:

On Tue, 22 Oct 2013 15:39:42 +, Grant Edwards wrote:


No, I was thinking of an array. Arrays aren't automatically initialised
in C.


If they are static or global, then _yes_they_are_.  They are zeroed.


Not that I don't believe you, but do you have a reference for this?
Because I keep finding references to uninitialised C arrays filled with
garbage if you don't initialise them.

Wait... hang on a second...

/fires up the ol' trusty gcc


[steve@ando c]$ cat array_init.c
#includestdio.h

int main()
{
   int i;
   int arr[10];
   for (i = 0; i  10; i++) {
 printf(arr[%d] = %d\n, i, arr[i]);
 }
 printf(\n);
 return 0;
}

[steve@ando c]$ gcc array_init.c
[steve@ando c]$ ./a.out
arr[0] = -1082002360
arr[1] = 134513317
arr[2] = 2527220
arr[3] = 2519564
arr[4] = -1082002312
arr[5] = 134513753
arr[6] = 1294213
arr[7] = -1082002164
arr[8] = -1082002312
arr[9] = 2527220


What am I missing here?




arr is local to main, not static or global.

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Chris Kaynor
On Tue, Oct 22, 2013 at 9:40 AM, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:

 On Tue, 22 Oct 2013 15:39:42 +, Grant Edwards wrote:

  No, I was thinking of an array. Arrays aren't automatically initialised
  in C.
 
  If they are static or global, then _yes_they_are_.  They are zeroed.

 Not that I don't believe you, but do you have a reference for this?
 Because I keep finding references to uninitialised C arrays filled with
 garbage if you don't initialise them.

 Wait... hang on a second...

 /fires up the ol' trusty gcc


 [steve@ando c]$ cat array_init.c
 #includestdio.h

 int main()
 {
   int i;
   int arr[10];
   for (i = 0; i  10; i++) {
 printf(arr[%d] = %d\n, i, arr[i]);
 }
 printf(\n);
 return 0;
 }

 [steve@ando c]$ gcc array_init.c
 [steve@ando c]$ ./a.out
 arr[0] = -1082002360
 arr[1] = 134513317
 arr[2] = 2527220
 arr[3] = 2519564
 arr[4] = -1082002312
 arr[5] = 134513753
 arr[6] = 1294213
 arr[7] = -1082002164
 arr[8] = -1082002312
 arr[9] = 2527220


 What am I missing here?


The array you made there is an auto variable (stack), not a static or a
global. Try one of the following (neither has been tested):

Static:

int main()
{
  int i;
  static int arr[10];
  for (i = 0; i  10; i++) {
printf(arr[%d] = %d\n, i, arr[i]);
}
printf(\n);
return 0;
}



Global:

int arr[10];
int main()
{
  int i;
  for (i = 0; i  10; i++) {
printf(arr[%d] = %d\n, i, arr[i]);
}
printf(\n);
return 0;
}

As for a reference:
http://stackoverflow.com/questions/1831290/static-variable-initialization
 and
http://stackoverflow.com/questions/3373108/why-are-static-variables-auto-initialized-to-zero,
both of which then reference the C++ standard.



 --
 Steven
 --
 https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Frank Miles
On Tue, 22 Oct 2013 16:40:32 +, Steven D'Aprano wrote:

 On Tue, 22 Oct 2013 15:39:42 +, Grant Edwards wrote:
 
 No, I was thinking of an array. Arrays aren't automatically
 initialised in C.
 
 If they are static or global, then _yes_they_are_.  They are zeroed.
 
 Not that I don't believe you, but do you have a reference for this?
 Because I keep finding references to uninitialised C arrays filled with
 garbage if you don't initialise them.
 
 Wait... hang on a second...
 
 /fires up the ol' trusty gcc
 
 
 [steve@ando c]$ cat array_init.c
 #includestdio.h
 
 int main()
 {
   int i;
   int arr[10];
   for (i = 0; i  10; i++) {
 printf(arr[%d] = %d\n, i, arr[i]);
 }
 printf(\n);
 return 0;
 }
 
 [steve@ando c]$ gcc array_init.c
 [steve@ando c]$ ./a.out
 arr[0] = -1082002360
 arr[1] = 134513317
 arr[2] = 2527220
 arr[3] = 2519564
 arr[4] = -1082002312
 arr[5] = 134513753
 arr[6] = 1294213
 arr[7] = -1082002164
 arr[8] = -1082002312
 arr[9] = 2527220
 
 
 What am I missing here?

What you're missing is that arr[] is an automatic variable.  Put
a static in front of it, or move it outside the function (to become
global) and you'll see the difference.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Steven D'Aprano
On Tue, 22 Oct 2013 08:04:21 -0700, Mark Janssen wrote:


 A language specification in BNF is just syntax. It doesn't say
 anything about semantics. So how could this be used to produce
 executable C code for a program? BNF is used to produce parsers. But
 a parser isn't sufficient.

 A C program is just syntax also.  How does the compiler generate
 executable machine code?  Extrapolate into a Python front-end to C.
 
 [Dave Angel responds:]
 Did you even read the paragraph you quoted above?  The BNF
 specification does NOT completely describe a language, it only defines
 its syntax.
 
 [Steven D'Aprano responds:]
 Like every other language, C programs are certainly not *just* syntax.
 Here is some syntax:

 foo bar^ :=
 
 Now, I don't know where y'all were taught Computer Science, 

Melbourne University Computer Science Department. How about you?


 but BNF
 specifies not only syntax (which would be the *tokens* of a language),
 but also its *grammar*;  how syntax relates to linguistic categories
 like keywords, and tokens relate to each other.

I'm not about to get into a debate about the difference between syntax 
and grammar as they apply to computer languages, because it doesn't 
matter. Neither syntax nor grammar tell you what something *means*, the 
semantics of the code. The parser knows that (say) x ^% y is legal and 
(say) x y ^% is not, but it doesn't know what machine code to generate 
when it sees x ^% y. That's not the job of the parser.

I expect that some compilers -- ancient ones, or lousy ones, or simple 
ones -- have a single routine that do all the parsing, lexing, code 
generation, linking, optimizing, etc., rather than separate routines that 
do the parsing, the code generation, and so on. But even those compilers 
cannot just take a description of the syntax and intuit what it means.

Syntax isn't enough. At some point, the compiler needs to know that ^ 
means to generate code to dereference pointers (like in Pascal), or 
perhaps it's bitwise or (like in C), or maybe even exponentiation (like 
in VisualBasic), or perhaps it's something completely different.


 Dave is claiming that BNF only defines the syntax of a language, but
 then Stephen goes on to supply some syntax that a BNF specification of
 the language would not allow (even though Steven calls it syntax which
 is what BNF in Dave's claim parses).

I think you have misunderstood me. I gave an example of some invented 
syntax that your hypothetical language might choose to use. Here it is 
again:

foo bar^ :=

Since I didn't provide the BNF specification for that syntax, you aren't 
in a position to say it is illegal. You should assume that it is legal 
syntax. If you really insist, I'll waste my time and yours and generate a 
BNF specification that allows that as valid syntax, or you could just 
accept that it's legal for this imaginary language.

Your task is to describe what the code does, and hence what machine code 
your hypothetical compiler will generate, when it sees that line of code.

You should be asking How the hell can I tell what that does? Exactly. 
That's the point. Neither can the compiler, not from syntax alone.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Neil Cerutti
On 2013-10-22, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 On Tue, 22 Oct 2013 14:04:57 +, Dave Angel wrote:
 but here you go on to say the C code is unsafely skipping
 initialization, which is not the case.

 Are you talking generically, or specifically about the C code
 referenced in the link I gave?

 Memory is always zeroed is one of the advantages of Go over C and C++, 
 at least according to Rob Pike:

 http://commandcenter.blogspot.com.au/2012/06/less-is-exponentially-
 more.html

Go initializes variables to defined zero values, not simply to
all-bits zero as (I think) C does.

This isn't as great a feature as it seems, since the zero value
for some built in types, e.g., map, is unusable without manual
construction. In addition, you can't define a zero value for your
own types.

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Steven D'Aprano
On Tue, 22 Oct 2013 16:53:07 +, Frank Miles wrote:

[snip C code]
 What you're missing is that arr[] is an automatic variable.  Put a
 static in front of it, or move it outside the function (to become
 global) and you'll see the difference.

Ah, that makes sense. Thanks to everyone who corrected my 
misunderstanding.

Well, actually, no it doesn't. I wonder why C specifies such behaviour? 
Why would you want non-global arrays to be filled with garbage?


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Piet van Oostrum
Mark Janssen dreamingforw...@gmail.com writes:

 I love it.  Watch this...

 [context]
 A language specification in BNF is just syntax. It doesn't say anything
 about semantics. So how could this be used to produce executable C code
 for a program? BNF is used to produce parsers. But a parser isn't
 sufficient.

 A C program is just syntax also.  How does the compiler generate
 executable machine code?  Extrapolate into a Python front-end to C.

 [Dave Angel responds:]
 Did you even read the paragraph you quoted above?  The BNF specification
 does NOT completely describe a language, it only defines its syntax.

 [Steven D'Aprano responds:]
 Like every other language, C programs are certainly not *just* syntax.
 Here is some syntax:

 foo bar^ :=

 Now, I don't know where y'all were taught Computer Science, but BNF
 specifies not only syntax (which would be the *tokens* of a language),
 but also its *grammar*;  how syntax relates to linguistic categories
 like keywords, and tokens relate to each other.

Syntax is grammar. Tokens are part of the grammar (but often specified 
separately with a different grammar, usually regular expressions, which is a 
subset of BNF).

So are you just confused or are you trollong?

-- 
Piet van Oostrum p...@vanoostrum.org
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Steven D'Aprano
On Tue, 22 Oct 2013 23:20:52 +1100, Chris Angelico wrote:

 Considering that rapiding took about 1200ms (ish - again, cold cache)
 previously, adding even just 250ms is noticeable.

Please excuse my skepticism, but in my experience, that would probably 
mean in practice:

... rapiding took about 1200ms, plus or minus 200ms, plus 500ms if the 
system is under load, plus 800ms if the developer vagued out for a 
moment, plus 1900ms if he happened to be scratching an itch, plus 2700ms 
if the anti-virus happened to be scanning something, plus 4100ms if the 
dev decided this was a good time to take a sip of coffee, plus 437000ms 
if he needed to make the coffee first, plus 7200ms if he was just 
taking a moment to check something on Reddit or answer an email...

I don't have a lot of sympathy for this sort of micro-optimization of 
interactive software, where the random variation from run to run is often 
larger than the time being optimized, and where the human element is 
usually one or two orders of magnitude greater still. Yes, developers 
complain when they have to wait for the computer for half a second, or at 
least the one time in thirty that they *notice* that they're waiting. The 
other 29 times the computer is actually waiting for them.

Still, I'm probably no better. Only instead of optimizing code, I tend to 
optimize travel time with short cuts that are guaranteed[1] to shave 
off a minute from a journey that takes thirty minutes, plus or minus six 
minutes. Show me a way to avoid waiting at traffic lights for 30s, and 
I'll take it, even if it means waiting for a break in the traffic at a 
Give Way sign for three minutes. So I shouldn't mock too much :-)

You're right, of course, that 1/4 second is noticeable. I just find it 
hard to credit that it's *significant* in the circumstances you're 
describing. But I could be wrong.



[1] Guarantee void in the presence of rain, fog, heavy winds, light 
winds, police radar traps, industrial action, civil protests, riots, 
wars, earthquakes, acts of God, or other cars.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Chris Kaynor
On Tue, Oct 22, 2013 at 10:23 AM, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:

 On Tue, 22 Oct 2013 16:53:07 +, Frank Miles wrote:

 [snip C code]
  What you're missing is that arr[] is an automatic variable.  Put a
  static in front of it, or move it outside the function (to become
  global) and you'll see the difference.

 Ah, that makes sense. Thanks to everyone who corrected my
 misunderstanding.

 Well, actually, no it doesn't. I wonder why C specifies such behaviour?
 Why would you want non-global arrays to be filled with garbage?


Its a performance benefit, for cases where you are going to fill the array
from other means, such as from a file or other sources such as literals.
The global and static variables are effectively free to zero due to
standard OS behaviours.

The issue is actually more general than arrays, as the same behavior exists
for all the types in C. Stack and heap variables have undefined value when
initialized, while global and static variables (which are really the same
thing, but with differing lexical scopes) are zero-filled.



 --
 Steven
 --
 https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Neil Cerutti
On 2013-10-22, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 On Tue, 22 Oct 2013 16:53:07 +, Frank Miles wrote:

 [snip C code]
 What you're missing is that arr[] is an automatic variable.  Put a
 static in front of it, or move it outside the function (to become
 global) and you'll see the difference.

 Ah, that makes sense. Thanks to everyone who corrected my 
 misunderstanding.

 Well, actually, no it doesn't. I wonder why C specifies such
 behaviour? Why would you want non-global arrays to be filled
 with garbage?

Fish(enc)ey.

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread MRAB

On 22/10/2013 18:23, Steven D'Aprano wrote:

On Tue, 22 Oct 2013 16:53:07 +, Frank Miles wrote:

[snip C code]

What you're missing is that arr[] is an automatic variable.  Put a
static in front of it, or move it outside the function (to become
global) and you'll see the difference.


Ah, that makes sense. Thanks to everyone who corrected my
misunderstanding.

Well, actually, no it doesn't. I wonder why C specifies such behaviour?
Why would you want non-global arrays to be filled with garbage?


Static variables need be initialised only once, whereas auto variables
exist on the stack, so they would need to be initialised repeatedly,
which was considered too expensive, especially as they would be
assigned to before use anyway (hopefully!).

Of course, these days, with our much faster CPUs, we're not so
bothered, and prefer to allocate on the heap.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Mark Janssen
 So which of you is confused?  I ask that in the inclusive (not
 exclusive OR) sense ;^)  -- face says both.

 Could you please be less snarky?  We're trying to communicate here, and it
 is not at all clear yet who is confused and who is not.  If you are
 interested in discussing technical topics, then discuss them.

Okay.  The purpose of BNF (at least as I envision it) is to
produce/specify a *context-free* grammar.  A lexer parses the tokens
specified in the BNF into an Abstract Syntax Tree.  If one can produce
such a tree for any given source, the language, in theory, can be
compiled by GCC into an executable.

Boom.
-- 
MarkJ
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


using smtp in python

2013-10-22 Thread ashikbekal
I'm trying to send an email using python. The mail content is taken from file 
and subject of the mail is name of the file. The program is invoked as 
./mailclient.py -f from email address -d recipient email address -i 
file1 -s server IP address
.
How to i use server ip address and the mail id to send the email ? (would i 
require the password)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Skip Montanaro
On Tue, Oct 22, 2013 at 12:50 PM, Mark Janssen
dreamingforw...@gmail.com wrote:
 Okay.  The purpose of BNF (at least as I envision it) is to
 produce/specify a *context-free* grammar.  A lexer parses the tokens
 specified in the BNF into an Abstract Syntax Tree.  If one can produce
 such a tree for any given source, the language, in theory, can be
 compiled by GCC into an executable.


Well, not quite. The lexer breaks the stream of characters up into
tokens, which are fed to the parser, which produces an abstract syntax
tree. From the WIkipedia entry:

In computer science, an abstract syntax tree (AST), or just syntax
tree, is a tree representation of the abstract syntactic structure of
source code written in a programming language. Each node of the tree
denotes a construct occurring in the source code.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread rusi
Mark Janssen said:
 Unattributed
  No its not like those 'compilers' i dont really agree with a compiler 
  generating C/C++ and saying its producing native code. I dont really 
  believe 
  its truely within the statement. Compilers that do that tend to put in alot 
  of type saftey code and debugging internals at a high level to get things 
  working in other projects i am not saying python compilers here i havent 
  analysed enough to say this.
  
 Hmm, well what I'd personally find interesting from a computer science
 point of view is a app that will take a language specification in BNF
 (complete with keywords and all) and output C code which is then
 compiled to an executable as normal.  This is how a front-end should
 be designed.  A middle-layer for translating common language elements
 like lists, sets, etc, could make it easy. 

Taking this starting sortie I was going to try to justify what Mark is saying.
Somewhat along the following lines.

Things like lex and yacc (and equivalents in ecosystems other than C) give a 
kind of holy-grail in the following sense.

When a writer of a lex/yacc spec does his thing, he does not need to think at 
the C level at all.  Given that executable C is produced (and ignoring 
mishaps/bugs like shift-reduce conflicts etc) its a very ideal situation.
The yacc-grammar (and its lex-helper) are completely declarative and yet they 
result in perfectly good ( O(n)) good C code.

Taking this cue from the syntax domain one can treat it as a holy grail for 
semantics. ie can one specify the semantics of a language completely 
declaratively and have a lex/yacc *analogous* magic wand and get out a 
compiler/interpreter etc.

Many people have pursued this holy grail but it remains elusive. Some examples:
1. Atribute grammars
2. Utrecht univs UUAG
3. Action semantics
etc

Note a key word above is analogous

However when I see this:


 Okay.  The purpose of BNF (at least as I envision it) is to
 produce/specify a *context-free* grammar.  A lexer parses the tokens
 specified in the BNF into an Abstract Syntax Tree.  If one can produce
 such a tree for any given source, the language, in theory, can be
 compiled by GCC into an executable. 

all I will say is eyes-roll
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread MRAB

On 22/10/2013 18:50, Mark Janssen wrote:

So which of you is confused?  I ask that in the inclusive (not
exclusive OR) sense ;^)  -- face says both.


Could you please be less snarky?  We're trying to communicate here, and it
is not at all clear yet who is confused and who is not.  If you are
interested in discussing technical topics, then discuss them.


Okay.  The purpose of BNF (at least as I envision it) is to
produce/specify a *context-free* grammar.  A lexer parses the tokens
specified in the BNF into an Abstract Syntax Tree.  If one can produce
such a tree for any given source, the language, in theory, can be
compiled by GCC into an executable.

Boom.


But you still need to specify the semantics.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Mark Janssen
 So which of you is confused?  I ask that in the inclusive (not
 exclusive OR) sense ;^)  -- face says both.

 Could you please be less snarky?

 Okay.  The purpose of BNF (at least as I envision it) is to
 produce/specify a *context-free* grammar.  A lexer parses the tokens
 specified in the BNF into an Abstract Syntax Tree.  If one can produce
 such a tree for any given source, the language, in theory, can be
 compiled by GCC into an executable.

 Boom.

 Hmm, I don't hear the boom yet.  An Abstract Syntax Tree is a tree
 representation of a program.  To use my previous example: the program 123
 *!? 456 would become a tree:

 op: *!?
 num: 123
 num: 456

 There's still not enough information to compile this.

Is your language Turing complete?

-- 
MarkJ
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Neil Cerutti
On 2013-10-22, Mark Janssen dreamingforw...@gmail.com wrote:
 So which of you is confused?  I ask that in the inclusive (not
 exclusive OR) sense ;^)  -- face says both.

 Could you please be less snarky?  We're trying to communicate here, and it
 is not at all clear yet who is confused and who is not.  If you are
 interested in discussing technical topics, then discuss them.

 Okay.  The purpose of BNF (at least as I envision it) is to
 produce/specify a *context-free* grammar.

Context-sensitive grammars can be parse, too.

 A lexer parses the tokens specified in the BNF into an Abstract
 Syntax Tree.  

A lexer traditionaly reads the text and generates a stream of
tokens to the parser.

 If one can produce such a tree for any given source, the
 language, in theory, can be compiled by GCC into an executable.

What executable would GCC compile from a program that matched
this grammar?

spamgram  = spam1,  { ', ', more_spam }, '.'
spam1 = 'Spam'
more_spam = spam, { ', ', spam }
spam  = 'spam'

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Mark Janssen
 Okay.  The purpose of BNF (at least as I envision it) is to
 produce/specify a *context-free* grammar.  A lexer parses the tokens
 specified in the BNF into an Abstract Syntax Tree.  If one can produce
 such a tree for any given source, the language, in theory, can be
 compiled by GCC into an executable.

 Boom.

 But you still need to specify the semantics.

In my world, like writing pseudo-code or flow-charts, the AST *is* the
semantics.  What world are you guys from?
-- 
MarkJ
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Mark Janssen
 Is your language Turing complete?


 1) No, it's not.
 2) So what?  That should make it easier to compile to C, if anything.
 3) Don't change the subject.

Well, if your language is not Turing complete, it is not clear that
you will be able to compile it at all.  That's the difference between
a calculator and a computer.

Thank you.  You may be seated.

Mark J
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Ned Batchelder

On 10/22/13 2:16 PM, Mark Janssen wrote:

So which of you is confused?  I ask that in the inclusive (not
exclusive OR) sense ;^)  -- face says both.

Could you please be less snarky?

Okay.  The purpose of BNF (at least as I envision it) is to
produce/specify a *context-free* grammar.  A lexer parses the tokens
specified in the BNF into an Abstract Syntax Tree.  If one can produce
such a tree for any given source, the language, in theory, can be
compiled by GCC into an executable.

Boom.

Hmm, I don't hear the boom yet.  An Abstract Syntax Tree is a tree
representation of a program.  To use my previous example: the program 123
*!? 456 would become a tree:

 op: *!?
 num: 123
 num: 456

There's still not enough information to compile this.

Is your language Turing complete?



1) No, it's not.
2) So what?  That should make it easier to compile to C, if anything.
3) Don't change the subject.

A BNF doesn't provide enough information to compile a program to C. 
That's all I'm trying to help you understand.  If you don't agree, then 
we have to talk about the meaning of the words BNF, compile, program, and C.


I applaud your interest in this topic.  I think you need to learn more 
before you try to claim expertise, though.


--Ned.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Ned Batchelder

On 10/22/13 2:22 PM, Mark Janssen wrote:

Okay.  The purpose of BNF (at least as I envision it) is to
produce/specify a *context-free* grammar.  A lexer parses the tokens
specified in the BNF into an Abstract Syntax Tree.  If one can produce
such a tree for any given source, the language, in theory, can be
compiled by GCC into an executable.

Boom.


But you still need to specify the semantics.

In my world, like writing pseudo-code or flow-charts, the AST *is* the
semantics.  What world are you guys from?


Mark, you started this by describing a program that compiled to C. Now 
you say you are in the world of pseudo-code and flow-charts. Which is it?


In the world where actual programs get compiled and run, you need to 
have semantics, and they aren't expressed in an AST or a BNF.  I think 
you think that an AST is enough, but it isn't.  I'm also not sure what 
you actually think because we don't stay on a topic long enough to get 
into the details that would shed light.


It's fun to feel like you are right, and it's easy if you change the 
topic when the going gets tough.  You've done this a number of times.


I've tried to be polite, and I've tried to be helpful, but I'm sorry: 
either you don't understand a lot of the terms you are throwing around, 
or you aren't disciplined enough to focus on a topic long enough to 
explain yourself.  Either way, I don't know how else to move the 
discussion forward.


--Ned.
--
https://mail.python.org/mailman/listinfo/python-list


Re: using smtp in python

2013-10-22 Thread Dan Stromberg
On Tue, Oct 22, 2013 at 11:00 AM, ashikbe...@gmail.com wrote:

 I'm trying to send an email using python. The mail content is taken from
 file and subject of the mail is name of the file. The program is invoked as
 ./mailclient.py -f from email address -d recipient email address
 -i file1 -s server IP address
 .
 How to i use server ip address and the mail id to send the email ? (would
 i require the password)
 --
 https://mail.python.org/mailman/listinfo/python-list


Some SMTP servers require a password and some do not.  I'm guessing more
and more do, as spammers attack.

Here's a module that shows how to do it with a password:
http://stromberg.dnsalias.org/svn/mailer/trunk/mailer.py

You can check it out with svn checkout url, or just browse to the URL in
a web browser.

HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread rusi
On Tuesday, October 22, 2013 11:53:22 PM UTC+5:30, Ned Batchelder wrote:
 A BNF doesn't provide enough information to compile a program to C. 
 That's all I'm trying to help you understand.  If you don't agree, then 
 we have to talk about the meaning of the words BNF, compile, program, and C.

I believe we need to talk about the Dunning-Kruger effect
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread MRAB

On 22/10/2013 19:22, Mark Janssen wrote:

Okay.  The purpose of BNF (at least as I envision it) is to
produce/specify a *context-free* grammar.  A lexer parses the tokens
specified in the BNF into an Abstract Syntax Tree.  If one can produce
such a tree for any given source, the language, in theory, can be
compiled by GCC into an executable.

Boom.


But you still need to specify the semantics.


In my world, like writing pseudo-code or flow-charts, the AST *is* the
semantics.  What world are you guys from?


The real world. :-)

So what you're saying is that you generate an AST where there are
certain pre-defined operations (primitives?) available?

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Grant Edwards
On 2013-10-22, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 On Tue, 22 Oct 2013 16:53:07 +, Frank Miles wrote:

 [snip C code]
 What you're missing is that arr[] is an automatic variable.  Put a
 static in front of it, or move it outside the function (to become
 global) and you'll see the difference.

 Ah, that makes sense. Thanks to everyone who corrected my 
 misunderstanding.

 Well, actually, no it doesn't. I wonder why C specifies such behaviour? 
 Why would you want non-global arrays to be filled with garbage?

Firstly, it's not non-global arrays that have undefined contents. 
It's _auto_ arrays that have undefined contents.

void foo(void)
{
  int a[4];   // non-global, _auto_ variable and has undefined contents
}

void bar(void)
{
  static int a[4];  // non-global, _static_ variable initially 0's
}

As to _why_ it's that way, you'd have to ask the guys who decided
that.  I supect it's because zeroing static variables involves very
little run-time overhead, while zeroing auto variables could cause
huge amounts of overhead if that auto variable is declared inside the
innermost of nested loops.  [Presumably a good optimizing compiler
would not zero an auto variable that was always set before it was
referenced, but it takes a lot of smarts for compiler to figure that
out correctly 100% of the time -- probably more smarts than a PDP-11
had room for.]

-- 
Grant Edwards   grant.b.edwardsYow! Let's send the
  at   Russians defective
  gmail.comlifestyle accessories!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Mark Lawrence

On 22/10/2013 19:40, rusi wrote:

On Tuesday, October 22, 2013 11:53:22 PM UTC+5:30, Ned Batchelder wrote:

A BNF doesn't provide enough information to compile a program to C.
That's all I'm trying to help you understand.  If you don't agree, then
we have to talk about the meaning of the words BNF, compile, program, and C.


I believe we need to talk about the Dunning-Kruger effect



No need for me to discuss that as I used to be big headed but now I'm 
perfect.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Grant Edwards
On 2013-10-22, Neil Cerutti ne...@norwich.edu wrote:
 On 2013-10-22, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 On Tue, 22 Oct 2013 14:04:57 +, Dave Angel wrote:
 but here you go on to say the C code is unsafely skipping
 initialization, which is not the case.

 Are you talking generically, or specifically about the C code
 referenced in the link I gave?

 Memory is always zeroed is one of the advantages of Go over C and C++, 
 at least according to Rob Pike:

 http://commandcenter.blogspot.com.au/2012/06/less-is-exponentially-
 more.html

 Go initializes variables to defined zero values, not simply to
 all-bits zero as (I think) C does.

C initializes to defined zero values.  For most machines in use today,
those values _happen_ to be all-bits-zero.

This makes the implementation trivial: chuck them all into some
pre-defined section (e.g. .bss), and then on startup, you zero-out
all the bits in the section without having to know what's where within
that section.  If you design a machine such that integer, pointer, and
FP representations where 0, NULL, and 0.0 are all zero-bits, then life
get's tougher for the guys writing the compiler and startup code.

But the language doesn't require or assume that initializer values are
all-bits-zero.  FP values have to be initizliaed to 0.0.  Int's have
to be initialized to integer value 0, pointers have to be initialized
to (void*)0. Nowhere it the languauge is it required or assumed that
any or all of those values are all represented by contiguous blocks of
all-zero-bits.

 This isn't as great a feature as it seems, since the zero value for
 some built in types, e.g., map, is unusable without manual
 construction. In addition, you can't define a zero value for your own
 types.

-- 
Grant Edwards   grant.b.edwardsYow! Oh my GOD -- the
  at   SUN just fell into YANKEE
  gmail.comSTADIUM!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Ned Batchelder

On 10/22/13 1:50 PM, Mark Janssen wrote:

So which of you is confused?  I ask that in the inclusive (not
exclusive OR) sense ;^)  -- face says both.

Could you please be less snarky?  We're trying to communicate here, and it
is not at all clear yet who is confused and who is not.  If you are
interested in discussing technical topics, then discuss them.

Okay.  The purpose of BNF (at least as I envision it) is to
produce/specify a *context-free* grammar.  A lexer parses the tokens
specified in the BNF into an Abstract Syntax Tree.  If one can produce
such a tree for any given source, the language, in theory, can be
compiled by GCC into an executable.

Boom.


Hmm, I don't hear the boom yet.  An Abstract Syntax Tree is a tree 
representation of a program.  To use my previous example: the program 
123 *!? 456 would become a tree:


op: *!?
num: 123
num: 456

There's still not enough information to compile this.  The operator *!? 
needs to have a meaning assigned to it.  That's the role of the semantic 
specification of a language.  That has to be provided somehow.  A BNF, 
or a grammar, or a syntax, or an AST can't provide the semantics.  That 
was the original point: syntax isn't enough.


--Ned.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Piet van Oostrum
Neil Cerutti ne...@norwich.edu writes:


 Context-sensitive grammars can be parse, too.

That's not English. Do you mean parsed? 

But context-sentitive grammars cannot be specified by BNF.
-- 
Piet van Oostrum p...@vanoostrum.org
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Neil Cerutti
On 2013-10-22, Piet van Oostrum p...@vanoostrum.org wrote:
 Neil Cerutti ne...@norwich.edu writes:
 Context-sensitive grammars can be parse, too.

 That's not English. Do you mean parsed? 

Thanks, yes, I meant parsed.

 But context-sentitive grammars cannot be specified by BNF.

Yes. I thought Mark might have had a misconception that all
programming languages have to be defined in BNF.

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Mark Lawrence

On 22/10/2013 20:20, Piet van Oostrum wrote:

Neil Cerutti ne...@norwich.edu writes:



Context-sensitive grammars can be parse, too.


That's not English. Do you mean parsed?

But context-sentitive grammars cannot be specified by BNF.



That's not English.  Do you mean context-sensitive? :)

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Mark Lawrence

On 22/10/2013 20:27, Neil Cerutti wrote:

On 2013-10-22, Piet van Oostrum p...@vanoostrum.org wrote:

Neil Cerutti ne...@norwich.edu writes:

Context-sensitive grammars can be parse, too.


That's not English. Do you mean parsed?


Thanks, yes, I meant parsed.


But context-sentitive grammars cannot be specified by BNF.


Yes. I thought Mark might have had a misconception that all
programming languages have to be defined in BNF.



Please be kind enough to disambiguate Mark, as I would not wish to be 
tarred with the same brush.


TIA.

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


http://natigaals7ab.blogspot.com

2013-10-22 Thread essan
http://natigaals7ab.blogspot.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Neil Cerutti
On 2013-10-22, Mark Lawrence breamore...@yahoo.co.uk wrote:
 On 22/10/2013 20:27, Neil Cerutti wrote:
 On 2013-10-22, Piet van Oostrum p...@vanoostrum.org wrote:
 Neil Cerutti ne...@norwich.edu writes:
 Context-sensitive grammars can be parse, too.

 That's not English. Do you mean parsed?

 Thanks, yes, I meant parsed.

 But context-sentitive grammars cannot be specified by BNF.

 Yes. I thought Mark might have had a misconception that all
 programming languages have to be defined in BNF.

 Please be kind enough to disambiguate Mark, as I would not wish
 to be tarred with the same brush.

Oops! I didn't notice he'd dropped out of the attributions. I was
speculating about Mark Janssen, not you.

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screenshots in Mac OS X

2013-10-22 Thread Pratik Mehta
Anyone there to help me out???
-- 
https://mail.python.org/mailman/listinfo/python-list


numpy masked_where

2013-10-22 Thread Wanderer
Why does the numpy masked_where create a special case for all False?

import numpy
x = numpy.array([[9,9,9,9,9,9],[9,9,9,9,9,9],[9,9,9,9,9,9],[9,9,9,9,9,9]])
y = numpy.ma.masked_where(x3,x)
y.mask
Out[1]: False
z= numpy.arange(20)
z.reshape(4,5)
Out[1]: 
array([[ 0,  1,  2,  3,  4],
   [ 5,  6,  7,  8,  9],
   [10, 11, 12, 13, 14],
   [15, 16, 17, 18, 19]])
y = numpy.ma.masked_where(z3,z)
y.mask
Out[1]: 
array([ True,  True,  True, False, False, False, False, False, False,
   False, False, False, False, False, False, False, False, False,
   False, False], dtype=bool)

Is there a good way to work around this and get an all False array?

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Grant Edwards
On 2013-10-22, Grant Edwards invalid@invalid.invalid wrote:

 C initializes to defined zero values.  For most machines in use today,
 those values _happen_ to be all-bits-zero.

 This makes the implementation trivial: chuck them all into some
 pre-defined section (e.g. .bss), and then on startup, you zero-out
 all the bits in the section without having to know what's where within
 that section.  If you design a machine such that integer, pointer, and
 FP representations where 0, NULL, and 0.0 are all zero-bits, then life
   ^
  not
  
 get's tougher for the guys writing the compiler and startup code.

-- 
Grant Edwards   grant.b.edwardsYow! We are now enjoying
  at   total mutual interaction in
  gmail.coman imaginary hot tub ...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screenshots in Mac OS X

2013-10-22 Thread Mark Lawrence

On 22/10/2013 21:15, Pratik Mehta wrote:

Anyone there to help me out???



There are plenty of people who will help you out, but if and only if you 
make an attempt at writing some code and then ask for assistance when 
you run into problems.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Tkinter tutorial?

2013-10-22 Thread Walter Hurry
I have some experience with Python, having used it for a couple of years.

Until now, my builder of choice for cross-platform GUI applications has 
been wxPython (with wxGlade), and I have been well satisfied with these 
tools.

However, for a different project I need to get up to a reasonable speed 
with tkinter. Could some kind soul recommend a suitable on-line tutorial, 
or a (free) ebook?

Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Animated PNG Vs Gif: 120fr 3D Python Powered Logo

2013-10-22 Thread Ian Kelly
On Tue, Oct 22, 2013 at 8:23 AM, Metallicow metaliobovi...@gmail.com wrote:
 Maybe there is an option with the browsers to disable gif 0 delay mangling...?

Perhaps there is, but you couldn't rely on the user to have changed it.

 So What did you use to increase the speed of the gif? ...Errm Program or 
 whatever used to mod it? I made the gif with gimp, since I find 
 importing/exporting as layers a bit easier than using imageready.

I used a freeware called Photoscape to open the gif, change the
delays, and resave it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter tutorial?

2013-10-22 Thread MRAB

On 22/10/2013 21:57, Walter Hurry wrote:

I have some experience with Python, having used it for a couple of years.

Until now, my builder of choice for cross-platform GUI applications has
been wxPython (with wxGlade), and I have been well satisfied with these
tools.

However, for a different project I need to get up to a reasonable speed
with tkinter. Could some kind soul recommend a suitable on-line tutorial,
or a (free) ebook?

Thanks.


Ask Google! :-)

In practice I've had to go looking for specific answers, but there's
info available from various places, such as:

http://effbot.org/tkinterbook/

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Chris Angelico
On Wed, Oct 23, 2013 at 4:27 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 On Tue, 22 Oct 2013 23:20:52 +1100, Chris Angelico wrote:

 Considering that rapiding took about 1200ms (ish - again, cold cache)
 previously, adding even just 250ms is noticeable.

 Please excuse my skepticism, but in my experience, that would probably
 mean in practice:

 ... rapiding took about 1200ms, plus or minus 200ms, plus 500ms if the
 system is under load, plus 800ms if the developer vagued out for a
 moment, plus 1900ms if he happened to be scratching an itch, plus 2700ms
 if the anti-virus happened to be scanning something, plus 4100ms if the
 dev decided this was a good time to take a sip of coffee, plus 437000ms
 if he needed to make the coffee first, plus 7200ms if he was just
 taking a moment to check something on Reddit or answer an email...

Yes; and more importantly, at the times when it actually would be
used, the cache will likely be warm.

 You're right, of course, that 1/4 second is noticeable. I just find it
 hard to credit that it's *significant* in the circumstances you're
 describing. But I could be wrong.

Yeah, but the problem here is a fundamental of human nature. I
mentioned earlier that I was trying to sell the notion of an instant
pre-check of the code. I use one myself, have done for ages, and it's
helped me often enough that I don't care if it occasionally adds a
second to my time. (I have a few such assistants that involve
searching through recent git commit messages, so they can take
multiple seconds if the cache is cold. I don't care; once it's in
cache, it's way faster.) But imagine sitting beside a skeptical fellow
developer and saying, Enable this line here and it'll catch these
sorts of bugs before you even spin it up in your testbox - and he
hits F7 and notices that it takes twice as long as he's used to.
That's going to make it a pretty hard sell. That's why I wanted to get
the time cost of the smoke test as low as I possibly could, even on a
cold cache.

(I'm used to tough sells at my workplace. It took years before we
adopted source control yes, seriously. And even once we did, I had
to fight to get other developers to make useful commits and commit
messages. One in particular - who, fortunately, is no longer with us -
saw the whole thing as a nuisance that got in the way of his genius,
so he'd just commit once at the end of the day with a barely-useful
message. But then, he was pretty astounding in a lot of other areas,
too - really amazing... like using the For-Case paradigm in PHP with
an off-by-one error...)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screenshots in Mac OS X

2013-10-22 Thread John Gordon
In 03db6a3f-3b1c-4516-8bee-4e3a362eb...@googlegroups.com Pratik Mehta 
pratik.mehta13...@gmail.com writes:

 Anyone there to help me out???

Command-Shift-3 takes a screenshot of the whole screen and saves it as a
file on the desktop.

Command-Control-Shift-3: takes a screenshot of the whole screen and saves
it to the clipboard.

For other options (such as taking a screenshot of a window or a specific
region on the screen), see
http://guides.macrumors.com/Taking_Screenshots_in_Mac_OS_X

I wonder what this has to do with Python though.

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

-- 
https://mail.python.org/mailman/listinfo/python-list


functools and objective usage

2013-10-22 Thread Mohsen Pahlevanzadeh
Dear all,

Suppose i have function name, 3 arguments for it, and object of its
caller such as self.blahbalah
So:
my function is:
self.blahblah.name(arg1,arg2,arg3)

I read functools documentations, may be objictive usage and
functionality differ, Do you have experience with objective usage ? 
http://docs.python.org/2/library/functools.html#partial-objects

I need to use it in my class,

Thank you,

Yours,
Mohsen


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: using smtp in python

2013-10-22 Thread xDog Walker
On Tuesday 2013 October 22 11:44, Dan Stromberg wrote:
 Some SMTP servers require a password and some do not

POP3 before SMTP ?

-- 
Yonder nor sorghum stenches shut ladle gulls stopper torque wet 
strainers.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter tutorial?

2013-10-22 Thread Ben Finney
Walter Hurry walterhu...@lavabit.com writes:

 However, for a different project I need to get up to a reasonable
 speed with tkinter. Could some kind soul recommend a suitable on-line
 tutorial, or a (free) ebook?

TkDocs URL:http://www.tkdocs.com/ is both a book for purchase (“Modern
Tkinter”) and a cross-language tutorial for Tk, taking full advantage of
modern features of Tk 8.5 and 8.6.

The example code attempts to hew quite closely to the original Tcl, so
it makes for rather awful Python. But you do learn how Tkinter works.

-- 
 \“If you continue running Windows, your system may become |
  `\unstable.” —Microsoft, Windows 95 bluescreen error message |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screenshots in Mac OS X

2013-10-22 Thread Kevin Walzer

On 10/22/13 4:15 PM, Pratik Mehta wrote:

Anyone there to help me out???



import os
os.system('screencapture', 'foo.png')


--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: functools and objective usage

2013-10-22 Thread Ben Finney
Mohsen Pahlevanzadeh moh...@pahlevanzadeh.org writes:

 Suppose i have function name, 3 arguments for it, and object of its
 caller such as self.blahbalah

This doesn't make much sense to me. I think you mean: You have an
object, ‘self.blahblah’, which has a function attribute, ‘name’.

(Aside: Please choose better example names, these make it rather
difficult to talk about.)

 So:
 my function is:
 self.blahblah.name(arg1,arg2,arg3)

Your *function* is ‘self.blahblah.name’.

One possible way to express a *call* that function is
‘self.blahblah.name(arg1, arg2, arg3)’.

 I read functools documentations, may be objictive usage and
 functionality differ, Do you have experience with objective usage ? 
 http://docs.python.org/2/library/functools.html#partial-objects

I don't understand what the question is. You have shown a way to call
your function; what do you want to do now?

 I need to use it in my class,

Feel free :-)

-- 
 \ “Pinky, are you pondering what I'm pondering?” “I think so, |
  `\Brain, but I find scratching just makes it worse.” —_Pinky and |
_o__)   The Brain_ |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Piet van Oostrum
Mark Janssen dreamingforw...@gmail.com writes:

 Is your language Turing complete?


 1) No, it's not.
 2) So what?  That should make it easier to compile to C, if anything.
 3) Don't change the subject.

 Well, if your language is not Turing complete, it is not clear that
 you will be able to compile it at all.  That's the difference between
 a calculator and a computer.

You think a language that is not Turing-complete cannot be compiled?
What nonsense is that. Please Mark, spare us your nonsense.
-- 
Piet van Oostrum p...@vanoostrum.org
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screenshots in Mac OS X

2013-10-22 Thread Kevin Walzer

On 10/22/13 6:08 PM, Kevin Walzer wrote:

On 10/22/13 4:15 PM, Pratik Mehta wrote:

Anyone there to help me out???



import os
os.system('screencapture', 'foo.png')



...and see 'man screencapture' for options.

I leave setting up a Tkinter GUI with proper key bindings as an exercise 
for the reader.


--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter tutorial?

2013-10-22 Thread Ethan Furman

On 10/22/2013 03:06 PM, Ben Finney wrote:

Walter Hurry walterhu...@lavabit.com writes:


However, for a different project I need to get up to a reasonable
speed with tkinter. Could some kind soul recommend a suitable on-line
tutorial, or a (free) ebook?


TkDocs URL:http://www.tkdocs.com/ is both a book for purchase (“Modern
Tkinter”) and a cross-language tutorial for Tk, taking full advantage of
modern features of Tk 8.5 and 8.6.

The example code attempts to hew quite closely to the original Tcl, so
it makes for rather awful Python. But you do learn how Tkinter works.


Awesome!  Just bought my copy.  :D

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Grant Edwards
On 2013-10-22, Mark Janssen dreamingforw...@gmail.com wrote:
 Is your language Turing complete?


 1) No, it's not.
 2) So what?  That should make it easier to compile to C, if anything.
 3) Don't change the subject.

 Well, if your language is not Turing complete, it is not clear that
 you will be able to compile it at all.

Whether a language is turing complete or not has _NOTHING_ to do with
whether it can be compiled or not.

 That's the difference between a calculator and a computer.

No, it isn't.

 Thank you.  You may be seated.

Dunno what you're smoking, but you sure are getting your money's
worth...

-- 
Grant

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: functools and objective usage

2013-10-22 Thread MRAB

On 22/10/2013 23:13, Ben Finney wrote:

Mohsen Pahlevanzadeh moh...@pahlevanzadeh.org writes:


Suppose i have function name, 3 arguments for it, and object of its
caller such as self.blahbalah


This doesn't make much sense to me. I think you mean: You have an
object, ‘self.blahblah’, which has a function attribute, ‘name’.


Perhaps the OP means that 'name' is a variable which is bound to the
name of the function/method, which is an attribute of self.blahbalah.


(Aside: Please choose better example names, these make it rather
difficult to talk about.)


So:
my function is:
self.blahblah.name(arg1,arg2,arg3)


Your *function* is ‘self.blahblah.name’.

One possible way to express a *call* that function is
‘self.blahblah.name(arg1, arg2, arg3)’.


If 'name' is bound to the name, then:

func = getattr(self.blahblah, name)
func(arg1, arg2, arg3)

or just:

getattr(self.blahblah, name)(arg1, arg2, arg3)


I read functools documentations, may be objictive usage and
functionality differ, Do you have experience with objective usage ?
http://docs.python.org/2/library/functools.html#partial-objects


I don't understand what the question is. You have shown a way to call
your function; what do you want to do now?


I need to use it in my class,


Feel free :-)



--
https://mail.python.org/mailman/listinfo/python-list


Re: Screenshots in Mac OS X

2013-10-22 Thread Pratik Mehta
Hey John,

I want to code my own Snapshot taking program using Python.

Hence, had posted this question...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screenshots in Mac OS X

2013-10-22 Thread Pratik Mehta
Hey Kevin,

Thanks for reverting.

I know about the screencapture function and the parameters available.

But, how would I take the user input, as in, that is just command-line, as soon 
as I execute the program, it will take whatever kind of parameter is passed 
under screencapture.

I want that, in the same program, if the user presses Shift+Command+3, whole 
screenshot should be taken.

When, Shift + Command + 4 is pressed, a particular frame should be displayed to 
select the area / region.

Also, I want to create my own command : Shift + Command + 5 == this is 
specially for web browser, whenever I press this key on any of the web-page, 
the whole web page should be grabbed along with its snapshot, and snapshot's 
filename should be web-page's url which I am currently on.

Also, this process should be executing at the backend, so that, whenever these 
keys are pressed, it overrides the system's functionality and uses mine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screenshots in Mac OS X

2013-10-22 Thread Pratik Mehta
Hey Mark,

Thanks for reverting.

I had tried coding it using os.system(screencapture -s /filepath) // for 
selecting a particular region..


I have replied to Kevin's comment, that's exactly what I am looking for.  :)


Thanks ...

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Screenshots in Mac OS X

2013-10-22 Thread Kevin Walzer

On 10/22/13 8:19 PM, Pratik Mehta wrote:

Hey Kevin,

Thanks for reverting.

I know about the screencapture function and the parameters available.

But, how would I take the user input, as in, that is just command-line, as soon 
as I execute the program, it will take whatever kind of parameter is passed 
under screencapture.

I want that, in the same program, if the user presses Shift+Command+3, whole 
screenshot should be taken.

When, Shift + Command + 4 is pressed, a particular frame should be displayed to 
select the area / region.

Also, I want to create my own command : Shift + Command + 5 == this is 
specially for web browser, whenever I press this key on any of the web-page, the 
whole web page should be grabbed along with its snapshot, and snapshot's filename 
should be web-page's url which I am currently on.

Also, this process should be executing at the backend, so that, whenever these 
keys are pressed, it overrides the system's functionality and uses mine.



There are no simple answers to these questions.

With Tkinter, it's possible to code a basic UI and bind combinations of 
specific keys to trigger specific callbacks, which can fire specific 
sequences of arguments to the screencapture CLI tool. That's the quick 
and dirty way. I'm not going to write this code for you. Look at 
TkDocs.com and effbot's site for an introduction to Tkinter.


If you are not looking for a GUI app to do this, but some sort of 
system-level daemon, that requires a lower level of coding. You'll need 
to look at such system frameworks as CoreGraphics and Cocoa to find the 
API's you need. PyObjC (Python binding to Cocoa) can probably be helpful 
here. Frankly, I'm not sure Python is the best tool here, but if you go 
this route, you want a Python API that hews as closely to the 
system-level calls as possible, and PyObjC will likely be your best path 
here.


--Kevin

--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using with context handler, and catching specific exception?

2013-10-22 Thread Victor Hooi
Hi,

I'm actually on Python 2.7, so we don't have access to any of those nice new 
exceptions in Python 3.3 =(:

http://docs.python.org/2.7/library/exceptions.html#exception-hierarchy

@Ben - Good point about just catching the more general exception, and just 
printing out the string message.

I suppose in most cases, we won't be doing anything special for the different 
types (e.g. file not found, permission error, is a directory etc.) - it'll just 
be going into logs.

Is there anything wrong with me just catching Exception in this case of 
opening a file, and printing the message from there?

Cheers,
Victor


On Tuesday, 22 October 2013 14:53:58 UTC+11, Ben Finney  wrote:
 Victor Hooi victorh...@gmail.com writes:
 
 
 
  Aha, good point about IOError encapsulating other things, I'll use
 
  FileNotFoundError, and also add in some other except blocks for the
 
  other ones.
 
 
 
 Or not; you can catch OSError, which is the parent of FileNotFoundError
 
 URL:http://docs.python.org/3/library/exceptions.html#exception-hierarchy,
 
 but don't assume in your code that it means anything more specific.
 
 
 
 You should only catch specific exceptions if you're going to do
 
 something specific with them. If all you want to do is log them and move
 
 on, then catch a more general class and ask the exception object to
 
 describe itself (by using it in a string context).
 
 
 
 
 
 In versions of Python before 3.3, you have to catch EnvironmentError
 
 URL:http://docs.python.org/3.2/library/exceptions.html#EnvironmentError
 
 and then distinguish the specific errors by their ‘errno’ attribute
 
 URL:http://docs.python.org/3.2/library/errno.html::
 
 
 
 import errno
 
 
 
 try:
 
 with open('somefile.log', 'wb') as f:
 
 f.write(hello there)
 
 except EnvironmentError as exc:
 
 if exc.errno == errno.ENOENT:
 
 handle_file_not_found_error()
 
 elif exc.errno == errno.EACCES:
 
 handle_permission_denied()
 
 elif exc.errno == errno.EEXIST:
 
 handle_file_exists()
 
 …
 
 else:
 
 handle_all_other_environment_errors()
 
 
 
 That's much more clumsy, which is why it was improved in the latest
 
 Python. If you can, code for Python 3.3 or higher.
 
 
 
 -- 
 
  \ “Unix is an operating system, OS/2 is half an operating system, |
 
   `\Windows is a shell, and DOS is a boot partition virus.” —Peter |
 
 _o__)H. Coffin |
 
 Ben Finney
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread alex23

On 23/10/2013 4:40 AM, Ned Batchelder wrote:

I've tried to be polite, and I've tried to be helpful, but I'm sorry:
either you don't understand a lot of the terms you are throwing around,
or you aren't disciplined enough to focus on a topic long enough to
explain yourself.  Either way, I don't know how else to move the
discussion forward.


You forgot to end with a well-warranted Boom.

Mark Janssen is rapidly becoming Xah Lee 2.0, identical down to the 
repugnant misogyny he expresses elsewhere. The only difference is one of 
verbosity.

--
https://mail.python.org/mailman/listinfo/python-list


Re: pip won't ignore system-installed files

2013-10-22 Thread jason . gors . work
if you use a newer version of pip i think this should work.


On Tuesday, October 22, 2013 9:11:40 AM UTC-4, Neal Becker wrote:
 IIUC, it is perfectly legitimate to do install into --user to override system-
 
 wide installed modules.  Thus, I should be able to do:
 
 
 
 pip install --user --up blah
 
 
 
 even though there is already a package blah in 
 
 /usr/lib/pythonxxx/site_packages/...
 
 
 
 But even with -I (ignore installed) switch, pip fails:
 
 
 
 pip install --user --up -I matplotlib
 
 ...
 
  Installing collected packages: matplotlib, numpy, python-dateutil, tornado, 
 
 pyparsing, nose, six
 
   Found existing installation: matplotlib 1.2.0
 
 Uninstalling matplotlib:
 
 Exception:
 
 Traceback (most recent call last):
 
   File /usr/lib/python2.7/site-packages/pip-1.2.1-
 
 py2.7.egg/pip/basecommand.py, line 107, in main
 
 status = self.run(options, args)
 
   File /usr/lib/python2.7/site-packages/pip-1.2.1-
 
 py2.7.egg/pip/commands/install.py, line 261, in run
 
 requirement_set.install(install_options, global_options)
 
   File /usr/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py, 
 line 
 
 1162, in install
 
 requirement.uninstall(auto_confirm=True)
 
   File /usr/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py, 
 line 
 
 495, in uninstall
 
 paths_to_remove.remove(auto_confirm)
 
   File /usr/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py, 
 line 
 
 1492, in remove
 
 renames(path, new_path)
 
   File /usr/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/util.py, 
 line 
 
 273, in renames
 
 shutil.move(old, new)
 
   File /usr/lib64/python2.7/shutil.py, line 302, in move
 
 os.unlink(src)
 
 OSError: [Errno 13] Permission denied: '/usr/lib64/python2.7/site-
 
 packages/matplotlib-1.2.0-py2.7.egg-info'
 
 
 
 Can we please fix this?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: functools and objective usage

2013-10-22 Thread Piet van Oostrum
Mohsen Pahlevanzadeh moh...@pahlevanzadeh.org writes:

 Dear all,

 Suppose i have function name, 3 arguments for it, and object of its
 caller such as self.blahbalah
 So:
 my function is:
 self.blahblah.name(arg1,arg2,arg3)

 I read functools documentations, may be objictive usage and
 functionality differ, Do you have experience with objective usage ? 
 http://docs.python.org/2/library/functools.html#partial-objects

What do you mean with objective usage?
-- 
Piet van Oostrum p...@vanoostrum.org
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread rusi
On Wednesday, October 23, 2013 7:06:40 AM UTC+5:30, alex23 wrote:
 On 23/10/2013 4:40 AM, Ned Batchelder wrote:
 
  I've tried to be polite, and I've tried to be helpful, but I'm sorry:
  either you don't understand a lot of the terms you are throwing around,
  or you aren't disciplined enough to focus on a topic long enough to
  explain yourself.  Either way, I don't know how else to move the
  discussion forward.
 
 You forgot to end with a well-warranted Boom.
 
 Mark Janssen is rapidly becoming Xah Lee 2.0, identical down to the 
 repugnant misogyny he expresses elsewhere. The only difference is one of 
 verbosity.

Hey! Time to stop punching up a guy -- even (because?) he's a nut -- rather a 
hard one tho
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-22 Thread Michael Torrie
On 10/22/2013 12:28 PM, Mark Janssen wrote:
 Thank you.  You may be seated.

Ranting Rick, is that you?
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   >