Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 7:02 AM, Grant Edwards wrote: > On 2015-02-12, Ian Kelly wrote: >> On Thu, Feb 12, 2015 at 1:23 PM, Hrvoje Nikšić wrote: >> >>> {:.15g} is supposed to give 15 digits of precision, but with trailing >>> zeros removed. >> >> The

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 1:33 PM, Grant Edwards wrote: > On 2015-02-13, Ian Kelly wrote: >> On Fri, Feb 13, 2015 at 7:02 AM, Grant Edwards >> wrote: >>> On 2015-02-12, Ian Kelly wrote: >>>> On Thu, Feb 12, 2015 at 1:23 PM, Hrvoje Nikšić wrote: >>>

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 2:22 PM, Grant Edwards wrote: > On 2015-02-13, Dave Angel wrote: >> On the other hand, the Decimal package has a way that the programmer >> can tell how many digits to use at each stage of the calculation. > > That's what surpised me. From TFM: > > https://docs.python.org

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 2:40 PM, Ian Kelly wrote: > On Fri, Feb 13, 2015 at 2:22 PM, Grant Edwards > wrote: >> On 2015-02-13, Dave Angel wrote: >>> On the other hand, the Decimal package has a way that the programmer >>> can tell how many digits to use at

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 4:05 PM, Mark Lawrence wrote: > I still think it's a bug as the 'p' being referred to in the OP's original > message is "The precision is a decimal number indicating how many digits > should be displayed after the decimal point for a floating point value > formatted with 'f

Re: ctypes.cdll.LoadLibrary() freezes when loading a .so that contains dlopen()

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 8:39 AM, Russell wrote: > I have a shared library, libfoo.so, that references another .so which isn't > linked but instead loaded at runtime with > myso=dlopen("/usr/local/lib/libbar.so", RTLD_NOW); when I try to load it with > ctypes, the call hangs and I have to ctl-c.

Re: Floating point "g" format not stripping trailing zeros

2015-02-14 Thread Ian Kelly
On Fri, Feb 13, 2015 at 6:22 PM, Mark Lawrence wrote: > On 14/02/2015 00:11, Ian Kelly wrote: >> >> On Fri, Feb 13, 2015 at 4:05 PM, Mark Lawrence >> wrote: >>> >>> I still think it's a bug as the 'p' being referred to in the OP's >

Re: Python implementations in JavaScript

2015-02-14 Thread Ian Kelly
On Fri, Feb 13, 2015 at 4:05 PM, Jonathan Hayward wrote: > > What is the relative maturity of different Python implementations in > JavaScript? Are any of the implementations ready to rely on? Brython is about two years old now. Skulpt has been around for at least four years. I don't use either

Re: Flagging classes as not intended for direct initialization

2015-02-16 Thread Ian Kelly
On Mon, Feb 16, 2015 at 3:55 AM, Mario Figueiredo wrote: > In article <54e14cfe$0$12997$c3e8da3$54964...@news.astraweb.com>, > steve+comp.lang.pyt...@pearwood.info says... >> Unless you have good reason not to, you should use super rather than >> directly call the superclass. >> >> https://rhettin

Re: Assigning a function to sys.excepthook doesn't work in WSGI

2015-02-18 Thread Ian Kelly
On Wed, Feb 18, 2015 at 8:08 AM, wrote: > I want to generate an html page with http response status '200 OK' in case of > an uncaught exception in my wsgi application, instead of web server's > standard '500 Internal Server Error' response for such case. To do so, I've > made the following sam

Re: What the Pythons docs means by "container" ?

2015-02-18 Thread Ian Kelly
On Wed, Feb 18, 2015 at 11:04 AM, MRAB wrote: > On 2015-02-18 02:14, candide wrote: >> >> Le mercredi 18 février 2015 01:50:16 UTC+1, Chris Angelico a écrit : >> >>> So, what's a container? It's a thing that you put other objects >>> into. >> >> >> I agree with this approach. The important point t

Re: Logging with Custom Levels not working

2015-02-18 Thread Ian Kelly
On Wed, Feb 18, 2015 at 6:49 AM, Didymus wrote: > def perror(self, message, *args, **kws): > """ Performance Error Message Level """ > # Yes, logger takes its '*args' as 'args'. > self._log(PERROR_NUM, message, args, **kws) > > logging.Logger.perror = perror I think you need to call s

Re: python implementation of a new integer encoding algorithm.

2015-02-19 Thread Ian Kelly
On Thu, Feb 19, 2015 at 8:45 AM, wrote: > On Wednesday, February 18, 2015 at 11:20:12 PM UTC+1, Dave Angel wrote: >> I'm not necessarily doubting it, just challenging you to provide a data >> sample that actually shows it. And of course, I'm not claiming that >> 7bit is in any way optimal. You

Re: python implementation of a new integer encoding algorithm.

2015-02-19 Thread Ian Kelly
On Thu, Feb 19, 2015 at 11:04 AM, Ian Kelly wrote: > There's also an optimization that can be added here if we wish to > inject a bit of cleverness. Notice that all values with more than one > group start with 11, never 10. We can borrow a trick from IEEE > floating point and m

Re: python implementation of a new integer encoding algorithm.

2015-02-19 Thread Ian Kelly
On Thu, Feb 19, 2015 at 11:24 AM, Dave Angel wrote: > Here's a couple of ranges of output, showing that the 7bit scheme does > better for values between 384 and 16379. > > 382 2 80fe --- 2 7e82 > 383 2 80ff --- 2 7f82 > 384 3 81 --- 2 0083 > 384 jan grew 3 81 > 385 3 810001 --- 2 0183 > 3

Re: Logging with Custom Levels not working

2015-02-20 Thread Ian Kelly
On Thu, Feb 19, 2015 at 11:16 AM, Didymus wrote: > On Wednesday, February 18, 2015 at 3:16:40 PM UTC-5, Ian wrote: >> > def perror(self, message, *args, **kws): >> > """ Performance Error Message Level """ >> > # Yes, logger takes its '*args' as 'args'. >> > self._log(PERROR_NUM, messa

Re: Python path on windows

2015-02-20 Thread Ian Kelly
On Feb 20, 2015 7:46 AM, "loial" wrote: > > On Linux we use > #!/usr/bin/env python > > At the start of scripts to ensure that the python executable used is the one defined in the PATH variable, rather than hardcoding a path to the python executable. > > What is the equivalent functionality in Win

Re: Python path on windows

2015-02-20 Thread Ian Kelly
On Fri, Feb 20, 2015 at 8:16 AM, loial wrote: > On Friday, February 20, 2015 at 2:54:26 PM UTC, Ian wrote: >> On Feb 20, 2015 7:46 AM, "loial" wrote: >> >> > >> >> > On Linux we use >> >> > #!/usr/bin/env python >> >> > >> >> > At the start of scripts to ensure that the python executable used is

Re: What the Pythons docs means by "container" ?

2015-02-20 Thread Ian Kelly
On Fri, Feb 20, 2015 at 4:37 AM, Rustom Mody wrote: > See https://www.python.org/dev/peps/pep-0246/ > > There Guido says "something much better is about to happen" > > Best as I know its not happened yet... Well, since that PEP was rejected we now have ABCs. Although PEP 3119 wasn't written until

Re: try pattern for database connection with the close method

2015-02-21 Thread Ian Kelly
On Sat, Feb 21, 2015 at 5:22 AM, Mark Lawrence wrote: > On 21/02/2015 02:42, Mario Figueiredo wrote: >> >> Hello all, >> >> I'm using the following pattern for db access that requires me to >> close the connection as soon as it is not needed: >> >> import sqlite3 as lite >> >> t

Re: try pattern for database connection with the close method

2015-02-21 Thread Ian Kelly
On Sat, Feb 21, 2015 at 8:27 AM, Peter Otten <__pete...@web.de> wrote: > Ian Kelly wrote: > >> On Sat, Feb 21, 2015 at 5:22 AM, Mark Lawrence >> wrote: >>> try: >>> with lite.connect('data.db') as db: >>> try: >>

Re: Design thought for callbacks

2015-02-21 Thread Ian Kelly
On Sat, Feb 21, 2015 at 1:57 PM, Grant Edwards wrote: > On 2015-02-21, Cem Karan wrote: >> >> On Feb 21, 2015, at 12:42 AM, Chris Angelico wrote: >> >>> On Sat, Feb 21, 2015 at 1:44 PM, Cem Karan wrote: In order to inform users that certain bits of state have changed, I require them

Re: Design thought for callbacks

2015-02-22 Thread Ian Kelly
On Sun, Feb 22, 2015 at 7:22 AM, Cem Karan wrote: > > On Feb 22, 2015, at 5:15 AM, Gregory Ewing > wrote: > >> Frank Millman wrote: >>> "In order to inform users that certain bits of state have changed, I >>> require them to register a callback with my code." >>> This sounds to me like a pub/su

Re: Best practice: Sharing object between different objects

2015-02-23 Thread Ian Kelly
On Mon, Feb 23, 2015 at 1:02 PM, wrote: > What's REALLY interesting is that this happens: > import myModule myModule.myInt > 1 myModule.myInt = 2 myModule.myInt > 2 del myModule import myModule myModule.myInt > 2 > > I would REALLY expect that deleting the modul

Re: new.py and having '.' in PYTHONPATH

2015-02-23 Thread Ian Kelly
On Mon, Feb 23, 2015 at 3:14 PM, Ethan Furman wrote: > On 02/23/2015 01:00 PM, Tobiah wrote: > >> Anyway, it raises the question as to whether having '.' in the >> PYTHONPATH is at all a sane thing to do. > > The current directory is added to sys.path /only/ for the interactive > interpreter. Wh

Re: Bug in timsort!?

2015-02-24 Thread Ian Kelly
On Tue, Feb 24, 2015 at 3:45 PM, Grant Edwards wrote: > On 2015-02-24, Roy Smith wrote: > >> http://envisage-project.eu/proving-android-java-and-python-sorting-algorithm-is-broken-and-how-to-fix-it/ > > I don't get it. > > 3.2 Corrected Python merge_collapse function > > merge_collapse(Me

Re: strip bug?

2015-02-24 Thread Ian Kelly
On Tue, Feb 24, 2015 at 4:05 PM, wrote: 'http://xthunder'.strip('http://') > 'xthunder' 'http://thunder'.strip('http://') > 'under' This removes all leading and trailing occurrences of the characters in the string 'http://', not the exact substring 'http://'. For that, use either

Re: Are threads bad? - was: Future of Pypy?

2015-02-24 Thread Ian Kelly
On Tue, Feb 24, 2015 at 10:54 PM, Chris Angelico wrote: > On Wed, Feb 25, 2015 at 4:46 PM, Marko Rauhamaa wrote: >> Marcos Almeida Azevedo : >> >>> Synchronized methods in Java really makes programming life simpler. >>> But I think it is standard practice to avoid this if there is a >>> lighter a

Re: Running Idle on Windows 8 (.1)

2015-02-25 Thread Ian Kelly
On Tue, Feb 24, 2015 at 6:29 PM, Terry Reedy wrote: > On 2/24/2015 3:13 PM, blakemal...@gmail.com wrote: > >> I too can not get idle to run on win 8.1 using python3.4.2 installed from >> the python-3.4.2.amd64.msi. > > > What experience have others had with Idle and Windows 8? > > The OP for > htt

Re: Are threads bad? - was: Future of Pypy?

2015-02-25 Thread Ian Kelly
On Wed, Feb 25, 2015 at 9:37 AM, Mark Lawrence wrote: > On 25/02/2015 06:02, Ian Kelly wrote: >> >> >> Is the name of that database program "Microsoft Access" perchance? >> > > Are you referring to the GUI, the underlying database engine, both,

Re: Bug in timsort!?

2015-02-25 Thread Ian Kelly
On Wed, Feb 25, 2015 at 10:21 AM, Peter Otten <__pete...@web.de> wrote: > Mark Lawrence wrote: > >> Reading the bug report http://bugs.python.org/issue23515, specifically >> msg236586, it looks as if the proposed fix was wrong and one of the >> smarter members of the python community fixed it. > >

Re: Python Worst Practices

2015-02-25 Thread Ian Kelly
On Wed, Feb 25, 2015 at 1:45 PM, Mark Lawrence wrote: > http://www.slideshare.net/pydanny/python-worst-practices > > Any that should be added to this list? Any that be removed as not that bad? Using XML for configuration is a good example of a worst practice, but using Python instead isn't best

Re: Bug in timsort!?

2015-02-25 Thread Ian Kelly
On Wed, Feb 25, 2015 at 4:13 PM, Steven D'Aprano wrote: > TimSort is an algorithm, and it is not broken. The algorithm is correct. The algorithm asserted an invariant but failed to actually establish it. That sounds broken to me. -- https://mail.python.org/mailman/listinfo/python-list

Re: Wait... WHAT?

2014-02-12 Thread Ian Kelly
On Wed, Feb 12, 2014 at 12:43 PM, wrote: > http://postimg.org/image/rkm9lhj8n/ > > So, I was doing some cx freeze stuff. If you cant understand everything from > the pic, I'll give extra info. Please help me. It would be preferable if you would please copy and paste the exception along with the

Re: Working with the set of real numbers

2014-02-12 Thread Ian Kelly
On Wed, Feb 12, 2014 at 7:11 AM, Rustom Mody wrote: > On Wednesday, February 12, 2014 3:37:04 PM UTC+5:30, Ben Finney wrote: >> Chris Angelico writes: > >> > On Wed, Feb 12, 2014 at 7:56 PM, Ben Finney wrote: >> > > So, if I understand you right, you want to say that you've not found >> > > a com

Re: Wait... WHAT?

2014-02-12 Thread Ian Kelly
On Wed, Feb 12, 2014 at 1:21 PM, wrote: > I think of it as a bit strange. Should I report it as a bug? I was trying to > incorporate a save/load, and this happened. > def save(): > target = open ("save.swroc", 'w') > target.write([counter, loop, number_of_competitors, competi

Re: Wait... WHAT?

2014-02-12 Thread Ian Kelly
On Wed, Feb 12, 2014 at 3:14 PM, Tim Chase wrote: > On 2014-02-12 14:35, Ian Kelly wrote: >> You can't write lists directly to files. You can only write strings >> to files. To write and read a list, you'll need to first serialize >> it and later deserialize it. &

Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!)

2014-02-13 Thread Ian Kelly
On Feb 12, 2014 9:16 PM, "Steven D'Aprano" wrote: > > On Tue, 11 Feb 2014 07:36:34 -0800, Travis Griggs wrote: > > > On Feb 10, 2014, at 10:30 PM, Steven D'Aprano > > wrote: > > > > > >>>1. Parenthesis should not be required for parameter- less > >>>functions. > >> > >> Of course they sho

Re: Explanation of list reference

2014-02-14 Thread Ian Kelly
On Fri, Feb 14, 2014 at 11:54 AM, dave em wrote: > Thanks for your quick response. I'm still not sure we understand. The code > below illustrates the concept we are trying to understand. > > Case 1: Example of variable with a specific value from P 170 of IYOCGWP > spam = 42 cheese = s

Re: Explanation of list reference

2014-02-14 Thread Ian Kelly
On Fri, Feb 14, 2014 at 12:56 PM, Marko Rauhamaa wrote: > There are two fundamentally different kinds of values in Python: "small" > values and "big" values. A variable can only hold a small value. A list > element can only hold a small value. A dictionary entry can only hold a > small value. The

Re: Generator using item[n-1] + item[n] memory

2014-02-14 Thread Ian Kelly
On Fri, Feb 14, 2014 at 3:27 PM, Nick Timkovich wrote: > I have a Python 3.x program that processes several large text files that > contain sizeable arrays of data that can occasionally brush up against the > memory limit of my puny workstation. From some basic memory profiling, it > seems like w

Re: Explanation of list reference

2014-02-14 Thread Ian Kelly
On Fri, Feb 14, 2014 at 9:24 PM, Rustom Mody wrote: > In the case of physical objects like dice there is a fairly > unquestionable framing that makes identity straightforward -- > 4-dimensional space-time coordiantes. If the space-time coordinates of > 2 objects are all equal then the objects are

Re: Generator using item[n-1] + item[n] memory

2014-02-14 Thread Ian Kelly
On Fri, Feb 14, 2014 at 8:31 PM, Nick Timkovich wrote: > OK, now the trick; adding `data = None` inside the generator works, but in > my actual code I wrap my generator inside of `enumerate()`, which seems to > obviate the "fix". Can I get it to play nice or am I forced to count > manually. Is th

Re: Explanation of list reference

2014-02-15 Thread Ian Kelly
On Fri, Feb 14, 2014 at 11:07 PM, Rustom Mody wrote: > On Saturday, February 15, 2014 10:50:35 AM UTC+5:30, Ian wrote: >> This is false. It happens to hold for CPython, but that's an >> implementation detail. The definition of object identity does not >> depend on memory address. It also doesn'

Re: Explanation of list reference

2014-02-15 Thread Ian Kelly
On Sat, Feb 15, 2014 at 9:29 AM, Marko Rauhamaa wrote: > Steven D'Aprano : >> On Sat, 15 Feb 2014 14:07:35 +0200, Marko Rauhamaa wrote: >>> Steven D'Aprano : On Sat, 15 Feb 2014 12:13:54 +0200, Marko Rauhamaa wrote: >5. id(x) == id(y) iff x is y # Counter-example py> x

Re: decimal numbers

2014-02-15 Thread Ian Kelly
On Sat, Feb 15, 2014 at 2:18 AM, wrote: > hello, > i have been working on a python resistor calculator to let my class show what > you can do with python. > now i have a script that makes the more speekable value of the resistance > (res) > > #if len(str(res)) > 9: > # res2 = res / 10

Re: decimal numbers

2014-02-15 Thread Ian Kelly
On Sat, Feb 15, 2014 at 10:17 AM, Luke Geelen wrote: > If i do set form thing in my script i get > Invalide syntax pointing at the last word of the form rule Please copy and paste the exact code you ran along with the full text of the exception into your post. Paraphrasing it like this doesn't h

Re: Explanation of list reference

2014-02-15 Thread Ian Kelly
On Sat, Feb 15, 2014 at 10:30 AM, Rustom Mody wrote: > Thanks! -- Nice to hear slightly more philosophically astute attempt than > the naivete going around: "Object?! We all know whats an object! > Everyone knows whats an object!!" > > However I am betting that the problem remains. Youve transfere

Re: Explanation of list reference

2014-02-15 Thread Ian Kelly
On Sat, Feb 15, 2014 at 11:37 AM, Ian Kelly wrote: > But what is a set? Cantor offers this definition: > > """ > A set is a gathering together into a whole of definite, distinct > objects of our perception [Anschauung] or of our thought - which are > called e

Re: Explanation of list reference

2014-02-15 Thread Ian Kelly
On Sat, Feb 15, 2014 at 1:20 PM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Sat, Feb 15, 2014 at 9:29 AM, Marko Rauhamaa wrote: >>> Thus "x and y are identical" *means* "x is y" and nothing else. >> >> This notion of identity sounds useless,

Re: decimal numbers

2014-02-15 Thread Ian Kelly
On Sat, Feb 15, 2014 at 11:57 AM, Luke Geelen wrote: > hey, is it possible to remove the .0 if it is a valua without something > behind the poit (like 5.0 gets 5 but 9.9 stays 9.9 The ':g' format specifier will trim off trailing zeroes, e.g.: >>> '{:g}'.format(5.0) '5' It also switches to expo

Re: Explanation of list reference

2014-02-16 Thread Ian Kelly
On Feb 16, 2014 1:11 AM, "Marko Rauhamaa" wrote: > > Marko Rauhamaa : > > > Conceptually, the "everything is a reference" and the "small"/"big" > > distinction are equivalent (produce the same outcomes). The question > > is, which model is easier for a beginner to grasp. > > Case in point, if ever

Re: Explanation of list reference

2014-02-16 Thread Ian Kelly
On Sun, Feb 16, 2014 at 1:28 AM, Ian Kelly wrote: > > On Feb 16, 2014 1:11 AM, "Marko Rauhamaa" wrote: >> Case in point, if everything is a reference, how come: >> >>>>> "hello".__str__() >>'hello' >>>&g

Re: Deepcopying a byte string is quicker than copying it - problem?

2014-02-27 Thread Ian Kelly
On Wed, Feb 26, 2014 at 11:30 PM, Frank Millman wrote: > Hi all > > I noticed this a little while ago, but dismissed it as a curiosity. On > reflection, I decided to mention it here in case it indicates a problem. > > This is with python 3.3.2. > > C:\>python -m timeit -s "import copy" "copy.copy(

Re: Tuples and immutability

2014-02-27 Thread Ian Kelly
On Thu, Feb 27, 2014 at 2:47 PM, Nick Timkovich wrote: > On Thu, Feb 27, 2014 at 10:33 AM, Chris Angelico wrote: >> >> On Fri, Feb 28, 2014 at 3:27 AM, Eric Jacoboni >> wrote: >> > But, imho, it's far from being a intuitive result, to say the least. >> >> It's unintuitive, but it's a consequence

Re: Tuples and immutability

2014-02-28 Thread Ian Kelly
On Fri, Feb 28, 2014 at 5:22 PM, Mark H. Harris wrote: > I really think this is a bug; honestly. IMHO it should be an error to use > += with an immutable type and that means not at all. In other words, the > list should not even be considered, because we're talking about changing a > tuple

Re: Tuples and immutability

2014-02-28 Thread Ian Kelly
On Fri, Feb 28, 2014 at 6:27 PM, Eric Jacoboni wrote: > Anyway, the TypeError should rollback, not commit the mistake. The Python interpreter isn't a database. It can't rollback the object because the operation that was performed may not be reversible. Consider for example a socket class where t

Re: Tuples and immutability

2014-02-28 Thread Ian Kelly
On Fri, Feb 28, 2014 at 9:45 PM, Mark H. Harris wrote: > I really believe IMHO that the error should have come when you made the list > an item of a tuple. An immutable object should have NO REASON to contain a > mutable object like list... I mean the whole point is to eliminate the > overhea

Re: Tuples and immutability

2014-03-01 Thread Ian Kelly
On Fri, Feb 28, 2014 at 11:25 PM, Mark H. Harris wrote: > On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote: > >> How would you propose doing that? Bear in mind that while Python >> knows that tuples specifically are immutable, it doesn't generally >> know whether a type is immutable. > >

Re: Tuples and immutability

2014-03-02 Thread Ian Kelly
On Sat, Mar 1, 2014 at 7:04 PM, Eric Jacoboni wrote: > In fact, i think i'm gonna forget += on lists :) Well, do what you want, but I think you're taking the wrong lesson from this. Don't forget about using += on lists. Instead, forget about using assignments, augmented or otherwise, on tuple e

Re: how to get bytes from bytearray without copying

2014-03-02 Thread Ian Kelly
On Sun, Mar 2, 2014 at 5:44 PM, Cameron Simpson wrote: > Have you considered subclassing memoryview and giving the subclass > a __hash__ method? >>> class MyMemoryView(memoryview): ... def __hash__(self): return 42 ... Traceback (most recent call last): File "", line 1, in TypeError: type

Re: how to get bytes from bytearray without copying

2014-03-02 Thread Ian Kelly
On Sun, Mar 2, 2014 at 5:07 PM, Juraj Ivančić wrote: > Is it possible to somehow 'steal' bytearray's buffer and make it a read-only > bytes? I failed to find a way to do this, and would like to make sure. > > My use case is, I would expect, fairly common. I read a certain (potentially > very large

Re: Password validation security issue

2014-03-02 Thread Ian Kelly
On Sun, Mar 2, 2014 at 4:10 PM, Renato wrote: > I would like to thank every one who posted a reply. I learnt a lot from you, > guys! I appreciate your attention and your help :) > > I took a class on Computer Simulation last year. It was told that > deterministic (pseudo-)random numbers are exce

Re: Password validation security issue

2014-03-02 Thread Ian Kelly
On Sun, Mar 2, 2014 at 6:16 PM, Steven D'Aprano wrote: > People have managed physical keys for *centuries*. Yes, there are a class > of threats where you lose your key, or someone steals it, or makes a > copy, but the risks are well-understood and can be managed even by your > grandmother. We have

Re: Password validation security issue

2014-03-02 Thread Ian Kelly
On Sun, Mar 2, 2014 at 10:44 PM, Chris Angelico wrote: > Of course, the whole concept depends on being able to use long > memorable passwords. Any system that sets a maximum password length of > anything less than about 30-40 characters is causing its users > problems. There's almost never any rea

Re: Origin of 'self'

2014-03-02 Thread Ian Kelly
On Sun, Mar 2, 2014 at 11:16 PM, Westley Martínez wrote: > I understand that in an object method the first argument in the object > itself, called self. However, it doesn't have to be called self, and can be > called anything. So my question is why is it called self and not this like > from C

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

2014-03-04 Thread Ian Kelly
On Mon, Mar 3, 2014 at 11:35 PM, Chris Angelico wrote: > In constant space, that will produce the sum of two infinite sequences > of digits. (And it's constant time, too, except when it gets a stream > of nines. Adding three thirds together will produce an infinite loop > as it waits to see if the

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

2014-03-04 Thread Ian Kelly
On Tue, Mar 4, 2014 at 4:19 AM, Ian Kelly wrote: > def cf_sqrt(n): > """Yield the terms of the square root of n as a continued fraction.""" >m = 0 > d = 1 > a = a0 = floor_sqrt(n) > while True: > yield a >

Re: How to create an instance of a python class from C++

2014-03-04 Thread Ian Kelly
On Tue, Mar 4, 2014 at 5:14 PM, Bill wrote: > Hello: > > I can't figure out how to create an instance > of a python class from 'C++': > > ( I am relatively new to Python so excuse some of > the following. ) > > In a .py file I create an ABC and then specialize it: Why are you creating an ABC?

Re: Reference

2014-03-04 Thread Ian Kelly
On Tue, Mar 4, 2014 at 8:36 PM, Rustom Mody wrote: > * ... which summarizes my objection in this thread: Python's 'is' leaks the > machine abstraction. 'id' does it legitimately (somewhat), > 'is' does it illegitimately Well, since "if x == None" is buggy as a test for sentinel values, that means

Re: Tuples and immutability

2014-03-07 Thread Ian Kelly
On Fri, Mar 7, 2014 at 4:51 AM, Alister wrote: > I would think it would be better if the exception was thrown before the > assignment to the list took place > simply seeing that a modification action was being applied to a tupple > should be enough. > this would alert the programmer to the fact th

Re: Is their a command to view code?

2014-03-07 Thread Ian Kelly
On Fri, Mar 7, 2014 at 10:55 AM, NexusRAwesome1995 . wrote: > I am making a text based aventure game for my assignment and a friends test > run has somehow saved over the entire code file and now im using an earlier > version of the code. I have 0 idea if there is anyway to look at the code > usin

Re: Tuples and immutability

2014-03-07 Thread Ian Kelly
On Fri, Mar 7, 2014 at 7:17 PM, Gregory Ewing wrote: > Here's another idea: If the __iadd__ method returns the > same object, *and* the LHS doesn't have a __setitem__ > method, then do nothing instead of raising an exception. Maybe it doesn't have a __setitem__ because the object that was retriev

Re: Balanced trees (was: Re: Tuples and immutability)

2014-03-08 Thread Ian Kelly
On Sat, Mar 8, 2014 at 1:34 AM, Marko Rauhamaa wrote: > Speaking of which, are there plans to add a balanced tree to the > "batteries" of Python? Timers, cache aging and the like need it. I'm > using my own AVL tree implementation, but I'm wondering why Python > still doesn't have one. None curre

Re: Tuples and immutability

2014-03-08 Thread Ian Kelly
On Sat, Mar 8, 2014 at 5:40 PM, Gregory Ewing wrote: > Ian Kelly wrote: >> >> class LessThanFilter: >> >> def __init__(self, the_list): >> self._the_list = the_list >> >> def __getitem__(self, bound): >> return [x fo

Re: Tuples and immutability

2014-03-08 Thread Ian Kelly
On Sat, Mar 8, 2014 at 5:45 PM, Gregory Ewing wrote: > Ian Kelly wrote: > >> I already mentioned this earlier in the thread, but a balanced binary >> tree might implement += as node insertion and then return a different >> object if the balancing causes the root node to

Re: Tuples and immutability

2014-03-09 Thread Ian Kelly
On Sun, Mar 9, 2014 at 4:03 PM, Gregory Ewing wrote: > Ian Kelly wrote: >> >> In my view the second one is wrong. a += b should be understood as >> being equivalent to a = a + b, but with the *possible* and by no means >> guaranteed optimization that the operatio

Re: Balanced trees

2014-03-09 Thread Ian Kelly
On Sun, Mar 9, 2014 at 4:08 PM, Dan Stromberg wrote: > On Sun, Mar 9, 2014 at 2:43 PM, Marko Rauhamaa wrote: >> Dan Stromberg : >> >>> On Sun, Mar 9, 2014 at 2:32 PM, Marko Rauhamaa wrote: There is no O(1) hash table. >>> >>> http://stackoverflow.com/questions/2771368/can-hash-tables-really

Re: golang OO removal, benefits. over python?

2014-03-10 Thread Ian Kelly
On Sun, Mar 9, 2014 at 10:49 PM, flebber wrote: > I was wondering if a better programmer than I could explain if the removal of > OO features in golang really does offer an great benefit over python. > > An article I was reading ran through a brief overview of golang in respect of > OO features

Re: Tuples and immutability

2014-03-10 Thread Ian Kelly
On Sun, Mar 9, 2014 at 8:37 PM, Steven D'Aprano wrote: > On Sun, 09 Mar 2014 17:42:42 -0600, Ian Kelly wrote: > >> On Sun, Mar 9, 2014 at 4:03 PM, Gregory Ewing >> wrote: > >>> Note that it says "when possible", not "if the implementation fee

Re: Closure/method definition question for Python 2.7

2014-03-10 Thread Ian Kelly
On Mon, Mar 10, 2014 at 11:27 AM, Brunick, Gerard:(Constellation) wrote: > The following code: > > --- > class Test(object): > x = 10 > > def __init__(self): > self.y = x > > t = Test() > --- > > raises > > NameError: global name 'x' is not defined. > > in Python 2.7. I don't unde

Re: Balanced trees

2014-03-10 Thread Ian Kelly
On Mon, Mar 10, 2014 at 7:45 PM, Chris Angelico wrote: > On Tue, Mar 11, 2014 at 12:26 PM, Steven D'Aprano > wrote: >> In my experience, the average developer has an amazing talent for >> pessimising code when they think they are optimising it. > > I remember a number of incidents from personal e

Re: Tuples and immutability

2014-03-11 Thread Ian Kelly
On Mon, Mar 10, 2014 at 11:03 PM, Gregory Ewing wrote: > As far as observable effects are concerned, it's > quite clear: mutable objects can *always* be updated > in-place, and immutable objects can *never* be. Hm. Consider the circle-ellipse problem. Briefly, a circle is-an ellipse, so in an in

Re: which async framework?

2014-03-11 Thread Ian Kelly
On Tue, Mar 11, 2014 at 4:58 AM, Marko Rauhamaa wrote: > Sturla Molden : > >> I'd go for using iocp, epoll and kqueue/kevent directly. Why bother to >> learn a framework? You will find epoll and kqueue/kevent in the select >> module and iocp in pywin32. > > You beat me to it. > > However, I'm hopi

Re: golang OO removal, benefits. over python?

2014-03-11 Thread Ian Kelly
On Mon, Mar 10, 2014 at 2:38 AM, Marko Rauhamaa wrote: >> On the whole though I think that the language is not yet mature enough >> to be able to seriously compete with more established languages like >> Python or Java. > > Also, is there anything seriously lacking in Python, Java and C? > > I was

Re: Tuples and immutability

2014-03-11 Thread Ian Kelly
On Tue, Mar 11, 2014 at 10:46 AM, Steven D'Aprano wrote: >> There are a number of possible solutions. One possibility would be to >> copy the Circle as an Ellipse and return the new object instead of >> mutating it. Then you have the situation where, given a mutable object >> x that satisfies isi

Re: Tuples and immutability

2014-03-12 Thread Ian Kelly
On Wed, Mar 12, 2014 at 12:28 AM, Steven D'Aprano wrote: > On Tue, 11 Mar 2014 23:25:19 -0400, Terry Reedy wrote: >> Nope, 'similar' is not 'equivalent'. Evaluating x twice instead of once >> and possibly allocating a new object versus not take extra time. In a >> statement like "x.y.z[3*n+m] += 1

Re: Tuples and immutability

2014-03-12 Thread Ian Kelly
On Wed, Mar 12, 2014 at 3:39 AM, Antoon Pardon wrote: > The documentation is wrong at that point as the following code illustrates. Either way it still has to do a getitem and a setitem, but if you have a more nested structure then the extra getitems are not repeated. For example, using your log

Re: which async framework?

2014-03-12 Thread Ian Kelly
On Tue, Mar 11, 2014 at 5:38 PM, Chris Angelico wrote: > On Wed, Mar 12, 2014 at 10:18 AM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> What corner cases are there with threads that you don't have with >>> anything else? >> >> There are numerous. Here's one example: deadlocks due to two threa

Re: What does gc.get_objects() return?

2014-03-12 Thread Ian Kelly
On Wed, Mar 12, 2014 at 3:44 PM, Chris Angelico wrote: > The concept is that the GC tracks (in that sense; everything in > CPython is refcounted, but that's not what these functions look at) > anything that could be a part of a reference cycle. That's all it > concerns itself with, so something th

Re: What does gc.get_objects() return?

2014-03-12 Thread Ian Kelly
On Wed, Mar 12, 2014 at 4:35 PM, Ian Kelly wrote: >> So not all optimizations are done that could be done. > > Or is it? > >>>> a = 1,2,3 >>>> gc.is_tracked(a) > True >>>> gc.collect() > 0 >>>> gc.is_tracked(a) > False I gu

Re: DB API question - where is a stored procedure's return value?

2014-03-12 Thread Ian Kelly
On Wed, Mar 12, 2014 at 3:44 PM, Skip Montanaro wrote: > What do other database adaptors do about stored procedure return > values? Does PEP 249 need revision? I can't speak generally, but in cx_Oracle you either execute a query like this: result = cursor.var(cx_Oracle.NUMBER) cursor.exe

Re: DB API question - where is a stored procedure's return value?

2014-03-12 Thread Ian Kelly
On Wed, Mar 12, 2014 at 5:00 PM, Ian Kelly wrote: > result = cursor.var(cx_Oracle.NUMBER) > cursor.execute(":1 := test_proc()", [result]) > print(result.getvalue()) Sorry, that should properly be: result = cursor.var(cx_Oracle.NUMBER) cursor.execute(&qu

Re: Tuples and immutability

2014-03-12 Thread Ian Kelly
On Wed, Mar 12, 2014 at 5:20 PM, Steven D'Aprano wrote: > On Tue, 11 Mar 2014 17:06:43 -0600, Ian Kelly wrote: > >> That's true but irrelevant to my point, which was to counter the >> assertion that mutable types can always be assumed to be able to perform >>

Re: Balanced trees

2014-03-13 Thread Ian Kelly
On Mon, Mar 10, 2014 at 11:34 AM, Marko Rauhamaa wrote: > The main thing is there are use cases where order is essential. That's > why I have had to implement the AVL tree in Python myself. No biggie, > but a C implementation would probably be much faster. Also, a standard > version would likely b

Re: Deep vs. shallow copy?

2014-03-13 Thread Ian Kelly
On Thu, Mar 13, 2014 at 5:55 PM, Chris Angelico wrote: > I'm going to troll for a moment and give you a function that has no > return value. > > def procedure(): > raise Exception >>> import dis >>> dis.dis(procedure) 2 0 LOAD_GLOBAL 0 (Exception) 3 RAIS

Re: pickle.dump (obj, conn)

2014-03-13 Thread Ian Kelly
On Thu, Mar 13, 2014 at 4:36 PM, Pedro Izecksohn wrote: > Shouldn't pickle.dump (obj, conn) raise an Exception if conn is a TCP > connection that was closed by the remote host? Can you be more specific about what you are doing, what you expect the result to be, and what the actual result is? h

Re: Thread._stop() behavior changed in Python 3.4

2014-03-17 Thread Ian Kelly
On Mon, Mar 17, 2014 at 11:40 AM, Chris Angelico wrote: > Antoine says that this doesn't even stop the thread > (I can't say; I've never used _stop(), for obvious reasons), so this > code was doubly broken. I was curious about that -- after all, Python's threads aren't truly concurrent, so perhap

Re: 'complex' function with string argument.

2014-03-17 Thread Ian Kelly
On Mon, Mar 17, 2014 at 12:15 PM, Marko Rauhamaa wrote: > Is "-2.0" a literal? > > What's the outcome of > >-2.0.__str__() No. The compiler will try to optimize it into a single constant if it can, but it has to be done in accordance with the order of operations. In that example, the __str_

Re: Thread._stop() behavior changed in Python 3.4

2014-03-17 Thread Ian Kelly
On Mar 17, 2014 12:53 PM, "Jurko Gospodnetić" wrote: > > Hi. > > > On 17.3.2014. 19:03, Ian Kelly wrote: >> >> So yes, despite the lack of true concurrency, a thread can continue to >> run after its _stop has been called. > > > Actuall

<    16   17   18   19   20   21   22   23   24   25   >