[Tutor] how to convert other type to string type
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Wed, 6 Mar 2002 08:29:18 -0800 (PST)
On Wed, 6 Mar 2002, hfang wrote:
> I use MMTK(molecular module tool kit) module, I want to convert atom
> type to string type, how can I do? thank you.
In many cases, doing an 'str()' on a Python object will coerse some useful
string from a Python object:
###
>>> str([1, 2, 3])
'[1, 2, 3]'
>>> str(17)
'17'
>>> str(1+1j)
'(1+1j)'
###
Using str() may be a good solution if Atom responds well to being turned
into a string.
Also, according to the MMTK documentation:
http://starship.python.net/crew/hinsen/MMTK/Manual/MMTK_9.html
we should be able to call the fullName() method of the atom, which will
get us the get another string. There may be several strings that can be
yanked from an Atom; it depends on what you're trying to pull out.
Good luck!