When controlling the measuring instrument with a PC, when the measured values were acquired, most of the returned values were separated by ```','` ``. It becomes a character string. Consider how to separate the strings. Let's consider the expected return value below.
result = '3.14E-3, -128.96'
By the way, this is the return of the measured value of the lock-in amplifier.
# Use slices
```python
R = result[0:7]
Th = result[9:16]
print('R:{}, Th:{}'.format(R, Th))
# R:3.14E-3, Th:-128.96
It is possible to decompose the character string by slicing and output it. However, at this time, is it malfunctioning depending on the measuring instrument? Depending on the value, there may be a space in the return value. At that time, the program stops. It's a healthy PC
result_list = result.split(',')
R = result_list[0]
Th = result_list[1]
print('R:{}, Th:{}'.format(R, Th))
# R:3.14E-3, Th:-128.96
' 3.14E-3, -128.96'Even for a return value like, this will separate it properly with a comma.
# Finally
This time, I wrote about the method of processing the return value that is often seen in measuring instruments.
To be honest, either method is OK, and I think it depends on your taste.
However, since it sometimes malfunctions and the space key is inserted, and the header peculiar to the measuring instrument is attached, I think that it is necessary to take flexible measures such as using it properly or combining it.
Recommended Posts