komm irgendwie nicht dahinter.
Möchte gerne os.path.join eine unbestimmte Zahl an Ordnern übergeben.
Ich habe die Ordner in einer Liste:
Code: Alles auswählen
List=["Ordner1","Ordner2","Ordner3"]
Code: Alles auswählen
os.path.join(List)
Danke
Stolzi
Code: Alles auswählen
List=["Ordner1","Ordner2","Ordner3"]
Code: Alles auswählen
os.path.join(List)
Code: Alles auswählen
def join_(l):
p = ""
while len(l):
p = j(p, l.pop(0))
return p
Code: Alles auswählen
In [54]: reduce(os.path.join, ['a', 'b', 'c'])
Out[54]: 'a/b/c'
http://docs.python.org/ref/calls.htmlStolzi hat geschrieben:Danke! Würd es nur noch gerne verstehen :-/ i
If the syntax "*expression" appears in the function call, "expression" must evaluate to a sequence. Elements from this sequence are treated as if they were additional positional arguments; if there are postional arguments x1,...,xN , and "expression" evaluates to a sequence y1,...,yM, this is equivalent to a call with M+N positional arguments x1,...,xN,y1,...,yM.
Code: Alles auswählen
>>> a = [1,2,3] # oder auch (1,2,3)
>>> foo(*a) # identisch mit foo(1,2,3)
>>> #oder auch
>>> foo(*(1,2,3)) # Wenngleich das auch ziemlich sinnlos ist
Code: Alles auswählen
>>> def foo(*args):
return args[0] + args[-1]
>>> foo(1,2,3,4)
5
>>> foo('foo','s', 'bar')
'foobar'
>>> foo(*xrange(100000))
99999
>>>