[Tutor] Parse files and create sqlite3 db (Alan Gauld)

Dave Angel davea at davea.name
Wed Dec 3 15:52:05 CET 2014


On 12/03/2014 08:07 AM, jarod_v6 at libero.it wrote:
> thanks so much,here you have the error:
> ---------------------------------------------------------------------------
> NameError                                 Traceback (most recent call last)
> <ipython-input-16-64f0293cca64> in <module>()
>       43                                                 status = line[-4:] #
> and overall status pass/warn/fail
>       44                                                 sql = "insert into
> fastqc_summary(fileid,module,status,total,duplicate) values(?,?,?,?,?);"
> ---> 45                                                 data = (fileid,module,
> status,total,dup)
>       46                                                 cursor.execute(sql,
> data)
>       47                                         elif (line[:2] != ">>" and line
> [:2] != "##"): # grab details under each module
>
> NameError: name 'total' is not defined

That's because you defined it only inside an if statement.  So if that 
condition is false, total is NOT a variable.  Perhaps you just want to 
give it a default value. I'd tend to do that in an else clause:

                     if "Total Sequence" in line:
                         total = line.split()[2]
                     else:
                         total = ""

Similarly for fileid and dup.

Now, you can test those values, or use their defaults directly, in 
whatever other place you need.

While I've got you can I request a few things to make the forum go smoother:

1) use text not html messages.  You did here, but in your original 
message you mentioned something about "red" and that doesn't show up 
everywhere.  This is a text forum.

2) Use reply-list or reply-all, or whatever your email program will 
manage.  Whenever you just compose a new message you start a new thread, 
and that just breaks the flow.  Many newsreaders don't handle split 
threads, and those that do still cause pain for the user.

3) Don't use attachments.  Just paste it in with everything else (in a 
text email, of course, as html messes up indentation about 50% of the 
time.)  Many environments don't even see the attachment.

-- 
DaveA


More information about the Tutor mailing list