« first day (3799 days earlier)      last day (1374 days later) » 
00:00 - 19:0019:00 - 23:00

00:34
hey , I have a flask system locally hosted via socketio.

every now and then while debugging something, I attempt to refresh the page , it takes so much time and in the end it shows this error
`sqlalchemy.exc.TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30`
iam the only pc who has access to the server, how could I be causing the system to overflow without doing anything ?
the only way to fix this is to shutdown the server and restart it.
Are you still using flask-sqlalchemy?
Then you've borked something in your code. That library basically wraps sqlalchemy and ensures that DB sessions are torn down
i'm confused, what could be broken ? I assume the logic has nothing to do with it. right ?
let me show u how i ran the app
"how could I be causing the system to overflow without doing anything ?" hammering the refresh button?
I mean, I guess that's a contradiction to your statement
00:45
@roganjosh yes like 2-3 times in a row just to make sure that cash are cleared
but iam just one user, when the system goes live and reaches 10-200 users at a time what would happen to it if 1% hit the refresh button at the same time?
Cache* and I was just typing "I guess that's a contradiction to your statement [hammering refresh]" but you've gone from "without doing anything" to admitting that, so the rabbit-hole opens up
lol what are u talking about .. so users aren't allowed to refresh the system 2 times while holding ctrl+sheift + R to clear the caches ?
Lol, I'm too tired for this. Night
alright buddy , good night :D
01:27
@EnthusiastiC What makes them important? How are those lines different than other lines in the file?
01:49
@AaronHall this maybe more of a functional programming thing, but using closures like chat.stackoverflow.com/transcript/6?m=51357096#51357096 but for non trivial purposes
user13727121
02:40
is it better to name a function with the word get? like, get_number, get_name?
03:55
@CoreVisional sure why not
 
2 hours later…
06:03
speaking of canonicals, do we have a good one for "return returns immediately"? A common newbie problem is not realizing that return will exit the current function and abandon any remaining code (like here)
06:15
isn't that basics in any language? or canonicals are just basics?
@tripleee was pondering whether that one could be made into a canonical
@python_user the sopython.com canonicals at present are mostly not newbie-oriented, but I regard that as a problem which should probably be fixed over time; we certainly get a lot of duplicates for NoneType (that one has a canonical), simple NameError for undeclared variables, etc
not to say we should remove any canonicals from the database, just add good general answers for common newbie problems as we come across them
my vague impression is that this resource is not very actively maintained at the mo but the proper regulars in this room can probably correct me or provide a more nuanced account of the situation
one problem is that while there are hundreds or thousands of questions for any of these topics, finding good questions with proper answers is an almost hopeless task at present
finding a good canonical also helps by providing a target for duplicates, so we can clean up many of the effectively abandoned poor-quality questions with at best one or two upvotes
(in some sense at worst, because they would have been deleted by the Roomba if they didn't have stray upvotes)
as such, "canonical" simply means a (or even the) recommended resource for a particular topic
that was a good explanation :D
07:45
@Kevin It's semantics, true. It might be more accurate to say that locals are initially bound to non-Python value (one which has no representation in the language).
S'pose the same applies to globals too. There shouldn't be any unassigned builtins.
@python_user In VBScript (and hence possibly in Visual BASIC?) one set the return value of the function by binding its name, but this did not terminate the function - that rrequired an explicit RETURN or completing the logic and"dropping off the end".
wow, I did not know that, TIL
@AnttiHaapala Nice catch, Antti!
@holdenweb I wish I wouldn't have to catch these.
I'm sure ...
I am worrying that people are overengineering Python standard library with all sorts of nuclear batteries with backup wind power generators..
and that had sat 2 years in review and I haven't even used it, I just read the code twice, and it occurred to me the 2nd time.
07:58
@AnttiHaapala that's what you get for reading the code
modern code is only meant to be written!
08:42
@AnttiHaapala Oof, nice catch indeed
Hey guys are you able to immitate a like query within a lambda function? basically what I have is dpaste.com/96NLCSXY6 essentially making a dynamic search where as typing it would show different results, but since encrypting the email and phone storage they don't react as a like query and was wondering if maybe it would be better to do a lambda search while decoding each email compared
not an answer or suggestion, but how did your scraping take home project go?
@AndrasDeak thanks! my search fu was obviously faulty again
added the tag to that too
@python_user I managed to finish the project and sent it off the end result was to slow the entire project down and sort of go slow and steady to get the results sending the requests randomly between a timeframe of 7 - 15 minutes allowed me to not get blocked. . . They are going to evaluate it and give feedback...
Did my best and made the code as clean as possible so wait and see and if not then find something else ^^ just continuing with a personal project now
08:57
good luck with that
Thanks mate
09:13
@tripleee meta-tag is meta
09:32
I have a StatMachine Class with methods configure/activate/deactivate/cleanup. Now I want to subclass those methods and that in the end of each of those methods which exists in the parent the parent method is called. Currently I always add super().configure() in the end, but I would like to make it more dry. I thought about a decorator, but that trades 1 line with another line. Is there a way to say, when you inherit from this class call all super methods on the parent with the same name?
Is this even a good idea?
10:08
Pretty sure it doesn't get better than the manual super().configure() at the end of the method
10:45
you can use __init_subclass__ to add the decorators automatically.
I would recommend against it, though.
11:05
@Aran-Fey hmmm, not super happy, but I already though that it doesn't get better
@MisterMiyagi why though?
How would you pick the methods to automatically decorate? Do you decorate all of them? That can cause problems with methods like __init__. Or do you make a list of methods to decorate? That's arguably worse than simply calling super() manually, because you end up fragmenting your functions' implementation into 2 parts. Instead of having to remember to call super(), you have to remember to add it to that list, so what's the point?
@Hakaishin The most critical thing is that it's not obvious to maintainers. There are some practical considerations as well, mostly that sometimes you do want to call the methods in different order.
and as such it would be nice to have common logic for all StateMachines tbh the init subclass method looks like exactly what I need
I already have a list of methods, so I would decorate just the one in the list:
transitions_l = [["configure", States.UNCONFIGURED, States.INACTIVE],
                 ["activate", States.INACTIVE, States.ACTIVE],
                 ["deactivate", States.ACTIVE, States.INACTIVE],
                 ["cleanup", States.INACTIVE, States.UNCONFIGURED],
                 ["shutdown", [States.UNCONFIGURED, States.INACTIVE, States.ACTIVE], States.FINALIZED],
                 ]
tbf I'm implementing it loosely no transition states and I have to see how I do it with an error state, but something like "*", States.ERROR should do the trick I think
Can't say I'm a fan of such frameworks in the first place. A state machine should be either some directed graph between states or some linked states. "Write a bunch of lists and strings and enums and sprinkle magic on it" isn't my cup of tea.
I mean it is a directed graph. transitions not in the list above are not allowed
I mean I get what you mean, I also don't like that it's "configure" and that the IDE doesn't see the method, but I don't know how else to implement it. And the idea of a state machine is really powerful
@MisterMiyagi what a definition of a state machine :D
11:18
Meh, let's just say I should never write a book on design patterns. It probably wouldn't manage a PG-13.
I was thinking of something like this:
def __init_subclass__(cls, **kwargs):
    def on_configure_replacement():
        super().__init_subclass__(**kwargs)
        cls.on_configure(cls)
        self.on_configure()
    cls.on_configure = on_configure_replacement
but it doesn't work, because I don't have access to self
on_configure_replacement should be a method, i.e. take self.
unless that thing is called on the cls?!?
@MisterMiyagi yes :D
@Hakaishin Why do you call both cls.on_configure(cls) and self.on_configure()?
11:27
I'm not sure :D I'm super confused. I want when I call child.configure() that it calls parent.configure() at the end too. That was my try of doing tha
but it's obviously not right :D
RecursionError: maximum recursion depth exceeded while calling a Python object
xD
def __init_subclass__(cls, **kwargs):
    super().__init_subclass__(**kwargs)
    def on_configure_replacement(self):
        self.on_configure()
        super(cls, self).on_configure()
    cls.on_configure = on_configure_replacement
I assume this should work.
@AnttiHaapala wait, what's that?
same error max, recursion depth exceeded :D
@AnttiHaapala I know that. Is the other repo where it came from into stdlib?
11:32
yes... some guy decided to go for the "locking alternative" because it has "acceptable performance characteristics"
@Hakaishin which one recurses too deep?
@MisterMiyagi thanks for the interest, I'm making a small mvce
@AnttiHaapala got it
import threading
from transitions import Machine
import enum

class States(enum.Enum):
    # Primary states
    UNCONFIGURED = 0
    INACTIVE = 1


transitions_l = [["configure", States.UNCONFIGURED, States.INACTIVE],
                 ]
transitions = []
for transition in transitions_l:
    transitions.append({"trigger": transition[0], "source": transition[1], "dest": transition[2], "before": "on_" + transition[0]})

class StateMachine(threading.Thread):
    def __init__(self, name):
        super().__init__()
11:38
oh, oops
of course it does :D
...and that's why this is a bad idea
    original_configure = cls.on_configure
    def on_configure_replacement(self):
        original_configure.__get__(self)()
        super().on_configure()
You need some additional scaffolding to skip calling the super method when it does not exist.
NB: I still haven't learned whether original_configure.__get__(self) not passing the type is actually correct or just works on all the implementations I care about.
You can use @functools.wraps(cls.on_configure) and then on_configure_replacement.__wrapped__.__get__(self)(), although I'm not sure if that's actually an improvement...
The super call here goes to Thread, I get this waring: Unresolved attribute reference 'on_configure' for class 'Thread' and the error super object has no attribute on configure
> PEP 252 specifies that __get__() is callable with one or two arguments. Python’s own built-in descriptors support this specification; however, it is likely that some third-party tools have descriptors that require both arguments.
11:44
^Yeah, that's still a lot like "maybe, if you feel lucky, punk".
@Hakaishin Fixing this is left as an exercise to the reader. shifty eyes
:D
PEP 487 sets out to take two common metaclass usecases and make them more accessible without having to understand all the ins and outs of metaclasses. haha I'm not sure it's working :D Still have to dig deeper
I feel this is primarily a challenge of understanding the MRO.
If you know that there is no multiple inheritance, only wrap the method if the parent has the method as well.
Yes :D I found out that this is the issue :P
So I think my question boils down to how to call a method in the init_subclass method of the class init_subclass is in. It would be so much easier if the definition of init_subclass where (self, cls, **kwargs) instead of just cls, **kwargs
12:09
I'm not sure what you need it for, but it sounds like the __class__ variable can help you
class Parent:
    def __init_subclass__(cls):
        print(cls, __class__)

class Child(Parent):
    pass  # output: <class '__main__.Child'> <class '__main__.Parent'>
yes that is it :)
aaah yes thanks it works :) thanks to both of you
    def __init_subclass__(cls, **kwargs):
        super().__init_subclass__(**kwargs)
        parent = __class__
        original_configure = cls.on_configure

        def on_configure_replacement(self):
            parent.on_configure(parent)
            original_configure.__get__(self)()

        cls.on_configure = on_configure_replacement
Shouldn't it be parent.on_configure(self)?
...or parent.on_configure.__get__(self)() for consistency
Actually, I don't think __class__ is correct there at all
__class__ is only "correct" if you inherit only once.
Yeah, just replace parent with cls and it should work
That's enough metaprogramming for today, time to go watch youtube
for trigger, source, dest in transitions_l:
    transitions.append({"trigger": trigger, "source": source, "dest": dest, "before": "on_" + trigger})
12:23
Well, it's a good way to show that maintenance is not for free with this task. :P
@MisterMiyagi YOLO YOIO
@Hakaishin For future reference, when iterating over a sequence of tuples/lists you can unpack the individual elements as above for improved reeadability.
@holdenweb uuuh nice
nvm, I see what you mean.
hmmm, that's annoying
No, sry I don't see. I have StateMachine -> Service -> SpecificService and it correctly calls specificservice.on_configure and then StateMachine.on_configure
It doesn't bubble up the chain, but that's fine, for now :P
I really hope you're only still going down this route for learning purposes, not because you're planning to actually use this code
I am planning on using it, why?
12:36
Surely it should be obvious by now what an unmaintainable mess you're creating?
? Not really no
It's quite nice, I can have classes with these methods and the activate method always runs in it's own thread
The fact that we've collectively spent more than an hour on something that could be replaced by a few super() calls really should be a red flag
I mean kiiiinda ;) But the thing is it's gonna be used often, so it does save time
Carry on then, but don't say I didn't warn you :P
What I'm doing feels like these automatic code generation tools which I hate, but well let's see how far down this rabbit hole I can go :P
12:53
ugh more issues are popping up, it's a hydra. I guess you are right, abandon ship
Now I have this and I kinda don't like that I have to manually start the thread after calling activate anyways and keep track of the is_running, but I guess it is what it is:
    def on_activate(self):
        print("Activating thread")
        self.is_running = True
        self.start()

    def on_deactivate(self):
        print("Stopping thread")
        self.is_running = False
13:09
I don't think we know enough about what you're doing to give you any tips about that, but maybe I missed something
FWIW, I've completely stopped inheriting from Thread. It's never been worth the trouble.
Better to treat Thread as a primitive that you use, and perhaps compose into another class.
Well I agree, but our codebase inherits from it all the time
13:29
Wow, good thing I wrote tests to check if my functions properly throw a DeprecationWarning. I wasn't sure if it was worth it, because surely I'm not stupid enough to mess that up, right...?
Spoiler alert you messed it up? :D
N-no... *looks away*
:D
now that i think about it, it's weird
if you wrote a test like that and then tripped yourself up, you've created a paradox
maybe we're creating paradoxes all the time when we write a single line of test code
we were clearly smart enough to guard against the possibility of something like that, and then stupid enough to fall for it. but how could we be stupid enough to fall for it, if we were smart enough to guard against it
It's called double book keeping :)
I blame caching!
No wait, that's an old answer. Booze. I blame cabbage booze.
13:44
@ParitoshSingh edge cases
Just pick any incompleteness theorem to proof you are as close to perfection as possible.
hey, how do u guys query the latest 10 objects from the database ?
I saw on reddit that the way to do that is before recording anything, I should use
`db.session.flush()` , on sqlalchemy documents , it says it already does that before every save point.

`class1.query.get(10)` i didnt really specified if i want the latest 10 or the first 10 or just random 10.
does it get the latest by default?
@LoopingDev no, no, no, no and no.
get(10) will return the single class1 object whose primary key in DB is 10.
you can get 10 random arbitrary ones by class1.query.limit(10). Naturally you want to do order by if you just don't want to get some arbitrary ones.
14:00
ok i assume its query.last(10)?
14:12
no.
there's no provision for "last(10)"
you need to order by some attribute descending and you can get first 10 with limit(10).
This is about constructing SQL queries, and SQL does not have "last 10"
@AnttiHaapala thanks !!
q = class1.query.order_by(db.desc(class1.id)).limit(10)

if i'm not wrong that is the syntex for flask-sqlalcehmy.
class1.id.desc() should work alike
so that is still a query, if you want a list of those objects, add .all() (or also, objects = q.all())
you mean like :

class1.query.order_by(db.desc(class1.id)).limit(10).all()
or
class1.query.order_by(class1.id.desc()).limit(10).all()
both worked with Flask-sqlAlchemy , thanks a lot !
14:25
Is it only me or is this bad code?
self.foo_group.to_all(lambda foo: foo.set_param1(self._param1))
self.foo_group.to_all(lambda foo: foo.set_param2(self._param2))
self.foo_group.to_all(lambda foo: foo.set_param3(self._param3))
self.foo_group.to_all(lambda foo: foo.set_param4(self._param4))
self.foo_group.to_all(lambda foo: foo.set_param5(self._param5))
param have descriptive names, but this just feels like way too much repetition and something which belongs in a yaml file and then should be automatically read
you could zip the setters and params, and call to_all in a loop.
5 lambdas, you could have one function :D
14:48
and you'll need setattr and getattr
15:16
To begin with, methods starting with set are usually an antipattern compared to properties
... Not that converting to properties here would fix the repetition
15:28
people who've been in industry longer than I have: I'm reviewing a colleagues code right now, and I've encountered this:
# comment about the following line
actual_code()
I made a minor comment that this shouldn't be in two lines. Colleague says "Personally, I prefer this style of commenting for my own readability since it means the comment explaining the line comes before the code itself". I disagree - I think the comment should be at the end of the line (on principle, and there's no line length violation in this case to override that)
My understanding of commenting philosophy is that comments should supplement the code, and explain "why" (not "what"). Has anyone seen this sort of commenting practice in the wild? It seems very unnatural to me
basically, if this sort of commenting occurs in the wild, my comment is just a "me problem". Otherwise, I'm somewhat justified in calling it "not standard practice"
hey has anyone ever used dataclasses to serialize objects from the database ?
I use that when the next 2 or 3 lines are related to the comment like
# call the functions
f1()
f2()
I have only professionally coded about 3 months now :D so this is not what you were looking for, but you could think of why people like me would do this
I also put a comment above a "paragraph" of related statements
if I am writing something that needs a comment, it's probably not a short comment that will fit at the end of a line. unless it's a 2-3 word comment stating something non-obvious.
problem is, I don't like mixing end-of-line comments and pre-line comments. so at least in a function/class, I'll stick to one pattern; preferring the pre-line version
"above a paragraph of code", I get. This was above a single line, which I really dislike. I'm trying to deteremine if my dislike is just personal preference or whether it is based in standard practice
@aneroid "don't mix comment style" is a very good point
15:41
@inspectorG4dget it may be personal. most of the code I've seen/worked with is 99% pre-line
@inspectorG4dget I think that's fine, I do it all the time. If anything, I'd say you need a reason to put your comment to the side instead of on top. Maybe the comment will grow longer in the future and won't fit on the same line any more. Or maybe you already have a bunch of other comments nearby and only one of them fits on the same line, leading to code like
# a long comment, spanning multiple lines
...

...  # this one's on the side for some reason

# another comment
...
I suppose in my professional experience I see comment-on-top less frequently than comment-on-side. Perhaps not to the extent that I'd call one standard practice over the other.
interesting. So it seems to be very much a team-level code-style
even worse, end-of-line comments are like: x = 3 # set x to 3 which drives me nuts. in those cases, I don't mind "initialisers" to be eol comments: x = 3 # number of steps if not just steps = 3 or ...
foo = []  # results
bar = []  # intermediate values
python.org/dev/peps/pep-0008/#comments, is worded such that you can rules-lawyer your way into justifying comment-on-top, by saying that # frobnicate the widget. is a "block comment" despite it being the smallest paragraph in the world. But I think the spirit of the rule is that block comments are for in-depth explanations of the following code.
On the other hand comment-on-side is allowed in both spirit and read as written
15:46
thanks folks. You've given me much to munch on
Whenever you turn to PEP8 for commenting/documenting purposes, remember it wants your docstrings to look like this:
"""Return a foobang

Optional plotz says to frobnicate the bizbaz first.
"""
# set x to 3 is banned forever, however
confession: sometimes I do something much worse: paragraph style comments before the code block as a docstring. I won't apologise for it, it's very readable
When will the government stop your sinful hand
@aneroid * assuming I haven't already put that in the function docstring already
15:48
> Use inline comments sparingly.
I see comment-on-bottom is not mentioned in the PEP so I must assume that it is allowed, and that I can do whatever I want with it
no space after the pound sign, no complete sentences, no proper capitalization, all in esperanto. Chaos reigns.
/me preps holy water to throw at @Kevin
#NotReligious
PREP 8. Hint: not to be used orally.
@Kevin oh dear God. I always hear my second year Java prof: "I can read Java!"
@AndrasDeak and you've just made it the butt of all jokes :P
Concept: secular holy water. Now available at Whole Foods in the homeopathic section.
Water is well-known for its ability to dissolve/neutralize/dilute dangerous things such as acid and lava and house fires. By diluting water in water to one millionth of its original concentration, its abilities are significantly magnified.
I'm surprised PEP8 advocates for two spaces after a sentence-ending period in a comment. AFAIK single-spacing is the dominant recommendation in American English style guides for written prose.
16:04
anyone work with github actions? I restricted the repo to run the linter on pull_request, but that means that the linter does not run when I push changes onto the PR branch "because I didn't create a PR"
Perhaps emacs and vim are to blame, because they have an easier time distinguishing sentence boundaries from e.g. acronyms if only the former use two spaces
My vim doesn't and shouldn't do that. LaTeX does.
I'll take your word for it. I have little direct experience with any of them.
@Kevin to be momentarily pedantic, water "diluted" to one-millionth of its concentration is air, or more likely, a partial vacuum
On closer look, I misread en.wikipedia.org/wiki/Sentence_spacing_in_digital_media, it says "vi", not vim
16:10
Two spaces after a period (or any sentence ending punctuation) used to be the recommendation because word processors only had fixed-width fonts, and it helps break up the paragraph. If your comments are read in a fixed-width font... the principle still applies.
It's no longer the rule because word processors nowadays know when they're at the end of a sentence (most of the time) and know to make the space a bit bigger for that case.
I like my paragraphs unbroken. Big hefty chunk of information
hey i'm trying `dataclasses` for the first time it releases list of objects like this

x = class1.query.filter_by(id=class1.id).all()

// x return something like this [ class1(id=2 , name='some name', someInt=342), class1(...) ,... ]

looks pretty decent but what is next ?

when i jsonifiy it and print the result
v = jsonify(x)
print(v) --> <Response 390 bytes [200 OK]>

I'm trying to pass v to jinja using

const test = {{ v }}

it gives me an error because it reads exactly what we saw on python
is there any table-markdown format which allows for multiple header rows?
@LoopingDev what is x's type?
At first glance I'd guess list, but it might be a custom list-like type with strange behavior when jsonified
@Kevin how to check ? i think it's a list .. its what dataclasses does
16:23
print(type(x)) should tell you
Just to confirm, are we talking about the built-in module dataclasses or something else with the same name?
None/n/n
what the hell is that ^^
so i was following this answer stackoverflow.com/questions/5022066/…
tom's answer , it's the third ones
"Python 3.7+ and Flask 1.1+ can use the built-in dataclasses package". Ok, so it is the built in module.
Uhhh it's quite unusual for print(type(x)) to display None/n/n
let me try it again then
I'd go as far as saying it's impossible unless print or type have been overwritten, or the stdout object is doing something silly
Not impossible when your environment is something other than a regular old cmd window, I suppose
Metaclass' __repr__ is too much of a stretch?
I hear the web has some dark corners.
16:33
metaclass repr... I need to write that one down in my underhanded tricks notebook
@Kevin sorry could have been a typo or something
i cleaned the print line and did it again it said that <class 'list'>
Ok
pretty sure you want json.dumps instead of jsonify
Oh, I misremembered how jsonify works. It returns the json data wrapped in a response object, which is why it says response 200 OK
@Aran-Fey let me try it out
16:36
Now it makes sense. Yeah, if you just want regular non-wrapped json data, use json.dumps
TypeError: Object of type class1 is not JSON serializable
maybe this is important
Oh right, I keep forgetting dataclasses can't be jsonified just like that...
I also forgot.
It's surprising to me that jsonify didn't raise a similar error. Is it doing lazy evaluation? Or is it taking creative liberties with what can be serialized?
json.dumps([vars(obj) for obj in x]) should do it
but i didnt add this line
` users = User(email="[email protected]"), User(email="[email protected]")` i dont know where am i supposed add if i have to.
@Aran-Fey lets do it.
16:40
I'm curious what the output of jsonify(x).text would be.
@Kevin will do both
creating users probably doesn't matter right now because you're not getting a NameError
@Aran-Fey TypeError: Object of type InstanceState is not JSON serializable
These newfangled stdlib modules are so unpythonic -.-
@Kevin AttributeError: 'Response' object has no attribute 'text'
16:43
json.dumps([dataclasses.asdict(obj) for obj in x])
it's kinda odd why is this so hard to use form package that comes with python?
@Aran-Fey AttributeError: 'function' object has no attribute 'asdict'
lets read the document ^^
dataclasses, not dataclass
Dataclasses in particular are not special in terms of being unserializable. Almost all types you can find in the built-in libraries are not json serializable.
Basically everything but integers, floats, strings, lists, and dicts. That leaves like 100 unserializable stdlib types.
@Aran-Fey that wasnt a typo ? from where am i suppose to get it ?
dataclass ?
import dataclasses
16:46
oh ok
If you hadn't even imported dataclasses until now, I don't think you can blame dataclasses for the problems you've been having ;-)
My money's on a from dataclasses import dataclass import
Yeah :-)
@Aran-Fey lol well u won :D , there is not dataclasses form dataclasses , just data class as i did
Or perhaps he's defining his dataclasses in another file which he's importing here
16:50
@Kevin i do
could that be the problem ?
Nah, probably not
i just think it's better the documents for an example or a hint
import statements are usually harmless unless you've wontonly polluted the namespace with a lot of ambiguous variable names. But that almost always happens only if you do from thing import *
i dont think that is the case here, i only like 5 classes so far.
circling back for a minute -- does jsonify(x).text give anything useful and/or interesting?
16:54
i believe that is what we got from it AttributeError: 'Response' object has no attribute 'text'
hello! I have a numpy array containing lists of 3 elements [[index, value1, value2], [[index, value1, value2], ...[index, value1, value2]]. How can I search for the indexes? Like : I would like to get the value 1 and 2 from index 2 (or I would like to take the index from the corespounding value1 and value 2)
Sorry, I must be misremembering the name of the attribute I'm thinking of. One sec
sure take ur time , thanks for all the time u gave it , iam grateful !
hey i found this
could be useful
If jsonify turns out not to have magically good serialization, Aran-Fey's dataclasses.asdict suggestion seems quite promising
If you're stuck on that because you tried from dataclasses import dataclasses and it crashed, try just doing import dataclasses in addition to your existing from dataclasses import dataclass
ok it looks ok now , lets give it a go
yeah it didnt work
`ImportError: cannot import name 'dataclasses' from 'dataclasses'`
i only wrote this
`import dataclasses`
17:03
Sounds like you still have a from dataclasses import dataclasses floating around in your file somewhere
wait a sec
You might not get an error or warning from your IDE before runtime, if it's not trying very hard to validate the module's public api
hey i think that is a hit!
(which would be understandable because bulletproof validation would be NP-hard)
it broke because of something else but i can read it on cosole, looks like it's a decent json obj!
17:04
Progress!
Yup it worked !!
thank you so much , u guys are awesome !!
@Kevin
@Aran-Fey

thank you so much!!
It occurs to me that from dataclasses import dataclass, asdict would be stylistically better than having two imports, but I like to focus on getting things working before making them pretty
yeah me too ^^ , i have lots on comments that makes the code file looks like a trash but i keep them because i might need those tips / old code if what i'm doing failed , so i definitely dont mind an extra line ^^
thanks a lot! , querying from database to the front end is like 2 lines now
Glad to hear it :-)
For long-term projects, consider using source control as a way of storing old versions of your code. It frees you from the burden of having old commented-out functions in your file "just in case"
I admit that I have quite a lot of just-in-case commented code in my quick projects, because I can't always be bothered to spin up a repository
@CătălinaSîrbu Hmm, sounds possible... I'll play around with this and see if I can figure something out.
Actually I think I need to tell you the long story :))
Having about 500 nodes like this
<node id="1">
  <data key="d0">2.1</data>
  <data key="d1">10.47</data>
</node>
17:17
that is great idea, i ususally just dump them if they didnt work or seprate them in a folder with title of what they do.
for example .

if i had a meathod that pulls from db to front end that i would replace it by the one we figured out today. and i will leave it under a folder
( depreciated - form_Db_to_front end)
they are used for pathplanning into a simulator. I have my own x,y coordinates and I somhow need to see if I am near the 1,2,3, etc node
i will look into source control , i might be able to dump all those things there
"My programming problem started last autumn. The crisp fallen leaves crunched under my hiking boots, a poignant reminder of the impermanence of things..."
the problem is that each time I have to iterrate through the entire numpy array and check that delta x and delta y (my pos - each node) is the minimum
"Each time"? How often do you have to do that?
17:20
"Returning to my family's cabin in remote Maine, I recalled the recipe for numpy arrays that had been passed from my grandmother, to my mother, and now to me. But the aged and creased paper had faded at the last step, where it described how to get the index"
so I'm telling you this maybe you have a better ideea
let's say oance every second
@CătălinaSîrbu Could you create a short mcve?
because this is the gps refresh rate. Meaning each second it gives my my position
mcve =?
not really
17:23
Can you create a not particularly short, but still complete and verifiable example? :-)
I have no pride, I'll run a thousand line program if I gotta
the problem is that this is simulated under ubuntu on gazebo simulator and ros
but I can give you the xml and just send you a bunch of coordinates stored into a file
to simulate the simulation :))
just let me know
If the big-picture problem here is "I have a list of coordinates, and my own coordinates. How do I quickly find the element in the list that's closest to me?", there's quite a bit of academic research into this problem: Nearest Neighbor Search
thanks I ll look
yes, that's the problem basically
Ah, the wiki article also mentions kd trees, so it must be a fairly reputable approach
17:32
nice
O(log N) could be quite zippy if you have only 500 nodes
A minute ago I was going to suggest generating a voronoi diagram, but on further consideration I don't think it would contribute anything beyond looking cool
18:19
anyone know what PEP8 says about blank lines having whitespace? I see violations in linters, but I don't see any specifications on this in the PEP8 docs
18:32
Cbg guys, I ran into bit of a trouble. I am making a list of numbers and then iterating through list of numbers and then i want to call the function that creates the list and then continue the looping forever.
import random

def creator():
    return [random.randint(0,21) for a in range(6)]

def typer(l):
    print(l)

lst = creator()
for a in lst:
    typer(a)
This is what I have so far, which calls the function and prints it out, what i want is, once the item in lst is over, to run creator() and then run the loop again and call typer().
Any ideas?
18:46
Put the last three lines in a while True: perhaps?
00:00 - 19:0019:00 - 23:00

« first day (3799 days earlier)      last day (1374 days later) »