Re: A trivial question that I don't know - document a function/method
Am Sat, Oct 22, 2022 at 09:49:55PM -0400 schrieb Thomas Passin: > def make_title_from_headline(self, p, h): > """From node title, return title with over- and underline- strings. ... >RETURNS >a string > """ > def plot(self, stackposition=MAIN, clearFirst=True): > """Plot a 2-D graph. ... > RETURNS > nothing > """ Would it not, these days, be clearer to def make_title_from_headline(self, p, h) -> str: def plot(self, stackposition=MAIN, clearFirst=True) -> None: and use RETURNS (or Returns:) only when what is returned warrants further explanation (say, as to what is returned when). Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list
Update from 3.9 to 3.10.8 and uninstall 3.9
I am new to python and wish to update 3.9 to3.10.8 which I have downloaded. How do I replace 3.9 with the 3.10.8 I downloaded. Kind regards JohnGee -- https://mail.python.org/mailman/listinfo/python-list
need help
How to fix Traceback (most recent call last):
File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\socket.py",
line 833, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the
connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\i9shu\Downloads\python email bot\email bot.py", line 25,
in
server = smtplib.SMTP('smtp.gmail.com',2525)
File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\smtplib.py",
line 255, in __init__
(code, msg) = self.connect(host, port)
File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\smtplib.py",
line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\smtplib.py",
line 312, in _get_socket
return socket.create_connection((host, port), timeout,
File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\socket.py",
line 833, in create_connection
sock.connect(sa)
KeyboardInterrupt
Process finished with exit code -1073741510 (0xC13A: interrupted by
Ctrl+C)
eorr
Sent from [1]Mail for Windows
References
Visible links
1. https://go.microsoft.com/fwlink/?LinkId=550986
--
https://mail.python.org/mailman/listinfo/python-list
Typing: Is there a "cast operator"?
Hello! I am in the process of "typing" of some of my scripts. Using it should help a lot to avoid some errors. But this is new for me and I'm facing some problems. Let's I have the following code (please don't look at the program content): f=None # mypy naturally assumes Optional(int) because later, at open, it is assigned an int. .. if f is None: f=os.open(... .. if f is not None: os.write(f, ...) .. if f is not None: os.close(f) When I use mypy, it claims Argument 1 to "write" has incompatible type "Optional[int]"; expected "int" Argument 1 to "close" has incompatible type "Optional[int]"; expected "int" How to solve this? Is there a way to specify that when calling os.open f is an int only? I use None a lot for specify uninitialized vars. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
score function in linear regression model
Hi every one ! Using sklearn and linear model I made a linear regression and I reached out to a function named "score". Does anyone know what does it exactly calculate? The code for this function is like this: model.score(X,Y) Thanks in advance! -- https://mail.python.org/mailman/listinfo/python-list
Re: Are Floating Point Numbers still a Can of Worms?
Mostowski Collapse writes: > I also get: > > Python 3.11.0rc1 (main, Aug 8 2022, 11:30:54) 2.718281828459045**0.8618974796837966 > 2.367649 > > Nice try, but isn't this one the more correct? > > ?- X is 2.718281828459045**0.8618974796837966. > X = 2.36764897. > That's probably the accuracy of the underlying C implementation of the exp function. In [25]: exp(0.8618974796837966) Out[25]: 2.367649 But even your answer can be improved: Maxima: (%i1) fpprec:30$ (%i2) bfloat(2.718281828459045b0)^bfloat(.8618974796837966b0); (%o2) 2.367648983187397393143b0 but: (%i7) bfloat(%e)^bfloat(.8618974796837966b0); (%o7) 2.36764900085638369695b0 surprisingly closer to Python's answer. but 2.718281828459045 isn't e. Close but no cigar. (%i10) bfloat(2.718281828459045b0) - bfloat(%e); (%o10) - 2.35360287471352802147785151603b-16 Fricas: (1) -> 2.718281828459045^0.8618974796837966 (1) 2.367648_98319 (2) -> exp(0.8618974796837966) (2) 2.367649_00086 -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list
Python For TinyML
Hello am a (M) and glad that I've joined this group. Any help in python for TinyML, i will honored -- https://mail.python.org/mailman/listinfo/python-list
Re: A trivial question that I don't know - document a function/method
On 10/23/2022 2:37 PM, Karsten Hilbert wrote: Am Sat, Oct 22, 2022 at 09:49:55PM -0400 schrieb Thomas Passin: def make_title_from_headline(self, p, h): """From node title, return title with over- and underline- strings. ... RETURNS a string """ def plot(self, stackposition=MAIN, clearFirst=True): """Plot a 2-D graph. ... RETURNS nothing """ Would it not, these days, be clearer to def make_title_from_headline(self, p, h) -> str: def plot(self, stackposition=MAIN, clearFirst=True) -> None: and use RETURNS (or Returns:) only when what is returned warrants further explanation (say, as to what is returned when). It might, but remember: 1. Knowing the type of a parameter isn't all you usually want to know; 2. If the type information isn't in the docstring, it won't be reported by reporting tools that use the docstring. Then there are all those cases where the signature hasn't been type-annotated, either because adding them to existing code would be a big burden, or because the developer feels it's too much trouble, all things considered. I would say that if the types are annotated, the method is simple enough, and the names are clear enough, sure, go ahead and rely on the type annotations. The most important thing is that readers can understand what the arguments and returns are intended to be, so some flexibility makes sense. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python For TinyML
On Sun, 23 Oct 2022 08:46:10 -0700 (PDT), Kisakye Moses wrote: > Hello am a (M) and glad that I've joined this group. > Any help in python for TinyML, i will honored https://tinynet.autoai.org/en/latest/ -- https://mail.python.org/mailman/listinfo/python-list
Re: A trivial question that I don't know - document a function/method
Às 21:58 de 22/10/22, Paulo da Silva escreveu: Hi all! What is the correct way, if any, of documenting a function/method? Thank you all for the, valuable as usual, suggestions. I am now able to make my choices. Paulo -- https://mail.python.org/mailman/listinfo/python-list
Re: A trivial question that I don't know - document a function/method
Am Sun, Oct 23, 2022 at 05:16:48PM -0400 schrieb Thomas Passin: > > def make_title_from_headline(self, p, h) -> str: > > > > def plot(self, stackposition=MAIN, clearFirst=True) -> None: > 1. Knowing the type of a parameter isn't all you usually want to know; Sure, as I said: > >and use RETURNS (or Returns:) only when what is returned > >warrants further explanation (say, as to what is returned > >when). same for arguments, which *usually* warrant some further explanation, except for rare cases such as def format_a_string(string2format:str=None) -> str: where string2format just might not require further explanation. > 2. If the type information isn't in the docstring, it won't be reported by > reporting > tools that use the docstring. While true such tools could be considered suboptimal (these days, again as I said). > Then there are all those cases where the signature hasn't been type-annotated True but OPs question was *how* to document so there's no perceived problem with having to document. > I would say that if the types are annotated, the method is simple enough, and > the names > are clear enough, sure, go ahead and rely on the type annotations. The most > important > thing is that readers can understand what the arguments and returns are > intended to be, > so some flexibility makes sense. +1 Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list
Re: Update from 3.9 to 3.10.8 and uninstall 3.9
On 23/10/2022 9:13 pm, B N wrote: I am new to python and wish to update 3.9 to3.10.8 which I have downloaded. How do I replace 3.9 with the 3.10.8 I downloaded. Kind regards JohnGee It depends on the operating system. Typically, you can just install the new version and adjust your environment vars (ie., path) to point to the new version instead of the old. The theoretical reason is that you may have other programs/scripts etc which still rely on the old version. If you are new to Python, you should probably avoid installing later versions until you have studied virtual environments. A venv will let you keep your "system" Python(s) clean and unencumbered while being able to experiment with all sorts of additional libraries, packages etc in multiple separate sub-environments. Cheers Mike -- Signed email is an absolute defence against phishing. This email has been signed with my private key. If you import my public key you can automatically decrypt my signature and be sure it came from me. Just ask and I'll send it to you. Your email software can handle signing. OpenPGP_signature Description: OpenPGP digital signature -- https://mail.python.org/mailman/listinfo/python-list
Re: Typing: Is there a "cast operator"?
On 23Oct2022 21:36, Paulo da Silva wrote: I am in the process of "typing" of some of my scripts. Using it should help a lot to avoid some errors. But this is new for me and I'm facing some problems. Let's I have the following code (please don't look at the program content): f=None # mypy naturally assumes Optional(int) because later, at open, it is assigned an int. .. if f is None: f=os.open(... .. if f is not None: os.write(f, ...) .. if f is not None: os.close(f) When I use mypy, it claims Argument 1 to "write" has incompatible type "Optional[int]"; expected "int" Argument 1 to "close" has incompatible type "Optional[int]"; expected "int" How to solve this? Is there a way to specify that when calling os.open f is an int only? I use None a lot for specify uninitialized vars. Maybe you shouldn't. The other way is to just not initialise the var at all. You could then just specify a type. Example: Python 3.8.13 (default, Aug 11 2022, 15:46:53) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> f:int >>> f Traceback (most recent call last): File "", line 1, in NameError: name 'f' is not defined >>> So now `f` has `int` type definitely (for `mypy`'s purposes), and if used before assignment raises a distinctive error (versus having the value `None`, which you might then pass around, and perhaps successfully use in some contexts). It is probably better on the whole to specify types up front rather than relying on `mypy` or similar to infer them. That way (a) you're stating your intent and (b) not relying on an inferred type, which if you've got bugs may be inferred _wrong_. If `mypy` infers a type incorrectly all the subsequent checks will also be flawed, perhaps subtly. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: Typing: Is there a "cast operator"? [RESOLVED]
Às 21:36 de 23/10/22, Paulo da Silva escreveu: Hello! I am in the process of "typing" of some of my scripts. Using it should help a lot to avoid some errors. But this is new for me and I'm facing some problems. Let's I have the following code (please don't look at the program content): f=None # mypy naturally assumes Optional(int) because later, at open, it is assigned an int. .. if f is None: f=os.open(... .. if f is not None: os.write(f, ...) .. if f is not None: os.close(f) When I use mypy, it claims Argument 1 to "write" has incompatible type "Optional[int]"; expected "int" Argument 1 to "close" has incompatible type "Optional[int]"; expected "int" How to solve this? Is there a way to specify that when calling os.open f is an int only? And yes there is! Exactly the "cast" operator. A mistype led me to wrong search results. I'm sorry. So, in the above code, we have to do: os.write(cast(int,f), ...) and os.close(cast(int,f), ...) Regards. Paulo -- https://mail.python.org/mailman/listinfo/python-list
Re: need help
Please try to choose more descriptive subject lines (eg "problem with
sock.connect" or similar). That you want help is almost implicit, and
what the whole list is for.
Anyway, to your problem:
On 23Oct2022 10:19, Shuaib Akhtar wrote:
How to fix Traceback (most recent call last):
File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\socket.py",
line 833, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because
the connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond
This usually means that either the host address is legal but incorrect
(there's no host/server listening with that address) or that the port is
incorrect and some firewall is _discarding_ your traffic because of the
wrong port instead of returning a nice "connection refused", which is
usually instant.
Fortunately you've listed your call:
File "C:\Users\i9shu\Downloads\python email bot\email bot.py",
line 25,
in
server = smtplib.SMTP('smtp.gmail.com',2525)
So, I'll try that by hand here:
% telnet smtp.gmail.com 2525
Trying 142.250.4.108...
telnet: connect to address 142.250.4.108: Operation timed out
Trying 2404:6800:4003:c0f::6d...
telnet: connect to address 2404:6800:4003:c0f::6d: No route to host
telnet: Unable to connect to remote host
%
I'd say GMail are rudely dropping traffic to port 2525. Maybe try just
25, the normal SMTP port?
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
Re: Typing: Is there a "cast operator"?
Às 23:56 de 23/10/22, Cameron Simpson escreveu: On 23Oct2022 21:36, Paulo da Silva wrote: I am in the process of "typing" of some of my scripts. Using it should help a lot to avoid some errors. But this is new for me and I'm facing some problems. Let's I have the following code (please don't look at the program content): f=None # mypy naturally assumes Optional(int) because later, at open, it is assigned an int. .. if f is None: f=os.open(... .. if f is not None: os.write(f, ...) .. if f is not None: os.close(f) When I use mypy, it claims Argument 1 to "write" has incompatible type "Optional[int]"; expected "int" Argument 1 to "close" has incompatible type "Optional[int]"; expected "int" How to solve this? Is there a way to specify that when calling os.open f is an int only? I use None a lot for specify uninitialized vars. Maybe you shouldn't. The other way is to just not initialise the var at all. You could then just specify a type. Example: Python 3.8.13 (default, Aug 11 2022, 15:46:53) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> f:int >>> f Traceback (most recent call last): File "", line 1, in NameError: name 'f' is not defined >>> So now `f` has `int` type definitely (for `mypy`'s purposes), and if used before assignment raises a distinctive error (versus having the value `None`, which you might then pass around, and perhaps successfully use in some contexts). It is probably better on the whole to specify types up front rather than relying on `mypy` or similar to infer them. That way (a) you're stating your intent and (b) not relying on an inferred type, which if you've got bugs may be inferred _wrong_. If `mypy` infers a type incorrectly all the subsequent checks will also be flawed, perhaps subtly. Yes. I also use to make f unavailable (f=None) when something goes wrong and I don't want to stop the script but of course I could use "del f". I also need to care about using "try", which might be better than "if" tests. A thing to think of ... Thanks. Paulo -- https://mail.python.org/mailman/listinfo/python-list
Re: need help
On Mon, 24 Oct 2022 10:02:10 +1100, Cameron Simpson wrote: > I'd say GMail are rudely dropping traffic to port 2525. Maybe try just > 25, > the normal SMTP port? 2525 is an alternative to 587, the standard TLS port. 25 and 587 work. telnet smtp.gmail.com 587 Trying 2607:f8b0:4023:1004::6d... Connected to smtp.gmail.com. Escape character is '^]'. 220 smtp.gmail.com ESMTP s6-20020a056870ea8600b0010bf07976c9sm13154711oap. 41 - gsmtp EHLO 501-5.5.4 Empty HELO/EHLO argument not allowed, closing connection. 501 5.5.4 https://support.google.com/mail/?p=helo s6-20020a056870ea8600b0010bf07976c9sm13154711oap.41 - gsmtp Connection closed by foreign host. The EHLO needs a domain. Port 25 is the same. -- https://mail.python.org/mailman/listinfo/python-list
Beautiful Soup - close tags more promptly?
Parsing ancient HTML files is something Beautiful Soup is normally great at. But I've run into a small problem, caused by this sort of sloppy HTML: from bs4 import BeautifulSoup # See: https://gsarchive.net/gilbert/plays/princess/tennyson/tenniv.htm blob = b""" 'THERE sinks the nebulous star we call the Sun, If that hypothesis of theirs be sound,' Said Ida;' let us down and rest:' and we Down from the lean and wrinkled precipices, By every coppice-feather'd chasm and cleft, Dropt thro' the ambrosial gloom to where below No bigger than a glow-worm shone the tent Lamp-lit from the inner. Once she lean'd on me, Descending; once or twice she lent her hand, And blissful palpitations in the blood, Stirring a sudden transport rose and fell. """ soup = BeautifulSoup(blob, "html.parser") print(soup) On this small snippet, it works acceptably, but puts a large number of tags immediately before the . On the original file (see link if you want to try it), this blows right through the default recursion limit, due to the crazy number of "nested" list items. Is there a way to tell BS4 on parse that these elements end at the next , rather than waiting for the final ? This would make tidier output, and also eliminate most of the recursion levels. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Typing: Is there a "cast operator"?
On Sun, Oct 23, 2022 at 2:11 PM Paulo da Silva < [email protected]> wrote: > Hello! > > I am in the process of "typing" of some of my scripts. > Using it should help a lot to avoid some errors. > But this is new for me and I'm facing some problems. > > Let's I have the following code (please don't look at the program content): > > f=None # mypy naturally assumes Optional(int) because later, at open, > it is assigned an int. > .. > if f is None: > f=os.open(... > .. > if f is not None: > os.write(f, ...) > .. > if f is not None: > os.close(f) > > When I use mypy, it claims > Argument 1 to "write" has incompatible type "Optional[int]"; expected "int" > Argument 1 to "close" has incompatible type "Optional[int]"; expected "int" > > How to solve this? > Is there a way to specify that when calling os.open f is an int only? > > I use None a lot for specify uninitialized vars. > I've found that mypy understands simple assert statements. So if you: if f is not None: assert f is not None os.write(f, ...) You might be in good shape. -- https://mail.python.org/mailman/listinfo/python-list
Re: Typing: Is there a "cast operator"?
On Mon, 24 Oct 2022 at 14:15, Dan Stromberg wrote: > I've found that mypy understands simple assert statements. > > So if you: > if f is not None: > assert f is not None > os.write(f, ...) > > You might be in good shape. Why can't it simply understand the if statement? I'm not a fan of coddling a type system like this. The entire point of type checking is to help you find bugs more efficiently, so if you have to repeat yourself every time you do these kinds of checks just so that mypy is satisfied, that's counter-productive (case in point: what happens if you say "if fn is not None: assert f is not None"? Now you've introduced a bug just to deal with the type system). ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: need help
On 24Oct2022 01:02, rbowman wrote: On Mon, 24 Oct 2022 10:02:10 +1100, Cameron Simpson wrote: I'd say GMail are rudely dropping traffic to port 2525. Maybe try just 25, the normal SMTP port? 2525 is an alternative to 587, the standard TLS port. Yah. My point was more focussed on GMail's shoddy firewall practices not returning connection refused. 25 and 587 work. Good to know. Thanks! Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: Typing: Is there a "cast operator"?
On 10/23/2022 11:14 PM, Dan Stromberg wrote: On Sun, Oct 23, 2022 at 2:11 PM Paulo da Silva < [email protected]> wrote: Hello! I am in the process of "typing" of some of my scripts. Using it should help a lot to avoid some errors. But this is new for me and I'm facing some problems. Let's I have the following code (please don't look at the program content): f=None # mypy naturally assumes Optional(int) because later, at open, it is assigned an int. .. if f is None: f=os.open(... .. if f is not None: os.write(f, ...) .. if f is not None: os.close(f) When I use mypy, it claims Argument 1 to "write" has incompatible type "Optional[int]"; expected "int" Argument 1 to "close" has incompatible type "Optional[int]"; expected "int" How to solve this? Is there a way to specify that when calling os.open f is an int only? I use None a lot for specify uninitialized vars. I've found that mypy understands simple assert statements. So if you: if f is not None: assert f is not None os.write(f, ...) You might be in good shape. I'm not very familiar with anything but the simplest typing cases as yet, but mypy is happy with these two fragments. if f: os.write(int(f)) # f must be an int if it is not None, so we can cast it to int. Or something like this (substitute write() for print() as needed) - from typing import Optional, Any def f1(x:int)->Optional[int]: if x == 42: return x return None def zprint(arg:Any): if type(arg) == int: print(arg) y0 = f1(0) # None y42 = f1(42) # 42 zprint(y0) # Prints nothing zprint(y42) # Prints 42 Another possibility that mypy is happy with (and probably the simplest) - just declare g:int = None instead of g = None: g: int = None def yprint(arg: int): if arg: yprint(arg) else: print('arg is None') yprint(g) # Prints "arg is None" And **please** let's not go doing this kind of redundant and inelegant construction: if f is not None: assert f is not None os.write(f, ...) -- https://mail.python.org/mailman/listinfo/python-list
