Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #87664 > unrolled thread

UnboundLocalError in TKinter, SQLAlchemy script.

Started byChris Kavanagh <ckava3@gmail.com>
First post2015-03-17 22:41 -0400
Last post2015-03-19 01:21 -0700
Articles 10 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  UnboundLocalError in TKinter, SQLAlchemy script. Chris Kavanagh <ckava3@gmail.com> - 2015-03-17 22:41 -0400
    Re: UnboundLocalError in TKinter, SQLAlchemy script. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-18 23:02 +1100
      Re: UnboundLocalError in TKinter, SQLAlchemy script. Chris Kavanagh <ckava3@gmail.com> - 2015-03-18 12:42 -0700
        Re: UnboundLocalError in TKinter, SQLAlchemy script. Terry Reedy <tjreedy@udel.edu> - 2015-03-18 17:37 -0400
          Re: UnboundLocalError in TKinter, SQLAlchemy script. Chris Kavanagh <ckava3@gmail.com> - 2015-03-19 01:23 -0700
            Re: UnboundLocalError in TKinter, SQLAlchemy script. Terry Reedy <tjreedy@udel.edu> - 2015-03-19 05:42 -0400
        Re: UnboundLocalError in TKinter, SQLAlchemy script. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-18 21:49 +0000
          Re: UnboundLocalError in TKinter, SQLAlchemy script. Chris Kavanagh <ckava3@gmail.com> - 2015-03-19 01:22 -0700
        Re: UnboundLocalError in TKinter, SQLAlchemy script. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-19 09:38 +1100
          Re: UnboundLocalError in TKinter, SQLAlchemy script. Chris Kavanagh <ckava3@gmail.com> - 2015-03-19 01:21 -0700

#87664 — UnboundLocalError in TKinter, SQLAlchemy script.

FromChris Kavanagh <ckava3@gmail.com>
Date2015-03-17 22:41 -0400
SubjectUnboundLocalError in TKinter, SQLAlchemy script.
Message-ID<mailman.511.1426646469.21433.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

I have a simple script that takes user input (for an Employee) such as
name, age, etc then puts in an sqlite3 database. The script worked fine
until I realized one problem. The age input field is defined in SQLAlchemy
as an Integer, so if a user inputs a string instead of a number in that
field, an error will occur (in IDLE). . .

So, I put a try: except clause in the code for the age field in the
add_data method. . .
try:
            age = self.age_var.get()
        except ValueError:
            showinfo("Error:", "Please Enter A Number In Age Field.")

If the user inputs a string (instead of an Int) the showinfo dialogue box
opens as it should, but when the user clicks "ok" in the box, I get the
error "UnboundLocalError: local variable 'age' referenced before
assignment". I tried using a default value above the try: except clause
(age=0), which corrects the error, but causes "0" to be saved in the
database instead of letting the user choose another value. I want to figure
why I get the error (with the try: except clause) and what exactly to do
about it. Thanks in advance for any help!

Here's the original code (without the try: except clause above). . .Just
put the try: except clause in the age variable in the add_data method as
shown above to get the error.

from datetime import datetime
from Tkinter import *
from tkMessageBox import *
import sqlite3, sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, DateTime, Integer, String, MetaData
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# map classes to tables through Base Class
Base = declarative_base()


class Employee(Base):
    __tablename__ = 'employee'
    id = Column(Integer, primary_key=True)
    name = Column(String(250))
    age = Column(Integer)
    address = Column(String(250))
    city = Column(String(10))
    state = Column(String(2))
    zip = Column(Integer)
    ssn = Column(String(12))
    phone = Column(String(12))
    cell = Column(String(12))

# create engine for Session connection
engine = create_engine('sqlite:///employee.db')

# create all tables in engine ('CREATE TABLE' in raw SQL)
Base.metadata.create_all(engine)

# create configured 'Session' class
Session = sessionmaker(bind=engine)

# create session
session = Session()


class GUI:
    def __init__(self, parent):
        self.parent = parent

        # create top frame
        frame = Frame(parent)
        frame.pack(expand=YES, fill=BOTH, padx=5, pady=5)

        # create bottom frame
        btm_frame = Frame(parent, relief=SUNKEN, borderwidth=1)
        btm_frame.pack(side=BOTTOM, expand=YES, fill=BOTH, padx=5, pady=5)

        # create datetime object
        d = datetime.today()
        date = d.strftime("%Y-%m-%d")


#------------------------Create Labels-------------------------------#


        # label to display date
        date_label = Label(btm_frame, text=date)
        date_label.pack(side=LEFT)

        # name label
        name_label = Label(frame, text="Enter Name:")
        name_label.grid(row=0, sticky=W)

        # age label
        age_label = Label(frame, text="Enter Age:")
        age_label.grid(row=1, sticky=W)

        # address label
        addr_label = Label(frame, text="Enter Address:")
        addr_label.grid(row=2, sticky=W)

        # city label
        city_label = Label(frame, text="Enter City:")
        city_label.grid(row=3, sticky=W)

        # state label
        state_label = Label(frame, text="Enter State:")
        state_label.grid(row=4, sticky=W)

        # zip code label
        zip_label = Label(frame, text="Enter Zip Code:")
        zip_label.grid(row=5, sticky=W)

        # ssn label
        ssn_label = Label(frame, text="Enter Social Security #:")
        ssn_label.grid(row=6, sticky=W)

        # phone label
        phone_label = Label(frame, text="Enter Phone #:")
        phone_label.grid(row=7, sticky=W)

        # cell label
        cell_label = Label(frame, text="Enter Cell #:")
        cell_label.grid(row=8, sticky=W)


#----------------------Create Vars and Entry-------------------------#


        # name variable and entry
        self.name_var = StringVar()
        self.e1 = Entry(frame, textvariable=self.name_var)
        self.e1.grid(row=0, column=1)

        # age variable and entry
        self.age_var =  IntVar()
        self.e2 = Entry(frame, textvariable=self.age_var)
        self.e2.grid(row=1, column=1)

        # address variable and entry
        self.address_var = StringVar()
        self.e3 = Entry(frame, textvariable=self.address_var)
        self.e3.grid(row=2, column=1)

        # city variable and entry
        self.city_var = StringVar()
        self.e4 = Entry(frame, textvariable=self.city_var)
        self.e4.insert(0, "Roanoke")        # insert default value
        self.e4.grid(row=3, column=1)

        # state variable and entry
        self.state_var = StringVar()
        self.e5 = Entry(frame, textvariable=self.state_var)
        self.e5.insert(0, "VA")             # insert default value
        self.e5.grid(row=4, column=1)

        # zip code variable and entry
        self.zip_var = IntVar()
        self.e6 = Entry(frame, textvariable=self.zip_var)
        self.e6.grid(row=5, column=1)

        # s.s.n variable and entry
        self.ssn_var = StringVar()
        self.e7 = Entry(frame, textvariable=self.ssn_var)
        self.e7.grid(row=6, column=1)

        # phone variable and entry
        self.phone_var = StringVar()
        self.e8 = Entry(frame, textvariable=self.phone_var)
        self.e8.grid(row=7, column=1)

        # cell variable and entry
        self.cell_var = StringVar()
        self.e9 = Entry(frame, textvariable=self.cell_var)
        self.e9.grid(row=8, column=1)

        # quit, search, clear, add, delete buttons
        quit_button = Button(btm_frame, text="Quit", relief=GROOVE,
command=parent.destroy)
        quit_button.pack(side=RIGHT)

        search_button = Button(btm_frame, text="Search", relief=GROOVE,
command=self.search)
        search_button.pack(side=RIGHT, padx=1, pady=1)

        clear_button = Button(btm_frame, text="Clear", relief=GROOVE,
command=self.clear_entries)
        clear_button.pack(side=RIGHT, padx=1, pady=1)

        del_button = Button(btm_frame, text="Delete", relief=GROOVE,
command=self.del_employee)
        del_button.pack(side=RIGHT, padx=1, pady=1)

        add_button = Button(btm_frame, text="Add", relief=GROOVE,
command=self.add_data)
        add_button.pack(side=RIGHT, padx=1, pady=1)


    def add_data(self):
        name = self.name_var.get()
        age = self.age_var.get()
        addr = self.address_var.get()
        city = self.city_var.get()
        state = self.state_var.get()
        zip = self.zip_var.get()
        ssn = self.ssn_var.get()
        phone = self.phone_var.get()
        cell = self.cell_var.get()
        # create new Employee in .db
        new_person = Employee(name=name, age=age, address=addr, city=city,
state=state, zip=zip, ssn=ssn, phone=phone, cell=cell)
        session.add(new_person)
        session.commit()
        session.close()
        self.callback()
        return

    def callback(self):
        showinfo("New Employee", "Data Added")
        self.clear_entries()
        return

    def clear_entries(self):
        entries = [self.e1, self.e2, self.e3, self.e4, self.e5, self.e6,
self.e7, self.e8, self.e9]
        for entry in entries:
            entry.delete(0, END)
        return

    def search(self):
        search_win = Toplevel()
        search_win.title("Employee Search")

        # create labels for each employee attribute
        attr =
["Id","Name","Age","Address","City","State","Zip","SSN","Cell","Phone"]
        column = 0
        for a in attr:
                Label(search_win, text=a).grid(row=0,column=column,padx=2,
pady=2)
                column += 1

        # search all employees, put each emp. in Entry Widget with For Loop
        res = session.query(Employee).all()
        row = 1
        column = 0
        for employee in res:
            txt = [employee.id, employee.name, employee.age,
employee.address, employee.city, employee.state, employee.zip,
employee.ssn, employee.phone, employee.cell]
            for t in txt:
                ent = Entry(search_win, relief=RIDGE, width=19)
                ent.grid(row=row, column=column, sticky=W, padx=1, pady=1)
                ent.insert(0, t)
                column += 1
            row += 1
            column = 0
        return

    def del_employee(self):
        del_win = Toplevel()
        del_win.title("Delete Employee")

        id_label = Label(del_win, text="Enter Employee Id:")
        id_label.grid(row=0, column=0, padx=5, pady=5)

        self.employee_id = IntVar()
        self.e10 = Entry(del_win, textvariable=self.employee_id)
        self.e10.grid(row=0, column=1, padx=5, pady=5)

        del_button = Button(del_win, text="Delete Employee", relief=GROOVE,
command=self.erase)
        del_button.grid(row=0, column=2, padx=5, pady=5)
        return

    def erase(self):
        emp_id = self.employee_id.get()
        res = session.query(Employee).filter(Employee.id==emp_id).first()
        session.delete(res)
        session.commit()
        showinfo("Employee", "Data Deleted")
        return



if __name__ == '__main__':
    root = Tk()
    root.geometry("310x270")
    root.title("Employee Info")
    mygui = GUI(root)
    root.mainloop()

[toc] | [next] | [standalone]


#87676

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-03-18 23:02 +1100
Message-ID<5509693b$0$12996$c3e8da3$5496439d@news.astraweb.com>
In reply to#87664
On Wed, 18 Mar 2015 01:41 pm, Chris Kavanagh wrote:

> I have a simple script that takes user input (for an Employee) such as
> name, age, etc then puts in an sqlite3 database. The script worked fine
> until I realized one problem. The age input field is defined in SQLAlchemy
> as an Integer, so if a user inputs a string instead of a number in that
> field, an error will occur (in IDLE). . .
> 
> So, I put a try: except clause in the code for the age field in the
> add_data method. . .
> try:
>             age = self.age_var.get()
>         except ValueError:
>             showinfo("Error:", "Please Enter A Number In Age Field.")
> 
> If the user inputs a string (instead of an Int) the showinfo dialogue box
> opens as it should, but when the user clicks "ok" in the box, I get the
> error "UnboundLocalError: local variable 'age' referenced before
> assignment".

As much as I love guessing games, I reckon I have about a 2/3 chance of
guessing right, but you will get MUCH better results by posting the
*entire* traceback, not just the last line. In particular, look at the line
of code shown. That's where the problem expresses itself, and that may give
good hints as to where the problem actually is.


> I tried using a default value above the try: except clause 
> (age=0), which corrects the error, but causes "0" to be saved in the
> database instead of letting the user choose another value. I want to
> figure why I get the error (with the try: except clause) and what exactly
> to do about it. Thanks in advance for any help!

And again, guessing games are lots of fun, but showing us the actual code is
better. You might think it is "obvious" what you are talking about, but the
change that you think is obvious and the change that I think is obvious are
not necessarily that same.

 
> Here's the original code (without the try: except clause above). . .Just
> put the try: except clause in the age variable in the add_data method as
> shown above to get the error.

We don't need to see almost 300 lines of irrelevant GUI code that has
nothing to do with the problem. Here's the add_data method:


>     def add_data(self):
>         name = self.name_var.get()
>         age = self.age_var.get()
>         addr = self.address_var.get()
>         city = self.city_var.get()
>         state = self.state_var.get()
>         zip = self.zip_var.get()
>         ssn = self.ssn_var.get()
>         phone = self.phone_var.get()
>         cell = self.cell_var.get()
>         # create new Employee in .db
>         new_person = Employee(name=name, age=age, address=addr, city=city,
>                               state=state, zip=zip, ssn=ssn, phone=phone,
>                               cell=cell) 
>         session.add(new_person)
>         session.commit()
>         session.close()
>         self.callback()
>         return

Most of that is irrelevant too. My guess is that it can be simplified to
this:

    def add_data(self):
        age = self.age_var.get()
        new_person = Employee(name=name, age=age, address=addr, city=city,
                              state=state, zip=zip, ssn=ssn, phone=phone,
                              cell=cell)


Where are we supposed to put the try: except clause? My guess is:

    def add_data(self):
        try:
            age = self.age_var.get()
        except ValueError:
            showinfo("Error:", "Please Enter A Number In Age Field.")
        new_person = Employee(name=name, age=age, address=addr, city=city,
                              state=state, zip=zip, ssn=ssn, phone=phone,
                              cell=cell)

and the error occurs on the call to Employee. Is that right? 

Follow the program logic. The line of code:

    age = self.age_var.get()

tries to run, and fails. Since the line of code never completes, "age" never
gets a value set. Then the dialog box is shown, and your program blindly
continues. Eventually it reaches the Employee() line, and tries to use the
value of "age". But it doesn't exist, so you get the UnboundLocalVariable
error.

The right solution here is to set the age_var field in the GUI to force it
to be an integer. By the time you get to running the add_data method, it is
too late to pause and let the user re-type a new value in the field. You
could try this:

http://tkinter.unpythonic.net/wiki/ValidateEntry


Another option is to make the add_data method simply halt when the age is
not an integer, and do nothing. Then the user will have to click the Add
button again to make it work:


    def add_data(self):
        try:
            age = self.age_var.get()
        except ValueError:
            showinfo("Error:", "Please Enter A Number In Age Field.")
            return  # Return early, do nothing.
        new_person = Employee(name=name, age=age, address=addr, city=city,
                              state=state, zip=zip, ssn=ssn, phone=phone,
                              cell=cell)





-- 
Steven

[toc] | [prev] | [next] | [standalone]


#87695

FromChris Kavanagh <ckava3@gmail.com>
Date2015-03-18 12:42 -0700
Message-ID<2cfe4170-5ee4-4dd9-80b2-3d7819b08e02@googlegroups.com>
In reply to#87676
On Wednesday, March 18, 2015 at 8:02:14 AM UTC-4, Steven D'Aprano wrote:
> On Wed, 18 Mar 2015 01:41 pm, Chris Kavanagh wrote:
> 
> > I have a simple script that takes user input (for an Employee) such as
> > name, age, etc then puts in an sqlite3 database. The script worked fine
> > until I realized one problem. The age input field is defined in SQLAlchemy
> > as an Integer, so if a user inputs a string instead of a number in that
> > field, an error will occur (in IDLE). . .
> > 
> > So, I put a try: except clause in the code for the age field in the
> > add_data method. . .
> > try:
> >             age = self.age_var.get()
> >         except ValueError:
> >             showinfo("Error:", "Please Enter A Number In Age Field.")
> > 
> > If the user inputs a string (instead of an Int) the showinfo dialogue box
> > opens as it should, but when the user clicks "ok" in the box, I get the
> > error "UnboundLocalError: local variable 'age' referenced before
> > assignment".
> 
> As much as I love guessing games, I reckon I have about a 2/3 chance of
> guessing right, but you will get MUCH better results by posting the
> *entire* traceback, not just the last line. In particular, look at the line
> of code shown. That's where the problem expresses itself, and that may give
> good hints as to where the problem actually is.
> 
> 
> > I tried using a default value above the try: except clause 
> > (age=0), which corrects the error, but causes "0" to be saved in the
> > database instead of letting the user choose another value. I want to
> > figure why I get the error (with the try: except clause) and what exactly
> > to do about it. Thanks in advance for any help!
> 
> And again, guessing games are lots of fun, but showing us the actual code is
> better. You might think it is "obvious" what you are talking about, but the
> change that you think is obvious and the change that I think is obvious are
> not necessarily that same.
> 
>  
> > Here's the original code (without the try: except clause above). . .Just
> > put the try: except clause in the age variable in the add_data method as
> > shown above to get the error.
> 
> We don't need to see almost 300 lines of irrelevant GUI code that has
> nothing to do with the problem. Here's the add_data method:
> 
> 
> >     def add_data(self):
> >         name = self.name_var.get()
> >         age = self.age_var.get()
> >         addr = self.address_var.get()
> >         city = self.city_var.get()
> >         state = self.state_var.get()
> >         zip = self.zip_var.get()
> >         ssn = self.ssn_var.get()
> >         phone = self.phone_var.get()
> >         cell = self.cell_var.get()
> >         # create new Employee in .db
> >         new_person = Employee(name=name, age=age, address=addr, city=city,
> >                               state=state, zip=zip, ssn=ssn, phone=phone,
> >                               cell=cell) 
> >         session.add(new_person)
> >         session.commit()
> >         session.close()
> >         self.callback()
> >         return
> 
> Most of that is irrelevant too. My guess is that it can be simplified to
> this:
> 
>     def add_data(self):
>         age = self.age_var.get()
>         new_person = Employee(name=name, age=age, address=addr, city=city,
>                               state=state, zip=zip, ssn=ssn, phone=phone,
>                               cell=cell)
> 
> 
> Where are we supposed to put the try: except clause? My guess is:
> 
>     def add_data(self):
>         try:
>             age = self.age_var.get()
>         except ValueError:
>             showinfo("Error:", "Please Enter A Number In Age Field.")
>         new_person = Employee(name=name, age=age, address=addr, city=city,
>                               state=state, zip=zip, ssn=ssn, phone=phone,
>                               cell=cell)
> 
> and the error occurs on the call to Employee. Is that right? 
> 
> Follow the program logic. The line of code:
> 
>     age = self.age_var.get()
> 
> tries to run, and fails. Since the line of code never completes, "age" never
> gets a value set. Then the dialog box is shown, and your program blindly
> continues. Eventually it reaches the Employee() line, and tries to use the
> value of "age". But it doesn't exist, so you get the UnboundLocalVariable
> error.
> 
> The right solution here is to set the age_var field in the GUI to force it
> to be an integer. By the time you get to running the add_data method, it is
> too late to pause and let the user re-type a new value in the field. You
> could try this:
> 
> http://tkinter.unpythonic.net/wiki/ValidateEntry
> 
> 
> Another option is to make the add_data method simply halt when the age is
> not an integer, and do nothing. Then the user will have to click the Add
> button again to make it work:
> 
> 
>     def add_data(self):
>         try:
>             age = self.age_var.get()
>         except ValueError:
>             showinfo("Error:", "Please Enter A Number In Age Field.")
>             return  # Return early, do nothing.
>         new_person = Employee(name=name, age=age, address=addr, city=city,
>                               state=state, zip=zip, ssn=ssn, phone=phone,
>                               cell=cell)
> 
> 
> 
> 
> 
> -- 
> Steven

While I appreciate the help greatly I thought I had put the entire traceback of the error. I was posting here and on StackOverflow, and suppose I got confused. 

 2nd, you say you "don't want to play guessing games", yet complain about "300 lines of irrelevant code", lol. Which way is it? Do you want the code, or not? How do I know what's relevant or irrelevant when I'm clearly confused? On Stack, if you don't post the entire code, you are asked to do so. I would think it would be the same procedure here.

Anyways, thanks again for the advice.

[toc] | [prev] | [next] | [standalone]


#87701

FromTerry Reedy <tjreedy@udel.edu>
Date2015-03-18 17:37 -0400
Message-ID<mailman.9.1426714650.10327.python-list@python.org>
In reply to#87695
On 3/18/2015 3:42 PM, Chris Kavanagh wrote:

> 2nd, you say you "don't want to play guessing games", yet complain
> about "300 lines of irrelevant code", lol. Which way is it? Do you
> want the code, or not? How do I know what's relevant or irrelevant
> when I'm clearly confused?

You comment out apparently irrelevant lines and see if you still have 
the same problem, and if you do, delete.  Repeat until you have a 
Minimal Complete Verifiable Example.

> On Stack, if you don't post the entire
> code, you are asked to do so. I would think it would be the same
> procedure here.

On StackOverflow, you are also asked to post a MCVE,
https://stackoverflow.com/help/mcve
not 'the entire code' you every ran.

I ignored your post because you obviously posted way, way, too much 
code, along with no stack trace.  I do the same on SO.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#87732

FromChris Kavanagh <ckava3@gmail.com>
Date2015-03-19 01:23 -0700
Message-ID<98a3ba48-f769-44c8-af24-752f94662117@googlegroups.com>
In reply to#87701
On Wednesday, March 18, 2015 at 5:37:53 PM UTC-4, Terry Reedy wrote:
> On 3/18/2015 3:42 PM, Chris Kavanagh wrote:
> 
> > 2nd, you say you "don't want to play guessing games", yet complain
> > about "300 lines of irrelevant code", lol. Which way is it? Do you
> > want the code, or not? How do I know what's relevant or irrelevant
> > when I'm clearly confused?
> 
> You comment out apparently irrelevant lines and see if you still have 
> the same problem, and if you do, delete.  Repeat until you have a 
> Minimal Complete Verifiable Example.
> 
> > On Stack, if you don't post the entire
> > code, you are asked to do so. I would think it would be the same
> > procedure here.
> 
> On StackOverflow, you are also asked to post a MCVE,
> https://stackoverflow.com/help/mcve
> not 'the entire code' you every ran.
> 
> I ignored your post because you obviously posted way, way, too much 
> code, along with no stack trace.  I do the same on SO.
> 
> -- 
> Terry Jan Reedy

Thanks. . .Understood now.

[toc] | [prev] | [next] | [standalone]


#87737

FromTerry Reedy <tjreedy@udel.edu>
Date2015-03-19 05:42 -0400
Message-ID<mailman.22.1426758206.10327.python-list@python.org>
In reply to#87732
On 3/19/2015 4:23 AM, Chris Kavanagh wrote:
> On Wednesday, March 18, 2015 at 5:37:53 PM UTC-4, Terry Reedy wrote:

>> You comment out apparently irrelevant lines and see if you still have
>> the same problem, and if you do, delete.  Repeat until you have a
>> Minimal Complete Verifiable Example.

> Thanks. . .Understood now.

I should mention that the other approach to the same end is to start a 
new 'experiment' file that starts with what might be the minimum and 
adds more only if the error is not reproduced.  I sometimes do this with 
posted SO code.  With tkinter questions, 10 lines (versus an original 
and incomplete code of, say, 50 lines) is typically enough.  Answering 
with such an MCVE, along with the usually simple fix, focuses attention 
on the particular issue

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#87703

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-03-18 21:49 +0000
Message-ID<mailman.11.1426715403.10327.python-list@python.org>
In reply to#87695
On 18/03/2015 19:42, Chris Kavanagh wrote:
>
>   2nd, you say you "don't want to play guessing games", yet complain about "300 lines of irrelevant code", lol. Which way is it? Do you want the code, or not? How do I know what's relevant or irrelevant when I'm clearly confused? On Stack, if you don't post the entire code, you are asked to do so. I would think it would be the same procedure here.
>

http://sscce.org/

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#87731

FromChris Kavanagh <ckava3@gmail.com>
Date2015-03-19 01:22 -0700
Message-ID<0888838a-ec0c-468b-b281-739bbcb56161@googlegroups.com>
In reply to#87703
On Wednesday, March 18, 2015 at 5:50:49 PM UTC-4, Mark Lawrence wrote:
> On 18/03/2015 19:42, Chris Kavanagh wrote:
> >
> >   2nd, you say you "don't want to play guessing games", yet complain about "300 lines of irrelevant code", lol. Which way is it? Do you want the code, or not? How do I know what's relevant or irrelevant when I'm clearly confused? On Stack, if you don't post the entire code, you are asked to do so. I would think it would be the same procedure here.
> >
> 
> http://sscce.org/
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Thanks. . .I've read the links and stand corrected.

[toc] | [prev] | [next] | [standalone]


#87704

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-03-19 09:38 +1100
Message-ID<5509fe6e$0$12996$c3e8da3$5496439d@news.astraweb.com>
In reply to#87695
On Thu, 19 Mar 2015 06:42 am, Chris Kavanagh wrote:

> While I appreciate the help greatly I thought I had put the entire
> traceback of the error. I was posting here and on StackOverflow, and
> suppose I got confused.

We all make mistakes. I got distracted and forgot to link you to 

http://sscce.org/

("Short, Self Contained, Correct (Compilable), Example") which might have
helped you understand where I was coming from.

I understand that when you're focused on fixing this one error, its hard to
care about the big picture, but the bigger picture is that the error you
had was actually a pretty basic problem. Learning how to debug your own
code is the most important thing we can teach you, in the sense of the old
proverb about giving a person a fish versus teaching them how to fish.

What I hope you learned from my post is:

- The traceback contains valuable debugging information, particularly 
  when it shows the actual line of code that fails. If you're not 
  reading it, you should. If you're not understanding it, you should
  ask about it.

- Most bugs are localised, and if you can isolate the bug, not only 
  do you help us to help you, but you may even solve the problem 
  yourself.

- And *least important of all*, hopefully I gave you some solutions
  to your immediate problem.


> 2nd, you say you "don't want to play guessing games", yet complain about
> "300 lines of irrelevant code", lol. Which way is it? Do you want the
> code, or not? How do I know what's relevant or irrelevant when I'm clearly
> confused? On Stack, if you don't post the entire code, you are asked to do
> so. I would think it would be the same procedure here.

I'm pretty sure that on Stackoverflow they don't insist on you posting your
entire program. What if it is 100,000 lines of code split over twenty
files? I think they ask for the same as the SSCCE site above, a minimum
sample of code which they can run and see the error themselves.

Have you got a solution to your immediate problem now, or are you still
looking for help?




-- 
Steven

[toc] | [prev] | [next] | [standalone]


#87730

FromChris Kavanagh <ckava3@gmail.com>
Date2015-03-19 01:21 -0700
Message-ID<87a23380-18fb-4030-99aa-a302eaadd665@googlegroups.com>
In reply to#87704
On Wednesday, March 18, 2015 at 6:38:48 PM UTC-4, Steven D'Aprano wrote:
> On Thu, 19 Mar 2015 06:42 am, Chris Kavanagh wrote:
> 
> > While I appreciate the help greatly I thought I had put the entire
> > traceback of the error. I was posting here and on StackOverflow, and
> > suppose I got confused.
> 
> We all make mistakes. I got distracted and forgot to link you to 
> 
> http://sscce.org/
> 
> ("Short, Self Contained, Correct (Compilable), Example") which might have
> helped you understand where I was coming from.
> 
> I understand that when you're focused on fixing this one error, its hard to
> care about the big picture, but the bigger picture is that the error you
> had was actually a pretty basic problem. Learning how to debug your own
> code is the most important thing we can teach you, in the sense of the old
> proverb about giving a person a fish versus teaching them how to fish.
> 
> What I hope you learned from my post is:
> 
> - The traceback contains valuable debugging information, particularly 
>   when it shows the actual line of code that fails. If you're not 
>   reading it, you should. If you're not understanding it, you should
>   ask about it.
> 
> - Most bugs are localised, and if you can isolate the bug, not only 
>   do you help us to help you, but you may even solve the problem 
>   yourself.
> 
> - And *least important of all*, hopefully I gave you some solutions
>   to your immediate problem.
> 
> 
> > 2nd, you say you "don't want to play guessing games", yet complain about
> > "300 lines of irrelevant code", lol. Which way is it? Do you want the
> > code, or not? How do I know what's relevant or irrelevant when I'm clearly
> > confused? On Stack, if you don't post the entire code, you are asked to do
> > so. I would think it would be the same procedure here.
> 
> I'm pretty sure that on Stackoverflow they don't insist on you posting your
> entire program. What if it is 100,000 lines of code split over twenty
> files? I think they ask for the same as the SSCCE site above, a minimum
> sample of code which they can run and see the error themselves.
> 
> Have you got a solution to your immediate problem now, or are you still
> looking for help?
> 
> 
> 
> 
> -- 
> Steven

Again,thanks for the help and sorry about the mistake(s). . .No, I'm sure if the code is "10,000" lines no one want it posted no matter what site. However, mine wasn't 10,000 lines it was a relatively small piece of code, that's why I posted it. I've been admonished on S.O. for NOT posting entire code before. Of course what I've posted in the past has been relatively short examples.

No, I don't need any further help as far as the direct question goes. It was a question I should've easily figured out myself. Unfortunately due to long work hours and me doing this in the middle of the night, I got lazy. I would like to figure out how to code this better , but haven't had time to look at your links (examples) closely yet (which is greatly appreciated).

Anyways, I thought I was doing the right thing by posting all of it. You live and you learn. I know better now, lol. Thanks to all for the help.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web