« first day (4067 days earlier)      last day (864 days later) » 

10:42 AM
hello is anyone there
I am following socket tutorial where it is given the following code for client:
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print('The OS assigned the address {} to me'.format(s.getsockname()))
> Instead of explicitly binding the socket to a given port and IP as we did previously, we can let the OS take care of it. Remember ephemeral ports? Yes, the OS will bind the socket to a port dynamically. So all we really need is to create a UDP socket (line 3).
But instead I get the error:
> print("The OS assigned the address {} to me".format(s.getsockname()))
OSError: [WinError 10022] An invalid argument was supplied
how can i use dynamic port in this case for client program
 
The code "works" on MacOS, but it basically says that the socket is not bound.
 
the tutorial says that OS will provide a port on its own but my windows machine gives error
maybe the tutorial is not for windows
 
TBH, maybe the tutorial is just wrong. :P
stackoverflow.com/questions/43330897/… suggests you have to bind the socket, and as mentioned on my MacOS the code also does not bind the socket automatically.
Use a port of 0 when binding to get a free port assigned dynamically.
 
also as programmer do we have to make sure that our program is not using any other programs port
Or just give it port 0 then
@MisterMiyagi this works in windows
 
It's a bit buried in the socket docs, but it does indeed say "If host or port are ‘’ or 0 respectively the OS default behavior will be used."-
 
10:52 AM
Thanks a lot its working now got to learn something new :-D
 
@jeea If another program is already using the port you try to bind to, the bind fails. If another program tries to use the port you already bound to, that program fails. So it's a good idea not to use a port known to be used by another program.
 
 
1 hour later…
12:18 PM
@MisterMiyagi I didn't know this either :o but wait, if you assign it dynamically, how would the other side eg: in a client-server implementation using this, would it find the port it can connect to?
ah, nevermind, I think I know what you mean:
tcpSocket.connect(('0.0.0.0', 8000)) would do what you meant here...
guess I already knew how to do this after all
 
hey guys. i'm new to python and i just can't figure out the syntax in the following code snippet. can someone please explain it to me?
def __new__(cls, clsname, bases, attrs):
uppercase_attrs = {
attr if attr.startswith("__") else attr.upper(): v
for attr, v in attrs.items()
}
this part : attr if attr.startswith("__") else attr.upper(): v
for attr, v in attrs.items()
 
this looks like a dict comprehension if I'm not wrong (since it use {})
@Mehdi if you want to understand how this works, try this link. (although it's about list comprehension instead of dict, it's basically the same thing except it's a different type)
 
1:03 PM
@NordineLotfi yesss it was. thank you so muchhhh
 
1:17 PM
@NordineLotfi A dynamic port is not really suitable for disconnected client-server setups. Instead you would have some means of discovery, e.g. writing the port to a file so that local clients can connect or announcing it at some third service that has a well-defined address.
 
@MisterMiyagi ah, yeah I see what you mean :)
thanks for the clarification
 
For example, our distributed compute and storage services work like the latter: There are a few services at well-known addresses that clients and compute/data services connect to.
 
Interesting. I guess one could use more complex method, like sending the address through a packet and doing packet sniffing on a specific port (eg: could be useful on offline clusters connected through ethernet cables)
btw, I finally managed to fix 99% of bugs in a project I'm trying to port to py3...except I now also managed to hit the last 1% which is already reported on the official bug tracker :D
It's the first time I actually find a real python bug or at least related to the main codebase
(and while it's marked as resolved, mind you it's actually not, at least not on 3.8 which is what I use on my end)
 
 
6 hours later…
wjm
6:59 PM
Why does heappush run in O(log n) if list insertion runs in O(n)?
 
heappush does not preserve the order of elements.
it only has to move some of the elements after the inserted one.
 
wjm
So `heappush`'s worst should be `O(n)` if you're always pushing a smaller element, but I noticed that

`for i in reversed(range(100000)): L.insert(0, i)`

is way slower than

`for i in reversed(range(100000)): heappush(L, i)`
I wonder if heappush is actually appending and then doing a few in-place operations.
 
 
2 hours later…
8:44 PM
but even after reading that, I still have a lingering feeling that heappush is faster here because it doesn't keep the order of the elements...probably just a feeling but it would make sense if so
 
 
1 hour later…
10:16 PM
Hello Guys
Can we continue try-catch block if we catch an exception pls?
 
You mean you want to jump back into the try block after the except block was executed? That's not possible, no
 
Thanks Aran. Yeah like continue execution after error catched
Probably this is the case with most compilers Aran?
No compiler allow to continue execution after exception cartched in try-except block?
 
Yeah, python-the-language doesn't support this.
 
Great! So the whole program will stop once exception is catched?
The solution is to fix that before deployment?
 
No, execution will continue after the except block. (Or in the finally block, if you have one.)
 
10:21 PM
So, that's great. Thanks.
What I did is to put it in a while loop with true condition!
It keeps taking all inputs and drop bad inputs aside...
 

« first day (4067 days earlier)      last day (864 days later) »