Ammended proposal: Python 832? Re: The next major Python version will be Python 8

2016-04-01 Thread Stefan Hagen
Sorry for the blunt terseness, but wasn't the plan to target Python 832
i.e. 8.3.2 as a single, frozen thus *eternal* version tag to firstly
integrate all beauty (PEP8), good (3.x), bad (2.x) and secondly
**never** have to embrace those thrilling, dirty changes again, was it?

$ python832 -m stefan
Before you write, think, after you read.

Am 01.04.16 um 00:26 schrieb Victor Stinner:
> Hi,
> 
> Python 3 becomes more and more popular and is close to a dangerous point
> where it can become popular that Python 2. The PSF decided that it's
> time to elaborate a new secret plan to ensure that Python users suffer
> again with a new major release breaking all their legacy code.
> 
> The PSF is happy to announce that the new Python release will be
> Python 8!
> 
> Why the version 8? It's just to be greater than Perl 6 and PHP 7, but
> it's also a mnemonic for PEP 8. By the way, each minor release will now
> multiply the version by 2. With Python 8 released in 2016 and one
> release every two years, we will beat Firefox 44 in 2022 (Python 64) and
> Windows 2003 in 2032 (Python 2048).
> 
> A major release requires a major change to justify a version bump: the
> new killer feature is that it's no longer possible to import a module
> which does not respect the PEP 8. It ensures that all your code is pure.
> Example:
> 
> $ python8 -c 'import keyword'
> Lib/keyword.py:16:1: E122 continuation line missing indentation or 
> outdented
> Lib/keyword.py:16:1: E265 block comment should start with '# '
> Lib/keyword.py:50:1: E122 continuation line missing indentation or 
> outdented
> (...)
> ImportError: no pep8, no glory
> 
> Good news: since *no* module of the current standard library of Python 3
> respect the PEP 8, the standard library will be simplified to one
> unique module, which is new in Python 8: pep8. The standard library will
> move to the Python Cheeseshop (PyPI), to reply to an old and popular
> request.
> 
> 
> DON'T PANIC! You are still able to import your legacy code into
> Python 8, you just have to rename all your modules to add a "_noqa" suffix
> to the filename. For example, rename utils.py to utils_noqa.py. A side
> effect is that you have to update all imports. For example, replace
> "import django" with "import django_noqa". After a study of the PSF,
> it's a best option to split again the Python community and make sure
> that all users are angry.
> 
> 
> The plan is that in 10 years, at least 50% of the 77,000 packages on the
> Python cheeseshop will be updated to get the "_noqa" tag. After 2020,
> the PSF will start to sponsor trolls to harass users of the legacy
> Python 3 to force them to migrate to Python 8.
> 
> 
> Python 8 is a work-in-progress (it's still an alpha version), the
> standard library was not removed yet. Hopefully, trying to import any
> module of the standard library fails.
> 
> Don't hesitate to propose more ideas to make Python 8 more incompatible
> with Python 3!
> 
> Note: The change is already effective in the default branch of Python:
> https://hg.python.org/cpython/rev/9aedec2dbc01
> 
> Have fun,
> Victor
> 


-- 
Stefan Hagen
read://stefan-hagen.website
talk://0049 151 70 89 64 00
-- 
https://mail.python.org/mailman/listinfo/python-list


Help is needed!

2016-04-01 Thread A. ElKader
Hi,

I am trying to do the following :

I am trying to show the changes in the command line in real time in my
Tkinter GUI, I managed to create the GUI and integrate the terminal into
it, but I cant bind the buttons with the terminal, my code is :

import Tkinterfrom Tkinter import *import subprocessimport osfrom os
import system as cmd

WINDOW_SIZE = "600x400"
top = Tkinter.Tk()
top.geometry(WINDOW_SIZE)
def helloCallBack():
   print "Below is the output from the shell script in terminal"
   subprocess.call('perl
/projects/tfs/users/$USER/scripts_coverage.pl', shell=True)def
BasicCovTests():
   print "Below is the output from the shell script in terminal"
   subprocess.call('perl
/projects/tfs/users/$USER/basic_coverage_tests.pl', shell=True)def
FullCovTests():
   print "Below is the output from the shell script in terminal"
   subprocess.call('perl
/projects/tfs/users/$USER/basic_coverage_tests.pl', shell=True)

Scripts_coverage  = Tkinter.Button(top, text ="Scripts Coverage",
command = helloCallBack)Scripts_coverage.pack()
Basic_coverage_tests  = Tkinter.Button(top, text ="Basic Coverage
Tests", command = BasicCovTests)Basic_coverage_tests.pack()
Full_coverage_tests  = Tkinter.Button(top, text ="Full Coverage
Tests", command = FullCovTests)Full_coverage_tests.pack()

termf = Frame(top, height=100, width=500)

termf.pack(fill=BOTH, expand=YES)
wid = termf.winfo_id()

os.system('xterm -into %d -geometry 100x20 -sb &' % wid)
def send_entry_to_terminal(*args):
"""*args needed since callback may be called from no arg (button)
   or one arg (entry)
   """
cmd("%s" % (BasicCovTests))

top.mainloop()
I want win I click the button to see it printing the command in the
terminal[image: enter image description here]



How do I do that ???

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


Re: Suggestion: make sequence and map interfaces more similar

2016-04-01 Thread Antoon Pardon
Op 31-03-16 om 16:12 schreef Mark Lawrence via Python-list:
> On 31/03/2016 14:27, Random832 wrote:
>> So can we discuss how a unified method to get a set of all valid
>> subscripts (and/or subscript-value pairs) on an object would be a useful
>> thing to have without getting bogged down in theoretical claptrap about
>> the meaning of the mapping contract?
>>
>
> We can discuss anything here until the cows come home, but it's a
> complete waste of time if the powers that be over on python-ideas
> and/or python-dev don't agree.  This was suggested a day or two back
> but seems to have gone completely over people's heads.

Just because you are not interested, doesn't mean it's a complete waste of time.
Discussions like this often enough produce suggestions on how one could handle
these things within python without the need for the powers that be to agree on
anything.

If you are not interested just don't contribute. Others can make up their own
mind on whether this is a waste of their time or not.

-- 
Antoon. 

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


Re: Suggestion: make sequence and map interfaces more similar

2016-04-01 Thread Michael Selik

> On Mar 31, 2016, at 10:02 AM, Marko Rauhamaa  wrote:
> 
> However, weirdly, dicts have get but lists don't.

Read PEP 463 for discussion on this topic.
https://www.python.org/dev/peps/pep-0463/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-04-01 Thread Tim Golden
On 01/04/2016 08:59, Antoon Pardon wrote:
> Op 31-03-16 om 16:12 schreef Mark Lawrence via Python-list:
>> On 31/03/2016 14:27, Random832 wrote:
>>> So can we discuss how a unified method to get a set of all valid
>>> subscripts (and/or subscript-value pairs) on an object would be a useful
>>> thing to have without getting bogged down in theoretical claptrap about
>>> the meaning of the mapping contract?
>>>
>>
>> We can discuss anything here until the cows come home, but it's a
>> complete waste of time if the powers that be over on python-ideas
>> and/or python-dev don't agree.  This was suggested a day or two back
>> but seems to have gone completely over people's heads.
> 
> Just because you are not interested, doesn't mean it's a complete waste of 
> time.
> Discussions like this often enough produce suggestions on how one could handle
> these things within python without the need for the powers that be to agree on
> anything.
> 
> If you are not interested just don't contribute. Others can make up their own
> mind on whether this is a waste of their time or not.

FWIW I'm broadly with Antoon here: wider-ranging discussions can be
interesting and useful. (And informative, especially where people speak
knowledgeably about an area outside my own competence). There *are*
technical forums where anything outside their strict subject matter is
frowned upon or curtailed. I don't think we need to be that rigid here.

However I think there are a couple of lines which can be crossed. In one
case a a poster (perhaps abruptly) says: I think Python should do this;
why doesn't it? The other is where the discussion goes so far into
cloud-cuckoo land that it alienates all but a few devoted adherents to
the thread. Especially where it goes round in circles.

For the latter, I take the view that I know where the delete key is (or
the "ignore thread" button or whatever) and I just skip the thread when
it shows up. Perhaps missing some interesting points in the process if
it comes back down to earth but that's the way it goes.

For the former, I think it's fine if someone is asking in a genuine
spirit of enquiry, ie to learn about the history of a particular
decision or the ramifications of an alternative which might not be
obvious at first glance. (Why do we have both lists and tuples? Why does
Python index from 0? etc). People who know something about it can
explain if they wish.

If it becomes clear that the poster is in fact pushing for a change
(either intelligently thought-out or naively ill-considered) then I
would push them towards Python-ideas sooner than later, because that's
exactly the purpose of *that* mailing list. People on python-ideas want
to go to and fro over the relative merits of proposals. Specifically, I
believe that's the only mailing list which GvR follows apart from
python-dev. Any discussion here would likely have to be repeated over
there anyway, so why not go there earlier on?

Courtesy & respect on this and any list are important, so as long as
someone's not being genuinely rude or abusive, your best plan is to make
your point clearly and politely and then step back. I've been impressed
again and again on Python lists where people maintain a courteous front
in the course of a perhaps quite heated discussion. And more impressed
when people who have lost their cool come back and apologise (without
necessarily backing down from their point, of course).

Feel free to contact the list owner [python-list-ow...@python.org] if
you think there's a real contravention of the list etiquette but I'm
personally not inclined to jump too heavily on rambling discussions or
wild-eyed ideas as such.

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


Re: The next major Python version will be Python 8

2016-04-01 Thread Michael Selik
It suddenly occurred to me that if Microsoft announced it's
Ubuntu-in-Windows feature today, no one would believe it.

On Thu, Mar 31, 2016 at 11:55 PM Steven D'Aprano 
wrote:

> On Fri, 1 Apr 2016 11:13 am, Chris Angelico wrote:
>
> > Now's the time to get in with the ideas. My proposal is that Python 8,
> > in keeping with its new opinionated style, will require everyone to
> > follow a single timezone: Europe/Amsterdam.
>
> Swatch Internet time:
>
> https://en.wikipedia.org/wiki/Swatch_Internet_Time
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-04-01 Thread Mark Lawrence via Python-list

On 01/04/2016 08:59, Antoon Pardon wrote:

Op 31-03-16 om 16:12 schreef Mark Lawrence via Python-list:

On 31/03/2016 14:27, Random832 wrote:

So can we discuss how a unified method to get a set of all valid
subscripts (and/or subscript-value pairs) on an object would be a useful
thing to have without getting bogged down in theoretical claptrap about
the meaning of the mapping contract?



We can discuss anything here until the cows come home, but it's a
complete waste of time if the powers that be over on python-ideas
and/or python-dev don't agree.  This was suggested a day or two back
but seems to have gone completely over people's heads.


Just because you are not interested, doesn't mean it's a complete waste of time.
Discussions like this often enough produce suggestions on how one could handle
these things within python without the need for the powers that be to agree on
anything.

If you are not interested just don't contribute. Others can make up their own
mind on whether this is a waste of their time or not.



Who said I'm not interested?  It is a simple fact of life in Python 
world that anything that gets discussed has to go through python-dev, 
and possibly python-ideas first.  You can spend years discussing 
anything you like here and get 100% agreement, but if the devlopers say 
no it does not happen.


I believe that this proposal is like trying to change the design of the 
Morris Minor and a McClaren Mercedes because they're both cars, so you 
can make them similar.


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

Mark Lawrence

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


Re: The next major Python version will be Python 8

2016-04-01 Thread alister
On Fri, 01 Apr 2016 11:13:43 +1100, Chris Angelico wrote:

> On Fri, Apr 1, 2016 at 11:09 AM, Ethan Furman 
> wrote:
>> On 03/31/2016 05:02 PM, Roel Schroeven wrote:
>>>
>>> Victor Stinner schreef op 2016-03-31 23:40:
>>
>>
 Python 3 becomes more and more popular and is close to a dangerous
 point where it can become popular that Python 2. The PSF decided that
 it's time to elaborate a new secret plan to ensure that Python users
 suffer again with a new major release breaking all their legacy code.
>>>
>>>
>>> "2016-03-31 23:40"
>>> You're 20 minutes early :)
>>
>>
>> No, that's a naive datetime.  You need to travel to Victor's location
>> to figure out what that is there.
>>
>> I sure hope Python 8 doesn't have that problem!
> 
> Now's the time to get in with the ideas. My proposal is that Python 8,
> in keeping with its new opinionated style, will require everyone to
> follow a single timezone: Europe/Amsterdam.
> 
> ChrisA

Not bad but it would have to be Zulu (GMT)



-- 
Nobody's gonna believe that computers are intelligent until they start
coming in late and lying about it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The next major Python version will be Python 8

2016-04-01 Thread Chris Angelico
On Fri, Apr 1, 2016 at 8:44 PM, alister  wrote:
> On Fri, 01 Apr 2016 11:13:43 +1100, Chris Angelico wrote:
>
>> Now's the time to get in with the ideas. My proposal is that Python 8,
>> in keeping with its new opinionated style, will require everyone to
>> follow a single timezone: Europe/Amsterdam.
>>
>> ChrisA
>
> Not bad but it would have to be Zulu (GMT)

Why? Nothing in Python's documentation ever says you have to be a Zuul
to understand its design choices!

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


Re: Suggestion: make sequence and map interfaces more similar

2016-04-01 Thread Steven D'Aprano
On Fri, 1 Apr 2016 07:27 pm, Tim Golden wrote:

> FWIW I'm broadly with Antoon here: wider-ranging discussions can be
> interesting and useful. 

Sure. But sometimes conversations are going nowhere:

http://www.youtube.com/watch?v=kQFKtI6gn9Y

http://www.montypython.net/scripts/argument.php


[...]
> If it becomes clear that the poster is in fact pushing for a change
> (either intelligently thought-out or naively ill-considered) then I
> would push them towards Python-ideas sooner than later, because that's
> exactly the purpose of *that* mailing list. People on python-ideas want
> to go to and fro over the relative merits of proposals. Specifically, I
> believe that's the only mailing list which GvR follows apart from
> python-dev. Any discussion here would likely have to be repeated over
> there anyway, so why not go there earlier on?

Informally, ideas are supposed to have an initial "sanity check" here to
avoid the really silly ideas:


Q: "Suggestion: I'm sick of writing

for key, value in other_dict.items():
mydict[key] = value

I think that dicts should have a method to copy all the keys and values from
another dict."

A: "You mean dict.update?"


Or perhaps:

Q: "I think that object oriented programming is too inefficient. I think
that Python should get rid of all the objects and just be a lightweight,
easy-to-read wrapper around C, with the same semantics and limitations as
the 1988 C standard."

A: "Surely you aren't serious?"


But most people don't bother passing ideas through here first, they just go
straight to Python-Ideas.




-- 
Steven

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


Re: Suggestion: make sequence and map interfaces more similar

2016-04-01 Thread Marko Rauhamaa
Steven D'Aprano :

> On Fri, 1 Apr 2016 07:27 pm, Tim Golden wrote:
>
>> FWIW I'm broadly with Antoon here: wider-ranging discussions can be
>> interesting and useful. 
>
> Sure. But sometimes conversations are going nowhere:

That's why GNUS has the "k" command to wipe out a whole thread.

I know, it depends on threading working...


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


install open cv on windows 10 and python 3.5

2016-04-01 Thread saxri89
hello,

i have windows 10 and python 3.5 and i want to use
open cv but i think so opencv work only on python 2.7 ?
and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
but not work again
-- 
https://mail.python.org/mailman/listinfo/python-list


Strange range

2016-04-01 Thread Marko Rauhamaa

This seems sane:

>>> it = iter(range(10))
>>> for i in it:
...   if i >= 3:
... break
...
>>> list(it)
[4, 5, 6, 7, 8, 9]

As does this:

>>> it = iter(list(range(10)))
>>> for i in it:
...   if i >= 3:
... break
...
>>> list(it)
[4, 5, 6, 7, 8, 9]

This not so much:

>>> it = range(10)
>>> for i in it:
...   if i >= 3:
...  break
...
>>> list(it)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Note to self: range(10) is an iterator factory, not an iterator.


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


Re: Strange range

2016-04-01 Thread Chris Angelico
On Sat, Apr 2, 2016 at 12:15 AM, Marko Rauhamaa  wrote:
> Note to self: range(10) is an iterator factory, not an iterator.

It is an iterable. It is not a factory, as that implies that you call
it. It is an object which, when you ask it for an iterator, gives you
an iterator. That's called an iterable.

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


Re: Strange range

2016-04-01 Thread Steven D'Aprano
On Sat, 2 Apr 2016 12:15 am, Marko Rauhamaa wrote:

> 
> This seems sane:
[...] 
> This not so much:
> 
> >>> it = range(10)
> >>> for i in it:
> ...   if i >= 3:
> ...  break
> ...
> >>> list(it)
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> 
> Note to self: range(10) is an iterator factory, not an iterator.

Incorrect. range is a lazy sequence.

The only difference between [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] and range(10) is
that the list [0, ..., 9] is calculated eagerly, ahead of time, while
range(10) only generates the values on demand. You can think of range as
equivalent to something close to this:


class Range(object):
def __init__(self, start, end, step=1):
self.start = start
self.end = end
self.step = step

def __getitem__(self, index):
value = self.start + (index-1)*self.step
if value < self.end:
return value
raise IndexError

def __iter__(self):
try:
index = 0
while True:
yield self[index]
index += 1
except IndexError:
return



except with more error checking, better bounds checking, support for the
`in` operator, etc.



-- 
Steven

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


Re: The next major Python version will be Python 8

2016-04-01 Thread Gisle Vanem via Python-list
Michael Selik wrote:

> It suddenly occurred to me that if Microsoft announced it's
> Ubuntu-in-Windows feature today, no one would believe it.

My feeling too, but this was announced 30 March.
In the video in this link:
  
http://www.cnx-software.com/2016/03/31/microsoft-brings-bash-on-ubuntu-on-windows-10/

they say Python inside Ubuntu-in-Windows works! Ref. time 03:03.

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


Re: Strange range

2016-04-01 Thread Marko Rauhamaa
Steven D'Aprano :

> On Sat, 2 Apr 2016 12:15 am, Marko Rauhamaa wrote:
>> Note to self: range(10) is an iterator factory, not an iterator.
>
> Incorrect. range is a lazy sequence.

Incorrect. You and I agree.

> You can think of range as equivalent to something close to this:
>
> class Range(object):
> def __init__(self, start, end, step=1):
> self.start = start
> self.end = end
> self.step = step
>
> def __getitem__(self, index):
> value = self.start + (index-1)*self.step
> if value < self.end:
> return value
> raise IndexError
>
> def __iter__(self):
> try:
> index = 0
> while True:
> yield self[index]
> index += 1
> except IndexError:
> return

Yes, I realize it now. I had thought it was:

def range(start, end=None, step=1):
if end is None:
start, end = 0, start
i = start
while step * (end - i) > 0:
yield i
i += step


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


Re: Strange range

2016-04-01 Thread Fabien

On 04/01/2016 03:26 PM, Steven D'Aprano wrote:

Incorrect. range is a lazy sequence.


But how does range "know" that it has to start from scratch again? As in 
this example:


it = range(10)
for i in it:
if i >= 3:
break
for i in it:
# why does it start from zero again?
print(i)
--
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-01 Thread Jussi Piitulainen
Fabien writes:

> On 04/01/2016 03:26 PM, Steven D'Aprano wrote:
>> Incorrect. range is a lazy sequence.
>
> But how does range "know" that it has to start from scratch again? As
> in this example:
>
> it = range(10)
> for i in it:
> if i >= 3:
> break
> for i in it:
> # why does it start from zero again?
> print(i)

The loops are effectively iterating over iter(it) each time. Since "it"
is not already an iterator, iter constructs a new one based on "it".

Try it = iter(range(10)) to see it not start over.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-01 Thread Chris Angelico
On Sat, Apr 2, 2016 at 1:16 AM, Fabien  wrote:
> On 04/01/2016 03:26 PM, Steven D'Aprano wrote:
>>
>> Incorrect. range is a lazy sequence.
>
>
> But how does range "know" that it has to start from scratch again? As in
> this example:
>
> it = range(10)
> for i in it:
> if i >= 3:
> break
> for i in it:
> # why does it start from zero again?
> print(i)

It's not an iterator. It's an iterable. So every time you call iter()
on it - which is done implicitly by the starting of the 'for' loop -
you get a completely new iterator which will step through the whole
range object.

*A range object is not an iterator.*

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


Re: The next major Python version will be Python 8

2016-04-01 Thread Grant Edwards
On 2016-04-01, alister  wrote:
> On Fri, 01 Apr 2016 11:13:43 +1100, Chris Angelico wrote:
>
>> On Fri, Apr 1, 2016 at 11:09 AM, Ethan Furman 
>> wrote:
>>> On 03/31/2016 05:02 PM, Roel Schroeven wrote:

 Victor Stinner schreef op 2016-03-31 23:40:
>>>
>>>
> Python 3 becomes more and more popular and is close to a dangerous
> point where it can become popular that Python 2. The PSF decided that
> it's time to elaborate a new secret plan to ensure that Python users
> suffer again with a new major release breaking all their legacy code.


 "2016-03-31 23:40"
 You're 20 minutes early :)
>>>
>>>
>>> No, that's a naive datetime.  You need to travel to Victor's location
>>> to figure out what that is there.
>>>
>>> I sure hope Python 8 doesn't have that problem!
>> 
>> Now's the time to get in with the ideas. My proposal is that Python 8,
>> in keeping with its new opinionated style, will require everyone to
>> follow a single timezone: Europe/Amsterdam.
>
> Not bad but it would have to be Zulu (GMT)

Nope, my vote is for TAI.  It's even more opinionated.  That whole
making the time agree with the changing rotation of the Earth thing is
just too wishy-washy.

-- 
Grant Edwards   grant.b.edwardsYow! ... I don't like FRANK
  at   SINATRA or his CHILDREN.
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-01 Thread Marko Rauhamaa
Fabien :

> On 04/01/2016 03:26 PM, Steven D'Aprano wrote:
>> Incorrect. range is a lazy sequence.
>
> But how does range "know" that it has to start from scratch again?

The "for .. in" statement invokes the __iter__() method of the iterable
object to get an iterator (maybe via the builtin iter() function).

Iterators have an __iter__() method as well which returns the iterator
itself.

Thus,

   >>> it = iter(range(10))
   >>> it is iter(it)
   True


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


Re: Strange range

2016-04-01 Thread Marko Rauhamaa
Chris Angelico :

> *A range object is not an iterator.*

We now have learned as much.

However, doesn't that extra level of indirection seem like an odd
choice?


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


Re: Strange range

2016-04-01 Thread Random832
On Fri, Apr 1, 2016, at 10:12, Marko Rauhamaa wrote:
> Yes, I realize it now. I had thought it was:
> 
> def range(start, end=None, step=1):
> if end is None:
> start, end = 0, start
> i = start
> while step * (end - i) > 0:
> yield i
> i += step

You know the other funny thing? Even people who understand this about
Python 3 ranges, many assume that python 2 xrange was more similar to
your latter example (possibly caused by the fact that python 2 had other
things such as dict.iteritems which _were_ mere iterators)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-01 Thread Random832
On Fri, Apr 1, 2016, at 09:24, Chris Angelico wrote:
> It is an iterable. It is not a factory, as that implies that you call
> it.

I do have an objection to this statement. It's perfectly reasonable to
describe the factory pattern as applying to objects on which you call a
method to return the new object you are interested in. In this sense,
all collections are iterator factories.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-01 Thread Jussi Piitulainen
Marko Rauhamaa writes:
> Chris Angelico wrote:
>
>> *A range object is not an iterator.*
>
> We now have learned as much.
>
> However, doesn't that extra level of indirection seem like an odd
> choice?

I think it's brilliant. The range object behaves like a tuple containing
the numbers in the range, one can index it, slice it, zip it, for it,
like it, without it taking up the space or getting consumed in the
process.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-04-01 Thread Rustom Mody
On Friday, April 1, 2016 at 1:58:29 PM UTC+5:30, Tim Golden wrote:
> 
> For the latter, I take the view that I know where the delete key is (or
> the "ignore thread" button or whatever) and I just skip the thread when
> it shows up.



> Feel free to contact the list owner [python list-owner] if
> you think there's a real contravention of the list etiquette but I'm
> personally not inclined to jump too heavily on rambling discussions or
> wild-eyed ideas as such.

I thought sanity was frowned upon out here 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-01 Thread Chris Angelico
On Sat, Apr 2, 2016 at 1:34 AM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> *A range object is not an iterator.*
>
> We now have learned as much.
>
> However, doesn't that extra level of indirection seem like an odd
> choice?

No; a range object is an entity in itself. You can test if something's
within the range:

>>> 5 in range(2,10)
True
>>> 5 in range(2,10,2)
False

You can ask how many numbers are in the range:

>>> len(range(2,10,2))
4

You can even ask what position a number would be in, if you index
through the range:

>>> range(3,100,3).index(57)
18

Iterators can't do any of this, except the 'in' check, which is
destructive and O(N).

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


Re: Strange range

2016-04-01 Thread Chris Angelico
On Sat, Apr 2, 2016 at 1:42 AM, Random832  wrote:
> On Fri, Apr 1, 2016, at 09:24, Chris Angelico wrote:
>> It is an iterable. It is not a factory, as that implies that you call
>> it.
>
> I do have an objection to this statement. It's perfectly reasonable to
> describe the factory pattern as applying to objects on which you call a
> method to return the new object you are interested in. In this sense,
> all collections are iterator factories.

Hmm. I suppose that would be reasonable, if you expect to call
range_object.__iter__() - but you shouldn't. You should call
iter(range_object), which, to my mind, means that *iter* is an
iterator factory.

Anyway, the word "iterable" accurately sums up the state: it's a thing
you can iterate over.

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


Re: Strange range

2016-04-01 Thread Ian Kelly
On Fri, Apr 1, 2016 at 8:42 AM, Random832  wrote:
> On Fri, Apr 1, 2016, at 09:24, Chris Angelico wrote:
>> It is an iterable. It is not a factory, as that implies that you call
>> it.
>
> I do have an objection to this statement. It's perfectly reasonable to
> describe the factory pattern as applying to objects on which you call a
> method to return the new object you are interested in. In this sense,
> all collections are iterator factories.

I think the problem with that is that it implies something about the
purpose of the object. Usually when we talk about the factory pattern,
we're talking about an object that creates instances of something and
does nothing else. So in that sense it's misleading to refer to dict
or list or even range objects as "iterator factories", because they
also do a lot of other things that are equally if not more important.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Set type for datetime intervals

2016-04-01 Thread Random832
On Fri, Apr 1, 2016, at 01:24, Nagy László Zsolt wrote:
>  
>   Hello,
> 
> I need to compare sets of datetime intervals, and make set operations on
> them: intersect, union, difference etc. One element of a set would be an
> interval like this:

Two thoughts on this: Such an object is not precisely a set* of
datetimes, rather it is a set of nonintersecting intervals. It could
also be useful to have one for numbers (the datetime version could even
maybe be implemented in terms of it)

*in the python sense. in the mathematical sense, it is a set with
infinite* cardinality
**well, datetimes have a fixed resolution, so it's not _really_
infinite. Numbers don't, though.

> element ::= (start_point_in_time, end_point_in_time)
> intervalset ::= { element1, element2,  }

Are these open intervals or closed intervals?

Also, how are you going to handle daylight savings?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The next major Python version will be Python 8

2016-04-01 Thread Gene Heskett
On Friday 01 April 2016 09:06:20 Gisle Vanem via Python-list wrote:

> Michael Selik wrote:
> > It suddenly occurred to me that if Microsoft announced it's
> > Ubuntu-in-Windows feature today, no one would believe it.
>
> My feeling too, but this was announced 30 March.
> In the video in this link:
>  
> http://www.cnx-software.com/2016/03/31/microsoft-brings-bash-on-ubuntu
>-on-windows-10/
>
> they say Python inside Ubuntu-in-Windows works! Ref. time 03:03.
>
> --
> --gv

I am inclined to think that because microsoft just "has to be first" even 
when they are last, they chose to do it a full 2 days early.

Me?  I'm from Missouri.  And I don't know of anyone in my neck of the 
woods who is running winderz-10 so I could go ask them. Shrug.

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-01 Thread Marko Rauhamaa
Chris Angelico :

> On Sat, Apr 2, 2016 at 1:34 AM, Marko Rauhamaa  wrote:
>> However, doesn't that extra level of indirection seem like an odd
>> choice?
>
> No; a range object is an entity in itself. You can test if something's
> within the range:
>
 5 in range(2,10)
> True
 5 in range(2,10,2)
> False
>
> You can ask how many numbers are in the range:
>
 len(range(2,10,2))
> 4
>
> You can even ask what position a number would be in, if you index
> through the range:
>
 range(3,100,3).index(57)
> 18
>
> Iterators can't do any of this, except the 'in' check, which is
> destructive and O(N).

I can't think of a situation where I would have needed those things. I'm
hard-pressed to find an example of noniterator usage of range in the
standard library, for example. Here the only counterexample that caught
my eye among the first couple of hundred of occurrences:

   reversed(range(len(self)))


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


Re: Set type for datetime intervals

2016-04-01 Thread Random832
More thoughts... sorry.

On Fri, Apr 1, 2016, at 01:24, Nagy László Zsolt wrote:
>  
>   Hello,
> 
> I need to compare sets of datetime intervals, and make set operations on
> them: intersect, union, difference etc. One element of a set would be an
> interval like this:
> 
> element ::= (start_point_in_time, end_point_in_time)
> intervalset ::= { element1, element2,  }
> 
> Operations on elements:


Eh... I think these should be realized as operations on an intervalset
with a single element, and that elements should simply have properties
like the start, end, and if it's open or closed on each side. In
particular, any one of these could return something that is not an
element.

> element1.intersect(element2)
May return the empty set, if they do not intersect.

> element1.union(element2)
May return {element1, element 2}

> element1.minus(element2)
May return { (start1, start2), (end2, end1) }... and the open/closeness
of the element2 endpoints is reversed.


> Operations on sets:
> 
> intervalset1.intersect(intervalset2)
> intervalset1.union(intervalset2)
> intervalset1.minus(intervalset2)

These should be operators. s1 & s2, s1 | s2, s1 - s2. There's also a s1
^ s2 operation for python sets, the symmetric difference.


Wouldn't it be useful to have some operations on datetimes?

intervalset1.ltall(dt)
 all(dt < x.start or dt == x.start and x.startopen for x in dt)
intervalset1.gtall(dt)
 all(dt > x.end or dt == x.end and x.endopen for x in dt)
intervalset1.leall(dt)
 all(dt <= x.start for x in intervalset1) # I _think_ this is all
you need for this
intervalset1.geall(dt)
 all(dt >= x.end for x in intervalset1)
dt in intervalset1
... any(dt in elem for x in intervalset1)
dt in elem
... dt > elem.start and dt < elem.end or dt == elem.start and not
elem.startopen or dt == elem.end and not elem.endopen
min and max
... seems trivial, but what to return if the first/last element is open?

I'm truly shocked you didn't even mention the "in" operation.

Also, as long as we're setting up an infinite (not really but anyway)
set, why not also have the ability to have open-ended intervals that
extend to infinity. Then you could invert the set too, for free given
the minus operation: ~x == {(-inf, inf)} - x.


It occurs to me that while I mentioned numbers, in principle you could
use _any_ total-ordered type*. strings, tuples...

*nitpicker's corner: here, "type" is used to mean any set/class/category
of objects, possibly of multiple python types and possibly not
comprising the entirety of a single type, which are total-ordered with
respect to each other, including the codomain of any key projection
function suitable for sorting.
-- 
https://mail.python.org/mailman/listinfo/python-list


A tool to add diagrams to sphinx docs

2016-04-01 Thread George Trojan - NOAA Federal
What graphics editor would you recommend to create diagrams that can be
included in sphinx made documentation? In the past I used xfig, but was not
happy with font quality. My understanding is the diagrams would be saved in
a .png file and I should use an image directive in the relevant .rst file.

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


Re: A tool to add diagrams to sphinx docs

2016-04-01 Thread Irmen de Jong
On 1-4-2016 17:59, George Trojan - NOAA Federal wrote:
> What graphics editor would you recommend to create diagrams that can be
> included in sphinx made documentation? In the past I used xfig, but was not
> happy with font quality. My understanding is the diagrams would be saved in
> a .png file and I should use an image directive in the relevant .rst file.
> 
> George
> 

I've used .png successfully for a few images in my sphinx docs.
However if you're concerned with font quality, a better option is perhaps to 
use a
vector format like SVG instead. You can create them using a tool like Inkskape 
or
Illustrator. I haven't tried to use .svg in sphinx myself yet but I guess it 
simply
embeds/links it into the resulting html so a recent web browser should display 
them just
fine.

Irmen

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


Re: [Python-ideas] Decorators for variables

2016-04-01 Thread Ian Kelly
On Fri, Apr 1, 2016 at 11:14 AM, Matthias welp  wrote:
>> An example of the transformation would help here
>
> An example, that detects cycles in a graph, and doesn't do an update if
> the graph has cycles.

Thanks.

> class A(object):
> def __init__(self, parent):
> @prevent_cycles
> self.parent = parent

I think you'll find that this doesn't work. Properties are members of
the class, not of instances of the class.

> This would prevent cycles from being created in this object A, and would
> make
> some highly reusable code. The same can be done for @not_none, etc, to
> prevent
> some states which may be unwanted.

But you could accomplish the same thing with "self.parent =
prevent_cycles(parent)". So I'm still not seeing how the use of the
decorator syntax eliminates repetition.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: install open cv on windows 10 and python 3.5

2016-04-01 Thread Terry Reedy

On 4/1/2016 6:56 AM, saxr...@gmail.com wrote:

hello,

i have windows 10 and python 3.5 and i want to use
open cv but i think so opencv work only on python 2.7 ?


The following link has binaries for 3.4 and 3.5 as well.  I believe 
Gohlke tests his binaries, so I expect them to work.



and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
but not work again


I don't know what 'not work again' means here.

--
Terry Jan Reedy

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


Re: install open cv on windows 10 and python 3.5

2016-04-01 Thread saxri89
Τη Παρασκευή, 1 Απριλίου 2016 - 1:56:52 μ.μ. UTC+3, ο χρήστης sax...@gmail.com 
έγραψε:
> hello,
> 
> i have windows 10 and python 3.5 and i want to use
> open cv but i think so opencv work only on python 2.7 ?
> and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
> but not work again

i install opencv_python-3.1.0-cp35-none-win32.whl 
but if i import cv2 or import opencv
then show me no module with that name
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: A tool to add diagrams to sphinx docs

2016-04-01 Thread Albert-Jan Roskam


> Subject: Re: A tool to add diagrams to sphinx docs
> From: irmen.nos...@xs4all.nl
> Date: Fri, 1 Apr 2016 18:26:48 +0200
> To: python-list@python.org
> 
> On 1-4-2016 17:59, George Trojan - NOAA Federal wrote:
> > What graphics editor would you recommend to create diagrams that can be
> > included in sphinx made documentation? In the past I used xfig, but was not
> > happy with font quality. My understanding is the diagrams would be saved in
> > a .png file and I should use an image directive in the relevant .rst file.
> > 
> > George
> > 
> 
> I've used .png successfully for a few images in my sphinx docs.
> However if you're concerned with font quality, a better option is perhaps to 
> use a
> vector format like SVG instead. You can create them using a tool like 
> Inkskape or
> Illustrator. I haven't tried to use .svg in sphinx myself yet but I guess it 
> simply
> embeds/links it into the resulting html so a recent web browser should 
> display them just
> fine.
I used .svg for dependency graphs made with snakefood. Looked good in html, 
though they essily get too detailed. The .rst:

.. figure:: images/my_image.svg:width: 100% 
  
-- 
https://mail.python.org/mailman/listinfo/python-list


extract rar

2016-04-01 Thread Jianling Fan
Hello everyone,

I am wondering is there any way to extract rar files by python without
WinRAR software?

I tried Archive() and patool, but seems they required the WinRAR software.

Thanks,

Regards,

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


Re: extract rar

2016-04-01 Thread Random832
On Fri, Apr 1, 2016, at 15:22, Jianling Fan wrote:
> Hello everyone,
> 
> I am wondering is there any way to extract rar files by python without
> WinRAR software?
> 
> I tried Archive() and patool, but seems they required the WinRAR
> software.

Rar is a proprietary format. They do distribute a free "unrar" program
for multiple platforms.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: extract rar

2016-04-01 Thread Albert-Jan Roskam


> Date: Fri, 1 Apr 2016 13:22:12 -0600
> Subject: extract rar
> From: fanjianl...@gmail.com
> To: python-list@python.org
> 
> Hello everyone,
> 
> I am wondering is there any way to extract rar files by python without
> WinRAR software?
> 
> I tried Archive() and patool, but seems they required the WinRAR software.

Perhaps 7-zip in a Python 
subprocess:http://superuser.com/questions/458643/unzip-rar-from-command-line-with-7-zip/464128
  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-01 Thread Erik

On 01/04/16 15:34, Marko Rauhamaa wrote:

Chris Angelico :


*A range object is not an iterator.*


We now have learned as much.

However, doesn't that extra level of indirection seem like an odd
choice?


If you write your own class which has an __iter__ method, would you expect:

  >>> o = MyClass()
  >>> i1 = iter(o)
  >>> i2 = iter(o)
  >>> list(i1)
  ['foo', 'bar', 'baz']
  >>> list(i2)
  []

?

Or, would you expect both iterators to be independent and both return 
the 'foo', 'bar', 'baz' sequence (where that is the hypothetical result 
of iterating over your object)?


If you now replace MyClass() with range(10), why would you expect the 
two iterators to be related?


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


Re: Strange range

2016-04-01 Thread Marko Rauhamaa
Erik :

> On 01/04/16 15:34, Marko Rauhamaa wrote:
>> Chris Angelico :
>>
>>> *A range object is not an iterator.*
>>
>> We now have learned as much.
>>
>> However, doesn't that extra level of indirection seem like an odd
>> choice?
>
> [...]
>
> If you write your own class which has an __iter__ method, would you
> [...] expect both iterators to be independent and both return the
> 'foo', 'bar', 'baz' sequence (where that is the hypothetical result of
> iterating over your object)?
>
> If you now replace MyClass() with range(10), why would you expect the
> two iterators to be related?

I simply had thought of range() returning an iterator. I would expect an
iterator to behave like one.

There's a bit of a cognitive dissonance between iterables and iterators.
On the one hand, they behave identically in many contexts. On the other
hand, the distinction is crucial in some special cases.

(Somehow, the difference between iterables and iterators is analogous
with the difference between C's arrays and pointers.)


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


Re: Strange range

2016-04-01 Thread Rob Gaddi
Marko Rauhamaa wrote:

> Erik :
>
>> On 01/04/16 15:34, Marko Rauhamaa wrote:
>>> Chris Angelico :
>>>
 *A range object is not an iterator.*
>>>
>>> We now have learned as much.
>>>
>>> However, doesn't that extra level of indirection seem like an odd
>>> choice?
>>
>> [...]
>>
>> If you write your own class which has an __iter__ method, would you
>> [...] expect both iterators to be independent and both return the
>> 'foo', 'bar', 'baz' sequence (where that is the hypothetical result of
>> iterating over your object)?
>>
>> If you now replace MyClass() with range(10), why would you expect the
>> two iterators to be related?
>
> I simply had thought of range() returning an iterator. I would expect an
> iterator to behave like one.
>
> There's a bit of a cognitive dissonance between iterables and iterators.
> On the one hand, they behave identically in many contexts. On the other
> hand, the distinction is crucial in some special cases.

You're missing a key point.  All (well-behaved) iterators are iterables,
with their __iter__ method returning themselves.

for x in y:
  ...

implies:

try:
  _it = iter(y)
  while True:
x = next(_it)
...
except StopIteration:
  pass

That's true for any iterable y, including a y which is itself an
iterator.  You still call iter() on it, and get _it, the iterator over
y, which if y is an iterator is the same thing as y.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Drowning in a teacup?

2016-04-01 Thread Fillmore


notorious pass by reference vs pass by value biting me in the backside 
here. Proceeding in order.


I need to scan a list of strings. If one of the elements matches the 
beginning of a search keyword, that element needs to snap to the front 
of the list.

I achieved that this way:


   for i in range(len(mylist)):
if(mylist[i].startswith(key)):
mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]

Since I need this code in multiple places, I placed it inside a function

def bringOrderStringToFront(mylist, key):

for i in range(len(mylist)):
if(mylist[i].startswith(key)):
mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]

and called it this way:

 if orderstring:
 bringOrderStringToFront(Tokens, orderstring)

right?
Nope, wrong! contrary to what I thought I had understood about how 
parameters are passed in Python, the function is acting on a copy(!) and 
my original list is unchanged.


I fixed it this way:

def bringOrderStringToFront(mylist, key):

for i in range(len(mylist)):
if(mylist[i].startswith(key)):
mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
return(mylist)

and:

if orderstring:
   Tokens = bringOrderStringToFront(Tokens, orderstring)

but I'm left with a sour taste of not understanding what I was doing 
wrong. Can anyone elaborate? what's the pythonista way to do it right?


Thanks

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


Re: Set type for datetime intervals

2016-04-01 Thread Michael Selik
On Fri, Apr 1, 2016 at 1:32 AM Nagy László Zsolt 
wrote:

> Does anyone know a library that already implements these functions?
>

What do you not like about the ones on PyPI?
https://pypi.python.org/pypi?%3Aaction=search&term=interval&submit=search

Depending on the resolution you want, you might be able to use builtin sets
for everything.

def interval(start, stop, precision=60):
a = round(start.timestamp(), precision)
b = round(stop.timestamp(), precision)
return set(range(a, b, precision))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Set type for datetime intervals

2016-04-01 Thread Michael Selik
Whoops, I mixed up tasks. Here's what I meant:

def interval(start, stop, precision=60):
a, b = start.timestamp(), stop.timestamp()
return set(range(a, b, precision))

On Fri, Apr 1, 2016 at 4:31 PM Michael Selik 
wrote:

> On Fri, Apr 1, 2016 at 1:32 AM Nagy László Zsolt 
> wrote:
>
>> Does anyone know a library that already implements these functions?
>>
>
> What do you not like about the ones on PyPI?
> https://pypi.python.org/pypi?%3Aaction=search&term=interval&submit=search
>
> Depending on the resolution you want, you might be able to use builtin
> sets for everything.
>
> def interval(start, stop, precision=60):
> a = round(start.timestamp(), precision)
> b = round(stop.timestamp(), precision)
> return set(range(a, b, precision))
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: install open cv on windows 10 and python 3.5

2016-04-01 Thread MRAB

On 2016-04-01 20:11, saxr...@gmail.com wrote:

Τη Παρασκευή, 1 Απριλίου 2016 - 1:56:52 μ.μ. UTC+3, ο χρήστης sax...@gmail.com 
έγραψε:

hello,

i have windows 10 and python 3.5 and i want to use
open cv but i think so opencv work only on python 2.7 ?
and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
but not work again


i install opencv_python-3.1.0-cp35-none-win32.whl
but if i import cv2 or import opencv
then show me no module with that name


"OpenCV" is the name of the project, not the name of a module.

The name of the module "cv2".
--
https://mail.python.org/mailman/listinfo/python-list


Re: install open cv on windows 10 and python 3.5

2016-04-01 Thread saxri89
Τη Παρασκευή, 1 Απριλίου 2016 - 1:56:52 μ.μ. UTC+3, ο χρήστης sax...@gmail.com 
έγραψε:
> hello,
> 
> i have windows 10 and python 3.5 and i want to use
> open cv but i think so opencv work only on python 2.7 ?
> and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
> but not work again

show me no module name cv2
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Drowning in a teacup?

2016-04-01 Thread Rob Gaddi
Fillmore wrote:

>
> notorious pass by reference vs pass by value biting me in the backside 
> here. Proceeding in order.
>
> I need to scan a list of strings. If one of the elements matches the 
> beginning of a search keyword, that element needs to snap to the front 
> of the list.
> I achieved that this way:
>
>
> for i in range(len(mylist)):
>  if(mylist[i].startswith(key)):
>  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
>
> Since I need this code in multiple places, I placed it inside a function
>
> def bringOrderStringToFront(mylist, key):
>
>  for i in range(len(mylist)):
>  if(mylist[i].startswith(key)):
>  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
>
> and called it this way:
>
>   if orderstring:
>   bringOrderStringToFront(Tokens, orderstring)
>
> right?
> Nope, wrong! contrary to what I thought I had understood about how 
> parameters are passed in Python, the function is acting on a copy(!) and 
> my original list is unchanged.
>

Nope, that's not your problem.  Your problem is the line:

>  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]

Which should be read as: "Take mylist[i], all of mylist before i,
and all of mylist after i and create a new list from it. Store that
new list in a variable called mylist, overwriting the previous value."

If instead you were using the .insert and .remove methods, you'd be
manipulating the existing list instead.  But you don't want to do that,
because those methods are O(N) on the list length; manipulating the
middle of lists is slow.

That said, you've got some logic problems too; which come from the fact
that your iteration is shooting at a moving target.

How about:
  newlist = (
[x for x in mylist if x.startswith(key)] +
[x for x in mylist if not x.startswith(key)]
  )
  return newlist

Or if you really insist on mutating the original list (which seems less
clean to me, but you do you), then:
  newlist = blahblahblah
  mylist[:] = newlist

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-01 Thread Marko Rauhamaa
Rob Gaddi :

> Marko Rauhamaa wrote:
>> There's a bit of a cognitive dissonance between iterables and iterators.
>> On the one hand, they behave identically in many contexts. On the other
>> hand, the distinction is crucial in some special cases.
>
> You're missing a key point.  All (well-behaved) iterators are iterables,
> with their __iter__ method returning themselves.

I don't know what I'm missing.


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


Re: Drowning in a teacup?

2016-04-01 Thread MRAB

On 2016-04-01 21:27, Fillmore wrote:


notorious pass by reference vs pass by value biting me in the backside
here. Proceeding in order.

I need to scan a list of strings. If one of the elements matches the
beginning of a search keyword, that element needs to snap to the front
of the list.
I achieved that this way:


 for i in range(len(mylist)):
  if(mylist[i].startswith(key)):
  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]

Since I need this code in multiple places, I placed it inside a function

def bringOrderStringToFront(mylist, key):

  for i in range(len(mylist)):
  if(mylist[i].startswith(key)):
  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]

and called it this way:

   if orderstring:
   bringOrderStringToFront(Tokens, orderstring)

right?
Nope, wrong! contrary to what I thought I had understood about how
parameters are passed in Python, the function is acting on a copy(!) and
my original list is unchanged.

I fixed it this way:

def bringOrderStringToFront(mylist, key):

  for i in range(len(mylist)):
  if(mylist[i].startswith(key)):
  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
  return(mylist)

and:

if orderstring:
 Tokens = bringOrderStringToFront(Tokens, orderstring)

but I'm left with a sour taste of not understanding what I was doing
wrong. Can anyone elaborate? what's the pythonista way to do it right?

Python always passes a reference to the object, so the name "mylist" in 
the function is a local name that refers to the list that you passed.


When you say "mylist = something", you're just binding that local name 
to another object (i.e., it'll now refer to that object instead).


What you want to do it mutate the list itself. You can do that by 
replacing its elements with the new list you've created:


mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:]

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


Re: Drowning in a teacup?

2016-04-01 Thread Michael Selik
Give this a shot

def snap(keyword, words):
matches = [i for i, s in enumerate(words) if s.startswith(keyword)]
for i in matches:
lst.insert(0, lst.pop(i))

Your current implementation is reassigning the local variable ``mylist`` to
a new list inside the function.

On Fri, Apr 1, 2016 at 4:30 PM Fillmore  wrote:

>
> notorious pass by reference vs pass by value biting me in the backside
> here. Proceeding in order.
>
> I need to scan a list of strings. If one of the elements matches the
> beginning of a search keyword, that element needs to snap to the front
> of the list.
> I achieved that this way:
>
>
> for i in range(len(mylist)):
>  if(mylist[i].startswith(key)):
>  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
>
> Since I need this code in multiple places, I placed it inside a function
>
> def bringOrderStringToFront(mylist, key):
>
>  for i in range(len(mylist)):
>  if(mylist[i].startswith(key)):
>  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
>
> and called it this way:
>
>   if orderstring:
>   bringOrderStringToFront(Tokens, orderstring)
>
> right?
> Nope, wrong! contrary to what I thought I had understood about how
> parameters are passed in Python, the function is acting on a copy(!) and
> my original list is unchanged.
>
> I fixed it this way:
>
> def bringOrderStringToFront(mylist, key):
>
>  for i in range(len(mylist)):
>  if(mylist[i].startswith(key)):
>  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
>  return(mylist)
>
> and:
>
> if orderstring:
> Tokens = bringOrderStringToFront(Tokens, orderstring)
>
> but I'm left with a sour taste of not understanding what I was doing
> wrong. Can anyone elaborate? what's the pythonista way to do it right?
>
> Thanks
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Drowning in a teacup?

2016-04-01 Thread Ian Kelly
On Fri, Apr 1, 2016 at 2:39 PM, Rob Gaddi
 wrote:
> Fillmore wrote:
>> Nope, wrong! contrary to what I thought I had understood about how
>> parameters are passed in Python, the function is acting on a copy(!) and
>> my original list is unchanged.
>>
>
> Nope, that's not your problem.  Your problem is the line:
>
>>  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
>
> Which should be read as: "Take mylist[i], all of mylist before i,
> and all of mylist after i and create a new list from it. Store that
> new list in a variable called mylist, overwriting the previous value."
>
> If instead you were using the .insert and .remove methods, you'd be
> manipulating the existing list instead.  But you don't want to do that,
> because those methods are O(N) on the list length; manipulating the
> middle of lists is slow.

Or use slice assignment. This should work in place of the above:

mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:]

Still O(n), but so will be any implementation that removes something
from an arbitrary list position and inserts it at the front.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: install open cv on windows 10 and python 3.5

2016-04-01 Thread Terry Reedy

On 4/1/2016 4:38 PM, saxr...@gmail.com wrote:

Τη Παρασκευή, 1 Απριλίου 2016 - 1:56:52 μ.μ. UTC+3, ο χρήστης sax...@gmail.com 
έγραψε:

hello,

i have windows 10 and python 3.5 and i want to use
open cv but i think so opencv work only on python 2.7 ?
and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
but not work again


show me no module name cv2


Do you have other versions of python installed.  How did you install 
opencv/cv2?  If pip, what did it say? What you you see in 
python35/Lib/site-packages?


--
Terry Jan Reedy


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


Re: extract rar

2016-04-01 Thread Jianling Fan
Thanks, but the problem is that I am not allowed to install any
software in my office PC, even free software.
Normally, I use zip files but this time I need to extract a rar file.
I don't like to go to IT guys because it takes time.
That's why I am looking for an alternative way without installing
other software.

 Thanks,

On 1 April 2016 at 13:37, Albert-Jan Roskam  wrote:
>
>
>
>> Date: Fri, 1 Apr 2016 13:22:12 -0600
>> Subject: extract rar
>> From: fanjianl...@gmail.com
>> To: python-list@python.org
>>
>> Hello everyone,
>>
>> I am wondering is there any way to extract rar files by python without
>> WinRAR software?
>>
>> I tried Archive() and patool, but seems they required the WinRAR software.
>
> Perhaps 7-zip in a Python subprocess:
> http://superuser.com/questions/458643/unzip-rar-from-command-line-with-7-zip/464128
>



-- 
Jianling Fan
樊建凌
-- 
https://mail.python.org/mailman/listinfo/python-list


writing to command line thru python gui

2016-04-01 Thread A. ElKader
I posted this question, no reply :

Any advice :

http://unix.stackexchange.com/questions/273573/write-to-terminal-in-tkinter-gui
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Drowning in a teacup?

2016-04-01 Thread Chris Kaynor
On Fri, Apr 1, 2016 at 1:52 PM, Ian Kelly  wrote:

> On Fri, Apr 1, 2016 at 2:39 PM, Rob Gaddi
>  wrote:
> > Fillmore wrote:
> >> Nope, wrong! contrary to what I thought I had understood about how
> >> parameters are passed in Python, the function is acting on a copy(!) and
> >> my original list is unchanged.
> >>
> >
> > Nope, that's not your problem.  Your problem is the line:
> >
> >>  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
> >
> > Which should be read as: "Take mylist[i], all of mylist before i,
> > and all of mylist after i and create a new list from it. Store that
> > new list in a variable called mylist, overwriting the previous value."
> >
> > If instead you were using the .insert and .remove methods, you'd be
> > manipulating the existing list instead.  But you don't want to do that,
> > because those methods are O(N) on the list length; manipulating the
> > middle of lists is slow.
>
> Or use slice assignment. This should work in place of the above:
>
> mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:]
>
> Still O(n), but so will be any implementation that removes something
> from an arbitrary list position and inserts it at the front.
>

The overall algorithm is O(n^2), as its doing a O(n) operation in a O(n)
loop:

def bringOrderStringToFront(mylist, key):
   for i in range(len(mylist)): # O(n)
if(mylist[i].startswith(key)):
mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:] # O(n)

You should get an overall O(n) with (untested):

def bringOrderStringToFront(mylist, key):
starts = []
other = []
for item in mylist: # O(n)
if item.startswith(key):
starts.append(item) # amortized O(1)
else:
other.append(item) # amortized O(1)
mylist[:] = starts[::-1] + other # O(n); slice assignment mutates input
list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Drowning in a teacup?

2016-04-01 Thread Ethan Furman

On 04/01/2016 01:27 PM, Fillmore wrote:


notorious pass by reference vs pass by value biting me in the backside
here. Proceeding in order.


It's only notorious for folks that don't understand that Python uses 
neither.  It also doesn't help when folks don't understand how 
name-binding works.


if orderstring:
bringOrderStringToFront(Tokens, orderstring)

Tokens has now been passed in to bringOrderStringToFront, and it has 
been assigned the name of `mylist`.



def bringOrderStringToFront(mylist, key):

At this point `mylist` and `Tokens` are the same object.

for i in range(len(mylist)):
if(mylist[i].startswith(key)):
mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]

And now they are not, as you just assigned the name `mylist` to 
something else.


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


Re: Drowning in a teacup?

2016-04-01 Thread Ian Kelly
On Fri, Apr 1, 2016 at 3:10 PM, Chris Kaynor  wrote:
> The overall algorithm is O(n^2), as its doing a O(n) operation in a O(n)
> loop:

Depends on whether the OP expects to find only one match or
potentially multiple matches in the list. E did say "if one of the
elements matches".

If there are only ever a constant number of matches, then it's O(n) overall.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange range

2016-04-01 Thread Terry Reedy

On 4/1/2016 4:14 PM, Marko Rauhamaa wrote:


There's a bit of a cognitive dissonance between iterables and iterators.
On the one hand, they behave identically in many contexts.


Because iterators *are* (a proper subset of) iterables  This goes back 
to pre-iterator days when for-loops worked on sequences and 
sequence-like objects.  When iterators (and generators and generator 
functions) were added and the iteration protocol added to the sequence 
protocol, 'sequence' was generalized to 'iterable'.  Replacing 
'sequence' with 'iterator' (and having an iterator not be an iterable) 
would have broken most code and made for loops less convenient to use.



On the other hand, the distinction


between iterators and non-iterator iterables


is crucial in some special cases.


I often call non-iterator iterables 're-iterables' (which is usually 
correct) but there is no agree-on term.  It is sort of like having 
'people' and 'men' but no word for non-men people.



(Somehow, the difference between iterables and iterators is analogous
with the difference between C's arrays and pointers.)


(Yes, C uses pointers to iterates through arrays, in either direction.)

--
Terry Jan Reedy

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


Grab metadata from images and save to file, batch mode

2016-04-01 Thread accessnewbie
I have a directory (and sub-directories) full of images that I want to cycle 
through and grab certain metadata values and save those values to a single row 
in a cvs file. I would like to tack on the full path name to the row as a 
separate value.

Folder
C:\Images\Family
Brother.jpg
Sister.jpg
Mom.jpg

Keys/Values
Original Date/Time
User Name
File Name

Thus, data might look like this in a Family.csv file
2014:11:10 13:52:12; BillyBob111; Brother.jpg; C:\Images\Family\Brother.jpg
2015:10:54 11:45:34; BillyBob111; Sister.jpg; C:\Images\Family\Sister.jpg
2010:10:31 19:22:11; SallySue232; Mom.jpg; C:\Images\Family\Mom.jpg

Big time noob. Much of what I have read cites command line examples dealing 
with single files and no info as to how to extract specific keys and their 
values.
What module would some of you users recommend I use (I want it to be python as 
that is what I am trying to learn)

Can you give me some coding suggestions to get me goings? I haven't found any 
substantive scripts to use as guides.

Many thanks in advance
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: install open cv on windows 10 and python 3.5

2016-04-01 Thread Xristos Xristoou
Τη Παρασκευή, 1 Απριλίου 2016 - 1:56:52 μ.μ. UTC+3, ο χρήστης Xristos Xristoou 
έγραψε:
> hello,
> 
> i have windows 10 and python 3.5 and i want to use
> open cv but i think so opencv work only on python 2.7 ?
> and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
> but not work again

in my site-packages i have :
opencv_python-3.1.0.dist-info
cv2.cp35-win32.pyd
cv2.pyd
cv
and more opencv.dlls
yes i have and python2.7 for other version
in pip install succefully

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


[beginner] What's wrong?

2016-04-01 Thread Michael Okuntsov

Hello,
I have a Pascal code for some hash function. I've tried to rewrite it on 
Python but it doesn't give the right value (which is 32202). Please tell 
me where is the error.


Thanks.

**
Pascal program
**

Program K_S;
Var
  ST: String;
function KSUM(var S: String): String;
var
  i, l: Integer;
  KS: Word;
  SS: String;
begin
  KS:=65535;
  for i:=2 to Length(S) do
  begin
KS := KS xor Ord(S[i]);
writeln(S[i]);
for l:=1 to 8 do
 if (KS div 2)*2<>KS then KS := (KS div 2) xor 40961
 else KS := (KS div 2);
  end;
  Str(KS, SS);
  KSUM := SS;
end;


Begin
 ST := ':1;1;2;';
 Writeln(KSUM(ST));
End.


**
Python program
**

def myhash(s):
KS=65535
for i in range(1,len(s)):
KS=KS ^ ord(s[i])
for j in range(1,8):
if (KS // 2)*2 != KS:
KS=(KS // 2) ^ 40961
else:
KS=KS // 2
return(str(KS))
if __name__ ==  "__main__":
st=myhash(":1;1;2;")
print (st)
--
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-01 Thread Michael Okuntsov

Nevermind. for j in range(1,8) should be for j in range(8).
--
https://mail.python.org/mailman/listinfo/python-list


Re: Drowning in a teacup?

2016-04-01 Thread Mark Lawrence via Python-list

On 01/04/2016 21:27, Fillmore wrote:


notorious pass by reference vs pass by value biting me in the backside
here. Proceeding in order.


It is pass by object.

By definition your following analysis is wrong.

To my knowledge this has been discussed at least twice a year for the 
past 15 years.


I would suggest that you search the archives, but that would upset 
teacher, so I won't.


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

Mark Lawrence

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


Re: [beginner] What's wrong?

2016-04-01 Thread Mark Lawrence via Python-list

On 01/04/2016 23:10, Michael Okuntsov wrote:

Nevermind. for j in range(1,8) should be for j in range(8).


Thank you for your correction, we in Python land greatly appreciate such 
things :)


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

Mark Lawrence

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


Re: Strange range

2016-04-01 Thread Mark Lawrence via Python-list

On 01/04/2016 21:44, Marko Rauhamaa wrote:

Rob Gaddi :


Marko Rauhamaa wrote:

There's a bit of a cognitive dissonance between iterables and iterators.
On the one hand, they behave identically in many contexts. On the other
hand, the distinction is crucial in some special cases.


You're missing a key point.  All (well-behaved) iterators are iterables,
with their __iter__ method returning themselves.


I don't know what I'm missing.

Marko



Neither do we, which is why so many threads here belong, eventually, on 
comp.lang.theoretical.claptrap.


I remember when we used to have Bots here commenting on the Python 
language.  Obviously they've all given up as so much drivel is spouted, 
and/or they've gone to join the Norwegian Blue.


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

Mark Lawrence

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


Re: [beginner] What's wrong?

2016-04-01 Thread sohcahtoa82
On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote:
> Nevermind. for j in range(1,8) should be for j in range(8).

I can't tell you how many times I've gotten bit in the ass with that off-by-one 
mistake whenever I use a range that doesn't start at zero.

I know that if I want to loop 10 times and I either want to start at zero or 
just don't care about the actual number, I use `for i in range(10)`.  But if I 
want to loop from 10 to 20, my first instinct is to write `for i in range(10, 
20)`, and then I'm left figuring out why my loop isn't executing the last step.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Drowning in a teacup?

2016-04-01 Thread Steven D'Aprano
On Sat, 2 Apr 2016 07:27 am, Fillmore wrote:

> 
> notorious pass by reference vs pass by value biting me in the backside
> here. Proceeding in order.

Python is NEITHER pass by reference nor pass by value.

Please read this:

http://import-that.dreamwidth.org/1130.html

before asking any additional questions.


> def bringOrderStringToFront(mylist, key):
> 
>  for i in range(len(mylist)):
>  if(mylist[i].startswith(key)):
>  mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]

[mylist[i]] + mylist[:i] + mylist[i+1:]

creates a new list. It doesn't modify the existing list.

mylist = ...

performs an assignment to the LOCAL VARIABLE mylist, setting it to the new
list just created. The original list is unchanged.

Trick: you can use slicing to write to the original list:

mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:]


Or you can modify the list directly in place:

for i in range(len(mylist)):
if mylist[i].startswith(key):
x = mylist[i]
del mylist[i]
mylist.insert(0, x)


which is better written as:

for i, x in enumerate(mylist):
if x.startswith(key):
del mylist[i]
mylist.insert(0, x)

or if you prefer:

for i, x in enumerate(mylist):
if x.startswith(key):
mylist[:] = [x] + mylist[:i] + mylist[i+1:]



-- 
Steven

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


Re: install open cv on windows 10 and python 3.5

2016-04-01 Thread MRAB

On 2016-04-01 22:37, Xristos Xristoou wrote:

Τη Παρασκευή, 1 Απριλίου 2016 - 1:56:52 μ.μ. UTC+3, ο χρήστης Xristos Xristoou 
έγραψε:

hello,

i have windows 10 and python 3.5 and i want to use
open cv but i think so opencv work only on python 2.7 ?
and i install this http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
but not work again


in my site-packages i have :
opencv_python-3.1.0.dist-info
cv2.cp35-win32.pyd
cv2.pyd
cv
and more opencv.dlls
yes i have and python2.7 for other version
in pip install succefully

If a module has been written in Python, it will have the extension 
".py", but if it has been written in C, it will have the extension 
".pyd" (on Windows) or ".so" (on Linux).


The real test is if you can import it:

>>> import cv2

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


Re: [beginner] What's wrong?

2016-04-01 Thread Mark Lawrence via Python-list

On 01/04/2016 23:44, sohcahto...@gmail.com wrote:

On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote:

Nevermind. for j in range(1,8) should be for j in range(8).


I can't tell you how many times I've gotten bit in the ass with that off-by-one 
mistake whenever I use a range that doesn't start at zero.

I know that if I want to loop 10 times and I either want to start at zero or 
just don't care about the actual number, I use `for i in range(10)`.  But if I 
want to loop from 10 to 20, my first instinct is to write `for i in range(10, 
20)`, and then I'm left figuring out why my loop isn't executing the last step.



"First instinct"?  "I expected"?  The Python docs might not be perfect, 
but they were certainly adequate enough to get me going 15 years ago, 
and since then they've improved.  So where is the problem, other than 
failure to RTFM?


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

Mark Lawrence

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


pow() & modulo QUESTION

2016-04-01 Thread vaulhausen
Having trouble performing the pow() function with 
real numbers.

I want to also take a modulo value

Weirdly, this works fine ;

pow(2,6000,400) = 176

However, this returns an error ;

pow(1.4142, 6000, 400)

I have tried also the math.pow() function but it doesnt
work either. can any one give me a hand with this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-01 Thread Michael Selik
Humans have always had trouble with this, in many contexts. I remember
being annoyed at folks saying the year 2000 was the first year of the new
millennium, rather than 2001. They'd forgotten the Gregorian calendar
starts from AD 1.

On Fri, Apr 1, 2016, 6:58 PM Mark Lawrence via Python-list <
python-list@python.org> wrote:

> On 01/04/2016 23:44, sohcahto...@gmail.com wrote:
> > On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote:
> >> Nevermind. for j in range(1,8) should be for j in range(8).
> >
> > I can't tell you how many times I've gotten bit in the ass with that
> off-by-one mistake whenever I use a range that doesn't start at zero.
> >
> > I know that if I want to loop 10 times and I either want to start at
> zero or just don't care about the actual number, I use `for i in
> range(10)`.  But if I want to loop from 10 to 20, my first instinct is to
> write `for i in range(10, 20)`, and then I'm left figuring out why my loop
> isn't executing the last step.
> >
>
> "First instinct"?  "I expected"?  The Python docs might not be perfect,
> but they were certainly adequate enough to get me going 15 years ago,
> and since then they've improved.  So where is the problem, other than
> failure to RTFM?
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
>
> Mark Lawrence
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Grab metadata from images and save to file, batch mode

2016-04-01 Thread Dale Marvin

On 4/1/16 2:20 PM, accessnew...@gmail.com wrote:

I have a directory (and sub-directories) full of images that I want to cycle 
through and grab certain metadata values and save those values to a single row 
in a cvs file. I would like to tack on the full path name to the row as a 
separate value.

Folder
C:\Images\Family
Brother.jpg
Sister.jpg
Mom.jpg

Keys/Values
Original Date/Time
User Name
File Name

Thus, data might look like this in a Family.csv file
2014:11:10 13:52:12; BillyBob111; Brother.jpg; C:\Images\Family\Brother.jpg
2015:10:54 11:45:34; BillyBob111; Sister.jpg; C:\Images\Family\Sister.jpg
2010:10:31 19:22:11; SallySue232; Mom.jpg; C:\Images\Family\Mom.jpg

Big time noob. Much of what I have read cites command line examples dealing 
with single files and no info as to how to extract specific keys and their 
values.
What module would some of you users recommend I use (I want it to be python as 
that is what I am trying to learn)

Can you give me some coding suggestions to get me goings? I haven't found any 
substantive scripts to use as guides.

Many thanks in advance



Hi accessnewbie,

I do a fair amount of media processing and automation with python.
Look at exiftool 
There are python bindings as well .

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


Introduction

2016-04-01 Thread Dale Marvin
I just sent my first post, been using python for about 12 years to 
automate media production tasks.


Lately I've been adding testing (Thanks Ned Batchelder: 
), and documentation with 
Sphinx/rst.


Thanks

Dale Marvin
digital OutPost

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


Re: pow() & modulo QUESTION

2016-04-01 Thread MRAB

On 2016-04-02 00:08, vaulhau...@gmail.com wrote:

Having trouble performing the pow() function with
real numbers.

I want to also take a modulo value

Weirdly, this works fine ;

pow(2,6000,400) = 176

However, this returns an error ;

pow(1.4142, 6000, 400)

I have tried also the math.pow() function but it doesnt
work either. can any one give me a hand with this?


The 2-argument form pow(x, y) is equivalent to x ** y.

When working with integers, there's a more efficient way of calculating 
x ** y % z, so pow provides that with the 3-argument form pow(x, y, z).


Of course, you could argue that pow should allow the 3-argument for even 
with floats, but it wouldn't be any faster than x ** y % z.


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


Django Channels examples

2016-04-01 Thread justin walters
To all of my Web developer bros and broettes,

You all should check out this github repo:
https://github.com/andrewgodwin/channels-examples

This is not my repo or my work.

Channels is a package for Django that allows Django to work more easily
with websockets through an asgi interface. The Django devs intend to add
Channels into the core packages with the next major release.

The linked repo contains 2 examples. One is a live blogging application,
and one is a live chat application. I just typed out all of the code to
build the chat application myself and it works well. It was a fun exercise.

If you are interested in websocket applications with Python, I highly
recommend checking it out.

Let me know if this kind of thing does not belong on this list.

I'm just really excited about this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Drowning in a teacup?

2016-04-01 Thread Fillmore

On 04/01/2016 04:27 PM, Fillmore wrote:


notorious pass by reference vs pass by value biting me in the backside here. 
Proceeding in order.



Many thanks to all of those who replied!
--
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-01 Thread Random832
On Fri, Apr 1, 2016, at 19:29, Michael Selik wrote:
> Humans have always had trouble with this, in many contexts. I remember
> being annoyed at folks saying the year 2000 was the first year of the new
> millennium, rather than 2001. They'd forgotten the Gregorian calendar
> starts from AD 1.

Naturally, this means the first millennium was only 999 years long, and
all subsequent millennia were 1000 years long. (Whereas "millennium" is
defined as the set of all years of a given era for a given integer k
where y // 1000 == k. How else would you define it?)

And if you want to get technical, the gregorian calendar starts from
some year no earlier than 1582, depending on the country. The year
numbering system has little to do with the calendar type - your
assertion in fact regards the BC/AD year numbering system, which was
invented by Bede.

The astronomical year-numbering system, which does contain a year zero
(and uses negative numbers rather than a reverse-numbered "BC" era), and
is incidentally used by ISO 8601, was invented by Jacques Cassini in the
17th century.



Rule #1 of being pedantic: There's always someone more pedantic than
you, whose pedantry supports the opposite conclusion.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [beginner] What's wrong?

2016-04-01 Thread Michael Selik
On Sat, Apr 2, 2016, 12:28 AM Random832  wrote:

> On Fri, Apr 1, 2016, at 19:29, Michael Selik wrote:
> > Humans have always had trouble with this, in many contexts. I remember
> > being annoyed at folks saying the year 2000 was the first year of the new
> > millennium, rather than 2001. They'd forgotten the Gregorian calendar
> > starts from AD 1.
>
> Naturally, this means the first millennium was only 999 years long, and
> all subsequent millennia were 1000 years long. (Whereas "millennium" is
> defined as the set of all years of a given era for a given integer k
> where y // 1000 == k. How else would you define it?)
>
> And if you want to get technical, the gregorian calendar starts from
> some year no earlier than 1582, depending on the country. The year
> numbering system has little to do with the calendar type - your
> assertion in fact regards the BC/AD year numbering system, which was
> invented by Bede.
>
> The astronomical year-numbering system, which does contain a year zero
> (and uses negative numbers rather than a reverse-numbered "BC" era), and
> is incidentally used by ISO 8601, was invented by Jacques Cassini in the
> 17th century.
>
>
>
> Rule #1 of being pedantic: There's always someone more pedantic than
> you, whose pedantry supports the opposite conclusion.
>

I'll have to remember that one. And thanks for the facts.

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


Re: Drowning in a teacup?

2016-04-01 Thread Vito De Tullio
Fillmore wrote:

> I need to scan a list of strings. If one of the elements matches the
> beginning of a search keyword, that element needs to snap to the front
> of the list.

I know this post regards the function passing, but, on you specific problem, 
can't you just ... sort the list with a custom key?

something like (new list)

>>> sorted(['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x'],
... key=lambda e: not e.startswith('yes'))
['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y']

or (in place)

>>> l = ['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x']
>>> l.sort(key=lambda e: not e.startswith('yes'))
>>> l
['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y']



-- 
By ZeD

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


Re: [beginner] What's wrong?

2016-04-01 Thread William Ray Wing

> On Apr 1, 2016, at 6:57 PM, Mark Lawrence via Python-list 
>  wrote:
> 
>> On 01/04/2016 23:44, sohcahto...@gmail.com wrote:
>>> On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote:
>>> Nevermind. for j in range(1,8) should be for j in range(8).
>> 
>> I can't tell you how many times I've gotten bit in the ass with that 
>> off-by-one mistake whenever I use a range that doesn't start at zero.
>> 
>> I know that if I want to loop 10 times and I either want to start at zero or 
>> just don't care about the actual number, I use `for i in range(10)`.  But if 
>> I want to loop from 10 to 20, my first instinct is to write `for i in 
>> range(10, 20)`, and then I'm left figuring out why my loop isn't executing 
>> the last step.
> 
> "First instinct"?  "I expected"?  The Python docs might not be perfect, but 
> they were certainly adequate enough to get me going 15 years ago, and since 
> then they've improved.  So where is the problem, other than failure to RTFM?
> 
I've always found it vaguely amusing that the server(s) for just about all the 
technical info at MIT reside behind http://rtfm.mit.edu

Bill

> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Drowning in a teacup?

2016-04-01 Thread Michael Selik
On Sat, Apr 2, 2016, 1:46 AM Vito De Tullio  wrote:

> Fillmore wrote:
>
> > I need to scan a list of strings. If one of the elements matches the
> > beginning of a search keyword, that element needs to snap to the front
> > of the list.
>
> I know this post regards the function passing, but, on you specific
> problem,
> can't you just ... sort the list with a custom key?
>
> something like (new list)
>
> >>> sorted(['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x'],
> ... key=lambda e: not e.startswith('yes'))
> ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y']
>
> or (in place)
>
> >>> l = ['no_a', 'yes_c', 'no_b', 'yes_z', 'no_y', 'yes_x']
> >>> l.sort(key=lambda e: not e.startswith('yes'))
> >>> l
> ['yes_c', 'yes_z', 'yes_x', 'no_a', 'no_b', 'no_y']
>

If the number of matches is small relative to the size of the list, I'd
expect the sort would be slower than most of the other suggestions.

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


Re: Drowning in a teacup?

2016-04-01 Thread Vito De Tullio
Michael Selik wrote:

>> > I need to scan a list of strings. If one of the elements matches the
>> > beginning of a search keyword, that element needs to snap to the front
>> > of the list.
>>
>> I know this post regards the function passing, but, on you specific
>> problem,
>> can't you just ... sort the list with a custom key?
>
> If the number of matches is small relative to the size of the list, I'd
> expect the sort would be slower than most of the other suggestions.

umm... I take the liberty to set up a little test

$ cat test_sort_prefix.py
#!/usr/bin/env python3

from sys import argv
from timeit import timeit


def sort_in_place(l):
def key(e):
return not e.startswith('yes')
l.sort(key=key)


def original_solution(mylist):
for i in range(len(mylist)):
if(mylist[i].startswith('yes')):
mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:]


def main():
if argv[1] == 'sort_in_place':
f = sort_in_place
elif argv[1] == 'original_solution':
f = original_solution
else:
raise Exception()

nomatches = int(argv[2])
matches = int(argv[3])

l = ["no_" for _ in range(nomatches)] + ["yes_" for _ in 
range(matches)]

print(timeit("f(l)", number=100, globals={"f": f, "l": l}))

if __name__ == '__main__':
main()
$ ./test_sort_prefix.py sort_in_place 100 3
33.260575089996564
$ ./test_sort_prefix.py original_solution 100 3
35.93009542999789
$


in my tests there is no sensible difference between the two solutions... and 
the number of matches is risible :)

-- 
By ZeD

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