Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-24-2020, 04:11 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Example: Python - Lookup Data from CSV File Using CSV Reader

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:
Whether the user enters data from column #1 or column #2, the script will search for that data. As examples:
<< or >>
The return value will come from column #3 if a match was found in either column #1 or column #2 within the CSV file.
If a supplied input does not match any data, a different message will be displayed.
>>>

Enjoy!

--Jake
Attached Images
File Type: png FT_PyCSVPrompt1.png (4.3 KB, 4531 views)
File Type: png FT_PyCSVPrompt2.png (4.4 KB, 4474 views)
File Type: png FT_PyCSVPrompt2a.png (4.4 KB, 4480 views)
File Type: png FT_PyCSVMsg1.png (4.1 KB, 4450 views)
File Type: png FT_PyCSVPrompt2b.png (4.5 KB, 4430 views)
File Type: png FT_PyCSVMsg2.png (3.3 KB, 4530 views)
Attached Files
File Type: txt CSVReaderExample.py.txt (3.4 KB, 2507 views)
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support

Last edited by jdev; 01-24-2020 at 04:17 PM.
Closed Thread

Tags
csv , example script , python , securecrt

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:56 PM.