19

I have a list:

ueid_list = [['0'],['0','1'],['0','1','2']...]

corefiles(str type): {"core0.log", "core4.log","core3.log","core7.log"}

RNTI(str type):{"0x0000","0x003f",...}

The below code has a loop that iterates over the above three by taking values one after other in the function and prints details accordingly...

My code:

 for a in (ueid_list):

  for b in (corefiles):

      for c in (rnti):

          getUeLinesFromcorefiles(b,a,c)

The above getueid function is defined as:

def getUeLinesFromcorefiles(filenames, ueid, rnti)
.
.
.
.
.

This is showing an error:

as attributeerror: 'list' object has no attribute 'join'

How can I deal with this error?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dee
  • 221
  • 1
  • 2
  • 4
  • 4
    Where are you calling `join`? Post a [mcve] – UnholySheep Dec 18 '18 at 12:06
  • The order of parameters to the function `getUeLinesFromcorefiles` appears to be incorrect, should it be `getUeLinesFromcorefiles(b,a,c)`(or maybe your for loops are in the incorrect order) – Verma Dec 18 '18 at 12:09
  • If you had chosen better names than a, b, c, your calls would have been `getUeLinesFromcorefiles(ueid, corefile, rnti)`. The first error is that ueid and corefile are the wrong way round relative to the function definition. The second is that the function definition takes filenameS - are you sure you aren't supposed to pass it the whole of `corefiles` – Martin Bonner supports Monica Dec 18 '18 at 12:09
  • When i mentioned the order as getUeLinesFromcorefiles(corefiles, ueid_list, rnti) it shows an error as int() can't convert non string with explicit base at a condition in the function getUeLinesFromcorefiles() where RNTi= int(rnti, 16). – Dee Dec 18 '18 at 12:19
  • See [python - Why is it string.join(list) instead of list.join(string)?](https://stackoverflow.com/q/493819). – li ki Jul 30 '22 at 16:57

2 Answers2

68

The main question is not relevant, but the title is the error I got.

I mixed up the syntax trying to join a list of strings. I was doing this:

list_of_str.join(' ')

when I should do this:

' '.join(list_of_str)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
gannonbarnett
  • 1,638
  • 1
  • 16
  • 28
0

.join should be applied on strings. You are trying that on list. Basically, a in the for loop is a list.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abhicoding
  • 115
  • 1
  • 7