Jul-04-2018, 09:35 AM
Which OS are you using at work?
Newbie help
|
Jul-04-2018, 09:35 AM
Which OS are you using at work?
Jul-04-2018, 10:01 AM
You could install it following this:
Python on Windows with no admin priviledges Like one of the answers, I recommend that you try Miniconda too.
Jul-04-2018, 10:03 AM
(Jul-04-2018, 10:01 AM)gontajones Wrote: You could install it following this:It's ok, am sorted now and beavering away on v3.... :)
Hi all, thanks for your help a few weeks back, I'm still making a (very) slow foray into learning about databases via Python and have hit another stumbling block. I'm on this page:
https://www.blog.pythonlibrary.org/2012/...-tutorial/ And am at the "Basic SQLite Queries" section where I'm running this code: import sqlite3 conn = sqlite3.connect("mydatabase.db") #conn.row_factory = sqlite3.Row cursor = conn.cursor() sql = "SELECT * FROM albums WHERE artist=?" cursor.execute(sql, [("Red")]) print cursor.fetchall() # or use fetchone() print "\nHere's a listing of all the records in the table:\n" for row in cursor.execute("SELECT rowid, * FROM albums ORDER BY artist"): print row print "\nResults from a LIKE query:\n" sql = """ SELECT * FROM albums WHERE title LIKE 'The%'""" cursor.execute(sql) print cursor.fetchall()Yet, all I'm getting is an Invalid Syntax error at the first "print cursor.fetchall()" command. Any idea why, is this another old page that's using Python 2?
Jul-25-2018, 09:14 AM
in the example they use cursor.executemany, that is why they supply list of tuples.
in your case it would be cursor.execute(sql, ("Red",))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs (Jul-25-2018, 09:07 AM)dust Wrote: is this another old page that's using Python 2their post is python2 and based on using print statement, not print function - you are using python2 too
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Aug-01-2018, 11:11 AM
In reverse order...
(Jul-25-2018, 09:16 AM)buran Wrote: their post is python2 and based on using print statement, not print function - you are using python2 tooNo, I'm using Python 3, as already detailed above. buran Wrote:in the example they use cursor.executemany, that is why they supply list of tuples.Sorry, where? I can't see that anywhere in the code I listed. Forgive my ignorance but I don't know what you mean by tuples either. Newbie here. buran Wrote:Note type: WarnThere wasn't any traceback, just a popup window stating "Syntax Error", as I already said. I can't cut/paste something that doesn't exist.
Aug-01-2018, 11:24 AM
(Aug-01-2018, 11:11 AM)dust Wrote: No, I'm using Python 3, as already detailed above.if you run the above code with python3 you will get SyntaxError: Missing parentheses in call to 'print' see
(Aug-01-2018, 11:11 AM)dust Wrote: Sorry, where? I can't see that anywhere in the code I listed. Forgive my ignorance but I don't know what you mean by tuples either. Newbie here. from their code albums = [('Exodus', 'Andy Hunter', '7/9/2002', 'Sparrow Records', 'CD'), ('Until We Have Faces', 'Red', '2/1/2011', 'Essential Records', 'CD'), ('The End is Where We Begin', 'Thousand Foot Krutch', '4/17/2012', 'TFKmusic', 'CD'), ('The Good Life', 'Trip Lee', '4/10/2012', 'Reach Records', 'CD')] cursor.executemany("INSERT INTO albums VALUES (?,?,?,?,?)", albums)albums is list of tuples. as you can see they supply it to cursor.executemany() method (Aug-01-2018, 11:11 AM)dust Wrote: There wasn't any traceback, just a popup window stating "Syntax Error", as I already said. I can't cut/paste something that doesn't exist. in this code there is nothing that will pop-up. All error messages will be printed to the terminal/command prompt. In your original post you have example of traceback you get. We need the same thing for this SynatxError
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
Aug-01-2018, 11:35 AM
I'm telling you now, *no* Traceback text appears. I'd attach a screen grab if it was possible. In the main Python 3.6.2 Shell, nothing happens when I press the F5 key, it just comes with a Windows Popup that's headed "SyntaxError" and states "invalid syntax"...
|
|