« first day (3863 days earlier)      last day (1068 days later) » 

12:45 AM
@CoolCloud but can you do this :p
@roganjosh I will give this a read later today Josh, thanks for the link
 
 
2 hours later…
gig
2:36 AM
@Kevin @Kevin worked like a charm can you explain how it is sorting in brief?
 
2:56 AM
@python_user Can barely afford a bottle o' water :p
Another day another exec(). stackoverflow.com/a/67528495/13382000
I once read in a comment to an answer that uses exec that, just giving a warning is not useful. Avoid it.
 
not adding that disclaimer will cost him downvotes and he knows that :D
 
3:48 AM
I've been checking sqlite3 and there is surely an overlap between filtering methods from pandas and querying in sql is there a reason I should use one over another?
Assuming I can perform operations using pandas alone is there a structure benefit of storing in a .db format compared to just saving it in a .csv format if i'm just doing solo projects? Since i'm not sure if I have a need to learn SQL
 
4:03 AM
@Pherdindy no.
Anyone know if any projects seriously tried to use annotations for anything other than type hinting? Was looking into struct tags in go, and realized annotations could be used in the same way (of course, you can also attach whatever you want to fields via descriptors, but that's besides the point)
 
Cool actually i'm just sticking to flat files for now. Just gonna deal with any problems when it starts slowing down or something
 
4:23 AM
@alkasm fastAPI uses annotations in REST handler methods to take path and query parameters that are parsed as str, and validate and convert them if annotated as other types (such as int, for instance).
 
Ah right, pydantic and fastapi are actually using the types at runtime
 
@Pherdindy If you're just filtering with pandas there's no reason. An advantage of using SQL is you can offload a lot of the computational burden from python on your machine, to a SQL server. But in the case of SQLite, that lives on your computer in memory. Still worth learning SQL... it's literally everywhere
 
Wonder if anyone is using them for data other than types? for e.g. in golang, you often see them used to tag a yaml field name
They were of course built to support it but it's a little bit of a bummer that you have to forego typing if you want to try other usages. Or do you? Maybe I can have the types in a .pyi and use the annotations for other things inside the .py file.
 
4:46 AM
anyone else doing Pycon tomorrow?
 
@NathanKrowitz Thanks makes sense. Would definitely like to learn SQL in the future when I get the time
 
5:23 AM
@piRSquared I saw it earlier this month but completely forgot the dates, thanks for the reminder
 
Indeed a .pyi file does overrule the .py file when they exist, so you can still utilize annotations for other things without forgoing types. Huzzah for eating cake, and having it too.
 
 
1 hour later…
6:39 AM
hm, at that point i wonder if you shouldn't call it a pyi file
since if you call it a pyi file and then do stuff that users won't expect, you're creating an opportunity for surprise, but you don't really need that extra baggage. use the same type of contents in a file with a different extension or whatnot, and call it good perhaps?
 
6:50 AM
@piRSquared not in presence obviously, but also don't have a working mic./video to work with so... just listening in mostly...
 
"*** TypeError: Parameterized Tuple cannot be used with isinstance()." But why?
 
@Mikhail how are you using it?
 
Something like:

`isinstance(my_object,Optional[types.MyCustomType].__args__)`
As the error says you can't do an isinstance check on
typing.Tuple[int, ...]
but why?
because the ... can be any type? (really?)
 
hm, typing wasn't intended to be used that way
what happens if you explicitly make a tuple out of it?
 
7:22 AM
I mean, it passes the check when my_object is a tuple, aka isinstance(my_object,Optional[Tuple].__args__) works fine
but it's kinda sad because I can't easily reuse MyCustomType (which happens to be a "parametrized tuple")
As in most of my contributions to this chat, this is more of a rant thinly veiled as a question :-)
 
@alkasm stdlib: dataclasses and singledispatch
still a nasty surprise, probably
 
7:50 AM
Type hints being optional and no-ops at runtime are a deep almost-truth. Making type hints affect your execution especially in a non-type-related way would be a horrible pitfall for experienced users.
 
@AndrasDeak meh, depending. either way it was for a fun idea, not an actual thing. annotations were definitely intended to be extensible in this way in the beginning, it's just that we've moved towards their only main use being typing as a community. didn't have to be that way if someone made something else interesting with it early-on.
 
I wonder if Cython can benefit from typehints
 
@alkasm and renamed the language Typethon ;)
 
Pretty sure they were never designed for runtime use. They only added some sort public API as an afterthought in 3.8 or so
 
python was never designed :-)
 
7:55 AM
heh, true enough
too true, in fact :|
 
Today was a good day, I was able to make Black, mypy, and pylint ICE
ICE-ing Black wasn't too hard just invert the standard fmt sections:

# fmt : on
# fmt : off
 
@Mikhail python's no C++ but it's no JS either
 
From personal experience I've found typing hard to maintain unless its being enforced with asserts. Too many devs change the code, and it's easy to get wrong.
If it was JS it be more performant due to the interest in optimizing its runtimes
 
To be fair, implementing isinstance and issubclass for all the stuff in the typing module is pretty complicated, especially when Callable and TypeVar are involved
 
8:15 AM
issubclass should just look at the .__mro__ ?
 
it does
 
actually I think its pretty easy?
 
Does it not?
not sure how __subclasshook__ and things work
 
issubclass(Callable[[T, Iterable[T]], T], Callable[[T, Tuple[T, ...]], Foo]) is easy?
 
What were you thinking was hard?
 
8:18 AM
@Aran-Fey we've had __annotations__ through signature objects since the introduction of py3: python.org/dev/peps/pep-3107/#function-signature-objects
 
also likely that Callable has a something like .__args__
 
@alkasm he means it only started affecting runtime in the stdlib with 3.8
until then there was a pinky-swear that it would never do that
 
@alkasm Sure, that gets you a dict of annotations. So what do you then when you see annotations like Tuple[T, ...] or Callable[[int], str]?
 
why does standard lib matter at all? Aran-fey said 'they were never designed for runtime use'. they were explicitly designed to be available at runtime through a sanctioned mechanism
for clarity: annotations are not type hints
 
You can look at the annotations, yes, but you can't really look inside
 
8:22 AM
since "python was not designed" (apparently), cpython leads by example
 
@alkasm What's the difference? O.o
 
annotations are syntax. a: "whatever", "whatever" is an annotation
My question above was explicitly asking about non-type related uses of annotations
 
@Mikhail Figuring out if there's a value for T that makes every possible value of T makes the first Callable a subtype of the 2nd Callable. If you don't think that's hard, well, I assure you it is
 
like, in the initial pep iirc it mentions an example use case of function annotations as like adding documentation per-parameter, which is a pretty cool idea that never took off
i cant find which pep mentions that
 
Oh, I thought you meant uses other than type checking. I think annotations are only intended for types? Pretty sure I read a warning somewhere that using non-type values in annotations may not be allowed anymore in the future
 
8:38 AM
@Kevin You can think of a null pointer in C as something like an as-yet unbound name in Python. It's intended to have a value at some stage, but it doesn't have one yet. Having said which, null is often used to indicate the absence of data, a role equally often played in Python by None.
But you already knew that :)
 
@Aran-Fey they weren't initially intended only for types. also i don't think there's any reason why a literal string won't continue to be supported (the peps around this currently are moving towards making all annotations strings at runtime I think?)
 
Hmm, true, when annotations are automagically stringified there isn't really a way to detect non-type annotations
 
 
3 hours later…
11:26 AM
Today's wacky version of Hello World:
10
__name__ = 'Hello World'

@print
@next
@iter
@dict.values
@dict
@vars
class Foo:
    pass
 
good god..
 
this is fantastic
 
heh
this is a game changer for @piRSquared
 
12:08 PM
that is cool
also surprisingly easy to understand knowing that decorators are stacked
 
@Aran-Fey Why does that print without a call to Foo?
 
it doesn't need to call Foo because the module name is bundled on the class's vars
you dont need to make objects out of a class to see the class's attributes.
 
Decorators modify the class/function they're applied to, so they run immediately after the definition. No calling required
 
Ah, cool
 
coincidentally there is a decorator tutorial on pycon 2021
 
12:29 PM
Is it recorded? Looks like the tutorials were May 12th & 13th.
 
usually its on YouTube idk why its not on now
 
Decorators are fun but decorators-with-arguments give me a mild headache
 
Of today's talks, "From 3 to 300 fps: NES Emulation in Python and Cython by
James Murphy" looks interesting, and I'd also listen to "Patterns of ML Models in Production by
Simon Mo" if I was there.
 
Their behavior is logical from basic principles but I can't effortlessly keep straight the design of a triple nested function in my head
 
@Dodge us.pycon.org/2020/schedule/presentation/75 I am not sure if the content is different but it is the same guy with the same topic, unless I really messed up reading this
 
12:42 PM
@python_user huh, same tutorial, same presenter two years in a row.
 
def adds_to_result(amt):        #function that returns a decorator
    def f(func):                #decorator
        def g(*args, **kwargs): #function that replaces decorated function
            return amt + func(*args, **kwargs)
        return g
    return f

@adds_to_result(7)
def product(a,b):
    return a*b

print(product(2,3)) # 13
A fair amount of work to add 7 to something
 
@Dodge yeah that was why I was not sure if linked the right one, but I guess that is the case
@Kevin there is no way to do this without 3 functions nested?
 
I have a half-serious idea of writing a decorator for decorators that does some of the nesting for you...
 
@python_user There is, but that's the easiest way to get the arguments (amt) into the function that needs them (g)
 
I have used decorators that take an argument but I just learnt that you need 3 functions to write that decorator
 
12:52 PM
If you're saying "strange, I wrote decorators-with-args in the past, but they weren't triple-nested", I'm intrigued
 
I mean @app.route('/') that is something I have used, I didnt put thought into knowing how the parameters are passed
 
decorator.decorator seems like it can help with this
 
1:16 PM
@Kevin How about classes as decorators
class AddsToResult:
    def __init__(self, amt):
        self.amt = amt
    def __call__(self, func):
        def g(*args, **kwargs): #function that replaces decorated function
            return self.amt + func(*args, **kwargs)
        return g


@AddsToResult(7)
def product(a,b):
    return a*b

print(product(2,3))
i guess technically it gets to the same level of indentation because classes need 1 indentation, but that's not really triple nesting, yeah?
 
I actually know this, I once answered a question on main, OP already had the class decorator, I just had to answer relevant parts
but yeah it didnt really occur to me and this is still 3 functions
 
morning cabbages folks!
 
cbg :D
 
1:41 PM
The problem with classes as decorators is that 1) You have to use functools.update_wrapper instead of functools.wraps (and I can never remember if the wrapped function is the first or 2nd argument), and 2) you need to jump through a bunch of hoops to make them work on methods
...and even more hoops to make them work properly on classes
Imagine if there was an @instancemethod decorator that automagically turns any callable into a function-like descriptor
 
good luck getting a decorator that does the default behaviour
 
It's very niche, sure, but not as niche as memoryview :P
 
Ok, I think I successfully wrote a decorator decorator decorator: dpaste.org/E6V6
It basically does the same thing as the decorator.decorator in Aran-Fey's link. Define your decorator-with-args with the signature, (func, whatever_args_you_want), and then dec_with_args will expand it into the triple-nested form that Python understands
 
2:08 PM
The lack of @functools.wraps is making this a lot harder to understand...
 
Here, I'll add type annotations, that will help
def dec_with_args(concise_decorator: Callable[[Callable[[...], Object], ...], Callable[[...], Object]]): -> Callable[[Callable[[...], Object]], Callable[[...], Object]]
    def make_decorator(*maker_args, **maker_kwargs) -> Callable[[Callable[[...], Object]], Callable[[...], Object]]:
        def decorator(func: Callable[[...], Object]) -> Callable[[...], Object]:
            return concise_decorator(func, *maker_args, **maker_kwargs)
        return decorator
    return make_decorator
:^)
 
Ha, annotating decorators is a fool's errand
There's no annotation for "returns a callable with the same signature as the input"
 
deja vu..i feel like i had this conversation recently
there might be a convoluted hack for it
 
Might be possible with a TypeVar(bound=Callable), actually
Although I'm pretty sure there's a PEP in the works that's designed to solve this problem, so probably not
 
I joke, but seriously... If I assign sane names to intermediary type hints, then it might actually be useful for comprehension:
#Remember that `Callable[a,b]` means "a function (or similar) whose argument list has type a, and whose return value has type b"
#And `[...]` is essentilly equivalent to *args, **kwargs

Func = Callable[[...], Object]                          #regular old function, takes any arguments, returns any arguments
Decorator = Callable[[Func], Func]                      #regular old decorator, takes a Func and returns a Func
DecoratorMaker = Callable[[Decorator, ...], Decorator]  #aka a decorator with arguments.
 
2:14 PM
Is Object supposed to be object or typing.Any? :P
 
Any, I suppose.
 
@Aran-Fey exactly, you got it
I'll go digging for the examples in a few
 
And I see the convention is to use Callable[..., Any] for a func that takes/returns anything, not Callable[[...], Any]. Oh well! I like my way better because I can declare a function that takes a first argument of a specific type, followed by arbitrary argumnts
 
Callable[..., Any] is equivalent to Callable by the way
 
Cool. I wasn't sure whether Callable-without-brackets was allowed*, so I erred on the side of caution
(*insofar as anything is "allowed" or "forbidden" in type hinting, it's not like any of it is natively enforced)
That which is syntactically valid is permissible
 
2:20 PM
Admittedly, those annotations do help
 
D'oh, dec_with_args's return hint should be DecoratorMaker. So much for comprehensibility
 
Drive-by-shuddering-at-Kevin's-annotations cbg!
 
If only I knew Lisp, I could have written this with my eyes closed, while reciting the definition of "endofunctor"
 
here is a cross post link to my new question at code review, anyone interested can check it codereview.stackexchange.com/questions/260737/… if this is against room rules do feel free to move, or I will delete if its within the time
 
Have to admit, (Callable (...) Any) isn't all that bad....
 
2:27 PM
@python_user I'll allow it
 
One might argue that our solicitation rules apply explicitly to Stack Overflow posts, and Code Review is not Stack Overflow. I do appreciate a good rules lawyering from time to time.
Hmm, not sure if I found another typo in my annotations, or if I've simply confused myself into a tizzy
 
I'd say that code review could be a part of stack overflow. Since it's code and code. :/
 
@Kevin I also thought there was a mistake but then realized it was correct after all...
 
stackoveflow = mostly not working code, code review = strictly working (my understanding)
 
2:35 PM
Once you're done with SO you go to CR :P
 
75% sure that I should have written DecoratorMaker = Callable[[...], Decorator]
Ok, annotation v1.1 dpaste.org/uiqS
Still doesn't actually run if you actually import the necessary bits from typing, because my "alternative" *args hinting, Callable[[...], Any], raises a TypeError.
If there's a "correct" way to annotate Callable[[Func, ...], Func], I will be glad to use it
 
That's how it is 90% of the time. At least for me.
1) "I think I'll use type annotations for once"
2) "Wait, how do I correctly annotate this?!"
3) "Never mind, no annotations after all"
 
2:51 PM
@Kevin Use a Protocol for anything that goes beyond a fixed number of args.
from typing import Protocol

class Kevable(Protocol):
    def __call__(self, func: Func, *args) -> Func: ...
 
If I de-generalize the v1.1 code so it only works on functions with static known-at-compile-time signatures, then it all runs and looks logically consistent, to my untrained eyes dpaste.org/RPht
@MisterMiyagi Good idea.
 
Which flag should I use for this
 
@CoolCloud not an answer
Review might disagree, you'll find out
 
It is an answer though?
unformatted code-only answer, but still an answer
 
@python_user Re: "As it is a generator will that make memoization different?". In my experience, generators and memoization are basically incompatible.
 
2:58 PM
Maybe, hard to say. Definitely should be a comment or edit on another answer which is one of the LQP(?) review deletion reasons.
 
I'd first format the code and see if it's really a clone of the other person's code. If yes, flag as plagiarism, if no, do nothing (or maybe downvote)
 
Bad news for graph search algorithms, which can't be converted into a function that returns a list of all valid paths, while still guaranteeing it terminates in finite time. Unless you explicitly ban cyclic graphs.
 
@Aran-Fey that works too
Edit would help review too
 
Perhaps you could do something interesting with itertools.tee, although it might consume a catastrophic amount of memory
 
Not a clear copy, but the core code is same. Just added made 2 changes there I guess
 
3:02 PM
It's not plagiarism as there's attribution
 
@Kevin memoized generator
^ was a bad example
 
None of this is to say that it's a wild goose chase to try to closely incorporate generators and some kind of caching... It just won't have quite the same impressive performance qualities as conventional memoization of conventional functions
And also it's harder to get right, natch
 
keeps on typing answer exactly folks, don't even try *shifty eyes*
 
3:18 PM
Janky generator memoizer prototype: dpaste.org/zbQQ
Despite calling generator fib() twice, the super difficult math is performed only the first time for each yielded value
(Feel free to incorporate into an answer on Code Review, or use for any other purpose, no attribution required)
 
@Kevin this stackoverflow.com/questions/4566769/… was something I came across in my search
 
Wait, isn't tee single-use as well?
 
Hmm, quite close to my prototype. I'm not sure what the isinstance check is for... Maybe I'm forgetting a corner case.
 
So the cache would be exhaustable just like the initial generator.
 
Pretty sure tee has special behavior for teeing a tee
 
3:27 PM
I store only un-exhausted tees in my cache, so I didn't think I needed to check
 
Oh, I see... it's a chain of tees...
 
...which does not necessarily solve the problem of being single-use
 
If anyone can produce a failing test case for my decorator, I would be grateful for the amount of theorycrafting it would save me from doing
 
Easy, just call it with keyword arguments :P
 
Decently sure it's correct, just not sensible.
Since the cache will always have a tee up to the start, you might as well record all elements into a list.
 
3:29 PM
Yes, I agree. Every already-yielded value is permanently saved, so right off the bat we've discarded one of the main selling points of generators, memory efficiency.
The other selling point, facilitation of exotic and sometimes frightening nonlinear flow control, is still intact. So the memoizer might yet come in handy if, say, you're BFSing over a cyclic graph.
 
sometimes I find its slightly easier to write a recursive generator than having to use lists to concatenate the return values
 
yield from is cool and good
 
3:54 PM
Hello, I was in here the other day and someone clued me in about, if string in list: which has been great. Is there a way to get the index from where it was found? Or do I need to just use the .find() method?
 
you mean ...
['my', 'list', 'of', 'strings'].index('of')
?
 
for i in range(len(fileList)):
    #search files for product total sheet
    result = fileList[i].find("Products Ordered Total Quantity")
    if result >= 0:
        #finds the index location of labor, which is the last item on the product sheet
        endlocation = fileList[i].find("LABOR", result)
        #adds all informationed betwen the last letter of Quantity and Labor
        products = fileList[i][result+31:endlocation]
 
Nope, you can't get the index from an a in b expression. If you need to know the index of the substring, you may as well use find from the beginning.
 
ok thanks! I was j/w if there was a way to do that in the if substring in string: line.
 
Alternatively, consider using an approach that simultaneously finds a string and slices out the substrings surrounding it, for example str.split or str.partition or the various methods in the re module
>>> line = "apple Products Ordered Total Quantity banana LABOR orange"
>>> line.partition("Products Ordered Total Quantity")
('apple ', 'Products Ordered Total Quantity', ' banana LABOR orange')
>>> line.partition("Products Ordered Total Quantity")[2]
' banana LABOR orange'
>>> line.partition("Products Ordered Total Quantity")[2].partition("LABOR")
(' banana ', 'LABOR', ' orange')
>>> line.partition("Products Ordered Total Quantity")[2].partition("LABOR")[0]
' banana '
>>> import re
>>> re.search("Products Ordered Total Quantity (.*?) LABOR", line).group(1)
'banana'
In my opinion, there's almost always a better approach than .index
 
4:14 PM
match objects also support indexing, though I rarely use that
 
In a perfect world, you never need to touch or think about an integer that describes the position of a character in a string
I've got some numbers in my code up there, but they index a tuple or group collection respectively, which is OK
 
would your regex work if the data is on new lines? like:
Products Ordered Total Quantity
SH5500 5
HR5510 2
AR5520 1
MULL 1
PW5520 2
SGD5570 2
LABOR 1
I'd think I would have to add \n in there somewhere
 
@Kevin That's just because they have to return a function that when called with a function as its argument returns a function. It's really quite simple :P
 
@ChristopherBrown Throw in a flags=re.S
 
@Kevin It really helps if you turn your head inside out while you think about it.
 
4:32 PM
Yeah, I definitely need to enter corkscrew-shaped-brain mode in order to reach the correct destination in solution space
Bah, my recursive memoized BFS algorithm yields results slightly out of order if some branches of the graph are larger than others.
I got so caught up in making it elegantly handle infinite cycles, I forgot to handle obscure cases like "what if the left branch is 3 deep but the right branch is 4 deep"
 
BFS can be done recursively? O_0
 
As far as I can tell, no, because the thing I have right now is not strictly speaking "breadth first". It's more like, breadth first unless inconvenient
I'll clean it up and post a copy, for the curious
 
I will have something to think over when I wake up
 
4:50 PM
In a correct BFS implementation, the output of either of the loops displayed here should always be in increasing order. The fact that three element ['b', 'b', 'd'] is yielded after four element ['c', 'd', 'd', 'd'], disqualifies the algorithm from true BFS status.
I believe it still eventually iterates over all legal paths just as BFS does, but it won't do it from smallest to largest
I have an idea for a true recursive BFS which uses a generator that yields generators, but I'm out of corkscrew brain powder, so I can't write it today.
 
5:43 PM
@Kevin "Ut apud se ne dimittatis quicquam de manubrio amicum algorithms infinitis off-in-unum erroribus gaudeat."
Though I have to admit that ""Algorithms that handle infinities do not concern themselves with off-by-one errors." isn't quite as snappy as "the law does not concern itself with trifles".
The unreliability of the translation is underlined by translate's conversion of the Latin back to English: "Do not be concerned with other algorithms to handle an unlimited number of off-the-one errors." :D
 
Cbg, ppl!
What would be the process of determining whether I can install 3.8 on windows server 2008 r1 (without actually going through the process)? Where do I start to look after reading the "Note that Python 3.8.10 cannot be used on Windows XP or earlier." The wiki says server 2008 is based on Windows Vista. Should be fine, right? Let me know if this is better suited for a superuser question.
 
5:59 PM
Wouldn't creating a class and then storing normal variables as instance variables of that class, avoid the need of global? Perhaps something like:
class GlobalRemover:
    def __init__(self):
        pass

def foo():
    inst.foobar = 15
    print(inst.foobar)

def bar():
    print(inst.foobar)

inst = GlobalRemover()

inst.foobar = 12 # Removing this will still work

foo() # Prints the new 15 without global
bar() # Prints the new 15 without global
 
cabbage
anyone else doing PyCon today?
 
6:20 PM
@CoolCloud Sure, but... what's the point of that?
 
@Aran-Fey global is 'evil'? So getting rid of it?
 
No, global variables are evil. And you still have those
Well, one of them
Not that that makes things better
 
@Aran-Fey Still? Without using global ?
 
Yes, inst is global.
 
Just like replacing global with a one-element list in the global scope won't solve your global problems.
Turns out the issue is not with the global keyword itself D:
 
6:23 PM
Oh I see
So even though I don't use global, there are still globalized variables and it is still evil
 
ask yourself what the problem is with globals
 
Global variables aren't bad per se. Like, modules are global. Functions are global. Classes are global. Loggers are global. That's fine. What's bad is a global variable that changes value
 
Oh okay so even inside a class, when you use self.foo = 10 and later self.foo = 15 in some other method, is it still bad?
 
Good question. No, but also yes.
 
Hmmmm I see, thanks :)
 
6:30 PM
It kind of... reduces the problem a little bit. When it's a class, you can easily create more instances (read: copies) of it, which you couldn't do with global variables. So that increases reusability
 
Makes sense :D
 
It also helps that classes have a name. For example, if you have a Person class, well, it makes sense that a person has a name, right? But if you have a global variable name, then there's no context
And finally, classes tend to be shorter than modules. So the "scope" of the variables is smaller
 
Hmmm I should read more about why global variables are bad. Last time I read, I could not understand much from it. Maybe better now
 
simple tip: think big programs, not small. think "updating" the global variable, not just reading
 
What it essentially boils down to is that this:
 
6:34 PM
@ParitoshSingh So how would big programs update these?
 
def add(a, b):
    return a + b

result = add(1, 2)
Is easier to follow than this:
def add():
    global result
    result = a + b

a = 1
b = 2
add()
 
i..uhm..that's a surprisingly succinct program that gets the point across.
@CoolCloud same as small programs do. the updating itself isn't the problem per se.
 
@Aran-Fey True
 
It's when you put 2 and 2 together.. that is..when inevitably bugs develop, how will you track where the incorrect update happened
 
Though in tkinter button callbacks cannot return so you would have to use global somewhere, or store it in a container?
 
6:37 PM
if every part of your program can update a variable, and does update a variable, then when things go wrong, where do you start?
 
@CoolCloud Yeah, a container. Usually a class
 
@ParitoshSingh Hmmmm I kinda get what you mean
@Aran-Fey Actually by container I foolishly meant lists, tuples and dictionaries. But I guess classes makes more sense
 
then, say, your coworker Alex was tasked to update a functionality by showing a bigger figure in one part of the program that used the global var
and they update it...
And then, for the fun of it, let's try to speed up your big code base by moving critical pieces to parallel processing, or maybe ship the workload off to a different machine
oh wait..they use the global vars and update them too...
 
Just add some global locks, it'll be fine /s
 
haha. Essentially, the issue with globals will never (almost) manifest themselves immediately.
You'll just create a booby trap for yourself, your future self, and anyone else who ever needs to update, read, modify, or extend your code in any way
 
6:41 PM
:p now that is evil
 
no, that's eval. but globals are close. ;)
 
insidious
might be the apt word
 
I have a list: a = [1, 2, 3, 4]. How can I get [1, 4] with a[start:end:step]?
 
a[::3]
 
I mean, I want to get the first and the last elements. List could be larger.
a = [1, 2, 3, 4, 5, 6,..., 100] -> [1, 100]
 
6:45 PM
a[::len(a)-1]
 
No, I can't store list to the variable.
 
Not possible then
 
((
 
what's weird are these arbitrary restrictions that are being invented just to make a task that shouldn't be hard, hard.
just write an extra line, it's not a sin.
 
nono, I want one-line solution
 
6:48 PM
sigh.
 
I'm guessing this is part of a bigger program with poor abstraction
 
use ; to write two statement in 1 line.
 
But then again, I'm known to be too optimistic about these things
 
yes, definitely too optimistic
 
actually, the task is to find all numbers which starts on 8 and ends on 8 too in a range. I mean, if we have range from 1 to 100 (for example), we need to find all numbers which is like 8...8
[ i for i in range(a, b + 1) if [ (i // (10 ** x) if x else i) % 10 for x in range(int(math.log10(i) + 1)) ] ]
 
6:50 PM
Far too optimistic.
 
so there in the if statement idk how to check last and first elements
 
is there any part of that task that states you must write terrible code that fits in one line to succeed?
 
That code needs to be at least 5 lines longer
 
im doing it just for fun
 
i see a lot of pain and not a lot of fun in this. but okay. at least that's a reason.
 
6:52 PM
you are right about the pain
the thought I can do nothing with this kills me
 
reassemble
 
actually
I figured out
import operator
operator.itemgetter(0, -1)([1, 2, 3, 4])
[1, 4]
 
obviously you should convert to a numpy array and index it with [0, -1]
 
I cant use numpy
vanilla python only
 
what a shame
 
7:03 PM
@ParitoshSingh [ i for i in range(a, b + 1) if all ( k == 8 for k in operator.itemgetter(0, -1)([ (i // (10 ** x) if x else i) % 10 for x in range(int(math.log10(i) + 1)) ]) )]
done it
now, I can suicide
 
7:15 PM
as always, the harm is already done
 
8:01 PM
cabbage
 
cbg :)
 
cbg
 
8:15 PM
Just stepped in and seen that one-liner. Do I dare scroll up to see what drove that abomination?
 
knock yourself out :P
 
It's a tragic story
 
self-harm, apparently
 
Ok, it really is self-inflicted and I'll just wash my brain of it
 
that one-liner itself requires a TL;DR version
 
8:22 PM
@roganjosh see, when i said knock yourself out, i meant it, so you wouldn't have to suffer as we did.
 
Spoiler: TL;DR is bigger than the one liner :p
 
You've gotta be clearer on these things, Paritosh :(
I mean, on the upside, maybe something was learned this day? :P
 
love was in me all along?
 
8:37 PM
Please don't tell me that's a song reference I should be getting because then I'll feel silly :/
 
no, just an "<x> was inside you all along" reference
 
I was just investigating an issue that my Mac decided to throw up. Apparently I need to disconnect USB devices that are draining too much power... despite it having no USB ports (at least not in the sense that I understand them) and the only thing attached is the yamming charger
 
9:03 PM
@roganjosh that's only been an issue for a decade, apparently discussions.apple.com/thread/3739129
 
I just found it amusing given that the only thing plugged in was actually giving it power... then slightly concerned by the sheer absurdity that it could be the result of a deceased uncle's convoluted way of telling me I was to inherit millions if I just enter certain details
 
9:49 PM
@roganjosh actually such funny things imporoving the way of thinking
ofc we wont use it in production or somewhere else. Made it just because I wanted to make a one-line solution
 
10:02 PM
Pratchett's Equal Rites raises the point that the greatest power there is is to possess magic and not use it.
 
Perhaps Prachett can make @Kevin wish of changing 'Right' into 'Rite' :P
 
He doesn't do many things these days
 
<goes for glass of water> so dry
The person that made a comment that my non-private variables weren't useful in the library I wrote had also apparently taken it upon themselves to raise an issue on another issue on github and self-flag it as a bug when they really were just abusing the actual API I wrote and their use-case was covered by a different object. I'm getting some whole new learnings on maintaining a library
 
10:22 PM
seeking recommendation for tutorial stackoverflow.com/questions/67541474/…
 
I don't think I appreciated how upsetting it could be to have bug reports levelled against my own creation, especially when it wasn't even a bug and the error was deliberate on my part. I have a new appreciation for maintainers
I... don't know what happened to my punctuation, looking back at my last few messages. Sorry :/
@entithat I don't think this was the phrase you wanted (it's actually a cause for alarm). In any case, I'm glad the one-liner was just for curiosity
 
@roganjosh Your ghost USB device is drawing ghost power...? who could that be a case for...
 
@smci Big business is sucking power out of my laptop battery to fuel the National Grid. I've blown the conspiracy wide open!
 
@roganjosh import conspiracy_theory
 
10:40 PM
That module is broken, every object is falsey :/
 

« first day (3863 days earlier)      last day (1068 days later) »