0

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.

Brad Koch
  • 17,848
  • 18
  • 106
  • 133

2 Answers2

4

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.

Daniel
  • 40,885
  • 4
  • 53
  • 79
0

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.

saudi_Dev
  • 809
  • 2
  • 7
  • 11