Re: program to generate data helpful in finding duplicate large files

2014-09-18 Thread Chris Angelico
On Fri, Sep 19, 2014 at 3:45 PM, Steven D'Aprano wrote: > David Alban wrote: >> *import sys* > > Um, how did you end up with leading and trailing asterisks? That's going to > stop your code from running. They're not part of the code, they're part of the mangling of the formatting. So this isn't a

Re: program to generate data helpful in finding duplicate large files

2014-09-18 Thread Steven D'Aprano
David Alban wrote: > *#!/usr/bin/python* > > *import argparse* > *import hashlib* > *import os* > *import re* > *import socket* > *import sys* Um, how did you end up with leading and trailing asterisks? That's going to stop your code from running. > *from stat import ** "import *" is slightly

Re: Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread Chris Angelico
On Fri, Sep 19, 2014 at 3:15 PM, Steven D'Aprano wrote: > However, as far as I am aware, there are no built-ins that will fail that > test, yet. Although the iteration order of dicts and sets is arbitrary, I > think that (at least to date) it will be the same order every time you > iterate over th

Re: Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread Steven D'Aprano
Roy Smith wrote: > Is there anything which requires an iterator to be deterministic? Absolutely not. py> def spam(): ... while True: ... n = random.randint(0, 10) ... s = ' '.join(['spam']*n) ... if not s: ... return ... yield s + '!' ... py> for s

Re: Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread Steven D'Aprano
cool-RR wrote: > My function gets an iterable of an unknown type. I want to check whether > it's ordered. I could check whether it's a `set` or `frozenset`, which > would cover many cases, but I wonder if I can do better. Is there a nicer > way to check whether an iterable is ordered or not? See

Re: hashlib suddenly broken

2014-09-18 Thread Steven D'Aprano
Ned Deily wrote: > In article > , > Larry Martell wrote: >> Do you think I should install this update? Perhaps that would restore >> whatever is missing. > > Yes. You should install the update in any case and it's unlikely to make > the hashlib situation worse :=) However, it is likely to make

Re: the python shell window is already executing a command

2014-09-18 Thread Chris Angelico
On Fri, Sep 19, 2014 at 5:05 AM, Terry Reedy wrote: > A couple more questions; after you run the file once, is there a warning > above the first >>> prompt? If, after the program stop and you see a second prompt and run import sys; len(sys.modules), 'array' in sys.modules > what is the

Re: Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread Chris Angelico
On Fri, Sep 19, 2014 at 9:52 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> The one thing you can rely on (and therefore must comply with, when >> you design an iterable) is that iteration will hit every element >> exactly once. > > Does it actually say that somewhere? For exa

Re: Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread Roy Smith
In article , Chris Angelico wrote: > The one thing you can rely on (and therefore must comply with, when > you design an iterable) is that iteration will hit every element > exactly once. Does it actually say that somewhere? For example: for i in bag.pick_randomly_with_replacement(n=5): p

Re: program to generate data helpful in finding duplicate large files

2014-09-18 Thread Gregory Ewing
Chris Angelico wrote: On Fri, Sep 19, 2014 at 4:45 AM, Chris Kaynor wrote: from stat import * I was going to say the same thing, except that this module specifically is documented as recommending that. I still don't like "import *", but either this is a special case, or the docs need to be c

Re: hashlib suddenly broken

2014-09-18 Thread Ned Deily
In article , Larry Martell wrote: > Do you think I should install this update? Perhaps that would restore > whatever is missing. Yes. You should install the update in any case and it's unlikely to make the hashlib situation worse :=) -- Ned Deily, n...@acm.org -- https://mail.python.org/

Re: hashlib suddenly broken

2014-09-18 Thread Christian Heimes
On 18.09.2014 23:39, Larry Martell wrote: > $ python > Python 2.7.2 (default, Oct 11 2012, 20:14:37) > [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin > Type "help", "copyright", "credits" or "license" for more information. import _hashlib _hashlib.__file__ >

Re: hashlib suddenly broken

2014-09-18 Thread Larry Martell
On Thu, Sep 18, 2014 at 2:49 PM, Christian Heimes wrote: > On 18.09.2014 21:23, Larry Martell wrote: >> On Thu, Sep 18, 2014 at 11:18 AM, Chris Angelico wrote: >>> On Fri, Sep 19, 2014 at 3:07 AM, Steven D'Aprano >>> wrote: but I expect that's probably not where the problem lies. My *wild g

Re: hashlib suddenly broken

2014-09-18 Thread Larry Martell
On Thu, Sep 18, 2014 at 2:44 PM, Ned Deily wrote: > In article > , > Larry Martell wrote: >> On Thu, Sep 18, 2014 at 1:22 PM, Larry Martell >> wrote: >> > On Thu, Sep 18, 2014 at 11:07 AM, Steven D'Aprano >> > wrote: >> >> Larry Martell wrote: >> >>> I am on a mac running 10.8.5, python 2.7 >>

Re: hashlib suddenly broken

2014-09-18 Thread Larry Martell
On Thu, Sep 18, 2014 at 2:21 PM, John Gordon wrote: > In Larry Martell > writes: > >> It's failing on the 'import _sha' in hashlib.py: > >> 66 def __get_builtin_constructor(name): >> 67try: >> 68 if name in ('SHA1', 'sha1'): >> 69 ->import _sha >> 70

Re: hashlib suddenly broken

2014-09-18 Thread Christian Heimes
On 18.09.2014 21:23, Larry Martell wrote: > On Thu, Sep 18, 2014 at 11:18 AM, Chris Angelico wrote: >> On Fri, Sep 19, 2014 at 3:07 AM, Steven D'Aprano >> wrote: >>> but I expect that's probably not where the problem lies. My *wild guess* is >>> that your system updated SSL, and removed some unde

Re: hashlib suddenly broken

2014-09-18 Thread Ned Deily
In article , Larry Martell wrote: > On Thu, Sep 18, 2014 at 1:22 PM, Larry Martell > wrote: > > On Thu, Sep 18, 2014 at 11:07 AM, Steven D'Aprano > > wrote: > >> Larry Martell wrote: > >>> I am on a mac running 10.8.5, python 2.7 > >>> Suddenly, many of my scripts started failing with: > >>>

Re: hashlib suddenly broken

2014-09-18 Thread John Gordon
In Larry Martell writes: > It's failing on the 'import _sha' in hashlib.py: > 66 def __get_builtin_constructor(name): > 67try: > 68 if name in ('SHA1', 'sha1'): > 69 ->import _sha > 70 return _sha.new > (Pdb) s > ImportError: 'No module named _sh

Re: program to generate data helpful in finding duplicate large files

2014-09-18 Thread Peter Otten
David Alban wrote: > *sep = ascii_nul* > > *print "%s%c%s%c%d%c%d%c%d%c%d%c%s" % ( thishost, sep, md5sum, sep, > dev, sep, ino, sep, nlink, sep, size, sep, file_path )* file_path may contain newlines, therefore you should probably use "\0" to separate the records. The other fields may n

Re: the python shell window is already executing a command

2014-09-18 Thread Seymore4Head
On Thu, 18 Sep 2014 15:05:53 -0400, Terry Reedy wrote: >On 9/18/2014 11:24 AM, Seymore4Head wrote: >> On Wed, 17 Sep 2014 23:50:56 -0400, Terry Reedy >> wrote: > >>> My question was "How do you start Idle?" >>> (I can make a difference.) >> >> The way I start IDLE is to go to my programs folder

Re: hashlib suddenly broken

2014-09-18 Thread Larry Martell
On Thu, Sep 18, 2014 at 1:22 PM, Larry Martell wrote: > On Thu, Sep 18, 2014 at 11:07 AM, Steven D'Aprano > wrote: >> Larry Martell wrote: >> >>> I am on a mac running 10.8.5, python 2.7 >>> >>> Suddenly, many of my scripts started failing with: >>> >>> ValueError: unsupported hash type sha1 >> [

Re: hashlib suddenly broken

2014-09-18 Thread Larry Martell
On Thu, Sep 18, 2014 at 11:07 AM, Steven D'Aprano wrote: > Larry Martell wrote: > >> I am on a mac running 10.8.5, python 2.7 >> >> Suddenly, many of my scripts started failing with: >> >> ValueError: unsupported hash type sha1 > [...] >> This just started happening yesterday, and I cannot think o

Re: hashlib suddenly broken

2014-09-18 Thread Larry Martell
On Thu, Sep 18, 2014 at 11:18 AM, Chris Angelico wrote: > On Fri, Sep 19, 2014 at 3:07 AM, Steven D'Aprano > wrote: >> but I expect that's probably not where the problem lies. My *wild guess* is >> that your system updated SSL, and removed some underlying SHA-1 library >> needed by hashlib. SHA-1

Re: hashlib suddenly broken

2014-09-18 Thread Larry Martell
On Thu, Sep 18, 2014 at 10:47 AM, John Gordon wrote: > In Larry Martell > writes: > >> Googling this showed that it's an issue with hashlib with a common >> cause being a file called hashlib.py that gets in the way of the >> interpreter finding the standard hashlib module, but that doesn't seem

Re: the python shell window is already executing a command

2014-09-18 Thread Terry Reedy
On 9/18/2014 11:24 AM, Seymore4Head wrote: On Wed, 17 Sep 2014 23:50:56 -0400, Terry Reedy wrote: My question was "How do you start Idle?" (I can make a difference.) The way I start IDLE is to go to my programs folder and right click on file.py in the directory and select "edit with IDLE".

Re: Best practice for opening files for newbies?

2014-09-18 Thread chris . barker
On Thursday, September 18, 2014 9:38:00 AM UTC-7, Chris Angelico wrote: > On Fri, Sep 19, 2014 at 2:19 AM, wrote: > > So: there are way too many ways to open a simple file to read or write a > > bit of text (or binary): > > open() > > Personally, I'd just use this, all the way through - and not

Re: program to generate data helpful in finding duplicate large files

2014-09-18 Thread Chris Angelico
On Fri, Sep 19, 2014 at 4:45 AM, Chris Kaynor wrote: >> from stat import * > > > Generally, from import * imports are discouraged as they tend to populate > your namespace and have issues with accidentally overriding imported > functions/variables. Generally, its more Pythonic to use the other imp

Re: program to generate data helpful in finding duplicate large files

2014-09-18 Thread Chris Angelico
On Fri, Sep 19, 2014 at 4:11 AM, David Alban wrote: > i'm a long time perl programmer who is learning python. i'd be interested > in any comments you might have on my code below. feel free to respond > privately if you prefer. i'd like to know if i'm on the right track. Sure! Happy to help out

Re: program to generate data helpful in finding duplicate large files

2014-09-18 Thread Chris Kaynor
On Thu, Sep 18, 2014 at 11:11 AM, David Alban wrote: > *#!/usr/bin/python* > > *import argparse* > *import hashlib* > *import os* > *import re* > *import socket* > *import sys* > > *from stat import ** > Generally, from import * imports are discouraged as they tend to populate your namespace and

program to generate data helpful in finding duplicate large files

2014-09-18 Thread David Alban
greetings, i'm a long time perl programmer who is learning python. i'd be interested in any comments you might have on my code below. feel free to respond privately if you prefer. i'd like to know if i'm on the right track. the program works, and does what i want it to do. is there a differen

Re: hashlib suddenly broken

2014-09-18 Thread Chris Angelico
On Fri, Sep 19, 2014 at 3:07 AM, Steven D'Aprano wrote: > but I expect that's probably not where the problem lies. My *wild guess* is > that your system updated SSL, and removed some underlying SHA-1 library > needed by hashlib. SHA-1 is pretty old, and there is now a known attack on > it, so some

Re: hashlib suddenly broken

2014-09-18 Thread Steven D'Aprano
Larry Martell wrote: > I am on a mac running 10.8.5, python 2.7 > > Suddenly, many of my scripts started failing with: > > ValueError: unsupported hash type sha1 [...] > This just started happening yesterday, and I cannot think of anything > that I've done that could cause this. Ah, the ol' "I

Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))`

2014-09-18 Thread Ian Kelly
On Thu, Sep 18, 2014 at 10:35 AM, wrote: > It's be nice if Python's math module did more than simply wrap the default i > implementation of the underlying C lib -- it's gotten better over the years > (Inf and NaN used to be really hard to get), but still not quite what it > could be. I think

Re: Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread Tim Chase
On 2014-09-18 08:58, Roy Smith wrote: > I suspect what he meant was "How can I tell if I'm iterating over > an ordered collection?", i.e. iterating over a list vs. iterating > over a set. > > list1 = [item for item in i] > list2 = [item for item in i] > > am I guaranteed that list1 == list2? It

Re: hashlib suddenly broken

2014-09-18 Thread John Gordon
In Larry Martell writes: > Googling this showed that it's an issue with hashlib with a common > cause being a file called hashlib.py that gets in the way of the > interpreter finding the standard hashlib module, but that doesn't seem > to be the case: Perhaps hashlib imports some other module

Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))`

2014-09-18 Thread chris . barker
On Wednesday, September 17, 2014 11:22:42 PM UTC-7, wxjm...@gmail.com wrote: > >>> 1e300*1e300 > > inf > > >>> exp(1e300) > > Traceback (most recent call last): > > File "", line 1, in > > OverflowError: math range error FWIW, numpy is a bit more consistent: In [89]: numpy.exp(1e300) Out[

Re: Best practice for opening files for newbies?

2014-09-18 Thread Chris Angelico
On Fri, Sep 19, 2014 at 2:19 AM, wrote: > So: there are way too many ways to open a simple file to read or write a bit > of text (or binary): > > open() Personally, I'd just use this, all the way through - and not importing from io, either. But others may disagree. Be clear about what's text a

hashlib suddenly broken

2014-09-18 Thread Larry Martell
I am on a mac running 10.8.5, python 2.7 Suddenly, many of my scripts started failing with: ValueError: unsupported hash type sha1 Googling this showed that it's an issue with hashlib with a common cause being a file called hashlib.py that gets in the way of the interpreter finding the standard

Best practice for opening files for newbies?

2014-09-18 Thread chris . barker
Folks, I'm in the position of teaching Python to beginners (beginners to Python, anyway). I'm teaching Python2 -- because that is still what most of the code "in the wild" is in. I do think I"ll transition to Python 3 fairly soon, as it's not too hard for folks to back-port their knowledge, bu

Re: Best approach to get data from web page continuously

2014-09-18 Thread Joel Goldstick
On Thu, Sep 18, 2014 at 9:30 AM, Juan Christian wrote: > I'll write a python (Python 3.4.1) script to fetch for new data (topics) > from this page (http://steamcommunity.com/app/440/tradingforum) > continuously. > > All the topics follow this structure: href="http://steamcommunity.com/app/440/tra

Re: the python shell window is already executing a command

2014-09-18 Thread Seymore4Head
On Wed, 17 Sep 2014 23:50:56 -0400, Terry Reedy wrote: >On 9/17/2014 9:34 PM, Seymore4Head wrote: >> On Wed, 17 Sep 2014 18:56:47 -0400, Terry Reedy > >>> A little digging with Idle's grep (Find in Files) shows that the message >>> is produced by this code in idlelib/PyShell.py, about 825. >>> >

Re: Controlling ALLUSERS property in non-interactive MSI installer (Python 3.4.1)

2014-09-18 Thread Joel Goldstick
On Thu, Sep 18, 2014 at 3:22 AM, wrote: > Hey list > > I need to install a private copy of Python on Windows 7 and 8, for use only > by one specific tool. The install should happen as part of the installation > of the tool. > > I can control TARGETDIR and extensions (via ADDLOCAL) but I'm faili

Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))`

2014-09-18 Thread Grant Edwards
On 2014-09-18, Steven D'Aprano wrote: > Marko Rauhamaa wrote: > >> Maybe IEEE had some specific numeric algorithms in mind when it >> introduced inf and nan. However, I have a feeling an exception would be >> a sounder response whenever the arithmetics leaves the solid ground. > > I'm afraid that

Re: Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread Terry Reedy
On 9/18/2014 8:58 AM, Roy Smith wrote: I suspect what he meant was "How can I tell if I'm iterating over an ordered collection?", i.e. iterating over a list vs. iterating over a set. One can check whether the iterable is a tuple, list, range, or tuple or list iterator (the latter not being re

Re: Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread Chris Angelico
On Thu, Sep 18, 2014 at 10:58 PM, Roy Smith wrote: > I suspect what he meant was "How can I tell if I'm iterating over an > ordered collection?", i.e. iterating over a list vs. iterating over a > set. Right, which is what I meant by asking if the order mattered. When you iterate over a set, you'l

Best approach to get data from web page continuously

2014-09-18 Thread Juan Christian
I'll write a python (Python 3.4.1) script to fetch for new data (topics) from this page (http://steamcommunity.com/app/440/tradingforum) continuously. All the topics follow this structure: http://steamcommunity.com/app/440/tradingforum/TOPIC_ID/";> It will work like that: I'll get the last topic

Re: Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread Roy Smith
In article , Chris Angelico wrote: > On Thu, Sep 18, 2014 at 9:55 PM, cool-RR wrote: > > My function gets an iterable of an unknown type. I want to check whether > > it's ordered. I could check whether it's a `set` or `frozenset`, which > > would cover many cases, but I wonder if I can do bet

Re: Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread Chris Angelico
On Thu, Sep 18, 2014 at 9:55 PM, cool-RR wrote: > My function gets an iterable of an unknown type. I want to check whether it's > ordered. I could check whether it's a `set` or `frozenset`, which would cover > many cases, but I wonder if I can do better. Is there a nicer way to check > whether

Is there a canonical way to check whether an iterable is ordered?

2014-09-18 Thread cool-RR
My function gets an iterable of an unknown type. I want to check whether it's ordered. I could check whether it's a `set` or `frozenset`, which would cover many cases, but I wonder if I can do better. Is there a nicer way to check whether an iterable is ordered or not? Thanks, Ram. -- https:

Re: Hierarchical consolidation in Python

2014-09-18 Thread Mark Lawrence
On 18/09/2014 09:57, ap501...@gmail.com wrote: I am looking for some tips as to how Python could be used to solve a simple business problem involving consolidation of financial data across a company with a number of business units rolling up to a department and departments rolling up to the w

Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))`

2014-09-18 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Maybe IEEE had some specific numeric algorithms in mind when it > introduced inf and nan. However, I have a feeling an exception would be > a sounder response whenever the arithmetics leaves the solid ground. I'm afraid that you're missing the essential point of INF and qu

Re: Hierarchical consolidation in Python

2014-09-18 Thread Chris Angelico
On Thu, Sep 18, 2014 at 6:57 PM, wrote: > Required to find: > > (1)Income, Expenses and Surplus consolidated for all units within a > Department; and > (2)Income, Expenses and Surplus consolidated for all departments within the > company. > > I would welcome any help in expressing this problem

Hierarchical consolidation in Python

2014-09-18 Thread ap501228
I am looking for some tips as to how Python could be used to solve a simple business problem involving consolidation of financial data across a company with a number of business units rolling up to a department and departments rolling up to the whole organization. Company = Department(1)+Depar

Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))`

2014-09-18 Thread cool-RR
On Thursday, September 18, 2014 6:12:08 AM UTC+3, Steven D'Aprano wrote: > cool-RR wrote: > > Chris, why is this invariant `div*y + mod == x` so important? Maybe it's > > more important to return a mathematically reasonable result for the the > > floor-division result than to maintain this invarian

Controlling ALLUSERS property in non-interactive MSI installer (Python 3.4.1)

2014-09-18 Thread norman . ives
Hey list I need to install a private copy of Python on Windows 7 and 8, for use only by one specific tool. The install should happen as part of the installation of the tool. I can control TARGETDIR and extensions (via ADDLOCAL) but I'm failing to install "just for this user". I've been trying