Loading variable from txt
<p>I'm having problems with the following code:</p>

<pre><code>f=open('config.txt')
lines=f.readlines()
print(lines[1])
print(lines[3])
print(lines[5])
print(lines[7])
print(lines[9])
print(lines[11])

#Import and define
import serial
import time
time.sleep(5)

#Settings
Port = lines[1]
TargetMaxVoltage = float(lines[3])
TargetStartVoltage = float(lines[5])
TargetIntervalVoltage = float(lines[7])
DelayTime = float(lines[9])
LogInterval = float(lines[11])
CV = True

ser = serial.Serial(Port, 9600)
TargetStartVoltageLock = TargetStartVoltage


#Starting Settings
ser.write(b'&gt;Start\r\n')
ser.write(b'&gt;VoSet 0.5\r\n')

time.sleep(1)

ser.write(b'&gt;expMode 1\r\n')
ser.write(b'&gt;runTime 1000000000\r\n')
ser.write(b'&gt;stDly 1000000000\r\n')
ser.write(b'&gt;IoSet 1\r\n')
ser.write(b'&gt;Imax 50\r\n')
ser.write(b'&gt;Imin 1\r\n')
ser.write(b'&gt;FarEfc 1\r\n')
ser.write(b'&gt;MolMax 9999\r\n')

LogTimeInterval = "&gt;logIntv "+str(format(LogInterval, '.4f'))+"\r\n"
ser.write(LogTimeInterval.encode('utf-8'))

time.sleep(5)


#Running Method None CV Screening
while (TargetStartVoltage != TargetMaxVoltage and CV == False):
    DataSend = "&gt;VoSet "+str(format(TargetStartVoltage, '.2f'))+"\r\n"
    print (DataSend)
    ser.write(DataSend.encode('utf-8'))
    TargetStartVoltage += TargetIntervalVoltage
    time.sleep(DelayTime)


#Running Method CV Screening
CVComplete = False
while (TargetStartVoltage &lt;= TargetMaxVoltage and CV == True and CVComplete     != True):
    DataSend = "&gt;VoSet "+str(format(TargetStartVoltage, '.2f'))+"\r\n"
    print (DataSend)
    ser.write(DataSend.encode('utf-8'))
    TargetStartVoltage += TargetIntervalVoltage
    time.sleep(DelayTime)
 else:
    TargetStartVoltage -= 2*TargetIntervalVoltage
    while(TargetStartVoltageLock &lt;= TargetStartVoltage and CV == True and CVComplete != True):
        DataSend = "&gt;VoSet "+str(format(TargetStartVoltage, '.2f'))+"\r\n"
        print (DataSend)
        ser.write(DataSend.encode('utf-8'))
        TargetStartVoltage -= TargetIntervalVoltage
        time.sleep(DelayTime)
    else:
        CVComplete = True

    ser.close()
</code></pre>

<p>And I get the following error message:</p>

<blockquote>
  <p>Traceback (most recent call last):   File
  "C:\Users\Mikkel\Desktop\Python Scripts\CV_and_Screeningv100.py", line
  24, in 
      ser = serial.Serial(Port, 9600)   File "C:\Users\Mikkel\AppData\Local\Programs\Python\Python35\lib\site-packages\serial\serialwin32.py",
  line 31, in <strong>init</strong>
      super(Serial, self).<strong>init</strong>(*args, **kwargs)   File "C:\Users\Mikkel\AppData\Local\Programs\Python\Python35\lib\site-packages\serial\serialutil.py",
  line 182, in <strong>init</strong> self.open()   File
  "C:\Users\Mikkel\AppData\Local\Programs\Python\Python35\lib\site-packages\serial\serialwin32.py",
  line 62, in open raise SerialException("could not open port {!r}:
  {!r}".format(self.portstr, ctypes.WinError()))
  serial.serialutil.SerialException: could not open port 'COM11\n':<br>
  FileNotFoundError(2, 'The system cannot find the file specified.',
  None, 2)</p>
</blockquote>

<p>I'm loading the data from a txt file called 'config.txt', and it seems that it is the </p>

<p><code>Port = lines[1]</code> </p>

<p>or </p>

<pre><code>ser = serial.Serial(Port,9600)
</code></pre>

<p>that are the problem. Am I using the wrong format? I tried to introduce a 'str', 'init' and 'float', but nothing works. The data on lines[1] is COM11, which is the current port.</p>