interpreter - Why is a part of my Python code interpreted diffently when I add a seemingly unrelated part? -


some background: i'm implementing gui interact equipment via gpib. issue arises in method:

from tkinter import * tkinter import ttk import visa #pyvisa package. pyvisa.readthedocs.io time import sleep import numpy np #numpy package. scipy.org  def onedsweep(): voltage =[] current =[] source = [] try:     #gate = parsegate(gate1input.get()) #not implemented yet.     min = float(gate1mininput.get()) #add check valid input     #if min < .001:             #throw exception     max = float(gate1maxinput.get()) #add check valid input     voltageinterval = .02 #prompt user interval?     rm = visa.resourcemanager()     sim900 = rm.open_resource("gpib0::1::instr") #add check session open.      x = 0     volt = min     while volt <= max:         sim900.write("sndt 1, 'volt " + str(volt) + "'") #set voltage.         sim900.write("sndt 7, 'volt? 1'") #ask port voltage.         vnow = sim900.query("getn? 7, 50") #retrieve data previous port.         vnow = vnow[6:15]         vnow = float(vnow) ############error location         voltage = np.append(voltage, vnow)          sim900.write("sndt 1, 'volt?'") #ask different port voltage.         snow = sim900.query("getn? 1, 50") #retrieve data.         print(snow) #debugging method. not problematic.         snow = snow[4:]         snow = float(snow)          sleep(1) #add delay science reasons.         #the code below helps while loop act loop.         x = x+1         volt = min + voltageinterval*x         volt = float(truncate(volt, 7))  finally:     print(voltage)     print(source)     voltage.tofile("output.txt.",sep=",")     sim900.write("flsh")#flush ports' memories ensure no bad data stays there. 

i simple valueerror @ marked location during first pass of while loop; python says cannot convert string float(more on later). however, remove these 5 lines of code:

    sim900.write("sndt 1, 'volt?'")     snow = sim900.query("getn? 1, 50")     print(snow)     snow = snow[4:]     snow = float(snow) 

and program runs perfectly. understand source of error. lines added, when send these 2 lines instrument:

    sim900.write("sndt 7, 'volt? 1'")     vnow = sim900.query("getn? 7, 50") 

i null error. #3000 returned, blank message machine sends when asked output data , has none output. however, these same 2 lines produce #3006 00.003 when 4 lines mentioned excluded program. in other words, adding 4 lines program has changed message sent instrument @ beginning of while loop, despite adding them near end.

i convinced python's interpreter @ fault here. earlier, cleaning code , discovered 1 particular set of quotes, when changed ' ", produced same error, despite no other quote pair exhibiting behavior, within same line. question is, why execution of code change dependent upon unrelated alterations code(would appreciate fix)? understand problem difficult replicate given specific application, if there more information helpful can provide, please let me know.

edit: functionality has improved after moving command prompt idle. i'm still baffled happened, due meager command prompt skills, can't provide proof. please close question.

python telling wrong code -- valueerror. gives exact line number , value causing problem.

'#3006 00.003' 

that value of snow being printed out. this

snow = snow[4:] 

now snow is

'6 00.003' 

you try call float() on string. 6 00.003 can't converted float because it's nonsensical number.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -