Re: using classes
one more question. In the code below, there are 2 init() methods, one for the class 'Fahrzeug' and one for the class 'PKW'. The program works when I instantiate the class as: fiat = PKW("Fiat Marea",50,0) but it fails if I say: *fiat = PKW("Fiat Marea",50,0,1)* *Traceback (most recent call last): File "erben_a.py", line 19, in fiat = PKW("Fiat Marea",50,0,1)TypeError: __init__() takes 4 positional arguments but 5 were given* yet the statement in *bold* matches IMO the init() method of the PKW class. Can anyone explain why? Thanks. --- class Fahrzeug: def __init__(self, bez, ge): self.bezeichnung = bez self.geschwindigkeit = ge def beschleunigen(self, wert): self.geschwindigkeit += wert def __str__(self): return self.bezeichnung + " " +str(self.geschwindigkeit) + " km/h" class PKW(Fahrzeug): def __init__(self, bez, ge, ins): super(PKW, self).__init__(bez,ge) self.insassen = ins def __str__(self): return Fahrzeug.__str__(self) + " " + str(self.insassen) + " Insassen" def einsteigen(self, anzahl): self.insassen += anzahl def aussteigen(self, anzahl): self.insassen -= anzahl fiat = PKW("Fiat Marea",50,0,1) fiat = PKW("Fiat Marea",50,0) fiat.einsteigen(3) fiat.aussteigen(1) fiat.beschleunigen(10) print(fiat) Am Do., 12. März 2020 um 17:38 Uhr schrieb Pieter van Oostrum < piete...@vanoostrum.org>: > joseph pareti writes: > > > thank you, that fixes it. I also noticed that both statements work: > > > > super(PKW, self).__init__(bez,ge) > > > > or > > > >super().__init__(bez,ge) > > The first is the required Python 2 calling (at least the first argument is > required). The second way can be used in Python 3. > -- > Pieter van Oostrum > www: http://pieter.vanoostrum.org/ > PGP key: [8DAE142BE17999C4] > -- > https://mail.python.org/mailman/listinfo/python-list > -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple comparisons in a single statement
*Chris:* Thank you for your confirmation. *All: *For the record, I meant that the tuples are all the same. The tuples I have in mind contain strings, so the issue regarding the "equality" (or otherwise) of 0 and 0.0 does not arise in my case. Stephen. To answer the question On Thu, Mar 12, 2020 at 11:26 PM John Pote wrote: > > On 12/03/2020 18:08, Chris Angelico wrote: > > On Fri, Mar 13, 2020 at 4:55 AM Stephen Tucker > wrote: > >> A quickie (I hope!). > >> > >> I am running Python 2.7.10 (and, yes, I know, support for it has been > >> withdrawn.) > > This is the same in Python 3. > > > >> I have three tuples that have been generated separately and I want to > check > >> that they are identical. all I want to do is to terminate the program > and > >> report an error if all three are not identical. > >> > >> My initial attempt to do this is to use logic of the form > >> > >> if not (mytup1 == mytup2 == mytup3): > >> raise Exception ("Tuples are not identical") > >> > >> I have tried this logic form in IDLE, and it seems to do what I want. > >> > >> Is this a reasonable way to do this, or is there a better way? > >> > > Yes absolutely! (Although, as a minor quibble, I would say "equal" > > rather than "identical" here - when you talk about identity, you're > > usually using the 'is' operator.) The meaning of chained comparisons > > is broadly equivalent to comparing the middle one against the others > > ("a==b==c" is "a==b and b==c"), which does the right thing here. > > > > It's slightly unusual to negate a query rather than using "!=", but it > > makes good sense here. > > In case anyone thinks the original expr > not (mytup1 == mytup2 == mytup3) > could be changed to > (mytup1 != mytup2!= mytup3) > remember that applying De Morgan's theorem to the original expression > would require the 'and' operation used in chained comparisons to change > to an 'or' operation (Python always does the 'and' operation in chained > comparisions). EG for simple integers instead of tuples, > > >>> not (1==1==1) > False > >>> not (2==1==1) > True > >>> (1!=1!=1) > False correct as before > >>> (2!=1!=1) > False oops! > > John > > > > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: using classes
On 2020-03-13 09:46:29 +0100, joseph pareti wrote: > The program works when I instantiate the class as: > > fiat = PKW("Fiat Marea",50,0) > > but it fails if I say: > > *fiat = PKW("Fiat Marea",50,0,1)* The __init__ method of PKW has this signature: > def __init__(self, bez, ge, ins): You are calling it with self = (the newly created object) bez = "Fiat Marea" ge = 50 ins = 0 and an extra Parameter 1, Python doesn't know what to do with that parameter, so it complains about it: Traceback (most recent call last): File "joepareti54", line 19, in fiat = PKW("Fiat Marea",50,0,1) TypeError: __init__() takes 4 positional arguments but 5 were given hp PS: Please add spaces after commas. «PKW("Fiat Marea", 50, 0, 1)» is much easier to read than «PKW("Fiat Marea",50,0,1)». -- _ | Peter J. Holzer| Story must make more sense than reality. |_|_) || | | | h...@hjp.at |-- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" signature.asc Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple comparisons in a single statement
On Fri, Mar 13, 2020 at 8:36 PM Stephen Tucker wrote: > > *Chris:* Thank you for your confirmation. > > *All: *For the record, I meant that the tuples are all the same. The > tuples I have in mind contain strings, so the issue regarding the > "equality" (or otherwise) of 0 and 0.0 does not arise in my case. > > Stephen. If you create the tuples independently, they can be equal but not identical. Example: >>> def cons(x, y): return x, y ... >>> spam = cons("foo", "bar") >>> spon = cons("foo", "bar") >>> spam == spon True >>> spam is spon False For the most part, you won't care about identity, only equality. Everything you said was correct for equality. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python question
On 3/12/20 4:19 PM, Mike Dewhirst wrote: > I'm not sure I understand what you are saying. How is gmail > behaviour breaking things? The problem is if I post to a mailing list from gmail (either the web interface or Thunderbird via Google's SMTP servers), Google will silently discard my own message when the list serv echos it back to me. In the web-based "conversation" view, Google puts my own sent message in the conversation. However via IMAP I see nothing. Thus when looking at my list mail on Thunderbird, my own messages to the list never show up. Does that make sense? There was a lot of fuss about this when gmail first started doing this, but Google ignored it and continues to ignore this issue. They regard this sort of email use as "legacy." Here's an old message describing the problem and showing Google's non-response: https://support.google.com/mail/forum/K7un8RUduyrfxS01ac/?hl=en The only way to prevent this is to send your message via a non-Gmail SMTP server, and not to put those messages in your Gmail Sent folder. This runs the risk of messages being flagged as untrustworthy, but as long as Python's smtp server accepts them, it works. Of course python's list messages going out are often flagged as suspicious because they have our own "from" addresses on them but come through Python's servers. > I do have a gmail account but don't use it. > > As background, I signed up to the Django google-group list and > traffic there arrives in my Thunderbird client. I also occasionally > use Roundcube web client for my accounts when travelling. I think > that might be a php thing. > > Maybe there is a case for developing a gmail-like web client? No the problem has nothing to do with the web interface or the client. It's a bug/feature of the Google back end. -- https://mail.python.org/mailman/listinfo/python-list
Need some GUIDE
First of all sry for asking this type of question. I started my Python journey a year ago. From then I learned a lot(Basics to advanced topics ) But when it comes to getting a job(Python related) I failed a lot. Every time I attended the recruitment process they offer python in the coding test but never took me into the python stream after getting placed in that company. PLS someone help me how to get it a job which is purely based on python -- https://mail.python.org/mailman/listinfo/python-list
Re: using classes
joseph pareti wrote: > one more question. In the code below, there are 2 init() methods, one for > the class 'Fahrzeug' and > one for the class 'PKW'. > The program works when I instantiate the class as: > > fiat = PKW("Fiat Marea",50,0) > > but it fails if I say: > > fiat = PKW("Fiat Marea",50,0,1) > > Traceback (most recent call last): > File "erben_a.py", line 19, in > fiat = PKW("Fiat Marea",50,0,1) > TypeError: __init__() takes 4 positional arguments but 5 were given > > yet the statement in bold matches IMO the init() method of the PKW class. > Can anyone explain why? > Thanks. No, the 'self' in the definition of init is the object being initialised. It is supplied by the class code that creates the new instance, not something you provide yourself. Your arguments are bez, ge, ins. class PKW(Fahrzeug): def __init__(self, bez, ge, ins): -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list
Re: pyttsx3 installation error
Got the same error here please help ERROR: Command errored out with exit status 1: command: 'c:\users\jerald lashy jeffery\appdata\local\programs\python\python38-32\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Jerald Lashy Jeffery\\AppData\\Local\\Temp\\pip-install-ej949hlq\\pyobjc-framework-AddressBook\\setup.py'"'"'; __file__='"'"'C:\\Users\\Jerald Lashy Jeffery\\AppData\\Local\\Temp\\pip-install-ej949hlq\\pyobjc-framework-AddressBook\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Jerald Lashy Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\pip-egg-info' cwd: C:\Users\Jerald Lashy Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\ Complete output (15 lines): Traceback (most recent call last): File "", line 1, in File "C:\Users\Jerald Lashy Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\setup.py", line 22, in Extension( File "C:\Users\Jerald Lashy Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\pyobjc_setup.py", line 408, in Extension os_level = get_os_level() File "C:\Users\Jerald Lashy Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\pyobjc_setup.py", line 218, in get_os_level pl = plistlib.readPlist("/System/Library/CoreServices/SystemVersion.plist") File "c:\users\jerald lashy jeffery\appdata\local\programs\python\python38-32\lib\plistlib.py", line 99, in readPlist with _maybe_open(pathOrFile, 'rb') as fp: File "c:\users\jerald lashy jeffery\appdata\local\programs\python\python38-32\lib\contextlib.py", line 113, in __enter__ return next(self.gen) File "c:\users\jerald lashy jeffery\appdata\local\programs\python\python38-32\lib\plistlib.py", line 82, in _maybe_open with open(pathOrFile, mode) as fp: FileNotFoundError: [Errno 2] No such file or directory: '/System/Library/CoreServices/SystemVersion.plist' ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. -- https://mail.python.org/mailman/listinfo/python-list
Re: pyttsx3 installation error
On 2020-03-13 19:52, jlaat...@gmail.com wrote: Got the same error here please help ERROR: Command errored out with exit status 1: command: 'c:\users\jerald lashy jeffery\appdata\local\programs\python\python38-32\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Jerald Lashy Jeffery\\AppData\\Local\\Temp\\pip-install-ej949hlq\\pyobjc-framework-AddressBook\\setup.py'"'"'; __file__='"'"'C:\\Users\\Jerald Lashy Jeffery\\AppData\\Local\\Temp\\pip-install-ej949hlq\\pyobjc-framework-AddressBook\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Jerald Lashy Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\pip-egg-info' cwd: C:\Users\Jerald Lashy Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\ Complete output (15 lines): Traceback (most recent call last): File "", line 1, in File "C:\Users\Jerald Lashy Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\setup.py", line 22, in Extension( File "C:\Users\Jerald Lashy Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\pyobjc_setup.py", line 408, in Extension os_level = get_os_level() File "C:\Users\Jerald Lashy Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\pyobjc_setup.py", line 218, in get_os_level pl = plistlib.readPlist("/System/Library/CoreServices/SystemVersion.plist") File "c:\users\jerald lashy jeffery\appdata\local\programs\python\python38-32\lib\plistlib.py", line 99, in readPlist with _maybe_open(pathOrFile, 'rb') as fp: File "c:\users\jerald lashy jeffery\appdata\local\programs\python\python38-32\lib\contextlib.py", line 113, in __enter__ return next(self.gen) File "c:\users\jerald lashy jeffery\appdata\local\programs\python\python38-32\lib\plistlib.py", line 82, in _maybe_open with open(pathOrFile, mode) as fp: FileNotFoundError: [Errno 2] No such file or directory: '/System/Library/CoreServices/SystemVersion.plist' ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. Did you try to install from PyPI? It appears that you should clone the project from GitHub. This might help: https://medium.com/better-programming/an-introduction-to-pyttsx3-a-text-to-speech-converter-for-python-4a7e1ce825c3 I haven't tried it myself. -- https://mail.python.org/mailman/listinfo/python-list
Re: Need some GUIDE
On Fri, 13 Mar 2020 at 20:06, pro_ bro wrote: > First of all sry for asking this type of question. > I started my Python journey a year ago. From then I learned a lot(Basics to > advanced topics ) Can I ask you what had motivated you? > never took me into the python stream after getting placed in that > company. And which kind of job offered to you? -- https://mail.python.org/mailman/listinfo/python-list
Profiler showing path dependency?
Consider a simple call graph: `main()` calls `foo()`, which calls `bar()`. Then `main()` calls `qux()` which also calls `bar()`, but with different parameters. When you run the above through cProfile and view the result in SnakeViz, you will see `main()` calling `foo()` and `qux()`, with each of them calling `bar()`. However, if you hover or click on `bar()`, you will see the global aggregate statistics for it. For example, the number of times it has been called, and their total time cost. Is there a way to get a path-dependent profiler breakdown for `bar()`? Specifically for this example, statistics for when it is called by `foo()`, and separately statistics for when it is called by `qux()`. -- https://mail.python.org/mailman/listinfo/python-list
Re: pyttsx3 installation error
It's a know bug. Solution: https://stackoverflow.com/a/59909885/1763602 -- https://mail.python.org/mailman/listinfo/python-list
Re: Have you some experience / link about difference between Python builded with gcc and clang?
Well, I suppose we have a winner: pyperf_bench_3_8_gcc_9_2.json = Performance version: 1.0.0 Report on Linux-4.15.0-76-generic-x86_64-with-glibc2.27 Number of logical CPUs: 4 Start date: 2020-03-13 19:36:17.585796 End date: 2020-03-13 20:35:09.605718 pyperf_bench_3_8_clang_9.json = Performance version: 1.0.0 Report on Linux-4.15.0-76-generic-x86_64-with-glibc2.27 Number of logical CPUs: 4 Start date: 2020-03-13 20:55:54.239018 End date: 2020-03-13 21:59:19.778522 +-+---+---+--+-+ | Benchmark | pyperf_bench_3_8_gcc_9_2.json | pyperf_bench_3_8_clang_9.json | Change | Significance| +=+===+===+==+=+ | 2to3| 477 ms| 527 ms | 1.11x slower | Significant (t=-210.10) | +-+---+---+--+-+ | chameleon | 13.2 ms | 15.9 ms | 1.20x slower | Significant (t=-123.35) | +-+---+---+--+-+ | chaos | 155 ms| 193 ms | 1.25x slower | Significant (t=-176.57) | +-+---+---+--+-+ | crypto_pyaes| 158 ms| 195 ms | 1.24x slower | Significant (t=-81.20) | +-+---+---+--+-+ | deltablue | 10.2 ms | 12.1 ms | 1.19x slower | Significant (t=-50.11) | +-+---+---+--+-+ | django_template | 69.4 ms | 80.9 ms | 1.17x slower | Significant (t=-77.25) | +-+---+---+--+-+ | dulwich_log | 106 ms| 113 ms | 1.06x slower | Significant (t=-62.12) | +-+---+---+--+-+ | fannkuch| 659 ms| 789 ms | 1.20x slower | Significant (t=-62.44) | +-+---+---+--+-+ | float | 165 ms| 198 ms | 1.20x slower | Significant (t=-124.75) | +-+---+---+--+-+ | genshi_text | 40.5 ms | 46.6 ms | 1.15x slower | Significant (t=-111.00) | +-+---+---+--+-+ | genshi_xml | 87.3 ms | 97.2 ms | 1.11x slower | Significant (t=-66.48) | +-+---+---+--+-+ | go | 361 ms| 434 ms | 1.20x slower | Significant (t=-136.23) | +-+---+---+--+-+ | hexiom | 14.0 ms | 16.4 ms | 1.17x slower | Significant (t=-103.53) | +-+---+---+--+-+ | html5lib| 143 ms| 157 ms | 1.10x slower | Significant (t=-14.52) | +-+---+---+--+-+ | json_dumps | 18.2 ms | 20.8 ms | 1.14x slower | Significant (t=-82.67) | +-+---+---+--+-+ | json_loads | 42.9 us | 46.0 us | 1.07x slower | Significant (t=-42.16) | +-+---+-
Re: pyttsx3 installation error
On Friday, 13 March 2020 23:45:08 UTC+2, MRAB wrote: > On 2020-03-13 19:52, jlaat...@gmail.com wrote: > > > > Got the same error here please help > > ERROR: Command errored out with exit status 1: > > command: 'c:\users\jerald lashy > > jeffery\appdata\local\programs\python\python38-32\python.exe' -c 'import > > sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Jerald Lashy > > Jeffery\\AppData\\Local\\Temp\\pip-install-ej949hlq\\pyobjc-framework-AddressBook\\setup.py'"'"'; > > __file__='"'"'C:\\Users\\Jerald Lashy > > Jeffery\\AppData\\Local\\Temp\\pip-install-ej949hlq\\pyobjc-framework-AddressBook\\setup.py'"'"';f=getattr(tokenize, > > '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', > > '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' > > egg_info --egg-base 'C:\Users\Jerald Lashy > > Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\pip-egg-info' > > cwd: C:\Users\Jerald Lashy > > Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\ > > Complete output (15 lines): > > Traceback (most recent call last): > >File "", line 1, in > >File "C:\Users\Jerald Lashy > > Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\setup.py", > > line 22, in > > Extension( > >File "C:\Users\Jerald Lashy > > Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\pyobjc_setup.py", > > line 408, in Extension > > os_level = get_os_level() > >File "C:\Users\Jerald Lashy > > Jeffery\AppData\Local\Temp\pip-install-ej949hlq\pyobjc-framework-AddressBook\pyobjc_setup.py", > > line 218, in get_os_level > > pl = > > plistlib.readPlist("/System/Library/CoreServices/SystemVersion.plist") > >File "c:\users\jerald lashy > > jeffery\appdata\local\programs\python\python38-32\lib\plistlib.py", line > > 99, in readPlist > > with _maybe_open(pathOrFile, 'rb') as fp: > >File "c:\users\jerald lashy > > jeffery\appdata\local\programs\python\python38-32\lib\contextlib.py", line > > 113, in __enter__ > > return next(self.gen) > >File "c:\users\jerald lashy > > jeffery\appdata\local\programs\python\python38-32\lib\plistlib.py", line > > 82, in _maybe_open > > with open(pathOrFile, mode) as fp: > > FileNotFoundError: [Errno 2] No such file or directory: > > '/System/Library/CoreServices/SystemVersion.plist' > > > > ERROR: Command errored out with exit status 1: python setup.py egg_info > > Check the logs for full command output. > > > Did you try to install from PyPI? It appears that you should clone the > project from GitHub. This might help: > > https://medium.com/better-programming/an-introduction-to-pyttsx3-a-text-to-speech-converter-for-python-4a7e1ce825c3 > > I haven't tried it myself. Thank you this worked for me. -- https://mail.python.org/mailman/listinfo/python-list
Re: pyttsx3 installation error
On Saturday, 14 March 2020 01:52:51 UTC+2, Marco Sulla wrote: > It's a know bug. Solution: https://stackoverflow.com/a/59909885/1763602 Thank you for your concern.I tried the above solution first and it worked as well. Thank you -- https://mail.python.org/mailman/listinfo/python-list