Re: Version numbers in Standard Library

2019-03-03 Thread Thomas Jollans
On 01/03/2019 16:35, Thompson, Matt (GSFC-610.1)[SCIENCE SYSTEMS AND APPLICATIONS INC] via Python-list wrote: > Dear Python List, > > A question. I help maintain a Python stack for users in my division here > at NASA and one user asked about updating the re module to 2.4. I > believe because he

Re: Version numbers in Standard Library

2019-03-01 Thread Skip Montanaro
The point of the "Changed in version ..." or "New in version ..." bits in the documentation is to alert readers who maintain software which needs to remain backward compatible with older versions of Python. If you maintain a package which you support for Python 3.4, 3.5, 3.6, and 3.7, you'll

Re: converting numbers into words

2017-11-09 Thread Grant Edwards
On 2017-11-09, r161...@rguktrkv.ac.in wrote: > How can I covert numbers into word like ex:-123 One hundred twenty three? That's one of the classic freshman intro-to-programming homework problems. I remember having to write a Pascal program to do that back in the 70's...

Re: converting numbers into words (Posting On Python-List Prohibited)

2017-11-09 Thread Christopher Reimer
On Nov 9, 2017, at 3:45 AM, John Ladasky wrote: > >> On Wednesday, November 8, 2017 at 11:40:18 PM UTC-8, Lawrence D’Oliveiro >> wrote: >>> On Thursday, November 9, 2017 at 7:51:35 PM UTC+13, r16...@rguktrkv.ac.in >>> wrote: >>> >>> How can I covert numbers into

Re: converting numbers into words

2017-11-09 Thread bartc
On 09/11/2017 06:51, r161...@rguktrkv.ac.in wrote: How can I covert numbers into word like ex:-123 One hundred twenty three? google for something like "algorithm numbers to words". If this is homework, then it's not cheating as everyone else will be doing the same. > How can I covert

Re: converting numbers into words (Posting On Python-List Prohibited)

2017-11-09 Thread John Ladasky
On Wednesday, November 8, 2017 at 11:40:18 PM UTC-8, Lawrence D’Oliveiro wrote: > On Thursday, November 9, 2017 at 7:51:35 PM UTC+13, r16...@rguktrkv.ac.in > wrote: > > > How can I covert numbers into word like ex:-123 One hundred twenty three? > > Here’s

Re: converting numbers into words

2017-11-08 Thread jladasky
On Wednesday, November 8, 2017 at 10:51:35 PM UTC-8, r16...@rguktrkv.ac.in wrote: > How can I covert numbers into word like ex:-123 One hundred twenty three? That's a classic homework exercise. Expect guidance, not an answer. Why don't you solve a related, but simpler task first? This is a

Re: Format numbers

2015-11-15 Thread MRAB
On 2015-11-15 17:30, Seymore4Head wrote: Just screwing around making up practice problems. I can't get the format right. I am trying to learn how to get a output line to line up neatly. import random lo=1 hi=1 # I am adding or subtracting 0s from this input number fm=len(str(hi)) # This

Re: Format numbers

2015-11-15 Thread Seymore4Head
On Sun, 15 Nov 2015 19:00:42 +, MRAB wrote: >On 2015-11-15 17:30, Seymore4Head wrote: >> Just screwing around making up practice problems. I can't get the >> format right. I am trying to learn how to get a output line to line >> up neatly. >> >> import random >>

Re: Lucky numbers in Python

2015-04-30 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 04:55 CEST schreef Ian Kelly: On Wed, Apr 29, 2015 at 6:01 PM, Cecil Westerhof ce...@decebal.nl wrote: Op Thursday 30 Apr 2015 00:38 CEST schreef Ian Kelly: In that case you can definitely omit the middle term of the slice, which will be both more concise and clearer

Re: Lucky numbers in Python

2015-04-30 Thread Cecil Westerhof
Because I want the code to work with Python 3 also, the code is now: def lucky_numbers(n): Lucky numbers from 1 up-to n http://en.wikipedia.org/wiki/Lucky_number if n 3: return [1] sieve = list(range(1, n + 1, 2))

Re: Lucky numbers in Python

2015-04-30 Thread Dave Angel
On 04/30/2015 02:55 PM, Cecil Westerhof wrote: Because I want the code to work with Python 3 also, the code is now: def lucky_numbers(n): Lucky numbers from 1 up-to n http://en.wikipedia.org/wiki/Lucky_number if n 3: return [1]

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 12:24 PM, Cecil Westerhof ce...@decebal.nl 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

Re: Lucky numbers in Python

2015-04-29 Thread Cecil Westerhof
Op Wednesday 29 Apr 2015 21:57 CEST schreef Ian Kelly: On Wed, Apr 29, 2015 at 12:24 PM, Cecil Westerhof ce...@decebal.nl 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]

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 3:45 PM, Cecil Westerhof ce...@decebal.nl wrote: Op Wednesday 29 Apr 2015 21:57 CEST schreef Ian Kelly: And although it's not clear to me what this is supposed to be doing, you probably no longer need the middle term if the intention is to continue deleting all the way

Re: Lucky numbers in Python

2015-04-29 Thread Chris Kaynor
On Wed, Apr 29, 2015 at 2:45 PM, Cecil Westerhof ce...@decebal.nl 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 using

Re: Lucky numbers in Python

2015-04-29 Thread Steven D'Aprano
On Thu, 30 Apr 2015 05:57 am, Ian Kelly wrote: On Wed, Apr 29, 2015 at 12:24 PM, Cecil Westerhof ce...@decebal.nl wrote: I was wondering if there is a way to do this: for del_index in range((sieve_len // skip_count) * skip_count - 1,

Re: Lucky numbers in Python

2015-04-29 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 00:38 CEST schreef Ian Kelly: On Wed, Apr 29, 2015 at 3:45 PM, Cecil Westerhof ce...@decebal.nl wrote: Op Wednesday 29 Apr 2015 21:57 CEST schreef Ian Kelly: And although it's not clear to me what this is supposed to be doing, you probably no longer need the middle

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 6:01 PM, Cecil Westerhof ce...@decebal.nl wrote: Op Thursday 30 Apr 2015 00:38 CEST schreef Ian Kelly: In that case you can definitely omit the middle term of the slice, which will be both more concise and clearer in intent, though probably not significantly faster.

Re: Lucky numbers in Python

2015-04-29 Thread Ian Kelly
On Wed, Apr 29, 2015 at 6:11 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 30 Apr 2015 05:57 am, Ian Kelly wrote: On Wed, Apr 29, 2015 at 12:24 PM, Cecil Westerhof ce...@decebal.nl wrote: I was wondering if there is a way to do this: for del_index in

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Joel Goldstick
On Sun, Jan 11, 2015 at 2:31 PM, Store Makhzan stor...@gmail.com wrote: I have this script which can calculate the total of numbers given in a string script - total = 0 for c in '0123456789': total += int(c) print total script - How should I modify this script to find

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Store Makhzan
On Sunday, January 11, 2015 at 2:06:54 PM UTC-6, Joel Goldstick wrote: On Sun, Jan 11, 2015 at 2:31 PM, Store Makhzan wrote: I have this script which can calculate the total of numbers given in a string script - total = 0 for c in '0123456789': total += int(c) print

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Joel Goldstick
On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn pointede...@web.de wrote: Joel Goldstick wrote: Thomas 'PointedEars' Lahn wrote: Joel Goldstick wrote: my_list = 1.23, 2.4, 3.123.split(,) that will give you ['1.23', '2.4', '3.123'] No, it gives […] | my_list = 1.23, 2.4,

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Joel Goldstick wrote: On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn pointede...@web.de wrote: Joel Goldstick wrote: Am I missing something. ^ […] You are missing a leading space character because in the string the comma was followed by one. I see

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Mark Lawrence
On 11/01/2015 23:07, Thomas 'PointedEars' Lahn wrote: Store Makhzan wrote: I have this script which can calculate the total of numbers given in a string […] total = 0 for c in '0123456789': total += int(c) print total […] How should I modify this script to find the total of if the numbers

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Mark Lawrence wrote: On 11/01/2015 23:07, Thomas 'PointedEars' Lahn wrote: I thought I had more than a fair grasp of regular expressions, but I am puzzled by | $ python3 | Python 3.4.2 (default, Dec 27 2014, 13:16:08) | [GCC 4.9.2] on linux | from re import findall | s = '1.32, 5.32,

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Chris Angelico
On Mon, Jan 12, 2015 at 11:09 AM, Peter Otten __pete...@web.de wrote: print(sum(map(lambda x: float(x), s.split(','))) Please trim your quotes to the relevant minimum. Hm, can you explain what this lambda x: float(x) is supposed to achieve? I mean other than to confuse a newbie...

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Joel Goldstick wrote: my_list = 1.23, 2.4, 3.123.split(,) that will give you ['1.23', '2.4', '3.123'] No, it gives | $ python | Python 2.7.9 (default, Dec 11 2014, 08:58:12) | [GCC 4.9.2] on linux2 | Type help, copyright, credits or license for more information. | my_list = 1.23, 2.4,

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Joel Goldstick wrote: Thomas 'PointedEars' Lahn wrote: Joel Goldstick wrote: my_list = 1.23, 2.4, 3.123.split(,) that will give you ['1.23', '2.4', '3.123'] No, it gives […] | my_list = 1.23, 2.4, 3.123.split(,) | my_list | ['1.23', ' 2.4', ' 3.123'] ^ ^ |

Re: extracting numbers with decimal places from a string

2015-01-11 Thread MRAB
On 2015-01-12 00:04, Mark Lawrence wrote: On 11/01/2015 23:07, Thomas 'PointedEars' Lahn wrote: Store Makhzan wrote: I have this script which can calculate the total of numbers given in a string […] total = 0 for c in '0123456789': total += int(c) print total […] How should I modify this

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Joel Goldstick
On Sun, Jan 11, 2015 at 5:20 PM, Thomas 'PointedEars' Lahn pointede...@web.de wrote: Joel Goldstick wrote: my_list = 1.23, 2.4, 3.123.split(,) that will give you ['1.23', '2.4', '3.123'] No, it gives | $ python | Python 2.7.9 (default, Dec 11 2014, 08:58:12) | [GCC 4.9.2] on linux2 |

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Peter Otten
Thomas 'PointedEars' Lahn wrote: Joel Goldstick wrote: On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn pointede...@web.de wrote: Joel Goldstick wrote: Am I missing something. ^ […] You are missing a leading space character because in the string the

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Joel Goldstick
On Sun, Jan 11, 2015 at 3:26 PM, Store Makhzan stor...@gmail.com wrote: On Sunday, January 11, 2015 at 2:06:54 PM UTC-6, Joel Goldstick wrote: On Sun, Jan 11, 2015 at 2:31 PM, Store Makhzan wrote: I have this script which can calculate the total of numbers given in a string script

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Steven D'Aprano
Thomas 'PointedEars' Lahn wrote: The original script already does not do what it advertises. Instead, it iterates over the characters of the string, attempts to convert each to an integer and then computes the sum. That is _not_ “calculate the total of numbers given in a string”. Yes, and

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Store Makhzan wrote: I have this script which can calculate the total of numbers given in a string […] total = 0 for c in '0123456789': total += int(c) print total […] How should I modify this script to find the total of if the numbers given in the string form have decimal places?

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Grant Edwards
On 2015-01-11, Joel Goldstick joel.goldst...@gmail.com wrote: That's fine, but its different than your original question. In your original question you had a string of floats separated by commas. To solve that problem you need to first split the string on the commas: my_list = 1.23, 2.4,

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Steven D'Aprano
Thomas 'PointedEars' Lahn wrote: This is safer: | from re import split | split(r'\s*,\s*', '1.23, 2.4, 3.123') | ['1.23', '2.4', '3.123'] Safer, slower, and unnecessary. There is no need for the nuclear-powered bulldozer of regular expressions just to crack this tiny peanut. We can

Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Peter Otten wrote: Thomas 'PointedEars' Lahn wrote: […] But float() is always necessary for computing the sum and suffices indeed together with s.split() if s is just a comma-separated list of numeric strings with optional whitespace leading and trailing the comma:

Re: decimal numbers

2014-02-16 Thread wxjmfauth
Without any warranty. def z(r): ... # r: int 0 ... t = log10(r) ... if t = 12.0: ... prefix = '' ... prefix2 = '' ... elif t = 9.0: ... prefix = 'giga' ... prefix2 = 'G' ... r = r / 1.0e9 ... elif t = 6.0: ... prefix = 'mega'

Re: decimal numbers

2014-02-15 Thread Luke Geelen
Op zaterdag 15 februari 2014 10:18:36 UTC+1 schreef Luke Geelen: 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: #

Re: decimal numbers

2014-02-15 Thread Frank Millman
Luke Geelen luke.gee...@gmail.com wrote in message news:ec88852e-1384-4aa5-834b-85135be94...@googlegroups.com... Op zaterdag 15 februari 2014 10:18:36 UTC+1 schreef Luke Geelen: hello, i have been working on a python resistor calculator to let my class show what you can do with python.

Re: decimal numbers

2014-02-15 Thread Chris Angelico
On Sat, Feb 15, 2014 at 9:04 PM, Frank Millman fr...@chagford.com wrote: If you are using python2, an integer divided by an integer always returns an integer - 10/3 3 It was changed in python3 to return a float - 10/3 3.3335 You can reproduce the python3 behaviour in

Re: decimal numbers

2014-02-15 Thread Luke Geelen
Op zaterdag 15 februari 2014 11:04:17 UTC+1 schreef Frank Millman: Luke Geelen luke.gee...@gmail.com wrote in message news:ec88852e-1384-4aa5-834b-85135be94...@googlegroups.com... Op zaterdag 15 februari 2014 10:18:36 UTC+1 schreef Luke Geelen: hello, i have been working on a

Re: decimal numbers

2014-02-15 Thread Frank Millman
Luke Geelen luke.gee...@gmail.com wrote in message news:ae0da085-6c41-4166-92d2-92611a990...@googlegroups.com... Op zaterdag 15 februari 2014 11:04:17 UTC+1 schreef Frank Millman: Luke Geelen luke.gee...@gmail.com wrote in message news:ec88852e-1384-4aa5-834b-85135be94...@googlegroups.com...

Re: decimal numbers

2014-02-15 Thread Frank Millman
Frank Millman fr...@chagford.com wrote in message news:ldngnf$c3r$1...@ger.gmane.org... Luke Geelen luke.gee...@gmail.com wrote in message news:ae0da085-6c41-4166-92d2-92611a990...@googlegroups.com... Op zaterdag 15 februari 2014 11:04:17 UTC+1 schreef Frank Millman: Luke Geelen

Re: decimal numbers

2014-02-15 Thread Laurent Pointal
luke.gee...@gmail.com 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 # print de weerstand

Re: decimal numbers

2014-02-15 Thread Luke Geelen
If i do set form thing in my script i get Invalide syntax pointing at the last word of the form rule -- https://mail.python.org/mailman/listinfo/python-list

Re: decimal numbers

2014-02-15 Thread Ian Kelly
On Sat, Feb 15, 2014 at 2:18 AM, luke.gee...@gmail.com 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

Re: decimal numbers

2014-02-15 Thread Ian Kelly
On Sat, Feb 15, 2014 at 10:17 AM, Luke Geelen luke.gee...@gmail.com 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

Re: decimal numbers

2014-02-15 Thread Luke Geelen
Op zaterdag 15 februari 2014 18:23:20 UTC+1 schreef Ian: On Sat, Feb 15, 2014 at 10:17 AM, Luke Geelen luke.gee...@gmail.com 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

Re: decimal numbers

2014-02-15 Thread Luke Geelen
Op zaterdag 15 februari 2014 18:42:51 UTC+1 schreef Luke Geelen: Op zaterdag 15 februari 2014 18:23:20 UTC+1 schreef Ian: On Sat, Feb 15, 2014 at 10:17 AM, Luke Geelen luke.gee...@gmail.com wrote: If i do set form thing in my script i get Invalide syntax pointing at the

Re: decimal numbers

2014-02-15 Thread Mark Lawrence
On 15/02/2014 18:57, Luke Geelen wrote: Op zaterdag 15 februari 2014 18:42:51 UTC+1 schreef Luke Geelen: Op zaterdag 15 februari 2014 18:23:20 UTC+1 schreef Ian: On Sat, Feb 15, 2014 at 10:17 AM, Luke Geelen luke.gee...@gmail.com wrote: If i do set form thing in my script i get

Re: decimal numbers

2014-02-15 Thread Steven D'Aprano
On Sat, 15 Feb 2014 10:57:20 -0800, 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 Yes, but not easily. First, check the number's fractional part, and if it is zero, convert it to an int: # Here,

Re: decimal numbers

2014-02-15 Thread Ian Kelly
On Sat, Feb 15, 2014 at 11:57 AM, Luke Geelen luke.gee...@gmail.com 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

Re: decimal numbers

2014-02-15 Thread Steven D'Aprano
On Sat, 15 Feb 2014 14:34:45 -0700, Ian Kelly wrote: On Sat, Feb 15, 2014 at 11:57 AM, Luke Geelen luke.gee...@gmail.com 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

Re: decimal numbers

2014-02-15 Thread Chris Angelico
On Sun, Feb 16, 2014 at 1:30 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Even though I didn't ask the question, I learned something from the answer. Thank you. Reason #1443694 for mailing lists rather than personal tutoring :) I love this aspect of them. ChrisA --

Re: Floating numbers

2010-08-13 Thread Mark Dickinson
On Aug 12, 9:43 pm, Bradley Hintze bradle...@aggiemail.usu.edu wrote: Hi all. Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. Nitpick: unless you're on very unusual hardware, you're missing some zeros here. On my

Re: Floating numbers

2010-08-13 Thread jmfauth
A quick question. I understand how to get these numbers 34.5231263880373081783294677734375 and 47 (from 2**47) and the sign. with the decimal module, but I fail to find this one 4858258098025923 Possible? -- http://mail.python.org/mailman/listinfo/python-list

Re: Floating numbers

2010-08-13 Thread Mark Dickinson
On Aug 13, 3:03 pm, jmfauth wxjmfa...@gmail.com wrote: A quick question. I understand how to get these numbers 34.5231263880373081783294677734375 and 47 (from 2**47) and the sign. with the decimal module, but I fail to find this one 4858258098025923 Possible? See

Re: Floating numbers

2010-08-13 Thread jmfauth
On 13 août, 17:43, Mark Dickinson dicki...@gmail.com wrote: On Aug 13, 3:03 pm, jmfauth wxjmfa...@gmail.com wrote: A quick question. I understand how to get these numbers 34.5231263880373081783294677734375 and 47 (from 2**47) and the sign. with the decimal

Re: Floating numbers

2010-08-13 Thread Aahz
In article 595969e7-354f-456d-82b5-6aeafbabe...@d8g2000yqf.googlegroups.com, Mark Dickinson dicki...@gmail.com wrote: - If you *really* need a number that represents the *exact* value 34.52, then use the decimal module, or perhaps consider using a simple home-brewed fixed-point representation.

Re: Floating numbers

2010-08-12 Thread Gary Herron
On 08/12/2010 01:43 PM, Bradley Hintze wrote: Hi all. Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. Is this a Python question? The answer is both Yes and No. The binary floating point representation of

Re: Floating numbers

2010-08-12 Thread Grant Edwards
On 2010-08-12, Bradley Hintze bradle...@aggiemail.usu.edu wrote: Is there a way I can keep my floating point number as I typed it? No. For example, I want 34.52 to be 34.52 and NOT 34.520002. You can't represent 34.52 using base-2 IEEE floating point (the HW floating point format used by

Re: Floating numbers

2010-08-12 Thread Grant Edwards
On 2010-08-12, Grant Edwards inva...@invalid.invalid wrote: On 2010-08-12, Bradley Hintze bradle...@aggiemail.usu.edu wrote: Is there a way I can keep my floating point number as I typed it? No. For example, I want 34.52 to be 34.52 and NOT 34.520002. You can't represent 34.52 using

Re: Floating numbers

2010-08-12 Thread Philip Semanchuk
On Aug 12, 2010, at 4:43 PM, Bradley Hintze wrote: Hi all. Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. Hi Bradley, Use the Decimal type instead. It's not as convenient as float, but it will give you a

Re: Floating numbers

2010-08-12 Thread Thomas Jollans
On Thursday 12 August 2010, it occurred to Bradley Hintze to exclaim: Hi all. Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. The conversion from decimal to binary and vice versa is inexact -- but they're the

Re: Floating numbers

2010-08-12 Thread Chris Rebert
On Thu, Aug 12, 2010 at 1:43 PM, Bradley Hintze bradle...@aggiemail.usu.edu wrote: Hi all. Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. stuff repeating Gary's answer redacted See also:

Re: Floating numbers

2010-08-12 Thread Grant Edwards
On 2010-08-12, Grant Edwards inva...@invalid.invalid wrote: Here are the nitty-gritty details: http://docs.sun.com/source/806-3568/ncg_goldberg.html Here is a gentler intro: http://pyfaq.infogami.com/why-are-floating-point-calculations-so-inaccurate And another good page:

Re: Floating numbers

2010-08-12 Thread Christian Heimes
Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. This isn't a Python issue. Python uses IEEE 754 [1] double precision floats like most other languages. 34.52 can't be stored in a float. The next valid float is

Re: Floating numbers

2010-08-12 Thread Ned Deily
In article i41p6e$1f...@dough.gmane.org, Christian Heimes li...@cheimes.de wrote: Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. This isn't a Python issue. Python uses IEEE 754 [1] double precision floats like

Re: Floating numbers

2010-08-12 Thread Benjamin Kaplan
On Thu, Aug 12, 2010 at 6:14 PM, Ned Deily n...@acm.org wrote: In article i41p6e$1f...@dough.gmane.org,  Christian Heimes li...@cheimes.de wrote: Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.520002. This isn't a Python

Re: Floating numbers

2010-08-12 Thread Ned Deily
In article aanlkti=kom3xbknmmvwbhxxsvnya_kucokbnpzqp2...@mail.gmail.com, Benjamin Kaplan benjamin.kap...@case.edu wrote: Well, it is a *bit* of a Python issue since, as others have pointed out, Python's behavior has changed due to the implementation of Gay's rounding algorithm in 3.1 and

Re: Floating numbers

2010-08-12 Thread Nobody
On Thu, 12 Aug 2010 18:19:40 -0700, Benjamin Kaplan wrote: But that's not keeping the number the way it was typed. It's just not showing you the exact approximation. Nor is 34.523 showing you the exact approximation. The closest double to 34.52 is 4858258098025923 / 2**47, whose

Re: writing numbers in binary file

2010-05-31 Thread MRAB
eskandari wrote: Hi, I am a newbie in python. I have an data.pickle file which is serialized form of an array of strings, I want to write their offsets in another binary file, so an C++ program can read and analyse them. But when I try to write offset (number) in binary file, it raise exception

Re: writing numbers in binary file

2010-05-31 Thread Tim Chase
On 05/31/2010 10:56 AM, eskandari wrote: But when I try to write offset (number) in binary file, it raise exception below in line offsetfile.write(offset) TypeError: argument 1 must be string or read-only buffer, not int I search the internet, find that all suggest converting number to string

Re: writing numbers in binary file

2010-05-31 Thread eskandari
On May 31, 12:30 pm, MRAB pyt...@mrabarnett.plus.com wrote: eskandari wrote: Hi, I am a newbie in python. I have an data.pickle file which is serialized form of an array of strings, I want to write their offsets in another binary file, so an C++ program can read and analyse them. But

Re: writing numbers in binary file

2010-05-31 Thread Terry Reedy
On 5/31/2010 12:43 PM, eskandari wrote: On May 31, 12:30 pm, MRABpyt...@mrabarnett.plus.com wrote: eskandari wrote: Use the 'struct' module to convert the int to a bytestring, and remember to open the file as a binary file. Thanks alot, I have an question, if I do so, Will the second

Re: writing numbers in binary file

2010-05-31 Thread Dave Angel
eskandari wrote: On May 31, 12:30 pm, MRAB pyt...@mrabarnett.plus.com wrote: eskandari wrote: Hi, I am a newbie in python. I have an data.pickle file which is serialized form of an array of strings, I want to write their offsets in another binary file, so an C++ program can read and

Re: real numbers with infinity precission

2009-11-20 Thread Steven D'Aprano
On Thu, 19 Nov 2009 09:50:44 +0100, Hans Larsen wrote: I have a READ.me file for real.py, but where could I get that module? I use Python 3.+ I hope that sombody can help me Have you googled for real.py? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: replacing numbers in LARGE MATRIX with criterium in 2 columns (a-- b)

2009-05-04 Thread Alessandro
On May 4, 2:38 pm, Alexzive zasaconsult...@gmail.com wrote: Hello, I have this matrix [20*4 - but it could be n*4 , with n~100,000] in file EL_list like this: 1, 1, 2, 3 2, 4, 1, 5 3, 5, 1, 6 4, 7, 5, 6 5,

Re: Re: replacing numbers in LARGE MATRIX with criterium in 2 columns (a-- b)

2009-05-04 Thread Dave Angel
Alessandro wrote: On May 4, 2:38 pm, Alexzive zasaconsult...@gmail.com wrote: Hello, I have this matrix [20*4 - but it could be n*4 , with n~100,000] in file EL_list like this: 1, 1, 2, 3 2, 4, 1, 5 3, 5, 1, 6 4, 7,

Re: replacing numbers in LARGE MATRIX with criterium in 2 columns (a-- b)

2009-05-04 Thread MRAB
Alexzive wrote: Hello, I have this matrix [20*4 - but it could be n*4 , with n~100,000] in file EL_list like this: 1, 1, 2, 3 2, 4, 1, 5 3, 5, 1, 6 4, 7, 5, 6 5, 8, 7, 9 6, 8, 5,

Re: replacing numbers in LARGE MATRIX with criterium in 2 columns (a-- b)

2009-05-04 Thread Aahz
In article 68d22002-fc0a-4590-9395-c78b6ee41...@r34g2000vba.googlegroups.com, Alexzive zasaconsult...@gmail.com wrote: I have this matrix [20*4 - but it could be n*4 , with n~100,000] in file EL_list like this: Take a look at NumPy -- Aahz (a...@pythoncraft.com) *

Re: Converting numbers to words

2009-02-05 Thread Steve Holden
todp...@hotmail.com wrote: I've been trying to figure this out for over 2 hours and I'm really frustrated right now. I first made Python to ask user to input height in meters. If user puts certain value in meter, then it converts it to feet and inches as follows: Enter the height (in

Re: Converting numbers to words

2009-02-05 Thread Brian Allen Vanderburg II
todp...@hotmail.com wrote: I've been trying to figure this out for over 2 hours and I'm really frustrated right now. I first made Python to ask user to input height in meters. If user puts certain value in meter, then it converts it to feet and inches as follows: Enter the height

Re: Idenfity numbers in variables

2008-10-20 Thread John Machin
On Oct 20, 10:16 pm, Alfons Nonell-Canals [EMAIL PROTECTED] wrote: Hello, I have a trouble and I don't know how to solve it. I am working with molecules and each molecule has a number of atoms. I obtain each atom spliting the molecule. Ok. It is fine and I have no problem with it. The

Re: Idenfity numbers in variables

2008-10-20 Thread Peter Otten
Alfons Nonell-Canals wrote: I have a trouble and I don't know how to solve it. I am working with molecules and each molecule has a number of atoms. I obtain each atom spliting the molecule. Ok. It is fine and I have no problem with it. The problem is when I have to work with these atoms.

Re: Idenfity numbers in variables

2008-10-20 Thread Tim Chase
atom = 'C1' if '1' in atom: print 'kk' But, how can I do to identify in '1' all possibilities from 1-9, I tried: if '[1-9]', \d,... You're reaching in the right direction (regexps), so just use Python's re module: import re digit = re.compile(r'\d') # or [0-9] for test in

Re: Idenfity numbers in variables

2008-10-20 Thread Paul McGuire
On Oct 20, 7:07 am, Peter Otten [EMAIL PROTECTED] wrote: Alfons Nonell-Canals wrote: I have a trouble and I don't know how to solve it. I am working with molecules and each molecule has a number of atoms. I obtain each atom spliting the molecule. Ok. It is fine and I have no problem with

Re: Idenfity numbers in variables

2008-10-20 Thread Lie Ryan
On Mon, 20 Oct 2008 13:16:48 +0200, Alfons Nonell-Canals wrote: Hello, I have a trouble and I don't know how to solve it. I am working with molecules and each molecule has a number of atoms. I obtain each atom spliting the molecule. Ok. It is fine and I have no problem with it. The

Re: Idenfity numbers in variables

2008-10-20 Thread Duncan Booth
Lie Ryan [EMAIL PROTECTED] wrote: That's the job of regular expression: 'import re' numbered_atom = re.compile('[A-Z][a-z]?[0-9]+') if numbered_atom.match('C10'): # this is a numbered atom if numbered_atom.match('C'): # this WON'T match read more about regular expression on the

Re: replace numbers in a string

2008-10-09 Thread Gary Herron
Beema Shafreen wrote: hi All, i have few lines in file ttccatttctggacatgacgtctgt6901ggtttaagctttgtgaaagaatgtgctttgattcg i need to replace the number and get only the alphabet in such a case what should i do. Can any body suggest me From the regular expression module, use re.sub like this:

Re: replace numbers in a string

2008-10-09 Thread Peter Otten
Gary Herron wrote: Beema Shafreen wrote: hi All, i have few lines in file ttccatttctggacatgacgtctgt6901ggtttaagctttgtgaaagaatgtgctttgattcg i need to replace the number and get only the alphabet in such a case what should i do. Can any body suggest me From the regular expression module,

Re: negative numbers are not equal...

2008-08-15 Thread Fredrik Lundh
ariel ledesma wrote: i see now, so i guess that's also why id() returns the same address for them as well... i'll dive into the implementation file, it may be a bit out of my league but i'll see what i can gather, and hey, that's how it works, right? :-) well, there's another strategy, of

Re: negative numbers are not equal...

2008-08-15 Thread Steven D'Aprano
On Thu, 14 Aug 2008 20:44:32 -0700, castironpi wrote: For a= 6 b= a the test a is b should clearly return true. Since Python promises not to make a copy of a when you execute b = a, then I think that such behaviour is guaranteed by the language. Python distinguishes what

Re: negative numbers are not equal...

2008-08-15 Thread Dan Lenski
On Thu, 14 Aug 2008 17:18:55 -0300, ariel ledesma wrote: hello guys i just ran into this when comparing negative numbers, they start returning False from -6 down, but only when comparing with 'is' m = -5 a = -5 m is a True m = -6 a = -6 m is a False m == a True i

Re: negative numbers are not equal...

2008-08-15 Thread Carl Banks
On Aug 14, 4:42 pm, Christian Heimes [EMAIL PROTECTED] wrote: Integers between -5 and +256 are singletons as are some other objects like strings with one element or empty tuples. Not quite. Python 2.5.2 (r252:60911, May 28 2008, 08:35:32) [GCC 4.2.4 (Debian 4.2.4-1)] on linux2 Type help,

Re: negative numbers are not equal...

2008-08-15 Thread castironpi
On Aug 15, 8:56 am, Dan Lenski [EMAIL PROTECTED] wrote: On Thu, 14 Aug 2008 17:18:55 -0300, ariel ledesma wrote: hello guys i just ran into this when comparing negative numbers, they start returning False from -6 down, but only when comparing with 'is'   m = -5   a = -5   m is a

Re: negative numbers are not equal...

2008-08-15 Thread Bruno Desthuilliers
castironpi a écrit : (snip) It would be nice to put together a really canonical case of the use of the 'is' comparison. FTSOA for the sake of argument, when do you use it? When I want to test objects identity. An idenity test is an identity test is an identity test is an Why is it

Re: negative numbers are not equal...

2008-08-15 Thread Fredrik Lundh
castironpi wrote: This case actually misses handleC(). The solution is that the function that is returning '-10' cannot return -10, it has to return flagC. This can cause difficulties in cases when you're doing operations on flags. Worse, if flagC is nested somewhere, say

  1   2   3   4   >