Filling an array with random values
📁 python
import randomimport timeli = []tmp = 100000for i in range(0,100000): if tmp != 0: x1 = random.randint(0,tmp) li.append(x1) tmp = x1 else: breakn = 1start_time = time.clock()while n < len(li): for i in range(len(li)-n): if li[i] > li[i+
— this is the simplest way to get the output of an external command:
import subprocessoutput = subprocess.check_output(['program', 'argument 1', '2'])Everything that program outputs to standard output is saved in output. If the program exits with a non-zero return status (usually indicating an error), then check_output() will throw an exception (errors should not be implicitly ignored).
Starting from the simple case, there are many variations. For example, to get combined output from both the command's standard output stream (stdout) and the error stream (stderr), you can pass stderr=s
Log in to leave an answer