Re: type lookuperror

2016-08-19 Thread Marko Rauhamaa
Steve D'Aprano :
> And when all the hardware is migrated to "the cloud" (stupid marketing
> speak for "a bunch of computers that you don't control connected to
> the internet"), what exactly will "the cloud" be running on? Moonbeams
> and kitten purrs?

Your soul would no longer run on dedicated wetware. Instead, it would be
a virtual machine on a server farm.

> Personally I think it would be hilarious to see what happens when the
> wireless connection to "the cloud" go down, and people's
> intellectually capacity drop so low that they *literally cannot
> notice* that they're missing anything. Denial Of Service attacks will
> be *hilarious*.

No doubt about that. On the other hand, the same argument is used by
American Libertarian fundamentalists who choose to live in the desert
with narrow dirt roads leading up to their fenced properties. They have
hoarded enough provisions and ammo to sustain a prolonged siege.

When your brain tissue has given in and everybody else is having
immortal, transcendental fun in the virtual world, your priorities might
shift.

> Of course, for this scenario to be plausible will require a much more
> advanced understanding of human thought processes, one sufficiently
> advanced that these cloud "brain providers" would be more than capable
> of invisibly controlling your thoughts.

My point is exactly the opposite. I believe we will reach that stage
without having an exact clue of how consciousness functions. For
example, we probably won't have a way to decode your dreams.


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


use regex to search the page one time to get two types of Information

2016-08-19 Thread iMath
I need to use regex to search two types of Information within a web page, while 
it seems  searching the page two times rather than one is much time consuming , 
is it possible to search the page one time to get two or more types of 
Information?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use regex to search the page one time to get two types of Information

2016-08-19 Thread iMath
each regex only has one matched result in the web page
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use regex to search the page one time to get two types of Information

2016-08-19 Thread Peter Otten
iMath wrote:

> I need to use regex to search two types of Information within a web page,

Did you try specialised tools like BeautifulSoup?

> while it seems  searching the page two times rather than one is much time
> consuming 

It "seems"? Try it and only "fix" it if it proves to be a problem, i. e. if 
the regex searches take a significant part of your scripts runtime.

> , is it possible to search the page one time to get two or more
> types of Information?

> each regex only has one matched result in the web page

If the matches are in fixed order you can start the search for the second 
match at the position after the first one. Or you try to combine both 
patterns into one regex.

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


Two-Dimensional Expression Layout

2016-08-19 Thread Lawrence D’Oliveiro
It is handy to be able to keep complex expressions together sometimes, when 
breaking them up would simply obscure their structure. To avoid lines getting 
long, why not take advantage of the two available screen/page dimensions to 
make their structure clearer? As a bonus, spacing out parentheses makes them 
look less of a clutter.

Examples from :

A function call with complex arguments (specifying arguments by keywords is 
highly recommended here):

rect_1_pattern = \
qah.Pattern.create_linear \
  (
p0 = (0, 0),
p1 = (major_dim, 0),
colour_stops =
(
(0, rect_1_colour),
(1, complement(rect_1_colour)),
)
  )

Computing a variable value (using redundant parentheses to avoid 
backslash-continuations):

dest_rect = \
(
draw_bounds
+
Vector(col, row) * draw_bounds.dimensions
+
Vector(0, top_extra)
)

>From , a complex 
>condition (with redundant parentheses again):

if (
not isinstance(src, Image)
or
mask != None and not isinstance(mask, Image)
or
not isinstance(dest, Image)
) :
raise TypeError("image args must be Image objects")
#end if

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


Scipy.signal, spectrogram??

2016-08-19 Thread Ambroise Baudot
Hello,
http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectrogram.html
In Python (v. 3.4), scipy.signal.spectrogram doesn't exist?
Can you help me to find this function please?

Bonjour,
Impossible de trouver la fonction scpiy.signal.spectrogram indiquée ici : 
http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectrogram.html
J'utilise Python v.3.4
Pourriez-vous m'aider svp à la trouver??

Thanks a lot for yours answers
Merci d'avance pour vos réponses ;)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Scipy.signal, spectrogram??

2016-08-19 Thread Peter Otten
Ambroise Baudot wrote:

http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectrogram.html
> In Python (v. 3.4), scipy.signal.spectrogram doesn't exist?
> Can you help me to find this function please?

It's the scipy version that matters. The page you link to says

"""
New in version 0.16.0.
"""

so you need at least this version. You can find out your current version 
with

>>> import scipy
>>> scipy.__version__
'0.13.3'

Looks like I don't have the function either...

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


Re: Nuitka Release 0.5.22

2016-08-19 Thread Steve D'Aprano
On Thu, 18 Aug 2016 06:58 am, breamore...@gmail.com wrote:

> As Kay (him) is less than useless at sales and marketing, somebody has to
> do it, so here you are folks
> http://nuitka.net/posts/nuitka-release-0522.html

Thanks for the link.



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


index for regex.search() beyond which the RE engine will not go.

2016-08-19 Thread iMath

for
regex.search(string[, pos[, endpos]]) 
The optional parameter endpos is the index into the string beyond which the RE 
engine will not go, while this lead me to believe the RE engine will still 
search on till the endpos position even after it returned the matched object, 
is this Right ?

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


Re: index for regex.search() beyond which the RE engine will not go.

2016-08-19 Thread Jon Ribbens
On 2016-08-19, iMath  wrote:
> for
> regex.search(string[, pos[, endpos]]) 
> The optional parameter endpos is the index into the string beyond
> which the RE engine will not go, while this lead me to believe the
> RE engine will still search on till the endpos position even after
> it returned the matched object, is this Right ?

I am not able rightly to apprehend the kind of confusion of ideas
that could provoke such a question.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I tell if I'm running on a PowerPC?

2016-08-19 Thread Tim Chase
On 2016-08-14 13:54, Steven D'Aprano wrote:
> I need to be able to programmatically test whether I'm running on a
> PowerPC. How can I do that?
> 
> import platform
> if platform.machine() in ('ppc', 'ppc64'):
> print('running PowerPC')
> 
> 
> Is that right?

Running OpenBSD on a PPC iBook G4:

$ python3.5
Python 3.5.1 (default, Mar  6 2016, 01:17:51) 
[GCC 4.2.1 20070719 ] on openbsd5
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.machine()
'macppc'
>>> platform.processor()
'powerpc'

Just in case it matters.

-tkc




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


Re: use regex to search the page one time to get two types of Information

2016-08-19 Thread iMath
1. searching the page two times rather than one is a little bit time consuming .
2. starting the second search from the first match.endpos does reduce the time 
consuming .
3. how to  combine both patterns into one regex? while using the special | 
regex operator only matches one regex not both 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: use regex to search the page one time to get two types of Information

2016-08-19 Thread Chris Angelico
On Fri, Aug 19, 2016 at 11:13 PM, iMath  wrote:
> 1. searching the page two times rather than one is a little bit time 
> consuming .

Have you measured that? If not, ignore it. You're searching a web
page; if you're downloading that before you search it, chances are
very good that you spend far more time waiting for the download than
you ever will on the regex.

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


Re: use regex to search the page one time to get two types of Information

2016-08-19 Thread Friedrich Rentsch

On 08/19/2016 09:02 AM, iMath wrote:

I need to use regex to search two types of Information within a web page, while 
it seems  searching the page two times rather than one is much time consuming , 
is it possible to search the page one time to get two or more types of 
Information?


>>> r = re.compile ('page|Information|time')
>>> r.findall ( (your post) )
['Information', 'page', 'page', 'time', 'time', 'page', 'time', 
'Information']


Does that look right?

Frederic


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


Re: index for regex.search() beyond which the RE engine will not go.

2016-08-19 Thread Steve D'Aprano
On Fri, 19 Aug 2016 09:14 pm, iMath wrote:

> 
> for
> regex.search(string[, pos[, endpos]])
> The optional parameter endpos is the index into the string beyond which
> the RE engine will not go, while this lead me to believe the RE engine
> will still search on till the endpos position even after it returned the
> matched object, is this Right ?

No.

Once the RE engine finds a match, it stops. You can test this for yourself
with a small timing test, using the "timeit" module.

from timeit import Timer
huge_string = 'aaabc' + 'a'*100 + 'dea'
re1 = r'ab.a'
re2 = r'ad.a'

# set up some code to time.
setup = 'import re; from __main__ import huge_string, re1, re2'
t1 = Timer('re.search(re1, huge_string)', setup)
t2 = Timer('re.search(re2, huge_string)', setup)

# Now run the timers.
best = min(t1.repeat(number=1000))/1000
print("Time to locate regex at the start of huge string:", best)
best = min(t2.repeat(number=1000))/1000
print("Time to locate regex at the end of the huge string:", best)



When I run that on my computer, it prints:

Time to locate regex at the start of huge string: 4.9710273742675785e-06
Time to locate regex at the end of the huge string: 0.0038938069343566893


So it takes about 4.9 microseconds to find the regex at the beginning of the
string. To find the regex at the end of the string takes about 3893
microseconds.


The "endpos" parameter tells the RE engine to stop at that position if the
regex isn't found before it. It won't go beyond that point.






-- 
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: index for regex.search() beyond which the RE engine will not go.

2016-08-19 Thread Steve D'Aprano
On Fri, 19 Aug 2016 09:21 pm, Jon Ribbens wrote:

> On 2016-08-19, iMath  wrote:
>> for
>> regex.search(string[, pos[, endpos]])
>> The optional parameter endpos is the index into the string beyond
>> which the RE engine will not go, while this lead me to believe the
>> RE engine will still search on till the endpos position even after
>> it returned the matched object, is this Right ?
> 
> I am not able rightly to apprehend the kind of confusion of ideas
> that could provoke such a question.


Consider that iMath's native language may not be English, and that he or she
may not understand how regular expression matching works.




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


saving octet-stream png file

2016-08-19 Thread Larry Martell
I have some python code (part of a django app) that processes a
request that contains a png file. The request is send with
content_type = 'application/octet-stream'

In the python code I want to write this data to a file and still have
it still be a valid png file.

The data I get looks like this:

u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\x00\x00\x01\ufffd
..'

If I try and write that to a file it fails with a UnicodeEncodeError.
If I write it with encode('utf8') it writes the file, but then it's no
longer a valid png file.

Anyone know how I can do this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-19 Thread Chris Angelico
On Sat, Aug 20, 2016 at 3:10 AM, Larry Martell  wrote:
> I have some python code (part of a django app) that processes a
> request that contains a png file. The request is send with
> content_type = 'application/octet-stream'
>
> In the python code I want to write this data to a file and still have
> it still be a valid png file.
>
> The data I get looks like this:
>
> u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\x00\x00\x01\ufffd
> ..'
>
> If I try and write that to a file it fails with a UnicodeEncodeError.
> If I write it with encode('utf8') it writes the file, but then it's no
> longer a valid png file.
>
> Anyone know how I can do this?

At that point, you've already lost information. Each U+FFFD (shown as
"\ufffd" above) is a marker saying "a byte here was not valid UTF-8"
(or whatever was being used). Something somewhere took the .png file's
bytes and tried to interpret them as text, which they're not.

What sent you that data? How did you receive it?

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


Re: Two-Dimensional Expression Layout

2016-08-19 Thread Terry Reedy

On 8/19/2016 4:56 AM, Lawrence D’Oliveiro wrote:

It is handy to be able to keep complex expressions together sometimes, when 
breaking them up would simply obscure their structure. To avoid lines getting 
long, why not take advantage of the two available screen/page dimensions to 
make their structure clearer? As a bonus, spacing out parentheses makes them 
look less of a clutter.

Examples from :


To me, putting parens and '+' and 'or' on separate lines emphasizes them 
too much and makes the layout more, not less, cluttered.  But I won't 
argue with what you do in your own private code.



A function call with complex arguments (specifying arguments by keywords is 
highly recommended here):

rect_1_pattern = \
qah.Pattern.create_linear \
  (
p0 = (0, 0),
p1 = (major_dim, 0),
colour_stops =
(
(0, rect_1_colour),
(1, complement(rect_1_colour)),
)
  )

Computing a variable value (using redundant parentheses to avoid 
backslash-continuations):

dest_rect = \
(
draw_bounds
+
Vector(col, row) * draw_bounds.dimensions
+
Vector(0, top_extra)
)

From , a complex 
condition (with redundant parentheses again):

if (
not isinstance(src, Image)
or
mask != None and not isinstance(mask, Image)
or
not isinstance(dest, Image)
) :
raise TypeError("image args must be Image objects")
#end if




--
Terry Jan Reedy


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


Re: saving octet-stream png file

2016-08-19 Thread Terry Reedy

On 8/19/2016 1:10 PM, Larry Martell wrote:

I have some python code (part of a django app) that processes a
request that contains a png file. The request is send with
content_type = 'application/octet-stream'


An 'octet' is a byte of 8 bits.  So the content is a stream of bytes and 
MUST NOT be decoded as unicode text.



In the python code I want to write this data to a file and still have
it still be a valid png file.

The data I get looks like this:

u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\x00\x00\x01\ufffd
..'


The data you got looked like b'...PNG...' where the *ascii* codes for 
"PNG' identify it as a png byte stream.  It was mistakenly decoded to 
unicode text by something.  Png bytes must be decoded, when decoded, to 
a png image.  You want to write the bytes to a file exactly as received, 
without decoding.



If I try and write that to a file it fails with a UnicodeEncodeError.
If I write it with encode('utf8') it writes the file, but then it's no
longer a valid png file.


The data ceased representing a png image as soon as wrongfully decoded 
as unicode text.



--
Terry Jan Reedy

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


Re: saving octet-stream png file

2016-08-19 Thread Larry Martell
On Fri, Aug 19, 2016 at 1:24 PM, Chris Angelico  wrote:
> On Sat, Aug 20, 2016 at 3:10 AM, Larry Martell  
> wrote:
>> I have some python code (part of a django app) that processes a
>> request that contains a png file. The request is send with
>> content_type = 'application/octet-stream'
>>
>> In the python code I want to write this data to a file and still have
>> it still be a valid png file.
>>
>> The data I get looks like this:
>>
>> u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\x00\x00\x01\ufffd
>> ..'
>>
>> If I try and write that to a file it fails with a UnicodeEncodeError.
>> If I write it with encode('utf8') it writes the file, but then it's no
>> longer a valid png file.
>>
>> Anyone know how I can do this?
>
> At that point, you've already lost information. Each U+FFFD (shown as
> "\ufffd" above) is a marker saying "a byte here was not valid UTF-8"
> (or whatever was being used). Something somewhere took the .png file's
> bytes and tried to interpret them as text, which they're not.
>
> What sent you that data? How did you receive it?

The request is sent by a client app written in C++ with Qt. It's
received by a django based server. I am trying to port a falcon server
to django. The falcon server code did this:

form = cgi.FieldStorage(fp=req.stream, environ=req.env)

and then wrote the png like this:

fd.write(form[key].file.read())

Whereas in the django server I am doing:

fd.write(request.POST[key])

I've never used the cgi module. I guess I can try that. I've written a
lot with django but never had to receive a PNG file.
-- 
https://mail.python.org/mailman/listinfo/python-list


python module install manully

2016-08-19 Thread ldompeling
I have a module insteon.py what I need to install manually because it is not in 
the python index packages.
I copied the module in /usr/lib/python2.7/dist-packages and 
/usr/local/lib/python2.7/dist-packages.

When I try to import the module insteon.py I get this error:
Does someone knows what the problem can be.

Traceback (most recent call last):
  File "main.py", line 15, in 
from insteon import Insteon
  File "/usr/lib/python2.7/dist-packages/insteon.py", line 25, in 
config = configuration.loadConfig()
AttributeError: Configuration instance has no attribute 'loadConfig'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-19 Thread Larry Martell
On Fri, Aug 19, 2016 at 3:00 PM, Larry Martell  wrote:
> On Fri, Aug 19, 2016 at 1:24 PM, Chris Angelico  wrote:
>> On Sat, Aug 20, 2016 at 3:10 AM, Larry Martell  
>> wrote:
>>> I have some python code (part of a django app) that processes a
>>> request that contains a png file. The request is send with
>>> content_type = 'application/octet-stream'
>>>
>>> In the python code I want to write this data to a file and still have
>>> it still be a valid png file.
>>>
>>> The data I get looks like this:
>>>
>>> u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\x00\x00\x01\ufffd
>>> ..'
>>>
>>> If I try and write that to a file it fails with a UnicodeEncodeError.
>>> If I write it with encode('utf8') it writes the file, but then it's no
>>> longer a valid png file.
>>>
>>> Anyone know how I can do this?
>>
>> At that point, you've already lost information. Each U+FFFD (shown as
>> "\ufffd" above) is a marker saying "a byte here was not valid UTF-8"
>> (or whatever was being used). Something somewhere took the .png file's
>> bytes and tried to interpret them as text, which they're not.
>>
>> What sent you that data? How did you receive it?
>
> The request is sent by a client app written in C++ with Qt. It's
> received by a django based server. I am trying to port a falcon server
> to django. The falcon server code did this:
>
> form = cgi.FieldStorage(fp=req.stream, environ=req.env)
>
> and then wrote the png like this:
>
> fd.write(form[key].file.read())
>
> Whereas in the django server I am doing:
>
> fd.write(request.POST[key])
>
> I've never used the cgi module. I guess I can try that. I've written a
> lot with django but never had to receive a PNG file.

No joy using cgi.FieldStorage. The request I get (of type
django.core.handlers.wsgi.WSGIRequest) does not have a stream method.
I'm sure there's some way to do this, but I have not come up with
anything googling. Going to try the django list.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Two-Dimensional Expression Layout

2016-08-19 Thread codewizard
For some special cases, I prefer the versions below.


On Friday, August 19, 2016 at 4:56:31 AM UTC-4, Lawrence D’Oliveiro wrote:
> [snip]
> 
> Computing a variable value (using redundant parentheses to avoid 
> backslash-continuations):
> 
> dest_rect = \
> (
> draw_bounds
> +
> Vector(col, row) * draw_bounds.dimensions
> +
> Vector(0, top_extra)
> )

dest_rect = sum([
draw_bounds,
(col, row) * draw_bounds.dimensions,
Vector(0, top_extra),
])


> From , a complex 
> condition (with redundant parentheses again):
> 
> if (
> not isinstance(src, Image)
> or
> mask != None and not isinstance(mask, Image)
> or
> not isinstance(dest, Image)
> ) :
> raise TypeError("image args must be Image objects")
> #end if

if any([
not isinstance(src, Image),
mask != None and not isinstance(mask, Image),
not isinstance(dest, Image),
]):
raise TypeError("image args must be Image objects")

Or equivalently:

if not all([
isinstance(src, Image),
mask is None or isinstance(mask, Image),
isinstance(dest, Image),
]):
raise TypeError("image args must be Image objects")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-19 Thread Chris Kaynor
On Fri, Aug 19, 2016 at 12:00 PM, Larry Martell 
wrote:

> On Fri, Aug 19, 2016 at 1:24 PM, Chris Angelico  wrote:
> > On Sat, Aug 20, 2016 at 3:10 AM, Larry Martell 
> wrote:
> >> I have some python code (part of a django app) that processes a
> >> request that contains a png file. The request is send with
> >> content_type = 'application/octet-stream'
> >>
> >> In the python code I want to write this data to a file and still have
> >> it still be a valid png file.
> >>
> >> The data I get looks like this:
> >>
> >> u'\ufffdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\ufffd\
> x00\x00\x01\ufffd
> >> ..'
> >>
> >> If I try and write that to a file it fails with a UnicodeEncodeError.
> >> If I write it with encode('utf8') it writes the file, but then it's no
> >> longer a valid png file.
> >>
> >> Anyone know how I can do this?
> >
> > At that point, you've already lost information. Each U+FFFD (shown as
> > "\ufffd" above) is a marker saying "a byte here was not valid UTF-8"
> > (or whatever was being used). Something somewhere took the .png file's
> > bytes and tried to interpret them as text, which they're not.
> >
> > What sent you that data? How did you receive it?
>
> The request is sent by a client app written in C++ with Qt. It's
> received by a django based server. I am trying to port a falcon server
> to django. The falcon server code did this:
>
> form = cgi.FieldStorage(fp=req.stream, environ=req.env)
>
> and then wrote the png like this:
>
> fd.write(form[key].file.read())
>
> Whereas in the django server I am doing:
>
> fd.write(request.POST[key])
>
> I've never used the cgi module. I guess I can try that. I've written a
> lot with django but never had to receive a PNG file.
>
>
I don't know Django, however a quick search makes it seem like you might
need to use request.FILES[key] (1) rather than request.POST[key]. You may
also be able to use request.POST if you set request.encoding first (2). If
both of those fail, you may need to use request.body and parse the HTTP
form data manually, though I'd imagine there is an easier way.

[1]
https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.FILES

[2]
https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.encoding
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-19 Thread Lawrence D’Oliveiro
On Saturday, August 20, 2016 at 6:03:53 AM UTC+12, Terry Reedy wrote:
>
> An 'octet' is a byte of 8 bits.

Is there any other size of byte?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-19 Thread Random832
On Fri, Aug 19, 2016, at 16:51, Lawrence D’Oliveiro wrote:
> On Saturday, August 20, 2016 at 6:03:53 AM UTC+12, Terry Reedy wrote:
> >
> > An 'octet' is a byte of 8 bits.
> 
> Is there any other size of byte?

Not very often anymore. Used to be some systems had 9-bit bytes, and of
course a lot of communication protocols only supported 7-bit data bytes.
"Byte" is a technical term in the C and C++ standards meaning the
smallest addressable unit even if that is a larger word.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Two-Dimensional Expression Layout

2016-08-19 Thread Lawrence D’Oliveiro
On Saturday, August 20, 2016 at 7:52:09 AM UTC+12, codew...@gmail.com wrote:
> if any([
> not isinstance(src, Image),
> mask != None and not isinstance(mask, Image),
> not isinstance(dest, Image),
> ]):
> raise TypeError("image args must be Image objects")
> 
> Or equivalently:
> 
> if not all([
> isinstance(src, Image),
> mask is None or isinstance(mask, Image),
> isinstance(dest, Image),
> ]):
> raise TypeError("image args must be Image objects")

Using “all” or “any” in this sort of situation may not be such a good idea. 
More reasonable uses would be like 
:

if any(uvface.flipped for uvface in island.faces):

if any(island.bounding_box.x > cage_size.x or island.bounding_box.y > 
cage_size.y for island in self.islands):
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Two-Dimensional Expression Layout

2016-08-19 Thread Lawrence D’Oliveiro
On Saturday, August 20, 2016 at 5:53:22 AM UTC+12, Terry Reedy wrote:
>
> To me, putting parens and '+' and 'or' on separate lines emphasizes them 
> too much and makes the layout more, not less, cluttered.

So having whitespace around these symbols makes things look *more* cluttered, 
while packing them together without whitespace makes them *less* cluttered?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Two-Dimensional Expression Layout

2016-08-19 Thread codewizard
On Friday, August 19, 2016 at 5:30:22 PM UTC-4, Lawrence D’Oliveiro wrote:
> On Saturday, August 20, 2016 at 7:52:09 AM UTC+12, codew...@gmail.com wrote:
> > if any([
> > not isinstance(src, Image),
> > mask != None and not isinstance(mask, Image),
> > not isinstance(dest, Image),
> > ]):
> > raise TypeError("image args must be Image objects")
> > 
> > Or equivalently:
> > 
> > if not all([
> > isinstance(src, Image),
> > mask is None or isinstance(mask, Image),
> > isinstance(dest, Image),
> > ]):
> > raise TypeError("image args must be Image objects")
> 
> Using “all” or “any” in this sort of situation may not be such a good idea. 
> More reasonable uses would be like 
> :
> 
> if any(uvface.flipped for uvface in island.faces):
> 
> if any(island.bounding_box.x > cage_size.x or island.bounding_box.y > 
> cage_size.y for island in self.islands):

You showed examples where you think it would be a good idea to use any/all.
But you didn't say why my examples "may not be such a good idea".
Would you care to elaborate?
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Run Error

2016-08-19 Thread Suzanna McGee
I am unable to run Python on my computer because I keep getting the follow
error:

“The program can’t start because api-ms-win-crt-runtime-l1-1-0.dll is
missing from your computer. Try reinstalling the program to fix this
problem.”


-- 
Suzanna McGee
Computer Science Teacher
Notre Dame High School
Lawrenceville, New Jersey
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Two-Dimensional Expression Layout

2016-08-19 Thread Lawrence D’Oliveiro
On Saturday, August 20, 2016 at 9:56:05 AM UTC+12, codew...@gmail.com wrote:
>
> On Friday, August 19, 2016 at 5:30:22 PM UTC-4, Lawrence D’Oliveiro wrote:
>
>> On Saturday, August 20, 2016 at 7:52:09 AM UTC+12, codew...@gmail.com
>> wrote:
>>> if any([
>>> not isinstance(src, Image),
>>> mask != None and not isinstance(mask, Image),
>>> not isinstance(dest, Image),
>>> ]):
>>> raise TypeError("image args must be Image objects")
>>> 
>>> Or equivalently:
>>> 
>>> if not all([
>>> isinstance(src, Image),
>>> mask is None or isinstance(mask, Image),
>>> isinstance(dest, Image),
>>> ]):
>>> raise TypeError("image args must be Image objects")
>> 
>> Using “all” or “any” in this sort of situation may not be such a good
>> idea.
> 
> Would you care to elaborate?

There is no short-cut evaluation when constructing tuples and lists.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Run Error

2016-08-19 Thread Lawrence D’Oliveiro
On Saturday, August 20, 2016 at 10:01:08 AM UTC+12, Suzanna McGee wrote:
> “The program can’t start because api-ms-win-crt-runtime-l1-1-0.dll is
> missing from your computer. Try reinstalling the program to fix this
> problem.”

Why not do what it says?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Two-Dimensional Expression Layout

2016-08-19 Thread Chris Angelico
On Sat, Aug 20, 2016 at 8:31 AM, Lawrence D’Oliveiro
 wrote:
> On Saturday, August 20, 2016 at 9:56:05 AM UTC+12, codew...@gmail.com wrote:
>>
>> On Friday, August 19, 2016 at 5:30:22 PM UTC-4, Lawrence D’Oliveiro wrote:
>>
>>> On Saturday, August 20, 2016 at 7:52:09 AM UTC+12, codew...@gmail.com
>>> wrote:
 if any([
 not isinstance(src, Image),
 mask != None and not isinstance(mask, Image),
 not isinstance(dest, Image),
 ]):
 raise TypeError("image args must be Image objects")

 Or equivalently:

 if not all([
 isinstance(src, Image),
 mask is None or isinstance(mask, Image),
 isinstance(dest, Image),
 ]):
 raise TypeError("image args must be Image objects")
>>>
>>> Using “all” or “any” in this sort of situation may not be such a good
>>> idea.
>>
>> Would you care to elaborate?
>
> There is no short-cut evaluation when constructing tuples and lists.

I'm not sure how that would make difference in these examples. The
three parts are independent - the one place where short-circuiting is
important is indeed short-circuited.

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


Re: Two-Dimensional Expression Layout

2016-08-19 Thread codewizard
On Friday, August 19, 2016 at 6:38:34 PM UTC-4, Chris Angelico wrote:
> On Sat, Aug 20, 2016 at 8:31 AM, Lawrence D’Oliveiro
>  wrote:
> > On Saturday, August 20, 2016 at 9:56:05 AM UTC+12, codew...@gmail.com wrote:
> >>
> >> On Friday, August 19, 2016 at 5:30:22 PM UTC-4, Lawrence D’Oliveiro wrote:
> >>
> >>> On Saturday, August 20, 2016 at 7:52:09 AM UTC+12, codew...@gmail.com
> >>> wrote:
>  if any([
>  not isinstance(src, Image),
>  mask != None and not isinstance(mask, Image),
>  not isinstance(dest, Image),
>  ]):
>  raise TypeError("image args must be Image objects")
> 
>  Or equivalently:
> 
>  if not all([
>  isinstance(src, Image),
>  mask is None or isinstance(mask, Image),
>  isinstance(dest, Image),
>  ]):
>  raise TypeError("image args must be Image objects")
> >>>
> >>> Using “all” or “any” in this sort of situation may not be such a good
> >>> idea.
> >>
> >> Would you care to elaborate?
> >
> > There is no short-cut evaluation when constructing tuples and lists.
> 
> I'm not sure how that would make difference in these examples. The
> three parts are independent - the one place where short-circuiting is
> important is indeed short-circuited.
> 
> ChrisA

Agreed. Besides, just because this technique has limitations, it's still useful 
for me to improve readability.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Two-Dimensional Expression Layout

2016-08-19 Thread Lawrence D’Oliveiro
On Saturday, August 20, 2016 at 10:38:34 AM UTC+12, Chris Angelico wrote:
>
> On Sat, Aug 20, 2016 at 8:31 AM, Lawrence D’Oliveiro wrote:
>>
>> There is no short-cut evaluation when constructing tuples and lists.
> 
> I'm not sure how that would make difference in these examples. The
> three parts are independent - the one place where short-circuiting is
> important is indeed short-circuited.

That often is not the case, e.g. 
:

assert \
(
len(self.points) == 0
or
not self.points[0].off
and
(closed or not self.points[-1].off)
)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Two-Dimensional Expression Layout

2016-08-19 Thread Lawrence D’Oliveiro
On Friday, August 19, 2016 at 8:56:31 PM UTC+12, I wrote:
> To avoid lines getting long, why not take advantage of the two available
> screen/page dimensions to make [expression] structure clearer?

Another aspect of this has to do with line length. I regularly set my editor 
window width to around 100 columns. But if you exclude indentation whitespace, 
my lines are usually much shorter than that.

There is a limit to the length of text lines that a human reader can cope with 
(which is why newspapers, for example, tend to have a many-column layout). 
Using two-dimensional layout and indentation helps to keep the (non-whitespace) 
line length within reasonable limits.
-- 
https://mail.python.org/mailman/listinfo/python-list


Does This Scare You?

2016-08-19 Thread Lawrence D’Oliveiro
Python 3.5.2+ (default, Aug  5 2016, 08:07:14) 
[GCC 6.1.1 20160724] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import PureWindowsPath
>>> PureWindowsPath("prn").is_reserved()
True
>>> PureWindowsPath("prn.doc").is_reserved()
True
>>> PureWindowsPath("com9.exe").is_reserved()
True
>>> PureWindowsPath("c:/my documents/prn.doc").is_reserved()
True
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Run Error

2016-08-19 Thread MRAB

On 2016-08-19 23:31, Lawrence D’Oliveiro wrote:

On Saturday, August 20, 2016 at 10:01:08 AM UTC+12, Suzanna McGee wrote:

“The program can’t start because api-ms-win-crt-runtime-l1-1-0.dll is
missing from your computer. Try reinstalling the program to fix this
problem.”


Why not do what it says?


Because that won't fix it.

It needs the Universal C Runtime. An up-to-date system should already 
have it.


Read here:

Update for Universal C Runtime in Windows
https://support.microsoft.com/en-us/kb/2999226

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


Re: The Joys Of Data-Driven Programming

2016-08-19 Thread Lawrence D’Oliveiro
On Thursday, August 18, 2016 at 4:47:28 PM UTC+12, Marko Rauhamaa wrote:
> ... as a rule, I dislike rules. Rule languages tend to
> grow out of all bounds, always remain deficient and have impenetrable,
> ad-hoc semantics.

That’s a very peculiar thing to say, considering that data-driven programming 
is a well-known technique for writing compact code.

Less code, and in particular, less repetitive code => fewer bugs.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does This Scare You?

2016-08-19 Thread Chris Angelico
On Sat, Aug 20, 2016 at 9:42 AM, Lawrence D’Oliveiro
 wrote:
> Python 3.5.2+ (default, Aug  5 2016, 08:07:14)
> [GCC 6.1.1 20160724] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from pathlib import PureWindowsPath
> >>> PureWindowsPath("prn").is_reserved()
> True
> >>> PureWindowsPath("prn.doc").is_reserved()
> True
> >>> PureWindowsPath("com9.exe").is_reserved()
> True
> >>> PureWindowsPath("c:/my documents/prn.doc").is_reserved()
> True

When was the last time you wanted to create a file with a reserved
name? Paths, drive letters, file extensions, don't matter. All that
matters is the base name.

Not a Python issue; they're reserved by Windows.

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


Re: saving octet-stream png file

2016-08-19 Thread Steve D'Aprano
On Sat, 20 Aug 2016 06:51 am, Lawrence D’Oliveiro wrote:

> On Saturday, August 20, 2016 at 6:03:53 AM UTC+12, Terry Reedy wrote:
>>
>> An 'octet' is a byte of 8 bits.
> 
> Is there any other size of byte?


Depends what you mean by "byte", but the short answer is "Yes".

In the C/C++ standard, bytes must be at least eight bytes. As the below FAQ
explains, that means that on machines like the PDP-10 a C++ compiler will
define bytes to be 32 bits.

One common definition of "byte" is the smallest addressable unit of memory.
On that basis, there have been machines like the Control Data 6600 where a
byte was 60 bits. Honeywell machines used 9 bits.

Digital signal processes (DSPs) frequently have bytes with more than eight
bits, such as Texas Instruments C54x DSPs (16 bit bytes), BelaSigna DSPs
(24 bits) and DSP56K/Symphony Audio DSPs (24 bits).

The Saturn CPU (used in the HP-48SX/GX calculator line) addresses memory
4-bit bytes.

Windows CE took the unusual, and non-conformant, approach of running on
hardware with 16 bit bytes and simply not defining "char" (and
presumably "byte") in their C compiler.


See:

https://isocpp.org/wiki/faq/intrinsic-types
http://stackoverflow.com/questions/5516044/system-where-1-byte-8-bit
http://stackoverflow.com/questions/2098149/what-platforms-have-something-other-than-8-bit-char
http://programmers.stackexchange.com/questions/120126/what-is-the-history-of-why-bytes-are-eight-bits



-- 
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: Does This Scare You?

2016-08-19 Thread Wildman via Python-list
On Sat, 20 Aug 2016 10:57:37 +1000, Chris Angelico wrote:

> On Sat, Aug 20, 2016 at 9:42 AM, Lawrence D’Oliveiro
>  wrote:
>> Python 3.5.2+ (default, Aug  5 2016, 08:07:14)
>> [GCC 6.1.1 20160724] on linux
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> from pathlib import PureWindowsPath
>> >>> PureWindowsPath("prn").is_reserved()
>> True
>> >>> PureWindowsPath("prn.doc").is_reserved()
>> True
>> >>> PureWindowsPath("com9.exe").is_reserved()
>> True
>> >>> PureWindowsPath("c:/my documents/prn.doc").is_reserved()
>> True
> 
> When was the last time you wanted to create a file with a reserved
> name? Paths, drive letters, file extensions, don't matter. All that
> matters is the base name.
> 
> Not a Python issue; they're reserved by Windows.
> 
> ChrisA

Since I am fairly new to Python, I realize there is much that I
still don't know but I don't understand how Windows can have
reserved names on a Linux system.  What am I missing?

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does This Scare You?

2016-08-19 Thread Chris Angelico
On Sat, Aug 20, 2016 at 11:11 AM, Wildman via Python-list
 wrote:
> Since I am fairly new to Python, I realize there is much that I
> still don't know but I don't understand how Windows can have
> reserved names on a Linux system.  What am I missing?

The PureWindowsPath class is specifically working with the Windows
file system rules. Those names aren't reserved under Linux, but you
can still ask the pathlib module whether or not they *would be*
reserved under Windows. This is very handy if you're planning to
create files and don't know whether they'd work or not - you don't
need to grab a Windows machine (virtual or physical) to test stuff.

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


Re: Python Run Error

2016-08-19 Thread Lawrence D’Oliveiro
On Saturday, August 20, 2016 at 11:57:16 AM UTC+12, MRAB wrote:
>
> On 2016-08-19 23:31, Lawrence D’Oliveiro wrote:
>
>> On Saturday, August 20, 2016 at 10:01:08 AM UTC+12, Suzanna McGee wrote:
>>> “The program can’t start because api-ms-win-crt-runtime-l1-1-0.dll is
>>> missing from your computer. Try reinstalling the program to fix this
>>> problem.”
>>
>> Why not do what it says?
>>
> Because that won't fix it.

You mean, Windows is lying?

Say it isn’t so!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: saving octet-stream png file

2016-08-19 Thread Random832
On Fri, Aug 19, 2016, at 21:09, Steve D'Aprano wrote:
> Depends what you mean by "byte", but the short answer is "Yes".
> 
> In the C/C++ standard, bytes must be at least eight bytes. As the below
> FAQ
> explains, that means that on machines like the PDP-10 a C++ compiler will
> define bytes to be 32 bits.

I assume you mean 36, but I think this is mixing up two separate parts
of the FAQ along with some theory discussion. AFAIK all historical C
implementations for the PDP-10 and other 18- or 36-bit word systems have
used the "9-bit bytes, and an extra offset member in char and void
pointers if necessary" solution rather than the "word-sized byte"
solution.

In principle, I think a close reading of the standard would allow for an
implementation can have 'skipped bits' as discussed there so long as
there is no significance to the 'missing' bits in *any* type - so you
could legally have 8-bit bytes on a PDP-10 so long as you also had
16-bit shorts, 32-bit long/pointer/float, and in general *never ever*
broke the illusion that only the bits addressable via char pointers
exist. Modern implementations aren't expected to expose ECC bits, after
all.

Such an implementation would probably be best done by ignoring the high
bits of each word, which are easily masked off and often have no real
use anyway in pointers (How many of these systems supported 2^36 words =
288 modern gigabytes of memory?), rather than by ignoring a single bit
"between" each byte. AIUI many PDP-10 applications only used 18 bits for
word pointers.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does This Scare You?

2016-08-19 Thread Wildman via Python-list
On Sat, 20 Aug 2016 11:20:44 +1000, Chris Angelico wrote:

> On Sat, Aug 20, 2016 at 11:11 AM, Wildman via Python-list
>  wrote:
>> Since I am fairly new to Python, I realize there is much that I
>> still don't know but I don't understand how Windows can have
>> reserved names on a Linux system.  What am I missing?
> 
> The PureWindowsPath class is specifically working with the Windows
> file system rules. Those names aren't reserved under Linux, but you
> can still ask the pathlib module whether or not they *would be*
> reserved under Windows. This is very handy if you're planning to
> create files and don't know whether they'd work or not - you don't
> need to grab a Windows machine (virtual or physical) to test stuff.
> 
> ChrisA

OK.  I understand.  Python is after all cross-platform so that
makes perfect sense.  Thanks.

-- 
 GNU/Linux user #557453
The voices in my head may not be real
but, they have some good ideas.
-- 
https://mail.python.org/mailman/listinfo/python-list


Holding until next value change

2016-08-19 Thread Arshpreet Singh
I am writing a function as main_call() which is continuously producing values. 
(+ve or -ve) I want to print on screen only for first +ve value and hold until 
-ve value comes around. here is my code:


def main_call():
while True:
yield strategy()
 
for value in main_call():
if(value>0):
print '+ve'
elif(value>0):
print '-ve'
else:
pass 

Do I need to use threads or processes?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Holding until next value change

2016-08-19 Thread Steve D'Aprano
On Sat, 20 Aug 2016 02:53 pm, Arshpreet Singh wrote:

> I am writing a function as main_call() which is continuously producing
> values. (+ve or -ve) I want to print on screen only for first +ve value
> and hold until -ve value comes around. here is my code:
> 
> 
> def main_call():
> while True:
> yield strategy()
>  
> for value in main_call():
> if(value>0):
> print '+ve'
> elif(value>0):
> print '-ve'
> else:
> pass
> 
> Do I need to use threads or processes?

Only if you want a major headache.


Your code doesn't do what you want it to do. It prints "+ve" every time it
sees a positive value, not just the first time.

One solution to this is to think of a state machine: your machine starts off
in the state:

(1) Ignore negative values, print the first positive value you see, 
then change to the next state.

The second state is:

(2) Ignore positive values, print the first negative value you see,
then change to the next state.

The third state is unspecified. You don't know say what it is, so I'm going
to guess that you change to a third state:

(3) Don't ignore anything, print every value you see.


So here are our three machines:

def ignore_negative(x):
if x < 0:
return False
else:
print("+ve")
return True

def ignore_positive(x):
if x > 0:
return False
else:
print("-ve")
return True

def ignore_nothing(x):
if x > 0:
print("+ve")
else:
print("-ve")
return False


Here is a table that specifies the changes in state:

TABLE = { # current state: next state
ignore_negative: ignore_positive,
ignore_positive: ignore_nothing,
}


And some code to drive it:


state = ignore_negative  # DON'T call the function yet
for value in main_call():
print(value)  # for testing
if state(value):
print("changing state")
state = TABLE[state]




Another solution is to look at the itertools module, which has two
functions "dropwhile" and "takeuntil" that might help.


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