float « integer « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » integer » float 

1. Python - Parse String to Float or Int    stackoverflow.com

This should be simple - In python, how can I parse a numeric string like "545.2222" to its corresponding float value, 542.2222 or "31" to an integer, 31? EDIT: I just ...

2. Python Class with integer emulation    stackoverflow.com

Given is the following example:

class Foo(object):
    def __init__(self, value=0):
        self.value=value

    def __int__(self):
       ...

3. How to get the next token (int, float or string) from a file in Python?    stackoverflow.com

Is there some way to just get the next token from a file in Python, as for example the Scanner class does in Java?

File file = new File("something");
Scanner in = new ...

4. Faster float to int conversion in Python    stackoverflow.com

Here's a piece of code that takes most time in my program, according to timeit statistics. It's a dirty function to convert floats in [-1.0, 1.0] interval into unsigned integer [0, ...

5. How to fix this python error? OverflowError: cannot convert float infinity to integer    stackoverflow.com

it gives me this error:

Traceback (most recent call last):
  File "C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Plugins\NoisePlugin.py", line 113, in onPaint
    dc.DrawLine(valueWI, valueHI, valueWF, valueHF)
  File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py", line 3177, in DrawLine
 ...

6. Python making sure x is an int, and not a pesky float    stackoverflow.com

For example:

import random
x = random.randint(1, 6)
y = 2
new = x / y
...
now, lets say x turns out to be 5. How can I catch if it's an int or a float before ...

7. Python: convert 2 ints to 32 float    stackoverflow.com

How can I combine 2 ints to a single 32bit IEEE floating point ? (each of the 2 ints represent 16 bit) And in the opposite direction: How can I transform a ...

8. Check if python int is too large to convert to float    stackoverflow.com

Is there any way to check if a long integer is too large to convert to a float in python?

9. maximum float in python    stackoverflow.com

I think the maximum integer in python is available by calling sys.maxint, whereas the maximum float or long, what is it?

10. Python changes Integer in Float by itself    stackoverflow.com

I'm trying to learn Python, (i have 2.5.4) by writing a snake game, but I'm stuck. Some integers change into floats and keep changing randomly, at least from my perspective :) The problem ...

11. How to prevent boost::python::extract from accepting int    stackoverflow.com

I'm using boost::python::extract<> to convert the items in a boost::python::list to floats. My problem is with int's in python - extract<float> seems to regard int->float as a valid conversion, however I ...

12. Do I use integer or float?    stackoverflow.com

This is the model in Google App Engine:

class Rep(db.Model):
    mAUTHOR = db.UserProperty(auto_current_user=True)
    mUNIQUE = db.StringProperty()
    mCOUNT = db.IntegerProperty()
    mDATE ...

13. Python "safe" eval (string to bool/int/float/None/string)    stackoverflow.com

I'm making a webapp that does some data processing, so I frequently find myself parsing strings (from an URL or a text file) into Python values. I use a function that is ...

14. Explain the float - int problem in factorization    stackoverflow.com

I am missing here the technical word but the problem here is either to change int to float or float to int.

def factorize(n):
    def isPrime(n):
    ...

15. Wrapping Python int/float objects    stackoverflow.com

I am working on a Python concurrency framework (I know, YACF) and would like to be able to return variables as Futures, but without the user noticing it. Right now I am ...

16. How can I convert a string to either int or float with priority on int?    stackoverflow.com

I couldn't find another answer when I wanted this, so I thought I would post my own solution for anyone else and also get corrections if I've done something wrong. I had ...

17. Checking that float modulo int is finite ordinal    stackoverflow.com

In a for-loop, I'm integrating with respect to time with constant, fractional time step, dt. I only want to save the simulation results for integral (finite ordinal) time points. My solution ...

18. Getting function object for int() and float() functions    stackoverflow.com

I want to pass a function to a function in Python. I know I can do this simply by putting the function name as a parameter, eg:

blah(5, function)
However, I want to ...

19. Python float to int conversion problem    stackoverflow.com

Basically, I'm converting a float to an int, but I don't always have the expected value. Here's the code I'm executing:

    x = 2.51

    print("--------- 251.0")
 ...

20. python: composition of `int` and `float`    stackoverflow.com

As part of some other calculations, I noticed that I sometimes apply float() and then int() function to an integer input. Is it safe to assume that:

int(float(x)) == x
if x is ...

21. How do you change a list of integers and strings into a list of integers and floats in python?    stackoverflow.com

I have a long list with a bunch of lists: [0, ['0.2000', '0.2000', '3.0000', '0.5000']] How do I make the '...' floats and keep the integers (0) integers? I've tried numpy, but it ...

22. integers when reading a csv file in python    stackoverflow.com

I'm trying to read a csv file in python, so that I can then find the average of the values in one of the columns using numpy.average. My script looks like this:

import ...

23. Python question about exponents and int    stackoverflow.com

Out of curiosity I ran the following:

>>> int(1e100)
And, the output was:
10000000000000000159028911097599180468360808563945281389781327557747838772170381060813469985856815104L
Why? Why does this not look like:
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000L
Is this a product of the int function, or of the storage of a large ...

24. does the use of an float or double instead of an int, scale?    stackoverflow.com

in other words: Is distinguishing between ints and floats as important as it use to be? if this is language dependent, I'm interested in python. EDIT : I'm also interested in learning more ...

25. python saving the excess of a float to int conversion    stackoverflow.com

x=10.5
    if x==10.5:
        x=int(x)+1
        y= .5
ok i have x=10.5 i want to round up ...

26. conversion float to long in python    stackoverflow.com

I have a function fac(n) which return n!, and I am comparing it to gamma(n+1)

>>> from math import gamma
>>> gamma(101)-fac(100)
0.0
>>> math.floor(gamma(101))-fac(100)
0.0
>>> long(gamma(101))-fac(100)
-1716052534060312817912314997891197522637580074354635372754659484313875350886868191008427848256820699487696649234627144617147818134104040275968L
gamma(101) = 100! and is an integer. why are the ...

27. How to convert a file line to a float/int in python    stackoverflow.com

Whenever I try to run this code:

    #Open file
    f = open("i.txt", "r")
    line = 1

    #Detect start point
 ...

28. Floating Point to Integer?    bytes.com

Hi all first time posting in a while sry if i mess something up. Anyway I am using 2d arrays to make a game with pygame and i alter coordinates on this array by smaller than 1 increments. Then i need to reference the coordinates in an If statement. However by this time in the program the coordinates have been altered ...

29. FLoats, strings and integers    python-forum.org

Well i wrote this: number = raw_input('Enter a number: ') int(number) float(number) str(number) print "The integer is: ", number print "The float is: ", float print "The String is: ", str but when i run the program it comes out with: clamshell:~> python number3.py Enter a number: 3 The integer is: 3 The float is: The String is:

30. Float and int...    python-forum.org

31. Function keeps being print 'int' instead of 'float'    python-forum.org

import math print "Welcome to MathApplication, the application where you can calculate several distances using formulas" def circle_area(r): return math.pi * (r ** 2) print "Do you wish to calculate the area of a circle, giving its radius? y/n" answer1 = raw_input() if answer1 == "y": r = input("What is the radius? ") ...

32. Test a string for int, float, and empty    python-forum.org

response = raw_input(prompt_phrase) response = response.strip(' ') # remove leading/trailing spaces if not response: # do something because it's blank else: try: ...

33. [Solved] : converting float to int approximately    python-forum.org

if the float result is bigger than 1.0 but not exactly 2.0 then the integer should be 2 and sequentially rounding all the following float numbers not to their integer (by int() parameter) but by their integer plus 1 if they do not meet the condition of being their own integer like 1.0 = 1 and 2.0 = 2 etc ... ...

34. string/list to float or int    python-forum.org

i have a string that looks like: a = ['5,084,900', '3,153,700', '1,086,000'] and id like to do sum them up with something like sum(a[0:3]) but i get an error like this: TypeError: unsupported operand type(s) for +: 'int' and 'str' So i tried to make "a" into floats by doing somethign like... b = floatnums = [float(i) for i in a] ...

35. how to input data of mix types (eg. float, integer)    python-forum.org

f, i = 0.0, 0 try: line = raw_input("Enter float & int:") list = line.split() if len(list) < 2: print "Bad input" else: f, i = float(list[0]), int(list[1]) except ValueError: print "Bad Input" # safely use f & i

36. subclassing int and float    python-forum.org

class Int( int): def __init__( self, pNumb): # int.__init__( self, pNumb << 10) self = ( pNumb << 10) def __str__( self): return "%2.3f" % ( self / 1024)

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.