Re: Method Chaining

2016-06-16 Thread Lawrence D’Oliveiro
On Friday, June 17, 2016 at 4:24:24 PM UTC+12, Michael Selik wrote:
> On Thu, Jun 16, 2016 at 10:53 PM Lawrence D’Oliveiro wrote:
> 
> > Example from ,
> > concisely expressing a complex drawing sequence:
> >
> > (g
> > .move_to((p1 + p2a) / 2)
> > .line_to(p1 + (p2 - p1) * frac)
> > .line_to((p1 + p1a) / 2)
> > .stroke()
> > .move_to((p2 + p2a) / 2)
> > .line_to(p2 + (p1 - p2) * frac)
> > .line_to((p2 + p1a) / 2)
> > .stroke()
> > )
> 
> Wouldn't that look nicer with the ``g`` repeated on every line, no extra
> indentation, and no extraneous parentheses?
> 
> g.move_to((p1 + p2a) / 2)
> g.line_to(p1 + (p2 - p1) * frac)
> g.line_to((p1 + p1a) / 2)
> g.stroke()
> g.move_to((p2 + p2a) / 2)
> g.line_to(p2 + (p1 - p2) * frac)
> g.line_to((p2 + p1a) / 2)
> g.stroke()

Clearly, no.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tie dictionary to database table?

2016-06-16 Thread Lawrence D’Oliveiro
On Friday, June 10, 2016 at 12:30:47 AM UTC+12, Peter Heitzer wrote:
> What I would like is if I write 
> 
> email['frank']='fr...@middle-of-nowhere.org'
> 
> in my python script it generates a statement like
> update users set email='fr...@middle-of-nowhere.org' where username='frank';

That’s not a database, that’s a key-value store.


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


Re: Method Chaining

2016-06-16 Thread Michael Selik
On Thu, Jun 16, 2016 at 10:53 PM Lawrence D’Oliveiro 
wrote:

> Example from ,
> concisely expressing a complex drawing sequence:
>
> (g
> .move_to((p1 + p2a) / 2)
> .line_to(p1 + (p2 - p1) * frac)
> .line_to((p1 + p1a) / 2)
> .stroke()
> .move_to((p2 + p2a) / 2)
> .line_to(p2 + (p1 - p2) * frac)
> .line_to((p2 + p1a) / 2)
> .stroke()
> )
>

Wouldn't that look nicer with the ``g`` repeated on every line, no extra
indentation, and no extraneous parentheses?

g.move_to((p1 + p2a) / 2)
g.line_to(p1 + (p2 - p1) * frac)
g.line_to((p1 + p1a) / 2)
g.stroke()
g.move_to((p2 + p2a) / 2)
g.line_to(p2 + (p1 - p2) * frac)
g.line_to((p2 + p1a) / 2)
g.stroke()

Sometimes it's hard to know when a function has a side-effect. I appreciate
that these impure functions tend to return None.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is structured programming (was for/while else doesn't make sense)

2016-06-16 Thread Lawrence D’Oliveiro
On Thursday, June 16, 2016 at 11:13:14 PM UTC+12, Rustom Mody wrote:

> Please see https://en.wikipedia.org/wiki/Nassi%E2%80%93Shneiderman_diagram
> 
> | Nassi–Shneiderman diagrams are (almost) isomorphic with
> | flowcharts. Everything you can represent with a Nassi–Shneiderman
> | diagram you can also represent with a flowchart.
> 
> which is in line with what I am saying, viz that break/continue/goto are same
> in the sense of being 'unstructured' and therefore do not fit into a
> structured framework like NSDs

This is just a restatement of the “structure theorem”, which proves that 
structured control statements are mathematically equivalent to gotos, and 
anything that can be expressed one way can be expressed the other way.

True, but a complete red herring.
-- 
https://mail.python.org/mailman/listinfo/python-list


Method Chaining

2016-06-16 Thread Lawrence D’Oliveiro
Some kinds of objects often receive a whole lot of method calls in sequence. In 
these situations, it is handy if each method call ends with “return self”, so 
that you can chain the calls together. This is particularly common with 
graphics APIs, for instance.

Example from , 
concisely expressing a complex drawing sequence:

(g
.move_to((p1 + p2a) / 2)
.line_to(p1 + (p2 - p1) * frac)
.line_to((p1 + p1a) / 2)
.stroke()
.move_to((p2 + p2a) / 2)
.line_to(p2 + (p1 - p2) * frac)
.line_to((p2 + p1a) / 2)
.stroke()
)

Another example 
, where an 
object requires setup calls that cannot all be expressed in the constructor:

pattern = \
qah.Pattern.create_linear \
  (
p0 = (0, 0),
p1 = (pattern_length, 0), # base orientation is parallel to X-axis
colour_stops =
(
(0, Colour.from_hsva((0.475, 0.9, 0.8))),
(1, Colour.from_hsva((0.975, 0.9, 0.8))),
)
  ).set_extend(CAIRO.EXTEND_REPEAT)

In , a temporary 
drawing context is created, used to create the image pattern, and then 
discarded, without even having to give it a name:

mask = qah.ImageSurface.create \
  (
format = CAIRO.FORMAT_RGB24,
dimensions = dimensions * scale
  )
(qah.Context.create(mask)
.set_matrix(Matrix.scale(scale))
.set_source_colour(primary[component])
.set_operator(CAIRO.OPERATOR_SOURCE)
.rectangle(spot)
.fill()
)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Method Chaining

2016-06-16 Thread Steven D'Aprano
On Fri, 17 Jun 2016 12:02 pm, Lawrence D’Oliveiro wrote:

> Some kinds of objects often receive a whole lot of method calls in
> sequence. In these situations, it is handy if each method call ends with
> “return self”, so that you can chain the calls together. This is
> particularly common with graphics APIs, for instance.
[...]


Yes, this is design that (for example) Ruby classes tend to follow. It's not
one that the Python builtins tend to follow, but of course people are free
to return self from their own classes' methods if they like.

As an alternative, you might find this simple adaptor useful:

http://code.activestate.com/recipes/578770-method-chaining/



-- 
Steven

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


Re: Contradictory error messages in Python 3.4 - standard library issue!

2016-06-16 Thread Steven D'Aprano
Hi Harrison, and welcome!


On Fri, 17 Jun 2016 08:25 am, Harrison Chudleigh wrote:

> While working on a program, I ran into an error with the usage of the
> module tokenize.

So you have an error with the use of tokenize. Fair enough.

But why do you imagine that the errors lies in the module itself, rather
that your use of it? There are probably tens of thousands, maybe hundreds
of thousands, of people using that module (directly or indirectly). The
chances that you have identified a bug in the module that nobody else has
seen before is pretty slim.

And that certainly shouldn't be your first assumption.


> The following message was displayed. 
>  File
> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py",
> line 467, in tokenize
> encoding, consumed = detect_encoding(readline)
>   File
> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py",
> line 409, in detect_encoding
> if first.startswith(BOM_UTF8):
> TypeError: startswith first arg must be str or a tuple of str, not bytes
> Undaunted, I changed the error on line 409. The line then read:
> 
> if first.startswith(BOM_UTF8):

I'm not seeing any actual difference between the before and after:

if first.startswith(BOM_UTF8):
if first.startswith(BOM_UTF8):

but in another email, you state that you changed it to:

if first.startswith('BOM_UTF8'):


Changing the source code of the standard library is almost never what you
want to be do. I've been programming in Python for 20+ years, and the
number of times I've edited the source code of the standard library to fix
a program is exactly zero.

But making random changes to the source code of the standard library without
understanding what it is doing or why is NEVER what you want to do.

All you have accomplished by editing the code is changing the situation
from "one in a 100,000 chance of a bug in the standard library"
to "certainly a bug in a non-standard module shared by absolutely nobody
else in the world".

Before we can help you, you MUST revert the module back to the way it was.
You have introduced a bug to the module, but worse, you've now made it so
that it is different from everyone else's tokenize module. Any errors you
have received after making that change, or changes, are irrelevant.

Then you need to show us how you are calling tokenize. Show us the ENTIRE
traceback, starting with the line beginning "Traceback", not just the last
line with the error message. Once we've seen that, we may be able to help
you, or we may have more questions, but that's the bare minimum we need.



-- 
Steven

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


Re: Re - Contradictory error messages in Python 3.4 - standard library issue!

2016-06-16 Thread Matt Wheeler
On Thu, 16 Jun 2016, 23:31 Harrison Chudleigh, <
harrison.chudlei...@education.nsw.gov.au> wrote:

> Sorry! I was trying to indent a line and accidentally sent only half of the
> message.
>

It would be helpful if your reply was actually a reply to your previous
message, to enable us to follow the thread of the conversation.

As I was saying, I changed the line and reran the program. However, this
> produced another group of error messages. One was -
>

>From what, to what? Just showing us stacktraces means we have to guess at
the problem.

File
>
> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py",
> line 438, in open
> encoding, lines = detect_encoding(buffer.readline)
>   File
>
> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py",
> line 409, in detect_encoding
> if first.startswith('BOM_UTF8'):
> TypeError: startswith first arg must be bytes or a tuple of bytes, not str.
> So, first the interpreter says startswith() takes strings, now it says it
> takes bytes? What should the module be doing?
>

The reason you're getting seemingly contradictory error messages is that
`.startswith()` is a method which belongs to the `first` object, and that
object is a different type between the first and the second time it's
called.
Both the `bytes` and `str` types have a `startswith` method, but each one
(understandably) only accepts an argument of the same type.

Without actually seeing your code I can't guess what the cause of that is,
but perhaps you need to decode a `bytes` object to a `str` or encode the
other way around.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Re - Contradictory error messages in Python 3.4 - standard library issue!

2016-06-16 Thread Ned Batchelder
On Thursday, June 16, 2016 at 6:39:27 PM UTC-4, Harrison Chudleigh wrote:
> Sorry! I was trying to indent a line and accidentally sent only half of the
> message.
> 
> As I was saying, I changed the line and reran the program. However, this
> produced another group of error messages. One was -
> File
> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py",
> line 438, in open
> encoding, lines = detect_encoding(buffer.readline)
>   File
> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py",
> line 409, in detect_encoding
> if first.startswith('BOM_UTF8'):
> TypeError: startswith first arg must be bytes or a tuple of bytes, not str.
> So, first the interpreter says startswith() takes strings, now it says it
> takes bytes? What should the module be doing?
> This is an error with the standard library of Python 3.4.1, Mac OS X.

You shouldn't have to edit the stdlib files to get your program to work.
It sounds like you are using values with the tokenize module that it isn't
expecting. Can you show your code?

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


Re - Contradictory error messages in Python 3.4 - standard library issue!

2016-06-16 Thread Harrison Chudleigh
Sorry! I was trying to indent a line and accidentally sent only half of the
message.

As I was saying, I changed the line and reran the program. However, this
produced another group of error messages. One was -
File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py",
line 438, in open
encoding, lines = detect_encoding(buffer.readline)
  File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py",
line 409, in detect_encoding
if first.startswith('BOM_UTF8'):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str.
So, first the interpreter says startswith() takes strings, now it says it
takes bytes? What should the module be doing?
This is an error with the standard library of Python 3.4.1, Mac OS X.
***
This message is intended for the addressee named and may contain privileged 
information or confidential information or both. If you are not the intended 
recipient please delete it and notify the sender.
-- 
https://mail.python.org/mailman/listinfo/python-list


Contradictory error messages in Python 3.4 - standard library issue!

2016-06-16 Thread Harrison Chudleigh
While working on a program, I ran into an error with the usage of the
module tokenize. The following message was displayed.
 File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py",
line 467, in tokenize
encoding, consumed = detect_encoding(readline)
  File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tokenize.py",
line 409, in detect_encoding
if first.startswith(BOM_UTF8):
TypeError: startswith first arg must be str or a tuple of str, not bytes
Undaunted, I changed the error on line 409. The line then read:

if first.startswith(BOM_UTF8):
***
This message is intended for the addressee named and may contain privileged 
information or confidential information or both. If you are not the intended 
recipient please delete it and notify the sender.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bulk Adding Methods Pythonically

2016-06-16 Thread Ethan Furman
On 06/16, Random832 wrote:
> On Wed, Jun 15, 2016, at 15:03, Ethan Furman wrote:

>> [1] https://docs.python.org/3/library/functions.html#locals
>>  Yes, returning the class namespace is a language gaurantee.
> 
> How do you get a guarantee from that text?

Oops, my bad -- the gaurantee is in the vars() description on the same
page... although that still isn't very clear about during-class-construction;
okay, I'll have to chime in on the issue Steven opened.

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


Re: Bulk Adding Methods Pythonically

2016-06-16 Thread Steven D'Aprano
On Fri, 17 Jun 2016 01:53 am, Julien Salort wrote:

> Ethan Furman  wrote:
> 
>> If that is all correct, then, as Random suggested, move that loop into
>> the class body and use locals() [1] to update the class dictionary.
>> Just make sure and delete any temporary variables.[
> [...]
>> [1] https://docs.python.org/3/library/functions.html#locals
>>  Yes, returning the class namespace is a language gaurantee.
> 
> But that says:
> "Note The contents of this dictionary should not be modified; changes
> may not affect the values of local and free variables used by the
> interpreter."

That only applies to locals() inside a function. The intent of locals()
inside a class is to be writable, and if the docs don't explicitly make
that guarantee, they should.

http://bugs.python.org/issue27335



-- 
Steven

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


Re: Bulk Adding Methods Pythonically

2016-06-16 Thread Random832
On Wed, Jun 15, 2016, at 15:03, Ethan Furman wrote:
> [1] https://docs.python.org/3/library/functions.html#locals
>  Yes, returning the class namespace is a language gaurantee.

How do you get a guarantee from that text? I don't see any definition
asserting that the "current local symbol table" is the class namespace
(more specifically, the object returned by (metaclass).__prepare__,
which will be copied into [not used as, for normal types]
(class).__dict__). We *know* that "representing the current local symbol
table" can and often does mean "copied from the local symbol table which
is not a in fact a dictionary" rather than "being the local symbol table
which is a real dictionary object" (that's *why*, after all, updating
locals() doesn't work in the general case), nor does it mention any
exemption to the warning about updating it.

If there's a guarantee of this, it's somewhere else.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bulk Adding Methods Pythonically

2016-06-16 Thread Julien Salort
Ethan Furman  wrote:

> If that is all correct, then, as Random suggested, move that loop into
> the class body and use locals() [1] to update the class dictionary. 
> Just make sure and delete any temporary variables.[
[...]
> [1] https://docs.python.org/3/library/functions.html#locals
>  Yes, returning the class namespace is a language gaurantee.

But that says:
"Note The contents of this dictionary should not be modified; changes
may not affect the values of local and free variables used by the
interpreter."

-- 
Julien Salort
Entia non sunt multiplicanda praeter necessitatem
http://www.juliensalort.org
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mod_python compilation error in VS 2008 for py2.7.1

2016-06-16 Thread asimkostas
Τη Τρίτη, 14 Ιουνίου 2016 - 3:36:23 μ.μ. UTC+3, ο χρήστης Pavel S έγραψε:
> Have you considered to use rather WSGI-based solution? (for Apache Httpd is 
> mod_wsgi). Mod_python is totally obsolete.

Regarding my blog post, i would like to inform you that someone helped me to 
overcome this error but i got another one that i do not know it's meaning:

deleted #define ssize_t

error: [Errno 22] invalid mode ('wb') or filename: "dist\\mod_python-'{' \x9b\x9
c\xa4 \x98\xa4\x98\x9a\xa4\xe0\xa8\xe5\x9d\x9c\xab\x98\xa0 \xe0\xaa \x9c\xa9\xe0
\xab\x9c\xa8\xa0\xa1\xe3 \xe3 \x9c\xa5\xe0\xab\x9c\xa8\xa0\xa1\xe3 \x9c\xa4\xab\
xa6\xa2\xe3,\n\x9c\xa1\xab\x9c\xa2\xe2\xa9\xa0\xa3\xa6 \xa7\xa8\xe6\x9a\xa8\x98\
xa3\xa3\x98 \xe3 \x98\xa8\xae\x9c\xe5\xa6 \x9b\xe2\xa9\xa3\x9e\xaa \x9c\xa4\x9c\
xa8\x9a\x9c\xa0\xe9\xa4..win32-py2.7.exe"


Any idea would help me a lot?  Attached file for more information!

Regards
Kostas Asimakopoulos
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is structured programming (was for/while else doesn't make sense)

2016-06-16 Thread Rustom Mody
On Thursday, June 16, 2016 at 11:27:15 AM UTC+5:30, Lawrence D’Oliveiro wrote:
> On Thursday, June 16, 2016 at 5:48:48 PM UTC+12, Rustom Mody wrote:
> > On Thursday, June 16, 2016 at 8:25:10 AM UTC+5:30, Lawrence D’Oliveiro 
> > wrote:
> > So here is the formal definition I remember from decades ago:
> > 
> > A structured flow-graph is one that has a single point of entry and exit.
> > And is recursively made from smaller structured flow graphs
> > With a finite set of 'graph combinators'
> > 
> > A structured program is one who's flow graph is structured
> > 
> > As I said I dont find this definition very useful since
> > break is unstructured as is return, yield and much else.
> 
> On the contrary, it fits in nicely. Imagine trying to represent your code as 
> a Nassi-Shneiderman diagram. This consists (recursively) of nested and/or 
> concatenated sub-diagrams. Each piece has one entry point at the top, and one 
> exit point at the bottom. In particular, it is *not possible* to express a 
> goto that jumps from one arbitrary point to another--everything must strictly 
> nest.
> 
> For example, a loop is entered at the top, and exited at the bottom. A 
> “break” in the loop can cut it short, but it cannot violate this rule.
> 
> Even my C code follows this nesting principle, because it is goto-free.

Please see https://en.wikipedia.org/wiki/Nassi%E2%80%93Shneiderman_diagram

| Nassi–Shneiderman diagrams have no representation for a GOTO statement.

which seems to be what you are saying. But then next para goes on...

| Nassi–Shneiderman diagrams are (almost) isomorphic with
| flowcharts. Everything you can represent with a Nassi–Shneiderman
| diagram you can also represent with a flowchart. For flowcharts
| of programs, almost everything you can represent with a flowchart
| you can also represent with a Nassi–Shneiderman diagram. The
| exceptions are constructs like goto and the C programming
| language break and continue statements for loops.

which is in line with what I am saying, viz that break/continue/goto are same
in the sense of being 'unstructured' and therefore do not fit into a structured
framework like NSDs
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiline parsing of python compiler demistification needed

2016-06-16 Thread Frank Millman
"Yubin Ruan"  wrote in message 
news:930753e3-4c9c-45e9-9117-d340c033a...@googlegroups.com...


Hi, everyone, I have some problem understand the rule which the python 
compiler use to parsing the multiline string.


Consider this snippet:

str_1 = "foo"
str_2 = "bar"

print "A test case" + \
   "str_1[%s] " + \
   "str_2[%s] " % (str_1, str_2)

Why would the snippet above give me an "TypeError: not all arguments 
converted during string formatting" while the one below not ?


This has nothing to do with multi-line strings.

Try that as a single line -

   print "A test case " + "str_1[%s] " + "str_2[%s]" % (str_1, str_2)

You will get the same error message.

The reason is that the use of the '+' sign to concatenate strings requires 
that each sub-string is a valid string in its own right.


The correct way to write it is -

   print "A test case " + "str_1[%s] " % (str_1) + "str_2[%s]" % (str_2)

If you wrote it without the '+' signs, the answer would be different. Python 
treats contiguous strings as a single string, so you could write it like 
this -


   print "A test case " "str_1[%s] " "str_2[%s]" % (str_1, str_2)

Frank Millman


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


Re: Multiline parsing of python compiler demistification needed

2016-06-16 Thread Jussi Piitulainen
Yubin Ruan writes:

> Hi, everyone, I have some problem understand the rule which the python
> compiler use to parsing the multiline string.
>
> Consider this snippet:
>
> str_1 = "foo"
> str_2 = "bar"
>
> print "A test case" + \
>"str_1[%s] " + \
>"str_2[%s] " % (str_1, str_2)
>
> Why would the snippet above give me an "TypeError: not all arguments
> converted during string formatting" while the one below not ?
>
> print "A test case" + \
>"str_1[%s] " % str1
>
> Obviously the first snippet have just one more line and one more
> argument to format than the second one. Isn't that unreasonable ? I
> couldn't find any clue about that. Anyone help ?

Multiline is irrelevant. What is happening is that % binds more tightly
(has a higher precedence) than +.

print "foo" + "bar %s" % "baz"
==> foobar baz

print "foo %s" + "bar %s" % ("baz", "baz")
==> Traceback (most recent call last):
  File "", line 1, in 
TypeError: not all arguments converted during string formatting

print ("foo %s" + "bar %s") % ("baz", "baz")
==> foo bazbar baz
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiline parsing of python compiler demistification needed

2016-06-16 Thread Peter Otten
Yubin Ruan wrote:

> Hi, everyone, I have some problem understand the rule which the python
> compiler use to parsing the multiline string.
> 
> Consider this snippet:
> 
> str_1 = "foo"
> str_2 = "bar"
> 
> print "A test case" + \
>"str_1[%s] " + \
>"str_2[%s] " % (str_1, str_2)
> 
> Why would the snippet above give me an "TypeError: not all arguments
> converted during string formatting" while the one below not ?
> 
> print "A test case" + \
>"str_1[%s] " % str1
> 
> Obviously the first snippet have just one more line and one more argument
> to format than the second one. Isn't that unreasonable ? I couldn't find
> any clue about that. Anyone help ?
> 
> I am using python 2.7.6
> 

It doesn't matter into how many lines you break your statement. The % 
operator has higher precedence than +, so

a + b % c

is evaluated as a + (b % c). When c is a 2-tuple and b contains only one 
"%s" that inevitably fails:

>>> "%s" + "%s" % (1, 2)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: not all arguments converted during string formatting

> Also, I know the **Pythonic** way to play with multiline, which would be
> using triple quote or a pair of parenthesis to surround the multiline
> string to make it a **online** string. You don't have to show code in that
> respect.

Did you know that adjacent string literals are merged into one? Compare:

>>> print "foo" + \
...   "%s" + \
...   "%s" % (1, 2)
Traceback (most recent call last):
  File "", line 3, in 
TypeError: not all arguments converted during string formatting
>>> print "foo" \
...   "%s" \
...   "%s" % (1, 2)
foo12


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


Re: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool?

2016-06-16 Thread meInvent bbird
how can list be synchronized when multiprocessor working in it?

will one thread updating non-updated version, but another processor updating 
the version?

On Thursday, June 16, 2016 at 4:30:33 PM UTC+8, Steven D'Aprano wrote:
> On Thursday 16 June 2016 17:28, meInvent bbird wrote:
> 
> > is there like c# have concurrent list ?
> 
> What is a concurrent list?
> 
> Can you link to the C# documentation for this?
> 
> To me, "concurrent" describes a style of execution flow, and "list" describes 
> a 
> data structure. I am struggling to understand what "concurrent list" means.
> 
> > i find something these, but how can it pass an initlist list variable
> 
> initlist = ['a', 'b', 'c']
> result = comb(n, initlist)  # pass initlist
> 
> 
> > is it doing the same function as itertools.combinations ?
> 
> It is calling itertools.combinations. So, yes, it is doing the same function 
> as 
> itertools.combinations.
> 
> 
> > def comb(n, initlist): # the argument n is the number of items to select
> > res = list(itertools.combinations(initlist, n)) # create a list from the
> > # iterator 
> > return res
> 
> This does not generate the combinations in parallel. It generates them one at 
> a 
> time, and then creates a list of them.
> 
> This is an interesting question. Somebody could probably write a parallel 
> version of combinations. But I don't know that it would be very useful -- the 
> limiting factor on combinations is more likely to be memory, not time.
> 
> Suppose you generate combinations of 100 items, taken 10 at a time. If I 
> remember the formula for combinations correctly, the total number of 
> combinations is:
> 
> 100!/(10! * 90!) = 17310309456440
> 
> combinations in total. If each generated combination took just *one* byte of 
> memory, that would require over 17 TB of RAM.
> 
> 
> 
> -- 
> Steve

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


Re: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool?

2016-06-16 Thread meInvent bbird
the name in c# is not called concurrent list, it is called
blockingcollection

dictionary called concurrent dictionary

thread safe these kind of things

https://msdn.microsoft.com/en-us/library/dd267312(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/dd997369(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/dd997305(v=vs.110).aspx


On Thursday, June 16, 2016 at 4:30:33 PM UTC+8, Steven D'Aprano wrote:
> On Thursday 16 June 2016 17:28, meInvent bbird wrote:
> 
> > is there like c# have concurrent list ?
> 
> What is a concurrent list?
> 
> Can you link to the C# documentation for this?
> 
> To me, "concurrent" describes a style of execution flow, and "list" describes 
> a 
> data structure. I am struggling to understand what "concurrent list" means.
> 
> > i find something these, but how can it pass an initlist list variable
> 
> initlist = ['a', 'b', 'c']
> result = comb(n, initlist)  # pass initlist
> 
> 
> > is it doing the same function as itertools.combinations ?
> 
> It is calling itertools.combinations. So, yes, it is doing the same function 
> as 
> itertools.combinations.
> 
> 
> > def comb(n, initlist): # the argument n is the number of items to select
> > res = list(itertools.combinations(initlist, n)) # create a list from the
> > # iterator 
> > return res
> 
> This does not generate the combinations in parallel. It generates them one at 
> a 
> time, and then creates a list of them.
> 
> This is an interesting question. Somebody could probably write a parallel 
> version of combinations. But I don't know that it would be very useful -- the 
> limiting factor on combinations is more likely to be memory, not time.
> 
> Suppose you generate combinations of 100 items, taken 10 at a time. If I 
> remember the formula for combinations correctly, the total number of 
> combinations is:
> 
> 100!/(10! * 90!) = 17310309456440
> 
> combinations in total. If each generated combination took just *one* byte of 
> memory, that would require over 17 TB of RAM.
> 
> 
> 
> -- 
> Steve

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


Re: Python 3.6.0a2 is now available

2016-06-16 Thread Steven D'Aprano
On Thursday 16 June 2016 14:36, Lawrence D’Oliveiro wrote:

> On Thursday, June 16, 2016 at 2:19:33 AM UTC+12, MRAB wrote:
> 
>> Coincidentally, there was recently a discussion on the python-dev list
>> about whether to switch to C99.
> 
> Only slightly less than a generation after it came out...

You say that as if this is the first time that anyone has raised this issue. It 
comes up, oh, at least once a year, sometimes more.

Like the last few dozen times, the answer is still no, we still can't switch to 
requiring C99 yet, as there are still users that rely on compilers with partial 
support for C99. But unlike previous times, now we can begin to use some C99 
features, provided they are available on the important C compilers we support. 

https://mail.python.org/pipermail/python-dev/2016-June/144876.html

You should read the whole thread before commenting:

https://mail.python.org/pipermail/python-dev/2016-June/144816.html



-- 
Steve

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


Multiline parsing of python compiler demistification needed

2016-06-16 Thread Yubin Ruan
Hi, everyone, I have some problem understand the rule which the python compiler 
use to parsing the multiline string.

Consider this snippet:

str_1 = "foo"
str_2 = "bar"

print "A test case" + \
   "str_1[%s] " + \
   "str_2[%s] " % (str_1, str_2)

Why would the snippet above give me an "TypeError: not all arguments converted 
during string formatting" while the one below not ?

print "A test case" + \
   "str_1[%s] " % str1

Obviously the first snippet have just one more line and one more argument to 
format than the second one. Isn't that unreasonable ? I couldn't find any clue 
about that. Anyone help ?

I am using python 2.7.6

Also, I know the **Pythonic** way to play with multiline, which would be using 
triple quote or a pair of parenthesis to surround the multiline string to make 
it a **online** string. You don't have to show code in that respect.

Thanks in advance!

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


Re: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool?

2016-06-16 Thread Steven D'Aprano
On Thursday 16 June 2016 17:28, meInvent bbird wrote:

> is there like c# have concurrent list ?

What is a concurrent list?

Can you link to the C# documentation for this?

To me, "concurrent" describes a style of execution flow, and "list" describes a 
data structure. I am struggling to understand what "concurrent list" means.

> i find something these, but how can it pass an initlist list variable

initlist = ['a', 'b', 'c']
result = comb(n, initlist)  # pass initlist


> is it doing the same function as itertools.combinations ?

It is calling itertools.combinations. So, yes, it is doing the same function as 
itertools.combinations.


> def comb(n, initlist): # the argument n is the number of items to select
> res = list(itertools.combinations(initlist, n)) # create a list from the
> # iterator 
> return res

This does not generate the combinations in parallel. It generates them one at a 
time, and then creates a list of them.

This is an interesting question. Somebody could probably write a parallel 
version of combinations. But I don't know that it would be very useful -- the 
limiting factor on combinations is more likely to be memory, not time.

Suppose you generate combinations of 100 items, taken 10 at a time. If I 
remember the formula for combinations correctly, the total number of 
combinations is:

100!/(10! * 90!) = 17310309456440

combinations in total. If each generated combination took just *one* byte of 
memory, that would require over 17 TB of RAM.



-- 
Steve

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


python 3 + milter

2016-06-16 Thread Nagy László Zsolt
Does anyone know a module that can be used to write a before-queue,
smtpd time milter with Python 3?

Unfortunately, pymilter does not work with Python 3:

Downloading
https://pypi.python.org/packages/58/2f/d4799c9cade461177955ca19ade6ca55385286f066c0db9a0770a332ab8a/pymilter-1.0.tar.gz#md5=ec9b95fed2bc083d5f6a801bc150c253
Processing pymilter-1.0.tar.gz
Writing /tmp/easy_install-_eqt8c9r/pymilter-1.0/setup.cfg
Running pymilter-1.0/setup.py -q bdist_egg --dist-dir
/tmp/easy_install-_eqt8c9r/pymilter-1.0/egg-dist-tmp-o1n6sd1x
miltermodule.c:349:1: error: unknown type name 'staticforward'
staticforward struct smfiDesc description; /* forward declaration */
^
miltermodule.c:349:15: error: expected identifier or '('
staticforward struct smfiDesc description; /* forward declaration */
  ^
miltermodule.c:361:1: error: unknown type name 'staticforward'
staticforward PyTypeObject milter_ContextType;
^
miltermodule.c:361:27: error: expected ';' after top level declarator
staticforward PyTypeObject milter_ContextType;
  ^

I have a complete program that works with email.Message messages, but I
don't know how to use it with postfix.

A workaround would be to construct the message from python2 + pymilter,
and start a subprocess for the message processing, but that is obviously
bad.

Thanks,

   Laszlo



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


mod_python compilation error

2016-06-16 Thread asimkon
Regarding my blog post
, i would like to
inform you that someone helped me to overcome this error but i got another
one that i do not know it's meaning:

error: [Errno 22] invalid mode ('wb') or filename: "dist\\mod_python-'{'
\x9b\x9
c\xa4 \x98\xa4\x98\x9a\xa4\xe0\xa8\xe5\x9d\x9c\xab\x98\xa0 \xe0\xaa
\x9c\xa9\xe0
\xab\x9c\xa8\xa0\xa1\xe3 \xe3 \x9c\xa5\xe0\xab\x9c\xa8\xa0\xa1\xe3
\x9c\xa4\xab\
xa6\xa2\xe3,\n\x9c\xa1\xab\x9c\xa2\xe2\xa9\xa0\xa3\xa6
\xa7\xa8\xe6\x9a\xa8\x98\
xa3\xa3\x98 \xe3 \x98\xa8\xae\x9c\xe5\xa6 \x9b\xe2\xa9\xa3\x9e\xaa
\x9c\xa4\x9c\
xa8\x9a\x9c\xa0\xe9\xa4..win32-py2.7.exe"


Any idea would help me a lot?

Regards
Kostas Asimakopoulos
-- 
https://mail.python.org/mailman/listinfo/python-list


is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool?

2016-06-16 Thread meInvent bbird
is there like c# have concurrent list ? 

i find something these, but how can it pass an initlist list variable 

is it doing the same function as itertools.combinations ? 

def comb(n, initlist): # the argument n is the number of items to select 
res = list(itertools.combinations(initlist, n)) # create a list from the 
iterator 
return res 

#p = Pool(8) 
#times = range(0, len(initlist)+1)  
   
#values = p.map(comb, times) # pass the range as the sequence of arguments! 
#p.close() 
#p.join() 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is structured programming (was for/while else doesn't make sense)

2016-06-16 Thread Lawrence D’Oliveiro
On Thursday, June 16, 2016 at 5:48:48 PM UTC+12, Rustom Mody wrote:
> On Thursday, June 16, 2016 at 8:25:10 AM UTC+5:30, Lawrence D’Oliveiro wrote:
> So here is the formal definition I remember from decades ago:
> 
> A structured flow-graph is one that has a single point of entry and exit.
> And is recursively made from smaller structured flow graphs
> With a finite set of 'graph combinators'
> 
> A structured program is one who's flow graph is structured
> 
> As I said I dont find this definition very useful since
> break is unstructured as is return, yield and much else.

On the contrary, it fits in nicely. Imagine trying to represent your code as a 
Nassi-Shneiderman diagram. This consists (recursively) of nested and/or 
concatenated sub-diagrams. Each piece has one entry point at the top, and one 
exit point at the bottom. In particular, it is *not possible* to express a goto 
that jumps from one arbitrary point to another--everything must strictly nest.

For example, a loop is entered at the top, and exited at the bottom. A “break” 
in the loop can cut it short, but it cannot violate this rule.

Even my C code follows this nesting principle, because it is goto-free.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt5: is the wrapper incomplete?

2016-06-16 Thread Mark Summerfield
On Thursday, June 16, 2016 at 8:22:33 AM UTC+1, Mark Summerfield wrote:
> On Thursday, June 16, 2016 at 3:54:53 AM UTC+1, jlad...@itu.edu wrote:
> > I am developing a data acquisition system for a custom device that 
> > communicates over USB.  On the host computer side, I am using PyQt5.4.  My 
> > Linux box has both Qt4 and Qt5 installed on it.  I assume that PyQt5.4 
> > compiled on top of Qt5 automatically.  I'm not sure how to check that.
> 
> In IDLE or at some other Python prompt or in a tiny test.py file:
> 
> from PyQt5 import QtCore
> print(QtCore.qVersion())
> 
> > In any case, I used PySerial to handle the USB communication.  I just 
> > noticed that Qt also has serial features.  I need to give the completed 
> > program to other users, on Windows no less.  If I can forego PySerial and 
> > use Qt's serial interface instead, it would simplify the installation.
> > 
> > Now, the PyQt5 documentation implies that a module called QtSerial exists.  
> > But while I can write...
> > 
> > from PyQt5.QtWidgets import (...), or
> > from PyQt5.QtGui import (...), or
> > from PyQt5.QtCore import (...),
> > 
> > ...attempting to import from PyQt5.QtSerial raises an ImportError.
> > 
> > I've tried many variations on the spelling, and I've tried various import 
> > statements to inspect the (very large and complex) PyQt5 namespace.  I 
> > haven't found the QtSerial classes.  Are they even there?  Maybe the 
> > wrapping of the library is incomplete?
> 
> In Ubuntu 14.04 there is no QtSerial or QtSerialPort.

Sorry, my mistake, you have to install it as a separate package as Vincent 
explained.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt5: is the wrapper incomplete?

2016-06-16 Thread Mark Summerfield
On Thursday, June 16, 2016 at 3:54:53 AM UTC+1, jlad...@itu.edu wrote:
> I am developing a data acquisition system for a custom device that 
> communicates over USB.  On the host computer side, I am using PyQt5.4.  My 
> Linux box has both Qt4 and Qt5 installed on it.  I assume that PyQt5.4 
> compiled on top of Qt5 automatically.  I'm not sure how to check that.

In IDLE or at some other Python prompt or in a tiny test.py file:

from PyQt5 import QtCore
print(QtCore.qVersion())

> In any case, I used PySerial to handle the USB communication.  I just noticed 
> that Qt also has serial features.  I need to give the completed program to 
> other users, on Windows no less.  If I can forego PySerial and use Qt's 
> serial interface instead, it would simplify the installation.
> 
> Now, the PyQt5 documentation implies that a module called QtSerial exists.  
> But while I can write...
> 
> from PyQt5.QtWidgets import (...), or
> from PyQt5.QtGui import (...), or
> from PyQt5.QtCore import (...),
> 
> ...attempting to import from PyQt5.QtSerial raises an ImportError.
> 
> I've tried many variations on the spelling, and I've tried various import 
> statements to inspect the (very large and complex) PyQt5 namespace.  I 
> haven't found the QtSerial classes.  Are they even there?  Maybe the wrapping 
> of the library is incomplete?

In Ubuntu 14.04 there is no QtSerial or QtSerialPort.

> Any guidance is appreciated, thanks!

The best place to ask about the PyQt bindings is the PyQt mailing list:
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt5: is the wrapper incomplete?

2016-06-16 Thread Vincent Vande Vyvre

Le 16/06/2016 04:54, jlada...@itu.edu a écrit :

I am developing a data acquisition system for a custom device that communicates 
over USB.  On the host computer side, I am using PyQt5.4.  My Linux box has 
both Qt4 and Qt5 installed on it.  I assume that PyQt5.4 compiled on top of Qt5 
automatically.  I'm not sure how to check that.

In any case, I used PySerial to handle the USB communication.  I just noticed 
that Qt also has serial features.  I need to give the completed program to 
other users, on Windows no less.  If I can forego PySerial and use Qt's serial 
interface instead, it would simplify the installation.

Now, the PyQt5 documentation implies that a module called QtSerial exists.  But 
while I can write...

from PyQt5.QtWidgets import (...), or
from PyQt5.QtGui import (...), or
from PyQt5.QtCore import (...),

...attempting to import from PyQt5.QtSerial raises an ImportError.

I've tried many variations on the spelling, and I've tried various import 
statements to inspect the (very large and complex) PyQt5 namespace.  I haven't 
found the QtSerial classes.  Are they even there?  Maybe the wrapping of the 
library is incomplete?

Any guidance is appreciated, thanks!


On Debian, this is a separate package python3-pyqt5.qtserialport, I 
don't know for other Linux


After install you can use:

from PyQt5.QtSeriaPort import QSerialPort

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