Hi,

I'm extracting data from OpenLDAP, which needs to be formatted into hyperlinks. So far, I can print the generated HTML code:

print "<a href=\"http://users.example.com/~"; + userName + ">" + lastName + ", " + firstName + "</a>"

However I want to write each line to a file first, so that I can alphabetically sort the links by lastName, before printing them.

I've found this snippet:

# Let's create a file and write it to disk.
filename = "test.dat"
# Let's create some data:
done = 0
namelist = []
*while* *not* done:
   name = raw_input("Enter a name:")
   *if* type(name) == type(""):
       namelist.append(name)
   *else*:
       *break*
# Create a file object:
   # in "write" mode
   FILE = open(filename,"w")
   FILE.writelines(namelist)
# Alternatively
   # for name in namelist:
   #       FILE.write(name)
FILE.close() # this is icing, you can just exit and this will be
   # handled automagically.

source: http://www.penzilla.net/tutorials/python/fileio/

Going by the above snippet, I will need to write the hyperlink to a variable, e.g. name, which is in turn appended to namelist, and subsequently written to the file. How do I save this

<a href=\"http://users.example.com/~"; + userName + ">" + lastName + ", " + firstName + "</a>

to a variable, then?

Thanks

Dayo
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to