473,789 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comparing variable types

type(i) == "<type 'float'>"
this always returns false. How come?
type(i)returns <type 'float'> if i is a float so why isn't == working?
Jul 18 '05 #1
14 8659
>type(i) == "<type 'float'>"
this always returns false. How come?
type(i)retur ns <type 'float'> if i is a float so why isn't == working?


Use isinstance(), like this:
isinstance(i, float)
This will return True if i is a float, False if not.

- Kef
Jul 18 '05 #2

"Kill Bill" <bi**@kill.co m> wrote in message
news:bn******** *****@ID-198839.news.uni-berlin.de...
type(i) == "<type 'float'>"
This compares the current type of i to type("string"), which is <type
'str'>.

You can do:
i = 1.3
type(i) == "<type 'float'>"
False str(type(i)) == "<type 'float'>" True

this always returns false. How come?
type(i)returns <type 'float'> if i is a float so why isn't == working?

What you probably want is:
import types
type(i) == types.FloatType True


Emile van Sebille
em***@fenx.com


Jul 18 '05 #3
Can you tell me where you found that method in the docs? I'm having trouble
navigating them, the java docs are so much easier to look at.

"KefX" <ke**********@a ol.comNOSPAM> wrote in message
news:20******** *************** ****@mb-m07.aol.com...
type(i) == "<type 'float'>"
this always returns false. How come?
type(i)retur ns <type 'float'> if i is a float so why isn't == working?


Use isinstance(), like this:
isinstance(i, float)
This will return True if i is a float, False if not.

- Kef

Jul 18 '05 #4
>What you probably want is:
import types
type(i) == types.FloatTypeTrue


Using isinstance() as I described earlier is probably better because I think it
works better with the idea of unifying types and classes.

- Kef
Jul 18 '05 #5
>Can you tell me where you found that method in the docs?

It's a builtin, meaning it's in module __builtin__. You'll find them in the
library reference near the top under "built-in functions" or some such.

- Kef
Jul 18 '05 #6
On Sat, Oct 25, 2003 at 10:36:03PM -0400, Kill Bill wrote:
type(i) == "<type 'float'>"
this always returns false. How come?
type(i)returns <type 'float'> if i is a float so why isn't == working?


Because "<type 'float'>" is a string :)

You want
import types
type(i) == types.FloatType

or
type(i) == type(1.0)

or in 2.2 and later you can simply do
type(i) == float

-Andrew.
Jul 18 '05 #7
On Sat, Oct 25, 2003 at 10:50:21PM -0400, Kill Bill wrote:
Can you tell me where you found that method in the docs? I'm having trouble
navigating them, the java docs are so much easier to look at.


Library Reference, section 2.1: Built-in Functions
http://python.org/doc/current/lib/built-in-funcs.html

-Andrew.
Jul 18 '05 #8
Where can I find all the methods for Dictionaries? They list some here, but
is that all of them?
http://www.python.org/doc/2.3.2/tut/...00000000000000
I think it is, but I don't like how its written. I want it to be written
you know by method, constuctors, like in the Java API. Anyone know what I'm
talking about? Its so quick to skim through the API to see which method you
are looking for. Not the case here.

"Andrew Bennetts" <an************ ***@puzzling.or g> wrote in message
news:ma******** *************** *************@p ython.org...
On Sat, Oct 25, 2003 at 10:50:21PM -0400, Kill Bill wrote:
Can you tell me where you found that method in the docs? I'm having trouble navigating them, the java docs are so much easier to look at.


Library Reference, section 2.1: Built-in Functions
http://python.org/doc/current/lib/built-in-funcs.html

-Andrew.

Jul 18 '05 #9
On Sun, Oct 26, 2003 at 12:44:20AM -0400, Kill Bill wrote:
Where can I find all the methods for Dictionaries? They list some here, but
is that all of them?
http://www.python.org/doc/2.3.2/tut/...00000000000000
I think it is, but I don't like how its written. I want it to be written
you know by method, constuctors, like in the Java API. Anyone know what I'm
talking about? Its so quick to skim through the API to see which method you
are looking for. Not the case here.


Again, you can find it in the library reference:
http://python.org/doc/current/lib/typesmapping.html

Although it isn't clear until you've read that that dictionaries are a
"mapping type", if you look in the index you'll find that both "dictionary
object" and "dictionary type, operations on" point you to that section.

I think you probably want to familiarise yourself with all of section 2 of
the Library Reference.

-Andrew.
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2978
by: Doug | last post by:
I need to compare two "address" structures within a document, and perform some action if they are not equal. The XML document is a purchase order, with an address at both the header and line item level: <Order> <Header> ... other header level stuff ... <Address>
16
2822
by: Kevin Goodsell | last post by:
What do you think is the best way to handle a compiler warning about comparing an unsigned value to a signed value? Cast to silence it? Disable that warning altogether? Or just live with it? On one hand, the warning *could* be useful. Most of the time I get it in cases where I know the comparison is safe, but it's not hard to imagine that this won't always be the case. This makes disabling it undesirable. Casting is a workable solution,...
5
3191
by: Joe Black | last post by:
Hi all, Using Windows CP Pro VS .net 2005 I'm creating an app that allows user to extend its functionality by installing plug in modules, these modules support an interface I have created called IPlugInInterface. The problem is when I come to load them I check each dll to see if supports this interface, they all return false even though when I inspect them during debugging they look the
19
2658
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor = Color.Empty then..... or if mycolor is Color.Empty then .......
20
2167
by: Bill Pursell | last post by:
This question involves code relying on mmap, and thus is not maximally portable. Undoubtedly, many will complain that my question is not topical... I have two pointers, the first of which is mmapped to a single page. I want to determine if the second is on the page. I'd like to do: #include "platform_appropriate_definition_of_PAGESIZE.h" int compare1(const char *a, const char *b)
12
6861
by: John Smith | last post by:
This code for the comparison of fp types is taken from the C FAQ. Any problems using it in a macro? /* compare 2 doubles for equality */ #define DBL_ISEQUAL(a,b) (fabs((a)-(b))<=(DBL_EPSILON)*fabs((a))) Do the same issues involved in comparing 2 fp types for equality apply to comparing a float to zero? E.g. is if(x == 0.0) considered harmful?
2
3390
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function checkInteger(&$value, $checks) { $err = ''; if (!is_numeric($value) || (floatval($value) != intval($value))) { $err .= 'Input must be an integer. ';
3
3961
by: Mike J | last post by:
Hi..need help comparing types example method istypeof(object someobj) { if (someobj=int32) } ya kinda get my idea here.... MJ
25
13062
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void *p, void *q) that will take any two pointers and decide whether they can be compared or not. I really can't think how to do this - any suggestions?
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.