Python Forum
name error:name 'clf' is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
name error:name 'clf' is not defined
#4
Two options, either one will require you to go through your code in some detail.
1. Don't use clf as a global. That's what I would prefer. Pass it as a parameter when needed and return it when needed.
2. Use clf as a global and get rid of it in all function calls. If it is global it does not need to be passed.

To see some of the issues you can fall into with globals, look at the following code
global clf
clf = 1
def fnc():
    clf = 3
    print(clf)
fnc()
print(clf)
Output:
3 1
So how can clf be 3 inside the function but 1 outside?
Fix is to do this:
global clf
clf = 1
def fnc():
    global clf
    clf = 3
    print(clf)
fnc()
print(clf)
Output:
3 3
Now changing clf inside the function changes it outside the function.
That is SOOO prone to mistakes that are hard to find and code that is difficult to maintain. Which is why you need to go through your code and fix the globals one way or another.
Reply


Messages In This Thread
name error:name 'clf' is not defined - by saiankith - Mar-31-2020, 07:23 AM
RE: name error:name 'clf' is not defined - by jefsummers - Mar-31-2020, 06:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 516 Nov-23-2023, 02:53 PM
Last Post: rob101
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,045 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  Error 'Contour' not Defined DaveG 3 2,283 Mar-13-2022, 03:29 AM
Last Post: deanhystad
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 3,528 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Error when refering to class defined in 'main' in an imported module HeRo 2 2,335 Apr-13-2021, 07:22 PM
Last Post: HeRo
  Why does lambda throw 'name value_o is not defined' error? karabakh 3 2,123 Dec-14-2020, 05:45 PM
Last Post: karabakh
  name error "name"is not defined MaartenRo 1 3,377 Jul-28-2020, 02:39 AM
Last Post: bowlofred
  Name Error: name 'Stockton' is not defined Pinokchu 3 2,249 Jun-13-2020, 02:48 PM
Last Post: Yoriz
  python library not defined in user defined function johnEmScott 2 3,775 May-30-2020, 04:14 AM
Last Post: DT2000
  error ,,name append is not defined'' Killdoz 1 4,984 May-24-2020, 06:23 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020