Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie help
#11
Which OS are you using at work?
Reply
#12
(Jul-04-2018, 09:35 AM)gontajones Wrote: Which OS are you using at work?
Windows 7

Nevermind, got it installed now thanks to some techie help here, I'm good to go on V3... :)
Reply
#13
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.
Reply
#14
(Jul-04-2018, 10:01 AM)gontajones Wrote: 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.
It's ok, am sorted now and beavering away on v3.... :)
Reply
#15
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?
Reply
#16
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

Reply
#17
(Jul-25-2018, 09:07 AM)dust Wrote: is this another old page that's using Python 2
their 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

Reply
#18
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 too
No, 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: Warn
Post link: RE: Newbie help
Note message:
--
Please, ALWAYS post the entire traceback that you get. We need to see the whole thing. Do not just give us the last line.\r\nTake a time to read What to include in a post
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.
Reply
#19
(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
Error:
Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print something File "<stdin>", line 1 print something ^ SyntaxError: Missing parentheses in call to 'print'
(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

Reply
#20
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"...
Reply


Forum Jump:

User Panel Messages

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