Python Forum
How to pass variable as an argument to be used in a function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to pass variable as an argument to be used in a function?
#1
Hi everyone,
I'm new to python for forgive me if my fundamental idea of this concept is way off.

I have 2 python programs. One of them contains the following function. It's purpose being to connect to a db and run a query. I want to be able to pass some variable to it, and use the variables contained value in the sql query (note the ** portion of query):
def updateSent():
    cnxn = pyodbc.connect('UID='+dbUser+';PWD='+dbPassword+';DSN='+dbHost)
    cursor = cnxn.cursor()
    update_stmt = "UPDATE WKM_sms_outbound SET status = 'sent' WHERE msg_id = **value from msgId variable**"
    cursor.execute(update_stmt)
Then be able to call it from program 2 like this:
from program1 import updateSent
updateSent(msgId)
Is this possible? I'd imagine that I'm doing it incorrectly, but have googled for a while now and am unable to find exactly what I'm looking for.

Thank you in advance.
Reply


Messages In This Thread
How to pass variable as an argument to be used in a function? - by t4keheart - Jan-15-2020, 07:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable for the value element in the index function?? Learner1 8 665 Jan-20-2024, 09:20 PM
Last Post: Learner1
  mutable argument in function definition akbarza 1 488 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 594 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,323 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 949 Aug-07-2023, 05:58 PM
Last Post: Karp
  How to pass encrypted pass to pyodbc script tester_V 0 867 Jul-27-2023, 12:40 AM
Last Post: tester_V
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,100 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 1,876 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  Retrieve variable from function labgoggles 2 1,055 Jul-01-2022, 07:23 PM
Last Post: labgoggles
  Pass variable to subprocess paulo79 4 10,104 Apr-12-2022, 12:35 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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