Reputation: 11
I am new to python. This code is from "Dive Into Python" by Mark Pilgrim, it appears that join() is being called with 2 args, it works fine:
dirname="/usr/"
[f for f in os.listdir(dirname) if os.path.isdir(os.path.join(dirname,f))]
But if you try:
smthn="data"
smthnelse="otherdata"
print "\n".join(smthn,smthnelse)
We get an error that join() can take only one argument.
Upvotes: 0
Views: 3404
Reputation: 839
Look Using str.join() like this:
smthn="data"
smthnelse="otherdata"
print( "\n",smthn.join(smthnelse) )
Because you are put smthnelse between the spaces in smthn >>"data"
os.path.join() not look like str.join
the second for string and seq and the first only for File System paths.
Upvotes: 0
Reputation: 42748
os.path.join
takes as arguments an arbitrary number of strings, str.join
instead takes as one argument a iterable providing strings. These two functions are individual functions.
Upvotes: 4