From b3a3dc9b3f8bffc2d1c8b0e7cebe00dfcd7f145c Mon Sep 17 00:00:00 2001 From: jacques Grelet <jacques.grelet@gmail.com> Date: Wed, 13 Mar 2019 09:47:59 +0000 Subject: [PATCH] replace __getattr__ by __getitem__ --- Readme-python.txt | 6 +++++- roscop/roscop.py | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Readme-python.txt b/Readme-python.txt index 4bad544..c5ec3e0 100644 --- a/Readme-python.txt +++ b/Readme-python.txt @@ -8,8 +8,12 @@ Successfully installed pip-19.0.3 [ntird-us191-jg4:jgrelet]/c/git/python/pirata Sous Linux Ubuntu 16.04, l'upgrade de pip failed ! +--------------------------------------------------- +voir: https://askubuntu.com/questions/1025793/running-pip3-importerror-cannot-import-name-main Utiliser: > python3 -m pip install --user <package> # instead + +A tester: Then I recommend adding the following aliases to your .bashrc: pip() ( python -m pip "$@" ) pip3() ( python3 -m pip "$@" ) @@ -77,7 +81,7 @@ In setting.json: "python.autoComplete.addBrackets": true, "editor.formatOnPaste": true -Modules pYthon à intaller: +Modules Python à intaller: -------------------------- Autoformatting ---------------------- diff --git a/roscop/roscop.py b/roscop/roscop.py index 19297be..d811dd7 100644 --- a/roscop/roscop.py +++ b/roscop/roscop.py @@ -20,9 +20,9 @@ class Roscop: def __str__(self): return 'Class Roscop, file: %s, size = %d' % (self.file, len(self.hash)) - def __getattr__(self, name): + def __getitem__(self, name): ''' - overload r.key + overload r[key] ''' return self.hash[name] @@ -31,7 +31,7 @@ class Roscop: def disp(self, theKey): print("%s :" % theKey) - print(self.hash[theKey]) + print(self[theKey]) # read code roscop file def read(self): @@ -87,6 +87,5 @@ if __name__ == "__main__": for k in key: r.disp(k) - # print(r.TEMP) # r.disp('TEMP') # print(r[key]) -- GitLab