Skip to main content
added 29 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 187

field.name is a method, you need to call it with (): field.name() is the field name.

Same as:

somelist = ['a','b']
[letter.upper for letter in somelist]
[<built-in method upper of str object at 0x000002CDB16DCDF8>, <built-in method upper of str object at 0x000002CDB16DC768>]

[letter.upper() for letter in somelist]
['A', 'B']

So your fieldnamelist is a list of methods, not fieldnames. Try:

if field.name() != fieldname:
    fieldNameList.append(field.name())

field.name is a method, field.name() is the field name.

Same as:

somelist = ['a','b']
[letter.upper for letter in somelist]
[<built-in method upper of str object at 0x000002CDB16DCDF8>, <built-in method upper of str object at 0x000002CDB16DC768>]

[letter.upper() for letter in somelist]
['A', 'B']

So your fieldnamelist is a list of methods, not fieldnames. Try:

if field.name() != fieldname:
    fieldNameList.append(field.name())

field.name is a method, you need to call it with (): field.name() is the field name.

Same as:

somelist = ['a','b']
[letter.upper for letter in somelist]
[<built-in method upper of str object at 0x000002CDB16DCDF8>, <built-in method upper of str object at 0x000002CDB16DC768>]

[letter.upper() for letter in somelist]
['A', 'B']

So your fieldnamelist is a list of methods, not fieldnames. Try:

if field.name() != fieldname:
    fieldNameList.append(field.name())
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 187

field.name is a method, field.name() is the field name.

Same as:

somelist = ['a','b']
[letter.upper for letter in somelist]
[<built-in method upper of str object at 0x000002CDB16DCDF8>, <built-in method upper of str object at 0x000002CDB16DC768>]

[letter.upper() for letter in somelist]
['A', 'B']

So your fieldnamelist is a list of methods, not fieldnames. Try:

if field.name() != fieldname:
    fieldNameList.append(field.name())