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
14 8661
In article <bn************ *@ID-198839.news.uni-berlin.de>,
"Kill Bill" <bi**@kill.co m> 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.
Try typing help(dict) to the Python interpreter.
--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
In article <ma************ *************** *********@pytho n.org>,
Andrew Bennetts <an************ ***@puzzling.or g> wrote: 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
But it's almost always preferable to do
isinstance(i,fl oat)
because that allows subclasses of float to be used. If you really have
to test whether i is an unsubclassed float,
type(i) is float
would be a better choice than
type(i)==float
as it more accurately expresses the intent that only the precise float
type will be allowed.
--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
Emile van Sebille wrote: "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'>.
(Minor correction) Actually it compares it to the actual string
containing the letters "<type 'float'>", which is of course going
to get one nowhere.
The above would have worked if the OP had used
repr(type(i)) == "<type 'float'>"
but that is the absolute worst way of doing this...
-Peter
"Kill Bill" <bi**@kill.co m> writes: "KefX" <ke**********@a ol.comNOSPAM> wrote in message news:20******** *************** ****@mb-m07.aol.com...
[...] Use isinstance(), like this:
[...] Can you tell me where you found that method in the docs? I'm having trouble
[...]
Rule of thumb: If you can't find it, it's in section 2 of the library docs.
John
In article <ep************ *************** *@news.service. uci.edu>,
David Eppstein <ep******@ics.u ci.edu> wrote: In article <bn************ *@ID-198839.news.uni-berlin.de>, "Kill Bill" <bi**@kill.co m> 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.
Try typing help(dict) to the Python interpreter. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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>
|
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,...
|
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
|
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 .......
|
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)
| |
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?
|
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. ';
|
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
|
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?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |