Re: Recipe request: asyncio "spin off coroutine"

2016-12-15 Thread Frank Millman

"Marko Rauhamaa"  wrote in message news:[email protected]...


It ain't over till the fat lady sings. Things can accumulate, hang
and/or fail in surprising ways.

At the very least you should maintain statistics that reveal the number
of pending closing tasks for troubleshooting when things go south.



I know that you have vastly more experience in this area than I do, so I 
will take your advice to heart.


Thanks

Frank


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


Re: Name mangling vs qualified access to class attributes

2016-12-15 Thread Marco Paolieri
Hi all,

Thank you for the feedback. So, to recap, reasons to use name mangling
'self.__update(iterable)' rather than qualified access
'Mapping.update(self, iterable)' are:


1. Qualified access stops working when class 'Mapping' is renamed
(at compile-time) or its name is reassigned at runtime.

Honestly, I wouldn't worry about the first case: if I rename a class,
fixing qualified accesses within the class itself is just a matter of
refactoring.  Instead, when another class is assigned to the name
'Mapping' (in the scope where it was defined), qualified access breaks
at runtime, while looking up methods through 'self' still works.


2. Method lookup through 'self' allows subclasses or instances to
override mangled names.

This should be extremely rare. After all, mangled names are meant to
avoid overrides.


For me, the takeaway is that it's always better to invoke methods on
'self', rather than passing 'self' yourself. As Guido said about the
drawbacks of having methods see each other in their scopes:

"m1(self) and self.m1() [would be] equivalent.  That's evil, because
it opens up a meaningless choice between alternative (and the m1(self)
notation is inferior, because it doesn't look in base classes)."

https://mail.python.org/pipermail/python-dev/2000-November/010598.html


Best,
-- Marco
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best attack order for groups of numbers trying to destroy each other, given a victory chance for number to number attack.

2016-12-15 Thread skybuck2000
Hello,

I received a reply from somebody on my ISP newsserver. Apperently his reply is 
not visible on google groups. I wonder why, maybe it's a banned troll or 
something, but perhaps not.

Anyway... my ISP has problems accessing their newsserver. They won't offer the 
service to new customers or changing subscriptions and they lack software to 
access the server. The server currently has a technical problem. Uploading 
messages is not possible. Some kind of bug... this has been going on for 
months. Seems like the bug will be ever lasting.

Just called ISP helpdesk... I forgot to ask them if they could simply reset the 
server... but with the little information I was giving it seems to be a "remote 
control problem".

The server is probably remotely controlled and somehow that remote control has 
been lost... Either password lost, or software is not working anymore... kinda 
strange story... especially for such a large ISP which should have sufficient 
technical people to solve this... weird story isn't it... perhaps they just 
don't want to fix it to drop people of of it

This kinda sucks for me because using usenet via google newsgroups completely 
sucks... and is like 1.000.000 times more difficult with this very lacking 
interface.

But for messages that I consider worth it... like this one, I might keep on 
going(/presserve? gotta look that up in dictionary) for now... :)

Anyway here is my reply, it might enlighting others as well to this exact 
problem:


>So now I have the idea to make this program run when my computer is idling
>during the day, it should also be able to store it's progress so that it 
>can
>continue after it was shutdown.
>

"
Periodic snap-shots of the running environment will likely take up a
majority of the run-time.
"

(Since you the only one who has replied so far I will take some time to try 
and answer some of your questions to help you along and perhaps it will be 
usefull to others as well).

Haven't implemented this yet, but I don't see why that would be the case.

It would probably need to store very little. Only 8 indexes, and perhaps 
4x24 entries so that's nothing.

This could be then everything index4 increments for example, or index 3.

Somewhere below in this posting I will give some pseudo code for the indexes 
since it seems you might be struggling with that a little bit or you are 
trying to solve it a different way which is interesting to see but in this 
case I don't think it's better so I will adjust you there, but first

I reply to the rest of your posting so the pseudo code will be somewhere 
below...

"
Especially if your idea is to first generate two lists of the permutations 
of the inputs
"

The permutations were already given by me in my original post. No further 
permutation lists are needed. The permutation table was simple generated 
with some 1234 string with some Delphi code found from the internet.

Generating permutations is not the real issue here, since there is code on 
the internet which already solves that.

"
then generate a list of the "combat" permutations, and you want to be able 
to store-off/reload all
those lists.
"

I don't see why it would be necessary to store any lists at all, except from 
the permutation table as to avoid having to implement a complex permutation 
algorithm. Generating permutations is a topic in itself so I tried to avoid 
that by simply hard coding the small permutation list into the code to side 
step that sub problem.

Generating/storing/loading any kind combination list would either not be 
possible because of lack of memory or would require way too much time.

What should however be stored is the number of victories for each 
permutation.

>(Idea for now is to make it multi threaded and assign a low thread priority

"It's CPU-bound, so using multiple threads for the computation won't be
that effective..."

I disagree, the problem is pretty straight forward and can be split just 
fine by duplicating some simple indexes/data structures.

And should be able to run on each core at nearly 100% efficiency.

The results could be merged together at the very end.

At least in Delphi/native code this will work nicely...

"You add the system overhead of context switches between
the threads, and for common Python, you run into the GIL (so even if you
get subsets of processing assigned to each of multiple processor cores, the
GIL will block all but one from doing any work at any moment -- say you
partitioned it so core0 handles only the set where X begins [1, ...], core
1 handles [2, ...], etc.).
"

Your last sentence made the most sense to me... I don't know what GIL is or 
if Python has any multi threading issues or overhead.

I would assume it would not be to bad concerning overhead and that python 
threads can run pretty efficient as well, if not that would surprise me a 
little bit.

Ofcourse there would only be 2 threads since it's a dual core system. If you 
ment running more than 2 threads then yes there 

[OT] "Invisible posts", was: Best attack order for groups of numbers trying to destroy each other, given a victory chance for number to number attack.

2016-12-15 Thread Peter Otten
[email protected] wrote:

> I received a reply from somebody on my ISP newsserver. Apperently his
> reply is not visible on google groups. I wonder why, maybe it's a banned
> troll or something, but perhaps not.

No, that's Dennis Lee Bieber who doesn't want his posts to be kept, and 
seems to be the only one to post here with the X-No-Archive flag set.

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


Re: Python3, column names from array - numpy or pandas

2016-12-15 Thread renjith madhavan
Thank you for the reply. 
I tried that, I am trying to do this.

The context is I am trying to find mapk ( k = 3 ) for this list.
A, B , C, D and E are product names.

If I am trying manually I will do something like this.

TRUTH = [[A], [B,C], [A], [D,E]]
and if my prediction is :
PRED=[[B,A, D], [A,C,B], [A,B,C], [B,D,E]]

map3(truth, pred, 3)

 
How do I convert my input truth values in the TRUTH format.
Should I be looking for "boolean indexing" for this case.
idABCDE 
10010000 
10101100 
10210000 
10300011 
''') 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best attack order for groups of numbers trying to destroy each other, given a victory chance for number to number attack.

2016-12-15 Thread Random832
On Thu, Dec 15, 2016, at 08:31, Dennis Lee Bieber wrote:
>   As for my posts disappearing: I run with "X-NoArchive" set. I have from
> before Google absorbed DejaNews. Back then, most news-servers expired
> posts
> on some periodic basis (my ISP tended to hold text groups for 30 days or
> so, binaries groups cycled in less than 36 hours). When DejaNews arrived,
> many objected to the non-expiration facet:
> https://en.wikipedia.org/wiki/Google_Groups#Deja_News

As I recall, what most people *actually* said they objected to was the
fact that they profited from showing ads. X-No-Archive was just a
convenient blunt weapon to hit them with.
-- 
https://mail.python.org/mailman/listinfo/python-list


Unicode script

2016-12-15 Thread Steve D'Aprano
Suppose I have a Unicode character, and I want to determine the script or
scripts it belongs to.

For example:

U+0033 DIGIT THREE "3" belongs to the script "COMMON";
U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".


Is this information available from Python?


More about Unicode scripts:

http://www.unicode.org/reports/tr24/
http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt


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

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


Problem running Python 3.5.2 on school network PC

2016-12-15 Thread Jed Mack
We are having a problem running Python 3.5.2 on Windows 10 x64 computers,
which are members of a school network.



The program seems to install correctly, but when we try to run the program
it stops and give an error message saying:



*Fatal Python error: Py_Initialize: unable to load the file system codec*

*Traceback (most recent call last):*

*  File "C:\Program Files\Python35\lib\encodings\__init__.py", line 31, in<
module>*

*zipimport.ZipImportError: can't find module 'codecs'*





On a Windows 7 PCs, on the same network, the program runs with no problems.



We have no one here who is familiar with Python.  Do you have any
additional information on this error, and suggestions for fixing it?



We have a teacher who needs this program on Windows 10 PCs for students to
use beginning January 3.



Thanks,

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


Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Thomas 'PointedEars' Lahn
Ben Finney wrote:

> Chris Angelico  writes:
>> On Tue, Dec 13, 2016 at 10:17 AM, Ben Finney 
>> wrote:
>> > If the differences didn't matter I would agree that “overly
>> > pedantic” is fair. But those differences trip up newcomers. Thinking
>> > of ‘Foo.__init__’ leads people to wonder where the ‘self’ attribute
>> > came from – am I not meant to be constructing it? — and to attempt
>> > to return that instance. And when the time comes to lean about
>> > ‘__new__’ the confusion continues, because the newcomer has been
>> > told that something *else* is the constructor, so what's this?
>>
>> In JavaScript [different semantics apply].
>>
>> Ultimately, every language has slightly different semantics […], so
>> you have to learn that the "constructor" might have slightly different
>> semantics.

Actually, that is an inverse semantic fallacy.  There *is* always *some* 
common semantics to a the same term used in different domains; that is *why* 
it is used across domains (here: across object-oriented programming 
languages).  The common semantics here appears to be, as I substantiated by 
the FOLDOC reference, that a constructor initializes an object/instance.

“construct” does _not_ mean the same as “create” (make); understood 
literally, it means “heap together”, “build” (from Latin «construo», from 
«com» “together” + «struo» “I heap up, pile”).  A “constructor” is then the 
person or (here) the thing that “heaps together”.  ISTM that it “heaps 
together” the properties/attributes so that the object can be useful.

This is the same in Python as in several other OOPLs inasfar as that I can 
use super() or the superclass’ name to call the parent …what? – yes, the 
parent *constructor* of the class, i.e. the superclass’ (or in python, one 
of the superclass’) *constructor* from a class’ *constructor* (yes, I 
insist; see below) to initialize inherited attributes.

> Please read again the message you extracted that quote from. I already
> said I'm not claiming some other programming language's semantics should
> dictate Python's.
> 
> 
> What I'm saying is that in Python, there *already are* different
> semantics for a constructor, and they don't match the semantics of
> ‘Foo.__init__’.

Yes, *you* are saying that.
 
> In Python, a constructor for a class is a class method.

Says who, *you*?

> ‘Foo.__new__’ is a constructor. ‘Foo.__init__’ is an instance method, so
> it's not a constructor.

According to , 
“Foo.__init__” is _not_ an instance method.  Were it an instance 
method, the following would not happen:

| >>> class Foo:
| ... def __init__ (self):
| ... pass
| ...
| >>> Foo.__init__.__self__
| Traceback (most recent call last):
|   File "", line 1, in 
| AttributeError: 'function' object has no attribute '__self__'

Because “Instance method objects have attributes, too: m.__self__ is the 
instance object with the method m() […]”.

“Ex falso quodlibet”, “wishful thinking”, and “circular reasoning” come to 
mind here: *You* say that a constructor is a class method in Python, then 
*you* define __init__() to be an instance method, therefore __init__() 
*cannot* qualify anymore as a constructor.  So your wish is fulfilled, *far 
from reality*.

[If one would instantiate Foo, *then* the __init__() method of the instance 
would be an instance method (which is tautological):

| >>> Foo().__init__.__self__
| <__main__.Foo object at 0x7f86d73e8ef0>

]
 
> In Python, a constructor for a class makes the instance where it didn't
> already exist. ‘Foo.__new__’ is a constructor. ‘Foo.__init__’ requires
> the instance to already be constructed, so it's not a constructor.

You are also limiting the meaning of “constructor” in OOP to “create the 
instance” so that __init__() does not fit your definition of what is a 
constructor in Python in that regard as well.  But as I showed, not only 
does “constructor” not need to mean that, it can also mean much more than 
that.

So your reasoning is doubly invalid.
 
> I'm showing that Python classes *already have* constructors,

By *your* definition that you have *construed* (no pun intended) to fit your 
argument.

> and ‘Foo.__init__’ doesn't qualify because it doesn't have the semantics 
> of Python constructors.

By *your* definition.  That does not mean that your definition is correct, 
or that your reasoning is valid.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3, column names from array - numpy or pandas

2016-12-15 Thread Rhodri James

On 15/12/16 01:56, renjith madhavan wrote:

I have a dataset in the below format.

id  A   B   C   D   E
100 1   0   0   0   0
101 0   1   1   0   0
102 1   0   0   0   0
103 0   0   0   1   1

I would like to convert this into below:
100, A
101, B C
102, A
103, D E

How do I do this ? I tried numpy argsort but I am new to Python and finding 
this challenging.
Appreciate any help in this.



Numpy or pandas?  Neither, this is a straightforward bit of text 
manipulation you can do without needing to import anything.  I wouldn't 
bother considering either unless your dataset is massive and speed is 
anything of an issue.


with open("data.txt") as datafile:
# First line needs handling separately
line = next(datafile)
columns = line.split()[1:]
# Now iterate through the rest
for line in datafile:
results = []
for col, val in zip(columns, line.split()[1:]:
 if val == "1":
 results.append(col)
print("{0}, {1}".format(data[0], " ".join(results)))

Obviously there's no defensive coding for blank lines or unexpected data 
in there, and if want to use the results later on you probably want to 
stash them in a dictionary, but that will do the job.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Mapping with continguous ranges of keys

2016-12-15 Thread Steve D'Aprano
I have some key:value data where the keys often are found in contiguous
ranges with identical values. For example:

{1: "foo",
 2: "foo",
 3: "foo",
 # same for keys 4 through 99
 100: "foo",
 101: "bar",
 102: "bar",
 103: "foobar",
 104: "bar",
 105: "foo", 
}


So in this case, the keys 1 through 100, plus 105, all have the same value.

I have about a million or two keys, with a few hundred or perhaps a few
thousand distinct values. The size of each contiguous group of keys with
the same value can vary from 1 to perhaps a hundred or so.

Has anyone dealt with data like this and could give a recommendation of the
right data structure to use?

The obvious way is to explicitly list each key, in a regular dict. But I
wonder whether there are alternatives which may be better (faster, more
memory efficient)?


Thanks,


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

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


Re: Mapping with continguous ranges of keys

2016-12-15 Thread D'Arcy Cain

On 2016-12-15 12:06 PM, Steve D'Aprano wrote:

I have about a million or two keys, with a few hundred or perhaps a few
thousand distinct values. The size of each contiguous group of keys with
the same value can vary from 1 to perhaps a hundred or so.


There isn't enough info in your post to be sure but if those values are 
constant then you might be able to subclass dict and write a new 
__getitem__ that checks for specific ranges and calls the superclass 
only if not in the known ranges.  For example:


class MyDict(dict):
  def __getitem__(self, key):
if isinstance(key, int) and key >= 1 and key <= 100:
  return "foo"
return dict.__getitem__(self, key)

Obviously that middle section can be as complex as you need.

--
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:[email protected]
VoIP: sip:[email protected]
--
https://mail.python.org/mailman/listinfo/python-list


Re: Mapping with continguous ranges of keys

2016-12-15 Thread Thomas Nyberg

On 12/15/2016 09:06 AM, Steve D'Aprano wrote:

Has anyone dealt with data like this and could give a recommendation of the
right data structure to use?



I haven't dealt with a data structure exactly like this, but it's 
basically a sparse array. (I'm sure it has a name somewhere in the 
academic literature, but I couldn't find it with a quick search right 
now...)


My solution to what you're asking for would be to have a list of 
key-value pairs, only adding a key to the list if it "changes" the 
value. I.e. your data structure would be this:


l = [
(1, "foo"),
(101, "bar"),
(103, "foobar"),
(104, "bar"),
(105, "foo"),
]

Then the only thing you need to do is define the lookup function. I 
would basically just do a binary search on the first values in the 
tuples. I.e. if "n" is your integer, you check if the middle values of 
the list l has it's first element as less than or greater than your 
value. Then you split l in two and do the same thing. Do this until you 
either find your value, or you find a value less than your value with 
the added property that the next value is greater than your value. After 
that you spit out the final second value.


There might be better ways to find the keys, but I think this approach 
is probably your best bet.


Cheers,
Thomas
--
https://mail.python.org/mailman/listinfo/python-list


Re: Mapping with continguous ranges of keys

2016-12-15 Thread Peter Otten
Steve D'Aprano wrote:

> I have some key:value data where the keys often are found in contiguous
> ranges with identical values. For example:
> 
> {1: "foo",
>  2: "foo",
>  3: "foo",
>  # same for keys 4 through 99
>  100: "foo",
>  101: "bar",
>  102: "bar",
>  103: "foobar",
>  104: "bar",
>  105: "foo",
> }
> 
> 
> So in this case, the keys 1 through 100, plus 105, all have the same
> value.
> 
> I have about a million or two keys, with a few hundred or perhaps a few
> thousand distinct values. The size of each contiguous group of keys with
> the same value can vary from 1 to perhaps a hundred or so.
> 
> Has anyone dealt with data like this and could give a recommendation of
> the right data structure to use?
> 
> The obvious way is to explicitly list each key, in a regular dict. But I
> wonder whether there are alternatives which may be better (faster, more
> memory efficient)?

Use a list, either directly if there are no big holes

>>> r = range(10**5)
>>> sys.getsizeof(list(r))/sys.getsizeof(dict(zip(r, r)))
0.14306676635590074


or indirectly:

ranges_list = [
1,
101,
103,
104,
105,
106,
]

index_to_value = {
1: "foo",
2: "bar",
3: "foobar",
4: "bar",
5: "foo",
}

def get(key, default="missing"):
index = bisect.bisect(ranges_list, key)
return index_to_value.get(index, default)


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


Re: Unicode script

2016-12-15 Thread eryk sun
On Thu, Dec 15, 2016 at 4:53 PM, Steve D'Aprano
 wrote:
> Suppose I have a Unicode character, and I want to determine the script or
> scripts it belongs to.
>
> For example:
>
> U+0033 DIGIT THREE "3" belongs to the script "COMMON";
> U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
> U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".
>
> Is this information available from Python?

Tools/makunicodedata.py doesn't include data from "Scripts.txt". If
adding an external dependency is ok, then you can use PyICU. For
example:

>>> icu.Script.getScript('\u0033').getName()
'Common'
>>> icu.Script.getScript('\u0061').getName()
'Latin'
>>> icu.Script.getScript('\u03be').getName()
'Greek'

There isn't documentation specific to Python, so you'll have to figure
things out experimentally with reference to the C API.

http://icu-project.org/apiref/icu4c
http://icu-project.org/apiref/icu4c/uscript_8h.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode script

2016-12-15 Thread Joel Goldstick
I think this might be what you want:
https://docs.python.org/3/howto/unicode.html#unicode-properties

On Thu, Dec 15, 2016 at 11:53 AM, Steve D'Aprano
 wrote:
> Suppose I have a Unicode character, and I want to determine the script or
> scripts it belongs to.
>
> For example:
>
> U+0033 DIGIT THREE "3" belongs to the script "COMMON";
> U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
> U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".
>
>
> Is this information available from Python?
>
>
> More about Unicode scripts:
>
> http://www.unicode.org/reports/tr24/
> http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
> http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt
>
>
> --
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode script

2016-12-15 Thread MRAB

On 2016-12-15 16:53, Steve D'Aprano wrote:

Suppose I have a Unicode character, and I want to determine the script or
scripts it belongs to.

For example:

U+0033 DIGIT THREE "3" belongs to the script "COMMON";
U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".


Is this information available from Python?


More about Unicode scripts:

http://www.unicode.org/reports/tr24/
http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt


Interestingly, there's issue 6331 "Add unicode script info to the 
unicode database". Looks like it didn't make it into Python 3.6.


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


Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Terry Reedy

On 12/14/2016 11:14 PM, Thomas 'PointedEars' Lahn wrote:


According to , 
“Foo.__init__” is _not_ an instance method.  Were it an instance
method, the following would not happen:


This link points to subsection 9.3.4. Method Objects


| >>> class Foo:
| ... def __init__ (self):
| ... pass
| ...
| >>> Foo.__init__.__self__
| Traceback (most recent call last):
|   File "", line 1, in 
| AttributeError: 'function' object has no attribute '__self__'


You have misread the docs.  Foo.__init__ is the function. 
Foo().__init__ is a method object with the attribute __self__.  You 
omitted the ()s.


>>> class C:
def __init__(self): pass


>>> ci = C().__init__
>>> ci.__self__
<__main__.C object at 0x01E38A750E80>


Because “Instance method objects have attributes, too: m.__self__ is the
instance object with the method m() […]”.


This line is from section 9.7. Odds and Ends. In this quote, 'm' is a 
method object, the result of 'instance.method, not a function.  In 
Python 2, 'm' would have been called a 'bound method', as opposed to an 
unbound method.  Since the latter were eliminated in 3.x, the adjective 
is no longer needed.




--
Terry Jan Reedy


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


Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-15 Thread Peter Pearson
On Wed, 14 Dec 2016 11:50:30 -0600, Skip Montanaro wrote:
> On Wed, Dec 14, 2016 at 11:40 AM, Peter Pearson
> wrote:
>> Train your fingers to use C-[.
>
> As I recall, the location of the Ctrl key was one of the differences
> between Sun and PC101 keyboards. Doesn't matter so much now, as Sun
> has gone the way of the dodo, but it moved around more for me than ESC
> over the years.

Absolutely right.  Random migrations of the Ctrl key annoyed so many
of us set-in-our-ways geezers that Linux distributions always seem to
come with an easily activated option to put the Ctrl key where it
belongs, namely to the left of the A, right where God put it on Adam's
ASR 33.

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem running Python 3.5.2 on school network PC

2016-12-15 Thread Terry Reedy

On 12/15/2016 11:11 AM, Jed Mack wrote:

We are having a problem running Python 3.5.2 on Windows 10 x64 computers,
which are members of a school network.

The program seems to install correctly,


Is Python installed on each machine or on a network server?
Rather precisely, how was Python installed?
What installation package was downloaded?  From where?
How was it run?

> but when we try to run the program

it stops and give an error message saying:

*Fatal Python error: Py_Initialize: unable to load the file system codec*

*Traceback (most recent call last):*

*  File "C:\Program Files\Python35\lib\encodings\__init__.py", line 31, in<
module>*


The line is
import codecs


*zipimport.ZipImportError: can't find module 'codecs'*


This says that the stdlib is in the form of a zipfile instead of the 
normal /lib directory.  I don't know how one gets that result on 
Windows.  It appears that the zipped library is missing the file.



On a Windows 7 PCs, on the same network, the program runs with no problems.


Same Python version?  Same installation file?  Run the same way?


We have no one here who is familiar with Python.  Do you have any
additional information on this error, and suggestions for fixing it?



We have a teacher who needs this program on Windows 10 PCs for students to
use beginning January 3.


We appreciate that you are trying to use current Python to teach.  I 
hope we are able to solve the problem, given more information.


--
Terry Jan Reedy

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


Re: Problem running Python 3.5.2 on school network PC

2016-12-15 Thread Tim Golden

On 15/12/2016 16:11, Jed Mack wrote:

We are having a problem running Python 3.5.2 on Windows 10 x64 computers,
which are members of a school network.

The program seems to install correctly, but when we try to run the program
it stops and give an error message saying:

*Fatal Python error: Py_Initialize: unable to load the file system codec*

*Traceback (most recent call last):*

*  File "C:\Program Files\Python35\lib\encodings\__init__.py", line 31, in<
module>*

*zipimport.ZipImportError: can't find module 'codecs'*

On a Windows 7 PCs, on the same network, the program runs with no problems.

We have no one here who is familiar with Python.  Do you have any
additional information on this error, and suggestions for fixing it?

We have a teacher who needs this program on Windows 10 PCs for students to
use beginning January 3.


This most often seems to happen when there is another instance of Python 
installed (or, possibly, previously installed and partly uninstalled). 
Especially: look for environment variables which could be left over from 
such an installation, particularly PYTHONHOME.


NB it's possible for Python to have been installed as part of some OEM 
software, ie not as part of your school's own installation protocol.


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


Reading python list as a newsgroup (was ...)

2016-12-15 Thread Terry Reedy

On 12/15/2016 6:23 AM, [email protected] wrote:


Anyway... my ISP has problems accessing their newsserver. ...


If you want to read python-list as a news group, you might try 
news.gmane.org.  About once a year, it goes down for a few hours to a 
day, but has otherwise been dependable.  I found it when my ISP dropped 
newsgroup access around a decade ago.


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


Re: Problem running Python 3.5.2 on school network PC

2016-12-15 Thread Wildman via Python-list
On Thu, 15 Dec 2016 11:11:51 -0500, Jed Mack wrote:

> We are having a problem running Python 3.5.2 on Windows 10 x64 computers,
> which are members of a school network.
> 
> 
> 
> The program seems to install correctly, but when we try to run the program
> it stops and give an error message saying:
> 
> 
> 
> *Fatal Python error: Py_Initialize: unable to load the file system codec*
> 
> *Traceback (most recent call last):*
> 
> *  File "C:\Program Files\Python35\lib\encodings\__init__.py", line 31, in<
> module>*
> 
> *zipimport.ZipImportError: can't find module 'codecs'*
> 
> 
> 
> 
> 
> On a Windows 7 PCs, on the same network, the program runs with no problems.
> 
> 
> 
> We have no one here who is familiar with Python.  Do you have any
> additional information on this error, and suggestions for fixing it?
> 
> 
> 
> We have a teacher who needs this program on Windows 10 PCs for students to
> use beginning January 3.
> 
> 
> 
> Thanks,
> 
> Jed Mack

You might try adding the installation folders to the path, if it
hasn't been done already.  Change 'python' to the actual folder name.

C:\python
C:\python\Lib\site-packages
C:\python\Scripts

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


Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Ian Kelly
On Thu, Dec 15, 2016 at 11:05 AM, Terry Reedy  wrote:
> On 12/14/2016 11:14 PM, Thomas 'PointedEars' Lahn wrote:
>
>> According to
>> ,
>> “Foo.__init__” is _not_ an instance method.  Were it an instance
>> method, the following would not happen:
>
>
> This link points to subsection 9.3.4. Method Objects
>
>> | >>> class Foo:
>> | ... def __init__ (self):
>> | ... pass
>> | ...
>> | >>> Foo.__init__.__self__
>> | Traceback (most recent call last):
>> |   File "", line 1, in 
>> | AttributeError: 'function' object has no attribute '__self__'
>
>
> You have misread the docs.  Foo.__init__ is the function. Foo().__init__ is
> a method object with the attribute __self__.  You omitted the ()s.

I think this is actually the point that Thomas was making. He was
responding to the assertion that "Foo.__init__" is an instance method
and demonstrating that it's false because Foo is the class, not an
instance of Foo.

If I've observed anything about Thomas over the years he's been
posting here, it's that he's extremely literal and will pick apart
tiny irrelevant nuances to the point of being (or at least appearing)
trollish.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode script

2016-12-15 Thread Terry Reedy

On 12/15/2016 11:53 AM, Steve D'Aprano wrote:

Suppose I have a Unicode character, and I want to determine the script or
scripts it belongs to.

For example:

U+0033 DIGIT THREE "3" belongs to the script "COMMON";
U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".

Is this information available from Python?




Yes, though not as nicely as you probably want.  (Have you searched for 
existing 3rd party modules?)  As near as I can tell, there is no direct 
'script' property in the unicodedatabase.


Option 1: unicodedata module, from char name

>>> import unicodedata as ucd
>>> ucd.name('\u03be')
'GREEK SMALL LETTER XI'
>>> ucd.name('\u0061')
'LATIN SMALL LETTER A'

In most cases, the non-common char names start with a script name.
In some cases, the script name is 2 or w words.

>>> ucd.name('\U00010A60')
'OLD SOUTH ARABIAN LETTER HE'

In a few cases, the script name is embedded in the name.
>>> ucd.name('\U0001F200')
'SQUARE HIRAGANA HOKA'

Occasionally the script name is omitted.
>>> ucd.name('\u3300')
'SQUARE APAATO'  # Katakana

To bad the Unicode Consortium did not use a consistent name scheme:
script [, subscript]: character

LATIN: SMALL LETTER A
ARABIAN, OLD SOUTH: LETTER HE
KATAKANA: SQUARE APAATO


More about Unicode scripts:

http://www.unicode.org/reports/tr24/
http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt


Option 2: Fetch the above Scripts.txt.

Suboption 1: Turn Scripts.txt into a list of lines.  The lines could be 
condensed to codepoint or codepoint range, script.  Write a function 
that takes a character or codepoint and linearly scans the list for a 
matching line.  This makes each lookup O(number-of-lines).


Suboption 2. Turn Scripts.txt into a list of scripts, with codepoint 
being the index.  This takes more preparation, but makes each lookup 
O(1).  Once the preparation is done, the list could be turned into a 
tuple and saved as a .py file, with the tuple being a compiled constant 
in a .pyc file.


To avoid bloat, make sure that multiple entries for a script use the 
same string object instead of multiple equal strings.  (CPython string 
interning might do this automatically, but cross-implementation code 
should not depend on this.)  The difference is


scripts = [..., 'Han', 'Han', 'Han', ...] # multiple strings
versus
HAN = 'Han'
scripts = [..., HAN, HAN, HAN, ...]  # multiple references to one string

On a 64 bit OS, the latter would use 8 x defined codepoints (about 
200,000) bytes.  Assuming such does not already exits, it might be worth 
making such a module available on PyPI.



http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt


Essentially, ditto, except that I would use a dict rather than a 
sequence as there are only about 400 codepoints involved.


--
Terry Jan Reedy


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


A comparatively efficient software for embedding secret information bits into nataural language texts

2016-12-15 Thread Mok-Kong Shen


WORDLISTTEXTSTEGANOGRAPHY is a new software (employing an extensive
English word list) which, while performing linguistic steganography,
also involves pseudo-random separation of the word list into two
sublists (for denoting 0 and 1 bits) that are dependent on dynamic
session-key materials, thus furnishing simultaneously substantial
cryptographical security for the embedded stego bits.

The software has a stegobit embedding rate of roughly 0.5 or higher
per word of cover-text which the user composes to be as natural as
possible under the guidance of the software. To my knowledge there
is currently no other linguistic stego software that could compete
with it, when both the naturalness of the cover texts and the
stegobit embedding rate are taken into consideration as evaluation
criteria.

The software in Python with a GUI coded in tkinter is available at:
http://s13.zetaboards.com/Crypto/topic/9024439/1/

For comments and critiques I should be very grateful.

M. K. Shen
--
https://mail.python.org/mailman/listinfo/python-list


Re: Re: Install Problem

2016-12-15 Thread eryk sun
On Thu, Dec 15, 2016 at 8:24 PM, Rhesa Browning  wrote:
> I have not been able to find the temp folder.  I am doing this on a work 
> computer
> and don't have access to all the folders.  Some are hidden.

Enter %temp% in Explorer's location bar or the Win+R dialog.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Re: Install Problem

2016-12-15 Thread Rhesa Browning
Eryk sun.  I have not been able to find the temp folder.  I am doing this on a 
work computer and don't have access to all the folders.  Some are hidden.

-Original Message-
From: eryk sun [mailto:[email protected]] 
Sent: Tuesday, December 13, 2016 3:49 PM
To: [email protected]
Cc: Rhesa Browning 
Subject: [EXTERNAL] Re: Install Problem

On Tue, Dec 13, 2016 at 8:37 PM, Rhesa Browning  wrote:
> I have been trying to install Python 3.5.2 onto my computer.  I have 
> installed and uninstalled and resinstalled several times.  Every time 
> I get an error message saying that the python35.dll doesn't exist on my 
> computer so it can't open Python.
> How can this problem be fixed?

Please open an issue at bugs.python.org. Zip the installation logs ("Python 
3.5.2*.log") from your %temp% folder, and upload them to the issue.
3M security scanners have not detected any malicious content in this message.

To report this email as SPAM, please forward it to [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Mapping with continguous ranges of keys

2016-12-15 Thread Terry Reedy

On 12/15/2016 12:06 PM, Steve D'Aprano wrote:

I have some key:value data where the keys often are found in contiguous
ranges with identical values. For example:

{1: "foo",
 2: "foo",
 3: "foo",
 # same for keys 4 through 99
 100: "foo",
 101: "bar",
 102: "bar",
 103: "foobar",
 104: "bar",
 105: "foo",
}


For this particular example (untested):

def lookup(n):
F, B, FB = 'foo', 'bar', 'foobar'  # Ensure value objects reused
if 1 <= n <= 100:
return F
elif 101 <= n <= 105:
return (B, B, FB, B, F')[n - 101]
else:
raise ValueError('n must be in range(1, 106)')


So in this case, the keys 1 through 100, plus 105, all have the same value.

I have about a million or two keys, with a few hundred or perhaps a few
thousand distinct values. The size of each contiguous group of keys with
the same value can vary from 1 to perhaps a hundred or so.



Has anyone dealt with data like this and could give a recommendation of the
right data structure to use?

The obvious way is to explicitly list each key, in a regular dict. But I
wonder whether there are alternatives which may be better (faster, more
memory efficient)?


If, as in the example, the keys comprise a contiguous sequence of ints, 
the 'obvious' way to me is sequence of values.  A tuple of constants 
gets compiled and will load quickly from a .pyc file.  4 or 8 bytes per 
entry times 1 or 2 million entries is usually tolerable on a gigabyte 
machine.


Or trade time for space with binary search or search in explicit binary 
tree.  Or combine binary search and indexed lookup as I did above.



--
Terry Jan Reedy

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


Re: Mapping with continguous ranges of keys

2016-12-15 Thread Terry Reedy

On 12/15/2016 12:27 PM, Thomas Nyberg wrote:

On 12/15/2016 09:06 AM, Steve D'Aprano wrote:

Has anyone dealt with data like this and could give a recommendation
of the
right data structure to use?



I haven't dealt with a data structure exactly like this, but it's
basically a sparse array.


A sparse array has at least half missing values.  This one has none on 
the defined domain, but contiguous dupicates.


> (I'm sure it has a name somewhere in the

academic literature, but I couldn't find it with a quick search right
now...)


'Sparse array' is the name for sparse arrays.  I cannot think of one for 
blocks of duplicates.


--
Terry Jan Reedy

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


Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Terry Reedy

On 12/15/2016 2:04 PM, Ian Kelly wrote:

On Thu, Dec 15, 2016 at 11:05 AM, Terry Reedy  wrote:

On 12/14/2016 11:14 PM, Thomas 'PointedEars' Lahn wrote:


According to
,
“Foo.__init__” is _not_ an instance method.  Were it an instance
method, the following would not happen:



This link points to subsection 9.3.4. Method Objects


| >>> class Foo:
| ... def __init__ (self):
| ... pass
| ...
| >>> Foo.__init__.__self__
| Traceback (most recent call last):
|   File "", line 1, in 
| AttributeError: 'function' object has no attribute '__self__'



You have misread the docs.  Foo.__init__ is the function. Foo().__init__ is
a method object with the attribute __self__.  You omitted the ()s.


I think this is actually the point that Thomas was making. He was
responding to the assertion that "Foo.__init__" is an instance method
and demonstrating that it's false because Foo is the class, not an
instance of Foo.


The __init__ function *is* an 'instance method', but not a (bound) 
method object.  The distinction is important.  I admit that 'instance 
method' can be confusing if one does not understand the contextual 
meaning of the two words.  A 'method' is a function that is a class 
attribute. Being a method normally adds special behavior to the 
function.  An 'instance method', the default status of a method,  takes 
an *instance of the class* (or subclass) as first parameter.  A 'class 
method' (relatively rare) takes the *class* (or subclass) as first 
parameter.   A 'static method' (very rare) takes neither as first 
parameter and is really just a function.


--
Terry Jan Reedy


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


Re: Mapping with continguous ranges of keys

2016-12-15 Thread Thomas Nyberg

On 12/15/2016 12:48 PM, Terry Reedy wrote:

On 12/15/2016 12:27 PM, Thomas Nyberg wrote:


I haven't dealt with a data structure exactly like this, but it's
basically a sparse array.


A sparse array has at least half missing values.  This one has none on
the defined domain, but contiguous dupicates.



I'm sorry for devolving into semantics, but there certainly isn't a 
single definition of "sparse array" out there. For example, the 
definition in wikipedia (https://en.wikipedia.org/wiki/Sparse_array) 
doesn't agree with you:


"In computer science, a sparse array is an array in which most of the 
elements have the default value (usually 0 or null)."


Personally my usage of sparse arrays in scipy has _always_ had all 
defined values it's just that the default value was 0. I never deal with 
"missing" values.



(I'm sure it has a name somewhere in the
academic literature, but I couldn't find it with a quick search right
now...)


'Sparse array' is the name for sparse arrays.  I cannot think of one for
blocks of duplicates.



Yeah that's why I said "basically a sparse array". It has the same 
defining characteristics. It is a situation where you have a large 
number of values associated to a small number of values in such a way 
that you can fairly easily describe the association without needing to 
simply write out all pairs. For regular sparse arrays it's easy because 
you associate them to a single value by default and only specify the 
ones that aren't. In this case that doesn't work, but due to the fact 
that you have long runs of repeated values you can use that to encode 
and compress the mapping.


Still not sure what to call it. I like D'Arcy's idea of subclassing a 
dict in combination with Peter's idea of using bisect (I had no idea 
that module existed!) so maybe I'll change my own not so great 
terminology to "basically a sparse map".


Cheers,
Thomas
--
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode script

2016-12-15 Thread Terry Reedy

On 12/15/2016 1:06 PM, MRAB wrote:

On 2016-12-15 16:53, Steve D'Aprano wrote:

Suppose I have a Unicode character, and I want to determine the script or
scripts it belongs to.

For example:

U+0033 DIGIT THREE "3" belongs to the script "COMMON";
U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".


Is this information available from Python?


More about Unicode scripts:

http://www.unicode.org/reports/tr24/
http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt



Interestingly, there's issue 6331 "Add unicode script info to the
unicode database". Looks like it didn't make it into Python 3.6.


https://bugs.python.org/issue6331
Opened in 2009 with patch and 2 revisions for 2.x.  At least the Python 
code needs to be updated.


Approved in principle by Martin, then unicodedata curator, but no longer 
active.  Neither, very much, are the other 2 listed in the Expert's index.


From what I could see, both the Python API (there is no doc patch yet) 
and internal implementation need more work.  If I were to get involved, 
I would look at the APIs of PyICU (see Eryk Sun's post) and the 
unicodescript module on PyPI (mention by Pander Musubi, on the issue).


--
Terry Jan Reedy


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


Re: Python constructors have particular semantics2c and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Steve D'Aprano
On Fri, 16 Dec 2016 08:09 am, Terry Reedy wrote:

> The __init__ function *is* an 'instance method', but not a (bound)
> method object.  The distinction is important.  I admit that 'instance
> method' can be confusing if one does not understand the contextual
> meaning of the two words.  A 'method' is a function that is a class
> attribute. Being a method normally adds special behavior to the
> function.  An 'instance method', the default status of a method,  takes
> an *instance of the class* (or subclass) as first parameter.  A 'class
> method' (relatively rare) takes the *class* (or subclass) as first
> parameter.   A 'static method' (very rare) takes neither as first
> parameter and is really just a function.

I think that what Terry might be trying to get at is that there's actually
two distinct but related meanings for "instance method" in the context of
Python. (Other languages may be different.)

(Terry, forgive me if I'm misinterpreting what you are saying.)

The first is an object of type types.MethodType. Because functions and
methods are first-class values in Python, such instance methods could be
stuffed into lists, attached as attributes to unrelated objects, bound to
variables, etc. Instance methods are just a data type, and could come from
anywhere.

Proof of concept:

py> class X(object):
... pass
...
py> x = X()
py> from types import MethodType
py> def method(self):
... print("method bound to", self)
...
py> x.surprise = MethodType(method, "Hello world!")
py> x.surprise()
method bound to Hello world!


But the usual meaning of "instance method" is a function defined inside a
class body (with exceptions below):

class X(object):
def method(self):
...


That is *conceptually* an instance method even if the implementation uses an
object of different type. In Python 2, retrieving "method" from either the
class or the instance returns something which matches both definitions of
object:

X.method returns an "unbound method", an object of type MethodType;
X().method returns a "bound method", also an object of type MethodType.


But in Python 3, it is recognised that there is little or no conceptual
difference between an unbound method and a function, and the implementation
is changed:

X.method returns an "unbound method", an object of type FunctionType;
X().method returns a "bound method", an object of type MethodType.


But whether the implementation is a special form of MethodType or just
FunctionType, the object is still conceptually an instance method.


The exceptions to the "function defined inside a class body" rule includes
two built-in types used as decorators:

classmethod
staticmethod

which are deemed to be "kinds of methods" but not *instance* methods. In
Python, we call them "class methods" and "static methods", but in other
languages they may not exist at all or have other names.

(In Java, the closest equivalent to "class method" is called a "static
method".)



Adding to the complexity, the __name__ of MethodType is just "method", and
the __name__ of FunctionType is just "function", so introspecting the
objects (looking at their repr() etc) may give slightly different results.



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

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


Re: The right way to 'call' a class attribute inside the same class

2016-12-15 Thread Erik

On 13/12/16 06:14, Gregory Ewing wrote:

Ned Batchelder wrote:

if a C++ constructor raises an exception, will the corresponding
destructor
be run, or not? (No, because it never finished making an object of
type T.)


So it just leaks any memory that's been allocated by
the partially-run constructor?


If you're referring to resources in general that a constructor (in the 
C++ sense) allocates - memory, file descriptors, whatever - then it's up 
to the constructor to release those resources before throwing the 
exception should something fail. Destructors are not executed for 
objects that were not constructed.


If the constructor is not written to that standard, then yes - it will 
leak resources.


The memory allocated for the _object_ itself will be released though.

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


Re: The right way to 'call' a class attribute inside the same class

2016-12-15 Thread Erik

On 12/12/16 23:23, Chris Angelico wrote:

In JavaScript, it's normal to talk about "calling a function as a
constructor". When you do, there is a 'this' object before you start.


No there isn't. There is an implicit binding of a variable called "this" 
based on the syntactic sugar of whether you're calling a function as 
method on an object or not.


In "strict" mode, this has been redefined to be "undefined" (i.e., there 
is no object) for when you're not - otherwise it will be a binding to 
the global "document" object (and in Node.js, I think something else 
entirely. It's a mess ...).



Ultimately, every language has slightly different semantics


You're not wrong ;)

E.

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


Re: The right way to 'call' a class attribute inside the same class

2016-12-15 Thread Chris Angelico
On Fri, Dec 16, 2016 at 11:36 AM, Erik  wrote:
> On 12/12/16 23:23, Chris Angelico wrote:
>>
>> In JavaScript, it's normal to talk about "calling a function as a
>> constructor". When you do, there is a 'this' object before you start.
>
>
> No there isn't. There is an implicit binding of a variable called "this"
> based on the syntactic sugar of whether you're calling a function as method
> on an object or not.
>
> In "strict" mode, this has been redefined to be "undefined" (i.e., there is
> no object) for when you're not - otherwise it will be a binding to the
> global "document" object (and in Node.js, I think something else entirely.
> It's a mess ...).

I'm talking about when you call a function as a constructor: "new
Foo()". Doesn't that have a 'this' object before the function starts?

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


Re: Unicode script

2016-12-15 Thread MRAB

On 2016-12-15 21:57, Terry Reedy wrote:

On 12/15/2016 1:06 PM, MRAB wrote:

On 2016-12-15 16:53, Steve D'Aprano wrote:

Suppose I have a Unicode character, and I want to determine the script or
scripts it belongs to.

For example:

U+0033 DIGIT THREE "3" belongs to the script "COMMON";
U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".


Is this information available from Python?


More about Unicode scripts:

http://www.unicode.org/reports/tr24/
http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt



Interestingly, there's issue 6331 "Add unicode script info to the
unicode database". Looks like it didn't make it into Python 3.6.


https://bugs.python.org/issue6331
Opened in 2009 with patch and 2 revisions for 2.x.  At least the Python
code needs to be updated.

Approved in principle by Martin, then unicodedata curator, but no longer
active.  Neither, very much, are the other 2 listed in the Expert's index.

 From what I could see, both the Python API (there is no doc patch yet)
and internal implementation need more work.  If I were to get involved,
I would look at the APIs of PyICU (see Eryk Sun's post) and the
unicodescript module on PyPI (mention by Pander Musubi, on the issue).

For what it's worth, the post has prompted me to get back to a module I 
started which will report such Unicode properties, essentially the ones 
that the regex module supports. It just needs a few more tweaks and 
packaging up...


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


just started

2016-12-15 Thread metal . suomi
Hi everybody, I have just installed python 3.5.2 (downloaded from 
https://www.python.org/) on my mac (El Capitan). 

1) I see from command line that older version of python are already available 
on my machine (python, python2.6, python2.7, python3, python3.5). I guess some 
might have been installed as part of Xcode (?) or via macport (? despite I 
never explicitly asked for python).

2) if I wish to install extra libraries, in particularly SciPy, what's best way 
of doing it? From command line I see the following commands: pip3 and pip3.5. I 
guess pip3.5 is for python3.5 ? Can I use pip3 and pip3.5 interchangeably, or 
pip3 will only install things for python3, and not 3.5?

Are all these command equivalent?

pip3 install --user numpy scipy matplotlib
pip3.5 install --user numpy scipy matplotlib

python3.5 -m pip install numpy scipy matplotlib


3) I also see this command to install it from macport, although not sure it 
will be ok given I didn't install python3.5 via macport but from downaloaded 
package?

sudo port install py35-numpy py35-scipy py35-matplotlib py35-ipython +notebook 
py35-pandas py35-sympy py35-nose

Thanks! I'm going through a very confused start, with too many version and too 
many commands to guess the right way of doing.

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


Re: just started

2016-12-15 Thread Chris Angelico
On Fri, Dec 16, 2016 at 3:29 PM,   wrote:
> 2) if I wish to install extra libraries, in particularly SciPy, what's best 
> way of doing it? From command line I see the following commands: pip3 and 
> pip3.5. I guess pip3.5 is for python3.5 ? Can I use pip3 and pip3.5 
> interchangeably, or pip3 will only install things for python3, and not 3.5?
>
> Are all these command equivalent?
>
> pip3 install --user numpy scipy matplotlib
> pip3.5 install --user numpy scipy matplotlib
>
> python3.5 -m pip install numpy scipy matplotlib

In theory, "pip3" will install into the default "python3", whichever
that is. However, in practice, it's entirely possible that it installs
into a very different Python from the one you're expecting. The most
reliable form is the latter; whatever command you use to start Python,
add "-m pip" to it, and you know you're talking to that same
installation.

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


Re: A routine to calc Shannon's info entropy. I'm open to improvements/suggestions.

2016-12-15 Thread Steve D'Aprano
On Fri, 16 Dec 2016 09:21 am, DFS wrote:

> Code is based on the formula and results here:
> http://www.shannonentropy.netmark.pl
[...]
> Seems to work fine.
> 
> Any suggestions to improve the code?


- Separate the calculation logic from the display logic as much
  as practical.

- Modular programming: use functions to make it easier to test and easier
  to modify the program in the future, e.g. to add command line options.

- Use standard tools where possible.

- Better, more descriptive names.

- Avoid global variables unless really needed.

- More error checking.

- Errors should exit with a non-zero return code, and should print to
  stderr rather than stdout.

You end up with about twice as much code, but hopefully it is easier to
understand, and it should certainly be easier to debug and maintain if you
decide to change it.



# --- cut ---

# only needed in Python 2
from __future__ import division

import sys
import math
import string

from collections import Counter


def fatal_error(errmsg):
# Python 3 syntax
print(errmsg, file=sys.stderr)
## Python 2 syntax
## print >>sys.stderr, errmsg
sys.exit(1)


def display_header(msg):
print()
print("%s characters in '%s'" % (len(msg), msg))
print()
print(" #   Char  Freq   DistD*log2(D)  H(X) sum")
print("---      --  --  --")


def display_row(row_number, c, freq, dist, entropy, running_total):
args = (row_number, c, freq, dist, entropy, running_total)
template = "%3d  %-4c  %4d  %6.3f  %10.3f  %10.5f"
print(template % args)


def entropy(c, freqs, num_symbols):
"""Return the entropy of character c from frequency table freqs."""
f = freqs[c]/num_symbols
return -f*math.log(f, 2)


def display_results(freqs, Hs, num_symbols):
"""Display results including entropy of each symbol.

Returns the total entropy of the message.
"""
# Display rows with uppercase first, then lower, then digits.
upper = sorted(filter(str.isupper, freqs))
lower = sorted(filter(str.islower, freqs))
digits = sorted(filter(str.isdigit, freqs))
assert set(upper + lower + digits) == set(freqs)
count = 1
running_total = 0.0
for chars in (upper, lower, digits):
for c in chars:
f = freqs[c]
H = Hs[c]
running_total += H
display_row(count, c, f, f/num_symbols, H, running_total)
count += 1
total = running_total
print()
print("The Shannon entropy of your message is %.5f" % total)
print("The metric entropy of your message is %.5f"% (total/num_symbols))
return total


def main(args=None):
if args is None:
args = sys.argv[1:]
if len(args) != 1:
fatal_error("too many or too few arguments")
msg = args[0]
if not msg.isalnum():
fatal_error("only alphanumeric symbols supported")
display_header(msg)
frequencies = Counter(msg)
num_symbols = len(msg)
# Calculate the entropy of each symbol and the total entropy.
entropies = {}
for c in frequencies:
H = entropy(c, frequencies, num_symbols)
entropies[c] = H
total = display_results(frequencies, entropies, num_symbols)



if __name__ == "__main__":
# Only run when module is being used as a script.
main()


# --- cut ---





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

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