Oct-13-2016, 03:39 AM
(Oct-13-2016, 01:15 AM)wavic Wrote: How about this? It should work. More information.
Actually, CTRL+SHIFT+V should be browser specific.
The first does not work. At least not as expected
I added that then the code is
<pre class="brush: python">valid</pre><br><pre class="brush: python">=</pre><br><pre class="brush: python">"1234567890"</pre><br><pre class="brush: python">some stuff (flushing rangefinder, read RF data, etc)</pre><br><pre class="brush: python">data2</pre><br><pre class="brush: python">=</pre><br><pre class="brush: python">self</pre><br><pre class="brush: python">.RF.readline() </pre><br><pre class="brush: python"># read the rangefinder</pre><br><pre class="brush: python">Rnge2 </pre><br><pre class="brush: python">=</pre><br><br><pre class="brush: python">str</pre><br><pre class="brush: python">(data2)[</pre><br><pre class="brush: python">str</pre><br><pre class="brush: python">(data2).index(</pre><br><pre class="brush: python">'R'</pre><br><pre class="brush: python">)</pre><br><pre class="brush: python">+</pre><br><pre class="brush: python">1</pre><br><pre class="brush: python">:</pre><br><pre class="brush: python">str</pre><br><pre class="brush: python">(data2).index(</pre><br><pre class="brush: python">'R'</pre><br><pre class="brush: python">)</pre><br><pre class="brush: python">+</pre><br><pre class="brush: python">5</pre><br><pre class="brush: python">] </pre><br><pre class="brush: python">#strips down to 4 numbers</pre><br><pre class="brush: python">Rnge2 </pre><br><pre class="brush: python">=</pre><br><br><pre class="brush: python">Rnge2.replace(</pre><br><pre class="brush: python">"'"</pre><br><pre class="brush: python">,"") </pre><br><pre class="brush: python">#removes any single quotes</pre><br><pre class="brush: python">while</pre><br><br><pre class="brush: python">True</pre><br><pre class="brush: python">:</pre><br><pre class="brush: python"> </pre><br><pre class="brush: python">if</pre><br><br><pre class="brush: python">not</pre><br><br><pre class="brush: python">set</pre><br><pre class="brush: python">(Rnge2).issubset(valid): </pre><br><pre class="brush: python">#check for invalid chars - S/B only numerics</pre><br><pre class="brush: python"> </pre><br><pre class="brush: python">Rnge </pre><br><pre class="brush: python">=</pre><br><br><pre class="brush: python">'9000'</pre><br><pre class="brush: python"> </pre><br><pre class="brush: python">break</pre><br><pre class="brush: python"> </pre><br><pre class="brush: python">if</pre><br><br><pre class="brush: python">Rnge2 </pre><br><pre class="brush: python">=</pre><br><pre class="brush: python">=</pre><br><br><pre class="brush: python">'</pre><br><pre class="brush: python">' : #issubset won'</pre><br><pre class="brush: python">t catch this</pre><br><pre class="brush: python"> </pre><br><pre class="brush: python">Rnge </pre><br><pre class="brush: python">=</pre><br><br><pre class="brush: python">'9000'</pre><br><pre class="brush: python"> </pre><br><pre class="brush: python">break</pre><br><pre class="brush: python"> </pre><br><pre class="brush: python">if</pre><br><br><pre class="brush: python">int</pre><br><pre class="brush: python">(Rnge2) > </pre><br><pre class="brush: python">1000</pre><br><br><pre class="brush: python">: </pre><br><pre class="brush: python">#I get the error here</pre><br><pre class="brush: python"> </pre><br><pre class="brush: python">Rnge </pre><br><pre class="brush: python">=</pre><br><br><pre class="brush: python">'9000'</pre>when it should be this
valid="1234567890" some stuff (flushing rangefinder, read RF data, etc) data2=self.RF.readline() # read the rangefinder Rnge2 = str(data2)[str(data2).index('R')+1:str(data2).index('R')+5] #strips down to 4 numbers Rnge2 = Rnge2.replace("'","") #removes any single quotes while True: if not set(Rnge2).issubset(valid): #check for invalid chars - S/B only numerics Rnge = '9000' break if Rnge2 == '' : #issubset won't catch this Rnge = '9000' break if int(Rnge2) > 1000 : #I get the error here Rnge = '9000'
Recommended Tutorials: