Python Forum
Alternative to dynamic variable names
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alternative to dynamic variable names
#1
Hello !

This is a clasical example of pyvisa program:
import pyvisa
rm = pyvisa.ResourceManager()
rm.list_resources()
('ASRL1::INSTR', 'ASRL2::INSTR', 'GPIB0::12::INSTR')
inst = rm.open_resource('GPIB0::12::INSTR')
print(inst.query("*IDN?"))
Now, the problem is if I have a text file with multiple names and address of various instruments, something like this:

keithley,GPIB0::12::INSTR
lakeshore,GPIB0::11::INSTR
etc
How can I make the program from above to work without to dynamically create the variable with the name and address of each instrument from the file text?

I want to avoid this type of variable declaration:
rm = visa.ResourceManager()
vars()["lakeshore"] = rm.open_resource('GPIB0::11::INSTR')
Is possible?
Thank you!
Reply


Messages In This Thread
Alternative to dynamic variable names - by catosp - Jun-20-2020, 12:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Twilio alternative jmair 3 3,959 Feb-08-2024, 01:55 PM
Last Post: Sharmi
  dynamic variable name declaration in OOP style project problem jacksfrustration 3 879 Oct-22-2023, 10:05 PM
Last Post: deanhystad
  Pillow alternative? kucingkembar 4 949 Jul-27-2023, 10:50 AM
Last Post: Larz60+
  Alternative for Cairosvg? Maryan 0 2,495 Oct-26-2020, 01:27 PM
Last Post: Maryan
  Use dynamic variable from parallel running python script Sicksym 0 1,905 May-15-2020, 02:52 PM
Last Post: Sicksym
  Can I use iteration to create variable names? Mark17 8 6,990 Oct-17-2019, 06:05 AM
Last Post: perfringo
  another alternative to np.interp evelynow 1 2,979 Aug-22-2019, 03:32 PM
Last Post: Larz60+
  Multithreading alternative MartinV279 1 2,825 Aug-01-2019, 11:41 PM
Last Post: scidam
  Array alternative oldcity 3 3,541 Oct-01-2018, 10:03 PM
Last Post: ichabod801
  How do I create a Dynamic Variable? Nwb 1 2,787 Jun-10-2018, 11:50 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

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