Skip to content

Fixes old call to sort() method - #1

Open
orestesmas wants to merge 1 commit into
gmagno:masterfrom
orestesmas:hotfix-sort
Open

Fixes old call to sort() method#1
orestesmas wants to merge 1 commit into
gmagno:masterfrom
orestesmas:hotfix-sort

Conversation

@orestesmas

Copy link
Copy Markdown

SPR 'master' fails to load raw ngspice data on python 3.6

>>> from spr import load_raw
>>> data=load_raw('SR-UWB.dat')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/....(entire path isn't relevant).../site-packages/spr/__init__.py", line 65, in load_raw
    ret["vars"].sort(cmp=lambda x, y: int(x["idx"])-int(y["idx"]))
TypeError: 'cmp' is an invalid keyword argument for this function

As stated somewhere on internet:

Technical Detail: If you’re transitioning from Python 2 and are familiar with its function of the same name, you should be aware of a >couple important changes in Python 3:

Python 3’s sorted() does not have a cmp parameter. Instead, only key is used to introduce custom sorting logic.
key and reverse must be passed as keyword arguments, unlike in Python 2, where they could be passed as positional arguments.

If you need to convert a Python 2 cmp function to a key function, then check out functools.cmp_to_key(). This tutorial will not cover any examples using Python 2.

SPR 'master' fails to load raw ngspice data on python 3.6

As stated somewhere on internet:


>Technical Detail: If you’re transitioning from Python 2 and are familiar with its function of the same name, you should be aware of a >couple important changes in Python 3:

>    Python 3’s sorted() does not have a cmp parameter. Instead, only key is used to introduce custom sorting logic.
>    key and reverse must be passed as keyword arguments, unlike in Python 2, where they could be passed as positional arguments.

>If you need to convert a Python 2 cmp function to a key function, then check out functools.cmp_to_key(). This tutorial will not cover any examples using Python 2.


>>> from spr import load_raw
>>> data=load_raw('SR-UWB.dat')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/orestes/Documents/Recerca/SuperReg/NgSpice/ngspice/lib/python3.6/site-packages/spr/__init__.py", line 65, in load_raw
    ret["vars"].sort(cmp=lambda x, y: int(x["idx"])-int(y["idx"]))
TypeError: 'cmp' is an invalid keyword argument for this function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant