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
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
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)
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
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:
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]
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
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..
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:
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
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
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
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
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)
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:
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
--
16 matches
Mail list logo