Subscribe to get an answer vs automatic CC Was: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread anatoly techtonik
On Wed, May 27, 2015 at 3:57 PM, Laura Creighton  wrote:
> Chris Angelico apparantly has a problem with cc'd people who aren't
> on the list.

I thought that CC in this case works automatically? If that's not
the case, then I'll be annoyed by this too. So, thanks for CCing.
=)

Also, https://mail.python.org/mailman/listinfo/python-list - this
page should probably mention that you need to subscribe to
ask a question (people like me won't read it anyway, but it
may help others).

> python-list is very quiet these days, so if you
> subscribe it won't be drinking from the firehose.

1688 / 29 = 58.206896551724135 msg/day don't look quiet,
and I don't want to be distracted by interesting side threads,
because I will accomplish nothing, get stressed, and things
get worse at the end of the day.

> And you can
> always turn off delivery when you are done. Or you can just
> go read the archives: 
> https://mail.python.org/pipermail/python-list/2015-May/thread.html

I wish I could also commend from the web interface. I've
heard Mailman 3.0 is stable, it will be interesting to see what
is it capable of.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Chris Angelico
On Fri, May 29, 2015 at 4:18 PM, Stefan Behnel  wrote:
>> Lua's a much weaker language than Python is, though. Can it handle
>> arbitrary-precision integers? Unicode? Dare I even ask,
>> arbitrary-precision rationals (fractions.Fraction)?
>
> All of those and way more, as long as you use it embedded in Python.

Okay, so how would you go about using Lua-embedded-in-Python to
manipulate Unicode text? I'm not talking about things like the
unicodedata module and the name/codepoint lookups, I'm talking about
the basics of working with international text and the fundamental need
for your native string type to cope with that. Do you have to keep
bouncing back and forth between Python and Lua? And if you do
arithmetic in the single most obvious way, what happens?

http://www.lua.org/pil/2.3.html

Looks to me as if Lua doesn't have integers at all, and so the obvious
form of arithmetic will be equivalent to doing everything in Python
floats. That's not arbitrary precision. There's also a comment that
you can use some other type for numbers, but I suspect that's still
"some other C type", so you still can't do arbitrary precision. (Plus
you get one type for ints and floats, so even if you did select some
magic type that bounces through to a Python int, it'd stop you from
doing any non-integral arithmetic at all.)

http://www.lua.org/pil/2.4.html

Likewise, eight-bit strings, not Unicode. While I could accept some
sort of inter-language thunk for something uncommon, like
fractions.Fraction, forcing people to thunk back and forth for basic
arithmetic and string manipulation is way too much hassle - which
means they won't do it, which means strings will be eight-bit and
numbers will be doubles. And eight-bit strings might be treated as
UTF-8, or might be treated as some arbitrary codepage, or might be
both at once in different contexts, so you can't really depend on them
being anything more than ASCII.

Or can you change all this when you embed Lua?

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


Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread anatoly techtonik
On Wed, May 27, 2015 at 3:57 PM, Laura Creighton  wrote:
> --- Forwarded Message
>
> Return-Path: 
> Received: from mail.python.org (mail.python.org [82.94.164.166])
> by theraft.openend.se (8.14.4/8.14.4/Debian-4) with ESMTP id 
> t4RC09ap02From: Chris Angelico 
> Cc: "python-list@python.org" 
>
>
> On Wed, May 27, 2015 at 9:52 PM, anatoly techtonik  
> wrote:
>> And the short answer is that we need unicode because we are printing this
>> information to the stdout, and stdout is opened in text mode at least on
>> Windows, and without explicit conversion, Python will try to decode stuff
>> as being `ascii` and fail anyway.
>
> So you're working with text.

No. It is unknown.

I am printing Nodes of SCons build graph and I don't know how Nodes are
represented. In my case it appeared that Node contained Russian text, which
led to crash of SCons. It could contain Russian text in cp1251 or in utf-8 or in
KOI-8 and I can't do guessing of all possible encodings there. I just need to
print that tree without crash or information loss.

> That means you HAVE to decode it somehow;
> you fundamentally cannot print bytes to the console. Lossless
> concealment of arbitrary bytes won't help you.

Won't help me with what? I am debugging build scripts to find out the
*structure* of my dependencies and then all of the sudden Python crashes
with UnicodeDecode error leaving me pronouncing bad Russian curses
aloud.

It is not even less forgiving than Java, but is also more treacherous,
because of its run-time nature.

It will surely help to preserve my zen if Python could just flow through
the nodes of this graph. Garbage is okay - I can clean it up or remove if it
stands in the way, just disrupt my flow or say me that now I want to deal
with UnicodeDecode errors. Because I don't.

> If you can't adequately
> decode everything, either backslash-escape the rest, or use a
> replacement character; you can't print out those bytes.

Yes. How to backslash the rest in Python 2? In Python 3 there is
some freaky "surrogateescape" error strategy, but what to do in
Python 2?

Replacement character is not a solution, because it is a data loss,
and if I want to do post processing of graph log, I won't be able to
recover the missing bits.

> And no, I will not cc you. Subscribe to the list if you're going to
> ask a question.

Added Mailman to my suxx tracker:
https://github.com/techtonik/suxx-tracker#mailman

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


Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread Chris Angelico
On Fri, May 29, 2015 at 6:05 PM, anatoly techtonik  wrote:
>> On Wed, May 27, 2015 at 9:52 PM, anatoly techtonik  
>> wrote:
>>> And the short answer is that we need unicode because we are printing this
>>> information to the stdout, and stdout is opened in text mode at least on
>>> Windows, and without explicit conversion, Python will try to decode stuff
>>> as being `ascii` and fail anyway.
>>
>> So you're working with text.
>
> No. It is unknown.
>
> I am printing Nodes of SCons build graph and I don't know how Nodes are
> represented. In my case it appeared that Node contained Russian text, which
> led to crash of SCons. It could contain Russian text in cp1251 or in utf-8 or 
> in
> KOI-8 and I can't do guessing of all possible encodings there. I just need to
> print that tree without crash or information loss.

You're saying it's text, but you don't know the encoding. You're
trying to display bytes as if they're text, but fundamentally, you're
trying to work with text.

>> That means you HAVE to decode it somehow;
>> you fundamentally cannot print bytes to the console. Lossless
>> concealment of arbitrary bytes won't help you.
>
> Won't help me with what? I am debugging build scripts to find out the
> *structure* of my dependencies and then all of the sudden Python crashes
> with UnicodeDecode error leaving me pronouncing bad Russian curses
> aloud.

Your fundamental problem is not the UnicodeDecodeError, but the
unknown encoding. What you're seeing is that Python refuses to be
sloppy.

>> If you can't adequately
>> decode everything, either backslash-escape the rest, or use a
>> replacement character; you can't print out those bytes.
>
> Yes. How to backslash the rest in Python 2? In Python 3 there is
> some freaky "surrogateescape" error strategy, but what to do in
> Python 2?

Not sure what's so freaky about it. But hey. If Python 2 can't do what
you want, is it so hard to use Python 3? Unicode support really is
better. Alternatively, just do something like this:

b = "some arbitrary byte string that you got from somewhere"
try:
text = b.decode("utf-8")
except UnicodeDecodeError:
text = repr(b).decode("ascii")

The repr of a byte string in Py2 should be a safe way to display
arbitrary bytes, without data loss. It will expand the string
significantly (four characters for one \xNN escape, plus adding
backslashes to everything else that needs them), but it does guarantee
safety.

> Replacement character is not a solution, because it is a data loss,
> and if I want to do post processing of graph log, I won't be able to
> recover the missing bits.
>
>> And no, I will not cc you. Subscribe to the list if you're going to
>> ask a question.
>
> Added Mailman to my suxx tracker:
> https://github.com/techtonik/suxx-tracker#mailman

Why? You're trying to fire questions out to a community without being
a part of that community. Why is that the software's problem?

You can either subscribe to the list/ng or follow via some web
interface, but it's unreasonable to ask everyone to cc you. Imagine if
we _did_ all cc you, but we also cc you in on an entire sub-thread
that you're not interested in. Or maybe half of us do and half don't.
What then? You don't get any sort of control over what you get copies
of. Is that really what you want?

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


Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread Laura Creighton
In a message of Fri, 29 May 2015 11:05:07 +0300, anatoly techtonik writes:

>Added Mailman to my suxx tracker:
>https://github.com/techtonik/suxx-tracker#mailman

You are damning the wrong piece of software -- this is not a problem
with mailman; mailman doesn't care at all what software you use to
read mail and reply to it with.  The problem is with the various
readers and repliers that people are using.  In particular, people on
the other side of one the usenet -> python-list gateway may not be seeing
this as mail at all, or sending their replies as mail.

But back to your original problem.

I still don't understand why you need to go from some lossless
representation of your filename, back to the original.  You start
with the binary version of the filename  -- a series of bytes which
turns out to be good Cyrillic text, but could be anything.  You store
that as the first so many bytes of your file. If ever you need to have
the original representation of your filename, you already have it,
right there, by reading the first so many bytes of your file.  Why
care about what the user sees as a filename?

Laura


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


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Stefan Behnel
Chris Angelico schrieb am 29.05.2015 um 09:41:
> On Fri, May 29, 2015 at 4:18 PM, Stefan Behnel wrote:
>>> Lua's a much weaker language than Python is, though. Can it handle
>>> arbitrary-precision integers? Unicode? Dare I even ask,
>>> arbitrary-precision rationals (fractions.Fraction)?
>>
>> All of those and way more, as long as you use it embedded in Python.
> 
> Okay, so how would you go about using Lua-embedded-in-Python to
> manipulate Unicode text?

Lua only supports byte strings, so Lupa will encode and decode them for
you. If that's not enough, you'll have to work with Python Unicode string
objects through the language interface. (And I just noticed that the
handling can be improved here by overloading Lua operators with Python
operators - not currently implemented.)


> Looks to me as if Lua doesn't have integers at all

The standard number type in Lua is a C double float, i.e. the steady
integer range is somewhere within +/-2^53. That tends to be enough for a
*lot* of use cases. You could change that type in the Lua C code (e.g. to a
64 bit int), but that's usually a bad idea. The same comment as above
applies: if you need Python object features, use Python objects.

Embedding Lua in Python gives you access to all of Python's objects and
ecosystem. It may not always be as cool to use as from Python, but in that
case, why not code it in Python in the first place? You wouldn't use
Lua/Lupa to write whole applications, just the user defined parts of them.
The rest can happily remain in Python. And should, for your own sanity.

Stefan


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


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Chris Angelico
On Fri, May 29, 2015 at 7:23 PM, Stefan Behnel  wrote:
> Chris Angelico schrieb am 29.05.2015 um 09:41:
>> On Fri, May 29, 2015 at 4:18 PM, Stefan Behnel wrote:
 Lua's a much weaker language than Python is, though. Can it handle
 arbitrary-precision integers? Unicode? Dare I even ask,
 arbitrary-precision rationals (fractions.Fraction)?
>>>
>>> All of those and way more, as long as you use it embedded in Python.
>>
>> Okay, so how would you go about using Lua-embedded-in-Python to
>> manipulate Unicode text?
>
> Lua only supports byte strings, so Lupa will encode and decode them for
> you. If that's not enough, you'll have to work with Python Unicode string
> objects through the language interface. (And I just noticed that the
> handling can be improved here by overloading Lua operators with Python
> operators - not currently implemented.)
>
>
>> Looks to me as if Lua doesn't have integers at all
>
> The standard number type in Lua is a C double float, i.e. the steady
> integer range is somewhere within +/-2^53. That tends to be enough for a
> *lot* of use cases. You could change that type in the Lua C code (e.g. to a
> 64 bit int), but that's usually a bad idea. The same comment as above
> applies: if you need Python object features, use Python objects.

Unicode strings shouldn't involve the hassle of bouncing through an
interface layer. Nobody will bother, and the result will be code
that's ASCII-only. That happens often enough even in Python 2, where
u"foo" is a Unicode string.

> Embedding Lua in Python gives you access to all of Python's objects and
> ecosystem. It may not always be as cool to use as from Python, but in that
> case, why not code it in Python in the first place? You wouldn't use
> Lua/Lupa to write whole applications, just the user defined parts of them.
> The rest can happily remain in Python. And should, for your own sanity.

The point was to sandbox something inside Python. Otherwise, yes, just
write it in Python. But if you do have to sandbox like this, you lose
language-level Unicode support, language-level arbitrary precision
integers, etcetera, etcetera, etcetera. So I stand by my previous
statement: The price of security is functionality.

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


Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread anatoly techtonik
On Fri, May 29, 2015 at 11:41 AM, Laura Creighton  wrote:
> In a message of Fri, 29 May 2015 11:05:07 +0300, anatoly techtonik writes:
>
>>Added Mailman to my suxx tracker:
>>https://github.com/techtonik/suxx-tracker#mailman
>
> You are damning the wrong piece of software -- this is not a problem
> with mailman; mailman doesn't care at all what software you use to
> read mail and reply to it with.  The problem is with the various
> readers and repliers that people are using.  In particular, people on
> the other side of one the usenet -> python-list gateway may not be seeing
> this as mail at all, or sending their replies as mail.

Sounds legit. But middle ux in suxx stands for user experience,
and Mailman still doesn't improve it. If Mailman could subscribe
me automatically to the thread I am starting, that would resolve
all the problems.

> But back to your original problem.
>
> I still don't understand why you need to go from some lossless
> representation of your filename, back to the original.

It is just happened that the only way to get graph out of SCons
is to print its tree representation. That worked fine until we
switched to from StringIO to its io.StringIO unicode equivalent.

Dumping binary stuff in text form is a very common and reliable
way to backup and process data. Starting from SQL dumps to
SVN dumps - all these formats are convenient to store, transmit
and process.

> You start
> with the binary version of the filename  -- a series of bytes which
> turns out to be good Cyrillic text, but could be anything.

Right, good Cyrillic text in utf-8, and Python 2.x uses 'ascii', so if
Python 2.x used 'utf-8' as its default encoding, there won't be an
issue. For now. But I realize that it is not enough, so I want 100%
protection from unwanted crashes and data loss, so I want to
backslash non-utf-8 bytes when converting the data to unicode.

> You store
> that as the first so many bytes of your file. If ever you need to have
> the original representation of your filename, you already have it,
> right there, by reading the first so many bytes of your file.  Why
> care about what the user sees as a filename?

Not sure that I understand. I don't store anything in file. Build graph
is a representation of filesystem structure with entries that may or
may not exist. Node in build graph can also be a string that is never
written to disk. When I dump graph, I have no idea how I will
process it, but when I will need to identify some Node, grep it, find
a reference to it, I want its representation (which may as well serve
as ID) to be preserved to avoid conflicts and wrong interpretation
due to data loss

Hopefully now that my user story is clear, can you tell me how can I
do this bulletproof unicode conversion in Python 2? =)
-- 
anatoly t.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Laura Creighton
In a message of Fri, 29 May 2015 19:38:21 +1000, Chris Angelico writes:
>The point was to sandbox something inside Python. Otherwise, yes, just
>write it in Python. But if you do have to sandbox like this, you lose
>language-level Unicode support, language-level arbitrary precision
>integers, etcetera, etcetera, etcetera. So I stand by my previous
>statement: The price of security is functionality.
>
>ChrisA

You can run a pypy sandbox from inside your CPython app, if that
is what you want to do.  http://pypy.readthedocs.org/en/latest/sandbox.html

Just FYI.

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


Re: Fixing Python install on the Mac after running 'CleanMyMac'

2015-05-29 Thread Laura Creighton
In a message of Thu, 28 May 2015 23:07:42 -0700, Ned Deily writes:
>It would be helpful to know what utility it is that is encountering the 
>fatal error; that message is not familiar and I suspect it is coming 
>from trying to run some third-party application.  It may be that the 
>application was depending on a third-party framework installation of 
>Python (in /Library/Frameworks rather than the system Python in 
>/System/Library/Frameworks), such as provided by the python.org OS X 
>installers, but without knowing more information, like what particular 
>version of Python is needed, it would only be speculation.  Perhaps the 
>best thing to do is to suggest the OP to participate directly here or an 
>Apple users' forum like http://apple.stackexchange.com.
>
>-- 
> Ned Deily,
> n...@acm.org

I asked her to come here, but I fear she is feeling a tad too
embarassed to do that right now.  I don't know how to find out
the name of the Utility -- the Error message really does say
'Utility' -- with no name for it.  Apparantly there is some log
file you can go take a look at to find out, but I don't know
what it is ...

Laura

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


Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread Ian Kelly
On Fri, May 29, 2015 at 2:05 AM, anatoly techtonik  wrote:
> Added Mailman to my suxx tracker:
> https://github.com/techtonik/suxx-tracker#mailman

What a useless tool. Instead of tiredly complaining that things suck,
why not take some initiative to make them better?

I'm curious about your complaint about virtualenv. How do you envision
that "logging in" to the env would be any different from activating
it?
-- 
https://mail.python.org/mailman/listinfo/python-list


stdout of child process as an input of another thread in Python?

2015-05-29 Thread Kevin Peterson
Hi, 

I want to use the stdout of child process as an input of another thread, but 
some how I am not able to read the stdout.  Using Popen I have created a child 
process and stdout of it I have redirected to PIPE (because I don't want that 
to be printed on with my main process).  Now using this 
statement,"Line=Proc.stdout.readline()" I want to read stdout of child process 
and I have to do operation on that. but somehow i am not able to read from 
stdout of child process. 

Following is the code snapshot - 

Proc = Popen(["python.exe","filename.py"],stdout=PIPE)

while True:
Line = Proc.stdout.readline()
print Line

Here,
Filename.py(Child process) is continuously printing "Hello World!!" in place of 
reading stdout of child process. 



Thanks,
Kevin Peterson


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


Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread Mark Lawrence

On 29/05/2015 11:02, Ian Kelly wrote:

On Fri, May 29, 2015 at 2:05 AM, anatoly techtonik  wrote:

Added Mailman to my suxx tracker:
https://github.com/techtonik/suxx-tracker#mailman


What a useless tool. Instead of tiredly complaining that things suck,
why not take some initiative to make them better?



The guy who refuses to sign the CLA taking some initiative to make 
things better?  Is that an entire air force of flying pigs I observe 
going past my window, or merely one US atomic powered carrier's worth?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread Jon Ribbens
On 2015-05-29, Ian Kelly  wrote:
> On Fri, May 29, 2015 at 2:05 AM, anatoly techtonik  
> wrote:
>> Added Mailman to my suxx tracker:
>> https://github.com/techtonik/suxx-tracker#mailman
>
> What a useless tool. Instead of tiredly complaining that things suck,
> why not take some initiative to make them better?
>
> I'm curious about your complaint about virtualenv. How do you envision
> that "logging in" to the env would be any different from activating
> it?

Please Do Not Feed The Troll.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Logic problem: need better logic for desired thruth table.

2015-05-29 Thread Tim Chase
On 2015-05-29 13:48, Chris Angelico wrote:
> That said, though, using 0 for False and 1 for True is easily
> the most common convention in use today, and the next most likely
> case is that comparing booleans would give a simple and immediate
> error. So it's most likely to be safe to do.

There are popular exceptions though. coughshellscriptingcough

-tkc




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


Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread Laura Creighton
Do you know about the codecs module?

reading http://pymotw.com/2/codecs/ may be useful if this is new to you.

Have you read https://www.python.org/dev/peps/pep-0293/ ?

Will backslashreplace do what you want?

Laura

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


Re: Logic problem: need better logic for desired thruth table.

2015-05-29 Thread alister
On Fri, 29 May 2015 13:48:55 +1000, Chris Angelico wrote:

> On Fri, May 29, 2015 at 1:20 PM,   wrote:
>> The possibility of spelling these with the comparison operators, as
>> some have suggested, is a consequence of Python's implementation where
>> True == 1 and False == 0. In other languages bool may not be relatable
>> (or at least not orderable), or False may be == -1.
> 
> True. That said, though, using 0 for False and 1 for True is easily the
> most common convention in use today, and the next most likely case is
> that comparing booleans would give a simple and immediate error. So it's
> most likely to be safe to do. Cross-language compatibility is a tricky
> thing anyway; there are all sorts of odd edge cases, even with
> otherwise-similar languages (Pike and Python, for instance, have
> slightly different handling of slice ranges), so anything that's done in
> Python is meant to be interpreted with Python semantics.
> 
> ChrisA

in the past True has even been -1 with 0 as false
(all bits set in a signed integer)




-- 
I use technology in order to hate it more properly.
-- Nam June Paik
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Logic problem: need better logic for desired thruth table.

2015-05-29 Thread random832
On Thu, May 28, 2015, at 23:49, Skybuck Flying wrote:
> Ok thanks for this information.
> 
> I was just wondering how many thruth table combinations there can be for
> a 
> typical thruth table with 2 inputs and 1 output.
> 
> Since there are 2 inputs, this means 4 possible outputs, which means 2 to 
> the power of 4 different thruth tables possible, which is indeed 16.
> 
> Perhaps you have a link to all possible 16 thruth tables and their formal 
> names ? That would help !

http://en.wikipedia.org/wiki/Truth_table#Binary_operations

Scroll down a bit for the formal names.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Logic problem: need better logic for desired thruth table.

2015-05-29 Thread random832
On Thu, May 28, 2015, at 23:48, Chris Angelico wrote:
> On Fri, May 29, 2015 at 1:20 PM,   wrote:
> > The possibility of spelling these with the comparison operators, as some
> > have suggested, is a consequence of Python's implementation where True
> > == 1 and False == 0. In other languages bool may not be relatable (or at
> > least not orderable), or False may be == -1.
> 
> True.

Gah. I said "False may be -1", but what I *meant* was that *True* may be
-1: something that has some merit for bitwise logic (-1 is all-bits-1).
This is, for example, used in pre-.NET incarnations of Visual Basic (and
COM's VARIANT_BOOL type inherits from this). VB, incidentally, has its
own spellings for these operators, with the "Imp" and "Eqv" operators.
-- 
https://mail.python.org/mailman/listinfo/python-list


python

2015-05-29 Thread David Skardon
Absolute rubbish tried all ways to run python keeps saying processor isn't 
compatible, I have a 6 core 6200 amd processor, so how does one install this 
program and get its minute brain to operate
regards
Dave


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python

2015-05-29 Thread Laura Creighton
In a message of Fri, 29 May 2015 13:42:27 +0100, "David Skardon" writes:
>Absolute rubbish tried all ways to run python keeps saying processor isn't 
>compatible, I have a 6 core 6200 amd processor, so how does one install this 
>program and get its minute brain to operate
>regards
>Dave

We need more information, including
What operating system? Python 2 or Python 3?
Are you trying to build your own Python from source, or install
a binary?  Or are you embedding?

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


Re: Fixing Python install on the Mac after running 'CleanMyMac'

2015-05-29 Thread Cem Karan

On May 28, 2015, at 11:47 PM, Laura Creighton  wrote:

> webmas...@python.org just got some mail from some poor embarrased
> soul who ran this program and broke their Python install.
> 
> They are running Mac OSX 10.7.5
> 
> They are getting:
> 
> Utility has encountered a fatal error, and will now terminate.  A
> Python runtime could not be located. You may need to install a
> framework build of Python or edit the PyRuntimeLocations array in this
> applications info.plist file.  Then there are two oblong circles. One
> says Open Console. The other says Terminate.
> 
> So https://docs.python.org/2/using/mac.html says:
> 
>   The Apple-provided build of Python is installed in
>   /System/Library/Frameworks/Python.framework and /usr/bin/python,
>   respectively. You should never modify or delete these, as they are
>   Apple-controlled and are used by Apple- or third-party software.
> 
> So, I assume this poor soul has done precisely that.
> 
> What do I tell her to do now?

Does she have a recent Time Machine backup that she can restore from?  
Otherwise the solutions are all fairly painful:

1) Install Python 2.7 from scratch (easy).  Then figure out where to put 
symlinks that point back to the install (mildly annoying/hard).  Note that 
Python 3 won't work; none of the built-in scripts expect it.

2) OS X recovery - 
http://www.macworld.co.uk/how-to/mac/how-reinstall-mac-os-x-using-internet-recovery-3593641/
 I've never had to do that, so I have no idea how easy/reliable it is.  I 
**think** its supposed to save all the data on the drive, but again, I've not 
done this, so I can't make any guarantees.

3) Wipe it clean and reinstall from scratch.

Honestly, I hope she has a time machine backup.  I've had to do recoveries a 
couple of times, and it can really save you.

Good luck,
Cem Karan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python

2015-05-29 Thread Steven D'Aprano
On Fri, 29 May 2015 10:42 pm, David Skardon wrote:

> Absolute rubbish tried all ways to run python keeps saying processor isn't
> compatible, I have a 6 core 6200 amd processor, so how does one install
> this program and get its minute brain to operate regards Dave

Clearly a genius like yourself has discovered our plot. Python is a
practical joke, it doesn't actually run for anyone. We all hand around here
pretending to have conversations about an imaginary programming language,
just to play a prank on people like you.

Nah, just kidding.

It sounds like you are trying to run a binary compiled for one CPU on a
different CPU, just like the error message says. I see in my crystal ball
that you downloaded the Mac version of Python and are trying to run it on
your Windows system, or perhaps it is the other way around, my crystal ball
sometimes gets things reversed like that.

Perhaps it would help if you would stop with the stupid insults about minute
brains and absolute rubbish, and instead describe your problem in more
detail. Starting with what platform you are using (e.g. 32 bit Windows XP,
64-bit Linux, something else?), what you did to install Python, where you
got it from, and the *exact* error message.

Then perhaps I can stop relying on my crystal ball and give you some more
useful advice.




-- 
Steven

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


Inverted Comma Search

2015-05-29 Thread subhabrata . banerji
Dear Group,

I am trying to implement two searches, inverted comma search and search within 
brackets. I am trying to implement them in Whoosh, but not finding good 
tutorial or examples. If any one may kindly help me with.

Regards,
Subhabrata Banerjee. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Inverted Comma Search

2015-05-29 Thread Laura Creighton
In a message of Fri, 29 May 2015 06:41:49 -0700, subhabrata.bane...@gmail.com w
rites:
>Dear Group,
>
>I am trying to implement two searches, inverted comma search and search within 
>brackets. I am trying to implement them in Whoosh, but not finding good 
>tutorial or examples. If any one may kindly help me with.
>
>Regards,
>Subhabrata Banerjee. 
>--

I think you may get better answers if you try the Whoosh Google group.
https://groups.google.com/forum/#!forum/whoosh

But maybe people here know, too.

(alas, I don't).
Laura


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


Is it possible to find python34.lib from within Python?

2015-05-29 Thread Paul Moore
I want to set up a script to build some C code. I need to link it with 
python34.lib, but I'm not sure how to locate that file without hard-coding it.

There doesn't seem to be a sysconfig path I can use - best ways I can think of 
for finding it in a way that works even if I'm in a virtualenv is:

os.path.join(getattr(sys, 'real_prefix', sys.prefix), 'libs', 'python%s%s.lib' 
% sys.version_info[:2])

Is that the best way, or is there something better I could use?

In particular, this only works on Windows, which is OK for my needs, but it'd 
be nice if I could make it cross-platform, just in case.

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


Re: Accessing DataSocket Server with Python

2015-05-29 Thread William Ray Wing

> On May 28, 2015, at 6:17 PM, Dan Stromberg  wrote:
> 
> I have no idea about the protocol used by NI DataSockets, but you
> might be able to reverse engineer the protocol by using the official
> client with a sniffer.
> 
> Also, be aware that TCP/IP guarantees that you get the correct data in
> the correct order, but it doesn't guarantee anything about the sizes
> of the chunks in which that data arrives.  So you could send 100
> bytes, 100 bytes, 100 bytes, but on the other end receive 100 bytes,
> 50 bytes, 75 bytes, 75 bytes.  When you catenate them all together,
> it's still the same data though.
> 
> HTH.
> 
> On Wed, May 27, 2015 at 4:30 AM, Garrone, Corrado

While that’s certainly possible in a routed network (and even then can be 
overridden with the “do not fragment” bit), it won’t happen in a LAN or 
self-contained instrument set-up.  These days, even routed networks tend to 
deliver anything less than a 1500 byte packet as a single entity.  With fiber 
backbones and high-speed LANs, it is more work for a router to fragment a 
packet then to simply pass it on.  The days of 480 byte packets pretty much 
went away with dial-up modems.

Bill



>  wrote:
>> Dear Python Team,
>> 
>> currently I am working on a research project for my bachelor degree. A
>> LabVIEW application is used for current and power measurements, whereas the
>> measured data are sent to DataSocket Server, a technology by National
>> Instruments used for data exchange between computers and applications.
>> DataSocket is based on TCP/IP and thus requesting data from DataSocket
>> should be similar to an internet request.
>> I know with the socket library in Python it is possible with to establish
>> sockets, send internet requests and communicate between clients and servers.
>> Is there a possibility to access NI DataSocket and get measurement data with
>> Python on the same computer where Python is installed and the codes are
>> executed? Can you maybe send me an example code where such a connection with
>> DataSocket is established?
>> 
>> If you got any queries, please do not hesitate to contact me.
>> 
>> Thank you very much for your efforts.
>> 
>> Kind regards,
>> 
>> Corrado Garrone
>> DH-Student Fachrichtung Elektrotechnik / Co-op Student B.Eng. Electrical
>> Engineering
>> 
>> Roche Diagnostics GmbH
>> DFGHMV8Y6164
>> Sandhofer Strasse 116
>> 68305 Mannheim / Germany
>> 
>> Phone: apprentice
>> mailto:corrado.garr...@roche.com
>> 
>> Roche Diagnostics GmbH
>> Sandhofer Straße 116; D‑68305 Mannheim; Telefon +49‑621‑759‑0; Telefax
>> +49‑621‑759‑2890
>> Sitz der Gesellschaft: Mannheim - Registergericht: AG Mannheim HRB 3962 -
>> Geschäftsführung: Dr. Ursula Redeker, Sprecherin; Edgar Vieth -
>> Aufsichtsratsvorsitzender: Dr. Severin Schwan
>> 
>> Confidentiality Note
>> This message is intended only for the use of the named recipient(s) and may
>> contain confidential and/or privileged information. If you are not the
>> intended recipient, please contact the sender and delete the message. Any
>> unauthorized use of the information contained in this message is prohibited.
>> 
>> 
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread anatoly techtonik
On Fri, May 29, 2015 at 2:39 PM, Laura Creighton  wrote:
> Do you know about the codecs module?
>
> reading http://pymotw.com/2/codecs/ may be useful if this is new to you.

Does that work for Python 2 and Python 3?

> Have you read https://www.python.org/dev/peps/pep-0293/ ?

No.

> Will backslashreplace do what you want?

I don't know. I am sorry, but what is there the code that
does this:

  binary -> escaped utf-8 string -> unicode -> binary

I know about coding module, but I am not seeing a solution
to crash-proof output from Python. Is inserting a custom codec
class into every piece of code that I want to debug is the only
solution?
-- 
anatoly t.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OpenCV with Python (cv or cv2)

2015-05-29 Thread Markos

Hi Laura,

I will follow your advice and install Debian 8.0. I was postponing this 
upgrade. :^)


I just find that Jessie is the new stable release.

According to the tutorial:

http://milq.github.io/install-opencv-ubuntu-debian/

the simplest way to install opencv in jessie is:

apt-get install python-dev libopencv-opencv

And from what I saw the opencv package available in the repository is 2.4.9

https://packages.debian.org/jessie/python-opencv

And from what I saw on the site:

https://packages.debian.org/jessie/python3
and
https://packages.debian.org/jessie/python

There are packages in the repository for python 3.4.2-2 and 2.7.9-1

My doubt is which version of Python (3.4.2-2 or 2.7.9-1) is compatible 
with the opencv library 2.4.9 available in the repository?


Thanks for your attention,
Markos


On 28-05-2015 01:47, Laura Creighton wrote:

Your cmake output doesn't mention that it tried to build libcv.so
so, I guess the reason you cannot find it is that it never tried
to make it.

You may already have fixed your problem by just installing the relevant
debian package.  If not, it may be that you need to install this one
https://packages.debian.org/squeeze/libcv-dev to get libcv.

You have another problem. Squeeze is _very_ old.
According to 
http://stackoverflow.com/questions/5212728/libcxcore-so-2-missing-in-opencv
the opencv project renamed a bunch of libraries, so if at all possible you
should upgrade your debian distribution.  You may have all sorts of
mismatches between the source you just built and the libraries you
need -- which you will only find by trial and error.

Laura

   


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


Re: Accessing DataSocket Server with Python

2015-05-29 Thread Chris Angelico
On Fri, May 29, 2015 at 11:37 PM, William Ray Wing  wrote:
>> On May 28, 2015, at 6:17 PM, Dan Stromberg  wrote:
>>
>> I have no idea about the protocol used by NI DataSockets, but you
>> might be able to reverse engineer the protocol by using the official
>> client with a sniffer.
>>
>> Also, be aware that TCP/IP guarantees that you get the correct data in
>> the correct order, but it doesn't guarantee anything about the sizes
>> of the chunks in which that data arrives.  So you could send 100
>> bytes, 100 bytes, 100 bytes, but on the other end receive 100 bytes,
>> 50 bytes, 75 bytes, 75 bytes.  When you catenate them all together,
>> it's still the same data though.
>>
>> HTH.
>>
>> On Wed, May 27, 2015 at 4:30 AM, Garrone, Corrado
>
> While that’s certainly possible in a routed network (and even then can be 
> overridden with the “do not fragment” bit), it won’t happen in a LAN or 
> self-contained instrument set-up.  These days, even routed networks tend to 
> deliver anything less than a 1500 byte packet as a single entity.  With fiber 
> backbones and high-speed LANs, it is more work for a router to fragment a 
> packet then to simply pass it on.  The days of 480 byte packets pretty much 
> went away with dial-up modems.
>

It's uncommon to receive 100, 50, 75, 75, to be sure, but it's
certainly possible for multiple writes to be gathered together into
single reads; there are buffers at both ends, and if there's any delay
anywhere, stuff can get combined while it's waiting. (Even stuff that
had previously been sent out as multiple packets, if the data has to
be re-sent, might get grouped.) So you still need to consider your
protocol to be a stream, and delimit messages explicitly rather than
depending on the length of a socket-read. Most of these kinds of
protocols seem to have some kind of message boundary system, though,
so this shouldn't be a problem. (I'm not familiar with DataSocket
itself, but I've used several others that are like that. Even
venerable TELNET effectively does - a "message" is a line of text, so
it's delimited by newline.)

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


Re: Logic problem: need better logic for desired thruth table.

2015-05-29 Thread Chris Angelico
On Fri, May 29, 2015 at 8:53 PM, Tim Chase
 wrote:
> On 2015-05-29 13:48, Chris Angelico wrote:
>> That said, though, using 0 for False and 1 for True is easily
>> the most common convention in use today, and the next most likely
>> case is that comparing booleans would give a simple and immediate
>> error. So it's most likely to be safe to do.
>
> There are popular exceptions though. coughshellscriptingcough

Yes, so you'd have to be careful if you port your complex script to
bash [1]. I'm also not sure how you'd even implement the comparison.
But shell scripting is still dwarfed by languages in which false is 0
and true is (usually) 1. Using Redmonk rankings:

1 JavaScript
2 Java
3 PHP
4 Python
5 C#
5 C++
5 Ruby
8 CSS
9 C
10 Objective-C
11 Perl
11 Shell

I'm not sure about Ruby, and I don't think CSS has a concept of
boolean arithmetic, but ten languages outrank shell scripting (Perl is
tied) and of them eight (maybe nine) use 0/1. Using langpop.com stats,
shell scripting comse up rather higher, but it's still beaten out -
and by considerable margins - by C, Java, PHP, JavaScript, C++, and
Python, all of which use 0/1. The Tiobe index seems to split up
several shells, which penalizes them severely (Bourne shell and bash
both come up in the 51-100 range), but even if they were merged,
they're unlikely to be able to nudge out the top five of Java, C, C++,
Objective-C, and C#. So while it's clearly false to state that 0/1 is
the _only_ convention in use today, it's fairly justifiably the _most
common_.

And of course, there are plenty of historical systems that were
different, as have been mentioned. But most programmers aren't going
to come across those... I hope!

ChrisA

[1] You'd also have to be insane. A bash script should not, in my
opinion, exceed about a page or two of code. I'm not sure how large a
bash script has to be before it collapses under its own gravity and
forms a black hole out of which no comprehension or sanity can escape,
but I'm taking no chances.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Lossless bulletproof conversion to unicode (backslashing) (fwd)

2015-05-29 Thread Ian Kelly
On Fri, May 29, 2015 at 4:44 AM, Jon Ribbens
 wrote:
> On 2015-05-29, Ian Kelly  wrote:
>> On Fri, May 29, 2015 at 2:05 AM, anatoly techtonik  
>> wrote:
>>> Added Mailman to my suxx tracker:
>>> https://github.com/techtonik/suxx-tracker#mailman
>>
>> What a useless tool. Instead of tiredly complaining that things suck,
>> why not take some initiative to make them better?
>>
>> I'm curious about your complaint about virtualenv. How do you envision
>> that "logging in" to the env would be any different from activating
>> it?
>
> Please Do Not Feed The Troll.

It's not a troll if the discussion is potentially useful and not just
disruptive.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OpenCV with Python (cv or cv2)

2015-05-29 Thread Chris Angelico
On Sat, May 30, 2015 at 12:29 AM, Markos  wrote:
> the simplest way to install opencv in jessie is:
>
> apt-get install python-dev libopencv-opencv
>
> And from what I saw the opencv package available in the repository is 2.4.9
>
> https://packages.debian.org/jessie/python-opencv
>
> And from what I saw on the site:
>
> https://packages.debian.org/jessie/python3
> and
> https://packages.debian.org/jessie/python
>
> There are packages in the repository for python 3.4.2-2 and 2.7.9-1
>
> My doubt is which version of Python (3.4.2-2 or 2.7.9-1) is compatible with
> the opencv library 2.4.9 available in the repository?

Since it's managed by the Debian repo, you can simply look at its
dependencies. In this case, python-opencv is built for Python 2, not
Python 3, so it'll pull in Python 2.7.9-1. Unfortunately there isn't a
corresponding python3-opencv package, so I don't know how hard it
would be to install for Python 3.4.2; but personally, I'd just try
using pip to install it.

$ apt-cache show python-opencv
Version: 2.4.9.1+dfsg-1+b1
Depends: python (<< 2.8), python:any (>= 2.7.5-5~), python (>= 2.7~),
libc6 (>= 2.14), libgcc1 (>= 1:4.1.1), libopencv-calib3d2.4,
libopencv-contrib2.4, libopencv-core2.4, libopencv-features2d2.4,
libopencv-flann2.4, libopencv-highgui2.4, libopencv-imgproc2.4,
libopencv-legacy2.4, libopencv-ml2.4, libopencv-objdetect2.4,
libopencv-photo2.4, libopencv-video2.4, libpython2.7 (>= 2.7),
libstdc++6 (>= 4.1.1), python-numpy-abi9, python-numpy (>= 1:1.6.1)

If you simply "apt-get install python-opencv", it'll make sure you
have the right Python installed.

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


Re: Fixing Python install on the Mac after running 'CleanMyMac'

2015-05-29 Thread William Ray Wing

> On May 29, 2015, at 9:12 AM, Cem Karan  wrote:
> 
> 
> On May 28, 2015, at 11:47 PM, Laura Creighton  wrote:
> 
>> webmas...@python.org just got some mail from some poor embarrased
>> soul who ran this program and broke their Python install.
>> 
>> They are running Mac OSX 10.7.5
>> 
>> They are getting:
>> 
>>Utility has encountered a fatal error, and will now terminate.  A
>>Python runtime could not be located. You may need to install a
>>framework build of Python or edit the PyRuntimeLocations array in this
>>applications info.plist file.  Then there are two oblong circles. One
>>says Open Console. The other says Terminate.
>> 
>> So https://docs.python.org/2/using/mac.html says:
>> 
>>  The Apple-provided build of Python is installed in
>>  /System/Library/Frameworks/Python.framework and /usr/bin/python,
>>  respectively. You should never modify or delete these, as they are
>>  Apple-controlled and are used by Apple- or third-party software.
>> 
>> So, I assume this poor soul has done precisely that.
>> 
>> What do I tell her to do now?

As a minor addendum - you can point out that “Clean My Mac” is a well-known 
piece of crap-ware that is so badly written as to be labeled by most people as 
malware.  Best possible solution would be a clean boot and restore from a 
recent clone (either CarbonCopy Cloner or SuperDuper) followed by a restore of 
intervening files from Time Machine.  Failing that, Cem’s suggestions are good.

-Bill

> 
> Does she have a recent Time Machine backup that she can restore from?  
> Otherwise the solutions are all fairly painful:
> 
> 1) Install Python 2.7 from scratch (easy).  Then figure out where to put 
> symlinks that point back to the install (mildly annoying/hard).  Note that 
> Python 3 won't work; none of the built-in scripts expect it.
> 
> 2) OS X recovery - 
> http://www.macworld.co.uk/how-to/mac/how-reinstall-mac-os-x-using-internet-recovery-3593641/
>  I've never had to do that, so I have no idea how easy/reliable it is.  I 
> **think** its supposed to save all the data on the drive, but again, I've not 
> done this, so I can't make any guarantees.
> 
> 3) Wipe it clean and reinstall from scratch.
> 
> Honestly, I hope she has a time machine backup.  I've had to do recoveries a 
> couple of times, and it can really save you.
> 
> Good luck,
> Cem Karan
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re:

2015-05-29 Thread Mario R. Osorio
?Quien es Usted y por que pregunta?


Dtb/Gby
===
Mario R. Osorio

“If I had asked people what they wanted, they would have said faster
horses.”
 ― Henry Ford



On Fri, May 29, 2015 at 1:33 AM, Laura Creighton  wrote:

> Sabe usted acerca de estas páginas?
> https://mail.python.org/mailman/listinfo/python-es
> https://wiki.python.org/moin/SpanishLanguage
>
> Laura
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


What is considered an "advanced" topic in Python?

2015-05-29 Thread Mike Driscoll
Hi,

I've been asked on several occasions to write about intermediate or advanced 
topics in Python and I was wondering what the community considers to be 
"intermediate" or "advanced". I realize we're all growing in our abilities with 
the language, so this is going to be very subjective, but I am still curious 
what my fellow Python developers think about this topic.

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


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Joel Goldstick
Maybe itertools or generators

On Fri, May 29, 2015 at 12:01 PM, Mike Driscoll  wrote:
> Hi,
>
> I've been asked on several occasions to write about intermediate or advanced 
> topics in Python and I was wondering what the community considers to be 
> "intermediate" or "advanced". I realize we're all growing in our abilities 
> with the language, so this is going to be very subjective, but I am still 
> curious what my fellow Python developers think about this topic.
>
> Thanks,
> Mike
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Chris Angelico
On Sat, May 30, 2015 at 2:01 AM, Mike Driscoll  wrote:
> I've been asked on several occasions to write about intermediate or advanced 
> topics in Python and I was wondering what the community considers to be 
> "intermediate" or "advanced". I realize we're all growing in our abilities 
> with the language, so this is going to be very subjective, but I am still 
> curious what my fellow Python developers think about this topic.
>

Good fun! A few ideas:

How to write decorators, particularly those that take parameters.

The differences between the various number types (int, float, complex,
Fraction, Decimal) and when you'd want each one.

(CPython-specific) The dis.dis() function and what it can tell you
about how Python operates

These are all topics that have come up with my students; they're
advanced enough to be outside the scope of the course itself (the
course _uses_ decorators, but doesn't explain how to actually build
them), but not beyond the grasp of someone who's mastered Python's
fundamentals.

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


Re: Fixing Python install on the Mac after running 'CleanMyMac'

2015-05-29 Thread Ned Deily
In article <201505290959.t4t9xpdk016...@fido.openend.se>,
 Laura Creighton  wrote:
> I asked her to come here, but I fear she is feeling a tad too
> embarassed to do that right now.  I don't know how to find out
> the name of the Utility -- the Error message really does say
> 'Utility' -- with no name for it.  Apparantly there is some log
> file you can go take a look at to find out, but I don't know
> what it is ...

Well, she could just download a current Python 2.7.x for OS X from 
python.org, install it, and see if that solves the problem.  That would 
be likely the easiest thing to do and is unlikely to make matters worse.  
If that doesn't work, restoring files from a backup would be in order, 
again most likely /Library/Frameworks/Python.framework/*.  As others 
have noted, running third-party apps like CleanMyMac is probably not a 
good idea, but, even if it is as crappy as its sounds, I would think it 
unlikely that it would be fooling with the Apple-supplied system Python 
in /System/Library/Frameworks.  If it did though, then the safest 
approach is to do a full Time Machine or other backup and restore the 
base system from the recovery partition and use the Migration Assistant 
to restore user files and settings from the backup.  But that's a very 
long and somewhat risky process so should only be done as a last resort.

https://support.apple.com/en-us/HT201314

-- 
 Ned Deily,
 n...@acm.org

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


Re: Is it possible to find python34.lib from within Python?

2015-05-29 Thread Ned Deily
In article <68710660-0f24-403a-8c3d-996c06a26...@googlegroups.com>,
 Paul  Moore  wrote:
> I want to set up a script to build some C code. I need to link it with 
> python34.lib, but I'm not sure how to locate that file without hard-coding 
> it.
[...]

If you are embedding Python, refer to the "Extending and Embedding" 
document in the Python documentation set and the description of 
python-config:

https://docs.python.org/3/extending/embedding.html#compiling-and-linking-
under-unix-like-systems

(Of course, if you are extending Python, Distutils should provide all 
the necessary flags.)

-- 
 Ned Deily,
 n...@acm.org

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


Re: Accessing DataSocket Server with Python

2015-05-29 Thread Grant Edwards
On 2015-05-29, William Ray Wing  wrote:

> While that’s certainly possible in a routed network (and even then
> can be overridden with the “do not fragment” bit), it won’t happen in
> a LAN or self-contained instrument set-up.

You don't know that.

> These days, even routed networks tend to deliver anything less than a
> 1500 byte packet as a single entity.

Doesn't matter.

It can still happen in the network stack on either end.  If you
quickly call send() which small amounts of data, it's quite possible
that the network stack will combine them into a single packet.  Under
some conditions this is done intentionally to reduce the overall
network overhead.

On the receiving end, if several small packets are received between
calls to recv(), then a single call to recv() will return data from
multiple packets.

> With fiber backbones and high-speed LANs, it is more work for a
> router to fragment a packet then to simply pass it on.  The days of
> 480 byte packets pretty much went away with dial-up modems.

But modern TCP/IP stacks will still combine packets to save on network
overhead.

If you assume TCP read/write operations are atomic and "message"
boundaries are preserved, your code is wrong.  It will eventually
fail.  Period.

-- 
Grant Edwards   grant.b.edwardsYow! Inside, I'm already
  at   SOBBING!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Skip Montanaro
On Fri, May 29, 2015 at 11:01 AM, Mike Driscoll  wrote:
> ... I was wondering what the community considers to be "intermediate" or
"advanced".

Just about any topic on which Dave Beazley has given a keynote talk
.
:-)

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


Re: Accessing DataSocket Server with Python

2015-05-29 Thread Chris Angelico
On Sat, May 30, 2015 at 2:29 AM, Grant Edwards  wrote:
> If you assume TCP read/write operations are atomic and "message"
> boundaries are preserved, your code is wrong.  It will eventually
> fail.  Period.

Indeed. That said, though, if your writes are all smaller than one
packet, and you perfectly alternate a write and a read, a write and a
read, at both ends, then you can go a very long way without ever
running into this. In that case, you could have proper parsing and
buffering as a failure case, with the normal case expecting a
termination mark at the end of the socket-read - something like this:

write(query)
data = read(as_much_as_possible)
if data[-1] != "\n":
# Huh, stuff got split.
while True:
more_data = read(as_much_as_possible)
data += moredata
if data[-1] == "\n": break
cope_with_possibility_of(socket_disconnection)
handle_response(data)

Alternating writes and reads ensures that two messages can't be
combined, and if a single message fits inside a packet, it'll usually
be sent that way. But you still can't guarantee that.

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


Re: Fixing Python install on the Mac after running 'CleanMyMac'

2015-05-29 Thread Skip Montanaro
On Fri, May 29, 2015 at 11:11 AM, Ned Deily  wrote:

> Well, she could just download a current Python 2.7.x for OS X from
> python.org, install it, and see if that solves the problem.  That would
> be likely the easiest thing to do and is unlikely to make matters worse.
>

Might that appear to work at first, but leave some subtle issues which are
not at first apparent? I don't know how intertwined Apple's Python instance
is in the day-to-day operation of the operating system (it certainly seems
to be on some Linux distros), but it's possible that some Apple-specific
package isn't available at part of the stock Python 2.7 distribution.

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


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Chris Angelico
On Sat, May 30, 2015 at 2:39 AM, Skip Montanaro
 wrote:
> On Fri, May 29, 2015 at 11:01 AM, Mike Driscoll  wrote:
>> ... I was wondering what the community considers to be "intermediate" or
>> "advanced".
>
> Just about any topic on which Dave Beazley has given a keynote talk. :-)

Hehe. First hit is this one, with its awesome slide...

https://youtu.be/l_HBRhcgeuQ?t=3m34s

I showed that to my parents and siblings, most of whom are not
particularly adept with Python, and they found it highly amusing. As a
participant in python-ideas, I found it hilarious... and absolutely
right.

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


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Mike Driscoll
On Friday, May 29, 2015 at 11:08:19 AM UTC-5, Joel Goldstick wrote:
> Maybe itertools or generators
> 

Yeah, I was thinking along those lines. I was also thinking about some of the 
cool stuff in the collections and contextlib modules.

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


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Mike Driscoll

> 
> Good fun! A few ideas:
> 
> How to write decorators, particularly those that take parameters.


Yes, this one always seems to trip people up.


> 
> The differences between the various number types (int, float, complex,
> Fraction, Decimal) and when you'd want each one.

I hadn't considered this one


> 
> (CPython-specific) The dis.dis() function and what it can tell you
> about how Python operates

I remember seeing on PyMOTW - http://pymotw.com/2/dis/  I agree that it's a 
module most programmers don't know about.


> 
> These are all topics that have come up with my students; they're
> advanced enough to be outside the scope of the course itself (the
> course _uses_ decorators, but doesn't explain how to actually build
> them), but not beyond the grasp of someone who's mastered Python's
> fundamentals.
> 
> ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Accessing DataSocket Server with Python

2015-05-29 Thread Grant Edwards
On 2015-05-29, Chris Angelico  wrote:
> On Sat, May 30, 2015 at 2:29 AM, Grant Edwards  
> wrote:
>
>> If you assume TCP read/write operations are atomic and "message"
>> boundaries are preserved, your code is wrong.  It will eventually
>> fail.  Period.
>
> Indeed. That said, though, if your writes are all smaller than one
> packet, and you perfectly alternate a write and a read, a write and a
> read, at both ends, then you can go a very long way without ever
> running into this.

That's true.  You probably won't see a failure until you do something
like run through some sort of WAN connection (satellite and PPP links
are excellent for exposing bad network code), or somebody configures a
switch, router, or IP interface in a goofy (but entire valid) way, or
somebody changes the app such that it writes more than 1500 bytes, or
it violates the strict alternation of reads/writes.

But someday, somehow, (IME) one of those always happens. And whoever
has to fix it will wish bad things upon you and your descendants.

I've lost count of the times I've had to fix somebody else's code that
broke because they assumed TCP was a datagram service rather than a
byte-stream service.

-- 
Grant Edwards   grant.b.edwardsYow! UH-OH!!  I put on
  at   "GREAT HEAD-ON TRAIN
  gmail.comCOLLISIONS of the 50's"
   by mistake!!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Mike Driscoll
On Friday, May 29, 2015 at 11:40:11 AM UTC-5, Skip Montanaro wrote:
> On Fri, May 29, 2015 at 11:01 AM, Mike Driscoll  wrote:
> > ... I was wondering what the community considers to be "intermediate" or 
> > "advanced".
> 
> Just about any topic on which Dave Beazley has given a keynote talk. :-)
> 
> 
> Skip

I've always enjoyed reading Beazley's blog...and his presentations are always 
neat too. Good idea. 

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


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Todd
On Fri, May 29, 2015 at 7:02 PM, Todd  wrote:

> On Fri, May 29, 2015 at 6:01 PM, Mike Driscoll  wrote:
>
>> Hi,
>>
>> I've been asked on several occasions to write about intermediate or
>> advanced topics in Python and I was wondering what the community considers
>> to be "intermediate" or "advanced". I realize we're all growing in our
>> abilities with the language, so this is going to be very subjective, but I
>> am still curious what my fellow Python developers think about this topic.
>>
>> Thanks,
>> Mike
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
> The ast module and AST hacking
> The dist module and understanding the interpreter.
> Code objects
>

Sorry, miss-typed. I meant the "dis" module, not the "dist" module.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Todd
On Fri, May 29, 2015 at 6:01 PM, Mike Driscoll  wrote:

> Hi,
>
> I've been asked on several occasions to write about intermediate or
> advanced topics in Python and I was wondering what the community considers
> to be "intermediate" or "advanced". I realize we're all growing in our
> abilities with the language, so this is going to be very subjective, but I
> am still curious what my fellow Python developers think about this topic.
>
> Thanks,
> Mike
> --
> https://mail.python.org/mailman/listinfo/python-list
>

The ast module and AST hacking
The dist module and understanding the interpreter.
Code objects
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread sohcahtoa82
On Friday, May 29, 2015 at 9:02:06 AM UTC-7, Mike Driscoll wrote:
> Hi,
> 
> I've been asked on several occasions to write about intermediate or advanced 
> topics in Python and I was wondering what the community considers to be 
> "intermediate" or "advanced". I realize we're all growing in our abilities 
> with the language, so this is going to be very subjective, but I am still 
> curious what my fellow Python developers think about this topic.
> 
> Thanks,
> Mike

Metaclasses.

I've read about them.  I still don't understand them, why you would want them, 
and what you gain from them.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Chris Angelico
On Sat, May 30, 2015 at 2:57 AM, Mike Driscoll  wrote:
>>
>> Good fun! A few ideas:
>>
>> How to write decorators, particularly those that take parameters.
>
> Yes, this one always seems to trip people up.

It's like a Sherlock Holmes pronouncement. When you see something like
Flask's app.route(), or functools.wraps(), it's pure magic and
completely incomprehensible. But break it down into little pieces (a
function that takes a function and returns a function, then decorator
syntax, then closures and the ability to call the original, and
finally a decorator factory function, which is what a parameterized
decorator is), and it becomes elementary.

>> The differences between the various number types (int, float, complex,
>> Fraction, Decimal) and when you'd want each one.
>
> I hadn't considered this one

It's not often an actual *problem* - I've never seen anyone pick the
wrong data type and mess up their code, not in Python - but it's a
great way to explore some of the differences between real numbers and
what computers work with. Also, I like talking about Fraction and
Decimal for the simple reason that they're unobvious; you can poke
around with Python and discover int and float, and if ever you need
imaginary/complex numbers, you'll quickly come across complex, but you
might use Python for years and not realize that decimal.Decimal even
exists - nor when you'd want it.

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


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Ethan Furman

On 05/29/2015 10:03 AM, sohcahto...@gmail.com wrote:

On Friday, May 29, 2015 at 9:02:06 AM UTC-7, Mike Driscoll wrote:



I've been asked on several occasions to write about intermediate or advanced 
topics
 in Python and I was wondering what the community considers to be 
"intermediate" or
 "advanced". I realize we're all growing in our abilities with the language, so 
this
 is going to be very subjective, but I am still curious what my fellow Python
 developers think about this topic.


Metaclasses.

I've read about them.  I still don't understand them, why you would want them, 
and what you gain from them.


Metaclasses change the way a class behaves.

For example, the new (in 3.4) Enum class uses a metaclass.

  class SomeEnum(Enum):
 first = 1
 second = 2
 third = 3

The metaclass changes normal class behavior to:

  - support iterating: list(SomeEnum) --> [SomeEnum.first, SomeEnum.second, 
SomeEnum.third]
  - support a length:  len(SomeEnum) --> 3
  - not allow new instances to be created:  --> SomeEnum(1) is SomeEnum(1)  # 
True

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


Re: Accessing DataSocket Server with Python

2015-05-29 Thread Marko Rauhamaa
Chris Angelico :

> Indeed. That said, though, if your writes are all smaller than one
> packet, and you perfectly alternate a write and a read, a write and a
> read, at both ends, then you can go a very long way without ever
> running into this.

Rare errors are worse than consistent errors.

TCP streams are intercepted by address translators, load balancers,
proxies, protocol translators and what not. They will eagerly take
advantage of the fact that TCP is a full-duplex octet stream.

Also, programs could be plugged into other types of octet stream with
other stream chopping characteristics.

Finally, the MTU size is very unpredictable. You have all kinds of
encapsulation (6to4, VPN, VLAN, tunneling etc) that make it difficult to
be sure about what's a "small" write.

What's more, you should be on the lookout for partial writes not block
until they finish. Typically, it is not enough to rely on TCP's flow
control but also impose a separate application-level, end-to-end flow
control to avoid deadlocks on the one hand and buffer overflows on the
other hand.


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


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Marko Rauhamaa
sohcahto...@gmail.com:

> Metaclasses.
>
> I've read about them. I still don't understand them, why you would
> want them, and what you gain from them.

I don't think you would ever want them.


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


Re: Fixing Python install on the Mac after running 'CleanMyMac'

2015-05-29 Thread Ned Deily
In article 
,
 Skip Montanaro  wrote:

> On Fri, May 29, 2015 at 11:11 AM, Ned Deily  wrote:
> 
> > Well, she could just download a current Python 2.7.x for OS X from
> > python.org, install it, and see if that solves the problem.  That would
> > be likely the easiest thing to do and is unlikely to make matters worse.
> >
> 
> Might that appear to work at first, but leave some subtle issues which are
> not at first apparent? I don't know how intertwined Apple's Python instance
> is in the day-to-day operation of the operating system (it certainly seems
> to be on some Linux distros), but it's possible that some Apple-specific
> package isn't available at part of the stock Python 2.7 distribution.

Installing a python.org Python (/usr/local/bin/python*) is independent 
of and does not interfere with use of the Apple-supplied system Pythons 
(/usr/bin/python*).  Apple does ship various third-party Python packages 
("distributions") with its system Python, like numpy, but they tend to 
be old and outdated versions and there are a few Apple-only packages.  
But, should that issue arise, that can be resolved by choosing the right 
path (/usr/local/bin vs /usr/bin) or removing /usr/local/bin from $PATH.

The thing is the original message in this thread had this:
> They are getting:
>  Utility has encountered a fatal error, and will now terminate.  A
>  Python runtime could not be located. You may need to install a
>  framework build of Python or edit the PyRuntimeLocations array in this
>  applications info.plist file.  Then there are two oblong circles. One
>  says Open Console. The other says Terminate.

But ... I just did what I should have done earlier: googled for that 
message.  And I find that the message is coming from a py2app-built 
application (and it seems I answered the question 3 years ago!):

http://stackoverflow.com/questions/10184974/py2app-is-not-copying-the-pyt
hon-framework-to-the-new-app-while-using-virutalenv

The py2app glue code could be looking for Pythons in various spots 
including the system Python.  So, let's make sure the system Python is 
still working.  On the most up-to-date 10.7 Lion system (10.7.5), typing 
the following two commands should give results the same as those shown 
(->):

/usr/bin/python2.7 -c 'import sys;print(sys.version)'
-> 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
-> [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]

/usr/bin/python2.7 -c 'import numpy;print(numpy.__file__)'
-> 
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/pytho
n/numpy/__init__.py

If not, then it really may be necessary to restore system files which, 
as I noted before, is most safely and accurately done by following 
Apple's directions to restore the system from the recovery partition and 
a good backup of user files.

-- 
 Ned Deily,
 n...@acm.org

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


Re: Fixing Python install on the Mac after running 'CleanMyMac'

2015-05-29 Thread MrJean1
FWIW, I recently upgraded an older MacBook to Mac OS X 10.7.5 and there are 3 
different versions of Python in /System/Library/Frameworks/Python.framework, 
see:

$ ls /System/Library/Frameworks/Python.framework/Versions/
2.5 2.6 2.7 Current


It is unclear whether MacOS X 10.7.5 installed all four of these Python 
versions.  The older one(s) may be left over from the previous MacOS X release 
on the machine.  But all are Apple builds of the Python version, for example:

$ python2.7
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D


In addition, there is a link in /usr/bin to the python2.X, pythonw2.X and 
python2.X-config file for each version, see

$ ls -la /usr/bin/python*
-rwxr-xr-x  2 root  wheel  62752 May 21 19:06 /usr/bin/python
-rwxr-xr-x  6 root  wheel925 May 21 19:06 /usr/bin/python-config
lrwxr-xr-x  1 root  wheel 75 May 21 19:06 /usr/bin/python2.5 -> 
../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
lrwxr-xr-x  1 root  wheel 82 May 21 19:06 /usr/bin/python2.5-config -> 
../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
lrwxr-xr-x  1 root  wheel 75 May 21 19:06 /usr/bin/python2.6 -> 
../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x  1 root  wheel 82 May 21 19:06 /usr/bin/python2.6-config -> 
../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
lrwxr-xr-x  1 root  wheel 75 May 21 19:06 /usr/bin/python2.7 -> 
../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x  1 root  wheel 82 May 21 19:06 /usr/bin/python2.7-config -> 
../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x  2 root  wheel  62752 May 21 19:06 /usr/bin/pythonw
lrwxr-xr-x  1 root  wheel 76 May 21 19:06 /usr/bin/pythonw2.5 -> 
../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5
lrwxr-xr-x  1 root  wheel 76 May 21 19:06 /usr/bin/pythonw2.6 -> 
../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6
lrwxr-xr-x  1 root  wheel 76 May 21 19:06 /usr/bin/pythonw2.7 -> 
../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7


Perhaps you can reinstall these Pythons from the CD which came with the Mac.  
Let me know if you need  more info.

/Jean




On Thursday, May 28, 2015 at 11:47:52 PM UTC-4, Laura Creighton wrote:
> webmas...@python.org just got some mail from some poor embarrased
> soul who ran this program and broke their Python install.
> 
> They are running Mac OSX 10.7.5
> 
> They are getting:
> 
>  Utility has encountered a fatal error, and will now terminate.  A
>  Python runtime could not be located. You may need to install a
>  framework build of Python or edit the PyRuntimeLocations array in this
>  applications info.plist file.  Then there are two oblong circles. One
>  says Open Console. The other says Terminate.
> 
> So https://docs.python.org/2/using/mac.html says:
> 
>The Apple-provided build of Python is installed in
>/System/Library/Frameworks/Python.framework and /usr/bin/python,
>respectively. You should never modify or delete these, as they are
>Apple-controlled and are used by Apple- or third-party software.
> 
> So, I assume this poor soul has done precisely that.
> 
> What do I tell her to do now?
> 
> Laura
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Steven D'Aprano
On Sat, 30 May 2015 02:01 am, Mike Driscoll wrote:

> Hi,
> 
> I've been asked on several occasions to write about intermediate or
> advanced topics in Python and I was wondering what the community considers
> to be "intermediate" or "advanced". I realize we're all growing in our
> abilities with the language, so this is going to be very subjective, but I
> am still curious what my fellow Python developers think about this topic.


I would consider these advanced topics:


Metaclasses.
Descriptors.
Futures.
Asynchronous processing, including multiprocessing and threads.
Writing C or Fortran extensions.
Function/code object internals.
Byte-code hacking.
Manipulating ASTs.
OS-specific features like the os.exec* functions, os.fork, daemons, etc.
Multiple inheritance, mixins, traits, etc.
Coroutines.
Dynamic programming.
Neural nets.
Distributed processing, including remote procedure calls.
Fuzz testing.


I would consider these intermediate topics:


Closures.
Using classes and functions as first-class values.
Second-order functions.
Decorators.
Functional idioms (map, filter, reduce).
Viewing byte-code using the dis module.
Unicode, code pages, codecs and encodings.
Regular expressions.
SQL and dealing with databases.
The complexities of floating point, including Decimal.
Writing your own context managers.
Generators and iterators.
Unit testing, doctests, etc.
Code generation and metaprogramming.
Writing your own classes.
State machines.
The structure of URLs (they're more than just "http://blahblah.com";).
Anything to do with HTTP (client or server).
Commandline argument processing (argparse, optparse, etc.)

Some of the intermediate topics start at an intermediate level, but can go
on to include more advanced uses.



-- 
Steven

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


Re: Fixing Python install on the Mac after running 'CleanMyMac'

2015-05-29 Thread Ned Deily
In article ,
 MrJean1  wrote:
> FWIW, I recently upgraded an older MacBook to Mac OS X 10.7.5 and there are 3 
> different versions of Python in /System/Library/Frameworks/Python.framework, 
> see:
> 
> $ ls /System/Library/Frameworks/Python.framework/Versions/
> 2.5   2.6 2.7 Current
> > 
> It is unclear whether MacOS X 10.7.5 installed all four of these Python 
> versions.  The older one(s) may be left over from the previous MacOS X 
> release on the machine

For compatibility with applications linked on older OS X releases, Apple 
customarily ships more than one version of Python frameworks with OS X.  
There are actually three versions of the system Python frameworks there: 
you should see that "Current" is actually a symbolic link to "2.7".  All 
of those versions are shipped as part of OS X 10.7.

-- 
 Ned Deily,
 n...@acm.org

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


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Paul Rubin
Chris Angelico  writes:
> Looks to me as if Lua doesn't have integers at all

They fixed that in Lua 5.3:

  http://www.lua.org/manual/5.3/readme.html#changes

> Likewise, eight-bit strings, not Unicode. 

Also fixed in 5.3 (basic utf-8 support added, per above).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Paul Rubin
Chris Angelico  writes:
>> It doesn't add much to your application to embed Lua
> Lua's a much weaker language than Python is, though.  Can it handle
> arbitrary-precision integers? Unicode? Dare I even ask,
> arbitrary-precision rationals (fractions.Fraction)? Security comes at
> a price, I guess.

The language features are an orthogonal issue to embeddability.  Lua is
easier to embed securely because its embedding interface was designed
for that.  It's also easy to call C functions from Lua, so if you want
arbitrary precision integers or rationals, you can link GMP into your
application use it from your Lua scripts.  

As another example, Javascript is as powerful as Python (though worse in
many ways due to misdesign), but also by now supports reasonably secure
embedding (or else it wouldn't be usable in browsers).

See
http://lucumr.pocoo.org/2014/8/16/the-python-i-would-like-to-see/#the-damn-interpreter
for Armin Ronacher's comments on CPython's not-so-great embedding
interface.  The interface he contrasts it with is essentially how Lua
and Javascript (at least in some implementations) work.  I haven't
looked at MicroPython or PyPy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fixing Python install on the Mac after running 'CleanMyMac'

2015-05-29 Thread MrJean1
Correct, the "Current" version is just a link to "2.7".  Also, the binaries 
'/usr/bin/python{,w}" seem to be copies of the 
"/System/Library/.../Versions/2.7/bin/python{,w}" files.

/Jean


On Friday, May 29, 2015 at 2:01:05 PM UTC-4, Ned Deily wrote:
> In article ,
>  MrJean1  wrote:
> > FWIW, I recently upgraded an older MacBook to Mac OS X 10.7.5 and there are 
> > 3 
> > different versions of Python in 
> > /System/Library/Frameworks/Python.framework, 
> > see:
> > 
> > $ ls /System/Library/Frameworks/Python.framework/Versions/
> > 2.5 2.6 2.7 Current
> > > 
> > It is unclear whether MacOS X 10.7.5 installed all four of these Python 
> > versions.  The older one(s) may be left over from the previous MacOS X 
> > release on the machine
> 
> For compatibility with applications linked on older OS X releases, Apple 
> customarily ships more than one version of Python frameworks with OS X.  
> There are actually three versions of the system Python frameworks there: 
> you should see that "Current" is actually a symbolic link to "2.7".  All 
> of those versions are shipped as part of OS X 10.7.
> 
> -- 
>  Ned Deily,
>  n...@acm.org

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


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Marko Rauhamaa
Paul Rubin :

> The language features are an orthogonal issue to embeddability.

I doubt that. Guile is designed for embedding but it is a full-fledged
Scheme implementation.

> Lua is easier to embed securely because its embedding interface was
> designed for that.

I have very little experience with Lua. What surprises me is that it is
not as elementary as it could be: I don't really see the value of
metatables and weak tables.


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


Re: Fixing Python install on the Mac after running 'CleanMyMac'

2015-05-29 Thread random832
On Fri, May 29, 2015, at 12:11, Ned Deily wrote:
> As others 
> have noted, running third-party apps like CleanMyMac is probably not a 
> good idea, but, even if it is as crappy as its sounds, I would think it 
> unlikely that it would be fooling with the Apple-supplied system Python 
> in /System/Library/Frameworks. 

It sounds very likely to me. These "cleaner" apps are often designed to
remove "unnecessary" system components where the author doesn't know
what they are and doesn't think anyone needs them because his system
runs fine without it, along with the mistaken belief that these take up
a lot of space or that their existence slows down performance.

Looking at the version history of this page:
https://software.com/mac/utilities/cleanmymac/1.10.0

It looks like python is removed or otherwise messed-with by a module
called "System Junk" (earlier "Development Junk").

Version 1.9.4 _claims_ that it fixed: ""Sytem Junk" module reliability
improved and fixed issues with python applications." - but this is
basically an admission that it was messing with the sort of thing that
could cause these issues in the first place.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fixing Python install on the Mac after running 'CleanMyMac' (fwd)

2015-05-29 Thread Laura Creighton
Good news, we are getting closer to understanding what to do.
This in from Ned.  I will continue after the message:

--- Forwarded Message

Return-Path: 
From: Ned Deily 
Subject: Re: Fixing Python install on the Mac after running 'CleanMyMac'
Date: Fri, 29 May 2015 10:28:19 -0700
Lines: 63

> Might that appear to work at first, but leave some subtle issues which are
> not at first apparent? I don't know how intertwined Apple's Python instance
> is in the day-to-day operation of the operating system (it certainly seems
> to be on some Linux distros), but it's possible that some Apple-specific
> package isn't available at part of the stock Python 2.7 distribution.

Installing a python.org Python (/usr/local/bin/python*) is independent 
of and does not interfere with use of the Apple-supplied system Pythons 
(/usr/bin/python*).  Apple does ship various third-party Python packages 
("distributions") with its system Python, like numpy, but they tend to 
be old and outdated versions and there are a few Apple-only packages.  
But, should that issue arise, that can be resolved by choosing the right 
path (/usr/local/bin vs /usr/bin) or removing /usr/local/bin from $PATH.

The thing is the original message in this thread had this:
> They are getting:
>  Utility has encountered a fatal error, and will now terminate.  A
>  Python runtime could not be located. You may need to install a
>  framework build of Python or edit the PyRuntimeLocations array in this
>  applications info.plist file.  Then there are two oblong circles. One
>  says Open Console. The other says Terminate.

But ... I just did what I should have done earlier: googled for that 
message.  And I find that the message is coming from a py2app-built 
application (and it seems I answered the question 3 years ago!):

http://stackoverflow.com/questions/10184974/py2app-is-not-copying-the-pyt
hon-framework-to-the-new-app-while-using-virutalenv

The py2app glue code could be looking for Pythons in various spots 
including the system Python.  So, let's make sure the system Python is 
still working.  On the most up-to-date 10.7 Lion system (10.7.5), typing 
the following two commands should give results the same as those shown 
(->):

/usr/bin/python2.7 -c 'import sys;print(sys.version)'
- -> 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
- -> [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]

/usr/bin/python2.7 -c 'import numpy;print(numpy.__file__)'
- -> 
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/pytho
n/numpy/__init__.py

If not, then it really may be necessary to restore system files which, 
as I noted before, is most safely and accurately done by following 
Apple's directions to restore the system from the recovery partition and 
a good backup of user files.

- -- 
 Ned Deily,
 n...@acm.org

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

--- End of Forwarded Message

So please type

/usr/bin/python2.7 -c 'import sys;print(sys.version)'

and tell me what you get as an answer.

Then type

/usr/bin/python2.7 -c 'import numpy;print(numpy.__file__)'

and again tell me what you get.

But if it isn't as Ned expects, then you may have to go back to
your backups.

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


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Paul Rubin
Marko Rauhamaa  writes:
>> The language features are an orthogonal issue to embeddability.
> I doubt that. Guile is designed for embedding but it is a full-fledged
> Scheme implementation.

Orthogonal means independent, not opposing.

> I have very little experience with Lua. What surprises me is that it is
> not as elementary as it could be: I don't really see the value of
> metatables and weak tables.

It lets you implement various flavors of OOP etc. without different
language mechanisms.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Mike Driscoll
Hi Steven,

On Friday, May 29, 2015 at 12:55:48 PM UTC-5, Steven D'Aprano wrote:
> On Sat, 30 May 2015 02:01 am, Mike Driscoll wrote:
> 
> > Hi,
> > 
> > I've been asked on several occasions to write about intermediate or
> > advanced topics in Python and I was wondering what the community considers
> > to be "intermediate" or "advanced". I realize we're all growing in our
> > abilities with the language, so this is going to be very subjective, but I
> > am still curious what my fellow Python developers think about this topic.
> 
> 
> I would consider these advanced topics:
> 
> 
> Metaclasses.
> Descriptors.
> Futures.
> Asynchronous processing, including multiprocessing and threads.
> Writing C or Fortran extensions.
> Function/code object internals.
> Byte-code hacking.
> Manipulating ASTs.
> OS-specific features like the os.exec* functions, os.fork, daemons, etc.
> Multiple inheritance, mixins, traits, etc.
> Coroutines.
> Dynamic programming.
> Neural nets.
> Distributed processing, including remote procedure calls.
> Fuzz testing.
> 
> 
> I would consider these intermediate topics:
> 
> 
> Closures.
> Using classes and functions as first-class values.
> Second-order functions.
> Decorators.
> Functional idioms (map, filter, reduce).
> Viewing byte-code using the dis module.
> Unicode, code pages, codecs and encodings.
> Regular expressions.
> SQL and dealing with databases.
> The complexities of floating point, including Decimal.
> Writing your own context managers.
> Generators and iterators.
> Unit testing, doctests, etc.
> Code generation and metaprogramming.
> Writing your own classes.
> State machines.
> The structure of URLs (they're more than just "http://blahblah.com";).
> Anything to do with HTTP (client or server).
> Commandline argument processing (argparse, optparse, etc.)
> 
> Some of the intermediate topics start at an intermediate level, but can go
> on to include more advanced uses.
> 
> 
> 
> -- 
> Steven

That's a really good list of topics. Thanks so much for sharing your ideas.

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


Generating list of unique search sub-phrases

2015-05-29 Thread Nick Mellor
Hi all,

My own solution works but I'm sure it could be simpler or read better. How 
would you do it?

Say you've got a list of companies:

Aerosonde Ltd
Amcor
ANCA
Austal Ships
Australia Post
Australian Air Express
Australian Defence Industries
Australian Railroad Group
Australian Submarine Corporation

and you need to extract phrases from the company names that uniquely identify 
that company. The results for the above list of companies should be:

Company: 'Aerosonde Ltd'
 Aliases: Aerosonde,Ltd,Aerosonde Ltd

Company: 'Amcor'
 Aliases: Amcor

Company: 'ANCA'
 Aliases: ANCA

Company: 'Austal Ships'
 Aliases: Austal,Ships,Austal Ships

Company: 'Australia Post'
 Aliases: Post,Australia Post

Company: 'Australian Air Express'
 Aliases: Air,Express,Australian Air,Air Express,Australian Air Express

Company: 'Australian Defence Industries'
 Aliases: Defence,Industries,Australian Defence,Defence Industries,Australian 
Defence Industries

Company: 'Australian Railroad Group'
 Aliases: Railroad,Group,Australian Railroad,Railroad Group,Australian Railroad 
Group

Company: 'Australian Submarine Corporation'
 Aliases: Submarine,Corporation,Australian Submarine,Submarine 
Corporation,Australian Submarine Corporation

Here's my solution:

from itertools import combinations, chain

companies = [
"Aerosonde Ltd",
"Amcor",
"ANCA",
"Austal Ships",
"Australia Post",
"Australian Air Express",
"Australian Defence Industries",
"Australian Railroad Group",
"Australian Submarine Corporation",
]

def flatten(i):
return list(chain.from_iterable(i))

companies_as_text_stream = ' '.join(companies)
for company in companies:
word_combinations = [list(combinations(company.split(), r)) for r in 
range(1, len(company))]
phrases = [' '.join(phrase) for phrase in flatten(word_combinations)]
unique_phrases = [phrase for phrase in phrases if 
companies_as_text_stream.count(phrase) == 1]
aliases = ','.join(unique_phrases)
print("Company: '{0}'\n Aliases: {1}\n".format(company, aliases))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread sohcahtoa82
On Friday, May 29, 2015 at 10:18:29 AM UTC-7, Ethan Furman wrote:
> On 05/29/2015 10:03 AM, sohcahto...@gmail.com wrote:
> > On Friday, May 29, 2015 at 9:02:06 AM UTC-7, Mike Driscoll wrote:
> 
> >> I've been asked on several occasions to write about intermediate or 
> >> advanced topics
> >>  in Python and I was wondering what the community considers to be 
> >> "intermediate" or
> >>  "advanced". I realize we're all growing in our abilities with the 
> >> language, so this
> >>  is going to be very subjective, but I am still curious what my fellow 
> >> Python
> >>  developers think about this topic.
> >
> > Metaclasses.
> >
> > I've read about them.  I still don't understand them, why you would want 
> > them, and what you gain from them.
> 
> Metaclasses change the way a class behaves.
> 
> For example, the new (in 3.4) Enum class uses a metaclass.
> 
>class SomeEnum(Enum):
>   first = 1
>   second = 2
>   third = 3
> 
> The metaclass changes normal class behavior to:
> 
>- support iterating: list(SomeEnum) --> [SomeEnum.first, SomeEnum.second, 
> SomeEnum.third]
>- support a length:  len(SomeEnum) --> 3
>- not allow new instances to be created:  --> SomeEnum(1) is SomeEnum(1)  
> # True
> 
> --
> ~Ethan~

Regarding the first two, you can implement __iter__ and __len__ functions to 
create that functionality, though those functions would operate on an instance 
of the class, not the class itself.

As for the third, can't you override the __new__ function to make attempts to 
create a new instance just return a previously created instance?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Jason Swails
On Fri, May 29, 2015 at 5:06 PM,  wrote:

>
> > For example, the new (in 3.4) Enum class uses a metaclass.
> >
> >class SomeEnum(Enum):
> >   first = 1
> >   second = 2
> >   third = 3
> >
> > The metaclass changes normal class behavior to:
> >
> >- support iterating: list(SomeEnum) --> [SomeEnum.first,
> SomeEnum.second, SomeEnum.third]
> >- support a length:  len(SomeEnum) --> 3
> >- not allow new instances to be created:  --> SomeEnum(1) is
> SomeEnum(1)  # True
> >
> > --
> > ~Ethan~
>
> Regarding the first two, you can implement __iter__ and __len__ functions
> to create that functionality, though those functions would operate on an
> instance of the class, not the class itself.
>
> As for the third, can't you override the __new__ function to make attempts
> to create a new instance just return a previously created instance?
>

​Of course, but with metaclasses you don't *have* to (in fact, that's the
type of thing that the metaclass could do behind the scenes).

​In this case, any Enum subclass should *always* behave as Ethan described
-- without metaclasses that wouldn't necessarily be true (e.g., if the
person creating an Enum subclass didn't bother to correctly implement
__new__, __iter__, and __len__ for their subclass).

By using metaclasses, you can declare an Enum subclass as simply as Ethan
showed, since the metaclass does all of the dirty work implementing the
desired behavior at the time the class object is constructed (subclasses
inherit their parent class's metaclass).

In this use-case, you can think of it as a kind of "implicit class
factory".  Suppose you have a prescription for how you modify a class
definition (i.e., by implementing certain behavior in __new__ or __init__)
that you wrap up into some function "tweak_my_class".  The metaclass would
allow the class definition to be the equivalent of something like:

class MyClass(SubClass):
# whatever

MyClass = tweak_my_class(MyClass)

Or as a class decorator

@tweak_my_class
class MyClass(SubClass):
# whatever

(In fact, the `six` module allows you to implement metaclasses as
decorators to work with both Python 2 and Python 3, but I think metaclasses
are more powerful in Py3 than they are in Py2).​
​
They are cool ideas, and I've used them in my own code, but they do have a
kind of magic-ness to them -- especially in codes that you didn't write but
are working on.  As a result, I've recently started to prefer alternatives,
but in some rare cases (like Enum, for example), they are just the best
solution.

All the best,
Jason
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Ethan Furman

On 05/29/2015 02:06 PM, sohcahto...@gmail.com wrote:

On Friday, May 29, 2015 at 10:18:29 AM UTC-7, Ethan Furman wrote:


Metaclasses change the way a class behaves.

For example, the new (in 3.4) Enum class uses a metaclass.

class SomeEnum(Enum):
   first = 1
   second = 2
   third = 3

The metaclass changes normal class behavior to:

- support iterating: list(SomeEnum) --> [SomeEnum.first, SomeEnum.second, 
SomeEnum.third]
- support a length:  len(SomeEnum) --> 3
- not allow new instances to be created:  --> SomeEnum(1) is SomeEnum(1)  # 
True

--
~Ethan~


Regarding the first two, you can implement __iter__ and __len__ functions to 
create that functionality, though those functions would operate on an instance 
of the class, not the class itself.


Hence the need for a metaclass, as the point is to operate on the class, not 
the instance.


As for the third, can't you override the __new__ function to make attempts to 
create a new instance just return a previously created instance?


Yes.  In the case of Enum, however, it takes any user-defined __new__, which is 
needed for creating the original instances, and replaces it with a __new__ that 
only returns the already defined ones.

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


Re: What is considered an "advanced" topic in Python?

2015-05-29 Thread Ethan Furman

On 05/29/2015 02:28 PM, Jason Swails wrote:


​[...] e.g., if the person creating an Enum subclass didn't bother to correctly
implement [...] __iter__, and __len__ for their subclass


For __iter__ and __len__ to work on the Enum /class/ it must be defined in the 
metaclass.

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


functools.wraps does not play nice with doc tests?

2015-05-29 Thread Vlad
Hello,

So, I know this topic comes up a lot, but I haven't been able to find any 
discussion on this particular twist on the topic. Perhaps someone has some 
insight.

So, I have a function, which is decorated. In order for the doctest test finder 
to find the doc tests in the decorated function, my wrapper needs to use the 
functools.wraps decorator inside it. So far so good. *However*, the issue is 
that if the decorator and the decorated function are defined in different 
modules, and the decorator is defined at a greater line number in its module 
than the decorated function in its module, and the doc test fails, the test 
report lists the failure as occurring at an "unknown line number". This is a 
problem if you have additional logic built on top of the reporting that relies 
on line numbers of test failures (and even more fundamentally, it's a pain to 
manually find which test actually failed). 

Here is a specific example, this is running Python 2.7.9, in case that matters.

File decorator.py
 1  import functools
 2
 3
 4
 5
 6
 7
 8
 9  # The decorator has to be defined at a line number greater than the
10  # decorated function in order to trigger the bug.
11  def decorator(func):
12  @functools.wraps(func)
13  def wrapper(*args, **kwargs):
14  print('In Wrapper!')
15  return func(*args, **kwargs)
16  return wrapper


File decorated.py
 1  from . import decorator
 2
 3
 4  @decorator.decorator
 5  def my_func():
 6  '''
 7  >>> my_func()
 8  '''
 9  print('my_func!')
10
11
12  if __name__ == '__main__':
13  import doctest
14  doctest.testmod()


Now, let's try to run the tests:
> python -m decorated
**
File ".../decorated.py", line ?, in __main__.my_func
Failed example:
my_func()
Expected nothing
Got:
In Wrapper!
my_func!
**
1 items had failures:
   1 of   1 in __main__.my_func
***Test Failed*** 1 failures.


So, the test ran, and failed as we wanted, but the line number was not detected 
correctly. Has anyone run into this issue, and/or know a workaround? Or perhaps 
I am missing something obvious here?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Chris Angelico
On Sat, May 30, 2015 at 4:33 AM, Paul Rubin  wrote:
> Chris Angelico  writes:
>> Looks to me as if Lua doesn't have integers at all
>
> They fixed that in Lua 5.3:
>
>   http://www.lua.org/manual/5.3/readme.html#changes

That's 64-bit integers, not arbitrary-precision, but that's something
at least. You do still need to worry about what happens when your
numbers get too big; in Python, you simply don't. So it's still not
quite there in terms of functionality.

>> Likewise, eight-bit strings, not Unicode.
>
> Also fixed in 5.3 (basic utf-8 support added, per above).

This is definitely NOT what I'm talking about. From what I can see,
5.3 introduces a new library for working with strings of bytes as if
they were UTF-8. That's on par with PHP's Unicode support - basically,
nothing that isn't explicitly coded. It makes Unicode something that
you tack on with resignation, rather than something that's just an
automatic part of text handling. So, a long way from being there in
functionality.

Do you see what I mean about functionality being sacrificed for
security? There is no way that this could be called fully functional
by comparison with Python.

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


Re: Generating list of unique search sub-phrases

2015-05-29 Thread Peter Otten
Nick Mellor wrote:

> Hi all,
> 
> My own solution works but I'm sure it could be simpler or read better. How
> would you do it?
> 
> Say you've got a list of companies:
> 
> Aerosonde Ltd
> Amcor
> ANCA
> Austal Ships
> Australia Post
> Australian Air Express
> Australian Defence Industries
> Australian Railroad Group
> Australian Submarine Corporation
> 
> and you need to extract phrases from the company names that uniquely
> identify that company. The results for the above list of companies should
> be:
> 
> Company: 'Aerosonde Ltd'
>  Aliases: Aerosonde,Ltd,Aerosonde Ltd
> 
> Company: 'Amcor'
>  Aliases: Amcor
> 
> Company: 'ANCA'
>  Aliases: ANCA
> 
> Company: 'Austal Ships'
>  Aliases: Austal,Ships,Austal Ships
> 
> Company: 'Australia Post'
>  Aliases: Post,Australia Post
> 
> Company: 'Australian Air Express'
>  Aliases: Air,Express,Australian Air,Air Express,Australian Air Express
> 
> Company: 'Australian Defence Industries'
>  Aliases: Defence,Industries,Australian Defence,Defence
>  Industries,Australian Defence Industries
> 
> Company: 'Australian Railroad Group'
>  Aliases: Railroad,Group,Australian Railroad,Railroad Group,Australian
>  Railroad Group
> 
> Company: 'Australian Submarine Corporation'
>  Aliases: Submarine,Corporation,Australian Submarine,Submarine
>  Corporation,Australian Submarine Corporation
> 
> Here's my solution:
> 
> from itertools import combinations, chain
> 
> companies = [
> "Aerosonde Ltd",
> "Amcor",
> "ANCA",
> "Austal Ships",
> "Australia Post",
> "Australian Air Express",
> "Australian Defence Industries",
> "Australian Railroad Group",
> "Australian Submarine Corporation",
> ]
> 
> def flatten(i):
> return list(chain.from_iterable(i))
> 
> companies_as_text_stream = ' '.join(companies)
> for company in companies:
> word_combinations = [list(combinations(company.split(), r)) for r
> in range(1, len(company))] phrases = [' '.join(phrase) for phrase
> in flatten(word_combinations)] unique_phrases = [phrase for phrase
> in phrases if companies_as_text_stream.count(phrase) == 1] aliases
> = ','.join(unique_phrases) print("Company: '{0}'\n Aliases:
> {1}\n".format(company, aliases))

Here's an alternative that operates on the words rather than the text:

import itertools
from collections import defaultdict


def adjacent_combinations(words):
words = tuple(words)
for i in range(1, len(words)):
for k in range(len(words) + 1 - i):
yield words[k:k+i]
yield words


def unordered_combinations(words):
for i in range(1, len(words) + 1):
yield from map(frozenset, itertools.combinations(words, i))


def show_aliases(companies, combinations):
combo_to_companies = defaultdict(list)
for company in companies:
for combo in combinations(company.split()):
combo_to_companies[combo].append(company)

company_to_uniquecombos = defaultdict(list)
for combo, candidates in combo_to_companies.items():
if len(candidates) == 1:
company_to_uniquecombos[candidates[0]].append(combo)

for company in companies:
print("Company:", company)
print(
"Aliases:",
", ".join(map(" ".join, company_to_uniquecombos.get(company, 
()
print()


if __name__ == "__main__":
companies = [
"Aerosonde Ltd",
"Amcor",
"ANCA",
"Austal Ships",
"Australia Post",
"Australian Air Express",
"Australian Defence Industries",
"Australian Railroad Group",
"Australian Submarine Corporation",
]
show_aliases(companies, adjacent_combinations)
print("=" * 40)
show_aliases(companies, unordered_combinations)

Note that the result using adjacent_combinations() is similar but not 
identical to the one you asked for as "Australia" is sufficient to identify 
"Australia Post". 

The result based on unordered_combinations() accepts 
"Australian Corporation" to identify the "Australian Submarine Corporation" 
and would fail to find an alias if the list of companies contained items 
that differ only in the order of words.

So: different result and less concise -- what more can you wish for?

How about some nitpicking?

- you can avoid materialising some of the intermediate lists
- you can avoid cross-company matches (think "Express Australian") with an 
out-of-band character

Which gives:

def all_len_combinations(words):
return chain.from_iterable(
combinations(words, r) for r in range(1, len(words) + 1))

companies_as_text_stream = '\0'.join(companies)
for company in companies:
word_combinations = all_len_combinations(company.split())
phrases = (' '.join(phrase) for phrase in word_combinations)
unique_phrases = (phrase for phrase in phrases
  if companies_as_text_stream.count(phrase) == 1)
aliases = ','.join(unique_phrases)
print("Company: '{0}'\n Aliases: {1}\n"

Re: Logic problem: need better logic for desired thruth table.

2015-05-29 Thread M Philbrook
In article <3794b$55678d83$5419aafe$56...@news.ziggo.nl>, skybuck2000
@hotmail.com says...
> 
> Hello,
> 
> I was just coding and ran into a little logic problem which is as follows:
> 
> There are two booleans/variables which can be either false or true.
> 
> The desired thrutle table is:
> 
> A = input
> B = input
> C = output
> 
> A B C:
> ---
> F F T
> F T F
> T F T
> T T T
> 
> Surpisingly enough I don't think there is a casual/common operator for this 
> thruth table.
> 
> AND does not apply.
> OR does not apply.
> XOR does not apply.
> 
> So I would need some combined operators to give the desired result.
> 
> I tried logic below... but funny enough it failed, now I feel like a noob 
> lol and share this funny little fail logic with you.
> 
> Can you improve/fix the logic ?
> 
> This is python code, but this^ logic/thruth table problem basically applies 
> to any programming language:
> 
> # loop has to run if:
> # while DesiredResult==True:
> # Desired truth table for BotWaitForCooldown and CooldownDetected
> # BotWaitForCooldown:  CooldownDetected: Desired Result:
> # False   FalseTrue
> # False   True False
> # True FalseTrue
> # True True True
> # desired/suiting logic:
> # (BotWaitForCooldown or ((not BotWaitForCooldown) and CooldownDetected))
> 
> def TestLogic( BotWaitForCooldown, CooldownDetected ):
> return BotWaitForCooldown or ((not BotWaitForCooldown) and CooldownDetected) 

 First maintain a bit table, something that your code can reference as 
Bools via bit operations..
 In your case it's more less simple..
 
 A combine of 3 bits gives you the value of 7 this this can be used as 
the OR operation
  
 AND operation.
   If value = 7 then.

 OR Operation.

  If Value <> 0 then

 Xor Operation, 
  If Value in [1,2,4] then

 If you need to build the "Value" Product from dangling booleans.

 Value := (Value Shl 1) OR Byte(YourBool); 
 
 Since the compiler only uses the first bit for native booleans this 
works out.
 
 Do the above for all three bools to build a final value..

 Or you can simply mask off a bit as your boolean value from a VALUE
location, which makes it faster in the longrun...

Does that do anything for you ?

Jamie

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


Re: How to do integers to binary lists and back

2015-05-29 Thread John Pote



On 21/05/2015 23:31, MRAB wrote:

On 2015-05-21 23:20, John Pote wrote:

Hi everyone.
I recently had the problem of converting from an integer to its
representation as a list of binary bits, each bit being an integer 1 or
0, and vice versa. E.G.
0x53
becomes
[ 0, 1, 0, 1, 0, 0, 1, 1 ]

This I wanted to do for integers of many tens, if not hundreds, of bits.
Python very nicely expands integers to any size required, great feature.

Just wondered if there was a neat way of doing this without resorting to
a bit bashing loop.

Looking forward to some interesting answers,
John



I don't know how efficient you want it to be, but:

>>> number = 0x53
>>> bin(number)
'0b1010011'
>>> bin(number)[2 : ]
'1010011'
>>> list(map(int, bin(number)[2 : ]))
[1, 0, 1, 0, 0, 1, 1]

Thanks for the replies. Interesting that the offered solutions involve 
converting to a binary text string and then the individual chars back to 
ints. I had thought this would be a route to solve this problem but it 
seemed a bit 'heavy' hence I thought it worthwhile asking the question.


My solution to converting a list of 1s and 0s back to an int is
listLen = len( binList )
n = sum( [ binList[i]*( 2**(listLen-1 - i) ) for i in 
range(listLen)] )


In response to Ben Finney's question, I haven't done homework for 40 
years! Genuine problem, I had decided that the clearest way to write the 
algorithm I was working on was to use lists of 1s and 0s rather than 
normal ints.


Thanks for the help,
John
--
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Paul Rubin
Chris Angelico  writes:
> Do you see what I mean about functionality being sacrificed for
> security? 

No I don't.  Lua has less functionality because it was designed to have
a small embedding footprint.  Python is much bigger because it was
mostly designed to run as a standalone interpreter.  That has nothing to
do with security.  You haven't shown the slightest connection between
Lua's lower functionality and its higher sandbox security, because there
is none.  The lower functionality is because of a totally independent
reason, namely the desire to make the interpreter smaller.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Chris Angelico
On Sat, May 30, 2015 at 11:28 AM, Paul Rubin  wrote:
> Chris Angelico  writes:
>> Do you see what I mean about functionality being sacrificed for
>> security?
>
> No I don't.  Lua has less functionality because it was designed to have
> a small embedding footprint.  Python is much bigger because it was
> mostly designed to run as a standalone interpreter.  That has nothing to
> do with security.  You haven't shown the slightest connection between
> Lua's lower functionality and its higher sandbox security, because there
> is none.  The lower functionality is because of a totally independent
> reason, namely the desire to make the interpreter smaller.

This thread started out as "How can I sandbox Python inside Python?".
One of the responses was "You can't, but try sandboxing Lua inside
Python instead". This has the cost that Lua, unlike Python, simply
lacks features. You can *easily* sandbox something that has very
little functionality - all you have to do is provide a minimalist
"language" that permits only a very few actions, and you know it's
safe. But that security comes at a price.

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


Re: Creating a reliable sandboxed Python environment

2015-05-29 Thread Paul Rubin
Chris Angelico  writes:
> You can *easily* sandbox something that has very little functionality
> - all you have to do is provide a minimalist "language" that permits
> only a very few actions, and you know it's safe. But that security
> comes at a price.

This is a non-sequitur.  The reason they didn't put more features into
Lua is that it would have made the memory footprint bigger and they
pitch it as an embeddable extension engine so they want to keep it
small.  Stuff like bignums and unicode in themselves wouldn't have
affected security.  There's no obstacle to implementing Python the way
Lua is implemented, and for all I know, MicroPython does that.  It just
didn't happen to be done that way with CPython because of Python's
expected mode of use historically.  Armin Ronacher's blog entry that I
linked says a little more about this.

Heck, think of Java, which is monstrously more complicated than Python
and supports applet sandboxing, plus it can run Python programs (under
Jython).  Or Javascript, which has similar complexity to Python and runs
sandboxes in millions (billions?) of browsers.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: stdout of child process as an input of another thread in Python?

2015-05-29 Thread dieter
Kevin Peterson  writes:

> I want to use the stdout of child process as an input of another thread, but 
> some how I am not able to read the stdout.  Using Popen I have created a 
> child process and stdout of it I have redirected to PIPE (because I don't 
> want that to be printed on with my main process).  Now using this 
> statement,"Line=Proc.stdout.readline()" I want to read stdout of child 
> process and I have to do operation on that. but somehow i am not able to read 
> from stdout of child process. 
>
> Following is the code snapshot - 
>
> Proc = Popen(["python.exe","filename.py"],stdout=PIPE)
> 
> while True:
> Line = Proc.stdout.readline()
> print Line
>
> Here,
> Filename.py(Child process) is continuously printing "Hello World!!" in place 
> of reading stdout of child process. 

Your description is not sufficiently clear:

  If "filename.py" is your child process, why should it read the stdout
  of the child process (i.e. itself).

I suggest, you describe what "filename.py" (your child) does
and what behavior you observe for the parent.

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