Re: The "loop and a half"

2017-10-05 Thread Gregory Ewing

Steve D'Aprano wrote:

I recall that the Pascal compiler had to do some clever behind the scenes
jiggery-pokery to get eof() to work, but that's what compilers are supposed
to do: make common tasks easy for the programmer.


Sometimes the jiggery-pokery worked, sometimes it didn't.
For example, the following wouldn't work as expected:

   while not eof(input) do begin
  write(output, 'Enter something:');
  readln(input, buffer);
  process(buffer);
   end

because the eof() would block waiting for you to enter
something, so the prompt wouldn't get printed at the
right time.

Basically, Pascal's eof-flag model was designed for
batch processing, and didn't work very well for
interactive use.

Unix and Windows sidestep the issue by not trying to
pretend you can detect EOF independently of reading
data, but using that model gracefully requires a
loop-and-a-half.

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


Re: The "loop and a half"

2017-10-05 Thread Peter Otten
Stefan Ram wrote:

> bartc  writes:
>>Note that your reverse-indentation style is confusing!
> 
>   In Python, indentation can be significant.
> 
>   Sometimes, some lines in Python must be indented by 0.

Are there any editors that do not support a dedent operation?
In the interactive interpreter you can work around

print("Oh my god, this won't run!")

with

>>> if "heureka":
... print("Oh my god, this won't run!")
... 
Oh my god, this won't run!
 
>   This dictates that Python code cannot be indented
>   in posts to differentiate it from the natural-language
>   body of the post. Therefore, it's rather the
>   natural-language body that has to be indented.

That appears compelling. Can you find a flaw in the logic?

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


Re: The "loop and a half"

2017-10-05 Thread Chris Angelico
On Thu, Oct 5, 2017 at 5:59 PM, Peter Otten <[email protected]> wrote:
>>   This dictates that Python code cannot be indented
>>   in posts to differentiate it from the natural-language
>>   body of the post. Therefore, it's rather the
>>   natural-language body that has to be indented.
>
> That appears compelling. Can you find a flaw in the logic?
>

It assumes that the Python code and the English code are completely
independent. If they are not, and if (as is very common) the Python is
logically nested inside the English, then according to the rules of
both languages, the Python code should be indented.

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


Re: Lies in education [was Re: The "loop and a half"]

2017-10-05 Thread Thomas Jollans
On 2017-10-05 06:24, Steve D'Aprano wrote:
> On Thu, 5 Oct 2017 02:14 pm, Stefan Ram wrote:
> 
>> Chris Angelico  writes:
>>> You can get through a lot of life believing that mass is conserved,
>>> but technically it is not, as can be proven.
>>
>>   Well, in fact, it is conserved.
> 
> It certainly is not. The whole point of Einstein's equation E = mc² is that
> energy and mass are freely convertible. Neither energy nor mass alone are
> conserved.

You're both right, you're just defining "mass" in different ways.


> 
> 
>>   When an electron and a positron annihilate to give a gas of
>>   two photons, this gas as a whole still has the same mass as
>>   the electron before. And its center of gravity moves with
>>   less than c.
> 
> That doesn't sound like any description of matter/anti-matter annihilation
> I've every seen before.
> 
> I think you may be conflating the concepts of clouds of virtual
> electron/positron particles with actual annihilation events between real
> electron/positron particles.
> 
> In actual annihilation events, there is (as far as I know) generally a single
> real photon produced, with momentum equal to the sum of the momentum vectors
> of the original electron and positron. That moves away from the point of
> production at the speed of light.
> 
> 
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multithreaded compression/decompression library with python bindings?

2017-10-05 Thread Thomas Nyberg
On 10/04/2017 05:08 PM, Steve D'Aprano wrote:
> pbip2? Never heard of it, and googling comes up with nothing relevant.
> 
> Got a link?

Sorry it was a typo as Paul Moore said. pbzip2 is a parellelized
implementation of bzip2:

http://compression.ca/pbzip2/

> Why obviously?

Sorry again. I certainly shouldn't have said obviously. In fact, I may
be wrong. However, due to the fact that the compression algorithms are
almost entirely CPU-bound, I would be impressed if someone managed to
parallelize it within python itself due to the gil etc. But I don't want
to discount the possibility. In my experience many people throw their
hands up too early and decide something is impossible due to the gil
even when it's not. (As apparently I did...)

Basically here's the gist of the problem (at least as I understand it).
The way that bzip2 works is that it breaks data into blocks of a certain
size and then compresses those blocks individually. This effectively
makes the operation embarrassingly parallel on these blocks. The pbzip2
program takes advantage of this and does the compression and
decompression in parallel on these blocks leading to an almost linear
speedup in the number of cpus available. Both the inputs and outputs of
bzip2 and pbzip2 are compatible, though to gain the speedup the files
must be compressed with pbzip2. (I.e. for some reason pbzip2 cannot
decompress a file in parallel if it's been compressed with bzip2. There
is apparently some freedom in the object format. I'm not totally sure
why this is.)

I did some work on this yesterday so I'll put in the code I've gotten so
far which mostly works (I have an issue with waiting on a subprocess as
explained below). Also I'm running debian and using that heavily so I
presume nothing here works on Windows (sorry :( ).

In my case what I essentially wanted was just a very simple "compressed
archiver". I.e. a bzip2-compressed tar archive that I could fill up in
one pass and read from in one pass. I already had one using python's bz2
module, but I wanted a parallel version. The version I came up with is
the following (which is essentially what Stephen Houben was proposing):


pbz2.py

import io
import tarfile
from subprocess import Popen, PIPE


class Archive:
def __init__(self, filepath, mode="r"):
assert mode in {"r", "w"}
if mode == "r":
self._p = Popen(["pbzip2", "-dc", filepath], stdout=PIPE)
self._tar = tarfile.open(filepath, mode="r|",
fileobj=self._p.stdout)
# Seems like an odd way to do this, but works for now.
def tar_yielder():
for tarinfo in self._tar:
file_name = tarinfo.name
file_bytes = self._tar.extractfile(tarinfo).read()
file_contents = file_bytes.decode('utf-8')
yield file_name, file_contents
self._tar_yielder = tar_yielder()
else:
self._p = Popen(["pbzip2", "-zc"], stdin=PIPE,
stdout=open(filepath, "w"))
self._tar = tarfile.open(filepath, mode="w|",
fileobj=self._p.stdin)
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
def __iter__(self):
return self
def __next__(self):
return next(self._tar_yielder)
def write(self, file_name, file_contents):
file_contents = file_contents.encode('utf-8')
# The tar archiver requires file objects.
bytesstring = io.BytesIO(file_contents)
info = tarfile.TarInfo(name=file_name)
info.size=len(bytesstring.getbuffer())
self._tar.addfile(tarinfo=info, fileobj=bytesstring)
def close(self):
self._tar.close()


You could use it as follows:


with Archive("archive.tar.bz2", mode="w") as outfile:
outfile.write("file1", "file 1 contents")
outfile.write("file2", "file 2 contents")
outfile.write("file3", "file 3 contents")


And then can iterate this way:


with Archive("archive.tar.bz2") as infile:
for file_name, file_contents in infile:
print(file_name)
print(file_contents)


One problem though is that I have to run those two parts as two
_separate_ scripts. Otherwise I get errors from pbzip2. I'm pretty sure
it's a race condition. I.e. when the first archive finishes, it is not
waiting on the subprocess and so the second archive may try to iterate
before that part is finished. Does anyone here know the best way to wait
on the subprocess? Naively the right things seems to be to add a wait in
to the close method as follows:


def close(self):
self._tar.close()
self._p.wait()


Howe

Re: OT I before E [was Re: Lies in education [was Re: The "loop and a half"]]

2017-10-05 Thread Thomas Jollans
On 2017-10-05 06:47, Steve D'Aprano wrote:
> On Thu, 5 Oct 2017 02:54 pm, Chris Angelico wrote:
>> (There are exceptions even to the longer form of the rule, but only a
>> handful. English isn't a tidy language.)
> 
> Even with the longer version of the rule, there are so few applicable cases,
> and enough difficulty in applying the rule correctly, that the rule is not
> worth the breath it takes to say it.

Maybe we should just all switch to Dutch on this list. Might be easier.
Certainly more consistent.


groetjes
Thomas


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


Re: Multithreaded compression/decompression library with python bindings?

2017-10-05 Thread Thomas Nyberg
Btw if anyone knows a better way to handle this sort of thing, I'm all
ears. Given my current implementation I could use any compression that
works with stdin/stdout as long as I could sort out the waiting on the
subprocess. In fact, bzip2 is probably more than I need...I've half used
it out of habit rather than anything else.

I do personally really like the convenience of this compressed tar
archive format since I can just grab the files and run `tar xf filename`
in a terminal and get them all back again, but if there's an entirely
different and better way which allows me to stream in my fashion, I'm
certainly curious to hear about it.

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


Re: The "loop and a half"

2017-10-05 Thread Chris Angelico
On Thu, Oct 5, 2017 at 1:36 PM, Stefan Ram  wrote:
> Steve D'Aprano  writes:
>>If you were teaching people to drive a car, would you insist on teaching them
>>how to pull out and rebuild the engine before sitting them in the drivers
>>seat?
>
>   If I would have to teach people to drive a car, I would
>   exercise with them how to move the steering wheel to control
>   the direction, how to change gears, how to look over the
>   shoulder to check the blind spot, and I would first exercise
>   each of these actions /in isolation/ at a quiet training
>   area, before the people then possible have to do several of
>   these actions at the same time in real road traffic.

But you wouldn't dig down into the more concrete level of what
actually happens when you change gears (explaining both automatic AND
manual transmission, for completeness). You'd just say "change gears
by moving this thingy over to there".

(Caveat: I don't drive a car. Experienced drivers probably don't call
the thingy a thingy, they probably call it a gear lever or something
boring like that.)

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


Re: Easier way to do this?

2017-10-05 Thread Fabien

On 10/05/2017 12:00 AM, Thomas Jollans wrote:

On 04/10/17 22:47, Fabien wrote:

On 10/04/2017 10:11 PM, Thomas Jollans wrote:

Be warned, pandas is part of the scientific python stack, which is
immensely powerful and popular, but it does have a distinctive style
that may appear cryptic if you're used to the way the rest of the world
writes Python.

Can you elaborate on this one? As a scientist, I am curious;-)

Sure.

Python is GREAT at iterating. Generators are everywhere. Everyone loves
for loops. List comprehensions and generator expressions are star
features. filter and map are builtins. reduce used be a builtin, even
though almost nobody really understood what it did.

In [1]: import numpy as np

In the world of numpy (and the greater scientific stack), you don't
iterate. You don't write for loops.


Right, now I see what you meant. The first thing I teach to my students 
is that loops are evil, and that they should always avoid them when 
possible ;-)


Cheers,

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


Re: The "loop and a half"

2017-10-05 Thread bartc

On 05/10/2017 07:57, Gregory Ewing wrote:

Steve D'Aprano wrote:

I recall that the Pascal compiler had to do some clever behind the scenes
jiggery-pokery to get eof() to work, but that's what compilers are 
supposed

to do: make common tasks easy for the programmer.


Sometimes the jiggery-pokery worked, sometimes it didn't.
For example, the following wouldn't work as expected:

    while not eof(input) do begin
   write(output, 'Enter something:');
   readln(input, buffer);
   process(buffer);
    end

because the eof() would block waiting for you to enter
something, so the prompt wouldn't get printed at the
right time.

Basically, Pascal's eof-flag model was designed for
batch processing, and didn't work very well for
interactive use.


This doesn't make sense. For interactive use, you wouldn't bother 
testing for eof, as you'd be testing the eof status of the keyboard.


You might want a way of the user indicating end-of-data, but that's 
different; you don't want to abruptly send an EOF (via Ctrl-C, D, Z, 
Break or whatever). That would be a crass way of doing it. Besides you 
might want to continue interacting with the next part of the program.


So the loop would be like this (Python 3; don't know why it doesn't work 
in Python 2):


while 1:
buffer = input("Enter something (Type quit to finish): ")
if buffer == "quit": break
print ("You typed:", buffer) # process(buffer)

print ("Bye")

This is a loop-and-a-half.

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


Re: The "loop and a half"

2017-10-05 Thread Chris Angelico
On Thu, Oct 5, 2017 at 9:56 PM, bartc  wrote:
> This doesn't make sense. For interactive use, you wouldn't bother testing
> for eof, as you'd be testing the eof status of the keyboard.

You mean the way heaps and heaps of Unix programs work, processing
until EOF of stdin? Yeah, totally makes no sense, man, no sense at
all.

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


How do native namespaces work?

2017-10-05 Thread Thomas Nyberg
Hello,

I'm trying to understand native namespaces. I'm currently using python
3.5 as packaged in debian 9. I've been following the instructions here:


https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages

Those instructions link to the following example:

https://github.com/pypa/sample-namespace-packages/tree/master/native

I presume I'm doing something silly, but I can't get that to work. I've
tried creating a virtual environment as:

--
$ python3 -m venv venv
$ source venv/bin/activate
--

And then I've gone into those repo folders and run their setup.py files
(e.g. for namespace a):

--
$ cd sample-namespace-packages/native/pkg_a/
$ python3 setup.py install
--

Then if I try to run their sample verification file, things fail:

--
$ cat sample-namespace-packages/verify_packages.py
from example_pkg import a
from example_pkg import b

print(a.name)
print(a.__path__)
print(b.name)
print(b.__path__)
$ python3 sample-namespace-packages/verify_packages.py
Traceback (most recent call last):
  File "sample-namespace-packages/verify_packages.py", line 1, in 
from example_pkg import a
ImportError: No module named 'example_pkg'
--

Things seem to be installing:

--
$ ls venv/lib/python3.5/site-packages/
easy-install.pth   pkg_resources
easy_install.pypkg_resources-0.0.0.dist-info
example_pkg_a-1-py3.5.egg  __pycache__
example_pkg_b-1-py3.5.egg  setuptools
pipsetuptools-32.3.1.dist-info
pip-9.0.1.dist-info
--

Am I missing something totally obvious here? Does anyone here see what
I'm doing wrong? Thanks for any help!

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


Re: Lies in education [was Re: The "loop and a half"]

2017-10-05 Thread Marko Rauhamaa
[email protected] (Stefan Ram):

>   Some of you are experts in Python, but are only
>   half-educated when it comes to physics, C++ or other topics.
>   I wish those persons would not broadcast their
>   half-knowledge in the form of confident statements,

I don't wish that. That would only establish priesthoods and be an
obstacle to learning.

>   and I wish they would talk about those subjects in their
>   appropriate newsgroups. (For example, one can ask questions
>   about physics in "sci.physics.research".)

That's good advice, but it's not all that dangerous to express off-topic
statements in this newsgroup.


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


Re: newb question about @property

2017-10-05 Thread Gregory Ewing

bartc wrote:
Result? You can't just look at my 'any' class and see what fields it 
uses. You can't even just look at the static source code. You have to 
run the program to find out. And it might be different each time.


You can usually get a pretty good idea of what attributes a
class has by looking at its definition. The vast majority of
classes will either initialise their attributes in the __init__
method or provide defaults as class variables.

While in theory it's possible for code to add attributes
later after initialisation, in practice this is hardly ever
done.

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


Re: The "loop and a half"

2017-10-05 Thread bartc

On 05/10/2017 12:09, Chris Angelico wrote:

On Thu, Oct 5, 2017 at 9:56 PM, bartc  wrote:

This doesn't make sense. For interactive use, you wouldn't bother testing
for eof, as you'd be testing the eof status of the keyboard.


You mean the way heaps and heaps of Unix programs work, processing
until EOF of stdin? Yeah, totally makes no sense, man, no sense at
all.


Out of the hundreds, perhaps thousands of such input loops I must have 
written, how many needed to test EOF? Hmm, somewhere around zero I think.


Oh hang on, I wasn't using Unix; does that make a difference?

If you're referring to the ability to redirect stdin so that input can 
come from a file as well as from a live keyboard, then you're doing file 
handling; it's NOT interactive.


(And I've used such programs where you get no prompt as to what to type, 
or how to finish, and you just blindly press Ctrl C, Ctrl D, Ctrl Z or 
Ctrl Break in turn until it stops. Really friendly. Because the program 
reads from stdin but assumes it comes a from a file or pipe anyway.)


Note that Unix way isn't the ONLY way of doing things.

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


Re: newb question about @property

2017-10-05 Thread bartc

On 05/10/2017 12:29, Gregory Ewing wrote:

bartc wrote:
Result? You can't just look at my 'any' class and see what fields it 
uses. You can't even just look at the static source code. You have to 
run the program to find out. And it might be different each time.


You can usually get a pretty good idea of what attributes a
class has by looking at its definition. The vast majority of
classes will either initialise their attributes in the __init__
method or provide defaults as class variables.

While in theory it's possible for code to add attributes
later after initialisation, in practice this is hardly ever
done.


Yeah, but, like many other things in this language, there are million 
ways of doing it.


Just had a quick look, the first hit was talking about using a module 
'pyrecord'.


Another mentioned 'namedtuples'.

Another used the '__slots__' method already mentioned (remembering the 
difference between old and new classes in Python 2...)


One more uses a module 'recordtype'.

And then there is just using a normal class, where you have to look 
closely at the code to see what it's implementing. It allow ad-hoc 
fields to be created, or it may define __init__ etc.


And all with different capabilities regarding adding extra fields, 
having mutable records, initialising a record, comparing them, printing 
them, 


Am I allowed to say that it all seems a bit of a mess?


--
bartc

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


Re: Python-list Digest, Vol 169, Issue 7

2017-10-05 Thread ROGER GRAYDON CHRISTMAN
On Wed, Oct 4, 2017 22:42 Stefan Ram ([email protected]) wrote:
>
Steve D'Aprano  writes:
>>So, "bottom-up" in this case means: iterators should be
>>taught before for-loops.
>>Why? 
>
>  The syntax for is (from memory):
>
>for  in : 
>
>  . As an example, I might show:
>
>for i in range( 3 ): ...
>
>  . This raises the question:
>
>  "What is the value of ?range( 3 )??".
>
>  "Bottom up" means that the simple and constituent parts
>  are taught before the complex and compound parts. I.e.,
>  ?range( 3 )? is explained before ?for i in range( 3 ):?.
>
>


The easy answer here is to not use the range in the first for loop.

I introduce for with actual collections  (e.g. lists, strings, dictionaries)

It is very easy to figure out what  "for i in [2, 6,32, 7, 5]" means.

This is very easy to understand, and I teach it early, to avoid this common
error:

"if i == 2 or 6 or 32 or 7 or 5"

which plagues Python and C programmers alike (only Java complains about that
one)

You can even access the proper subscripts for a list without using range(),
if you are willing to use enumerate().  

So, by teaching the for loop without the range, not only do you get to postpone
the details of what range() does   (and can even point out -- hey, that's
exactly
the same numbers as enumerate listed!)   but you also get your students to
believe that there is a better way to access the elements of a list than
counting
down the subscripts.

I still see a lot of instructors and programmers who newly migrate to Python
that use counting a range() as their first choice in traversing a list.
Teaching the for loop without using range, I believe, is the best way 
to forestall that habit.

Oh, and it also steers people from this error I often see:
"for i in len(list)"

Roger Christman
Pennsylvania State University


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


Re: newb question about @property

2017-10-05 Thread Steve D'Aprano
On Thu, 5 Oct 2017 10:51 pm, bartc wrote:

> Am I allowed to say that it all seems a bit of a mess?


You may or may not be pleased to learn that there's a push to create a "record
like" or "struct like" datatype for Python 3.7 or 3.8, tentatively called
a "Data Class" for now.

The proposed syntax will use class syntax, to make it easy to add methods. For
example:


@dataclass
class InventoryItem:
name: str
unit_price: float
quantity_on_hand: int = 0

def total_cost(self) -> float:
return self.unit_price * self.quantity_on_hand


which will fill in the boilerplate for you:

- an appropriate initialiser __init__

- a good-looking __repr__

- equality, inequality, and rich comparison operators;

- an optional __hash__ method.



https://www.python.org/dev/peps/pep-0557/



-- 
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: Introducing the "for" loop

2017-10-05 Thread Peter Otten
Stefan Ram wrote:

> "ROGER GRAYDON CHRISTMAN"  writes:
>>On Wed, Oct 4, 2017 22:42 Stefan Ram ([email protected]) wrote:
>>Steve D'Aprano  writes:
So, "bottom-up" in this case means: iterators should be
taught before for-loops.
Why?
>>The easy answer here is to not use the range in the first for loop.
> 
>   I never intended to use »range«. But I also will not use lists.
> 
>   Very early in the course, I teach numeric and string literals:
> 
> 1, 2.3, 'abc'
> 
>   then come operators, functions and »if«, »while« and »try«.
>   But neither »range« nor lists have been shown so far.
> 
>   The basic course may already and there after about 12 - 18 hours.
>   (This time includes many exercises in the classroom.)
> 
>   But if I have time to introduce »for«, I'll do it as follows
>   at this point in the course:
> 
>   

To me it looks like Roger has some practical experience in that area.
You should seriously consider his advice lest your students end up missing 
the forest for the trees.


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


Re: How do native namespaces work?

2017-10-05 Thread Peter Otten
Thomas Nyberg wrote:

> Hello,
> 
> I'm trying to understand native namespaces. I'm currently using python
> 3.5 as packaged in debian 9. I've been following the instructions here:
> 
> https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages
> 
> Those instructions link to the following example:
> 
> https://github.com/pypa/sample-namespace-packages/tree/master/native
> 
> I presume I'm doing something silly, but I can't get that to work. I've
> tried creating a virtual environment as:
> 
> --
> $ python3 -m venv venv
> $ source venv/bin/activate
> --
> 
> And then I've gone into those repo folders and run their setup.py files
> (e.g. for namespace a):
> 
> --
> $ cd sample-namespace-packages/native/pkg_a/
> $ python3 setup.py install

Are you sure you are using the correct interpreter? When I activate a 
virtual environment it changes the prompt like so:

$ python3 -m venv venv
$ . venv/bin/activate
(venv) $ 
(venv) $ which python3
/home/peter/venv/bin/python3
(venv) $ deactivate 
$ 
$ which python3
/usr/bin/python3

> --
> 
> Then if I try to run their sample verification file, things fail:
> 
> --
> $ cat sample-namespace-packages/verify_packages.py
> from example_pkg import a
> from example_pkg import b
> 
> print(a.name)
> print(a.__path__)
> print(b.name)
> print(b.__path__)
> $ python3 sample-namespace-packages/verify_packages.py
> Traceback (most recent call last):
>   File "sample-namespace-packages/verify_packages.py", line 1, in 
> from example_pkg import a
> ImportError: No module named 'example_pkg'
> --
> 
> Things seem to be installing:
> 
> --
> $ ls venv/lib/python3.5/site-packages/
> easy-install.pth   pkg_resources
> easy_install.pypkg_resources-0.0.0.dist-info
> example_pkg_a-1-py3.5.egg  __pycache__
> example_pkg_b-1-py3.5.egg  setuptools
> pipsetuptools-32.3.1.dist-info
> pip-9.0.1.dist-info
> --
> 
> Am I missing something totally obvious here? Does anyone here see what
> I'm doing wrong? Thanks for any help!
> 
> Cheers,
> Thomas


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


Re: Easier way to do this?

2017-10-05 Thread Neil Cerutti
On 2017-10-04, 20/20 Lab  wrote:
> It's not quite a 'learning exercise', but I learn on my own if
> I treat it as such.  This is just to cut down a few hours of
> time for me every week filtering the file by hand for the
> office manager.

That looks like a 30-second job using a pivot table in Excel.
Office manager, learn thy Excel!

On the other hand, I think Python's csv module is a killer app,
so I do recommend taking the opportunity to learn csv.DictReader
and csv.DictWriter for your own enjoyment.

-- 
Neil Cerutti

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


Re: How to determine lowest version of Python 3 to run?

2017-10-05 Thread Steve D'Aprano
On Thu, 5 Oct 2017 01:23 pm, Christopher Reimer wrote:

> Greetings,
> 
> I've always installed the latest and greatest version of Python 3 to develop
> my own programs. I'm planning to release a program to the public. I could
> toss in a note that the program runs on the latest version of Python 3.6 but
> I haven't tested on earlier versions (i.e., 3.4 and 3.5). AFAIK, I haven't
> written any version-specific code.
> 
> How do I determine the lowest version of Python to run?

If you know your code uses a feature introduced in version X, then X is the
lowest version it will run in. E.g. if you use the u'' syntax for Unicode
strings, which was re-introduced in 3.3 to make it easier to write Python 2/3
compatible code, then it won't run it Python 3.1 or 3.2.


> I'm leaning towards installing the latest minor version of each available
> major version, running tox to run the unit tests against each one, and
> seeing what blows up.

That seems reasonable to me, except I think you mean latest release of each
minor version e.g.:

3.5.1 = major.minor.release

I'd also consider testing against the *earliest* release, rather than the
latest. If it works with (say) 3.5.0, then you should be safe to claim it
works for all 3.5. But if it works for 3.5.4, say, you aren't *quite* so safe
to make the same claim.



-- 
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: How do native namespaces work?

2017-10-05 Thread Thomas Nyberg
On 10/05/2017 04:07 PM, Peter Otten wrote:
> Are you sure you are using the correct interpreter? When I activate a 
> virtual environment it changes the prompt like so:

Sorry I just cut out the extra cruft from my prompt for clarity. (In
hindsight, I should probably have left the `(venv)` prompt in my cleaned
up prompt...) The venv was definitely activated (and in fact I tried again).

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


Re: Easier way to do this?

2017-10-05 Thread 20/20 Lab

On 10/05/2017 07:28 AM, Neil Cerutti wrote:

On 2017-10-04, 20/20 Lab  wrote:

It's not quite a 'learning exercise', but I learn on my own if
I treat it as such.  This is just to cut down a few hours of
time for me every week filtering the file by hand for the
office manager.

That looks like a 30-second job using a pivot table in Excel.
Office manager, learn thy Excel!

On the other hand, I think Python's csv module is a killer app,
so I do recommend taking the opportunity to learn csv.DictReader
and csv.DictWriter for your own enjoyment.

It would be if our practice management software would export to excel, 
or even a realistic csv.  Problem is that it only exports to csv and 
it's 80-90% garbage and redundant information.  I've taken to bringing 
the csv into excel and refining it so I can do that, but again.  I'd 
rather take half a second and have a program do it for me.  ;)

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


Re: Easier way to do this?

2017-10-05 Thread 20/20 Lab



On 10/04/2017 04:48 PM, Dennis Lee Bieber wrote:

On Wed, 4 Oct 2017 09:42:18 -0700, 20/20 Lab  declaimed
the following:

Well -- since your later post implies this is not some "homework
assignment"...


Looking for advice for what looks to me like clumsy code.

EMP1 = [0,0]
EMP2 = [0,0]
EMP3 = [0,0]


EEEK! Don't do that! Especially as...


for line in (inputfile):
     content = line.split(",")

You've already been told to use the CSV module, since it should handle
tricky cases (quoted strings with embedded commas, say).


     if content[18] == "EMP1":

... the name is part of the input data. Use a data structure in which the
name is part of the data -- like a dictionary.


     if float(content[24]) < 99.75:
     EMP1[0] += 1
     elif float(content[24]) > 99.74:
     EMP1[1] += 1

Pardon? Floating point numbers are not exact... It is possible that
some entry, in floating binary, is really between 99.75 and 99.74, so which
should it be counted as? At the least, just use an else: for the other
case.



employees = {}
for row in csvfile: #pseudo-code for however you read each row of data

emp = employees.get(content[18], [0, 0])
if float(content[24]) < 99.75
emp[0] += 1
else:
emp[1] += 1
employees[content[18]] = emp



and repeat if statements for the rest of 25+ employees.  I can make a
list of the employees, but I'd prefer to pull them from the csv, as our
turnover is rather high (however this is not important).  I'm thinking
another "for employee in content[18]" should be there, but when I tried,
my numbers were incorrect.

Actually -- I'd be more likely to load the data into an SQLite3
database, and use SQL queries to produce the above summary report. I'd have
to experiment with subselects to get the > and < sets, and then use a
count() and groupby to put them in order.
Thanks!  I knew there was an more refined way to do this.  I'm still 
learning, so this is a huge help.
The data actually already comes from a database, but doesnt allow me to 
produce a summary report, just a list of of each item.  Which I can then 
export to pdf, or the csv that I'm working with.  The developers have a 
ticket for a feature request, but they've had it there for over five 
years and I dont see them implementing it anytime soon.

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


Re: Easier way to do this?

2017-10-05 Thread 20/20 Lab



On 10/04/2017 05:11 PM, Irv Kalb wrote:

I'm assuming from your posts that you are not a student.  If that is the case, 
look at my solution below.


On Oct 4, 2017, at 9:42 AM, 20/20 Lab  wrote:

Looking for advice for what looks to me like clumsy code.

I have a large csv (effectively garbage) dump.  I have to pull out sales 
information per employee and count them by price range. I've got my code 
working, but I'm thinking there must be a more refined way of doing this.

---snippet of what I have---

EMP1 = [0,0]
EMP2 = [0,0]
EMP3 = [0,0]

for line in (inputfile):
 content = line.split(",")
 if content[18] == "EMP1":
 if float(content[24]) < 99.75:
 EMP1[0] += 1
 elif float(content[24]) > 99.74:
 EMP1[1] += 1
 if content[18] == "EMP2":
 if float(content[24]) < 99.75:
 EMP2[0] += 1
 elif float(content[24]) > 99.74:
 EMP2[1] += 1
 if content[18] == "EMP3":
 if float(content[24]) < 99.75:
 EMP3[0] += 1
 elif float(content[24]) > 99.74:
 EMP3[1] += 1

and repeat if statements for the rest of 25+ employees.  I can make a list of the 
employees, but I'd prefer to pull them from the csv, as our turnover is rather high 
(however this is not important).  I'm thinking another "for employee in 
content[18]" should be there, but when I tried, my numbers were incorrect.

Any help / advice is appreciated,

Matt



You could certainly use the csv module if you want, but this builds on your 
start of dealing with the data line by line.

Completely untested, but this approach works by building a dictionary on the 
fly from your data.  Each key is an employee name.  The data associated with 
each key is a two item list of counts.


# Constants
NAME_INDEX = 18
SALES_INDEX = 24
THRESHHOLD = 99.75

salesCountDict = {}  # start with an empty dict

for line in (inputfile):
 content = line.split(",")  # split the line into a list
 name = content[NAME_INDEX]  # extract the name from the content list

 # If we have not seen this employee name before, add it to the dictionary
 # like key value pair: '': [0, 0]
 if not(name in employeeDataDict):
 salesCountDict[name] = [0, 0]

 price = float(content[SALES_INDEX])  # extract the price

# If the price is under some threshhold, increment one value in the 
associated sales list
# otherwise increment the other
 if price < THRESHHOLD:
 salesCountDict[name][0] += 1
 else:
 salesCountDict[name][1] += 1
 


# Now you should have a dictionary.  Do what you want with it.  For example:

for name in salesCountDict:
 salesList = salesCountDict[name]
 print(name, salesList)# Assuming Python 3

 
 



Thanks for this.  I've recently had a hard time discerning when to use / 
the differences of the dict, list, set, tuple.  So this is a huge help.

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


Re: The "loop and a half"

2017-10-05 Thread Grant Edwards
On 2017-10-05, bartc  wrote:

> Note that Unix way isn't the ONLY way of doing things.

Of course not, but it is the CORRECT way of doing things.

:)

-- 
Grant Edwards   grant.b.edwardsYow! Am I in GRADUATE
  at   SCHOOL yet?
  gmail.com

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


type and object

2017-10-05 Thread Naveen Yadav
Hi folks,


>> isinstance(type, object) is True   # 1
and
>> isinstance(object, type) is True   # 2


its means type is object is type, But i am not sure how is this.

For what i can understand is 
for #1: since every thing is object in python, type is also an object.
and 
for #2: object is a base type. therefore object is type
>> object.__doc__
>> 'The most base type'


Am I understanding this correct ? Please shed light on this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The "loop and a half"

2017-10-05 Thread Chris Angelico
On Thu, Oct 5, 2017 at 10:26 PM, bartc  wrote:
> On 05/10/2017 12:09, Chris Angelico wrote:
>>
>> On Thu, Oct 5, 2017 at 9:56 PM, bartc  wrote:
>>>
>>> This doesn't make sense. For interactive use, you wouldn't bother testing
>>> for eof, as you'd be testing the eof status of the keyboard.
>>
>>
>> You mean the way heaps and heaps of Unix programs work, processing
>> until EOF of stdin? Yeah, totally makes no sense, man, no sense at
>> all.
>
>
> Out of the hundreds, perhaps thousands of such input loops I must have
> written, how many needed to test EOF? Hmm, somewhere around zero I think.
>
> Oh hang on, I wasn't using Unix; does that make a difference?
>
> If you're referring to the ability to redirect stdin so that input can come
> from a file as well as from a live keyboard, then you're doing file
> handling; it's NOT interactive.

How would you write a sort program? How would you tell it that you're
done entering data?

And yes, I have used sort(1) interactively, with no redirection whatsoever.

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


Re: type and object

2017-10-05 Thread Chris Angelico
On Fri, Oct 6, 2017 at 3:17 AM, Naveen Yadav  wrote:
> Hi folks,
>
>
>>> isinstance(type, object) is True   # 1
> and
>>> isinstance(object, type) is True   # 2
>
>
> its means type is object is type, But i am not sure how is this.
>
> For what i can understand is
> for #1: since every thing is object in python, type is also an object.
> and
> for #2: object is a base type. therefore object is type
>>> object.__doc__
>>> 'The most base type'
>
>
> Am I understanding this correct ? Please shed light on this.

Yep :) Everything's an object, everything has a type, every type has
an object. The hierarchy has a little loop in it at the top.

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


Pedagogical style [was Re: The "loop and a half"]

2017-10-05 Thread Steve D'Aprano
On Thu, 5 Oct 2017 07:29 am, Christian Gollwitzer wrote:

> To understand Stefan's way of teaching, take a look at his other
> courses, for example the C++ course:

Thanks for this Christian. It has been an eye-opener. More comments below.

 
> http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/c++-kurs
> 
> He defends the opinion that you learn a programming language best by
> studying syntax diagrams. He even writes in his FAQ about the language 
> courses:
> http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/faq_programmieren
> 
> "Neuere Forschungen haben gezeigt, daß es erfolgreicher ist, formale
> Systeme (wie Programmiersprachen oder Mathematik) zu unterrichten, wenn
> dabei kein künstlicher „Praxisbezug“ durch “real-world examples”
> (Beispiele aus dem „wahren Leben“) hergestellt wird!"
> 
> which means
> 
> "Recent research results show that it is more successful, to teach
> formal systems (like programming language or maths), if no artificial 
> practical use-case is demonstrated by "real-world examples" with a
> reference: "They said students who were taught abstract math concepts
> fared better in experiments than those taught with real-world examples,
> such as story problems.
> 
> Adding extraneous details makes it hard for students to extract the
> basic mathematical concepts and apply them to new problems, they said.
> 
> "We're really making it difficult for students because we are
> distracting them from the underlying math," said Jennifer Kaminski, a
> research scientist at Ohio State University, whose study appears in the
> journal Science.Reuters, 25. April 2008"

There's no link to the original paper, only to secondary sources that discuss
it, e.g.:

http://phys.org/pdf128266927.pdf

so I cannot really judge the quality of the paper. It might be good, it might
be full of holes, there's no way to tell.

But even if it appears really good, until it is replicated, a single paper --
especially one which claims to overturn decades of teaching experience and
convention -- should not be treated as anything more than *possibly*
suggestive. It certainly should not be treated as a proven fact.

Unfortunately, most scientific papers are wrong:

https://phys.org/news/2016-10-scientific-wrong.html

http://journals.plos.org/plosmedicine/article?id=10.1371/journal.pmed.0020124

The above is written from the perspective of a medical researcher, but the
general conclusion holds across all the sciences, even more so for soft
sciences like educational studies. Until the Kaminski study is replicated,
our default assumption should be that it is "wrong", or at least that it
doesn't generalise beyond the narrow examples tested in the study.

The most obvious potential/hypothetical objection is, this study seems to go
against the phenomenon that most people do poorly at abstract reasoning, the
more abstract, the less well they do, but pose the same problem in concrete
terms and they do much better.[1] This study implies the opposite should be
the case, and I find that implausible.

In my own experience in teaching maths, I can see some of the issues the
Kaminski study discusses: e.g. the majority of my students find it difficult
to generalise from one or three examples to a general principle, or to apply
a principle from one area to another.

(E.g. students who have successfully mastered Pythagoras' Theorem in the
context of geometry, will nevertheless often fail to apply it in the context
of trigonometry problems.)

I would never expect the majority of my students to generalise from a handful
of concrete examples to a general principle, but my experience strongly
suggests that concrete examples can and do aid in understanding general
principles.

The fact that this study found the opposite, that concrete examples
*suppressed* understanding, is so counter to my experience (including my own
learning style) that I feel very skeptical about its results.

Nevertheless, the study is interesting and necessary.

Even if the study turns out to be correct, or mostly correct, or even partly
correct, there is still a big gulf between what the study shows and Stefan's
teaching style:

(1) Programming in Python is NOT a formal system. Most programming isn't, and
Python *in particular* is further away from the mathematical purity of (say)
Haskell. There is a reason why we talk about "software engineering" and
why "computer science" is so little like a science.


(2) Kaminski's conclusion is:

"We really need to strip these concepts down to very symbolic
representations such as variables and numbers," she said. "Then 
students are better prepared to apply those concepts in a
variety of situations."

But she is talking specifically about symbolic maths here, not programming.
There's no reason to think that even if she is right about maths, that the
same will apply to teaching programming skills. Different skill sets require
different approaches to teaching.


(3) Stefan's so-called "bottom up" approach i

Re: type and object

2017-10-05 Thread Steve D'Aprano
On Fri, 6 Oct 2017 03:17 am, Naveen Yadav wrote:

> Hi folks,
> 
> 
>>> isinstance(type, object) is True   # 1
> and
>>> isinstance(object, type) is True   # 2
> 
> 
> its means type is object is type, But i am not sure how is this.

No. type and object are not the same thing:


py> type is object
False
py> id(type), id(object)
(2, 3)

(You may get different numbers if you call id() on your system. Remember that
id() returns an opaque ID number. What matters is that they are different,
not the specific values.)

> For what i can understand is
> for #1: since every thing is object in python, type is also an object.

Correct. type is an instance of object:

py> isinstance(type, object)
True

But type is also a subclass of object:

py> issubclass(type, object)
True

That means if we ask type what its superclasses are, object will be included
in the list of parent classes (superclasses):

py> type.__mro__
(, )


> and
> for #2: object is a base type. therefore object is type

No. That doesn't mean that object is type. It just means all objects inherit
from object, including type.

type and object are special, because object is also an instance of type!

py> isinstance(type, object)
True
py> isinstance(object, type)
True

So which came first? If type is an instance of object, then object must have
came first; but if object is an instance of type, then type must have come
first. Paradox!

The answer to this paradox is that type is special, and the Python interpreter
creates type before anything else. Once type is boot-strapped, then object
can be created, and then type can be turned into an object instance. All the
magic happens inside the interpreter.

This is one of the more brain-melting parts of Python, but don't worry about
it. In practice, you almost never need to care about it.



-- 
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: How do native namespaces work?

2017-10-05 Thread Peter Otten
Thomas Nyberg wrote:

> Hello,
> 
> I'm trying to understand native namespaces. I'm currently using python
> 3.5 as packaged in debian 9. I've been following the instructions here:
> 
> https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages
> 
> Those instructions link to the following example:
> 
> https://github.com/pypa/sample-namespace-packages/tree/master/native
> 
> I presume I'm doing something silly, but I can't get that to work. I've
> tried creating a virtual environment as:
> 
> --
> $ python3 -m venv venv
> $ source venv/bin/activate
> --
> 
> And then I've gone into those repo folders and run their setup.py files
> (e.g. for namespace a):
> 
> --
> $ cd sample-namespace-packages/native/pkg_a/
> $ python3 setup.py install
> --
> 
> Then if I try to run their sample verification file, things fail:
> 
> --
> $ cat sample-namespace-packages/verify_packages.py
> from example_pkg import a
> from example_pkg import b
> 
> print(a.name)
> print(a.__path__)
> print(b.name)
> print(b.__path__)
> $ python3 sample-namespace-packages/verify_packages.py
> Traceback (most recent call last):
>   File "sample-namespace-packages/verify_packages.py", line 1, in 
> from example_pkg import a
> ImportError: No module named 'example_pkg'
> --
> 
> Things seem to be installing:
> 
> --
> $ ls venv/lib/python3.5/site-packages/
> easy-install.pth   pkg_resources
> easy_install.pypkg_resources-0.0.0.dist-info
> example_pkg_a-1-py3.5.egg  __pycache__
> example_pkg_b-1-py3.5.egg  setuptools
> pipsetuptools-32.3.1.dist-info
> pip-9.0.1.dist-info
> --
> 
> Am I missing something totally obvious here? Does anyone here see what
> I'm doing wrong? Thanks for any help!

For me it's failing in the same way. I then tried 

pip install path/to/pkg_a

which works. Comparing the site-packages directories gave

added example_pkg/a/__init__.py
added example_pkg/a/__pycache__/__init__.cpython-34.pyc
added example_pkg_a-1.egg-info/PKG-INFO
added example_pkg_a-1.egg-info/SOURCES.txt
added example_pkg_a-1.egg-info/dependency_links.txt
added example_pkg_a-1.egg-info/installed-files.txt
added example_pkg_a-1.egg-info/top_level.txt
removed easy-install.pth
removed example_pkg_a-1-py3.4.egg

i. e. it looks like the modules have to be extracted from the egg and cannot 
be imported directly even though that is what I thought the pth file was 
supposed to achieve. This is all a bit of black magic to me -- I've no idea 
if this is some kind of misconfiguration or a version problem or whatever.

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


Re: OT I before E [was Re: Lies in education [was Re: The "loop and a half"]]

2017-10-05 Thread Roel Schroeven

Thomas Jollans schreef op 5/10/2017 10:30:

On 2017-10-05 06:47, Steve D'Aprano wrote:

On Thu, 5 Oct 2017 02:54 pm, Chris Angelico wrote:

(There are exceptions even to the longer form of the rule, but only a
handful. English isn't a tidy language.)

Even with the longer version of the rule, there are so few applicable cases,
and enough difficulty in applying the rule correctly, that the rule is not
worth the breath it takes to say it.


Maybe we should just all switch to Dutch on this list. Might be easier.
Certainly more consistent.


Although that way may not be obvious at first unless you're Dutch. (or 
Flemish)


There are a lot of exceptions, weird rules and other difficulties in 
Dutch as well; we native speakers just don't notice them that much.



--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven

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


Re: Multithreaded compression/decompression library with python bindings?

2017-10-05 Thread Stephan Houben
Op 2017-10-05, Thomas Nyberg schreef :
> Btw if anyone knows a better way to handle this sort of thing, I'm all
> ears. Given my current implementation I could use any compression that
> works with stdin/stdout as long as I could sort out the waiting on the
> subprocess. In fact, bzip2 is probably more than I need...I've half used
> it out of habit rather than anything else.

lzma ("xv" format) compression is generally both better and faster than
bzip2. So that gives you already some advantage.

Moreover, the Python lzma docs say:

"When opening a file for reading, the input file may be the concatenation
of multiple separate compressed streams. These are transparently decoded
as a single logical stream."

This seems to open the possibility to simply divide your input into,
say, 100 MB blocks, compress each of them in a separate thread/process
and then concatenate them. 

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


Re: The "loop and a half"

2017-10-05 Thread bartc

On 05/10/2017 18:01, Chris Angelico wrote:

On Thu, Oct 5, 2017 at 10:26 PM, bartc  wrote:

On 05/10/2017 12:09, Chris Angelico wrote:


On Thu, Oct 5, 2017 at 9:56 PM, bartc  wrote:


This doesn't make sense. For interactive use, you wouldn't bother testing
for eof, as you'd be testing the eof status of the keyboard.



You mean the way heaps and heaps of Unix programs work, processing
until EOF of stdin? Yeah, totally makes no sense, man, no sense at
all.



Out of the hundreds, perhaps thousands of such input loops I must have
written, how many needed to test EOF? Hmm, somewhere around zero I think.

Oh hang on, I wasn't using Unix; does that make a difference?

If you're referring to the ability to redirect stdin so that input can come
from a file as well as from a live keyboard, then you're doing file
handling; it's NOT interactive.


How would you write a sort program? How would you tell it that you're
done entering data?


How do you do it with any kind of iterative program?

It can be done with an in-band end-of-data code, although it might take 
some effort especially if you also want that to be invoked by pressing 
Ctrl-D. Then you can continue using a simple loop, and ignore dealing 
with 'EOF' on a keyboard.



And yes, I have used sort(1) interactively, with no redirection whatsoever.


Yes, I tried typing 'sort' in Linux, where it apparently hangs (same on 
Windows actually). The reason: because it might have killed someone to 
have added a message saying what you are expected to type and how to end 
it. (Namely, press Ctrl-D start at the start of a line in Linux, and 
Ctrl-Z followed by Enter, I think also at the start, in Windows.)



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


Re: Multithreaded compression/decompression library with python bindings?

2017-10-05 Thread Thomas Jollans
On 05/10/17 20:38, Stephan Houben wrote:
> Op 2017-10-05, Thomas Nyberg schreef :
>> Btw if anyone knows a better way to handle this sort of thing, I'm all
>> ears. Given my current implementation I could use any compression that
>> works with stdin/stdout as long as I could sort out the waiting on the
>> subprocess. In fact, bzip2 is probably more than I need...I've half used
>> it out of habit rather than anything else.
> lzma ("xv" format) compression is generally both better and faster than
> bzip2. So that gives you already some advantage.
>
> Moreover, the Python lzma docs say:
>
> "When opening a file for reading, the input file may be the concatenation
> of multiple separate compressed streams. These are transparently decoded
> as a single logical stream."
>
> This seems to open the possibility to simply divide your input into,
> say, 100 MB blocks, compress each of them in a separate thread/process
> and then concatenate them. 

Perhaps, but

 - this will probably be less space-efficient (by a small enough
fraction, if your blocks are large enough)
 - this *might* be a Python implementation detail (I doubt that, but who
knows)
 - this obviously won't work for decompression unless you know a priori
that there are division points, and where they are.

Thomas


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


Re: Pedagogical style [was Re: The "loop and a half"]

2017-10-05 Thread Ben Bacarisse
Steve D'Aprano  writes:

> There's no link to the original paper, only to secondary sources that discuss
> it, e.g.:
>
> http://phys.org/pdf128266927.pdf


> [1] Anecdotes are not data, but for what it is worth, just in the last two
> days I came across two examples of this. Teaching a boy in Year 10 maths
> about logarithms, he struggled with purely algebraic questions involving
> solving exponential equations by using logs, but when given a concrete
> problem involving an investment he was able to solve it immediately.
>
> The second example involved a girl in Year 8 maths, who again struggled with
> abstract questions about adding and multiplying fractions. In particular, she
> overgeneralised from fraction multiplication to addition, thinking that 1/4 +
> 1/4 must add to 2/8. But when put into concrete geometric terms, showing
> physical shapes divided into quarters, she could instantly tell that 1/4 plus
> 1/4 must be 1/2.
>
> As I said, anecdotes are not data, but when research claims to show that
> apples fall upwards in contradiction to anecdotal evidence that they fall
> downwards, we would be wise to be cautious before accepting the research as
> fact.

I think the paper is this one:

http://faculty.psy.ohio-state.edu/sloutsky/pdf/KSH-published.pdf

(You can find more recent papers by searching the Ohio State University
site.)

>From what I've read, your anecdotes are not in contradiction to the
paper's claims.

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


Re: How to determine lowest version of Python 3 to run?

2017-10-05 Thread Irmen de Jong
On 10/05/2017 04:23 AM, Christopher Reimer wrote:

> I'm leaning towards installing the latest minor version of each available 
> major version, running tox to run the unit tests against each one, and seeing 
> what blows up.

Perhaps you can use the service of Travis (travis-ci.org) to avoid installing 
the Python
versions yourself. They have lots of older versions available to run tests on.

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


Re: Introducing the "for" loop

2017-10-05 Thread Bill

Stefan Ram wrote:

"ROGER GRAYDON CHRISTMAN"  writes:

On Wed, Oct 4, 2017 22:42 Stefan Ram ([email protected]) wrote:
Steve D'Aprano  writes:

So, "bottom-up" in this case means: iterators should be
taught before for-loops.
Why?

The easy answer here is to not use the range in the first for loop.

   I never intended to use »range«. But I also will not use lists.

   Very early in the course, I teach numeric and string literals:

1, 2.3, 'abc'

   then come operators, functions and »if«, »while« and »try«.
   But neither »range« nor lists have been shown so far.


As long as I have two teachers here, which textbooks are you using? I am 
hoping to teach a college course in Python next fall.


Thanks,
Bill





   The basic course may already and there after about 12 - 18 hours.
   (This time includes many exercises in the classroom.)

   But if I have time to introduce »for«, I'll do it as follows
   at this point in the course:

   

   We want to walk through (traverse) a string
   character-by-character:

   To do this we need a walker. A walker can be
   obtained using »iter«:

|>>> walker = iter( 'abc' )

   Now, we can get character after character from the walker
   using »next« (transcript simplified):

|>>> next( walker )
|'a'
|>>> next( walker )
|'b'
|>>> next( walker )
|'c'
|>>> next( walker )
|StopIteration

   We can use »while« to automate this:

def example():
 walker = iter( 'abc' )
 try:
 while True:
 print( next( walker ))
 except StopIteration:
 pass

   A walker also is known as an /iterator/.

   An object, one can get an iterator from
   is called an /iterable object/.

   Strings are iterable objects.

   This for-loop does just what our previous
   while-loop did:

def example():
 for ch in 'abc':
 print( ch )

   It gets an iterator from »'abc'« and then does the suite
   repeatedly with »ch« being the result of a each »next«
   call until StopIteration.

   

   No »range«, no list.

   (Yes, »print('\n'.join('abc'))« can do the same and will
   be shown later in the course if there is still time.)



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


Re: Pedagogical style [was Re: The "loop and a half"]

2017-10-05 Thread Christian Gollwitzer

Am 05.10.17 um 19:04 schrieb Steve D'Aprano:

On Thu, 5 Oct 2017 07:29 am, Christian Gollwitzer wrote:


To understand Stefan's way of teaching, take a look at his other
courses, for example the C++ course:


Thanks for this Christian. It has been an eye-opener. More comments below.


You're welcome. Stefan is notorious for posting similar questions in 
c.l.c++ for years - asking about minute details of the C++ syntax 
(whether or not to call a "number literal" a "numeral" or similar) 
accompanied with code examples in a distinct unusual style. He's 
actually quite good in finding very concise C++ code for some (mostly 
mathematical) problems.



http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/c++-kurs

There's no link to the original paper, only to secondary sources that discuss
it, e.g.:

http://phys.org/pdf128266927.pdf

so I cannot really judge the quality of the paper. It might be good, it might
be full of holes, there's no way to tell.


Well you could read others who tried to replicate the study and found 
partially different results, and especially interpretations:


http://www.staff.science.uu.nl/~savel101/fi-msecint/literature/Bock2011.pdf



(1) Programming in Python is NOT a formal system. Most programming isn't, and
Python *in particular* is further away from the mathematical purity of (say)
Haskell.



I think this is the main argument against this way of teaching. As shown 
in the subsequent study above, the "formal way" may have an edge over 
the concrete examples when the task at hand involves working with 
abstract sets - however programming is not about knowing all details of 
the syntax. Instead, programming is the skill to break a given task down 
into steps and either attacking the subtasks in isolation or finding a 
library which does it. Syntax plays a minor role in that skill.


Similarly, in Germany many people learn both Latin and English in high 
school. Latin is taught mostly by studying grammar books and learning 
vocabulary. English is taught mostly by stories and conversation. Most 
students can reasonably communicate in English, but they are usually not 
able to form Latin sentences on their own. However they can enumerate 
the inflection cases of nouns and verbs.


Christian


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


Re: Lies in education [was Re: The "loop and a half"]

2017-10-05 Thread Bill

Marko Rauhamaa wrote:

That's good advice, but it's not all that dangerous to express off-topic
statements in this newsgroup.



It may not be "dangerous", but I find it a little annoying.  I wasn't 
going to say anything, but now you are bringing it up explicitly.



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


why does memory consumption keep growing?

2017-10-05 Thread Fetchinson . via Python-list
Hi folks,

I have a rather simple program which cycles through a bunch of files,
does some operation on them, and then quits. There are 500 files
involved and each operation takes about 5-10 MB of memory. As you'll
see I tried to make every attempt at removing everything at the end of
each cycle so that memory consumption doesn't grow as the for loop
progresses, but it still does.

import os

for f in os.listdir( '.' ):

x = [ ]

for ( i, line ) in enumerate( open( f ) ):

import mystuff
x.append( mystuff.expensive_stuff( line ) )
del mystuff

import mystuff
mystuff.some_more_expensive_stuff( x )
del mystuff
del x


What can be the reason? I understand that mystuff might be leaky, but
if I delete it, doesn't that mean that whatever memory was allocated
is freed? Similary x is deleted so that can't possibly make the memory
consumption go up.

Any hint would be much appreciated,
Daniel




-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why does memory consumption keep growing?

2017-10-05 Thread Bill

Fetchinson . wrote:

Hi folks,

I have a rather simple program which cycles through a bunch of files,
does some operation on them, and then quits. There are 500 files
involved and each operation takes about 5-10 MB of memory. As you'll
see I tried to make every attempt at removing everything at the end of
each cycle so that memory consumption doesn't grow as the for loop
progresses, but it still does.

import os

for f in os.listdir( '.' ):

 x = [ ]

 for ( i, line ) in enumerate( open( f ) ):

 import mystuff
 x.append( mystuff.expensive_stuff( line ) )
 del mystuff

 import mystuff
 mystuff.some_more_expensive_stuff( x )
 del mystuff
 del x


What can be the reason? I understand that mystuff might be leaky, but
if I delete it, doesn't that mean that whatever memory was allocated
is freed? Similary x is deleted so that can't possibly make the memory
consumption go up.

Any hint would be much appreciated,
Daniel



Try calling the garbage collector explicitly.

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


Re: why does memory consumption keep growing?

2017-10-05 Thread Chris Angelico
On Fri, Oct 6, 2017 at 8:06 AM, Fetchinson . via Python-list
 wrote:
> Hi folks,
>
> I have a rather simple program which cycles through a bunch of files,
> does some operation on them, and then quits. There are 500 files
> involved and each operation takes about 5-10 MB of memory. As you'll
> see I tried to make every attempt at removing everything at the end of
> each cycle so that memory consumption doesn't grow as the for loop
> progresses, but it still does.
>
> import os
>
> for f in os.listdir( '.' ):
>
> x = [ ]
>
> for ( i, line ) in enumerate( open( f ) ):
>
> import mystuff
> x.append( mystuff.expensive_stuff( line ) )
> del mystuff
>
> import mystuff
> mystuff.some_more_expensive_stuff( x )
> del mystuff
> del x
>
>
> What can be the reason? I understand that mystuff might be leaky, but
> if I delete it, doesn't that mean that whatever memory was allocated
> is freed? Similary x is deleted so that can't possibly make the memory
> consumption go up.

You're not actually deleting anything. When you say "del x", all
you're doing is removing the *name* x. Especially, deleting an
imported module basically does nothing; it's a complete waste of time.
Modules are kept in their own special cache.

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


Re: why does memory consumption keep growing?

2017-10-05 Thread Fetchinson . via Python-list
On 10/5/17, Chris Angelico  wrote:
> On Fri, Oct 6, 2017 at 8:06 AM, Fetchinson . via Python-list
>  wrote:
>> Hi folks,
>>
>> I have a rather simple program which cycles through a bunch of files,
>> does some operation on them, and then quits. There are 500 files
>> involved and each operation takes about 5-10 MB of memory. As you'll
>> see I tried to make every attempt at removing everything at the end of
>> each cycle so that memory consumption doesn't grow as the for loop
>> progresses, but it still does.
>>
>> import os
>>
>> for f in os.listdir( '.' ):
>>
>> x = [ ]
>>
>> for ( i, line ) in enumerate( open( f ) ):
>>
>> import mystuff
>> x.append( mystuff.expensive_stuff( line ) )
>> del mystuff
>>
>> import mystuff
>> mystuff.some_more_expensive_stuff( x )
>> del mystuff
>> del x
>>
>>
>> What can be the reason? I understand that mystuff might be leaky, but
>> if I delete it, doesn't that mean that whatever memory was allocated
>> is freed? Similary x is deleted so that can't possibly make the memory
>> consumption go up.
>
> You're not actually deleting anything. When you say "del x", all
> you're doing is removing the *name* x. Especially, deleting an
> imported module basically does nothing; it's a complete waste of time.
> Modules are kept in their own special cache.

Meaning that if mystuff has some leaky stuff in it, there is no way
for me to recover?

Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why does memory consumption keep growing?

2017-10-05 Thread bartc

On 05/10/2017 22:06, Fetchinson . wrote:

Hi folks,

I have a rather simple program which cycles through a bunch of files,
does some operation on them, and then quits. There are 500 files
involved and each operation takes about 5-10 MB of memory. As you'll
see I tried to make every attempt at removing everything at the end of
each cycle so that memory consumption doesn't grow as the for loop
progresses, but it still does.

import os

for f in os.listdir( '.' ):

 x = [ ]

 for ( i, line ) in enumerate( open( f ) ):

 import mystuff
 x.append( mystuff.expensive_stuff( line ) )


What if you change this line to:

   mystuff.expensive_stuff( line )

If it's still growing (perhaps a bit less as it's not added to x), then 
something in mystuff is remembering data about each line. You might try 
removing the line completely too (temporarily of course).


Other replies suggest that deleting the import [name] doesn't affect any 
data it contains. So might as well move it to the top where it belongs.




 del mystuff

 import mystuff
 mystuff.some_more_expensive_stuff( x )


You'll have to comment these lines out first I think.

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


stop/start windows services -python command

2017-10-05 Thread prabu . ts
hello all,what is the command to stop and start windows services ?
i can't install win32serviceutil bec am using latest python version.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lies in education [was Re: The "loop and a half"]

2017-10-05 Thread Gregory Ewing

Steve D'Aprano wrote:

I've seen (or at least, I remember seeing)
diagrams of matter/antimatter annihilation with the two particles coming
together and a single photon coming out: a simplified and strictly wrong view
of the physics.


It may or may not be wrong, depending on what the diagram was
supposed to represent.

Each vertex in a QED Feynman diagram involves one electron,
one positron and one photon. That much is perfectly true.

But if you work out the probability of that process happening
on its own, it turns out to be zero. You need a diagram with
at least two vertices to get a non-zero probability.

Another way to say it is that a single-vertex diagram
correctly represents a virtual process (involving virtual
particles, which don't have to conserve energy or
momentum), but it doesn't correspond to any real process
(since real particles have to conserve both).

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


Re: How to determine lowest version of Python 3 to run?

2017-10-05 Thread Christopher Reimer
On Oct 5, 2017, at 1:11 PM, Irmen de Jong  wrote:
> 
>> On 10/05/2017 04:23 AM, Christopher Reimer wrote:
>> 
>> I'm leaning towards installing the latest minor version of each available 
>> major version, running tox to run the unit tests against each one, and 
>> seeing what blows up.
> 
> Perhaps you can use the service of Travis (travis-ci.org) to avoid installing 
> the Python
> versions yourself. They have lots of older versions available to run tests on.
> 
> Irmen
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Travis might be a bit of an overkill for my project. Someone suggested docker 
containers and there is a docker plugin for tox that looks promising.

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


Re: stop/start windows services -python command

2017-10-05 Thread Prabu T.S.
On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote:
> hello all,what is the command to stop and start windows services ?
> i can't install win32serviceutil bec am using latest python version.

Please advice on this
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The "loop and a half"

2017-10-05 Thread Gregory Ewing

bartc wrote:

It can be done with an in-band end-of-data code,


Then you need some way of escaping that in-band code, in case
it happens to equal some of the data you want to sort. And
you need to ensure that your input is escaped properly.
All of which adds a lot of complexity.

Yes, I tried typing 'sort' in Linux, where it apparently hangs (same on 
Windows actually). The reason: because it might have killed someone to 
have added a message saying what you are expected to type and how to end 
it. (Namely, press Ctrl-D start at the start of a line in Linux, and 
Ctrl-Z followed by Enter, I think also at the start, in Windows.)


How to signal EOF from the keyboard is a fundamental piece
of knowledge about the OS. It's not the responsibility of
individual programs to teach it to you, any more than it's
your car's responsibility to explain what the steering wheel
does each time you start the engine.

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


Re: The "loop and a half"

2017-10-05 Thread Marko Rauhamaa
Gregory Ewing :

> bartc wrote:
>> Yes, I tried typing 'sort' in Linux, where it apparently hangs (same
>> on Windows actually). The reason: because it might have killed
>> someone to have added a message saying what you are expected to type
>> and how to end it. (Namely, press Ctrl-D start at the start of a line
>> in Linux, and Ctrl-Z followed by Enter, I think also at the start, in
>> Windows.)
>
> How to signal EOF from the keyboard is a fundamental piece of
> knowledge about the OS. It's not the responsibility of individual
> programs to teach it to you, any more than it's your car's
> responsibility to explain what the steering wheel does each time you
> start the engine.

Gladly, there is an individual program that *does* teach it to you on
Linux. Just give the command:

   stty -a

and you will see (among other things):

   [...]; eof = ^D; [...]

It is actually the terminal driver/emulator that gives Ctrl-D its
special meaning in accordance with how it has been configured.

As for informational messages, it is part of deep-seated Unix culture to
have quiet commands. The purpose of the silence is so you can easily
compose new commands out of existing commands via pipelines and scripts.
It would be inconvenient if you typed the command:

grep ython message.txt | sort

and the sort command instructed you to press Ctrl-D.


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


Re: Case Solution: Carolinas HealthCare System Consumer Analytics by John A. Quelch, Margaret Rodriguez

2017-10-05 Thread jclopezsmu
Carolinas HealthCare System: Consumer Analytics
John A. Quelch; Margaret Rodriguez
Source  Harvard Business School
Product #   515060-PDF-ENG

General Instructions

Please download this case from the Harvard website that you used to purchase 
the course pack at the beginning of the semester. The exam case was included in 
your coursepack; you have already paid for it.

 

Attempt all case discussion questions listed below. Please DO NOT write a 
nicely flowing essay, but answer each question separately, as directly and 
succinctly as possible. To save space, you may use bulleted lists where 
appropriate.  Also, simply reference the question number; you do not have to 
re-type the question.

The write-up should consist of no more than 5 pages (double spaced) of text.  
In addition, it may have an unlimited number of exhibits in an appendix, e.g., 
tables for comparing and contrasting, 2x2 frameworks that summarize facts from 
the case situation, or diagrams that demonstrate your analysis of the case. 
Please note, copying exhibits from the case as appendices is not appropriate.

Theories, frameworks and concepts covered in the course should be applied in 
the analysis of the empirical situation. Rely on these to justify your answers 
rather than on additional information from outside sources (e.g., Internet 
search or the firm’s economic success or failure since the case was written). 
Also, appropriately reference (through footnotes or endnotes) the articles you 
are drawing on or citing in your write-up. 

This final is regarded as individual work, implying that you are expected to 
complete it independently, without any assistance from others either in or 
outside of class. Please direct any questions you may have to your professor. 
You should not be discussing the case with your peers.

 

Deadline for submission of this take-home final: Monday, October 9, at midnight 
(US Central time).  Please submit your take-home final on Canvas. Please make 
sure the submission has been successful by checking to see whether it has been 
saved after you have submitted it.  Points will be subtracted for late 
submissions.  

 

Discussion Questions (Total: 50 points)

Why has Carolinas HealthCare System (CHS) invested in Dickson Advanced 
Analytics (DA²)? In your answer, be sure to also address the reasons for 
investing in DA² as a centralized, in-house provider of analytics. (10 points)
 

Has DA² been successful thus far? Evaluate DA²’s performance and identify the 
factors critical to its success or lack thereof. (10 points)
 

Which of the projects DA² has piloted to date do you consider the most 
challenging? Why? (4 points)
 

In an effort to develop a strategy roadmap, CHS summarized their strategic 
priorities and related measures in Exhibits 3 and 4. Help CHS complete its 
roadmap by building a Balanced Score Card (BSC) Strategy Map that makes the 
strategy elements captured in these exhibits more actionable by streamlining 
them and relating them to each other. To the extent that you have to make 
assumptions about their strategy as you formulate your recommended BSC strategy 
map, provide short arguments for them. (16 points)
 

What are Dulin’s most important challenges going forward? Which of these 
challenges would you tackle first, why, and how would you go about addressing 
it? (10 points)
 









On Saturday, September 2, 2017 at 5:58:15 AM UTC-5, Case Solution & Analysis 
wrote:
> Carolinas HealthCare System: Consumer Analytics Case Solution, Case Analysis, 
> Case Study Solution by John A. Quelch, Margaret Rodriguez is available at a 
> lowest price, send email to casesolutionscentre(at)gmail(dot)com if you want 
> to order the Case Solution. 
> 
> Case Study ID: 9-515-060
> 
> Get Case Study Solution and Analysis of Carolinas HealthCare System: Consumer 
> Analytics in a FAIR PRICE!! 
> 
> Our e-mail address is CASESOLUTIONSCENTRE (AT) GMAIL (DOT) COM. Please 
> replace (at) by @ and (dot) by . 
> 
> YOU MUST WRITE THE FOLLOWING WHILE PLACING YOUR ORDER: 
> Complete Case Study Name 
> Authors 
> Case Study ID 
> Publisher of Case Study 
> Your Requirements / Case Questions 
> 
> Note: Do not REPLY to this post because we do not reply to posts here. If you 
> need any Case Solution please send us an email. We can help you to get it.

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


Re: The "loop and a half"

2017-10-05 Thread bartc

On 05/10/2017 23:42, Gregory Ewing wrote:

bartc wrote:

It can be done with an in-band end-of-data code,


Then you need some way of escaping that in-band code, in case
it happens to equal some of the data you want to sort.


It needn't be a big deal. You can do this (you have to in Python as the 
normal 255 character signifying eof on a character stream is trapped):


 EOD=chr(26)  # can be anything that is an unlikely input line.

 def myinput(prompt):
 try:
 return input(prompt)
 except EOFError:
 return EOD

Then you can keep using a simple type of loop without worrying about EOF 
status:


 print ("Type Ctrl-Z on its own line to finish.") # Windows

 while 1:

 buffer=myinput("Enter something: ")
 if buffer==EOD: break
 print ("You typed:",buffer) # process(buffer)

 print ("Bye")

Yes, I tried typing 'sort' in Linux, where it apparently hangs (same 
on Windows actually). The reason: because it might have killed someone 
to have added a message saying what you are expected to type and how 
to end it. (Namely, press Ctrl-D start at the start of a line in 
Linux, and Ctrl-Z followed by Enter, I think also at the start, in 
Windows.)


How to signal EOF from the keyboard is a fundamental piece
of knowledge about the OS. It's not the responsibility of
individual programs to teach it to you, any more than it's
your car's responsibility to explain what the steering wheel
does each time you start the engine.


If you have a utility that is designed to also be used interactively, 
but it shows absolutely nothing when you start it, like this:


 >sort





then it stinks. You wouldn't think much of a shell prompt that literally 
showed nothing at all instead of something like:


 c:\python39>

How would you even know what program you were in the middle of after the 
initial command has scrolled off the screen? How would you now it was 
still running? As typing a line into it give no response.


I don't run these things often enough to remember exactly how to specify 
an EOF with the keyboard. It might be:


- One of Ctrl C, D, Z or Break

- It may or not may not only work at the start of a line

- It may or not require to be followed by Enter

I anyway would never inflict such an interface on my users, who would 
also associate Ctrl C etc with aborting a program that's gone wrong.


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


Re: why does memory consumption keep growing?

2017-10-05 Thread bartc

On 06/10/2017 00:38, Stefan Ram wrote:

"Fetchinson ."  writes:

I have a rather simple program which cycles through a bunch of files,
does some operation on them, and then quits. There are 500 files
involved and each operation takes about 5-10 MB of memory. As you'll
see I tried to make every attempt at removing everything at the end of
each cycle so that memory consumption doesn't grow as the for loop
progresses, but it still does.


   "2x 8GB DIMM DDR3-1600" cost $95.99 according to a web page.
   This might be in the order of magnitude of the hourly rate
   of a freelancing programmer.


Brilliant. We can forget about freeing memory or garbage collection, 
just keep adding a 16GB bank of memory every few hours. It's cheaper 
that paying a programmer to write memory-efficient code or fixing the 
memory leak!


(That's assuming such a program will only run on the programmer's 
machine and not a million consumer machines who would also need to fork 
out for extra memory. Their salaries may not stretch as far.)


--
bartc


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


Re: stop/start windows services -python command

2017-10-05 Thread MRAB

On 2017-10-05 23:32, Prabu T.S. wrote:

On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote:

hello all,what is the command to stop and start windows services ?
i can't install win32serviceutil bec am using latest python version.


Please advice on this


Ask Google: windows services start stop command line
--
https://mail.python.org/mailman/listinfo/python-list


Re: stop/start windows services -python command

2017-10-05 Thread Prabu T.S.
On Thursday, October 5, 2017 at 8:33:02 PM UTC-4, MRAB wrote:
> On 2017-10-05 23:32, Prabu T.S. wrote:
> > On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote:
> >> hello all,what is the command to stop and start windows services ?
> >> i can't install win32serviceutil bec am using latest python version.
> > 
> > Please advice on this
> > 
> Ask Google: windows services start stop command line

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


Re: php to python code converter

2017-10-05 Thread wordpyai
On Friday, May 8, 2009 at 3:38:25 AM UTC-7, bvidinli wrote:
> if anybody needs:
> http://code.google.com/p/phppython/

The link is down.
I'd like to give a plug to mynewly released product `pyx.php` Python module:

https://wordpy.com/pyx/php/

https://github.com/wordpy/pyx


Run Converted PHP Codes in Python with the Speed of Compiled-C

pyx.php is a Cython compiled module that you can use to convert or translate 
99% of most common PHP source codes to pure Python. In another words, it is a 
PHP-to-Python syntax emulation library in Cython.

The converted Python codes only require a Python 3.x interpreter, the modules 
in the pyx repository, and some standard Python libraries. PHP interpreter is 
not needed at all.

If we have already translated most of the WordPress core and other scripts from 
PHP to Python using pyx.php, you can convert almost any PHP code into Python.

With the speed of compiled Cython, running Python code translated from PHP 
using pyx.php might be even faster than running the original PHP code in the 
same computer.
Installation

$ git clone https://github.com/wordpy/pyx/

Currently, pyx.php is only available for Python 3.x running 64-bit Linux. 
Python 2.x, Mac, or other platforms can be compiled when there are many 
requests.
Quick Start

$ python # or ipython

>>> import pyx.php as Php; array = Php.array
>>> arr1 = array( (0,'1-0'),('a','1-a'),('b','1-b'),)
>>> arr2 = array( (0,'2-0'),(  1,'2-1'),('b','2-b'),('c','2-c'),)
>>> arr1 + arr2   # same as: Php.array_plus(arr1, arr2), see below
>>> Php.array_merge(arr1, arr2)


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


Re: The "loop and a half"

2017-10-05 Thread Chris Angelico
On Fri, Oct 6, 2017 at 11:08 AM, bartc  wrote:
> I don't run these things often enough to remember exactly how to specify an
> EOF with the keyboard. It might be:
>
> - One of Ctrl C, D, Z or Break

This is your problem, not the program's.

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


Re: why does memory consumption keep growing?

2017-10-05 Thread Steve D'Aprano
On Fri, 6 Oct 2017 10:38 am, Stefan Ram wrote:

> "Fetchinson ."  writes:
>>I have a rather simple program which cycles through a bunch of files,
>>does some operation on them, and then quits. There are 500 files
>>involved and each operation takes about 5-10 MB of memory. As you'll
>>see I tried to make every attempt at removing everything at the end of
>>each cycle so that memory consumption doesn't grow as the for loop
>>progresses, but it still does.
> 
>   "2x 8GB DIMM DDR3-1600" cost $95.99 according to a web page.
>   This might be in the order of magnitude of the hourly rate
>   of a freelancing programmer.

Plus the downtime and labour needed to install the memory, if the computer
will even take it.

And then if Fetchinson is right that there is a memory leak, those 16 GB will
soon be not enough, and they'll need to buy another 16GB plus more downtime
and more installation costs.

Memory leaks expand to fill the available memory.


-- 
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 "loop and a half"

2017-10-05 Thread Ethan Furman

On 10/04/2017 04:50 PM, Stefan Ram wrote:


names: are sequences of letters and stand for values
function names: names that stand for callable values
function call operator: calls a callable value (first operand)
argument: if present, it's value is passed to the function

   And, lo, I have explained everything one needs to know
   to understand the expression


No, you haven't.  What is a value?  What does callable mean?  Why is a function 
a value?

I taught myself assembly from a book when I was 16, and that was far easier to understand than your explanation.  I 
understand that teaching is hard, but please don't make learning harder than it already is.  One does not need to 
understand fluid dynamics nor specific gravity in order to swim.


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


Re: stop/start windows services -python command

2017-10-05 Thread MRAB

On 2017-10-06 01:37, Prabu T.S. wrote:

On Thursday, October 5, 2017 at 8:33:02 PM UTC-4, MRAB wrote:

On 2017-10-05 23:32, Prabu T.S. wrote:
> On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote:
>> hello all,what is the command to stop and start windows services ?
>> i can't install win32serviceutil bec am using latest python version.
> 
> Please advice on this
> 
Ask Google: windows services start stop command line


asking for python.


Again, ask Google: windows services start stop python

Those results talk about "win32serviceutil", which is not part of the 
standard library, but part of pywin32, which you can download.

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


Re: Introducing the "for" loop

2017-10-05 Thread Irv Kalb

> 
> As long as I have two teachers here, which textbooks are you using? I am 
> hoping to teach a college course in Python next fall.
> 
> Thanks,
> Bill
> 
> 

At least one more.  I teach Intro to Python courses at two colleges in Silicon 
Valley.  These courses are aimed at students who have zero background in 
programming.  In fact, one of the colleges is a game design college and most 
students are art students.  

I was contacted by a publisher about turning my course into a book.  After 
about a year, the book was published in Sept. 2016 by aPress, a division of 
Springer.  The book is a superset of the material I teach in my classes.  The 
book's title is "Learn to Program with Python" and is available on the aPress 
web site, on Amazon.com , and at better bookstore 
everywhere  :)

aPress:   http://www.apress.com/us/book/9781484218686 
   They also have an eBook 
version available

Amazon: 
https://www.amazon.com/Learn-Program-Python-Irv-Kalb/dp/148421868X/ref=sr_1_1?ie=UTF8&qid=1507250994&sr=8-1&keywords=kalb+python

In retrospect, the only problem with the book is that all the example code is 
built in Python 2.7 (which is what we were using at both colleges at the time). 
 However, in the small number of cases where there are differences, I explain 
the Python 3 way of doing the same thing (e.g., the print statement vs the 
print function).

Irv

PS:  I teach the while loop way before I teach the for loop.  That's because I 
use while loops to show how to allow the user to do things like play a small 
game over and over until the user says that they want to quit.  I introduce the 
for loop only after teaching about lists, as a means of iterating through a 
list.  The range function is discussed after that.

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


Re: The "loop and a half"

2017-10-05 Thread Steve D'Aprano
On Fri, 6 Oct 2017 09:57 am, Marko Rauhamaa wrote:

[quoting Bart]
>>> Yes, I tried typing 'sort' in Linux, where it apparently hangs (same
>>> on Windows actually). The reason: because it might have killed
>>> someone to have added a message saying what you are expected to type
>>> and how to end it. (Namely, press Ctrl-D start at the start of a line
>>> in Linux, and Ctrl-Z followed by Enter, I think also at the start, in
>>> Windows.)

Waiting for input isn't "hangs". That's an ignorant and foolish thing to say,
more suited for a wet-behind-the-ears newbie than somebody who claims to be a
long-time old-school programmer.


[Greg]
>> How to signal EOF from the keyboard is a fundamental piece of
>> knowledge about the OS.

Indeed.

The Unix commandline interface is not designed to be user-friendly for newbies
(or experts, for that matter). It is terse, often *painfully* so (would it
have killed the author to have spelled `umount` correctly?), the UI is
inconsistent, and it has a very steep learning curve -- a lot of effort is
required to make a little bit of progress.

But even a dilettante Unix user like me knows how to signal EOF. It is one of
a handful of indispensable skills you need to use Unix effectively, just as
you can't use Windows effectively without knowing how to right-click. Some
things you just have to learn.

[Marko]
> As for informational messages, it is part of deep-seated Unix culture to
> have quiet commands. The purpose of the silence is so you can easily
> compose new commands out of existing commands via pipelines and scripts.
> It would be inconvenient if you typed the command:
> 
> grep ython message.txt | sort
> 
> and the sort command instructed you to press Ctrl-D.

Indeed it would.

But in fairness, if the author of the `sort` command had a commitment to
friendliness in their programs, they could have `sort` only print a message
when it is reading from stdin and writing to stdout, much as `ls` defaults to
outputting control characters but automatically swaps to replacing them
with ? when writing to a terminal.

I believe that even Unix experts would be more effective with a judicious
amount of not so much hand-holding as gentle guidance. Even experts aren't
expert on every single command line tool.

But the OS is what it is, and the culture has a certain level of commandline
machismo, so that's unlikely to change.



-- 
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 "loop and a half"

2017-10-05 Thread Michael Torrie
On 10/05/2017 06:08 PM, bartc wrote:
> then it stinks. You wouldn't think much of a shell prompt that literally 
> showed nothing at all instead of something like:

Indeed many programs do go to extra effort to detect if the connecting
stream is an interactive device (a tty), and if so they do emit a prompt
and enable a REPL loop. For example the python interpreter itself does this.

However there are some fundamental commands that don't such as cat.

It all depends on what the command's purpose is for, and how it's
designed to be chained with other commands (cat for example).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why does memory consumption keep growing?

2017-10-05 Thread Steve D'Aprano
On Fri, 6 Oct 2017 08:06 am, Fetchinson . wrote:

> Hi folks,
> 
> I have a rather simple program which cycles through a bunch of files,
> does some operation on them, and then quits. There are 500 files
> involved and each operation takes about 5-10 MB of memory. As you'll
> see I tried to make every attempt at removing everything at the end of
> each cycle so that memory consumption doesn't grow as the for loop
> progresses, but it still does.

How do you know memory consumption is still growing?

I'm not saying it isn't, but knowing what the symptoms are and how you
determined the memory leak may be important in solving it.


> import os
> for f in os.listdir( '.' ):
> x = [ ]
> for ( i, line ) in enumerate( open( f ) ):
> import mystuff
> x.append( mystuff.expensive_stuff( line ) )
> del mystuff

As Chris has already said, deleting and re-importing mystuff is a waste of
time.


> import mystuff
> mystuff.some_more_expensive_stuff( x )
> del mystuff
> del x
> 
> 
> What can be the reason? I understand that mystuff might be leaky,

You know it is, you have good reason to think it is, or you're just guessing?


> but 
> if I delete it, doesn't that mean that whatever memory was allocated
> is freed? Similary x is deleted so that can't possibly make the memory
> consumption go up.

You are not deleting the list. You are deleting a single reference to the
list, which may or may not allow the list to be garbage collected.

I hesitate to suggest this, because I don't want to encourage superstitious
cargo-cult programming, but:

(1) assuming you have good evidence that memory consumption is increasing;

(2) rather than `del x`, try `x[:] = []`;

(3) then if memory consumption stops increasing

that may be evidence of a leak, and provide a reasonable work around until the
leak can be fixed.

But in a well-behaved program, you shouldn't need to manually delete x at all.


-- 
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 "loop and a half"

2017-10-05 Thread Ben Bacarisse
Steve D'Aprano  writes:

> On Fri, 6 Oct 2017 09:57 am, Marko Rauhamaa wrote:
>
> [quoting Bart]
 Yes, I tried typing 'sort' in Linux, where it apparently hangs (same
 on Windows actually). The reason: because it might have killed
 someone to have added a message saying what you are expected to type
 and how to end it. (Namely, press Ctrl-D start at the start of a line
 in Linux, and Ctrl-Z followed by Enter, I think also at the start, in
 Windows.)
>
> Waiting for input isn't "hangs". That's an ignorant and foolish thing to say,
> more suited for a wet-behind-the-ears newbie than somebody who claims to be a
> long-time old-school programmer.

I suspect it's a wind-up.


> [Marko]
>> As for informational messages, it is part of deep-seated Unix culture to
>> have quiet commands. The purpose of the silence is so you can easily
>> compose new commands out of existing commands via pipelines and scripts.
>> It would be inconvenient if you typed the command:
>> 
>> grep ython message.txt | sort
>> 
>> and the sort command instructed you to press Ctrl-D.
>
> Indeed it would.
>
> But in fairness, if the author of the `sort` command had a commitment to
> friendliness in their programs, they could have `sort` only print a message
> when it is reading from stdin and writing to stdout,

I think you mean "when reading from a terminal".  In the example given
sort /is/ reading from stdin and writing to stdout.

> much as `ls` defaults to
> outputting control characters but automatically swaps to replacing them
> with ? when writing to a terminal.

ls often behaves completely differently when writing to a terminal.  The
main one is that it tabulates the file names into columns!  That's very
old behaviour.  A more modern innovation is coloured output.

> I believe that even Unix experts would be more effective with a judicious
> amount of not so much hand-holding as gentle guidance. Even experts aren't
> expert on every single command line tool.

That's true.  Some of it is here already.  I am addicted to tab
completion, especially when it is command-aware.

And there's a flip side.  I've come across a few too many programs
lately clearly written by people who want to be helpful, but the wordy
output is hard to parse when using the program in a script.  Some
programs offer a flag to simplify the output so it can be processed more
easily, but not all...

> But the OS is what it is, and the culture has a certain level of commandline
> machismo, so that's unlikely to change.

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


Re: The "loop and a half"

2017-10-05 Thread Chris Angelico
On Fri, Oct 6, 2017 at 12:07 PM, Steve D'Aprano
 wrote:
> But in fairness, if the author of the `sort` command had a commitment to
> friendliness in their programs, they could have `sort` only print a message
> when it is reading from stdin and writing to stdout, much as `ls` defaults to
> outputting control characters but automatically swaps to replacing them
> with ? when writing to a terminal.
>
> I believe that even Unix experts would be more effective with a judicious
> amount of not so much hand-holding as gentle guidance. Even experts aren't
> expert on every single command line tool.

It's not as simple as that, because you can't always know whether
you're working with a console or a pipe. And it gets annoying when you
have to force some program to behave interactively when it thought you
were piping it into something, or vice versa.

The sort program is *usually* reading from stdin and writing to
stdout. Did you mean "reading from a TTY and writing to a TTY"? That's
the nearest, but it's still not perfect.

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


Re: stop/start windows services -python command

2017-10-05 Thread Prabu T.S.
On Thursday, October 5, 2017 at 9:00:19 PM UTC-4, MRAB wrote:
> On 2017-10-06 01:37, Prabu T.S. wrote:
> > On Thursday, October 5, 2017 at 8:33:02 PM UTC-4, MRAB wrote:
> >> On 2017-10-05 23:32, Prabu T.S. wrote:
> >> > On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote:
> >> >> hello all,what is the command to stop and start windows services ?
> >> >> i can't install win32serviceutil bec am using latest python version.
> >> > 
> >> > Please advice on this
> >> > 
> >> Ask Google: windows services start stop command line
> > 
> > asking for python.
> > 
> Again, ask Google: windows services start stop python
> 
> Those results talk about "win32serviceutil", which is not part of the 
> standard library, but part of pywin32, which you can download.

i tried pywin32, but its not compatible with python 3.6. Is there anyway i can 
implement start and stop services in python 3.6 version.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why does memory consumption keep growing?

2017-10-05 Thread Pankaj L Ahire
On Thu, Oct 5, 2017 at 17:07 Fetchinson . via Python-list <
[email protected]> wrote:

> Hi folks,
>
> I have a rather simple program which cycles through a bunch of files,
> does some operation on them, and then quits. There are 500 files
> involved and each operation takes about 5-10 MB of memory. As you'll
> see I tried to make every attempt at removing everything at the end of
> each cycle so that memory consumption doesn't grow as the for loop
> progresses, but it still does.
>
> import os
>
> for f in os.listdir( '.' ):
>
> x = [ ]
>
> for ( i, line ) in enumerate( open( f ) ):
>
> import mystuff
> x.append( mystuff.expensive_stuff( line ) )
> del mystuff
>
> import mystuff
> mystuff.some_more_expensive_stuff( x )
> del mystuff
> del x
>
>
> What can be the reason? I understand that mystuff might be leaky, but
> if I delete it, doesn't that mean that whatever memory was allocated
> is freed? Similary x is deleted so that can't possibly make the memory
> consumption go up.
>
> Any hint would be much appreciated,
> Daniel


You are not closing f anywhere.
Better to use a context manager, so it does the clean up on exit.

for f in os.listdir( '.' ):
with open(f) as fh:
for (i, line) in enumerate(fh):
#your code.
#for loop done
#context manager flushes, closes fh nicely.

P



>
>
>
> --
> Psss, psss, put it down! - http://www.cafepress.com/putitdown
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why does memory consumption keep growing?

2017-10-05 Thread breamoreboy
On Thursday, October 5, 2017 at 10:07:05 PM UTC+1, Fetchinson . wrote:
> Hi folks,
> 
> I have a rather simple program which cycles through a bunch of files,
> does some operation on them, and then quits. There are 500 files
> involved and each operation takes about 5-10 MB of memory. As you'll
> see I tried to make every attempt at removing everything at the end of
> each cycle so that memory consumption doesn't grow as the for loop
> progresses, but it still does.
> 
> import os
> 
> for f in os.listdir( '.' ):
> 
> x = [ ]
> 
> for ( i, line ) in enumerate( open( f ) ):
> 
> import mystuff
> x.append( mystuff.expensive_stuff( line ) )
> del mystuff
> 
> import mystuff
> mystuff.some_more_expensive_stuff( x )
> del mystuff
> del x
> 
> 
> What can be the reason? I understand that mystuff might be leaky, but
> if I delete it, doesn't that mean that whatever memory was allocated
> is freed? Similary x is deleted so that can't possibly make the memory
> consumption go up.
> 
> Any hint would be much appreciated,
> Daniel
> 
> -- 
> Psss, psss, put it down! - http://www.cafepress.com/putitdown

Nothing stands out so I'd start by closing all the file handles.  As you don't 
need the call to `enumerate` as you don't use the `i` something like:-

with open(f) as g:
for line in g:
...

--
Kindest regards.

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


Re: Introducing the "for" loop

2017-10-05 Thread breamoreboy
On Friday, October 6, 2017 at 2:05:58 AM UTC+1, Irv Kalb wrote:
>  
> The range function is discussed after that.
>  

FWIW range isn't a function in Python 3.  From 
https://docs.python.org/3/library/functions.html#func-range "Rather than being 
a function, range is actually an immutable sequence type, as documented in 
Ranges and Sequence Types — list, tuple, range.".

--
Kindest regards.

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


Re: Solutions Manual Test Bank for Human Anatomy 9th Edition by Martini

2017-10-05 Thread reembeshay555
On Monday, July 3, 2017 at 11:25:21 AM UTC-4, Test Banks wrote:
> Greetings, 
> 
> You can get Solution Manuals and Test Bank for " Human Anatomy, 9th Edition 
> by Frederic H. Martini, Robert B. Tallitsch, Judi L. Nath " at very 
> reasonable price. Our team is available 24/7 and 365 days / year to respond 
> your requests. Send us an email at pro.fast(@)hotmail(dot)com 
> 
> Place your order at PRO.FAST(@)HOTMAIL(DOT)COM 
> 
> ISBN Numbers for this book (ISBN-10: 013432076X and ISBN-13: 9780134320762) 
> 
> HUMAN ANATOMY 9TH EDITION BY MARTINI SOLUTIONS MANUAL TEST BANK 
> 
> You can also email for other Anatomy and Physiology books Solutions and Test 
> Bank at low prices and our team will try to get all resources you need. 
> 
> Do not post your reply here. Simply send us an email at PRO.FAST (AT) HOTMAIL 
> (DOT) COM 
> 
> Cheers,

Hello, I want to order this book but I want to see the sample one before I  
order it. Thank you,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The "loop and a half"

2017-10-05 Thread Dan Sommers
On Thu, 05 Oct 2017 19:14:33 -0600, Michael Torrie wrote:

> It all depends on what the command's purpose is for, and how it's
> designed to be chained with other commands (cat for example).

They're almost all designed to be chained with other commands.  Even
diff and ed are designed to work together in a pipe; the output from
"diff -e" can be piped into ed to make ed apply changes to a file.

Dan

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


Re: why does memory consumption keep growing?

2017-10-05 Thread Gregory Ewing

Steve D'Aprano wrote:

Plus the downtime and labour needed to install the memory, if the computer
will even take it.


Obviously we need an architecture that supports hot-swappable
robot-installable RAM.

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


Re: type and object

2017-10-05 Thread Naveen Yadav
On Thursday, 5 October 2017 21:47:34 UTC+5:30, Naveen Yadav  wrote:
> Hi folks,
> 
> 
> >> isinstance(type, object) is True   # 1
> and
> >> isinstance(object, type) is True   # 2
> 
> 
> its means type is object is type, But i am not sure how is this.
> 
> For what i can understand is 
> for #1: since every thing is object in python, type is also an object.
> and 
> for #2: object is a base type. therefore object is type
> >> object.__doc__
> >> 'The most base type'
> 
> 
> Am I understanding this correct ? Please shed light on this.

thanks guys for clearing this out.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why does memory consumption keep growing?

2017-10-05 Thread Chris Angelico
On Fri, Oct 6, 2017 at 4:14 PM, Gregory Ewing
 wrote:
> Steve D'Aprano wrote:
>>
>> Plus the downtime and labour needed to install the memory, if the computer
>> will even take it.
>
>
> Obviously we need an architecture that supports hot-swappable
> robot-installable RAM.
>

Cloud computing is the answer.

If you don't believe me, just watch the sky for a while - new clouds
get added without the sky turning off and on again.

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


Re: The "loop and a half"

2017-10-05 Thread Michael Torrie
On 10/05/2017 10:38 PM, Dan Sommers wrote:
> On Thu, 05 Oct 2017 19:14:33 -0600, Michael Torrie wrote:
> 
>> It all depends on what the command's purpose is for, and how it's
>> designed to be chained with other commands (cat for example).
> 
> They're almost all designed to be chained with other commands.  Even
> diff and ed are designed to work together in a pipe; the output from
> "diff -e" can be piped into ed to make ed apply changes to a file.

Right. And my point was several of them are smart about detecting
whether they are actually connected to a pipe or to a real tty. And they
change their mode to be more interactive when not on a pipe. For example:

/usr/bin/python3
/usr/bin/bc
/bin/less (reverts to acting like cat when outputting to pipe)

I'm sure there are others. So Bart's complaint does have merit. If a
developer wanted to make a command operate both interactively and not so
in a more verbose manner, he could.


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