problem with lists

Fredrik Lundh fredrik at pythonware.com
Tue Jul 6 12:36:49 EDT 1999


Peter Posselt Vestergaard wrote:
> It seems like I've completely misunderstood something or at least done
> something wrong. There's noway I can see why these two scripts are
> outputting nothing or more correctly only the 4 first lines which cannot
> be seen in a browser. Anybody knows why?

> ----script 1------------------------------------------------
>
> #!/usr/local/bin/python
> import cgi
>
> print "Content-type: text/html"
> print
>
> print "<HTML><HEAD>"
> print "<TITLE> Ændring af data </TITLE>"
> print '</HEAD><BODY BGCOLOR="#FFFFFF"><FONT FACE="Helvetica">'
>
> nydata.insert(0,'hej')

nydata must exist before you can insert things into it.
if it doesn't, you get a NameError exception (which
probably ends up somewhere in your server logs...)

by the way, you would have noticed this yourself if you
had executed this script from the command line...

anyway, to fix this, change this line to:

nydata = ['hej']

(this creates a single-item list)

> print nydata[0]
> print 'strange'

well, not really...

>
> print '</BODY></HTML>'

</F>





More information about the Python-list mailing list