On Nov 8, 2019, at 04:19, yejus...@163.com wrote:
> 
> (2) Using semicolons as a flag to make a better integration of a List-like 
> data type and Numpy. The Python interpreter will check whether the numpy 
> library is installed. If not, it will stop running and remind the user to 
> install it.  The expected syntax:
>       c = [1,2,3;]   or c = [1 2 3;] or c = [1 2 3]  
>       Notice the semicolon after the last number. If numpy is found, c will 
> be parsed as a Numpy ndarray. All these forms  are equivelent to c = 
> np.array([1,2,3]). For a vector, the semicolon is the key for Python to parse 
> it as a Numpy ndarray.
> 
>       d=[1,2,3;4,5,6] or d=[1,2,3;4,5,6;] or d=[1 2 3;4 5 6] or d=[1 2 3;4 5 
> 6;] 
>       Notice the semicolons. If numpy is found, d will be parsed as a Numpy 
> ndarray. All these forms  are equivelent to d=np.array([[1,2,3],[4,5,6]])

What about this?

    def A(*values, **kw):
        return np.array(values, **kw)

And now:

    c = A(1,2,3)
    d = A([1,2,3], [4,5,6])

Same number of characters, no custom parsing, no weird trailing semicolon that 
looks like noise to the reader, no need for any change to Python itself, just 
define the one-liner wherever you want to use it, and you can use it.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/YAYRL4MEGK2XZSJO5CKL6XEVMVFZT454/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to