Re: PEP 393 vs UTF-8 Everywhere

2017-01-20 Thread Chris Kaynor
. On Fri, Jan 20, 2017 at 3:15 PM, Thomas Nyberg wrote: > On 01/20/2017 03:06 PM, Chris Kaynor wrote: >> >> >> [...snip...] >> >> -- >> Chris Kaynor >> > > I was able to delete my response which was a wholly contained subset of this >

Re: PEP 393 vs UTF-8 Everywhere

2017-01-20 Thread Chris Kaynor
s only developers writing extension modules that need to care - and only then if they need maximum performance, and thus cannot convert every string they access to UTF32 or UTF8. -- Chris Kaynor -- https://mail.python.org/mailman/listinfo/python-list

Re: OSError: [Errno 12] Cannot allocate memory

2016-11-30 Thread Chris Kaynor
On Wed, Nov 30, 2016 at 4:54 PM, duncan smith wrote: > > Thanks. So something like the following might do the job? > > def _execute(command): > p = subprocess.Popen(command, shell=False, > stdout=subprocess.PIPE, > stderr=subprocess.STDOUT, >

Re: OSError: [Errno 12] Cannot allocate memory

2016-11-30 Thread Chris Kaynor
On Wed, Nov 30, 2016 at 4:12 PM, duncan smith wrote: > On 30/11/16 17:57, Chris Angelico wrote: >> On Thu, Dec 1, 2016 at 4:34 AM, duncan smith wrote: >>> >>> def _execute(command): >>> # shell=True security hazard? >>> p = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, >>>

Re: Asyncio -- delayed calculation

2016-11-30 Thread Chris Kaynor
On Wed, Nov 30, 2016 at 10:58 AM, Chris Angelico wrote: > On Thu, Dec 1, 2016 at 5:54 AM, Terry Reedy wrote: >> On 11/30/2016 7:53 AM, Chris Angelico wrote: >> >>> I also think that everyone should spend some time writing >>> multithreaded code before switching to asyncio. It'll give you a >>> be

Re: OSError: [Errno 12] Cannot allocate memory

2016-11-30 Thread Chris Kaynor
On Wed, Nov 30, 2016 at 9:34 AM, duncan smith wrote: > Hello, > I have had an issue with some code for a while now, and I have not > been able to solve it. I use the subprocess module to invoke dot > (Graphviz) to generate a file. But if I do this repeatedly I end up with > an error. The fol

Re: Random number help

2016-11-23 Thread Chris Kaynor
On Wed, Nov 23, 2016 at 11:17 AM, Thomas Grops via Python-list wrote: > I need a way of generating a random number but there is a catch: > > I don't want to include certain numbers, is this possible? > > random.randint(1,100) works as it will randomly pick numbers between 1 and > 100 but say i do

Re: MemoryError and Pickle

2016-11-21 Thread Chris Kaynor
On Mon, Nov 21, 2016 at 3:43 PM, John Gordon wrote: > In Fillmore > writes: > > >> Question for experts: is there a way to refactor this so that data may >> be filled/written/released as the scripts go and avoid the problem? >> code below. > > That depends on how the data will be read. Here is

Re: Syncing up iterators with gaps

2016-09-28 Thread Chris Kaynor
Here is a slight variation of Chris A's code that does not require more than a single look-ahead per generator. It may be better depending on the exact data passed in. Chris A's version will store all of the items for each output that have a matching key, which, depending on the expected data, cou

Re: pypy on windows much slower than linux/mac when using complex number type?

2016-09-20 Thread Chris Kaynor
On Tue, Sep 20, 2016 at 3:59 PM, Chris Angelico wrote: > On Wed, Sep 21, 2016 at 8:50 AM, Irmen de Jong > wrote: > >> Dunno if it's the cause or not, but you're running a 32-bit PyPy on a > >> 64-bit Windows. I could well imagine that that has some odd > >> significance. > >> > >> ChrisA > > > >

Re: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies]

2016-09-14 Thread Chris Kaynor
On Wed, Sep 14, 2016 at 1:19 PM, wrote: > It is so blantantly obvious that the world is not flat I find this > discussion flabbergasting. Anybody who has tried to take any form of > vehicle up, or probably more dangerously down, any form of hill knows > that. As for the raving lunatics who make

Re: saving octet-stream png file

2016-08-19 Thread Chris Kaynor
On Fri, Aug 19, 2016 at 12:00 PM, Larry Martell wrote: > On Fri, Aug 19, 2016 at 1:24 PM, Chris Angelico wrote: > > On Sat, Aug 20, 2016 at 3:10 AM, Larry Martell > wrote: > >> I have some python code (part of a django app) that processes a > >> request that contains a png file. The request is

Re: python and open office

2016-07-27 Thread Chris Kaynor
def __init__(self, name: str): That "name: str" syntax is called function annotations, and was added in Python 3, and you are trying to use the module in Python 2.7. There may be another variation of the module compatible with Python 2, or you'll need to upgrade your Python to a version of Python

Re: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)]

2016-07-21 Thread Chris Kaynor
On Thu, Jul 21, 2016 at 4:54 PM, Ben Bacarisse wrote: > Steven D'Aprano writes: > > > Or you might be using a language like Javascript, which intentionally has > > only floats for numbers. That's okay, you can still perform exact integer > > arithmetic, so long as you stay within the bounds of

Re: setrecursionlimit

2016-05-18 Thread Chris Kaynor
On Wed, May 18, 2016 at 10:15 AM, Steven D'Aprano wrote: > I don't really understand why the system can't track the current top of the > stack and bottom of the heap, and if they're going to collide, halt the > process. That would still be kinda awful, in a sudden "your application > just died" k

Re: setrecursionlimit

2016-05-18 Thread Chris Kaynor
On Wed, May 18, 2016 at 9:19 AM, Ned Batchelder wrote: > I believe the issue here is that Python recursion results in the C stack > growing. Each Python function call creates a number of C function calls, > which grows the C stack. The crash you see is the C stack overflowing. > > Is there a wa

Re: def __init__(self):

2016-04-26 Thread Chris Kaynor
On Tue, Apr 26, 2016 at 10:04 AM, Chris Angelico wrote: > On Wed, Apr 27, 2016 at 2:59 AM, Chris Kaynor > wrote: > > On Tue, Apr 26, 2016 at 9:32 AM, Steven D'Aprano > > wrote: > > > >> Subclassing immutable built-ins is the most obvious and simple (and &g

Re: def __init__(self):

2016-04-26 Thread Chris Kaynor
On Tue, Apr 26, 2016 at 9:32 AM, Steven D'Aprano wrote: > Subclassing immutable built-ins is the most obvious and simple (and > probably > common) way to get an immutable class. Actually immutable, short of doing > wicked things with ctypes. > By wicked things with ctypes, do you mean something

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

Re: Simple exercise

2016-03-10 Thread Chris Kaynor
On Thu, Mar 10, 2016 at 4:05 PM, BartC wrote: > Here's a rather un-Pythonic and clunky version. But it gives the expected > results. (I've dispensed with file input, but that can easily be added > back.) > > def last(a): > return a[-1] > > def init(a): # all except last elemen

Re: breaking out of outer loops

2016-03-07 Thread Chris Kaynor
On Mon, Mar 7, 2016 at 3:21 PM, Fillmore wrote: > On 3/7/2016 6:17 PM, Ian Kelly wrote: > >> On Mon, Mar 7, 2016 at 4:09 PM, Fillmore >> wrote: >> >>> >>> I must be missing something simple because I can't find a way to break >>> out >>> of a nested loop in Python. >>> >>> Is there a way to labe

Re: [Newbie] Tkinter Question

2016-02-23 Thread Chris Kaynor
On Tue, Feb 23, 2016 at 2:19 PM, Wildman via Python-list < python-list@python.org> wrote: > I am familiar with OO programming but I am new to Python > and Tkinter. I am working on a gui program that creates > a couple of temporary files. As part of the Exit button > command they are deleted. If

Re: [SOLVED] There has to be a better way to split this string!

2016-02-09 Thread Chris Kaynor
On Tue, Feb 9, 2016 at 5:58 PM, Anthony Papillion wrote: > > On 02/09/2016 07:47 PM, Ben Finney wrote: > > Anthony Papillion writes: > > > >> On 02/09/2016 07:26 PM, Anthony Papillion wrote: > >>> I am using datetime.now() to create a unique version of a filename. > >>> […] > >> > >> Found the so

Re: .format won't display my value with 2 decimal places: Why?

2016-01-25 Thread Chris Kaynor
On Mon, Jan 25, 2016 at 9:48 AM, Chris Angelico wrote: > On Tue, Jan 26, 2016 at 4:32 AM, Random832 wrote: > > On Mon, Jan 25, 2016, at 12:23, Chris Angelico wrote: > >> if some translations don't use a token at all, > > > > I'm not sure what situation that would be reasonable in. > > I don't do

Re: Bi-directional sub-process communication

2015-11-23 Thread Chris Kaynor
On Mon, Nov 23, 2015 at 2:18 PM, Israel Brewster wrote: > Of course, that last step could be interesting - implementing the block in > such a way as to not tie up the processor, while still getting the data "as > soon" as it is available. Unless there is some sort of built-in > notification syste

Re: Check if a given value is out of certain range

2015-10-01 Thread Chris Kaynor
On Thu, Oct 1, 2015 at 3:03 PM, Ian Kelly wrote: > On Thu, Oct 1, 2015 at 3:45 PM, John Gordon wrote: > > In <87r3le1ht3@elektro.pacujo.net> Marko Rauhamaa > > writes: > >> Wouldn't > > > >>x < 0 or 10 < x > > > >> be even more visual? > > > > [SNIP] > > > > Another strike is that the c

Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run

2015-08-25 Thread Chris Kaynor
On Tue, Aug 25, 2015 at 2:19 PM, RAH wrote: > Dear All, > > I experienced an incomprehensible behavior (I've spent already many hours on > this subject): the `file.write('string')` provides an error in run mode and > not when interpreted at the console. The string must contain non-ASCII > chara

Re: why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)?

2015-08-17 Thread Chris Kaynor
On Mon, Aug 17, 2015 at 3:25 PM, wrote: > > Sorry I completely mistype that. It was supposed to read: > > >>> id(multiprocessing.Process.is_alive) == > id(multiprocessing.Process.start) > True > What is going on here is that it get multiprocessing.Process.is_alive, computes the id of it, then thr

Re: 42**1000000 is CPU time free

2015-07-24 Thread Chris Kaynor
As you are doing an operation on a literal, Python is computing the value at import time, which occurs before your time.clock() calls run. Basically, what you really wrote in your code is: import time a = time.clock() 42000...00 # Replace the ... with z

Re: Could you explain lambda function to me?

2015-06-02 Thread Chris Kaynor
On Tue, Jun 2, 2015 at 11:14 AM, fl wrote: > Hi, > > I see the description of lambda at the online tutorial, but I cannot > understand it. '42' is transferred to the function. What 'x' value should > be? I do not see it says that it is '0'. And, what is 'x'? > The lambda keyword is merely anothe

Re: Lucky numbers in Python

2015-04-29 Thread Chris Kaynor
On Wed, Apr 29, 2015 at 2:45 PM, Cecil Westerhof wrote: > >> I was wondering if there is a way to do this: > >> for del_index in range((sieve_len // skip_count) * skip_count - 1, > >> skip_count - 2, -skip_count): > >> del sieve[del_index] > >> in a more efficient way. > > > > You can delete usin

Re: A question on the creation of list of lists

2015-04-22 Thread Chris Kaynor
On Wed, Apr 22, 2015 at 9:18 AM, wrote: > Dear Group, > > I am trying to open a bunch of files from a directory and trying to put > the results in list of lists that is to say, > > that is to say, > I have a list of file names of a directory, I want to read each one of > them. > After reading eac

Re: find all multiplicands and multipliers for a number

2015-04-15 Thread Chris Kaynor
On Wed, Apr 15, 2015 at 9:21 AM, Paul Rubin wrote: > Ian Kelly writes: >> Nope. You do end up with a lot of nested filter objects, but there's >> no recursion in the Python code, which means that you're not piling up >> frame objects, and you'll never hit the interpreter's recursion limit. > > I

Re: Best search algorithm to find condition within a range

2015-04-08 Thread Chris Kaynor
On Wed, Apr 8, 2015 at 3:06 PM, Marko Rauhamaa wrote: > BartC : > >> So the the number 3,012,345, in base 100, could represented in >> text form as the two 'digit': >> >> (3, 12345) >> >> ie. 3*100 + 12345*1. In internal binary, each digit can just be >> stored in the normal form, probabl

Re: Code critique please

2015-04-07 Thread Chris Kaynor
On Tue, Apr 7, 2015 at 3:43 PM, wrote: > I just wrote this bit (coming from Pascal) and am wondering how seasoned > Python programmers would have done the same? Anything terribly non-python? > > As always, thanks for all input. > > K > > > > """ > Creates a PNG image from EPD file > """ > > imp

Re: subprocess and stdin.write(), stdout.read()

2015-03-24 Thread Chris Kaynor
On Tue, Mar 24, 2015 at 12:08 PM, Tobiah wrote: > The docs for the subprocess.Popen() say: > > Use communicate() rather than .stdin.write, .stdout.read > or .stderr.read to avoid deadlocks due to any of the other > OS pipe buffers filling up and blocking the child process >

Re: Bug in timsort!?

2015-02-25 Thread Chris Kaynor
On Wed, Feb 25, 2015 at 8:44 AM, Sturla Molden wrote: > > On 25/02/15 17:04, Peter Otten wrote: > >> These guys found a bug that is subtler than what most of us have dealt with >> in a widely used piece of code originally developed by one of the smarter >> members of the python "community". >> >>

Re: Bug in timsort!?

2015-02-24 Thread Chris Kaynor
On Tue, Feb 24, 2015 at 4:07 PM, Chris Angelico wrote: > On Wed, Feb 25, 2015 at 10:50 AM, Skip Montanaro > wrote: > > Even if/when we get to the point where machines can hold an array of > > 2**49 elements, I suspect people won't be using straight Python to > > wrangle them. > > Looking just at

Re: strip bug?

2015-02-24 Thread Chris Kaynor
On Tue, Feb 24, 2015 at 3:05 PM, wrote: > >>> 'http://xthunder'.strip('http://') > 'xthunder' > >>> 'http://thunder'.strip('http://') > 'under' > >>> > > I could understand backslash but forward slash? I believe the issue is that str.strip does not do quite what you are thinking it does, howeve

Re: try pattern for database connection with the close method

2015-02-20 Thread Chris Kaynor
On Fri, Feb 20, 2015 at 6:42 PM, Mario Figueiredo wrote: > import sqlite3 as lite > > try: > db = lite.connect('data.db') > except lite.DatabaseError: > raise OSError('database file corrupt or not found.') > else: > try: >

Re: __next__ and StopIteration

2015-02-10 Thread Chris Kaynor
On Tue, Feb 10, 2015 at 12:30 AM, Ian Kelly wrote: > > On Mon, Feb 9, 2015 at 5:59 PM, Chris Kaynor wrote: > > On Mon, Feb 9, 2015 at 4:42 PM, Steven D'Aprano > > wrote: > >> so that's an excellent sign that doing so is best practice, but it should >

Re: __next__ and StopIteration

2015-02-09 Thread Chris Kaynor
On Mon, Feb 9, 2015 at 4:42 PM, Steven D'Aprano wrote: > so that's an excellent sign that doing so is best practice, but it should > not be seen as *required*. After all, perhaps you have good reason for > wanting your iterable class to only be iterated over once. In fact, there is one in the std

Re: pymongo and attribute dictionaries

2015-02-04 Thread Chris Kaynor
On Wed, Feb 4, 2015 at 12:16 PM, Travis Griggs wrote: > >> On Feb 4, 2015, at 9:22 AM, Ian Kelly wrote: >> >> On Wed, Feb 4, 2015 at 9:50 AM, Travis Griggs wrote: >>> I really like pymongo. And I really like Python. But one thing my fingers >>> really get tired of typing is >>> >>> someDoc[‘_’i

Re: Python is DOOMED! Again!

2015-01-29 Thread Chris Kaynor
On Thu, Jan 29, 2015 at 2:57 PM, BartC wrote: > I've read most of the thread but haven't been able to figure out /why/ this > is being proposed. What is the advantage, speed? Check out the rationale part of the PEP: https://www.python.org/dev/peps/pep-0484/#rationale-and-goals. Other parts of the

Re: parsing tree from excel sheet

2015-01-29 Thread Chris Kaynor
On Thu, Jan 29, 2015 at 1:59 PM, Mark Lawrence wrote: > On 29/01/2015 21:32, alb wrote: >> >> Hi MRAB, >> >> MRAB wrote: >> [] > > SyntaxError: invalid syntax > debian@debian:example$ python3 export_latex.py doctree.csv >File "export_latex.py", line 36 > yield from ch

Re: ANN: unpyc3 - a python bytecode decompiler for Python3

2015-01-28 Thread Chris Kaynor
On Wed, Jan 28, 2015 at 3:01 PM, Devin Jeanpierre wrote: > On Wed, Jan 28, 2015 at 2:02 PM, Chris Angelico wrote: >> On Thu, Jan 29, 2015 at 8:52 AM, Devin Jeanpierre >> wrote: >>> Git doesn't help if you lose your files in between commits, or if you >>> lose the entire directory between pushes.

Re: ANN: unpyc3 - a python bytecode decompiler for Python3

2015-01-28 Thread Chris Kaynor
On Wed, Jan 28, 2015 at 10:42 AM, Devin Jeanpierre wrote: > FWIW I put all my source code inside Dropbox so that even things I > haven't yet committed/pushed to Bitbucket/Github are backed up. So far > it's worked really well, despite using Dropbox on both Windows and > Linux. (See also: Google Dr

Re: Python is DOOMED! Again!

2015-01-22 Thread Chris Kaynor
On Thu, Jan 22, 2015 at 2:12 PM, Ian Kelly wrote: >>> def adder(a,b): return a+b >>> >>> This is one of the pythonic idioms that help with polymorphic functions. Is >>> there a proposal for providing hinting for these? >> >> You can use TypeVar for that. >> >> T = TypeVar('T') >> >> def adder(a:

Re: multiprocessing queue hangs up on the Amazon cloud

2015-01-14 Thread Chris Kaynor
On Wed, Jan 14, 2015 at 2:16 PM, Chris Angelico wrote: > And then you seek to run multiple workers. If my reading is correct, > one of them (whichever one happens to get there first) will read the > STOP marker and finish; the others will all be blocked, waiting for > more work (which will never

Re: Comparisons and sorting of a numeric class....

2015-01-08 Thread Chris Kaynor
On Thu, Jan 8, 2015 at 6:57 AM, Ian Kelly wrote: > On Wed, Jan 7, 2015 at 11:21 PM, Marko Rauhamaa wrote: > > Steven D'Aprano : > > > >> Marko Rauhamaa wrote: > >>> I prefer the Scheme way: > >>>#f is a falsey object > >>>everything else is a truthy object > >> > >> The Scheme way has no

Re: When do default parameters get their values set?

2014-12-11 Thread Chris Kaynor
On Wed, Dec 10, 2014 at 7:15 PM, Steven D'Aprano wrote: > On Wed, 10 Dec 2014 18:18:44 -0800, Rustom Mody wrote: > > > > And going the other way -- no defs only lambdas its this: > > > > > f = lambda : (lambda x= {}: x) > f()() is f()() > > False > d = f() > d() is d() > > Tru

Re: When do default parameters get their values set?

2014-12-08 Thread Chris Kaynor
On Mon, Dec 8, 2014 at 2:10 PM, bSneddon wrote: > I ran into an issue setting variables from a GUI module that imports a > back end module. My approach was wrong obviously but what is the best way > to set values in a back end module. > > #module name beTest.py > > cfg = { 'def' : 'blue'} > > de

Re: Potential pitfalls when going from old-style to new-style classes

2014-11-19 Thread Chris Kaynor
On Wed, Nov 19, 2014 at 11:14 AM, Skip Montanaro wrote: > I discussion on the code-quality list got me thinking. Suppose I have > an old-style class in a 2.x app: > > class Foo: > def __init__(self): > blah blah blah > > I still use 2.x exclusively, but anytime I run pylint over a bit of >

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-12 Thread Chris Kaynor
On Wed, Nov 12, 2014 at 1:51 PM, Ian Kelly wrote: > On Wed, Nov 12, 2014 at 2:33 PM, Chris Kaynor > wrote: > > A decorator is an interesting idea, and should be easy to implement (only > > lightly tested): > > > > def main(func): > > if func.__module__

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-12 Thread Chris Kaynor
On Wed, Nov 12, 2014 at 1:07 PM, Joel Goldstick wrote: > On Wed, Nov 12, 2014 at 4:02 PM, John Ladasky > wrote: > > I have taught Python to several students over the past few years. As I > have worked with my students, I find myself bothered by the programming > idiom that we use to determine w

Re: No Error; No Output...Nothing

2014-10-21 Thread Chris Kaynor
On Tue, Oct 21, 2014 at 2:44 PM, ryguy7272 wrote: > I commented out the import pylab as pl because I couldn't get the > matplotlib.pylab import working. So, anyway, I hit F5, and it seems to > run, but it doesn't really do anything. Isn't this either supposed to be > downloading data from the w

Re: Simple import in python 3 errors with complaint about bytes

2014-10-20 Thread Chris Kaynor
Are you perhaps doing an import inside of the C code? Chris On Mon, Oct 20, 2014 at 4:29 PM, Mike Boyle wrote: > I'm modifying an extension written with the c-api to have a datatype of > quaternions , with one of the > goals being python 3 support. It

Re: operator module functions

2014-10-08 Thread Chris Kaynor
On Wed, Oct 8, 2014 at 3:30 PM, Chris Angelico wrote: > > > > > > That doesn't always seem to have been the case, however. > > In Python 2.7 and 3.3, I get > > > operator.add is operator.__add__ > > False > > Huh. So it is. > > rosuav@sikorsky:~$ python3 > Python 3.5.0a0 (default:301b9a58021

Re: operator module functions

2014-10-08 Thread Chris Kaynor
On Wed, Oct 8, 2014 at 2:05 PM, Gelonida N wrote: > On 10/8/2014 9:09 PM, Terry Reedy wrote: > >> On 10/8/2014 6:57 AM, Steven D'Aprano wrote: >> >> According to the documentation, operator.__add__ is the "official" >>> function, >>> and operator.add is just there for convenience. >>> >> >> You

Re: Function passed as an argument returns none

2014-10-01 Thread Chris Kaynor
Chris On Wed, Oct 1, 2014 at 3:37 PM, Shiva wrote: > Hi, > I am learning Python (version 3.4) strings.I have a function that takes in > a > parameter and prints it out as given below. > > def donuts(count): > if count <= 5: > print('Number of donuts: ',count) > else: > print('Number

Re: Clearing globals in CPython

2014-10-01 Thread Chris Kaynor
On Wed, Oct 1, 2014 at 9:14 AM, Chris Angelico wrote: > On Thu, Oct 2, 2014 at 2:00 AM, Steven D'Aprano > wrote: > > Obviously the easiest way to recover is to exit the current session and > > restart it, but as a challenge, can we recover from this state? > > Oooh interesting. This is kinda lik

Re: Best way to deal with different data types in a list comprehension

2014-09-23 Thread Chris Kaynor
On Tue, Sep 23, 2014 at 3:01 PM, Larry Martell wrote: > I have some code that I inherited: > > ' '.join([self.get_abbrev()] + >[str(f['value') > for f in self.filters > if f.has_key('value')]).strip() > > This broke today when it encountered some non-ascii dat

Re: Python advice

2014-09-22 Thread Chris Kaynor
On Mon, Sep 22, 2014 at 12:39 PM, Ian Kelly wrote: > On Mon, Sep 22, 2014 at 1:00 PM, Chris Kaynor > wrote: > > Python is pretty good base-line language. It is really good as a glue > > language to piece together other components, or for IO-bound or > user-bound > >

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

2014-09-22 Thread Chris Kaynor
cially if some of the files are truly binary (such as *.exe on Windows). Chris On Mon, Sep 22, 2014 at 12:34 PM, wrote: > On Thu, Sep 18, 2014, at 14:45, Chris Kaynor wrote: > > Additionally, you may want to specify binary mode by using > > open(file_path, > > 'rb')

Re: Python advice

2014-09-22 Thread Chris Kaynor
On Mon, Sep 22, 2014 at 11:03 AM, Dave Angel wrote: > > I need a way forward on what more free ebooks i can get mt hands on so i > can accomplish my goals. > > > > I need some advice. should i go on to learn other languages like java or > c++ cos i want to be able to using all these knowledge for

Re: Love to get some feedback on my first python app!!!

2014-09-22 Thread Chris Kaynor
On Mon, Sep 22, 2014 at 8:52 AM, Jean-Michel Pichavant < jeanmic...@sequans.com> wrote: > Anyway it's seems we agree anyway because your example perfectly > illustrate what I was trying to demonstrate: > print(cells[2]) is very easy to understand, most of people would say 'no > need of any comment

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

Re: My backwards logic

2014-09-05 Thread Chris Kaynor
On Fri, Sep 5, 2014 at 2:49 PM, Seymore4Head wrote: > On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head > wrote: > > >I'm still doing practice problems. I haven't heard from the library > >on any of the books I have requested. > > > > > http://www.practicepython.org/exercise/2014/04/16/11-check-

Re: My backwards logic

2014-09-05 Thread Chris Kaynor
On Fri, Sep 5, 2014 at 10:44 AM, Seymore4Head wrote: > On Fri, 05 Sep 2014 10:08:18 -0700, Ethan Furman > wrote: > > >On 09/05/2014 09:48 AM, Seymore4Head wrote: > >> I'm still doing practice problems. I haven't heard from the library > >> on any of the books I have requested. > >> > >> > http:

Re: My backwards logic

2014-09-05 Thread Chris Kaynor
On Fri, Sep 5, 2014 at 9:48 AM, Seymore4Head wrote: > I'm still doing practice problems. I haven't heard from the library > on any of the books I have requested. > > > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > > This is not a hard problem, but it got m

Re: crc algorithm

2014-09-02 Thread Chris Kaynor
Also, depending on the use-case, binascii.crc32 might also work fine: https://docs.python.org/2/library/binascii.html#binascii.crc32 import binascii def calc_crc(data): return binascii.crc32(data) Much simpler. Chris On Tue, Sep 2, 2014 at 11:24 AM, Peter Otten <__pete...@web.de> wrote:

Re: Thread terminate

2014-08-28 Thread Chris Kaynor
On Thu, Aug 28, 2014 at 1:35 PM, Ervin Hegedüs wrote: > On Thu, Aug 28, 2014 at 12:34:18PM -0700, Chris Kaynor wrote: depending on what you are doing with the first two arguments to self._exit, >> the following might also work: >> >> def run(self): >> tr

Re: Thread terminate

2014-08-28 Thread Chris Kaynor
On Thu, Aug 28, 2014 at 11:39 AM, Ervin Hegedüs wrote: > Hi Chris, > > thanks for you answer, > > On Thu, Aug 28, 2014 at 09:23:24AM -0700, Chris Kaynor wrote: > > On Thu, Aug 28, 2014 at 1:52 AM, Ervin Hegedüs > wrote: > > > > > > > In your cas

Re: Thread terminate

2014-08-28 Thread Chris Kaynor
On Thu, Aug 28, 2014 at 1:52 AM, Ervin Hegedüs wrote: > > > In your case, you may want to just handle the exceptions inside the > > thread's run() function directly. If that is not possible and you really > > need to handle them inside the main thread, you would need to store off > the > > error

Re: iterating over strings seems to be really slow?

2014-08-27 Thread Chris Kaynor
On Wed, Aug 27, 2014 at 1:53 PM, Rodrick Brown wrote: def wc1(): > word="" > m={} > for c in s: > if c != " ": > word += c > else: > if m.has_key(word): > m[word] += 1 > else: > m[word] = 1 >

Re: Thread terminate

2014-08-27 Thread Chris Kaynor
On Wed, Aug 27, 2014 at 11:55 AM, Ervin Hegedüs wrote: > what's the correct way to terminate a thread by itself? > To terminate the thread, the run function must exit. This can be either from an exception or a return statement. > > I mean: > > class MyThread(threading.Thread): > def __init

Re: More Pythonic implementation

2014-08-19 Thread Chris Kaynor
On Tue, Aug 19, 2014 at 10:09 AM, Shubham Tomar wrote: > Lets say I have a function poker(hands) that takes a list of hands and > returns the highest ranking hand, and another function hand_rank(hand) that > takes hand and return its rank. As in Poker > http://www.pokerstars.com/poker/games/rules

Re: 'is not' or '!='

2014-08-18 Thread Chris Kaynor
On Mon, Aug 18, 2014 at 2:42 PM, Ethan Furman wrote: > If you are not dealing with singletons (which is most cases), such as > numbers, strings, lists, and most other arbitrary objects, you will need to > use "!=" or anytime the two objects you are comparing are not the exact > same object, you c

Re: Set static attributes...maybe.

2014-08-18 Thread Chris Kaynor
On Mon, Aug 18, 2014 at 10:00 AM, Beppe wrote: > hi to everybody, > in the following scrip I try to call the function read_parameters () but > returns me that wants two arguments!?!?! > My intent is to have in the class, Engine (), some static attributes that > can be used by other instances wit

Re: Module-level functions and the module type

2014-08-18 Thread Chris Kaynor
On Sun, Aug 17, 2014 at 8:15 AM, Chris Angelico wrote: > In a class definition, you have explicit state parameters on your > functions - 'self': > > class C: > def foo(self, arg): > # blah blah > > At module level, there's equivalent state - the function "knows" what > module it came

Re: Captcha identify

2014-08-13 Thread Chris Kaynor
On Wed, Aug 13, 2014 at 4:39 AM, Eric S. Johansson wrote: > eliminate captchas, 35+million disabled people would thank you as would > many more millions of the not-yet-disabled like your future self. And so would the spammers, which is who captchas are trying to block. For ease-of-use, most si

Re: Begginer in python trying to load a .dll

2014-08-12 Thread Chris Kaynor
On Tue, Aug 12, 2014 at 11:48 AM, Skip Montanaro wrote: > Just as the off-chance your DLL was written in C++... I don't think > you can interface with ctypes directly. I think you would have to > write a little shim DLL which exposes a C-compatible API. > You should be able to use ctypes with a

Re: Newbie needing some help

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 4:38 PM, Chris Angelico wrote: > On Sat, Aug 9, 2014 at 8:01 AM, Chris Kaynor > wrote: > > However, I'd recommend re-raising the exception after rolling back the > > transaction with a bare "raise" statement right after the db.rollback(

Re: Newbie needing some help

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 5:13 PM, Chris Angelico wrote: > On Sat, Aug 9, 2014 at 9:55 AM, Chris Kaynor > wrote: > > try: > > action > > commit > > finally: > > rollback > > If commit/rollback automatically opens a new transaction, this would &

Re: Newbie needing some help

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 12:07 PM, Matt Smith wrote: > I am trying to write a program that will loop through a text file and > delete rows in a mysql database. > > It seemingly runs but I don't see anything getting deleted in the db. > Is there anything apparent that I am missing? > > This is the

Re: Specifying `blocking` and `timeout` when acquiring lock as a context manager

2014-08-08 Thread Chris Kaynor
On Fri, Aug 8, 2014 at 11:35 AM, Neil D. Cerutti wrote: > On 8/8/2014 12:16 PM, Chris Angelico wrote: > >> On Sat, Aug 9, 2014 at 2:05 AM, Neil D. Cerutti >> wrote: >> >>> Perhaps defer release, a la a common Go pattern: >>> >>> with contextlib.ExitStack() as stack: >>> acquired = lock.acqu

Re: speed up pandas calculation

2014-07-30 Thread Chris Kaynor
On Wed, Jul 30, 2014 at 5:57 PM, Vincent Davis wrote: > > On Wed, Jul 30, 2014 at 6:28 PM, Vincent Davis > wrote: > >> The real slow part seems to be >> for n in drugs: >> df[n] = >> df[['MED1','MED2','MED3','MED4','MED5']].isin([drugs[n]]).any(1) >> > > ​I was wrong, this is fast, it was sel

Re: gethostbyaddr()

2014-07-28 Thread Chris Kaynor
On Mon, Jul 28, 2014 at 2:33 PM, Edward Manning wrote: > I wrote this code, but it seem to work fine if I only have one ip in the > file. When I have more than one IP in the file > > I get a error. Does anyone have an idea why. > It would be helpful to know what the error you are getting is. It

Re: problem on multi-threading

2014-07-25 Thread Chris Kaynor
On Fri, Jul 25, 2014 at 12:45 AM, 水静流深 <1248283...@qq.com> wrote: > > never quit from the thread ,why? > I am going to guess that you can actually run code in the interpreter here. When printing from threads, the prompt will end up in the wrong place as the prompt is printed in the main thread.

Re: Why does not pprint work?

2014-07-22 Thread Chris Kaynor
On Tue, Jul 22, 2014 at 3:17 PM, emile wrote: > Then, how can I list all the function of pprint? >> > > use the dir builtin: > > >>> dir (pprint) > ['PrettyPrinter', '_StringIO', '__all__', '__builtins__', '__doc__', > '__file__', '__name__', '_commajoin', '_id', '_len', '_perfcheck', > '_recursi

Re: Iterating through set

2014-07-14 Thread Chris Kaynor
On Mon, Jul 14, 2014 at 5:10 PM, LJ wrote: > Hi All. > > I'm coding a Dynamic Programming algorithm to solve a network flow > problem. At some point in the algorithm I have to iterate through a set of > nodes, while adding and/or removing elements, until the set is empty. I > know a regular set()

Re: initializing "parameters" class in Python only once?

2014-07-14 Thread Chris Kaynor
On Mon, Jul 14, 2014 at 3:24 PM, Catherine M Moroney < catherine.m.moro...@jpl.nasa.gov> wrote: > Hello, > > Pardon me for not using the proper Python language terms, but I hope that > people can still understand the question: > > The problem: I'm writing a large Python program and I have a bunch

Re: running python 2 vs 3

2014-03-20 Thread Chris Kaynor
On Thu, Mar 20, 2014 at 1:59 PM, Marko Rauhamaa wrote: > Well, with proper care, I suppose the same code base could support perl > as well. ;) > Go even farther; how about C, PHP, and bash? I'm sure if you tried, you could mix in some Python as well. http://en.wikipedia.org/wiki/Polyglot_(comput

Re: Balanced trees

2014-03-18 Thread Chris Kaynor
> > On Tue, Mar 18, 2014 at 1:55 PM, Marko Rauhamaa wrote: > Dan Stromberg : >> > The results are at >> > >> http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-03/ > > Size: 1048576, duration: 75.3, dictionary type: dict > [...] > Size: 262144, duration: 66.

Re: Oddity using sorted with key

2014-03-11 Thread Chris Kaynor
On Tue, Mar 11, 2014 at 9:13 AM, Josh English wrote: > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > In this case, the key being sorted on is the function object x.name.lower, not the result of the call. It might make more sense if you break the lambda out into a separate def s

Re: Working with the set of real numbers (was: Finding size of Variable)

2014-03-05 Thread Chris Kaynor
On Wed, Mar 5, 2014 at 9:43 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > At one time, Euler summed an infinite series and got -1, from which he > concluded that -1 was (in some sense) larger than infinity. I don't know > what justification he gave, but the way I think of it

Re: How security holes happen

2014-03-03 Thread Chris Kaynor
On Mon, Mar 3, 2014 at 2:25 PM, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 9:19 AM, Cameron Simpson wrote: > > On 03Mar2014 09:17, Neal Becker wrote: > >> Charles R Harris Wrote in message: > >> > > >> > >> Imo the lesson here is never write in low level c. Use modern > >> languages with

Re: Python 3.x adoption

2014-01-21 Thread Chris Kaynor
On Tue, Jan 21, 2014 at 11:04 AM, Travis Griggs wrote: > Being a fan of JIT, I have big hopes for PyPy, I can’t figure out why they > aren’t pitching their “cutting edge” interpreter, for the “cutting edge” > version of python. There should be a wall of superpowers/shame for > interpreters. A ve

Re: [newbie] Saving binaries in a specific way

2013-12-16 Thread Chris Kaynor
On Mon, Dec 16, 2013 at 2:19 PM, Djoser wrote: > Hi all, > > I am new to this forum and also to Python, but I'm trying hard to > understand it better. > I need to create a binary file, but the first 4 lines must be in > signed-Integer16 and all the others in signed-Integer32. I have a program >

Re: '_[1]' in .co_names using builtin compile() in Python 2.6

2013-11-27 Thread Chris Kaynor
On Wed, Nov 27, 2013 at 12:09 PM, Ned Batchelder wrote: > * Is there perhaps a better way to achieve what I'm trying to do? >> >> What I'm really after, is to check that python expressions embedded in >> text files are: >> - well behaved (no syntax errors etc) >> - don't accidentally access anythi

  1   2   3   >