Python Forum
Global variable does not seem to be global.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global variable does not seem to be global.
#3
Thanks. I need to increment the value of recNo and use it in that function to get the record. That is why I tried incrementing recNo within that function. I tried passing recNo as a parameter and then using local variable x=recNo, incrementing x and then recNo=x but have this error:

TypeError: fetchRecord() missing 1 required positional argument: 'recNo'

ef fetchRecord(recNo):
    recBox.delete(0,END)
    eName.delete(0,END)      #entry boxes
    eMeaning.delete(0,END)
    ePronounce.delete(0,END)
    ePeriod.delete(0,END)
    eGroup.delete(0,END)
    eSize.delete(0,END)
    eLived.delete(0,END)
    eDiet.delete(0,END)
    eFossils.delete(0,END)
    factFile.delete(1.0,END)    #Textbox
    
    x=recNo
    x += 1
    recNo = x
    
    conn=sqlite3.connect('dinobase.db')
    c=conn.cursor()
    c.execute('SELECT * FROM dino WHERE record = recNo')
    rows=c.fetchall()
    
    for row in rows:
        recBox.insert(0,row[0])
        eName.insert(0,row[1])
        eMeaning.insert(0,row[2])
        ePronounce.insert(0,row[3])
        ePeriod.insert(0,row[4])
        eGroup.insert(0,row[5])
        eSize.insert(0,row[6])
        eLived.insert(0,row[7])
        eDiet.insert(0,row[8])
        eFossils.insert(0,row[9])
        factFile.insert(1.0,row[10])
    
    c.close()
    conn.close()
Not the best way I guess.
Reply


Messages In This Thread
RE: Global variable does not seem to be global. - by Columbo - Jul-15-2019, 07:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesn't list require global keyword? johnywhy 9 862 Jan-15-2024, 11:47 PM
Last Post: sgrey
  It's saying my global variable is a local variable Radical 5 1,204 Oct-02-2023, 12:57 AM
Last Post: deanhystad
  Trying to understand global variables 357mag 5 1,157 May-12-2023, 04:16 PM
Last Post: deanhystad
  Why Pip is not listed in the official Global Python Module index? quazirfan 2 776 Apr-21-2023, 10:55 AM
Last Post: snippsat
  Delete all Excel named ranges (local and global scope) pfdjhfuys 2 1,822 Mar-24-2023, 01:32 PM
Last Post: pfdjhfuys
  Serial Port As Global Prasanjith 2 1,531 Mar-23-2023, 08:54 PM
Last Post: deanhystad
  global varname Skaperen 6 1,130 Mar-03-2023, 12:10 AM
Last Post: Skaperen
  Global variables or local accessible caslor 4 1,045 Jan-27-2023, 05:32 PM
Last Post: caslor
  global variables HeinKurz 3 1,169 Jan-17-2023, 06:58 PM
Last Post: HeinKurz
  How to use global value or local value sabuzaki 4 1,177 Jan-11-2023, 11:59 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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