Re: Functional programming

2014-03-04 Thread Steven D'Aprano
On Tue, 04 Mar 2014 17:04:55 +1100, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 4:35 PM, Steven D'Aprano > wrote: >> On Tue, 04 Mar 2014 05:37:27 +1100, Chris Angelico wrote: >>> x = 23 # Compiler goes: Okay, x takes ints. x += 5 # Compiler: No >>> prob, int += int --> int x = str(x) # Compile

Decoding a process output

2014-03-04 Thread Francis Moreau
Hi, In my understanding (I'm relatively new to python), I need to decode any bytes data provided, in my case, by a shell command (such as findmnt) started by the subprocess module. The goal of my application is to parse the command outputs. My application runs only on linux BTW and should run fin

Re: Functional programming

2014-03-04 Thread BartC
"Steven D'Aprano" wrote in message news:5314bb96$0$29985$c3e8da3$54964...@news.astraweb.com... Think about the sort of type declarations you have to do in (say) Pascal, and consider how stupid the compiler must be: function add_one(x: integer):integer; begin add_one := x+1; end; Given th

Python 2.7 documentation with readthedocs theme

2014-03-04 Thread Charles Gunawan
Hi, I was just looking into some documentation on readthedocs and I saw that they have a cool new theme. I was wondering how the python documentation will look like with that theme. So after some tinkering I have build python 2.7 CHM documentation with the theme. If you are wondering too you c

Logging

2014-03-04 Thread Igor Korot
Hi, ALL, Could someone please explain to me how the code in http://docs.python.org/2/howto/logging#logging-from-multiple-modules works? In particular I'm interested in how the mylib.py knows about the myapp.log. What I mean is: logging object is not passed to mylib.py, so essentially it should cre

Re: modification time in Python - Django: datetime != datetime :-(

2014-03-04 Thread Jaap van Wingerde
Op 2014-03-03T12:22:48 UTC schreef donarb in het bericht , ID: <04659633-e14e-4d5b-90f2-93af04f05...@googlegroups.com> het volgende. > You're using the months format '%m' when you should be using minutes > '%M'. Arrgh: stupid error (snik). p 2014-03-04T08:11:46 UTC schreef Chris Angelico in

Re: Functional programming

2014-03-04 Thread Antoon Pardon
Op 04-03-14 09:56, Steven D'Aprano schreef: > > >> If you >> explicitly say that this is an int, then yes, that should be disallowed; > It's that "explicitly" part that doesn't follow. Having to manage types > is the most tedious, boring, annoying, *unproductive* part of languages > like Java, C

Re: why indentation should be part of the syntax

2014-03-04 Thread Antoon Pardon
Op 02-03-14 11:41, Stefan Behnel schreef: > Haven't seen any mention of it on this list yet, but since it's such an > obvious flaw in quite a number of programming languages, here's a good > article on the recent security bug in iOS, which was due to accidentally > duplicated code not actually bei

Re: Working with the set of real numbers

2014-03-04 Thread Gregory Ewing
Chris Angelico wrote: In constant space, that will produce the sum of two infinite sequences of digits. It's not constant space, because the nines counter can grow infinitely large. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Reference

2014-03-04 Thread Alister
On Tue, 04 Mar 2014 09:18:57 +1100, Ben Finney wrote: > Marko Rauhamaa writes: > >> Mark Lawrence : >> >> > I'd just like to know why people are so obsessed with identities, >> > I've never thought to use them in 10+ years of writing Python. Do I >> > use the KISS principle too often? >> >> Cal

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 > next_m = d * a - m > next_d = (n - next_m * next

Re: Functional programming

2014-03-04 Thread Steven D'Aprano
On Tue, 04 Mar 2014 11:56:07 +0100, Antoon Pardon wrote: > Op 04-03-14 09:56, Steven D'Aprano schreef: > > >> >>> If you >>> explicitly say that this is an int, then yes, that should be >>> disallowed; >> It's that "explicitly" part that doesn't follow. Having to manage types >> is the most tedi

Re: Reference

2014-03-04 Thread Steven D'Aprano
On Tue, 04 Mar 2014 11:10:34 +, Alister wrote: > Definition of insanity > > Doing the same thing over and over again & expecting different results *rolls dice* :-) -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

find and replace string in binary file

2014-03-04 Thread loial
How do I read a binary file, find/identify a character string and replace it with another character string and write out to another file? Its the finding of the string in a binary file that I am not clear on. Any help appreciated -- https://mail.python.org/mailman/listinfo/python-list

Re: Working with the set of real numbers

2014-03-04 Thread Chris Angelico
On Tue, Mar 4, 2014 at 10:05 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> In constant space, that will produce the sum of two infinite sequences >> of digits. > > > It's not constant space, because the nines counter > can grow infinitely large. Okay, okay, technically yes. But the count

Re: Origin of 'self'

2014-03-04 Thread MRAB
On 2014-03-04 02:09, Dennis Lee Bieber wrote: On Sun, 2 Mar 2014 22:16:31 -0800 (PST), Westley Martínez declaimed the following: 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.

Re: Reference

2014-03-04 Thread Alexander Blinne
Am 03.03.2014 19:48, schrieb Terry Reedy: > The 'is' operator has three uses, two intended and one not. In > production code, 'is' tests that an object *is* a particular singular > object, such as None or a sentinel instance of class object. Just a bit of statistics on this one from a recent small

Re: Functional programming

2014-03-04 Thread Chris Angelico
On Tue, Mar 4, 2014 at 10:47 PM, Steven D'Aprano wrote: > Not even close. I'd like to see the compiler that can work out for itself > that this function is buggy: > > def sine_rule(side_a, side_b, angle_a): > """Return the angle opposite side_b.""" > return math.sin(side_b/side_a)*angle_a

Re: find and replace string in binary file

2014-03-04 Thread MRAB
On 2014-03-04 12:27, loial wrote: How do I read a binary file, find/identify a character string and replace it with another character string and write out to another file? Its the finding of the string in a binary file that I am not clear on. Any help appreciated Read it in chunks and search

Re: find and replace string in binary file

2014-03-04 Thread Peter Otten
loial wrote: > How do I read a binary file, find/identify a character string and replace > it with another character string and write out to another file? > > Its the finding of the string in a binary file that I am not clear on. That's not possible. You have to convert either binary to string o

Re: Idle thread (Polling) python GUI and saving program state

2014-03-04 Thread MRAB
On 2014-03-04 02:41, Rolando wrote:> On Monday, March 3, 2014 6:06:22 PM UTC-8, MRAB wrote: >> On 2014-03-04 01:33, Rolando wrote: >> > I have a GUI with a bunch of cells which is my "View" in the MVC >> > design. The user enters some information in the view and I pass >> > this on to the mode

Re: Functional programming

2014-03-04 Thread BartC
"Steven D'Aprano" wrote in message news:53159540$0$2923$c3e8da3$76491...@news.astraweb.com... It's that "explicitly" part that doesn't follow. Having to manage types is the most tedious, boring, annoying, *unproductive* part of languages like Java, C and Pascal. Almost always, you're telling th

Re: Functional programming

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 12:30 AM, BartC wrote: > But declaring variables is not just about specifying a type; it registers > the name too so that misspelled names can be picked up very early rather > than at runtime (and that's if you're lucky). The two are separate. I don't know of any language t

Re: Functional programming

2014-03-04 Thread Mark Lawrence
On 04/03/2014 13:30, BartC wrote: But declaring variables is not just about specifying a type; it registers the name too so that misspelled names can be picked up very early rather than at runtime (and that's if you're lucky). I've said before that this, to me, is one of the major downsides o

Re: Reference

2014-03-04 Thread Chris Angelico
On Tue, Mar 4, 2014 at 11:55 PM, Alexander Blinne wrote: > Am 03.03.2014 19:48, schrieb Terry Reedy: >> The 'is' operator has three uses, two intended and one not. In >> production code, 'is' tests that an object *is* a particular singular >> object, such as None or a sentinel instance of class ob

Re: Functional programming

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 1:05 AM, Mark Lawrence wrote: > On 04/03/2014 13:30, BartC wrote: >> >> >> But declaring variables is not just about specifying a type; it registers >> the name too so that misspelled names can be picked up very early rather >> than at runtime (and that's if you're lucky). >

Re: Origin of 'self'

2014-03-04 Thread Steven D'Aprano
On Tue, 04 Mar 2014 12:47:09 +, MRAB wrote: > In AppleScript a script can refer to the title of a window as "title of > window" or "window's title", and it can refer to the title of its own > window as "title of window of me" or "me's window's title". Consistent, > yes, but bad English. > > T

OT Sine Rule [was Re: Functional programming]

2014-03-04 Thread Steven D'Aprano
On Wed, 05 Mar 2014 00:01:01 +1100, Chris Angelico wrote: > On Tue, Mar 4, 2014 at 10:47 PM, Steven D'Aprano > wrote: >> Not even close. I'd like to see the compiler that can work out for >> itself that this function is buggy: >> >> def sine_rule(side_a, side_b, angle_a): >> """Return the ang

Re: OT Sine Rule [was Re: Functional programming]

2014-03-04 Thread Tim Chase
On 2014-03-04 14:25, Steven D'Aprano wrote: > Ask-me-about-versine-and-haversine-ly y'rs, More interested in a karosine, cuisine, and a limousine. ;-) -tkc -- https://mail.python.org/mailman/listinfo/python-list

Re: OT Sine Rule [was Re: Functional programming]

2014-03-04 Thread Mark Lawrence
On 04/03/2014 14:37, Tim Chase wrote: On 2014-03-04 14:25, Steven D'Aprano wrote: Ask-me-about-versine-and-haversine-ly y'rs, More interested in a karosine, cuisine, and a limousine. ;-) -tkc What do you get if you differentiate versines, haversines, karosines, cuisines and limosines?

Re: Functional programming

2014-03-04 Thread Steven D'Aprano
On Tue, 04 Mar 2014 14:05:44 +, Mark Lawrence wrote: > Once a statically typed language has been compiled the programmer can > head down to the pub. "It compiles? Quick! Ship it!" Well, that certainly explains the quality of some programs... -- Steven D'Aprano http://import-that.dreamwi

Re: Functional programming

2014-03-04 Thread Grant Edwards
On 2014-03-03, Ben Finney wrote: > Gregory Ewing writes: > >> Just because the compiler *can* infer the return type doesn't >> necessarily mean it *should*. When I was playing around with >> functional languages, I ended up adopting the practice of always >> declaring the types of my functions, b

Re: OT Sine Rule [was Re: Functional programming]

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 1:25 AM, Steven D'Aprano wrote: > > The Sine Rule, or Law of Sines, tells us that the ratio of the > length of a side and the sine of the angle opposite that side is constant > for any triangle. That is: > > a/sin(A) == b/sin(B) == c/sin(C) Oh! Right. Now I remember. Yeah.

Re: Functional programming

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 1:55 AM, Steven D'Aprano wrote: > On Tue, 04 Mar 2014 14:05:44 +, Mark Lawrence wrote: > >> Once a statically typed language has been compiled the programmer can >> head down to the pub. > > "It compiles? Quick! Ship it!" > > Well, that certainly explains the quality of

Re: Reference

2014-03-04 Thread Jerry Hill
On Mon, Mar 3, 2014 at 11:52 PM, Steven D'Aprano wrote: > If your intention is to treat None as a singleton sentinel, not as a > value, then you ought to use "is" to signal that intention, rather than > using == even if you know that there won't be any false positives. In all of the years I've be

Re: Functional programming

2014-03-04 Thread Steven D'Aprano
On Tue, 04 Mar 2014 13:30:04 +, BartC wrote: > "Steven D'Aprano" wrote in message > news:53159540$0$2923$c3e8da3$76491...@news.astraweb.com... > >> It's that "explicitly" part that doesn't follow. Having to manage types >> is the most tedious, boring, annoying, *unproductive* part of languag

Re: OT Sine Rule [was Re: Functional programming]

2014-03-04 Thread Tim Chase
On 2014-03-04 14:42, Mark Lawrence wrote: > What do you get if you differentiate versines, haversines, > karosines, cuisines and limosines? Well, with cuisines, you can usually differentiate by seasoning: your Tex/Mex is spicier and tends to have chili & cumin, while your Indian tends to lean more

Re: how to get bytes from bytearray without copying

2014-03-04 Thread Juraj Ivančić
On 3.3.2014. 2:27, Ian Kelly wrote: Python 3.3 has a C API function to create a memoryview for a char*, that can be made read-only. http://docs.python.org/3/c-api/memoryview.html#PyMemoryView_FromMemory I don't see a way to do what you want in pure Python, apart from perhaps writing an el

Re: Functional programming

2014-03-04 Thread Steven D'Aprano
On Tue, 04 Mar 2014 14:59:51 +, Grant Edwards wrote: > After a couple decades of working in software development, I've decided > that comments like that are not correct often enough to be useful. > You've got to reverse-engineer the code if there's no such comment. If > there _is_ a comment,

Re: Reference

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 2:19 AM, Jerry Hill wrote: > Out of curiosity, do you think we should be doing truth checking with > 'is'? True and False are singletons, and it seems to me that the > justification for idenity versus equality should be just as strong > there, but I don't think I've ever se

Re: Functional programming

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 2:18 AM, Steven D'Aprano wrote: > You don't need to have static typing to have declared variables. The two > are independent. E.g. one might have a system like Python, except you > have to declare your variables before using them: > > global x > local a > a = x+1 Aside: If

Re: Logging

2014-03-04 Thread Peter Otten
Igor Korot wrote: > Hi, ALL, > Could someone please explain to me how the code in > http://docs.python.org/2/howto/logging#logging-from-multiple-modules > works? > In particular I'm interested in how the mylib.py knows about the > myapp.log. > > What I mean is: logging object is not passed to myl

Re: Reference

2014-03-04 Thread Steven D'Aprano
On Tue, 04 Mar 2014 10:19:22 -0500, Jerry Hill wrote: > On Mon, Mar 3, 2014 at 11:52 PM, Steven D'Aprano > wrote: >> If your intention is to treat None as a singleton sentinel, not as a >> value, then you ought to use "is" to signal that intention, rather than >> using == even if you know that th

Re: Functional programming

2014-03-04 Thread Steven D'Aprano
On Wed, 05 Mar 2014 02:28:17 +1100, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 2:18 AM, Steven D'Aprano > wrote: >> You don't need to have static typing to have declared variables. The >> two are independent. E.g. one might have a system like Python, except >> you have to declare your variabl

Re: Reference

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 2:42 AM, Steven D'Aprano wrote: > # I never know when to stop > if bool(flag) is True is True is True is True is True is True: ... The banana problem. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Functional programming

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 2:45 AM, Steven D'Aprano wrote: >> Aside: If you declare your locals, you shouldn't need to declare your >> globals. Though I could imagine a rule that global rebinding still needs >> to be declared, but you certainly shouldn't need to declare nonlocal if >> you have a local

Re: Decoding a process output

2014-03-04 Thread Peter Otten
Francis Moreau wrote: > Hi, > > In my understanding (I'm relatively new to python), I need to decode any > bytes data provided, in my case, by a shell command (such as findmnt) > started by the subprocess module. The goal of my application is to parse > the command outputs. > > My application ru

Re: Reference

2014-03-04 Thread Roy Smith
In article , Chris Angelico wrote: > On Wed, Mar 5, 2014 at 2:42 AM, Steven D'Aprano > wrote: > > # I never know when to stop > > if bool(flag) is True is True is True is True is True is True: ... > > The banana problem. > > ChrisA You can refactor that as: eval(" is ".join(itertools.chain(

Re: how to get bytes from bytearray without copying

2014-03-04 Thread Stefan Behnel
Juraj Ivančić, 04.03.2014 16:23: > Just for reference, it is doable in pure Python, with ctypes help For some questionable meaning of "pure". Stefan -- https://mail.python.org/mailman/listinfo/python-list

Re: Reference

2014-03-04 Thread Rustom Mody
On Tuesday, March 4, 2014 8:49:22 PM UTC+5:30, Jerry Hill wrote: > On Mon, Mar 3, 2014 at 11:52 PM, Steven D'Aprano wrote: > > If your intention is to treat None as a singleton sentinel, not as a > > value, then you ought to use "is" to signal that intention, rather than > > using == even if you kn

Re: How security holes happen

2014-03-04 Thread sffjunkie
On Monday, 3 March 2014 22:55:32 UTC, Chris Kaynor wrote: > You can go much simpler than that. Merely port Python to LISP, then write a > LISP interpreter in Python. Done. http://blog.pault.ag/post/46982895940/heres-my-talk-from-pycon-2013-i-tried-to-queue -- https://mail.python.org/mailman/lis

Re: modification time in Python - Django: datetime != datetime :-(

2014-03-04 Thread donarb
Note that it's bad form to post the same question to different forums, you also posted this question to django-users. By posting to multiple forums, you run the risk of not having the question answered or followed up in one of the forums. This frustrates other users who may one day have a simila

Re: Functional programming

2014-03-04 Thread MRAB
On 2014-03-04 15:13, Chris Angelico wrote: On Wed, Mar 5, 2014 at 1:55 AM, Steven D'Aprano wrote: On Tue, 04 Mar 2014 14:05:44 +, Mark Lawrence wrote: Once a statically typed language has been compiled the programmer can head down to the pub. "It compiles? Quick! Ship it!" Well, that c

Re: How security holes happen

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 3:41 AM, wrote: > On Monday, 3 March 2014 22:55:32 UTC, Chris Kaynor wrote: >> You can go much simpler than that. Merely port Python to LISP, then write a >> LISP interpreter in Python. Done. > > http://blog.pault.ag/post/46982895940/heres-my-talk-from-pycon-2013-i-tried-

Re: Origin of 'self'

2014-03-04 Thread MRAB
On 2014-03-04 14:27, Steven D'Aprano wrote: On Tue, 04 Mar 2014 12:47:09 +, MRAB wrote: In AppleScript a script can refer to the title of a window as "title of window" or "window's title", and it can refer to the title of its own window as "title of window of me" or "me's window's title". C

Re: Reference

2014-03-04 Thread MRAB
On 2014-03-04 16:02, Chris Angelico wrote: On Wed, Mar 5, 2014 at 2:42 AM, Steven D'Aprano wrote: # I never know when to stop if bool(flag) is True is True is True is True is True is True: ... The banana problem. Speaking of which: The 'right' way to peel a banana http://www.telegraph.co.u

Re: How security holes happen

2014-03-04 Thread Skip Montanaro
On Tue, Mar 4, 2014 at 11:07 AM, Chris Angelico wrote: > I don't have time to watch an hour-long video... what'd he do, exactly that? If you fast forward to 16:14, his talk is about five minutes long. He wrote a Lisp compiler whose backend is Python. Skip -- https://mail.python.org/mailman/list

Re: modification time in Python - Django: datetime != datetime :-(

2014-03-04 Thread Roy Smith
In article , donarb wrote: > Note that it's bad form to post the same question to different forums, you > also posted this question to django-users. By posting to multiple forums, you > run the risk of not having the question answered or followed up in one of the > forums. This frustrates oth

Re: Working with the set of real numbers

2014-03-04 Thread Marko Rauhamaa
Chris Angelico : > As far as I know, there's no simple way, in constant space and/or > time, to progressively yield more digits of a number's square root, > working in decimal. I don't know why the constant space/time requirement is crucial. Anyway, producing more digits simple: http://nrich.math

Re: Functional programming

2014-03-04 Thread Marko Rauhamaa
Antoon Pardon : > In the same way writing unit tests is the most tedious, boring, > annoying, *unproductive* part. Amost always you are giving the program > results it can work out for itself. Undoubtedly, explicit type declarations add a dimension of quality to software. However, they also signi

Re: Working with the set of real numbers

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 6:49 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> As far as I know, there's no simple way, in constant space and/or >> time, to progressively yield more digits of a number's square root, >> working in decimal. > > I don't know why the constant space/time requirement is

Re: Functional programming

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 6:49 AM, Marko Rauhamaa wrote: > public ConnectionPool(int maxConnections, String url) throws SQLException { > try { > super(() -> { > try { > return DriverManager.getConnection(url); > } catch ( SQLException ex ) { >

NEW RESEARCH TEARS PALAEOANTHROPOLOGY APART: THE THRINAXODON TIMES

2014-03-04 Thread Thrinazodji0fecnfv
=== >BREAKING NEWS! === NEW YORK TIMES, THRINAXODON, OHIO = > THRINAXODON RECENTLY FOUND 3 HUMAN FOSSILS FROM DEVONIAN STRATA FROM GREENLAND, THE EVOLUTIONISTS HAVE NO BONES ABOUT. > ONE EVIL EVOLUTIONIST, BOB CASANOVA HAS ADMITTED THAT HUMAN EVOLUTIO

Re: How security holes happen

2014-03-04 Thread Ned Batchelder
On 3/4/14 12:16 PM, Skip Montanaro wrote: On Tue, Mar 4, 2014 at 11:07 AM, Chris Angelico wrote: I don't have time to watch an hour-long video... what'd he do, exactly that? If you fast forward to 16:14, his talk is about five minutes long. He wrote a Lisp compiler whose backend is Python. S

Re: Functional programming

2014-03-04 Thread Marko Rauhamaa
Chris Angelico : > On Wed, Mar 5, 2014 at 6:49 AM, Marko Rauhamaa wrote: >> public ConnectionPool(int maxConnections, String url) throws SQLException { >> try { >> super(() -> { >> try { >> return DriverManager.getConnection(url); >> } catch ( S

Proper conversion of timestamp

2014-03-04 Thread Igor Korot
Hi, ALL, I'm getting this: timestamp out of range for platform localtime()/gmtime() function trying to convert the timestamp with milliseconds into the datetime object. The first hit of Google gives me this: http://stackoverflow.com/questions/12458595/convert-epoch-timestamp-in-python but the

Re: Working with the set of real numbers

2014-03-04 Thread Oscar Benjamin
On 4 March 2014 19:58, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 6:49 AM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> As far as I know, there's no simple way, in constant space and/or >>> time, to progressively yield more digits of a number's square root, >>> working in decimal. >> >> I

Re: Functional programming

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 7:50 AM, Marko Rauhamaa wrote: > The "rigmarole" is trying to get around Java's mandatory exception > handling limitations, which Python doesn't have. > > You are not allowed to pass a lambda to the super constructor that > throws an SQLException. To get around the limitatio

Re: Working with the set of real numbers

2014-03-04 Thread Marko Rauhamaa
Oscar Benjamin : > To me the obvious method is Newton iteration which takes O(sqrt(N)) > iterations to obtain N digits of precision. This brings the above > complexity below quadratic: > > #!/usr/bin/env python > > from decimal import Decimal as D, localcontext > > def sqrt(y, prec=1000): > ''

Re: Working with the set of real numbers

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 7:55 AM, Oscar Benjamin wrote: > I don't quite follow your reasoning here. By "cut-and-try" do you mean > bisection? If so it gives the first N decimal digits in N*log2(10) > iterations. However each iteration requires a multiply and when the > number of digits N becomes lar

Re: Functional programming

2014-03-04 Thread Marko Rauhamaa
Chris Angelico : > Oh, it's THAT problem. Well, it's still not really a fair comparison > of declared types. It shows how Python's much easier to work with, but > what you're showing off is the simpler exception handling :) The other example I gave is really bread-and-butter Java. An ergonomic di

Re: Functional programming

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 8:21 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> Oh, it's THAT problem. Well, it's still not really a fair comparison >> of declared types. It shows how Python's much easier to work with, but >> what you're showing off is the simpler exception handling :) > > The other

Re: Proper conversion of timestamp

2014-03-04 Thread MRAB
On 2014-03-04 20:57, Igor Korot wrote: Hi, ALL, I'm getting this: timestamp out of range for platform localtime()/gmtime() function trying to convert the timestamp with milliseconds into the datetime object. The first hit of Google gives me this: http://stackoverflow.com/questions/12458595/co

Re: python decimal library dmath.py v0.3 released

2014-03-04 Thread Stefan Krah
[I found this via the python-ideas thread] Wolfgang Maier biologie.uni-freiburg.de> writes: > math.factorial is accurate and faster than your pure-Python function, especially for large numbers. It is slower for huge numbers than decimal if you use this Python function: http://www.bytereef.org/

Re: Proper conversion of timestamp

2014-03-04 Thread Mark Lawrence
On 04/03/2014 20:57, Igor Korot wrote: Hi, ALL, I'm getting this: timestamp out of range for platform localtime()/gmtime() function trying to convert the timestamp with milliseconds into the datetime object. The first hit of Google gives me this: http://stackoverflow.com/questions/12458595/co

Re: Functional programming

2014-03-04 Thread Marko Rauhamaa
Chris Angelico : > C++ at least has typedefs, and in the newer standards, the 'auto' > keyword was repurposed. Last I checked, C++ had no satisfactory way to express callbacks/functors/listeners/lambdas. That's why Qt came up with a metacompiler to supplement C++'s facilities. No, STL and Boost

Re: Proper conversion of timestamp

2014-03-04 Thread Igor Korot
MRAB, On Tue, Mar 4, 2014 at 1:38 PM, MRAB wrote: > On 2014-03-04 20:57, Igor Korot wrote: > >> Hi, ALL, >> I'm getting this: >> >> timestamp out of range for platform localtime()/gmtime() function >> >> trying to convert the timestamp with milliseconds into the datetime >> object. >> >> The fi

Re: Proper conversion of timestamp

2014-03-04 Thread Mark Lawrence
On 04/03/2014 21:38, MRAB wrote: On 2014-03-04 20:57, Igor Korot wrote: Hi, ALL, I'm getting this: timestamp out of range for platform localtime()/gmtime() function trying to convert the timestamp with milliseconds into the datetime object. The first hit of Google gives me this: http://stack

Re: Functional programming

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 8:43 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> C++ at least has typedefs, and in the newer standards, the 'auto' >> keyword was repurposed. > > Last I checked, C++ had no satisfactory way to express > callbacks/functors/listeners/lambdas. That's why Qt came up with a

Re: Reference

2014-03-04 Thread Alexander Blinne
Am 04.03.2014 15:06, schrieb Chris Angelico: > https://github.com/Rosuav/ExceptExpr/blob/master/find_except_expr.py I have always found it quite nice that the python parser is so easy to use from within python itself. > Run across the Python stdlib, that tells me there are 4040 uses of > is/is no

Re: Proper conversion of timestamp

2014-03-04 Thread Igor Korot
Mark, On Tue, Mar 4, 2014 at 1:45 PM, Mark Lawrence wrote: > On 04/03/2014 21:38, MRAB wrote: > >> On 2014-03-04 20:57, Igor Korot wrote: >> >>> Hi, ALL, >>> I'm getting this: >>> >>> timestamp out of range for platform localtime()/gmtime() function >>> >>> trying to convert the timestamp with m

Re: Proper conversion of timestamp

2014-03-04 Thread Igor Korot
Hi, Mark, On Tue, Mar 4, 2014 at 1:44 PM, Mark Lawrence wrote: > On 04/03/2014 20:57, Igor Korot wrote: > >> Hi, ALL, >> I'm getting this: >> >> timestamp out of range for platform localtime()/gmtime() function >> >> trying to convert the timestamp with milliseconds into the datetime >> object.

Re: Proper conversion of timestamp

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 8:46 AM, Igor Korot wrote: >> Are you using Python 2? If yes, then try dividing by 1000.0. > > > Yes, I'm using python 2.7. > But dividing by 1000 will give the precision in seconds, i.e. "-MM-DD > HH:MM:SS". Did you notice the bit at the end there? Try dividing by 1000

Re: Reference

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 8:53 AM, Alexander Blinne wrote: > Am 04.03.2014 15:06, schrieb Chris Angelico: >> https://github.com/Rosuav/ExceptExpr/blob/master/find_except_expr.py > > I have always found it quite nice that the python parser is so easy to > use from within python itself. Yes. Until I p

Re: Proper conversion of timestamp

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 8:55 AM, Igor Korot wrote: > > This is because this timestamp is not in seconds, but rather in > milliseconds. > > Now the question I have is: how do I properly convert this timestamp into > the datetime object with the milliseconds? Read elsewhere in the thread, two people

Re: Working with the set of real numbers

2014-03-04 Thread Oscar Benjamin
On 4 March 2014 21:18, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 7:55 AM, Oscar Benjamin > wrote: >> I don't quite follow your reasoning here. By "cut-and-try" do you mean >> bisection? If so it gives the first N decimal digits in N*log2(10) >> iterations. However each iteration requires a m

Re: Working with the set of real numbers

2014-03-04 Thread Oscar Benjamin
On 4 March 2014 21:05, Marko Rauhamaa wrote: > Oscar Benjamin : > >> To me the obvious method is Newton iteration which takes O(sqrt(N)) >> iterations to obtain N digits of precision. This brings the above >> complexity below quadratic: >> >> #!/usr/bin/env python >> >> from decimal import Decimal

Re: Working with the set of real numbers

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 9:02 AM, Oscar Benjamin wrote: > On 4 March 2014 21:18, Chris Angelico wrote: >> On Wed, Mar 5, 2014 at 7:55 AM, Oscar Benjamin >> wrote: >>> I don't quite follow your reasoning here. By "cut-and-try" do you mean >>> bisection? If so it gives the first N decimal digits in

Re: Proper conversion of timestamp

2014-03-04 Thread Ethan Furman
On 03/04/2014 01:55 PM, Igor Korot wrote: Now the question I have is: how do I properly convert this timestamp into the datetime object with the milliseconds? And Mark's point is: How do the docs say to do it? What fails when you try it that way? -- ~Ethan~ -- https://mail.python.org/mai

Re: How security holes happen

2014-03-04 Thread Ethan Furman
On 03/04/2014 12:47 PM, Ned Batchelder wrote: On 3/4/14 12:16 PM, Skip Montanaro wrote: On Tue, Mar 4, 2014 at 11:07 AM, Chris Angelico wrote: I don't have time to watch an hour-long video... what'd he do, exactly that? If you fast forward to 16:14, his talk is about five minutes long. He wr

Re: find and replace string in binary file

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 12:18 AM, Peter Otten <__pete...@web.de> wrote: > loial wrote: > >> How do I read a binary file, find/identify a character string and replace >> it with another character string and write out to another file? >> >> Its the finding of the string in a binary file that I am not

Re: Proper conversion of timestamp

2014-03-04 Thread Mark Lawrence
On 04/03/2014 21:55, Igor Korot wrote: But this particular question is easy. If it's easy why can't you answer it via the docs rather than ask here? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is f

Re: How security holes happen

2014-03-04 Thread Marko Rauhamaa
Ethan Furman : > Okay, that looks totally cool. Maybe I'll finally get a handle on > LISP! :) Lisp is conceptually simpler than Python, but awe-inspiring. One day, it will overtake Python, I believe. Once you have Lisp down pat, you'll be able to appreciate http://en.wikipedia.org/wiki/Combinato

Re: Working with the set of real numbers

2014-03-04 Thread Oscar Benjamin
On 4 March 2014 22:18, Chris Angelico wrote: > On Wed, Mar 5, 2014 at 9:02 AM, Oscar Benjamin > wrote: >> On 4 March 2014 21:18, Chris Angelico wrote: >>> On Wed, Mar 5, 2014 at 7:55 AM, Oscar Benjamin >>> wrote: >>> >>> epsilon = 0.0001 >>> def sqrt(n): >>> guess1, guess2 = 1, n >>> wh

Re: How security holes happen

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 9:48 AM, Marko Rauhamaa wrote: > Lisp is conceptually simpler than Python, but awe-inspiring. One day, it > will overtake Python, I believe. > > The final Nirvana is reached with... No no no. The final Nirvana is achieved when you no longer write text at all, but simply edi

Re: How security holes happen

2014-03-04 Thread Roy Smith
In article , Chris Angelico wrote: > On Wed, Mar 5, 2014 at 9:48 AM, Marko Rauhamaa wrote: > > Lisp is conceptually simpler than Python, but awe-inspiring. One day, it > > will overtake Python, I believe. > > > > The final Nirvana is reached with... > > No no no. The final Nirvana is achieved

Re: Working with the set of real numbers

2014-03-04 Thread Chris Angelico
On Wed, Mar 5, 2014 at 9:54 AM, Oscar Benjamin wrote: >> Let's compare two >> versions. In the first, you set the precision (I'm talking in terms of >> REXX's "NUMERIC DIGITS" statement > > I have no idea what that is. > >>- anything beyond this many digits >> will be rounded (and represented expo

Geezer learns python

2014-03-04 Thread notbob
I'm trying to learn python. I'm doing it via Zed Shaw's Learn Python the Hard Way. Sure enough, 16 lessons in and I've run aground. Is it OK for a painfully stupid ol' fart to ask painfully stupid noob questions, here? I'm a long time usenet fan and prefer it to irc. I've run Slackware for man

Re: Geezer learns python

2014-03-04 Thread Tobiah
On 03/04/2014 03:03 PM, notbob wrote: I'm trying to learn python. I'm doing it via Zed Shaw's Learn Python the Hard Way. Sure enough, 16 lessons in and I've run aground. Is it OK for a painfully stupid ol' fart to ask painfully stupid noob questions, here? I'm a long time usenet fan and prefe

  1   2   >