Re: Using namedtuples field names for column indices in a list of lists

2017-01-11 Thread BartC

On 11/01/2017 02:18, Steven D'Aprano wrote:

On Tuesday 10 January 2017 18:14, Deborah Swanson wrote:


I'm guessing that you (and those who
see things like you do) might not be used to working with quick learners
who make mistakes at first but catch up with them real fast, or you're
very judgemental about people who make mistakes, period. I certainly
don't care if you want to judge me, you're entitled to your opinion.


Be fair. We're not mind-readers, and we're trying to help you, not attack you.

It is true that we're often extremely pedantic. Sometimes annoyingly so, but on
the other hand precision is important, especially in technical fields. There's
a *huge* difference between a MTA and a MUA, even though they differ only by
one letter and both are related to email.


There's a bigger difference between USB and USA!

--
Bartc


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


Is there an peekable similar to peekable but in additional allowing one to put some data to it?

2017-01-11 Thread Peng Yu
Hi, peekable from more-itertools only allow peeking an iterator. But
sometimes, one may want to take a look at an element, manipulate it,
then put it back to the iterator. Is there a class in python that can
help do this?

https://pypi.python.org/pypi/more-itertools/

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


reactiveX vs Async

2017-01-11 Thread Rustom Mody
There is the recent flurry around the new async additions to python

Also, addressing the same problem area, there is the slightly older reactiveX 
system that seems to have bindings for at least 15 mainstream languages… 
including python: http://reactivex.io/

Has someone been able to put these two in context? To relate one to the other?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: reactiveX vs Async

2017-01-11 Thread Rustom Mody
On Wednesday, January 11, 2017 at 10:21:02 PM UTC+5:30, Rustom Mody wrote:
> There is the recent flurry around the new async additions to python

I meant to add: “… which I dont pretend to understand…”
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there an peekable similar to peekable but in additional allowing one to put some data to it?

2017-01-11 Thread Ian Kelly
On Wed, Jan 11, 2017 at 8:51 AM, Peng Yu  wrote:
> Hi, peekable from more-itertools only allow peeking an iterator. But
> sometimes, one may want to take a look at an element, manipulate it,
> then put it back to the iterator. Is there a class in python that can
> help do this?

Not that I'm aware of, but maybe this recipe will help.


from collections import deque

class PushIterator:

def __init__(self, iterable, push=()):
self._iter = iter(iterable)
self._pushed = deque(push)
self._stopped = False

def push(self, item):
if self._stopped:
raise RuntimeError('Cannot push onto exhausted iterator')
self._pushed.append(item)

def __iter__(self):
return self

def __next__(self):
if self._pushed:
return self._pushed.pop()
try:
return next(self._iter)
except StopIteration:
self._stopped = True
raise
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there an peekable similar to peekable but in additional allowing one to put some data to it?

2017-01-11 Thread Ian Kelly
On Wed, Jan 11, 2017 at 10:07 AM, Ian Kelly  wrote:
> On Wed, Jan 11, 2017 at 8:51 AM, Peng Yu  wrote:
>> Hi, peekable from more-itertools only allow peeking an iterator. But
>> sometimes, one may want to take a look at an element, manipulate it,
>> then put it back to the iterator. Is there a class in python that can
>> help do this?
>
> Not that I'm aware of, but maybe this recipe will help.
>
>
> from collections import deque
>
> class PushIterator:
>
> def __init__(self, iterable, push=()):
> self._iter = iter(iterable)
> self._pushed = deque(push)
> self._stopped = False
>
> def push(self, item):
> if self._stopped:
> raise RuntimeError('Cannot push onto exhausted iterator')
> self._pushed.append(item)
>
> def __iter__(self):
> return self
>
> def __next__(self):
> if self._pushed:
> return self._pushed.pop()
> try:
> return next(self._iter)
> except StopIteration:
> self._stopped = True
> raise


And in case it's not obvious, adding a peek method to this is pretty simple:


from collections import deque

class PushIterator:

def __init__(self, iterable, push=()):
self._iter = iter(iterable)
self._pushed = deque(push)
self._stopped = False

def peek(self):
item = next(self)
self.push(item)
return item

def push(self, item):
if self._stopped:
raise RuntimeError('Cannot push onto exhausted iterator')
self._pushed.append(item)

def __iter__(self):
return self

def __next__(self):
if self._pushed:
return self._pushed.pop()
try:
return next(self._iter)
except StopIteration:
self._stopped = True
raise
-- 
https://mail.python.org/mailman/listinfo/python-list


Cannot import GDAL

2017-01-11 Thread Falter, Donald [USA]
I am new to Python and I am trying to utilize GDAL.  I installed Python 3.6.  
The version I get when I activate IDLE is: MSC v.1900 32 bit (Intel)] on win32. 
 In downloading the GDAL bindings the latest version I can find is 
release-1800-gdal-2-1-2-mapserver-7-0-2 so I installed the following: 
gdal-201-1800-core.msi and GDAL-2.1.2.win32-py3.4.msi.

I added C:\Program Files\GDAL to my path and added the system variables 
GDAL_DATA = C:\Program Files\GDAL\gdal-data and\
GDAL_DRIVER_PATH = C:\Program Files\GDAL\gdalplugins

When I open IDLE and type the following: from osgeo import gdal I get the 
following error

>>> from osgeo import gdal
Traceback (most recent call last):
  File "", line 1, in 
from osgeo import gdal
ModuleNotFoundError: No module named 'osgeo'
>>>

I have been all over the internet looking for answer but have found none that 
work.  Some real help here would be appreciated.

Thanks,
Don

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


Re: Work between multiple processes

2017-01-11 Thread Irmen de Jong
On 10-1-2017 23:57, Patrick Zhou wrote:
> Hi Irmen,
> 
> I have successfully got it to work with both side as python but so far having 
> trouble with pyrolite.jar which is downloaded from 
> https://mvnrepository.com/artifact/net.razorvine/pyrolite/4.4
> 
> 

[...]

> 
> which "getDst" works on Java but hangs on handshake() in the call function. 
> 
> Any thought? Thanks. -P
> 

Yeah, don't use the oldest version of the library available, use the newest ;-)
https://mvnrepository.com/artifact/net.razorvine/pyrolite/4.15


Irmen

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


Re: Cannot import GDAL

2017-01-11 Thread Irmen de Jong
On 11-1-2017 18:31, Falter, Donald [USA] wrote:
> I am new to Python and I am trying to utilize GDAL.  I installed Python 3.6.
> I installed the following: gdal-201-1800-core.msi and 
> GDAL-2.1.2.win32-py3.4.msi.

Those don't match. You'll have to use a MSI built for py3.6, one thinks.

Either install and use Python 3.4 with this (rather than 3.6) or find the 
approprite
installer for python 3.6. It seems that you can get one here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal


Irmen

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


Re: Cannot import GDAL

2017-01-11 Thread Fabien

On 01/11/2017 06:31 PM, Falter, Donald [USA] wrote:

I am new to Python and I am trying to utilize GDAL


GDAL is notoriously difficult to install :-(

I would strongly recommend to use conda 
(http://conda.pydata.org/miniconda.html) for managing your packages and 
environments, and then use the conda-forge channel 
(https://conda-forge.github.io/) to install gdal:


conda install -c conda-forge gdal

Good luck!

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


Re: Cannot import GDAL

2017-01-11 Thread Fabien

On 01/11/2017 10:59 PM, Fabien wrote:

I would strongly recommend to use conda
(http://conda.pydata.org/miniconda.html) for managing your packages and
environments, and then use the conda-forge channel
(https://conda-forge.github.io/) to install gdal:

conda install -c conda-forge gdal



I forgot to mention that since py3.6 is quite recent, most packages 
still don't have binaries ready for it. Staying with py3.5 is a better 
idea for now.



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


RE: Using namedtuples field names for column indices in a list of lists

2017-01-11 Thread Deborah Swanson
Steven D'Aprano wrote, on January 10, 2017 6:19 PM
> 
> On Tuesday 10 January 2017 18:14, Deborah Swanson wrote:
> 
> > I'm guessing that you (and those who see things like you do) might 
> > not be used to working with quick learners who make mistakes at 
> > first but catch up with them real fast, or you're very judgemental 
> > about people who make mistakes, period. I certainly don't care if 
> > you want to judge me, you're entitled to your opinion.
> 
> Be fair. We're not mind-readers, and we're trying to help you, not 
> attack you.

You aren't, and I've never seen you as attacking me, but there's a few
others here who have attacked me, and they weren't trying to help me
either. But it's only a very few people who've harrassed me, and the
person I was writing to above wasn't one of them. 

> It is true that we're often extremely pedantic. Sometimes annoyingly
> so, but on the other hand precision is important, especially in 
> technical fields. > There's a *huge* difference between a MTA and a 
> MUA, even though they differ only by one letter and both are related 
> to email.
>
> One of the techs I work with has the same habit of correcting me, and 
> when I'm invariably forced to agree that he is technical correct, he 
> replies "technical correctness is the best kind of correctness". 
> Annoying as it is to be on the receiving end, he is right: at least 
> half the time I learn something from his pedantry. (The other half of 
> the time, its a difference that makes no difference.)

I'm sorry you have to work with someone like that, he sounds perfectly
awful. (But that doesn't give you license to do the same. You're better
than that.)

> What are we supposed to do when somebody asks a question based on an
> obvious mistake? Assume that they're a quick learner who has probably 
> already worked out their mistake and doesn't need an answer? That 
> would certainly make our life easier: we can just ignore everybody's 
> questions.

No, of course not. My advice to people who want to help is to not assume
that you know what the question asker does and doesn't know, and just
answer the questions without obsessing about what they know. If that's
impossible because they have something so wrong that you don't know what
they're asking, that would be a good time to point it out and give them
a chance to correct it. 

> Sometimes people make errors of terminology that doesn't affect the 
> semantics of what they're asking:
> 
> "I have an array [1, 2, 3, 4] and I want to ..."
> 
> It's very likely that they have a list and they're merely using a term

> they're familiar with from another language, rather than the array 
> module.
> 
> But what are we supposed to make of mistakes that *do* affect the 
> semantics of the question:
> 
> "I have a dict of ints {1, 2, 3, 4} and want to sort the values by

> key so that I get [4, 2, 3, 1], how do I do that?"
> 
> How can we answer that without correcting their misuse of terminology
> and asking for clarification of what data structure they *actually* 
> have?
>
> We get questions like this very frequently. How would you answer it?

Well, I'd tell them how to reverse sort a dictionary, and point out that
what they've given isn't a dictionary because it doesn't have any keys,
and on this occasion I'd just give them an example of what a dictionary
looks like (as part of showing them how to reverse sort it) with its
keys, including the curly braces, and see what they come back with. They
pretty clearly mean a dictionary and not a list, since they said "dict",
used curly braces, and said they want to sort the values by key" in the
first clause of their sentence. So they're just a little confused and
maybe absent-mindedly slipping back into the more familiar list notation
and concepts, or they don't exactly know what a dictionary is. I
wouldn't belabor the point at this time, unless they keep coming back
with the same issues. That would be the time to belabor it, in my
opinion.  When some people are learning it's hard to keep all the new
things firmly in mind and not confuse them with more familiar things
they already know. But if they get it all straight in reasonably good
time, that should be ok. 

> Or:
> 
> "I have a list l = namedtuple('l', 'field1 field2') and can't 
> extract fields by index, l[0] doesn't work..."
> 
> Of course it doesn't work. How would you respond to that if you were
> in our place?
> 
> - ignore the question because the poster is ever so smart and will
have
>   worked it out by now?
> 
> - point out that l is not a list, or even a tuple, and of course l[0] 
>   doesn't work because l is actually a class?

I'd go with some variant of option 2, depending on how well I knew the
person asking. If the asker had just dropped in out of the blue and I
knew nothing about them I'd say something like "You can't because 'l'
isn't a list." Then I'd try to gauge how useful it would be to them to
know exactly what 'l' is, but most likely 

RE: reactiveX vs Async

2017-01-11 Thread Joseph L. Casale
> Try these links on for size:
>
> https://msdn.microsoft.com/en-us/library/hh242982(v=vs.103).aspx which links 
> to
> https://msdn.microsoft.com/en-us/library/hh242983(v=vs.103).aspx near the end.

These two SO threads have a variation of pretty good explanations:

http://stackoverflow.com/questions/2550763/good-example-of-reactive-extensions-use
http://stackoverflow.com/questions/1596158/good-introduction-to-the-net-reactive-framework


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


RE: reactiveX vs Async

2017-01-11 Thread Joseph L. Casale
>> There is the recent flurry around the new async additions to python
>
> I meant to add: “… which I dont pretend to understand…”

Try these links on for size:

https://msdn.microsoft.com/en-us/library/hh242982(v=vs.103).aspx which links to
https://msdn.microsoft.com/en-us/library/hh242983(v=vs.103).aspx near the end.

That summarizes the conceptual difference pretty well imho. It's also 
summarized on
the .NET versions GitHub page: 
https://github.com/Reactive-Extensions/Rx.NET#a-brief-intro

I think you can summarize RX as a framework whereas async/await can be used 
without
significant buy-in (Overlook the "async top down or none at all" best practice 
sound bite).
That is, you can artificially convert a synchronous method into a threaded 
operation and
have it executely asynchronously while you do something else and wait on it for 
completion
at somne other time.

However, I have only used the .NET implementations.

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


Re: reactiveX vs Async

2017-01-11 Thread Rustom Mody
On Thursday, January 12, 2017 at 6:50:09 AM UTC+5:30, Joseph L. Casale wrote:
> >> There is the recent flurry around the new async additions to python
> >
> > I meant to add: “… which I dont pretend to understand…”
> 
> Try these links on for size:
> 
> https://msdn.microsoft.com/en-us/library/hh242982(v=vs.103).aspx which links 
> to
> https://msdn.microsoft.com/en-us/library/hh242983(v=vs.103).aspx near the end.
> 
> That summarizes the conceptual difference pretty well imho. It's also 
> summarized on
> the .NET versions GitHub page: 
> https://github.com/Reactive-Extensions/Rx.NET#a-brief-intro
> 
> I think you can summarize RX as a framework whereas async/await can be used 
> without
> significant buy-in (Overlook the "async top down or none at all" best 
> practice sound bite).
> That is, you can artificially convert a synchronous method into a threaded 
> operation and
> have it executely asynchronously while you do something else and wait on it 
> for completion
> at somne other time.
> 
> However, I have only used the .NET implementations.
> 
> jlc

Thanks Joseph
Trouble is there is stew of technologies/languages…
(meta)-stewed with more abstract concepts, eg push vs pull, 
Enumerable-Observable
duality, continuous vs discrete time
The last causing its own share of confusion with “functional reactive 
programming” (FRP) meaning sometimes the one and sometimes the other:
http://lambda-the-ultimate.org/node/4982

As for 'Overlook the “async/await can be used without significant buy-in” '
I believe Ive seen people with considerable experience/understanding of the area
take the opposite view, usually along the lines: “Once you start going 
non-blocking,
you have to non-block all the way”
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: reactiveX vs Async

2017-01-11 Thread Rustom Mody
On Thursday, January 12, 2017 at 6:50:09 AM UTC+5:30, Joseph L. Casale wrote:
> However, I have only used the .NET implementations.

One more question: Do you know if (and how much) of these things would work
in Linux/C# (ie mono)?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot import GDAL

2017-01-11 Thread Terry Reedy

On 1/11/2017 5:06 PM, Fabien wrote:

On 01/11/2017 10:59 PM, Fabien wrote:

I would strongly recommend to use conda
(http://conda.pydata.org/miniconda.html) for managing your packages and
environments, and then use the conda-forge channel
(https://conda-forge.github.io/) to install gdal:

conda install -c conda-forge gdal



I forgot to mention that since py3.6 is quite recent, most packages
still don't have binaries ready for it. Staying with py3.5 is a better
idea for now.


http://www.lfd.uci.edu/~gohlke/pythonlibs/
has 32 and 64 bit 3.6 binaries for over 200 packages, including GDAL 2.1.2.


--
Terry Jan Reedy

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


Re: Cannot import GDAL

2017-01-11 Thread Terry Reedy

On 1/11/2017 12:31 PM, Falter, Donald [USA] wrote:

I am new to Python and I am trying to utilize GDAL.  I installed Python 3.6.  
The version I get when I activate IDLE is: MSC v.1900 32 bit (Intel)] on win32. 
 In downloading the GDAL bindings the latest version I can find is 
release-1800-gdal-2-1-2-mapserver-7-0-2 so I installed the following: 
gdal-201-1800-core.msi and GDAL-2.1.2.win32-py3.4.msi.

I added C:\Program Files\GDAL to my path and added the system variables 
GDAL_DATA = C:\Program Files\GDAL\gdal-data and\
GDAL_DRIVER_PATH = C:\Program Files\GDAL\gdalplugins

When I open IDLE and type the following: from osgeo import gdal I get the 
following error


IDLE does not normally cause imports to fail (though it often get 
blamed), but one can check by running, in this case, 3.6, from the 
Windows console (ie, Command Prompt) and trying the same import statement.



from osgeo import gdal

Traceback (most recent call last):
  File "", line 1, in 
from osgeo import gdal
ModuleNotFoundError: No module named 'osgeo'


Does C:\Program Files\GDAL contain a package 'osgeo' containing a module 
'gdal'?


I am not sure if the version mismatch pointed out by others would cause 
that particular error.  If replacing the 3.4 package with a 3.6 package 
fixes your problem completely, please let us know.


--
Terry Jan Reedy

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


RE: reactiveX vs Async

2017-01-11 Thread Joseph L. Casale
> Thanks Joseph
> Trouble is there is stew of technologies/languages…
> (meta)-stewed with more abstract concepts, eg push vs pull, 
> Enumerable-Observable
> duality, continuous vs discrete time
> The last causing its own share of confusion with “functional reactive 
> programming” (FRP) meaning sometimes the one and sometimes the other:
> http://lambda-the-ultimate.org/node/4982

Heh,
Yeah I don't claim to be an expert, I have only just started using the syntax
in my own projects whereas I almost always used the classical thread model
with sync primitives and message passing.

> As for 'Overlook the “async/await can be used without significant buy-in” '
> I believe Ive seen people with considerable experience/understanding of the 
> area
> take the opposite view, usually along the lines: “Once you start going 
> non-blocking,
> you have to non-block all the way”

Right, as I mentioned overlook the pedantic argument just for the concept.
While you *can* do as I mentioned rather easily, it's not a useful or scalable
approach. Their suggestion is correct in reality but I only mentioned the 
minimal
buy-in it to illustrate that existing code *could* adopt the pattern trivially
whereas Rx is not simply two keywords, it's an entire framework.

Ultimately they accomplish the same thing, that is asynchronous execution
but use two different patterns. I'll paraphrase another source: "Rx adds a
convenient way to add callbacks and manage execution." The async/await
pattern is closer to the metal, it's not dealing with a sequence of observable
objects, it is however manipulating execution of the explicit block of code 
where
its applied.

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


RE: reactiveX vs Async

2017-01-11 Thread Joseph L. Casale
> One more question: Do you know if (and how much) of these things would work
> in Linux/C# (ie mono)?

Mono, I forgot what that is when .net core debuted:)

Looks like the .net Rx guys have a port, 
https://github.com/Reactive-Extensions/Rx.NET/issues/148

A package for .net core is up on nuget.

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


Re: reactiveX vs Async

2017-01-11 Thread Rustom Mody
On Thursday, January 12, 2017 at 7:47:21 AM UTC+5:30, Joseph L. Casale wrote:
> > One more question: Do you know if (and how much) of these things would work
> > in Linux/C# (ie mono)?
> 
> Mono, I forgot what that is when .net core debuted:)

A brief elaboration on that please?? ∵ …
> 
> Looks like the .net Rx guys have a port, 
> https://github.com/Reactive-Extensions/Rx.NET/issues/148

All this makes little sense to me :-(
C# is a sweet language, in many small ways better than java
But Windows/.NET?? Hoo boy!
[Just an ol-nixer getting lost... No judgement really!]

> 
> A package for .net core is up on nuget.

So you are saying that nuget-ing .Net core would be a workable pre-requisite for
Rx on mono?
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: reactiveX vs Async

2017-01-11 Thread Joseph L. Casale
> So you are saying that nuget-ing .Net core would be a workable pre-requisite 
> for
> Rx on mono?

Microsoft open sourced .net a while ago. With that came the movement to
bring .net to other platforms.

https://en.wikipedia.org/wiki/.NET_Framework#.NET_Core

As its currently being heavily developed, it only provides a subset of the full
.net base class library but its covering more ground constantly. A good intro
into what is covered is 
https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/

So you can install the sdk and runtime on many supported Linux versions,
a mac or Windows. Get it at https://www.microsoft.com/net/download/core

Then use your text editor of choice, or something like visual studio code 
(another
free offering that supports multiple platforms), add the nuget package and hack
away on your platform of choice;).

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


Re: just started

2017-01-11 Thread metal . suomi
along the above discussion, resuming my python after the Xmas break (hope you 
had a nice one!)

I want to install a number of scientific libraries, but I'm confused which 
packages it contains what. 

1) I see on scipy.org that scipy contains scipy library (fine, it makes sense), 
along with other ones  (numpy, matplotlib ). So, I would guess that the 
following command 

pip install --user scipy

install all the libraries I need, but instead it seems that I need to specify 
them too? I.e. to install them I need to name them

pip install --user scipy numpy matplotlib etc... etc...
(of course, I guess I can equivalently use the command python3.5 -m pip install 
--user scipy numpy matplotlib  right?)

2) I have already install matplotlib time ago. So, in the above commands I can 
avoid to add matplotlib, or I can included and a new installation will be 
overwritten, correct?

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