Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-23-2020, 03:37 AM
Neisany Neisany is offline
Registered User
 
Join Date: Feb 2019
Posts: 14
cells from csv

Main goal:
1. open CSV file <- success
2. read column 1 and 2 and place them in a prompt <-success but may not be right
3. prompt value is then used to go to the correct row and then get column 3 ip address
4. next it will ssh. <-SSHing is not an issue.





CSV file
Code:
1 | SVL | 10..23
2 | FRP | 10..30
3 | TUK | 10..38
4 | MIN | 10..100
5 | CHR | 10..202



Code:
# $language = "python"
# $interface = "1.0"

crt.Screen.Synchronous = True

def main():
	import csv
	import os
	strHome = os.path.expanduser('~')
	strPathToFileCSV = "{0}/Documents/SecureCRT_Director_list.csv".format(strHome)
	strPathToFileCSV = strPathToFileCSV.replace('\\','/')
	
	with open(strPathToFileCSV) as objCSV:
		csv_reader = csv.reader(objCSV)
		next(csv_reader)
		varX=""
		data =str (csv_reader)
		for line in csv_reader:
			varX += line[0]+'. ' + line[1]+ '  '
		
	VarDir = crt.Dialog.Prompt(varX)
	with open(strPathToFileCSV) as objCSV:
		csv_reader = csv.reader(objCSV)
		for row in enumerate(csv_reader):
			crt.Dialog.MessageBox(str(row[1]))
		
main()
Reply With Quote
  #2  
Old 01-23-2020, 09:49 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,228
Hi Neisany,

Do you have a question? Are you seeking assistance? Or is this just something you are posting for the community?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 01-23-2020, 10:41 PM
Neisany Neisany is offline
Registered User
 
Join Date: Feb 2019
Posts: 14
Sorry I forgot to ask my questions

I need assistance in step 3. I cant seem to pick a row and a column. I know this should be a simple task but I cant seem to make it work.

essential I need the prompt value
example = 2

to look at the table and grab row 2 column 3
Reply With Quote
  #4  
Old 01-24-2020, 07:23 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,228
Hi Neisany,

That's more Excel/Python than it is SecureCRT.

Take a look at the newly posted example from our script examples "sticky":
Example: Python - Lookup Data from CSV File Using CSV Reader
It should provide you with an example of accomplishing something similar to what you need.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730

Last edited by jdev; 01-24-2020 at 04:17 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 05:10 AM.