Open Source Software > Open Source application software for your PC

Python online compiler

(1/1)

ayeaye:
I looked at quite a few. Then found the following, and it appeared to be good.

https://trinket.io/python/403945f28d

The code can be edited, which is the most important for the purpose. One cannot provide a standard input data, which is bad. But one can provide an input file. The solution is to name it always "input.txt". So the example that i provided earlier, that inputs and outputs a list, becomes the following.


--- Quote ---a = 1.2
f = open("input.txt")
for s in f:
   print(float(s) + a)
f.close()

--- End quote ---

What was added is only file open and file close, and the file is always the same. The black triangle above there, runs it.

ayeaye:
To get some idea, parse a csv line from oscilloscope output, using the function nextt().


--- Quote ---def nextt(sl, separator):
  endp = sl[0].find(separator)
  if (endp == -1): endp = len(sl[0])
  tok = sl[0][: endp]
  sl[0] = sl[0][endp + 1 : ]
  return tok

csv = ["-8.800000e-07,-0.0335937,27.7188,29.9703,0.00242187,,-8.800000e-07,1.40625e-06"]
while (csv[0] != ""):
  print(csv)
  print(nextt(csv, ","))

--- End quote ---

Output.


--- Quote ---['-8.800000e-07,-0.0335937,27.7188,29.9703,0.00242187,,-8.800000e-07,1.40625e-06']
-8.800000e-07
['-0.0335937,27.7188,29.9703,0.00242187,,-8.800000e-07,1.40625e-06']
-0.0335937
['27.7188,29.9703,0.00242187,,-8.800000e-07,1.40625e-06']
27.7188
['29.9703,0.00242187,,-8.800000e-07,1.40625e-06']
29.9703
['0.00242187,,-8.800000e-07,1.40625e-06']
0.00242187
[',-8.800000e-07,1.40625e-06']

['-8.800000e-07,1.40625e-06']
-8.800000e-07
['1.40625e-06']
1.40625e-06

--- End quote ---

Trinket.

https://trinket.io/python/7b6e01a541

Navigation

[0] Message Index

Go to full version