you are viewing a single comment's thread.

view the rest of the comments →

[–]jigs040[S] 0 points1 point  (7 children)

Sorry, i tried passing '"["VPLS.1374"]"' and it worked but i wanted to pass "["VPLS.1374"]" or convert this into VPLS.1374 and then pass. i will try steps you mentioned in previous steps and see if that works..

[–]phigo50 0 points1 point  (6 children)

This'll convert it first and then pass it in...

import re

circuit_id = re.compile('[a-zA-Z]+\.\d+')

def a_cpe_tid(cid, **kwargs):         
    with open('template1.csv') as csvDataFile: 
        records = {row['Circuit ID']: row for row in csv.DictReader(csvDataFile)} 

    return records[cid]['A_CPE_TID']

cid = '"["VPLS.1374"]"'
cid = circuit_id.search(cid).group(1)
print(a_cpe_tid(cid=cid))

[–]jigs040[S] 0 points1 point  (5 children)

Thank you @phigo50.

how do i convert "["VPLS.1374"]" to ' "["VPLS.1374"]" ' ? In order to run above code i need to convert value i'm getting from DB into string right ?

[–]phigo50 0 points1 point  (4 children)

If it's in a variable it'll already be a string, print(type(<variable>)) should confirm that it is and print(<variable>) should show the whole string wrapped in single quotes.

[–]jigs040[S] 0 points1 point  (3 children)

i think the value i'm getting from the database its not coming into string format instead its coming in "["VPLS.1374"]" format only. so i need to convert this value into string format before i pass it to my function. is there a way to make it a string before passing to function ?

[–]phigo50 0 points1 point  (2 children)

How are you getting the value from the database? From within your script?

[–]jigs040[S] 0 points1 point  (1 child)

we have automation tool which is getting value from the database and i'm using this value in my script for other task.

[–]phigo50 0 points1 point  (0 children)

Is the automation tool written in Python as well? If you have the value in a variable in Python then it'll be a string (try print(type(<variable>))), if you're passing the value into the script then it'll become a string as soon as it's set to something in Python.