Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10014 > unrolled thread
| Started by | Thomas Jollans <t@jollybox.de> |
|---|---|
| First post | 2011-07-21 11:53 +0200 |
| Last post | 2011-07-21 04:09 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Convert '165.0' to int Thomas Jollans <t@jollybox.de> - 2011-07-21 11:53 +0200
Re: Convert '165.0' to int Frank Millman <frank@chagford.com> - 2011-07-21 04:09 -0700
| From | Thomas Jollans <t@jollybox.de> |
|---|---|
| Date | 2011-07-21 11:53 +0200 |
| Subject | Re: Convert '165.0' to int |
| Message-ID | <mailman.1318.1311242031.1164.python-list@python.org> |
On 21/07/11 11:31, Frank Millman wrote: > Hi all > > I want to convert '165.0' to an integer. Well, it's not an integer. What does your data look like? How do you wish to convert it to int? Do they all represent decimal numbers? If so, how do you want to round them? What if you get '165.xyz' as input? Should that raise an exception? Should it evaluate to 165? Should it use base 36? > If I convert to a float first, it does work - > >>>> int(float(x)) > 165 >>>> > > Is there a short cut, or must I do this every time (I have lots of > them!) ? I know I can write a function to do this, but is there anything > built-in? What's wrong with this? It's relatively concise, and it shows exactly what you're trying to do.
[toc] | [next] | [standalone]
| From | Frank Millman <frank@chagford.com> |
|---|---|
| Date | 2011-07-21 04:09 -0700 |
| Message-ID | <0364608c-c6a1-4f97-906f-94fd79a2df79@df3g2000vbb.googlegroups.com> |
| In reply to | #10014 |
On Jul 21, 11:53 am, Thomas Jollans <t...@jollybox.de> wrote: > On 21/07/11 11:31, Frank Millman wrote: > > > Hi all > > > I want to convert '165.0' to an integer. > > Well, it's not an integer. What does your data look like? How do you > wish to convert it to int? Do they all represent decimal numbers? If so, > how do you want to round them? What if you get '165.xyz' as input? > Should that raise an exception? Should it evaluate to 165? Should it use > base 36? > > > If I convert to a float first, it does work - > > >>>> int(float(x)) > > 165 > > > Is there a short cut, or must I do this every time (I have lots of > > them!) ? I know I can write a function to do this, but is there anything > > built-in? > > What's wrong with this? It's relatively concise, and it shows exactly > what you're trying to do. I am processing an xml file from a third party, and it is full of co- ordinates in the form 'x="165.0" y="229.0"'. I don't mind using int(float(x)), I just wondered if there was a shorter alternative. If there is an alternative, I will be happy for it to raise an exception if the fractional part is not 0. Thanks Frank
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web