What Is The Process Of This Program Written In Python?
I have to understand the process of a program which looks like measuring the performance of multiplication for several repeat sizes.
I tried to execute the program, but there was no clue to understand it from the output. I need a help how to use this program and please let me know what are input and output of it.
import sys import numpy as np import matplotlib.pyplot as plt if len(sys.argv) != 2: print ("usage:", sys.argv, "<filename>") exit() a = np.loadtxt(sys.argv) print(a) list1, list2 = zip(*a) plt.plot(list1, list2) plt.show()
When I executed the above code, its output was below.
$ python sample.py usage: sample.py <filename>
trial following the answer
I have executed the program like below. There was no change on the code of "sample.py". How can I fix the error and what is the appropriate content in fileToRead.txt?
$ python sample.py fileToRead.txt 3.1415926535 Traceback (most recent call last): File "arrmultbysize.py", line 24, in <module> list1, list2 = zip(*a) TypeError: iteration over a 0-d array
It seems you are new to the world of programming. "sys.argv" is used to take Command Line Arguments.
- when you run as "python sample.py", the variable sys.argv will be a single element list i.e. ["sample.py"]
- len(sys.argv) is 1 in this case
The Expected Working of the program is:
- when you run as "python sample.py fileToRead.txt", the variable sys.argv will be a two element list i.e. ["sample.py","fileToRead.txt"]
- len(sys.argv) is 2 in this case
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module