What I need it to do is check if the value of "line" is greater than "line2" however I cannot do so because they are strings which contain numbers.
Print "Check " + Name_Input + "'s " + "spies"
#Convert string to number python 2.7 code#
The code reads from two files which contain names and number after a space, it then goes on to compare them to determine what it outputs to the user: if line = line2: Print(Name_Input + " " + "actually has " + line2 + " " + "allies.") Print(Name_Input + " " + "actually has " + line2 + " " + "ally.") What I need it to do is check if the value of 'line' is greater than 'line2' however. Print(Name_Input + " " + "should have " + line + " " + "allies.") The code reads from two files which contain names and number after a space, it then goes on to compare them to determine what it outputs to the user: if line line2: print 'All good' elif line line2: print 'Check ' + NameInput + 's ' + 'spies' print ' '. The following code uses the astype () method from the NumPy library to convert a string to decimal in Python. If the width field is preceded by a zero ( '0') character, this enables zero-padding. If not specified, then the field width will be determined by the content.
width is a decimal integer defining the minimum field width. This will tell anyone using your code that you support Python 2 and 3.
#Convert string to number python 2.7 update#
Once your code works under Python 3, you should update the classifiers in your setup.py to contain Programming Language :: Python :: 3 and to not specify sole Python 2 support.
This function can take any Python data type as its parameter and return the corresponding integer value, as long as it is definable. This kind of conversion of types is known as type casting Type of variable can be determined using this function type(variable) > string 123 > type(string. Print(Name_Input + " " + "should have " + line + " " + "ally.") Use the astype () Method From the NumPy Library to Convert a String to Decimal in Python The NumPy library contains an in-built astype () method that assists in converting the data type of the given NumPy array. Changed in version 2.7: Added the ',' option (see also PEP 378 ). Update your setup.py file to denote Python 3 compatibility. The built-in int () function in Python converts a string to its corresponding integer value. I'm trying to make a program which reads from two text file line by line and stores the line which you have specified in Name_Input earlier (in variable line and line 2), it then strips off anything which is not a number from the string.