Re: Python-based monads essay (Re: Assignment versus binding)

2016-10-12 Thread Steven D'Aprano
On Sunday 09 October 2016 18:48, Gregory Ewing wrote:

> Here's the first part of the essay I said I'd write about
> monads:
> 
> 
http://www.cosc.canterbury.ac.nz/greg.ewing/essays/monads/DemystifyingMonads.html


Quoting from the essay:

"the implementation is free to use in-place mutations of the state object – 
which obviously allows considerable gains in efficiency, both in time and 
memory usage – without giving up any functional purity."

Surely that should be as follows?

"the implementation is free to use in-place mutations of the state object – 
which obviously allows considerable gains in efficiency, both in time and 
memory usage – without letting anyone know that the implementation has given up 
any functional purity."


I'm inclined to agree with James Hague (via John Cook): functional programming 
is great, until you try to be strict about it. The closer you get to 100% 
functional, the less you can use it. He reckons the sweet spot is about 85% 
functional:

http://www.johndcook.com/blog/2010/04/15/85-functional-language-purity/




-- 
Steven
git gets easier once you get the basic idea that branches are homeomorphic 
endofunctors mapping submanifolds of a Hilbert space.

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


why solveset and dsolve do not have _fields for ast.walk?

2016-10-12 Thread meInvent bbird
Traceback (most recent call last):
  File "astgraphforsympy.py", line 86, in 
print get_func_calls(tree)
  File "astgraphforsympy.py", line 48, in get_func_calls
for node in ast.walk(tree):
  File "C:\Python27\lib\ast.py", line 213, in walk
todo.extend(iter_child_nodes(node))
  File "C:\Python27\lib\ast.py", line 178, in iter_child_nodes
for name, field in iter_fields(node):
  File "C:\Python27\lib\ast.py", line 166, in iter_fields
for field in node._fields:
AttributeError: Module instance has no attribute '_fields'
-- 
https://mail.python.org/mailman/listinfo/python-list


how to evaluate a ast tree and change Add to Multiply ?

2016-10-12 Thread meInvent bbird
import sys
import parser
import ast
from collections import deque


class ChangeAddtoMultiply(ast.NodeTransformer):
"""Wraps all integers in a call to Integer()"""
def visit_Num(self, node):
if isinstance(node.n, int):
return ast.Call(func=ast.Name(id='Add', ctx=ast.Load()),
args=[node], keywords=[])
return node


tree = ast.parse('2+5')
for node in ast.walk(tree):
print(str(node))

eval(tree)

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


Re: how to evaluate a ast tree and change Add to Multiply ?

2016-10-12 Thread Chris Angelico
On Wed, Oct 12, 2016 at 8:32 PM, meInvent bbird  wrote:
> class ChangeAddtoMultiply(ast.NodeTransformer):
> """Wraps all integers in a call to Integer()"""
> def visit_Num(self, node):
> if isinstance(node.n, int):
> return ast.Call(func=ast.Name(id='Add', ctx=ast.Load()),
> args=[node], keywords=[])
> return node
>
>

Your class name, docstring, and functionality are all different, and
you have given no explanation of what you want us to do. I can't read
minds quite that well.

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


how to faster to know which ast name or id we want to change?

2016-10-12 Thread meInvent bbird
how to faster to know which ast name or id we want to change?

because i use ast.walk to print all nodes then i know the name + is Add

if using cparser to parse linux kernel, 
it will be a very large
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop (Reposting On Python-List Prohibited)

2016-10-12 Thread BartC

On 12/10/2016 05:30, Lawrence D’Oliveiro wrote:

On Wednesday, October 12, 2016 at 11:23:48 AM UTC+13, BartC wrote:

while n>=x:
 n=n-1
 print "*"* n
else:
 print ("2nd loop exit n=",n,"x=",x)


What is the difference between that and

while n>=x:
 n=n-1
 print "*"* n
print ("2nd loop exit n=",n,"x=",x)

?

None at all.



Not so much in this specific example: that message will be shown whether 
there have been 0 or more iterations of the loop body.


But with 'else', if you see the message it means the while statement has 
been entered. Here:


if cond:
 while n>=x:
  n=n-1
  print "*"* n
 else:
  print ("2nd loop exit n=",n,"x=",x)

when cond is false, nothing will be printed. You then know the while 
statement hasn't been entered, so it's not looping for some other reason 
than its loop condition being false from the start.


Another situation is when the loop body contains 'break'; then it will 
bypass the 'else' part.


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


Re: How to process syntax errors

2016-10-12 Thread mr . puneet . goyal
Hi All

Its really good to see that some discussion happening around this topic. Sorry 
I was out from my work for sometime so couldn't follow up but I really find it 
useful. It gives me good opportunity to know python better as I recently 
started learning python. 

Ok so I tell you why I need to catch syntax error during compilation and 
process them. See below example, 

# I created a platform class with different method in a file and making it as a 
package. 
class platform:
def connect(self):
# connect device 
def destroy(self):
# destroy device
def config(self, command):
# Send command to configure device
def show(self, command):
# check device health

Now person who wants to write a script using above package can simply use below 
approach. Which does not make him to have knowledge in python. 

DUT = platform()
DUT connect
DUT config {commands}
DUT show {commands}
DUT destroy


But I know this is not easy to do in python. As they all invalid syntax for 
python language. So I thought of grabing syntax errors and manipulate them as 
below internally to call them while code is compiling. 

DUT = platform()
DUT.connect()
DUT.config(commands)
DUT.show(commands)
DUT.destroy()

Hope you understand my need of doing this. If there is another solution to 
achieve what I am trying to. Please let me know. 

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


Re: how to evaluate a ast tree and change Add to Multiply ?

2016-10-12 Thread meInvent bbird

i use example here

 http://greentreesnakes.readthedocs.io/en/latest/examples.html




On Wednesday, October 12, 2016 at 5:47:12 PM UTC+8, Chris Angelico wrote:
> On Wed, Oct 12, 2016 at 8:32 PM, meInvent bbird  wrote:
> > class ChangeAddtoMultiply(ast.NodeTransformer):
> > """Wraps all integers in a call to Integer()"""
> > def visit_Num(self, node):
> > if isinstance(node.n, int):
> > return ast.Call(func=ast.Name(id='Add', ctx=ast.Load()),
> > args=[node], keywords=[])
> > return node
> >
> >
> 
> Your class name, docstring, and functionality are all different, and
> you have given no explanation of what you want us to do. I can't read
> minds quite that well.
> 
> ChrisA

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


Re: how to evaluate a ast tree and change Add to Multiply ?

2016-10-12 Thread meInvent bbird
i just expect to 
rewrite + become multiply
by edit the example in the link provided

but search no examples about this, 
feel unknown about args and keywords etc, 
do not know how to write this 

ast.Call(func=ast.Name(id='Add', ctx=ast.Load()), 
args=[node], keywords=[]) 

On Wednesday, October 12, 2016 at 5:53:42 PM UTC+8, meInvent bbird wrote:
> i use example here
> 
>  http://greentreesnakes.readthedocs.io/en/latest/examples.html
> 
> 
> 
> 
> On Wednesday, October 12, 2016 at 5:47:12 PM UTC+8, Chris Angelico wrote:
> > On Wed, Oct 12, 2016 at 8:32 PM, meInvent bbird  
> > wrote:
> > > class ChangeAddtoMultiply(ast.NodeTransformer):
> > > """Wraps all integers in a call to Integer()"""
> > > def visit_Num(self, node):
> > > if isinstance(node.n, int):
> > > return ast.Call(func=ast.Name(id='Add', ctx=ast.Load()),
> > > args=[node], keywords=[])
> > > return node
> > >
> > >
> > 
> > Your class name, docstring, and functionality are all different, and
> > you have given no explanation of what you want us to do. I can't read
> > minds quite that well.
> > 
> > ChrisA

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


Re: How to process syntax errors

2016-10-12 Thread mr . puneet . goyal
On Monday, October 10, 2016 at 7:45:40 PM UTC+5:30, mr.pune...@gmail.com wrote:
> Hi 
> 
> Is there any way to capture syntax errors and process them ? I want to write 
> a function which calls every time whenever there is syntax error in the 
> program.
> 
> For example, 
> 
> inside example.py 
> 
> I just mention below line 
> 
> 
> Obj = myClass()
> Obj xyz
> 
> Obj is instance of a class. But there is syntax error on xyz. So I want to 
> grab that error and process.
> 
> Regards, Puneet

Steve, You are absolutely right. I am trying to eliminate the method of using 
parenthesis while calling in my file. Especially when I call it from a instance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: while loop (Reposting On Python-List Prohibited)

2016-10-12 Thread Peter Otten
BartC wrote:

> On 12/10/2016 05:30, Lawrence D’Oliveiro wrote:
>> On Wednesday, October 12, 2016 at 11:23:48 AM UTC+13, BartC wrote:
>>> while n>=x:
>>>  n=n-1
>>>  print "*"* n
>>> else:
>>>  print ("2nd loop exit n=",n,"x=",x)
>>
>> What is the difference between that and
>>
>> while n>=x:
>>  n=n-1
>>  print "*"* n
>> print ("2nd loop exit n=",n,"x=",x)
>>
>> ?
>>
>> None at all.
>>
> 
> Not so much in this specific example: that message will be shown whether
> there have been 0 or more iterations of the loop body.
> 
> But with 'else', if you see the message it means the while statement has
> been entered. Here:
> 
> if cond:
>   while n>=x:
>n=n-1
>print "*"* n
>   else:
>print ("2nd loop exit n=",n,"x=",x)

Lawrence is right. The enclosing if doesn't make a difference.
 
> when cond is false, nothing will be printed. You then know the while
> statement hasn't been entered, so it's not looping for some other reason
> than its loop condition being false from the start.
> 
> Another situation is when the loop body contains 'break'; then it will
> bypass the 'else' part.

This is the only case where while...else makes sense: the code in the else 
suite is executed if and only if the break was not reached.


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


Re: repr/str diff between Python 2 and 3

2016-10-12 Thread Skip Montanaro
Thanks everyone. I'm not going to try to be too cute, and will just change
my test case. I'm leaving Python 2 behind in this particular case for now
anyway. I can always return to the issue if I decide I need Python 2.7
support at some point in the future.

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


Re: while loop (Reposting On Python-List Prohibited)

2016-10-12 Thread BartC

On 12/10/2016 11:15, Peter Otten wrote:

BartC wrote:


On 12/10/2016 05:30, Lawrence D’Oliveiro wrote:

On Wednesday, October 12, 2016 at 11:23:48 AM UTC+13, BartC wrote:

while n>=x:
 n=n-1
 print "*"* n
else:
 print ("2nd loop exit n=",n,"x=",x)


What is the difference between that and

while n>=x:
 n=n-1
 print "*"* n
print ("2nd loop exit n=",n,"x=",x)

?

None at all.



Not so much in this specific example: that message will be shown whether
there have been 0 or more iterations of the loop body.

But with 'else', if you see the message it means the while statement has
been entered. Here:

if cond:
  while n>=x:
   n=n-1
   print "*"* n
  else:
   print ("2nd loop exit n=",n,"x=",x)


Lawrence is right. The enclosing if doesn't make a difference.


The idea is to detect whether the while loop has been entered.

With while-else-print, it will always execute the else (assuming no 
break). With while then print, you can't tell if it has attempted to or 
not. My example above has wrapped the if-cond around the whole of 
while-else because it has to (that's the advantage).


With a separate print it need not do that:

 if cond:
while n>=x:
   n=n-1
   print "*"* n
 print ("2nd loop exit n=",n,"x=",x)

With real code it may not be as easy to see. 'else' adds structure.

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


Re: [RELEASE] Python 3.6.0b2 is now available

2016-10-12 Thread Robin Becker

On 11/10/2016 02:12, Ned Deily wrote:

On behalf of the Python development community and the Python 3.6 release
team, I'm happy to announce the availability of Python 3.6.0b2. 3.6.0b2
is the second of four planned beta releases of Python 3.6, the next major
release of Python, and marks the end of the feature development phase
for 3.6.

...

thanks


--
  Ned Deily
  n...@python.org -- []




I notice an extra space at the windows command prompt compared with 3.5, is that 
deliberate?



C:\ux\XB33>\python35\python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit 
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import sys




C:\ux\XB33\repos\pyRXP>..\..\py36_amd64\Scripts\python.exe
Python 3.6.0b2 (default, Oct 10 2016, 21:15:32) [MSC v.1900 64 bit (AMD64)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.

 import sys


--
Robin Becker

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


Re: How to process syntax errors

2016-10-12 Thread Steve D'Aprano
On Wed, 12 Oct 2016 08:59 pm, mr.puneet.go...@gmail.com wrote:

> Now person who wants to write a script using above package can simply use
> below approach. Which does not make him to have knowledge in python.
> 
> DUT = platform()
> DUT connect
> DUT config {commands}
> DUT show {commands}
> DUT destroy
> 
> 
> But I know this is not easy to do in python. 

This is *impossible* to do in Python. You cannot expect to write something
in a language which is not Python, and have the Python interpreter run it
as Python code.

Either your users have to write Python code, or you have to write your own
interpreter for whatever language it is that they wish to write. The
interpreter doesn't need to be very complicated, and it can be written in
Python. 

The Python standard library includes support for writing *interactive*
command interpreters:

https://docs.python.org/3/library/cmd.html

You can study that to get some hints for writing a non-interactive
interpreter.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Local variables to a function doesn't disapear after function execution. Why ?

2016-10-12 Thread ast

Hello, here is the small program:

from tkinter import *

class Test:
   def __init__(self):
   root = Tk()
   label = Label(root, text="this is a test")
   label.pack()
   root.mainloop()

test=Test()

I dont understand why this program works. After execution
of function __init__, local variables 'root' and 'label' should 
disapear and the widgets Tk and Label should be garbage 
collected. But it's not the case, the window Tk is still on the 
screen with the label inside it. Why ?


Usually, we write:

class Test:
   def __init__(self):
   self.root = Tk()
   self.label = Label(self.root, text="this is a test")
   self.label.pack()
   self.root.mainloop()

test = Test()

to keep some references to Tk() and Label()
--
https://mail.python.org/mailman/listinfo/python-list


Re: Local variables to a function doesn't disapear after function execution. Why ?

2016-10-12 Thread Christian Gollwitzer

Am 12.10.16 um 13:18 schrieb ast:

Hello, here is the small program:

from tkinter import *

class Test:
   def __init__(self):
   root = Tk()
   label = Label(root, text="this is a test")
   label.pack()
   root.mainloop()

test=Test()

I dont understand why this program works. After execution
of function __init__, local variables 'root' and 'label' should disapear
and the widgets Tk and Label should be garbage collected. But it's not
the case, the window Tk is still on the screen with the label inside it.
Why ?



Because the Test() call does never terminate. You have the mainloop 
inside of your constructor. As long as this loop runs, your program 
exists. Try it by putting


test=Test()
print("Now I am here")

and you'll see.

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


Re: Local variables to a function doesn't disapear after function execution. Why ?

2016-10-12 Thread ast


"Christian Gollwitzer"  a écrit dans le message de 
news:ntl6in$on5$1...@dont-email.me...

Am 12.10.16 um 13:18 schrieb ast:


Because the Test() call does never terminate. You have the mainloop inside of your constructor. As 
long as this loop runs, your program exists. Try it by putting


test=Test()
print("Now I am here")

and you'll see.

Christian


Ah yes, mainloop() is an endless loop.
Thanks 


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


an other issue when installing python under Windows OS

2016-10-12 Thread Karlheinz Hoening
   Hello all,

   on my iMac I have installed Windows (7) and I am now trying to install
   Python 3.5.2 (32-bit) under Windows OS.
   Every time after having 'repaired' with the installation procedere I
   receive the following message when starting Python 3.5:
   

   python.exe - Sytemfehler
   Das Programm kann nicht gestartet werden, da api-ms-win-crt-I1-1-0.dll auf
   dem Computer fehlt.
   Installieren Sie das Programm erneut ...
   

   Can you give any hint (support)?
   Where can I find the above mentionned driver?

   Thanks a lot in advance.
   cheers
   Kalle
   (k.hoen...@gmx.net)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay (Re: Assignment versus binding)

2016-10-12 Thread Gregory Ewing

Steven D'Aprano wrote:
"the implementation is free to use in-place mutations of the state object – 
... without letting anyone know that the implementation has given up 
any functional purity."


If it's impossible to tell that functional purity has
been given up, then in what sense has it been given up
at all?

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


Re: an other issue when installing python under Windows OS

2016-10-12 Thread Vlastimil Brom
2016-10-12 14:24 GMT+02:00 Karlheinz Hoening :
>Hello all,
>
>on my iMac I have installed Windows (7) and I am now trying to install
>Python 3.5.2 (32-bit) under Windows OS.
>Every time after having 'repaired' with the installation procedere I
>receive the following message when starting Python 3.5:
>
> 
>python.exe - Sytemfehler
>Das Programm kann nicht gestartet werden, da api-ms-win-crt-I1-1-0.dll auf
>dem Computer fehlt.
>Installieren Sie das Programm erneut ...
>
> 
>Can you give any hint (support)?
>Where can I find the above mentionned driver?
>
>Thanks a lot in advance.
>cheers
>Kalle
>(k.hoen...@gmx.net)
> --
> https://mail.python.org/mailman/listinfo/python-list

Hello,
I believe, that file is a part of Windows runtime libraries and may be
downloaded from the Microsoft webpage:
https://support.microsoft.com/de-de/kb/2999226
(for multiple windows versions)
However, there might be some specificities in handling this update on
your computer.

hth,
   vbr
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to process syntax errors

2016-10-12 Thread Pierre-Alain Dorange
Terry Reedy  wrote:

> > Using this function, the code is "compiled".
> > I do not think this function is often used and most python project
> > simply use the interpreter (which do a small translation into byte-code
> > to be faster and check syntax error before running interpretation
> 
> You seem to be confusing CPython with, for instance, simple BASIC 
> interpreters that tokenized the code, translated keywords to function
> numbers, and did other 'small translations' before execution.
> 
> The CPython compiler lexes (tokenizes), ll(1) parses to a syntax tree,
> does some analysis and transformation of the tree, and translates it to
> the bytecode for an stack machine.  All done using standard compiler theory.

Yes i'm probably confusing things ; i've not explore Python
implentation, i'm just an amateur developer.
But what confuse me, is that Python require "real live" interpratation
of the code to work properly (or perhaps i also confuse on that but
Python rely on interpretation of the code to conform to its own
standard, ie variables can change type during execution...)

-- 
Pierre-Alain Dorange   Moof 

Ce message est sous licence Creative Commons "by-nc-sa-2.0"

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


Re: How to process syntax errors

2016-10-12 Thread Chris Angelico
On Thu, Oct 13, 2016 at 12:46 AM, Pierre-Alain Dorange
 wrote:
> Terry Reedy  wrote:
>
>> > Using this function, the code is "compiled".
>> > I do not think this function is often used and most python project
>> > simply use the interpreter (which do a small translation into byte-code
>> > to be faster and check syntax error before running interpretation
>>
>> You seem to be confusing CPython with, for instance, simple BASIC
>> interpreters that tokenized the code, translated keywords to function
>> numbers, and did other 'small translations' before execution.
>>
>> The CPython compiler lexes (tokenizes), ll(1) parses to a syntax tree,
>> does some analysis and transformation of the tree, and translates it to
>> the bytecode for an stack machine.  All done using standard compiler theory.
>
> Yes i'm probably confusing things ; i've not explore Python
> implentation, i'm just an amateur developer.
> But what confuse me, is that Python require "real live" interpratation
> of the code to work properly (or perhaps i also confuse on that but
> Python rely on interpretation of the code to conform to its own
> standard, ie variables can change type during execution...)

Variables don't have types; objects do. A variable in Python always
holds a thing of type 'object', and everything in Python is a subclass
of object. This doesn't stop Python from being compiled - you could do
the exact same thing in C++ or Java.

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


Re: an other issue when installing python under Windows OS

2016-10-12 Thread eryk sun
On Wed, Oct 12, 2016 at 12:24 PM, Karlheinz Hoening  wrote:
>
>on my iMac I have installed Windows (7) and I am now trying to install
>Python 3.5.2 (32-bit) under Windows OS.
>Every time after having 'repaired' with the installation procedere I
>receive the following message when starting Python 3.5:
>
> 
>python.exe - Sytemfehler
>Das Programm kann nicht gestartet werden, da api-ms-win-crt-I1-1-0.dll auf
>dem Computer fehlt.
>Installieren Sie das Programm erneut ...
>
> 
>Can you give any hint (support)?
>Where can I find the above mentionned driver?

It's not a driver; it's an API set DLL for the C runtime library. The
C runtime is now an OS component, so preferably you should get this
from Windows Update to install the most recent version available. It
may be listed under optional updates.
-- 
https://mail.python.org/mailman/listinfo/python-list


testfixtures 4.11.0 Released!

2016-10-12 Thread Chris Withers

Hi All,

I'm pleased to announce the release of testfixtures 4.10.1 featuring the 
following:


- Allow the attributes returned in LogCapture.actual() rows to be
  specified.

- Allow a default to be specified for encoding in TempDirectory.read() 
and TempDirectory.write().


The package is on PyPI and a full list of all the links to docs, issue 
trackers and the like can be found here:


https://github.com/Simplistix/testfixtures

Any questions, please do ask on the Testing in Python list or on the 
Simplistix open source mailing list...


cheers,

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


Re: How to process syntax errors

2016-10-12 Thread Steve D'Aprano
On Thu, 13 Oct 2016 12:46 am, Pierre-Alain Dorange wrote:

> Terry Reedy  wrote:
> 
>> > Using this function, the code is "compiled".
>> > I do not think this function is often used and most python project
>> > simply use the interpreter (which do a small translation into byte-code
>> > to be faster and check syntax error before running interpretation
>> 
>> You seem to be confusing CPython with, for instance, simple BASIC
>> interpreters that tokenized the code, translated keywords to function
>> numbers, and did other 'small translations' before execution.
>> 
>> The CPython compiler lexes (tokenizes), ll(1) parses to a syntax tree,
>> does some analysis and transformation of the tree, and translates it to
>> the bytecode for an stack machine.  All done using standard compiler
>> theory.
> 
> Yes i'm probably confusing things ; i've not explore Python
> implentation, i'm just an amateur developer.
> But what confuse me, is that Python require "real live" interpratation
> of the code to work properly 

That is true, but not as much as you would think. Only two things in Python
absolutely require runtime interpretation: eval() and exec().

But that depends on what you mean by "real live" interpretation. Compiled
languages like Java and C++ also include runtime features like runtime
dispatch, V-tables, 

> (or perhaps i also confuse on that but 
> Python rely on interpretation of the code to conform to its own
> standard, ie variables can change type during execution...)

Variables changing type is the least important part of this.

The Rust programming language is strongly typed, compiled to efficient
machine code like C, and it allows you to change variable types. Say you
have code like this in Rust:

let x = 1;
f(x);
let x = 'this is a string';
g(x);

The Rust compiler is clever enough to tell that when you call f(), x is an
integer, and when you call f(), x is a string. It can do that at compile
time, not just runtime.

If you can read a piece of source code, and work out what type a variable
has, then so can the compiler -- if it is smart enough. The type systems of
older languages like Pascal and C are not very smart, so they are very
restrictive: they insist that variables have only a single type, which must
be explicitly declared. But modern languages like Rust have very smart
compilers with a very powerful type system, and they don't have that
restriction.

 

-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: How to process syntax errors

2016-10-12 Thread Rob Gaddi
mr.puneet.go...@gmail.com wrote:

> On Monday, October 10, 2016 at 7:45:40 PM UTC+5:30, mr.pune...@gmail.com 
> wrote:
>> Hi 
>> 
>> Is there any way to capture syntax errors and process them ? I want to write 
>> a function which calls every time whenever there is syntax error in the 
>> program.
>> 
>> For example, 
>> 
>> inside example.py 
>> 
>> I just mention below line 
>> 
>> 
>> Obj = myClass()
>> Obj xyz
>> 
>> Obj is instance of a class. But there is syntax error on xyz. So I want to 
>> grab that error and process.
>> 
>> Regards, Puneet
>
> Steve, You are absolutely right. I am trying to eliminate the method of using 
> parenthesis while calling in my file. Especially when I call it from a 
> instance.

There's a simple solution then.  Don't do that.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: an other issue when installing python under Windows OS

2016-10-12 Thread eryk sun
On Wed, Oct 12, 2016 at 3:25 PM, eryk sun  wrote:
> On Wed, Oct 12, 2016 at 12:24 PM, Karlheinz Hoening  wrote:
>>
>>on my iMac I have installed Windows (7) and I am now trying to install
>>Python 3.5.2 (32-bit) under Windows OS.
>>Every time after having 'repaired' with the installation procedere I
>>receive the following message when starting Python 3.5:
>>
>> 
>>python.exe - Sytemfehler
>>Das Programm kann nicht gestartet werden, da api-ms-win-crt-I1-1-0.dll auf
>>dem Computer fehlt.
>>Installieren Sie das Programm erneut ...
>>
>> 
>>Can you give any hint (support)?
>>Where can I find the above mentionned driver?
>
> It's not a driver; it's an API set DLL for the C runtime library. The
> C runtime is now an OS component, so preferably you should get this
> from Windows Update to install the most recent version available. It
> may be listed under optional updates.

I just checked a Windows 7 system's update history. KB3118401 [1] was
installed in March of this year as a recommended update. Typical
Windows users just ignore and put off installing updates. That's why
Microsoft switched to compulsory updates in Windows 10.

[1]: https://support.microsoft.com/en-us/kb/3118401
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to process syntax errors

2016-10-12 Thread sohcahtoa82
On Wednesday, October 12, 2016 at 3:01:26 AM UTC-7, mr.pune...@gmail.com wrote:
> Hi All
> 
> Its really good to see that some discussion happening around this topic. 
> Sorry I was out from my work for sometime so couldn't follow up but I really 
> find it useful. It gives me good opportunity to know python better as I 
> recently started learning python. 
> 
> Ok so I tell you why I need to catch syntax error during compilation and 
> process them. See below example, 
> 
> # I created a platform class with different method in a file and making it as 
> a package. 
> class platform:
> def connect(self):
> # connect device 
> def destroy(self):
> # destroy device
> def config(self, command):
> # Send command to configure device
> def show(self, command):
> # check device health
> 
> Now person who wants to write a script using above package can simply use 
> below approach. Which does not make him to have knowledge in python. 
> 
> DUT = platform()
> DUT connect
> DUT config {commands}
> DUT show {commands}
> DUT destroy
> 
> 
> But I know this is not easy to do in python. As they all invalid syntax for 
> python language. So I thought of grabing syntax errors and manipulate them as 
> below internally to call them while code is compiling. 
> 
> DUT = platform()
> DUT.connect()
> DUT.config(commands)
> DUT.show(commands)
> DUT.destroy()
> 
> Hope you understand my need of doing this. If there is another solution to 
> achieve what I am trying to. Please let me know. 
> 
> Thanks, Puneet

You have two possible solutions:

1. Write an interpreter that can read an interpret the commands without 
parentheses.
2. Tell your users to use the dot "." operator and parentheses.  You don't need 
to teach them Python, just how to properly format the script.

Personally, I'd go with option #2.

But as others have said, you can't get Python to just "work" without 
parentheses.  Sure, you COULD attempt to import the script the users have 
written and catch the SyntaxError exception, but what would you do with it?  At 
that point, you're going to have to interpret the line of code in the script 
yourself, and at that point, you should just be writing an interpreter and not 
attempting to treat the script as Python.
-- 
https://mail.python.org/mailman/listinfo/python-list


smtplib TimeoutError not catch

2016-10-12 Thread Joaquin Alzola
Hi Guys

Try to connect to the smtp via smtplib.

The connection is down because the Firewall has not been open yet so the 
exception is something that should appear.
Now I want to catch this timeout in case error happens in future.

Here the exception trace.

[2016-10-12 14:14:06,289] ERROR in app: Exception on /api/barredMSISDN [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1988, in 
wsgi_app
response = self.full_dispatch_request()
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1641, in 
full_dispatch_request
rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1544, in 
handle_user_exception
reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.4/site-packages/flask/_compat.py", line 33, in 
reraise
raise value
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1639, in 
full_dispatch_request
rv = self.dispatch_request()
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1625, in 
dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/main.py", line 34, in barredMSISDN
smtp_con(http_json)
  File "/root/main.py", line 134, in smtp_con
server = smtplib.SMTP('smtp.lebara.com')
  File "/usr/local/lib/python3.4/smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.4/smtplib.py", line 321, in connect
self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/lib/python3.4/smtplib.py", line 292, in _get_socket
self.source_address)
  File "/usr/local/lib/python3.4/socket.py", line 516, in create_connection
raise err
  File "/usr/local/lib/python3.4/socket.py", line 507, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out


How to catch such exception? ... have been trying with a lot of combinations 
(of course except the correct one :))

try:
server.sendmail(sender, receivers, msg.as_string())
except Exception as e: <-- have try with many combinations here
print("SMTP could not be contacted: %s",e)
pass
finally:
   server.quit()

Joaquin
This email is confidential and may be subject to privilege. If you are not the 
intended recipient, please do not copy or disclose its content but contact the 
sender immediately upon receipt.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smtplib TimeoutError not catch

2016-10-12 Thread MRAB

On 2016-10-12 14:21, Joaquin Alzola wrote:

Hi Guys

Try to connect to the smtp via smtplib.

The connection is down because the Firewall has not been open yet so the 
exception is something that should appear.
Now I want to catch this timeout in case error happens in future.

Here the exception trace.

[2016-10-12 14:14:06,289] ERROR in app: Exception on /api/barredMSISDN [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1988, in 
wsgi_app
response = self.full_dispatch_request()
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1641, in 
full_dispatch_request
rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1544, in 
handle_user_exception
reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.4/site-packages/flask/_compat.py", line 33, in 
reraise
raise value
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1639, in 
full_dispatch_request
rv = self.dispatch_request()
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1625, in 
dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/main.py", line 34, in barredMSISDN
smtp_con(http_json)
  File "/root/main.py", line 134, in smtp_con
server = smtplib.SMTP('smtp.lebara.com')
  File "/usr/local/lib/python3.4/smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.4/smtplib.py", line 321, in connect
self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/lib/python3.4/smtplib.py", line 292, in _get_socket
self.source_address)
  File "/usr/local/lib/python3.4/socket.py", line 516, in create_connection
raise err
  File "/usr/local/lib/python3.4/socket.py", line 507, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out


How to catch such exception? ... have been trying with a lot of combinations 
(of course except the correct one :))

try:
server.sendmail(sender, receivers, msg.as_string())
except Exception as e: <-- have try with many combinations here
print("SMTP could not be contacted: %s",e)
pass
finally:
   server.quit()


Not surprisingly, the exception you should catch is simply TimeoutError:

try:
server.sendmail(sender, receivers, msg.as_string())
except TimeoutError as e:
print("SMTP could not be contacted: %s" % e)
finally:
server.quit()

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


Scripting Help please

2016-10-12 Thread LongHairLuke
Hi l am on my way to make a bot for the game Piano Tiles 2. 
But the code l have written so far saids invalid syntax at 2nd line. Here is my 
code: 



while True:
   If active then
  FFSnapShot(areaX, areaY + height - offsetBottom, areaX + width, areaY + 
height - offsetBottom, sid)
  For row = 0 To norows - 1
 c = FFGetPixel(areaX + row * rowWidth + 5, areaY + height - 
offsetBottom, sid)
 cs = _ColorGetRGB(c)
 b = ( cs[0] * 0.3 ) + ( cs[1] * 0.59 ) + ( cs[2] * 0.11 )
 If lock[row] Then
If b < darkness Then
   ContinueLoop
Else
   lock[row] = False
EndIf
 EndIf
 If b < darkness Then
MouseUp("Left")
lock[row] = True
MouseMove(areaX + row * rowWidth + rowWidth / 2, areaY + height - 
offsetBottom, 1)
MouseDown("Left")
 EndIf
  Next
   EndIf
End

Can someone help me please? 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Scripting Help please

2016-10-12 Thread alister
On Wed, 12 Oct 2016 13:37:23 -0700, LongHairLuke wrote:

> Hi l am on my way to make a bot for the game Piano Tiles 2.
> But the code l have written so far saids invalid syntax at 2nd line.
> Here is my code:
> 
> 
> 
> while True:
>If active then
>   FFSnapShot(areaX, areaY + height - offsetBottom, areaX + width,
>   areaY + height - offsetBottom, sid)
>   For row = 0 To norows - 1
>  c = FFGetPixel(areaX + row * rowWidth + 5, areaY + height -
>  offsetBottom, sid)
>  cs = _ColorGetRGB(c)
>  b = ( cs[0] * 0.3 ) + ( cs[1] * 0.59 ) + ( cs[2] * 0.11 )
>  If lock[row] Then
> If b < darkness Then
>ContinueLoop
> Else
>lock[row] = False
> EndIf
>  EndIf If b < darkness Then
> MouseUp("Left")
> lock[row] = True MouseMove(areaX + row * rowWidth + rowWidth
> / 2, areaY + height - offsetBottom, 1)
> MouseDown("Left")
>  EndIf
>   Next
>EndIf
> End
> 
> Can someone help me please?

Is observation this is not Python code
it looks more like some variety of BASIC but I could easily be wrong



-- 
Regarding astral projection, Woody Allen once wrote, "This is not a bad 
way
to travel, although there is usually a half-hour wait for luggage."
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to process syntax errors

2016-10-12 Thread Terry Reedy

On 10/12/2016 5:59 AM, mr.puneet.go...@gmail.com wrote:


# I created a platform class with different method in a file

> # and making it as a package.

class platform:
def connect(self):
# connect device
def destroy(self):
# destroy device
def config(self, command):
# Send command to configure device
def show(self, command):
# check device health



Now person who wants to write a script using above package can simply

> use below approach. Which does not make him to have knowledge in python.


DUT = platform()
DUT connect
DUT config {commands}
DUT show {commands}
DUT destroy



But I know this is not easy to do in python.


Actually, as long as args (commands) continue to be space separated, it 
is. One way would be to add the following after the class statement.


def execute(file):
with open(file) as f:
ns = {}
for line in f:
 if '=' in line:
 exec(line, ns)
 else:
 fields = line.split()
 exec('%s.%s(*%s)' %
  (fields[0], fields[1], fields[2:]), nd)

if __name__ = __main__:
import sys
execute(sys.argv[1])
--
If the module is platform.py, then the command line usage would be
> platform 

Re: Scripting Help please

2016-10-12 Thread Wildman via Python-list
On Wed, 12 Oct 2016 20:48:31 +, alister wrote:

> On Wed, 12 Oct 2016 13:37:23 -0700, LongHairLuke wrote:
> 
>> Hi l am on my way to make a bot for the game Piano Tiles 2.
>> But the code l have written so far saids invalid syntax at 2nd line.
>> Here is my code:
>> 
>> 
>> 
>> while True:
>>If active then
>>   FFSnapShot(areaX, areaY + height - offsetBottom, areaX + width,
>>   areaY + height - offsetBottom, sid)
>>   For row = 0 To norows - 1
>>  c = FFGetPixel(areaX + row * rowWidth + 5, areaY + height -
>>  offsetBottom, sid)
>>  cs = _ColorGetRGB(c)
>>  b = ( cs[0] * 0.3 ) + ( cs[1] * 0.59 ) + ( cs[2] * 0.11 )
>>  If lock[row] Then
>> If b < darkness Then
>>ContinueLoop
>> Else
>>lock[row] = False
>> EndIf
>>  EndIf If b < darkness Then
>> MouseUp("Left")
>> lock[row] = True MouseMove(areaX + row * rowWidth + rowWidth
>> / 2, areaY + height - offsetBottom, 1)
>> MouseDown("Left")
>>  EndIf
>>   Next
>>EndIf
>> End
>> 
>> Can someone help me please?
> 
> Is observation this is not Python code
> it looks more like some variety of BASIC but I could easily be wrong

I looks very similar to Visual Basic except I know of no instances
where '[]' are used in an array, as in lock[row].  The functions
that begin with 'FF' are from a pixel search library called FastFind.
It works with several different programming languages so no definite
clue there.  I'm not sure about the Mouse functions.  They could also
be from a library.  In VB the functions would be called like this:
object.MouseUp().  I'm not sure what the code is but it definitely
is not Python.

-- 
 GNU/Linux user #557453
May the Source be with you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay (Re: Assignment versus binding)

2016-10-12 Thread Steve D'Aprano
On Wed, 12 Oct 2016 11:52 pm, Gregory Ewing wrote:

> Steven D'Aprano wrote:
>> "the implementation is free to use in-place mutations of the state object
>> – ... without letting anyone know that the implementation has given up
>> any functional purity."
> 
> If it's impossible to tell that functional purity has
> been given up, then in what sense has it been given up
> at all?

Did I say it was impossible to tell?

Just because Donald Trump doesn't admit to wearing a hairpiece doesn't mean
that nobody can tell that he does. *wink*

The way you can usually tell your functional language has given up purity in
favour of mutating implementations is that your code actually runs with
non-toy amounts of data :-)




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Scripting Help please

2016-10-12 Thread Terry Reedy

On 10/12/2016 4:37 PM, LongHairLuke wrote:

Hi l am on my way to make a bot for the game Piano Tiles 2. But the
code l have written so far saids invalid syntax at 2nd line. Here is
my code:


If you want to write Python code, start by working through the tutorial 
included with the docs.


--
Terry Jan Reedy

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


RE: smtplib TimeoutError not catch

2016-10-12 Thread Joaquin Alzola
>Not surprisingly, the exception you should catch is simply TimeoutError:

 >try:
 >server.sendmail(sender, receivers, msg.as_string())
 >except TimeoutError as e:
 >print("SMTP could not be contacted: %s" % e)
 >finally:
 >   server.quit()

The error was thrown by another line :S, after putting the TimeoutError it work 
OK (with the proper exception line).

I had to apply a WA server = None to avoid the finally " UnboundLocalError: 
local variable 'server' referenced before assignment "

server = None
   try:
server = smtplib.SMTP('smtp.mail.com')   <--- this is where the 
exception was happening.
server.set_debuglevel(True) # show communication with the server
server.sendmail(sender, receivers, msg.as_string())
except TimeoutError as e:
print("SMTP could not be access: %s"%e)
pass
finally:
if server:
server.quit()


Joaquin


This email is confidential and may be subject to privilege. If you are not the 
intended recipient, please do not copy or disclose its content but contact the 
sender immediately upon receipt.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [TIP] testfixtures 4.11.0 Released!

2016-10-12 Thread Chris Withers

*sigh*, it's 4.11.0 that was released with these changes...

On 12/10/2016 17:06, Chris Withers wrote:

Hi All,

I'm pleased to announce the release of testfixtures 4.10.1 featuring 
the following:


- Allow the attributes returned in LogCapture.actual() rows to be
  specified.

- Allow a default to be specified for encoding in TempDirectory.read() 
and TempDirectory.write().


The package is on PyPI and a full list of all the links to docs, issue 
trackers and the like can be found here:


https://github.com/Simplistix/testfixtures

Any questions, please do ask on the Testing in Python list or on the 
Simplistix open source mailing list...


cheers,

Chris

___
testing-in-python mailing list
testing-in-pyt...@lists.idyll.org
http://lists.idyll.org/listinfo/testing-in-python


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