How to detect what type a variable is?

2006-11-29 Thread Leandro Ardissone
Hi, I want to know what type is a variable. For example, I get the contents of an xml but some content is a list or a string, and I need to know what type it is. Thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: How to detect what type a variable is?

2006-11-29 Thread Grant Edwards
On 2006-11-29, Leandro Ardissone [EMAIL PROTECTED] wrote: I want to know what type is a variable. For example, I get the contents of an xml but some content is a list or a string, and I need to know what type it is. x = 'asdf' type(x) type 'str' i = 0 type(i) type 'int' -- Grant

Re: How to detect what type a variable is?

2006-11-29 Thread Neil Cerutti
On 2006-11-29, Grant Edwards [EMAIL PROTECTED] wrote: On 2006-11-29, Leandro Ardissone [EMAIL PROTECTED] wrote: I want to know what type is a variable. For example, I get the contents of an xml but some content is a list or a string, and I need to know what type it is. x = 'asdf' type(x)

Re: How to detect what type a variable is?

2006-11-29 Thread SeanDavis12
Leandro Ardissone wrote: Hi, I want to know what type is a variable. For example, I get the contents of an xml but some content is a list or a string, and I need to know what type it is. type(variable) Sean -- http://mail.python.org/mailman/listinfo/python-list

Re: How to detect what type a variable is?

2006-11-29 Thread Leandro Ardissone
great, thanks And how I can compare this type 'str' output ? I want to decide what to do if the var is an string and what to do if not.. Tried with: if type(artistList) == type 'list': and if type(artistList) == list: but nothing.. On Nov 29, 12:41 pm, Grant Edwards [EMAIL PROTECTED] wrote:

Re: How to detect what type a variable is?

2006-11-29 Thread Leandro Ardissone
Thanks, I don't store Python objects in xml, but I get an object from a library that parses xml and converts it to objects. On Nov 29, 12:43 pm, Neil Cerutti [EMAIL PROTECTED] wrote: On 2006-11-29, Grant Edwards [EMAIL PROTECTED] wrote: On 2006-11-29, Leandro Ardissone [EMAIL PROTECTED]

Re: How to detect what type a variable is?

2006-11-29 Thread Roberto Bonvallet
Leandro Ardissone wrote: And how I can compare this type 'str' output ? I want to decide what to do if the var is an string and what to do if not.. Tried with: if type(artistList) == type 'list': and if type(artistList) == list: but nothing.. type() doesn't return a string, it

Re: How to detect what type a variable is?

2006-11-29 Thread Leandro Ardissone
great, that is just what I need! Thank you all! -- Leandro Ardissone On Nov 29, 1:29 pm, Roberto Bonvallet [EMAIL PROTECTED] wrote: Leandro Ardissone wrote: And how I can compare this type 'str' output ? I want to decide what to do if the var is an string and what to do if not..

Re: How to detect what type a variable is?

2006-11-29 Thread Daniel Klein
On 29 Nov 2006 08:25:35 -0800, Leandro Ardissone [EMAIL PROTECTED] wrote: great, thanks And how I can compare this type 'str' output ? I want to decide what to do if the var is an string and what to do if not.. Tried with: if type(artistList) == type 'list': and if type(artistList) == list:

Re: How to detect what type a variable is?

2006-11-29 Thread [EMAIL PROTECTED]
Leandro Ardissone wrote: Hi, I want to know what type is a variable. For example, I get the contents of an xml but some content is a list or a string, and I need to know what type it is. You should try to treat it as a list, catch the exceptions raise when it is a string (problably

Re: How to detect what type a variable is?

2006-11-29 Thread Luis M. González
Leandro Ardissone wrote: great, thanks And how I can compare this type 'str' output ? I want to decide what to do if the var is an string and what to do if not.. Tried with: if type(artistList) == type 'list': and if type(artistList) == list: but nothing.. You shouldn't enclose

Re: How to detect what type a variable is?

2006-11-29 Thread Grant Edwards
On 2006-11-29, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Leandro Ardissone wrote: Hi, I want to know what type is a variable. For example, I get the contents of an xml but some content is a list or a string, and I need to know what type it is. You should try to treat it as a list, catch

Re: How to detect what type a variable is?

2006-11-29 Thread Tim Chase
I want to know what type is a variable. You should try to treat it as a list, catch the exceptions raise when it is a string (problably ValueError, TypeError ou Attribute error, depends on what are you doing), and then treat it as a string. This is the BAFP (better ask for forgiveness than

Re: How to detect what type a variable is?

2006-11-29 Thread Eduardo \EdCrypt\ O. Padoan
One might prefer to check for string-ness, as strings can duck-type somewhat like lists: my_list = ['my', 'brain', 'hurts'] my_string = 'Are you the brain specialist?' for test in [my_list, my_string]: try: for thing in test: process_list_item(thing)

Re: How to detect what type a variable is?

2006-11-29 Thread Dustan
Eduardo EdCrypt O. Padoan wrote: One might prefer to check for string-ness, as strings can duck-type somewhat like lists: my_list = ['my', 'brain', 'hurts'] my_string = 'Are you the brain specialist?' for test in [my_list, my_string]: try: for thing in test:

Re: How to detect what type a variable is?

2006-11-29 Thread Calvin Spealman
On 29 Nov 2006 07:36:26 -0800, Leandro Ardissone [EMAIL PROTECTED] wrote: Hi, I want to know what type is a variable. For example, I get the contents of an xml but some content is a list or a string, and I need to know what type it is. Thanks --