os.path.join and lists

Dave Swegen dswegen at allstor-sw.co.uk
Wed Oct 17 14:01:20 EDT 2001


I'm having a problem where I'm trying to use the os.path.join function
to put together a path from various elements (a list slice, a string
variable, and a fixed value). It looks somthing like this:

bar = [ "fred", "barney", "froo" ]
foo = os.path.join(bar[1:2], "bob")

This causes a type error (TypeError: can only concatenate list (not
"string") to list). Using just the bar variable doesn't work either.

Basically, I guess the question is: How do I quote the values in a list
(similiar to perl's, qw I guess)?

I would really appreciate some pointers on how to get this to work
without resorting to lengthy 'for i in bar' loops, which is the only way
I can think of to do it (which isn't perhaps surprising, as I've just
recently started using python).

Cheers
	Dave




More information about the Python-list mailing list