Python Forum
How to use a returned value?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use a returned value?
#1
Hi everybody,
I'm working on a program that involves querying a database with pyodbc and working with the results. below you will see my program, and the function I'm working with here. The end goal is to be able to work with the returned variables to be able to import/pass them along to another python program.

As you can see, the function works to connect to a database, run a query, and stores the query results in a dictionary. After that, I assign the specific dictionary keys to variables and "return" them at the end of the function. As noted above, I need to be able to import these variables (msg, destPhone, caseNum, timeStamp, sender) from another program... however when I try to print one of them (to test), I don't get any result.

Forgive me for the noobish question, but I'm new to python.. and new around here.
Thank you for your time!

def pullData():
    cnxn = pyodbc.connect('UID='+dbUser+';PWD='+dbPassword+';DSN='+dbHost)
    cursor = cnxn.cursor()

    outbound = cursor.execute("SELECT * FROM WKM_SMS_outbound ORDER BY id DESC")
    results = cursor.fetchone()
    collection = {}
    for index, outbound in enumerate(results):
        key_name = "col{0}".format(index)
        collection[key_name] = outbound

    msg = collection['col1']
    destPhone = collection['col2']
    caseNum = collection['col4']
    timeStamp = collection['col8']
    sender = collection['col10']

    cnxn.close()

    return (msg, destPhone, caseNum, timeStamp, sender)

pullData()
print(msg)
Reply


Messages In This Thread
How to use a returned value? - by t4keheart - Jan-14-2020, 10:06 PM
RE: How to use a returned value? - by joe_momma - Jan-14-2020, 11:13 PM
RE: How to use a returned value? - by ndc85430 - Jan-15-2020, 08:51 AM
RE: How to use a returned value? - by DeaD_EyE - Jan-15-2020, 09:22 AM
RE: How to use a returned value? - by perfringo - Jan-15-2020, 09:28 AM
RE: How to use a returned value? - by t4keheart - Jan-15-2020, 02:14 PM
RE: How to use a returned value? - by perfringo - Jan-15-2020, 02:39 PM
RE: How to use a returned value? - by buran - Jan-15-2020, 02:27 PM
RE: How to use a returned value? - by t4keheart - Jan-15-2020, 02:49 PM
RE: How to use a returned value? - by joe_momma - Jan-15-2020, 02:53 PM
RE: How to use a returned value? - by t4keheart - Jan-15-2020, 03:03 PM
RE: How to use a returned value? - by DeaD_EyE - Jan-15-2020, 03:23 PM
RE: How to use a returned value? - by perfringo - Jan-16-2020, 06:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to access values returned from inquirer cspower 6 1,028 Dec-26-2023, 09:34 PM
Last Post: cspower
  SQLAlchemy Object Missing when Null is returned Personne 1 1,840 Feb-19-2022, 02:50 AM
Last Post: Larz60+
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 3,795 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Libraries installed with pipenv, but ModuleNotFoundError returned jpncsu 2 3,132 Sep-06-2021, 07:24 PM
Last Post: jpncsu
  Exception: Returned Type Mismatch Error devansing 1 5,288 Mar-06-2020, 07:26 PM
Last Post: ndc85430
  Strange Characters in JSON returned string fioranosnake 4 5,366 Dec-02-2019, 07:25 PM
Last Post: fioranosnake
  Not all data returned from sys.argv ecdhyne 2 2,892 Sep-05-2019, 08:27 PM
Last Post: buran
  I always get 'None' returned. Confused. What did I miss? jpezz 2 2,450 Apr-07-2019, 10:06 AM
Last Post: jpezz
  How to resolve 404 returned from web method when not running on localhost littleGreenDude 3 3,195 Feb-05-2019, 09:01 PM
Last Post: littleGreenDude
  TypeError: __str__ returned non-string error jolinchewjb 5 10,247 Jan-24-2019, 07:54 AM
Last Post: jolinchewjb

Forum Jump:

User Panel Messages

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