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
  • 19,267
  • 19
  • 110
  • 137
user3000139
  • 11
  • 1
  • 3

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
  • 42,087
  • 4
  • 55
  • 81
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
  • 829
  • 2
  • 7
  • 11