[Tutor] Re: Convert list to literal string.

Derrick 'dman' Hudson dman@dman13.dyndns.org
Mon Jun 30 18:54:18 2003


--vEao7xgI/oilGqZ+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Jun 28, 2003 at 10:00:04AM -0500, David wrote:

| I can make a loop and process the info.

Dealing with the list of data is certainly doable.  You still didn't
provide the code that shows how you ended up with a list (how!?
command line arguments are strings until you parse them into something
else) so I can't explain what you are doing wrong.

Abel already reminded you of
    ','.join( ['IBM', 'EK', 'MO', 'UTX'] )

(if this helps you, then I suspect you called .split() on the command
line argument, and that's where your list came from)

[... lots and lots of snip ...]
| --addstocks  IBM,EK,MO,UTX

This is easy.  See sample (but untested) code below :


import sys
import getopt

try:
    opts, args =3D getopt.getopt(sys.argv[1:], "", ["addstocks=3D"])
except getopt.GetoptError:
    # print help information and exit:
    usage()     # Note: you have to define this function!
    sys.exit(2)

stock_labels =3D None
for o, a in opts:
    if o =3D=3D "--addstocks" :
        stock_labels =3D a

if not stock_labels :
    usage()
    sys.exit(3)

print stock_labels
print type(stock_labels)
print stock_labels.__class__  # use this with python >=3D 2.2
addstock( stock_labels )


-D

--=20
A violent man entices his neighbor
and leads him down a path that is not good.
        Proverbs 16:29
=20
http://dman13.dyndns.org/~dman/

--vEao7xgI/oilGqZ+
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj8Av3EACgkQiB6vp1xAVUAiuwCeNkrIAAt2rnOS68eJ7w4Y92h2
MIoAnjnLumBlZlLlNUqGY6BCZeprMnBu
=7tgh
-----END PGP SIGNATURE-----

--vEao7xgI/oilGqZ+--