« first day (3699 days earlier)      last day (1232 days later) » 

12:19 AM
 
12:39 AM
is using return to end a function early hacky or okay? Like return xyz.add(abc) but the operation is a void function
kinda trying to avoid indenting a chunk under an else block
 
@aadibajpai if by "void function" you mean a function that returns None then I'd do xyz.add(abc) and then separately return. There's nothing wrong with an early return from a function.
 
@AndrasDeak yeah I meant a function that doesn't explicitly return anything (so None), just wasn't sure if it's poor style
 
return xyz.add(abc) would indeed be poor style, hinting at developer confusion. Like doing res = lst.append(val), which will invariably give you None.
 
right-but bare returns in general are not considered bad style?
 
nope
if it makes you uneasy you could return None ;)
 
12:48 AM
yeah haha I do prefer that more
 
of course an empty early return only makes sense for certain classes of functions: ones that don't return anything anyway, or ones that explicitly specify that they might return None (like a regex match that doesn't find anything)
I guess in the latter case it might be nicer to explicitly return None... I'm not sure. Someone better versed in program design might be able to help.
 
yeah it doesn't return anything anyway, for a separate similar function I was try catching to avoid a simple if check and early return but that did not seem clean
*excepting, guess my cpp is leaking
hmm actually not sure which is cleaner / better although probably in nitpicking territory here
def write(self, arg):
        if not arg:
            self.current.add(File(self.current))
            return None
        name, contents = arg.split(None, 1)
        if not self.current.exists(name):
            self.current.add(File(self.current, name, contents))
        else:
            print(f"An item with name {name} already exists.")

    def mv(self, arg):
        try:
            old, new = arg.split(None, 1)
            if not self.current.exists(old):
                print(f"The item with name {old} does not exist.")
basically either checking parameter early or going ahead and then catching exception
 
1:08 AM
@aadibajpai that's EAFP vs LBYL. Plenty of discussion about that. In most cases they are just a matter of taste, but in some rare cases EAFP is more correct.
Although you should have as little code as possible in the try block. What if self.curent.exists raises a ValueError?
 
Here is another fun one: I found a python line that triggers a core dump but when I try to debug it in pdb, the "where" command also triggers a core dump, so I can't quite figure out the call stack (and apparently neither can python :-)
 
1:35 AM
Hmm tcp is about 100 times more complicated than I thought it was
How silly of me to assume that every send call would always send exactly one packet containing all the data you supplied it, and recv would always read at most one packet, occasionally reading only a fraction of a packet if it was a particularly large packet
Merely because that's exactly how my first hundred tests turned out. Then my 101st test decides that, no, one recv can read the data from two consecutive send calls actually
The HOWTO makes this more obvious than the docs. "messages must either be fixed length (yuck), or be delimited (shrug), or indicate how long they are (much better), or end by shutting down the connection." None of these would be necessary if packets were guaranteed to not be smooshed or exploded in transit.
 
Amazing that the 51 people who upvoted this aren't aware this does not work, even worse that the OP marked this answer as correct... — Danny Watson Nov 9 at 15:54
Welcome to SO
 
1:51 AM
One demerit to Wikipedia's TCP article for spending approximately one word explaining that TCP is a streaming protocol. Compare to en.wikipedia.org/wiki/…, which is significantly clearer: "Streaming – Data is read as a byte stream, no distinguishing indications are transmitted to signal message (segment) boundaries."
Silly me, not reading the article on UDP so I can understand TCP
 
 
2 hours later…
3:57 AM
cabbage worldly pythonistas
 
4:30 AM
cbg :)
 
4:53 AM
see bee gee
 
 
1 hour later…
6:04 AM
Hello, If the below code is used to decompress, how to compress it back using the same mechanism?


print(type(item))#prints byte
buff = io.BytesIO(base64.standard_b64decode(item))

with gzip.GzipFile(fileobj=buff) as gz:
decompressed_data = gz.read()
decompressed_prod_details = decompressed_data.decode("utf-8")
 
6:17 AM
cbg guys
 
6:43 AM
recbg
 
 
1 hour later…
8:01 AM
Hello guys... Is it possible to calculate the mean time in python??
I tried like
final_df1.groupby('Final_Label', as_index=False)['Ticket_time'].mean()
But getting error
 
8:15 AM
cbg
 
cbg
 
cbg @AndyK & @Arne, long time no see!
 
It's been a while, I see you're participating in AoC too?
 
user14596741
Guys, What should i use as backend in website, if website have to do heavy task like doing search engine?
 
@ReblochonMasque hey man, sup ?
 
user14596741
8:24 AM
Hi
 
@aadibajpai If a function might return other values than None then use an explicit return None rather than the implicit return - even at the end of a function. Of course if the function is designed not to produce a return value then just use return, which can be omitted at the end of the function.
 
user14596741
:)
 
@ReblochonMasque cbg, haven't seen you for a while.
 
@Taylor you probably need it in some numeric dtype. You haven't really explained the setup; is that column a series of timedeltas?
 
@edward Moar power?
 
user14596741
8:35 AM
:)
 
Otherwise the ASF publishes various search systems, none of which I am currently able to name. Search engines (text-based ones, anyway) are essentially specialised forms of free text retrieval systems.
But don't expect to get much out of Solr without some hard work. There are cimplex relationships to understand.
@roganjosh good to talk with you yesterday. A wide-ranging chat, though geeky.
 
Hello, If the below code is used to decompress, how to compress it back using the same mechanism?


print(type(item))#prints byte
buff = io.BytesIO(base64.standard_b64decode(item))

with gzip.GzipFile(fileobj=buff) as gz:
    decompressed_data = gz.read()
    decompressed_prod_details = decompressed_data.decode("utf-8")
 
@holdenweb indeed. But that's the best kind of chat, no? :)
 
8:51 AM
@roganjosh Yes it is in timedelta format
@roganjosh is there any way to calculate the mean of time??
 
Hey, yes, I have not been much around this past year.
 
@Taylor Yes. If you have timedeltas then you can get it expressed in seconds and get the mean of that. I'm about to enter 5 hours of meetings so I gotta go, sorry
 
user14638035
9:13 AM
Does anyone now how to use tkinkter and would like to help me? :)
 
@roganjosh It suits me
 
@owgitt I mean, just do the opposite. Which part exactly are you struggling with?
 
@Carl-ErikPettersson If you have a quick question we may be able to help. If you want us to architect a complete multi-window solution, assistance would be less likely. Might as well ask, anyway: sopython.com/chatroom
 
@Carl-ErikPettersson You'll have a hard time finding volunteers like that. Just ask your question and people will probably help if they're able
 
user14638035
9:38 AM
Is it possible to make a variable with using tkcalendar that has attribute 'month' in it (like the datetime-modul has)? I get this error: AttributeError: 'str' object has no attribute 'month'. I have a list that contains information and that is supposed to be printed our for some seasons, other seasons should only contain a part from the list etc.
 
Why not just use a datetime.date object?
 
user14638035
9:57 AM
@Aran-Fey yes its better, just one question: is it possible to make a variable that "gets" any datetime?
 
user14638035
I mean like this:
 
user14638035
I have a function that handles seasons. For example if the user types in month = 2 he get the information from the winter. I would like this variable to be any month so that when the button gets clicked in the calendar it prints out the information for that month. For example: d = any_month_variable , then I can place it in the function that handles months: handle_months(d,list) and iterate over the list
 
I'm completely lost here. I have no clue how we went from date objects to a month variable, or what this list has to do with anything
 
If you are asking whether one can write a function that receives an integer, the answer is yes. If you are asking something else, it is not clear what that something is.
 
10:13 AM
There are only twelve months and you are writing a gui. Why make the user type anything, just give them a "month" dropdown and action each new selection?
 
user14638035
Okey thanks :)
 
12:13 PM
You can also look up tkcalendar @Carl-ErikPettersson
 
12:42 PM
@Carl-ErikPettersson tkcalendar would give you an interface for dates, but as far as i know, there is no way to display just months, using tkcalendar, you have to display the entire year month and day with it.
 
Hi
Is there any api where I can upload some data, and edit it later using py?
 
Does anyone have any idea why the name lambda for anonymous functions? Like in physics lambda represents wavelength and in maths it usually represents a small value, and so on? Was there any real inspiration behind the name lambda? Google seems to give me definition of lambda when i search for 'why the name lambda'
 
@BlackThunder google drive?
 
its slower, smh
I have tried a lot of google services, they all take a lot of time to authenticate
 
AFAIK lambda, the name, comes from lambda calculus, via functional programming @CoolCloud
 
12:51 PM
@ReblochonMasque Oh okays, thanks!
 
watermelon
 
@Carl-ErikPettersson Take a look at this example, it might help you out, not sure
import tkinter as tk
import tkcalendar, datetime
from tkinter import messagebox

root = tk.Tk()

def process():
    date = cal.get_date()
    month = datetime.datetime.strptime(date,'%Y-%m-%d').month
    if 1 <= int(month) <= 5:
        messagebox.showinfo('Season','This is the Summer season')
    elif 6 <= int(month) <= 7:
        messagebox.showinfo('Season','This is the Spring season')
    elif 8 <= int(month) <= 12:
        messagebox.showinfo('Season','This is the Winter season')

cal = tkcalendar.Calendar(root,date_pattern='Y-mm-dd')
Pardon me if the seasons are wrong, not sure with those : p
@ReblochonMasque 🍉
 
1:13 PM
morning cabbages, folks!
 
cbg :)
 
Trying to decide whether my communication protocol really needs to be able to send strings longer than 256 characters. That should be large enough for everybody, right?
 
i mean, windows paths decided 256 is enough for everyone, whether you like it or not! im sure you'll be fine :P
 
@ParitoshSingh whats cbg?
 
@CoolCloud part of our (completely optional!) salad language, check it out here.
 
1:25 PM
Somewhat vestigial these days as 95% of the room doesn't know how to do anything but greet one another
I feel a bit bad for the neophytes that get all gung-ho about the concept and then discover nobody knows what they mean by "Endive kale turnip? Tatsoi! Watercress brooklime arugula."
 
Chalk it up to another instance of lost wisdom then, i have absolutely no idea what that meant :)
 
I saw the message about the AoC chatroom annd got s uper excited because I thought Alexandira Ocasio-Cortez popped by to say hello
 
I intentionally picked words with no associated meaning so the reader can experience my own cluelessness
 
1:42 PM
potato guys
 
See, like that, I have no idea what potato means
 
laurel
@Kevin i feel ya
 
2:02 PM
I recently learned a few choice salad words. So I happen to know that potato is an "all good?" inquiry. But I really don't know most of the vocabulary
 
Hi
 
2:16 PM
ahoy
 
@inspectorG4dget I have actually given the vocab a few good reads but I don't remember anything except cabbage and kevin'd
 
cabbage, kevin'd, potato, melon, rhubarb/rbrb, laurel. That's what I rememebr
 
Ahh I do remember melon as well. and I just got reminded about potato
 
@Kevin Just reserve the first and last 64 characters for continuation string markers. And keep some 64 chars for a future-proof header.
 
2:33 PM
I do have a fondness for RFCs that keep a reserved byte or two even though it's been twenty years since the first draft and making any changes whatsoever would destroy all modern technology
Any sane person would change "byte 3: reserved. Currently always zero" to "byte 3: always zero", but we are not sane, we are engineers
 
I'm worse. I'm not an engineer - I'm a scientist. So while you good folk have your feet firmly planted in reality, I start conversations with "so if we could change the universal gravitational constant..."
 
Having accessed the universe's admin console, I turn the gravitational constant dial, and everything's atoms explode at the speed of light. "Huh. I wonder if that happens every time."
 
Don't forget the folks who do use byte 3 when no one is looking.
 
They are in a forever war with the folks who crash when byte 3 is anything but zero, even though this technically makes their code future-incompatible
What can they say, it's an easy way to filter out 99.5% of instances where clients send them random noise for fun
 
user14638035
@CoolCloud Thank you sir! Exactly what i meant
 
2:40 PM
If you filter out 99.5% of instances where clients send them random noise for fun, you break the internet! Think of the kittens!
 
Ok, if they put the string "kitten" in their user agent, we'll allow noise.
20 years down the line and every modern communication protocol has ":3" somewhere in their 64 byte header and nobody remembers why
We're basically there now, except with geckos
 
Currently trying to decide whether I'll ever need more than 65,536 bytes in the body of my protocol, and whether I should go ham and allow messages of unlimited size.
 
you run into HTTP's problem, no matter what limit you decide on - you'd need to define a message identifier and a packet order
 
If PEP 312 were un-deferred, you could actually use :3 in Python!
 
2:54 PM
bytes 0,1,2,3: header-header. 4 byte integer indicating the size of the header.
bytes 4 through (somewhere between 5 and 18,446,744,073,709,551,616): header. indicates size of body.
remainder of message: body. Can be no larger than 2^(2^64) bytes.
 
@inspectorG4dget Isn't TCP ordered?
 
1 googleplexsquintillionabytes ought to be enough for everybody
 
@MisterMiyagi the packets can still show up out of order. They are reordered on the client side
 
@Kevin I somehow tend to doubt that :p
 
TCP is ordered insofar as anything can be ordered in a network where electrons bounce around semideterministically and sometimes vanish from existence
 
2:56 PM
@Kevin You just leaked 90% of all my custom network messaging protocols!
 
I'll have my lawyers meet yours for the customary duel
 
That reminds me of a custom UDP monitoring format which constantly recycled 2 bytes for a cyclic ordering sequence number. Quite fun to work with.
 
@Kevin was that pun intended?
 
As far as I can tell, no
 
@Kevin Let's hope no one loses their header...
 
3:00 PM
The homunculus that runs all of my lower mental functions rarely shares his notes with me
He could sneak in all sorts of (Help trapped in a cartesian dualism factory) things into my behavior that I'd never notice
 
He's probably busy working out the header format.
 
@PSSolanki Being of a somewhat sweary nature I find yam and yamming have occasional utility.
@Kevin Gold-plated over-specification, sir! ;-)
 
@Carl-ErikPettersson Watermelon!
 
@Kevin Remember the zero, one, infinity principle and apply it to the bytes in your essage.
 
If you guys had some meaning for 'sugar' for your salad language, coudve recreated Harry Styles' Watermelon Sugar, laurel!!
 
3:09 PM
In actual practice I'm just wrapping valid UDP packets in a tiny header and sending them to a second process, so 2^16ish bytes really ought to be enough for everybody
jumbograms forbidden
 
IPv6?
 
@Kevin Same machine or network?
 
Same machine.
 
Well, that should remove pretty much all of the Ugly in UDP at least.
 
My ultimate goal is to pass UDP packets from Wireshark to Python by making use of Wireshark's lua scripting capabilities. lua supports sockets, so that seemed like a straightforward way to get it to talk to Python. More straightforward than learning how to make lua create a python subprocess, or interface with the CPython API, or whatever.
And I definitely cannot be bothered to skip Wireshark entirely and learn how pcap works
 
3:19 PM
No socket.AF_UNIX, I take it?
 
Let's see... Nope, not available.
I half suspect that the lua interpreter will be more of a bottleneck than the interprocess packet latency, anyway
 
LuaJIT is freakishly fast, in case that's what you are using.
But plain Lua wasn't too bad either, AFAIK.
Been a while... stares into the sunset
 
There's a solid 60% chance that everything will be fast enough for my needs even though I've got N layers of bloated abstractions
And if it turns out that I need to rewrite the lua part in C, my efforts haven't been wasted, because a stable protocol specification will be portable and invaluable
 
Here's hoping you won't need byte 3! :3
 
@holdenweb :D
 
3:33 PM
cbg all, how do I negate the return value of a function that I store in a dict?
something like this (but this wont work obviously)
def on(x):
    # do stuff with x
    return 1 # bool result of some calulation

d={'on':on,'off':not on} # how to negate the function?

seq=[('on',1),('off',0)]

for i,j in seq:
    res=d[i](j) # if `i` is 'off' then the negated answer of `on` must be returned
 
By wrapping it with another function (perhaps a decorator)?
 
stackoverflow.com/questions/42561843/… was what I saw but I wanted to know if I can use partial or something
 
@python_learner only if you add a keyword to on that does the negation inside the function
 
the function is still not being called. So negation won't quite work that way. It might need to be a @property for named evaluation
 
@inspectorG4dget hmm?
 
3:37 PM
should I just have a new function off that does return not on(x) ?
 
@python_learner that's the wrapping alternative
the other is def on(x, no_wait_make_it_off=False), and then partial(on, no_wait_make_it_off=True)
 
I still dont have a hang of wraps or decorators so I wanted to sneak it in here to learn
 
@AndrasDeak {'on':on} is different from {'on':on(4)}. Assuming that's not a typo:
 
since it usually makes less sense to negate the return value inside the function, I'd probably wrap it
@inspectorG4dget well, yeah. We all know that. The function gets called on the last line. If the dict contained function calls the question would never arise.
 
class Foo:
    @property
    def on(self, x):
        #do stuff
could be the trick
 
3:39 PM
if the dict contained bools then you could just do 'off': not on(4)
@inspectorG4dget I think you misunderstood the question
 
I have a feeling I might have
last two cents' worth before I muddle this up further:
 
laurel, I have to re read this now, all cool though
 
{'on': lambda x: on(x), 'off': lambda x: not on(x)}
 
@inspectorG4dget lambda x : on(x) is a huge no-no!
 
@AndrasDeak how come?
 
3:40 PM
that's on with a little inefficiency
as for the other lambda: yes, that's the wrapper option
 
yup, but it homogenizes the value types, so that they're all single argument callables. Inefficient code, but cleaner. Depends on the use case, I suppose
 
@inspectorG4dget think list([1, 2, 3]) except during every function call
 
user14638035
4:19 PM
@CoolCloud If I want to do a function that handles different seasons seperatly so that I can call it when I need it is it possible? For example: I want to be able to ask the user too type in a date and get out the same result as you got, but now instead in the terminal. At the same time I want to be able to call this function and get the same output in the gui without having to repeat myself
 
4:32 PM
This is why it's usually a good idea to decouple data from presentation. In other words, make the function return a string, and then it's the caller's job to decide whether to print it to the console or put it in a message box or beam it into space or what
#bad
def print_average(a,b):
    print((a+b)/2)

def show_average(a,b):
    messagebox.display((a+b)/2)

print_average(23,42)
show_average(23, 42)

#good
def average(a,b):
    return (a+b)/2

x = average(23, 42)
print(x)
messagebox.display(x)
 
you'll have to encode the string before you can beam it into space
 
Do some fourier transforms to it
Just really go hog wild
 
4:53 PM
@inspectorG4dget You only need one lambda: {'on': on, 'off': lambda x: not on(x)}
 
ahh, good call :)
(pun totally not intended, but a happy accident)
 
I propose 'on': lambda x: not not on(x)
This conveniently coerces the 1 returned into a more conventional True
 
not on: lambda x: not (lambda y: not on(y))(x)?
 
[chef's kiss]
 
@Kevin But surely 'on': lambda x: bool(on(x)) is more pythonic?
 
4:57 PM
That's-a spicy lambda
 
@holdenweb Why use many parens when few parens do trick ( ͡° ͜ʖ ͡°)
(yes, you are correct)
 
Just picking nits 'cos i've no tyres to kick.
 
That's basically all we do around here anyway. Paint the bike shed, shave the yak, pick the nits
 
less paren save time. Many small time make big time. Go se[ea] world
 
5:00 PM
Can't kick the tyres because they're in the bike shed and we painted over the lock
 
I tried shaving the yacc once, but I couldn't find the right tokens
 
@Carl-ErikPettersson These are really part of basics of python and tkinter, just create functions and then when you want to, call the function like winter() or whatsoever. If you want to get the input from the user, then make sure they are in the same format that datetime expects, like yyyy-mm-dd
 
5:56 PM
@inspectorG4dget Should have tried the bison ...
 
@holdenweb hey! what does a cow say when she drops off her son at school every morning? :P
 
"Even though you are the only cow at a school full of humans, I know you can overcome your differences and make friends. Not to put any pressure on you, but this is the first cow/human integrated school and the nation is watching, so do your best."
 
"... just don't let the bullies turn you into leather"
 
6:41 PM
rb folks
 
well, this is a python chatroom... but I'm pretty sure there's someone here familiar with ruby
 
7:04 PM
trying to disable the cors error at django
is there anyway to disable cors?
 
Isn't CORS a safety mechanism?
 
yes - but i need to allow all for testing purpose
there is some IBM tool - need to integrate the api with that
its been crazy working with the tool, by far the worst i have seen :p
 
 
4 hours later…
11:13 PM
I'm getting irked by this question because I feel I should know the answer. I actually face something similar at work because the workspace borks url_for and I had to get around it with a "template dispatcher" function in my Flask app. It's definitely a hack in my workspace, but I don't know if it's a hack overall. Am I missing a trick in Flask?
Well, it's 2-fold. You can have a template dispatcher using a template dict for full pages, and another for embedded "static" content but I don't think it belongs in that folder, which was suggested in comments
 

« first day (3699 days earlier)      last day (1232 days later) »