Re: how to send a json of yield list

2016-10-13 Thread dieter
meInvent bbird  writes:

> after google a several solutions, 
> First method i searched has memory error
> sock.send(json.dumps(StreamArray()))
> Traceback (most recent call last):
>   File "pusher.py", line 43, in 
> sock.send(json.dumps(StreamArray()))
> ...
> MemoryError

"MemoryError" means that the operating system could not provide
as much memory as required.

This is a bit surprising as you seem to try to dump a newly
build object. But, maybe, your objects starts huge right from the
beginning?


> if use this solution, got another error
>
> combobject = getcombinations()
> sock.send(json.dumps(combobject, cls=PythonObjectEncoder))
>
> Traceback (most recent call last):
> ...
> sock.send(json.dumps(combobject, cls=PythonObjectEncoder))
> ...
> TypeError: can't pickle generator objects

Apply "list" to your generator before dumping, i.e.
  sock.send(json.dumps(list(combobject), ...))


Note in addition, that you can get a file like object from a socket
and then use "json.dump" (rather then "json.dumps"). This might (!)
better hanlde huge objects.

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


Can't pickle : attribute lookup __builtin__.gen erator failed

2016-10-13 Thread meInvent bbird
Traceback (most recent call last):
  File "C:\Python27\lib\multiprocessing\queues.py", line 262, in _feed
send(obj)
PicklingError: Can't pickle : attribute lookup __builtin__.gen
erator failed


#python pusher.py tcp://*:8080
import sys
import time
import zmq

from multiprocessing import Queue
import threading

import json
from json import dumps, loads, JSONEncoder, JSONDecoder
import pickle
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput

class PythonObjectEncoder(JSONEncoder):
def default(self, obj):
if isinstance(obj, (list, dict, str, unicode, int, float, bool, 
type(None))):
return JSONEncoder.default(self, obj)
return {'_python_object': pickle.dumps(obj)}

def as_python_object(dct):
if '_python_object' in dct:
return pickle.loads(str(dct['_python_object']))
return dct

context = zmq.Context()
sock = context.socket(zmq.PUSH)
sock.bind(sys.argv[1])

def getcombinations():
for ii in range(1,2000):
for jj in range(1,2000):
for kk in range(1,2000):
yield [ii,jj,kk]

class StreamArray(list):
def __iter__(self):
return getcombinations()

# according to the comment below
def __len__(self):
return 1

def worker():
while True:
if q.qsize() < 1000:
q.put(getcombinations())

q = Queue(maxsize=1000)
t = threading.Thread(target=worker, args = ())
t.daemon = True
t.start()

while True:
time.sleep(1)
#sock.send(sys.argv[1] + ':' + time.ctime())
combobject = getcombinations()
#sock.send(json.dumps(combobject, cls=PythonObjectEncoder))
if q.qsize() > 0:
item = q.get()
sock.send(json.dumps(item))
#sock.send(json.dumps(combobject, cls=PythonObjectEncoder))
-- 
https://mail.python.org/mailman/listinfo/python-list


cannot import name pyhop

2016-10-13 Thread Gipper
I'm trying to run a script that calls pyhop (from pyhop import pyhop).  Details 
here > https://docs.extrahop.com/5.0/extrahop-python-api/#metrics

I've followed the directions to install and import pyhop, but no matter what I 
do, I always get the following error when running a script that calls pyhop >

Traceback (most recent call last):
  File "Migration.py", line 1, in 
from pyhop import pyhop
ImportError: cannot import name pyhop

Any ideas where I'm going wrong?  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Without compilation, how to find bugs?

2016-10-13 Thread Marko Rauhamaa
pozz :

> All the tricks have a common goal: to discover bugs as soon as possible,
> mostly during compilation process. Indeed I usually find some bugs
> during compilation (or static analysis). It seems to me very important.

Yes, it can be very useful, and with Python, you sacrifice that.

> I will not notice the bug until I test exactly the erroneous line of
> code (the call with only one argument).

Everything must be tested anyway, and even that may not be enough.
Recently, I was guilty of an atrocious buffer overflow in C. It wasn't
caught by the compiler or testing -- during the test run, the stack
happened to contain a series of zeros.

> Are the things exactly how I understood, or do I miss something in
> Python?

What you don't yet appreciate is how Python adds to program quality.
With its concise, high-level constructs, you end up expressing more with
far less code and far less boilerplate. Your code is far easier to get
right, and you can put together more complicated solutions that are
still robust.


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


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

2016-10-13 Thread Marko Rauhamaa
Gregory Ewing :

> Marko Rauhamaa wrote:
>> This suggests even the promoters of functional programming
>> intuitively prefer imperative programming, but that's ok as long as
>> it's all functional under the hood.
>
> You make it sound like functional programmers like functional
> programming because it gives them a warm fuzzy feeling. I don't think
> that's true -- there are specific reasons they like it, and those
> reason still apply when I/O is expressed using a monadic structure.
>
> Read Part 2 - I have something to say about that at the end.

I've read it. This looks awfully imperative to me:

   main = do
 putStrLn "Hi, what's your name?"
 name <- getLine
 putStrLn ("Aren't monads great, " ++ name ++ "?")

Scheme programmers have (begin ...) for sequential blocks and (do ...)
and (for-each ...) for loops.

As your Part 2 indicates, Haskell's use of monads to implement I/O is
not pure functional programming. The order of execution is significant
and functions have side effects.

Nothing wrong with any of this. I'm all for mixed paradigms.


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


Re: Python-based monads essay part 2

2016-10-13 Thread Jussi Piitulainen
Gregory Ewing writes:

> A bit more on SMFs, and then some I/O.
>
> http://www.cosc.canterbury.ac.nz/greg.ewing/essays/monads/DemystifyingMonads2.html

Thanks.

It would be good to spell out SMF at the start of the page.

"The definition of / above" (__truediv__ method) was not given "above"
(in the definition of SMF).
-- 
https://mail.python.org/mailman/listinfo/python-list


how to use pycallgraph in ubuntu and window?

2016-10-13 Thread meInvent bbird
i install in ubunbu 14

pip install graphviz
pip install pycallgraph

martin@ubuntu:~/Downloads$ pycallgraph graphviz -- ./pusher.py
Traceback (most recent call last):
  File "/usr/local/bin/pycallgraph", line 25, in 
with __pycallgraph.PyCallGraph(config=__config):
  File "/usr/local/lib/python2.7/dist-packages/pycallgraph/pycallgraph.py", 
line 32, in __init__
self.reset()
  File "/usr/local/lib/python2.7/dist-packages/pycallgraph/pycallgraph.py", 
line 53, in reset
self.prepare_output(output)
  File "/usr/local/lib/python2.7/dist-packages/pycallgraph/pycallgraph.py", 
line 97, in prepare_output
output.sanity_check()
  File "/usr/local/lib/python2.7/dist-packages/pycallgraph/output/graphviz.py", 
line 63, in sanity_check
self.ensure_binary(self.tool)
  File "/usr/local/lib/python2.7/dist-packages/pycallgraph/output/output.py", 
line 96, in ensure_binary
'The command "{}" is required to be in your path.'.format(cmd))
pycallgraph.exceptions.PyCallGraphException: The command "dot" is required to 
be in your path.


in window 

i had already added path

C:\Python27\Lib\site-packages\graphviz;C:\Python27\Lib\site-packages\pycallgraph

 to environment variable path

but in cmd

'pycallgraph' is not recognized as an internal or external command,
operable program or batch file.

then i use full path

>python "C:\Python27\Lib\site-packages\pycallgraph\py
callgraph.py"  -- "C:\Users\hello\Downloads\pusher.py"
Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\pycallgraph\pycallgraph.py", line 3, in 
from .output import Output
ValueError: Attempted relative import in non-package


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


how to send a json of yield list

2016-10-13 Thread meInvent bbird
after google a several solutions, 

First method i searched has memory error
sock.send(json.dumps(StreamArray()))
Traceback (most recent call last):
  File "pusher.py", line 43, in 
sock.send(json.dumps(StreamArray()))
  File "C:\Python27\lib\json\__init__.py", line 243, in dumps
return _default_encoder.encode(obj)
  File "C:\Python27\lib\json\encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
  File "C:\Python27\lib\json\encoder.py", line 270, in iterencode
return _iterencode(o, 0)
MemoryError

if use this solution, got another error

combobject = getcombinations()
sock.send(json.dumps(combobject, cls=PythonObjectEncoder))

C:\Users\martlee2\Downloads>python pusher.py tcp://*:8080
Traceback (most recent call last):
  File "pusher.py", line 42, in 
sock.send(json.dumps(combobject, cls=PythonObjectEncoder))
  File "C:\Python27\lib\json\__init__.py", line 250, in dumps
sort_keys=sort_keys, **kw).encode(obj)
  File "C:\Python27\lib\json\encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
  File "C:\Python27\lib\json\encoder.py", line 270, in iterencode
return _iterencode(o, 0)
  File "pusher.py", line 13, in default
return {'_python_object': pickle.dumps(obj)}
  File "C:\Python27\lib\pickle.py", line 1374, in dumps
Pickler(file, protocol).dump(obj)
  File "C:\Python27\lib\pickle.py", line 224, in dump
self.save(obj)
  File "C:\Python27\lib\pickle.py", line 306, in save
rv = reduce(self.proto)
  File "C:\Python27\lib\copy_reg.py", line 70, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle generator objects



#python pusher.py tcp://*:8080
import sys
import time
import zmq
import json
from json import dumps, loads, JSONEncoder, JSONDecoder
import pickle

class PythonObjectEncoder(JSONEncoder):
def default(self, obj):
if isinstance(obj, (list, dict, str, unicode, int, float, bool, 
type(None))):
return JSONEncoder.default(self, obj)
return {'_python_object': pickle.dumps(obj)}

def as_python_object(dct):
if '_python_object' in dct:
return pickle.loads(str(dct['_python_object']))
return dct

context = zmq.Context()
sock = context.socket(zmq.PUSH)
sock.bind(sys.argv[1])

def getcombinations():
for ii in range(1,2000):
for jj in range(1,2000):
for kk in range(1,2000):
yield [ii,jj,kk]

class StreamArray(list):
def __iter__(self):
return getcombinations()

# according to the comment below
def __len__(self):
return 1

while True:
time.sleep(1)
#sock.send(sys.argv[1] + ':' + time.ctime())
combobject = getcombinations()
sock.send(json.dumps(combobject, cls=PythonObjectEncoder))



puller.py

#python puller.py tcp://localhost:8080
import sys
import zmq
import json

context = zmq.Context()
sock = context.socket(zmq.PULL)

for arg in sys.argv[1:]:
sock.connect(arg)

while True:
message = sock.recv()
combinations = json.loads(message)
print(str(combinations))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Without compilation, how to find bugs?

2016-10-13 Thread sohcahtoa82
On Thursday, October 13, 2016 at 4:06:36 PM UTC-7, pozz wrote:
> I come from the C language, that is a compiled and strongly typed 
> language.  I learned many good tricks to write good code in C: choose a 
> coding style, turn on as many warnings as possible, explicitly declare 
> static variables and functions (when needed), explicitly declare const 
> variables (if the piece of code will not change them), explicitly 
> declare all the functions, and so on.
> 
> All the tricks have a common goal: to discover bugs as soon as possible, 
> mostly during compilation process. Indeed I usually find some bugs 
> during compilation (or static analysis). It seems to me very important.
> 
> Now I'm learning Python and it appears to me very simple, but at the 
> same time highly dangerous. For example, I can write a function that 
> accepts two arguments and call it with only one argument. I can execute 
> the script without any problem and I will not notice the bug until I 
> test exactly the erroneous line of code (the call with only one argument).
> 
> However, I think the language interpreter could emit the error before 
> launching the script even without executing the wrong instruction, 
> because it perfectly knows how many arguments the function wants and 
> that one instruction calls it with a wrong number of arguments.
> 
> Are the things exactly how I understood, or do I miss something in Python?

As others have said, user a linter.

I'd go a step further and use an actual code editor or IDE that includes some 
basic static analysis.  Using this example that Skip used:

def func2(a, b): 
print(a, b) 

def func1(a): 
print(a) 

func2(1)

Any code editor worth using will highlight the ) on the last line and tell you 
that there's a missing parameter.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Without compilation, how to find bugs?

2016-10-13 Thread Skip Montanaro
One other thing. The OP mentioned coming from C. If you are old enough, you
will remember that many errors caught by gcc and other modern compilers
used to be detected by external checkers like lint. Most Makefiles had
"lint" targets in them.

So although you might associate all sorts of error detection and reporting
with the compiler, there is no particular reason it must be there.

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


Re: Without compilation, how to find bugs?

2016-10-13 Thread Irmen de Jong
On 14-10-2016 1:07, pozz wrote:
> All the tricks have a common goal: to discover bugs as soon as possible, 
> mostly during
> compilation process. Indeed I usually find some bugs during compilation (or 
> static
> analysis). It seems to me very important.

I wanted to reply a bit more to this paragraph as well.

I agree that finding bugs as soon as possible is nice, but the thing to keep in 
mind is
that the kind of bugs you find during compilation are almost always syntactic 
errors,
typos or other simple mistakes. I think semantic and logic errors are usually 
the ones
that have the biggest impact and take by far the most time to debug and fix. 
These bugs
mostly cannot be detected by compilers anyway. A syntactically valid program 
can do
something completely bogus (and almost always does because humans make mistakes 
when
designing and building it)

In my personal experience I find that I make a lot LESS syntactic errors and 
simple
mistakes in Python than in other languages. Mostly because Python produces very 
clear
and concise programs when compared to other languages (especially languages as 
low level
as C).  A function of 30 lines in Python has a lot less chance to have a bug 
than an
equivalent function that requires 300 lines to write elsewhere.

Bottom line: >I< don't really need static compiler checks when working in 
Python.  I do
miss them sometimes when refactoring stuff, but that's where a solid unit test 
suite
comes to the rescue.


Irmen

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


Re: Without compilation, how to find bugs?

2016-10-13 Thread Ben Finney
pozz  writes:

> All the tricks have a common goal: to discover bugs as soon as
> possible, mostly during compilation process. Indeed I usually find
> some bugs during compilation (or static analysis). It seems to me very
> important.

Do you also use static code analysis? Do you find that static code
analysis finds many types of bugs that compilation could not find?

Do you always write use unit tests for the code you write? For the
existing code you change? Do you specify the unit tests so that they
each assert one specific thing about the function's behaviour, and fail
unambiguously when that's not the observed behaviour?

Do you aim for complete unit test coverage of all branches in your code?
Do you treat un-covered code as dangerously unpredictable code?

If your answer is “no” to any of those, I think you may have a good
answer to your overall question :-)

-- 
 \   “A poet can survive everything but a misprint.” —Oscar Wilde, |
  `\   _The Children of the Poets_, 1886-10-14 |
_o__)  |
Ben Finney

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


Re: Without compilation, how to find bugs?

2016-10-13 Thread Irmen de Jong
On 14-10-2016 1:07, pozz wrote:
> I come from the C language, that is a compiled and strongly typed language. 

C is far from a strongly typed language, IMO...
You can convert (cast) almost anything to anything else without compiler errors.
Have a a float? Ah yes no I mean treat it as a pointer to a function taking a 
char*
instead. Things can blow up majorly at runtime (segfault or worse)
Python is much more strongly typed than this. You can never do something to an 
object
that is not defined in its interface, and an object is always exactly known to 
be of one
particular type.

Perhaps you're thinking about statically typed versus dynamically typed?

> I learned
> many good tricks to write good code in C: choose a coding style, turn on as 
> many
> warnings as possible, explicitly declare static variables and functions (when 
> needed),
> explicitly declare const variables (if the piece of code will not change 
> them),
> explicitly declare all the functions, and so on.
> 
> All the tricks have a common goal: to discover bugs as soon as possible, 
> mostly during
> compilation process. Indeed I usually find some bugs during compilation (or 
> static
> analysis). It seems to me very important.
> 
> Now I'm learning Python and it appears to me very simple, but at the same 
> time highly
> dangerous. For example, I can write a function that accepts two arguments and 
> call it
> with only one argument. I can execute the script without any problem and I 
> will not
> notice the bug until I test exactly the erroneous line of code (the call with 
> only one
> argument).
> 
> However, I think the language interpreter could emit the error before 
> launching the
> script even without executing the wrong instruction, because it perfectly 
> knows how many
> arguments the function wants and that one instruction calls it with a wrong 
> number of
> arguments.
> 
> Are the things exactly how I understood, or do I miss something in Python?

Python is a *very* dynamic language so static checks are usually extremely hard 
to do.
Recent IDEs and tools (checkers, linters) have made some progress though, and 
type hints
have been added to the language recently to support this.

The biggie I think is that in the Python world the concept of *unit tests* is an
extremely important one. That is (I feel) the major tool being used to not only 
find
existing bugs, but also to avoid introducing new ones while changing the 
program.

Something which I believe you need everywhere else as well, regardless of 
programming
language. Proper unit testing (and testing in general) is much more powerful 
than
placing a lot of trust in the compiler.


Irmen

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


Re: Without compilation, how to find bugs?

2016-10-13 Thread Grant Edwards
On 2016-10-13, pozz  wrote:

> However, I think the language interpreter could emit the error before 
> launching the script even without executing the wrong instruction, 
> because it perfectly knows how many arguments the function wants and 
> that one instruction calls it with a wrong number of arguments.
>
> Are the things exactly how I understood, or do I miss something in Python?

Python is a dynamic language, and it turns out it's very difficult to
know for sure, using static code analysis, at compiler time, what
function a name is going to be bound to at any particular point at run
time.

That said, there is pylint which does try to do as much static error
checking as possible.



-- 
Grant





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


Re: Without compilation, how to find bugs?

2016-10-13 Thread Skip Montanaro
> I can execute the script without any problem and I will not notice the
bug until I
> test exactly the erroneous line of code (the call with only one argument).

The key phrase there being "until I test..."  There are static
analysis tools for Python like pylint. Given this simple module:

#!/usr/bin/env python

def func2(a, b):
print(a, b)

def func1(a):
print(a)

func2(1)

among other messages, pylint prints:

E:  9, 0: No value for argument 'b' in function call
(no-value-for-parameter)

where line 9 is the erroneous call to func2().

Static analysis tools like pylint aren't perfect, but do catch a bunch of
stuff. Also, given the run-time detection of errors, in dynamic languages
like Python, unit tests and code coverage are particularly important. Also,
check out type hints, mypy, and the typeshed project:

https://www.python.org/dev/peps/pep-0484/
http://mypy-lang.org/
https://github.com/python/typeshed

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


Without compilation, how to find bugs?

2016-10-13 Thread pozz
I come from the C language, that is a compiled and strongly typed 
language.  I learned many good tricks to write good code in C: choose a 
coding style, turn on as many warnings as possible, explicitly declare 
static variables and functions (when needed), explicitly declare const 
variables (if the piece of code will not change them), explicitly 
declare all the functions, and so on.


All the tricks have a common goal: to discover bugs as soon as possible, 
mostly during compilation process. Indeed I usually find some bugs 
during compilation (or static analysis). It seems to me very important.


Now I'm learning Python and it appears to me very simple, but at the 
same time highly dangerous. For example, I can write a function that 
accepts two arguments and call it with only one argument. I can execute 
the script without any problem and I will not notice the bug until I 
test exactly the erroneous line of code (the call with only one argument).


However, I think the language interpreter could emit the error before 
launching the script even without executing the wrong instruction, 
because it perfectly knows how many arguments the function wants and 
that one instruction calls it with a wrong number of arguments.


Are the things exactly how I understood, or do I miss something in Python?
--
https://mail.python.org/mailman/listinfo/python-list


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

2016-10-13 Thread Gregory Ewing

Marko Rauhamaa wrote:

This suggests even the promoters of functional programming intuitively
prefer imperative programming, but that's ok as long as it's all
functional under the hood.


You make it sound like functional programmers like functional
programming because it gives them a warm fuzzy feeling. I don't
think that's true -- there are specific reasons they like
it, and those reason still apply when I/O is expressed using
a monadic structure.

Read Part 2 - I have something to say about that at the end.

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


Re: [RELEASE] Python 3.6.0b2 is now available

2016-10-13 Thread eryk sun
On Thu, Oct 13, 2016 at 9:45 PM, Irmen de Jong  wrote:
>
>>> On 12-10-2016 12:56, Robin Becker wrote:
>>>
 I notice an extra space at the windows command prompt compared with 3.5, 
 is that
 deliberate?
> 
> Wow that was stupid, sorry. Anyway, I'm not seeing it with 3.6.0b2 either:
>
> Python 3.6.0b2 (v3.6.0b2:b9fadc7d1c3f, Oct 10 2016, 20:36:51) [MSC v.1900 32 
> bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
 import sys


I see the problem. In beta 2, PyOS_StdioReadline now decodes the
prompt string as UTF-8 and writes it via WriteConsoleW. This resolves
issue 28333 [1]. In my patch I used the length from strlen(prompt),
which doesn't include the terminating NUL, since it isn't needed when
calling WriteConsoleW. Steve Dower changed this to instead have
MultiByteToWideChar calculate the length, which is fine in itself, but
it does include the trailing NUL. Thus instead of writing ">>> "
(length 4) to the console, it's writing ">>> \x00" (length 5). You can
see this in the debugger when stepping into PyOS_StdioReadline:

python36!PyOS_StdioReadline+0x14c:
`52c89bd4 ff15def80200callqword ptr
[python36!_imp_WriteConsoleW (`52cb94b8)]
ds:`52cb94b8=
{KERNEL32!WriteConsoleW (7fff`6d264bc0)}

0:000> du @rdx
01d9`c334aee0  ">>> "
0:000> r r8
r8=0005
0:000> dw @rdx l5
01d9`c334aee0  003e 003e 003e 0020 

It's a simple fix. Just use (wlen - 1) instead of wlen.

[1]: http://bugs.python.org/issue28333
-- 
https://mail.python.org/mailman/listinfo/python-list


Python-based monads essay part 2

2016-10-13 Thread Gregory Ewing

A bit more on SMFs, and then some I/O.

http://www.cosc.canterbury.ac.nz/greg.ewing/essays/monads/DemystifyingMonads2.html

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


Re: [RELEASE] Python 3.6.0b2 is now available

2016-10-13 Thread MRAB

On 2016-10-13 22:45, Irmen de Jong wrote:

On 13-10-2016 23:43, MRAB wrote:

On 2016-10-13 20:42, Irmen de Jong wrote:

On 12-10-2016 12:56, Robin Becker wrote:


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




I'm not seeing this... (using the 32 bits version on win7)

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit 
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.

import sys




That's Python 3.5.1. The issue is with Python 3.6.0b2.



Wow that was stupid, sorry. Anyway, I'm not seeing it with 3.6.0b2 either:

Python 3.6.0b2 (v3.6.0b2:b9fadc7d1c3f, Oct 10 2016, 20:36:51) [MSC v.1900 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import sys




I'm seeing it on Windows 10.

Python 3.6.0b2 (v3.6.0b2:b9fadc7d1c3f, Oct 10 2016, 20:36:51) [MSC 
v.1900 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>>  import sys
>>>


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
>>>


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


Re: [RELEASE] Python 3.6.0b2 is now available

2016-10-13 Thread Irmen de Jong
On 13-10-2016 23:43, MRAB wrote:
> On 2016-10-13 20:42, Irmen de Jong wrote:
>> On 12-10-2016 12:56, Robin Becker wrote:
>>
>>> 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
>>>
>>
>> I'm not seeing this... (using the 32 bits version on win7)
>>
>> Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit 
>> (Intel)] on
>> win32
>> Type "help", "copyright", "credits" or "license" for more information.
> import sys
>
>>
> That's Python 3.5.1. The issue is with Python 3.6.0b2.
> 

Wow that was stupid, sorry. Anyway, I'm not seeing it with 3.6.0b2 either:

Python 3.6.0b2 (v3.6.0b2:b9fadc7d1c3f, Oct 10 2016, 20:36:51) [MSC v.1900 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>>


Irmen

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


Re: [RELEASE] Python 3.6.0b2 is now available

2016-10-13 Thread MRAB

On 2016-10-13 20:42, Irmen de Jong wrote:

On 12-10-2016 12:56, Robin Becker wrote:


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




I'm not seeing this... (using the 32 bits version on win7)

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit 
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.

import sys




That's Python 3.5.1. The issue is with Python 3.6.0b2.

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


Re: [RELEASE] Python 3.6.0b2 is now available

2016-10-13 Thread Irmen de Jong
Anyone else having problems with pip and python 3.6.0b2?
Pip now fails to create launcher scripts:

  File "c:\python36\lib\site-packages\pip\_vendor\distlib\scripts.py", line 
351, in
_get_launcher
result = finder(distlib_package).find(name).bytes
  File "c:\python36\lib\site-packages\pip\_vendor\distlib\resources.py", line 
324, in finder
raise DistlibException('Unable to locate finder for %r' % package)
pip._vendor.distlib.DistlibException: Unable to locate finder for 
'pip._vendor.distlib'


Using latest pip and distlib versions.
Python 3.6.0b2 32-bits on Windows 7.


Irmen

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


Re: [RELEASE] Python 3.6.0b2 is now available

2016-10-13 Thread Irmen de Jong
On 12-10-2016 12:56, Robin Becker wrote:

> 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
> 

I'm not seeing this... (using the 32 bits version on win7)

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit 
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>>

Irmen

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


Re: try-except with no exceptions

2016-10-13 Thread Ben Finney
Daiyue Weng  writes:

> I am wondering how to correct the code above (what it tries to do is
> basically trying one processing block, if not working, running another
> block of code in except). Also a warning 'Too broad exception clause'
> will be generated.

Yes. You need to be *very* clear about which specific “not working”
conditions you expect to handle, and catch only those.

Also, having identified which specific conditions you will handle, you
need to break complex statements and expressions into simpler ones, and
only place reduce the ‘try’ block to only those statements which will
encounter those conditions. Move everything else outside the ‘try …
except …’ altogether.

-- 
 \ “In prayer, it is better to have a heart without words than |
  `\ words without heart.” —Mohandas K. Gandhi |
_o__)  |
Ben Finney

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


Re: try-except with no exceptions

2016-10-13 Thread Peter Otten
Daiyue Weng wrote:

> Hi, I have seen code using try_except with no exceptions,
> 
> from dateutil import parser
> 
> try:
> from_date = datetime.datetime.strptime(parameters['from_date'],
> '%Y-%m-%d %H:%M:%S.%f')
> to_date = datetime.datetime.strptime(parameters['to_date'],
> '%Y-%m-%d %H:%M:%S.%f')
> except:
> from_date = parser.parse(parameters['from_date'])
> to_date = parser.parse(parameters['to_date'])
> 
> 
> I know that such try-catch usage is generally a bad practice, since it
> can't locate the root of the exceptions.
> 
> I am wondering how to correct the code above (what it tries to do is
> basically trying one processing block, if not working, running another
> block of code in except). Also a warning 'Too broad exception clause'
> will be generated.

Is it intentional that both times have to be parsed by the same function?
If not I'd do

def parse_date(datestr):
try:
return datetime.datetime.strptime(datestr, '%Y-%m-%d %H:%M:%S.%f')
except ValueError:
return dateutil.parser.parse(datestr)


from_date = parse_date(parameters['from_date'])
to_date = parse_date(parameters['to_date'])

Exceptions other than ValueError are probably hints that the program logic 
is flawed, so I'd rather have them bubble up.

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


Re: try-except with no exceptions

2016-10-13 Thread Jussi Piitulainen
Daiyue Weng writes:

> Hi, I have seen code using try_except with no exceptions,
>
> from dateutil import parser
>
> try:
> from_date = datetime.datetime.strptime(parameters['from_date'],
> '%Y-%m-%d %H:%M:%S.%f')
> to_date = datetime.datetime.strptime(parameters['to_date'],
> '%Y-%m-%d %H:%M:%S.%f')
> except:
> from_date = parser.parse(parameters['from_date'])
> to_date = parser.parse(parameters['to_date'])
>
>
> I know that such try-catch usage is generally a bad practice, since it
> can't locate the root of the exceptions.
>
> I am wondering how to correct the code above (what it tries to do is
> basically trying one processing block, if not working, running another
> block of code in except). Also a warning 'Too broad exception clause'
> will be generated.

Since help(datetime.strptime) didn't tell, I experimented with
datetime.strptime a bit. It seems to raise a ValueError when a string is
not formatted according to the pattern or has some component out of
range, and TypeError when given a non-string to parse. Tracebacks
indicate the exception type.

There's no point in catching KeyError, because the except clause would
do the same thing again.

try:
   # try with datetime.datetime.strptime
   ...
except (ValueError, TypeError):
   # try with dateutil.parser.parse
   ...

Also: https://docs.python.org/3/tutorial/errors.html
-- 
https://mail.python.org/mailman/listinfo/python-list


try-except with no exceptions

2016-10-13 Thread Daiyue Weng
Hi, I have seen code using try_except with no exceptions,

from dateutil import parser

try:
from_date = datetime.datetime.strptime(parameters['from_date'],
'%Y-%m-%d %H:%M:%S.%f')
to_date = datetime.datetime.strptime(parameters['to_date'],
'%Y-%m-%d %H:%M:%S.%f')
except:
from_date = parser.parse(parameters['from_date'])
to_date = parser.parse(parameters['to_date'])


I know that such try-catch usage is generally a bad practice, since it
can't locate the root of the exceptions.

I am wondering how to correct the code above (what it tries to do is
basically trying one processing block, if not working, running another
block of code in except). Also a warning 'Too broad exception clause'
will be generated.


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


Re: how to read linux kernel source with pycparser

2016-10-13 Thread Michael Torrie
On 10/13/2016 02:19 AM, meInvent bbird wrote:
> is it possible to git pull a part of directory such as sched
> and compile this subdirectory and pycparser it?

I'm sure you could but it wouldn't help you.  The parts of the kernel
are modular but you can't compile them without configuring the whole
source tree.  Configuration is stored in header files farther up the
tree, generated by the configuration process.  Once the kernel source
tree is configured (make menuconfig), you can, of course, just build a
particular directory, such as sched.  But as you can see from your trial
run, there are a lot of header file dependencies.

Why are you trying to use the linux kernel? That's one of the largest
and most complicated projects in the world.  Why not start with a
simple, one-file C program?
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANN] Zeus IDE - Version 3.98g released

2016-10-13 Thread jumppanen . jussi
Zeus does code folding, syntax highlighting, smart indenting, code
navigation for the Python language.

In addition the latest Zeus release has moved off Python 2.7x and 
now supports the latest Python 3.5x release.

To see what new visit this link:

   http://www.zeusedit.com/whatsnew.html

Jussi Jumppanen
Author: Zeus IDE
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-10-13 Thread Marko Rauhamaa
Gregory Ewing :
> Steve D'Aprano wrote:
>> 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 :-)
>
> Hmmm. Your argument here seems to be: "Everyone knows that functional
> languages are impractical, so if it's practical, then it can't be
> functional."
>
> If she weighs the same as a duck, she's a witch!

>From you essay:

   What's more, it's starting to look a lot like a sequential program.
   We can read it fairly clearly as "add the first element to the set,
   then add the rest of the elements to the set, unless the list is
   empty, in which case turn the set into a list and stop."

   http://www.cosc.canterbury.ac.nz/greg.ewing/essays/monads/Demy
   stifyingMonads.html>

It is interesting that right after introducing lambda calculus or pure
functional programming to students, textbooks quickly proceed to
demonstrate how the functional paradigm can emulate the imperative
paradigm, as you have done above.

This suggests even the promoters of functional programming intuitively
prefer imperative programming, but that's ok as long as it's all
functional under the hood.


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


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

2016-10-13 Thread Gregory Ewing

Steve D'Aprano wrote:

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 :-)


Hmmm. Your argument here seems to be: "Everyone knows
that functional languages are impractical, so if it's
practical, then it can't be functional."

If she weighs the same as a duck, she's a witch!

More seriously, saying "given up purity in favour of
mutating implementations" implies that the two are
mutually exclusive. I don't agree that they are.

At least as far as in-memory data structure are
concerned, in-place mutation is a form of garbage
collection. You notice that the old version of the
data is going to immediately become garbage, so it
might as well be replaced by the new version.

The observable behaviour of the program remains the
same. That's what I mean by "impossible to tell".

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


Re: how to read linux kernel source with pycparser

2016-10-13 Thread meInvent bbird
is it possible to git pull a part of directory such as sched
and compile this subdirectory and pycparser it?

i got error when run gcc -E

git submodule add he...@github.com:hello/repo.git kernel/sched
cd kernel/sched
git pull

martin@ubuntu:~/Downloads/kernel/sched$ gcc -E -std=c99 *.c
# 1 "auto_group.c"
# 1 ""
# 1 ""
# 1 "auto_group.c"
# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from auto_group.c:1:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "clock.c"
# 1 ""
# 1 ""
# 1 "clock.c"
clock.c:55:28: fatal error: linux/spinlock.h: No such file or directory
compilation terminated.
# 1 "completion.c"
# 1 ""
# 1 ""
# 1 "completion.c"
# 14 "completion.c"
# 1 "/usr/include/linux/sched.h" 1 3 4
# 15 "completion.c" 2
completion.c:15:30: fatal error: linux/completion.h: No such file or directory
compilation terminated.
# 1 "core.c"
# 1 ""
# 1 ""
# 1 "core.c"
core.c:29:25: fatal error: linux/kasan.h: No such file or directory
compilation terminated.
# 1 "cpuacct.c"
# 1 ""
# 1 ""
# 1 "cpuacct.c"
cpuacct.c:1:26: fatal error: linux/cgroup.h: No such file or directory
compilation terminated.
# 1 "cpudeadline.c"
# 1 ""
# 1 ""
# 1 "cpudeadline.c"
cpudeadline.c:14:23: fatal error: linux/gfp.h: No such file or directory
compilation terminated.
# 1 "cpufreq.c"
# 1 ""
# 1 ""
# 1 "cpufreq.c"
# 12 "cpufreq.c"
# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from cpufreq.c:12:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "cpufreq_schedutil.c"
# 1 ""
# 1 ""
# 1 "cpufreq_schedutil.c"
cpufreq_schedutil.c:14:27: fatal error: linux/cpufreq.h: No such file or 
directory
compilation terminated.
# 1 "cpupri.c"
# 1 ""
# 1 ""
# 1 "cpupri.c"
cpupri.c:30:23: fatal error: linux/gfp.h: No such file or directory
compilation terminated.
# 1 "cputime.c"
# 1 ""
# 1 ""
# 1 "cputime.c"
cputime.c:1:26: fatal error: linux/export.h: No such file or directory
compilation terminated.
# 1 "deadline.c"
# 1 ""
# 1 ""
# 1 "deadline.c"
# 17 "deadline.c"
# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from deadline.c:17:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "debug.c"
# 1 ""
# 1 ""
# 1 "debug.c"
debug.c:13:27: fatal error: linux/proc_fs.h: No such file or directory
compilation terminated.
# 1 "fair.c"
# 1 ""
# 1 ""
# 1 "fair.c"
# 23 "fair.c"
# 1 "/usr/include/linux/sched.h" 1 3 4
# 24 "fair.c" 2
fair.c:24:30: fatal error: linux/latencytop.h: No such file or directory
compilation terminated.
# 1 "idle.c"
# 1 ""
# 1 ""
# 1 "idle.c"



# 1 "/usr/include/linux/sched.h" 1 3 4
# 5 "idle.c" 2
idle.c:5:23: fatal error: linux/cpu.h: No such file or directory
compilation terminated.
# 1 "idle_task.c"
# 1 ""
# 1 ""
# 1 "idle_task.c"
# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from idle_task.c:1:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "loadavg.c"
# 1 ""
# 1 ""
# 1 "loadavg.c"
loadavg.c:9:26: fatal error: linux/export.h: No such file or directory
compilation terminated.
# 1 "rt.c"
# 1 ""
# 1 ""
# 1 "rt.c"





# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from rt.c:6:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "stats.c"
# 1 ""
# 1 ""
# 1 "stats.c"
stats.c:1:24: fatal error: linux/slab.h: No such file or directory
compilation terminated.
# 1 "stop_task.c"
# 1 ""
# 1 ""
# 1 "stop_task.c"
# 1 "sched.h" 1
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "sched.h" 2
In file included from stop_task.c:1:0:
sched.h:2:32: fatal error: linux/sched/sysctl.h: No such file or directory
compilation terminated.
# 1 "swait.c"
# 1 ""
# 1 ""
# 1 "swait.c"
# 1 "/usr/include/linux/sched.h" 1 3 4
# 2 "swait.c" 2
swait.c:2:25: fatal error: linux/swait.h: No such file or directory
compilation terminated.
# 1 "wait.c"
# 1 ""
# 1 ""
# 1 "wait.c"
wait.c:6:24: fatal error: linux/init.h: No such file or directory
compilation terminated.



On Wednesday, October 5, 2016 at 7:48:17 AM UTC+8, Michael Torrie wrote:
> On 10/04/2016 03:36 AM, meInvent bbird wrote:
> > i expect to use pycparser to read linux kernel source
> > and get a AST tree, 
> > 
> > but there are so many directory, 
> > 
> > how to read linux kernel source with pycparser?
> > 
> > how to customize pycparser to search what we want such as bug or fix 
> > to make a linux patch for linux kernel source with python?
> 
> C projects with many .c files aren't meant to be compiled into one unit
> (AST) usually.  The kernel is designed to be compiled into many
> discrete, compiled object files which are then linked together after
> compilation.  Each compilation unit would come from its own AST tree.
> Furthermore, most C files can't be

Re: Scripting Help please

2016-10-13 Thread Steven D'Aprano
On Thursday 13 October 2016 07:37, 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:

Folks, look at the email address of the poster:

trolleri.trollface at gmail.com

He's posted code that doesn't look anything like Python code, and all but 
admitted to trolling us. I don't think we should be responding.




-- 
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