VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Example: Python - Lookup Data from CSV File Using CSV Reader (https://forums.vandyke.com/showthread.php?t=14050)

jdev 01-24-2020 04:11 PM

Example: Python - Lookup Data from CSV File Using CSV Reader
 
7 Attachment(s)
There are a number of examples showing how SecureCRT with VBScript can be used to read data from an Excel spreadsheet. However, all of these examples make use of Excel's COM API which isn't available to SecureCRT when scripting with python.

This example (CSVReaderExample.py.txt) shows how to use the native python csv reader to read data from a CSV file and perform a lookup of related data coming from the same row in the file.

Given a CSV file that looks like this...
Code:

number,name,ip-address
1,LVS,192.168.232.101
2,PRF,10.0.0.230
3,UTK,10.0.0.138
4,NIM,10.0.0.10
5,RCH,10.0.0.20

...the user will be prompted for input. For example:
https://forums.vandyke.com/attachmen...achmentid=1805
Whether the user enters data from column #1 or column #2, the script will search for that data. As examples:
https://forums.vandyke.com/attachmen...achmentid=1806 << or >> https://forums.vandyke.com/attachmen...achmentid=1807
The return value will come from column #3 if a match was found in either column #1 or column #2 within the CSV file.
https://forums.vandyke.com/attachmen...achmentid=1808
If a supplied input does not match any data, a different message will be displayed.
https://forums.vandyke.com/attachmen...achmentid=1809 >>> https://forums.vandyke.com/attachmen...achmentid=1810

Enjoy!

--Jake


All times are GMT -6. The time now is 09:51 AM.