[Tutor] Python in Vertica

Dave Angel d at davea.name
Wed Sep 12 00:33:03 CEST 2012

A couple of points of order:  please do a reply-all, or equivalent, so
your response goes to the forum, and not just to one person.  or you can
add tutor at python.org to it, if that seem easier.

Also, please don't top-post on the forum, unless you're deleting all
context.  And you usually shouldn't delete all of it, just the parts
that aren't relevant.

On 09/11/2012 09:18 AM, C.L. Shetline wrote:
>>> If you're claiming that's coming from the above print statement (after
> fixing the syntax error), then the variable number_of_rows is NOT a long
> or an int.  Perhaps it's a string.  Without knowing that, we can't tell
> you the best way to fix it.
> Yes, it is coming from the print (claiming? Would I lie about that?). And no, there was not a syntax error, it was a

Not lie, but you might have been mistaken.  Now that I see all the code,
I know you were not mistaken.

> cut and paste error.

Since only part of the line was included, it gives a syntax error. Now
that I see the whole line, I realize what happened.  See below.

> This is the entire small test script:
> #!/usr/bin/python
> import pyodbc
> import time
> import os
> import sys
> cnstr = "DSN=dwprod;PWD=S at 1b@b at 18;Charset=UTF-8"
> targetSchema = 'public'
> cnxn = pyodbc.connect(cnstr, autocommit=False)
> cursor = cnxn.cursor()
> cursor.execute("SELECT COUNT(*) from cv_gls_wkly_misc")
> result = cursor.fetchone()
> number_of_rows = result[0]
> print `number_of_rows`

Here you're using a deprecated form of syntax.  The backquotes mean to
call repr() on the object inside.  The repr() function tries to give you
enough characters that you could reproduce the object.

Just remove the backquotes, and you won't see the trailing L.

    print number_of_rows

> cursor.execute('SELECT * FROM cv_gls_wkly_misc where period_gen_key = 5185')
> print cursor.fetchall()
> cursor.close()
> cnxn.close()
> It is executed from the command line:
> vertica1:dbadmin:/pro/COLEGIFT/source/fix/cece/sistest> ./sisupd1.py
> 4L
> [(5185L, 93L, Decimal("42.50"), Decimal("50.36"), Decimal("3406.35"), Decimal("0"), Decimal("78.00"), Decimal("0"), Decimal("66.00"), Decimal("0"), Decimal("12.73"), Decimal("0"), Decimal("0"), Decimal("311.00"))]
> I do not know why it is printing a data type along with the value. I do not know if this is a Python issue or a Vertica issue.
> Regards,
> CVez



More information about the Tutor mailing list