« first day (3802 days earlier)      last day (1150 days later) » 

1:40 AM
quick question, but is there anyway to instantiate a class, and set its parameters without having a variable point to it.
I have a dictionary and im trying to set the values to new instances of a class. I believe in C# it would look something like a = new b(){var 1= 0, var 2='a'}. Is there anything like this for python?
 
2:02 AM
you want a dict of instances?
 
2:14 AM
nah i just want to initiate the instances as im adding them to the dict
err the objects*
 
what stops you from doing {'o1':MyClass(args), 'o2':MyClass(args)}?
 
I dont know all the syntax for python yet heh...
 
you should look at that first then
 
ya, been learning as I go... I wont retain the information well if I just read it
 
whatever works for you :)
 
2:18 AM
its nice how easy python is though... I didnt realize how simple it was till recently... very freeing lol
 
very freeing = more bad code if people dont know what they are doing
 
Lol ya it is much harder to keep clean...
 
 
2 hours later…
user13727121
4:23 AM
@Aran-Fey May I know which end of check_guess_number? I keep getting NameError no matter where I put it, dpaste.com/HC94DZZTW, this is very frustrating...
 
Why is everything wrapped in function calls?
Is this a specific exercise/coding style you're trying to practice or are you trying to be "pythonic"?
 
user13727121
@roganjosh i have another version of this, it works, but it uses no function, dpaste.com/F2SQ9NYQ2, basically, I'm trying to practice using function by breaking down my first version of this program into pieces
 
user13727121
@roganjosh No, not practicing any style, though I do try to implement my code in a more Pythonic way. Anyway, the first version looks like a total mess, decided to break them down into smaller pieces by using functions and call them whenever I need to repeat a certain step in the code, turns out, it's even worse than the first version
 
Ok, that seems like a reasonable endeavor :) It looks like you're trying to maintain state with functions (I feel like I rambled about this earlier?). Ideally, your functions would be stateless
I think it's fine here that you have a loop that maintains the loop count (the state) and you would want functions that just act on whatever arguments you send them. They don't "remember" anything
At least, that's the impression I get of what you're trying to do
 
user13727121
Aran said something about placing it at the end of check_guess_number, I've been doing that and trying to figure out which end because I keep getting NameError everytime I do that
 
user13727121
4:47 AM
This is my current code, everything works fine except for the commented code at the end, dpaste.com/FDKP5ATTZ, slight changes on check_guess_number
 
I'm not so sure it does. It tells me I'll have 3 guesses and then exits
 
user13727121
@roganjosh Thank you, @Aran-Fey provided a link to his/her post about writing readable code when I first posted the first version of this program here to seek help, the example in that post is very similar to the way I code my program, so I try to improve it and make it more, I don't know, readable.
 
user13727121
@roganjosh That's my issue right now, I'm trying to get the commented code to work so that I can implement another if statement to test if the count is more than the limit, which is 3. There's no point for me to write that if I can't get the number of guess attempts by the user.
 
@CoreVisional Sure. and I think what you're doing is valuable learning, but I think you took it a bit too far. For example, this is just never appropriate:
"""
Importing the 'random' module will generate a random number for
the user to guess and randomly selecting the winning number.
"""
import random
You shouldn't need to explain your imports. Their use in your code should be obvious. That comment is noise to me, so it makes things less readable
The only time I've ever had to put comments on imports is when deploying dashboards on our internal system that has... interesting... ideas about what a valid filepath is, so I had to launch the app from a top-level directory that breaks just everything :'( In that case, I have to wrap imports in except ModuleNotFound handlers which is gross
 
user13727121
5:02 AM
@roganjosh I'll remove that. You could say that this is like a style I'm practicing since I don't usually comment on my codes, bad habit, I know, that's why I'm trying to comment on my codes as often as possible to make it into a good coding habit, hence the comment on that module
 
Please be aware that I'm just giving general feedback. It's not a criticism, it's only to try help as you learn. I hope you don't take my comments badly :)
Another thing - have you seen PEP8? That will also help with readability because many people will conform to that standard so it helps to present code in a way people expect
 
user13727121
@roganjosh I have no clue of what you've just written but I have a feeling I will be crossing that path one day
 
@CoreVisional pray you never have to. I'm close to making a calendar reminder on repeat for "moan to engineering about dashboard deployment"
 
user13727121
@roganjosh Yes, I read that, but not that in-depth yet, it's mostly about variable naming in function, commenting, indentation, those kinds that I'll be applying based on the knowledge I have in Python
 
I take the 80 character line limit way too seriously. I get palpitations if code crosses the almost-arbitrary line in my editor :P
 
user13727121
5:10 AM
@roganjosh Nah, I do welcome criticism about my code and coding style though, I'm learning this by myself, so that means I'll never learn to code correctly if I'll just always get a pat on my back
 
user13727121
@roganjosh Nvm, it's per line
 
They are. Palpitations were had
 
user13727121
5:38 AM
Anyway, I'm gonna give it up for a moment and come back later to fix this frustrating issue
 
6:37 AM
mods appear to be asleep, there's a spam on the python and amazon tag been left up for 11 minutes now
haha as I was saying it just got deleted
 
7:34 AM
@CoreVisional After the while True: loop
 
8:32 AM
Someone really didn't like my usage of golden hammer on their set of float question...
 
Neither do I, to be honest. The question is "Do sets of floats use X comparison function or Y?", and the duplicates are "How can I make a set of floats with X comparison function?", "What's the best way to compare floats with X comparison function?", and "How can I check for NaNs?"
 
9:03 AM
what's with people rushing to meta these days? oO
 
Does linux seriously not have a mechanism that lets you define user-wide environment variables? There's only global settings with /etc/environment, plus a dozen random startup files that depend on the shell you use?
 
don't think there is any. at the end of the day, the environment is set by applications; the shell just happens to be one.
the init service would be closest to linux setting an environment for you.
 
Ugh. Why do so many programs use environment variables for configuration anyway. I wouldn't have this problem if python had a config file in .config, like any sane program does -.-'
 
 
2 hours later…
11:08 AM
I swear sometimes that plotly.js was invented just to test me. 4 hours later and it still keeps inventing a second, invisible y-axis for my mixed bar chart :( It's a shame that dash will be fixed to this; at least I can try another graphing library
 
If it's invisible, is it really a problem?
 
Yup, because the scale is completely different. I need to plot bars for historic sales and then a different colour set of bars for forecast sales into the future. But the second set of bars (the future) shows 8000 cases at the same height as 20k cases in the past
 
@Aran-Fey yeah, unfortunately the alternative probably would be mark as unclear, since the question really was framed in a bad way.
 
And since the graph is dynamic, I can't sensibly fix the scale
 
user13727121
@Aran-Fey Oh my god, thank you sooo much!! dpaste.com/DFY8YX7E8, I wanted to remove guess_count as check_guess_number's parameter because I have guess_count variable outside the function, therefore, I thought I wouldn't need it, then the program outputs an UnboundLocalError, I don't plan on using globals since I read that it can be "problematic" sometimes
 
11:18 AM
@metatoaster Honestly, I don't see a problem with answering the question like "Sets compare elements with ==, so it boils down to how equality is defined for floats. And float equality doesn't include an epsilon."
 
still feels it's nothing novel because the other questions answer it much better, and for the record the downvote wasn't from me
 
I don't understand what they're hoping to achieve on Meta with that one. "Are these questions truly duplicates then?" is paper-thin context for it belonging there
 
11:35 AM
@PaulMcG Not sure how much you are still looking into parser theory, but I stumbled upon a nice paper on left-recursive PEG parsing via bottom-up matching. It's well-written and has a brief but sufficient implementation description. Might be of interest to you.
 
 
1 hour later…
12:47 PM
<maniacal laughter> I found the bug. I had duplicate values at multiple dates and plotly is silently additive with bar charts - it will sum the duplicate values but only display the singular last value it sees for each date when you inspect each bar. What a day :'(
 
1:30 PM
Do I have to call shutdown_asyncgens() and shutdown_default_executor() before calling event_loop.close()? The docs are not particularly enlightening
 
@Aran-Fey When in asyncio, do as asyncio.run does.
I still think it's no accident that the asyncio.run docs link straight to the source code.
So, cancel all tasks, then run shutdown_asyncgens(), then run shutdown_default_executor(). That should clean up all properly implemented resources *cough*. Only then is it safe to throw away the loop by closing it.
 
Hmm. I don't think any tasks should be running at this point, but maybe I should add a loop that cancels all of them just to be safe?
Probably not, if there are still tasks running, something must've gone wrong
 
You might want to raise an exception if there is anything running at that point. Or at least a warning.
I prefer to get yelled at when making concurrency mistakes.
FWIW, that might depend on whether all tasks actually can finish. In our async simulation framework, we explicitly allow for expendable background tasks similar to daemon threads.
 
Good point, I've had a case where I had to spawn a background process. So I guess I'll just cancel everything
 
1:58 PM
For today's lucky 10 thousand who haven't seen this gem of a music video yet: Fever The Ghost - SOURCE
 
2:27 PM
Nowt like a picnic and a game of cards while the party's going off :)
 
3:00 PM
@roganjosh sorry for late response, i have just seen the link, looks pretty smooth!
not sure why i didnt get notification for that mention yesterday.
 
Not sure. Overall, I think there will still be cleaner ways to do it, but that's at least a baseline
 
you know what, I've been thinking a lot about it and I really want to give that complicated method of mine a try, so I'll give it a try and give u my feedback on it.

i thought about it, it's basically keeping track of the user's sessions and delete them when the session drops.

if I need to drop a notification/message to a user, the app should send the notification to all opened sessions of that user. ( which would be stored in a separated table ) , that might be ok to do for a small group company ( 10-50) but i understand that would be more challenging in a larger scale companies.
 
U do u
 
yeah, we have to try and fail, we might discover something interesing.
 
3:57 PM
@MisterMiyagi I've downloaded that article, thanks! LR is a constant pain for me with pyparsing, and the PEG parser in Python seems to have solved it also (I think both articles include the requirement to use packrat cache).
@roganjosh I had a similar issue with an inherited codebase that (for some reason) vendored in a package, and required Python path munging through either a PYTHONPATH=path_to_vendored_stuffprefix to the Linux command or messing with sys.path before doing imports - both of which I found cumbersome and ugly. My solution was to add a .pth file in the path, which cleaned up the related bash scripts and all the Python sys.path cruft.
@roganjosh When we lived in Maine and would drive through New Hampshire to get down to Boston, I always winced at the toll booth between NH and Massachusetts - after throwing my coins in the basket, the gate would rise and the stop light would change from red to green, but the green lens had "THANK U" printed on it. Good grief, could we have spent just a couple more tax dollars to get a Y and O in there?
 
4:15 PM
hey, I have a files that has noting but class

i have another script that once i run it should pull those classes and create them to the database

but in doing so I keep getting this error .
`cannot import name 'class1' from partially initialized module 'classes' (most likely due to a circular import)`
 
Draw yourself a graph of the imports in your two files. If you have the case where each imports something from the other, that is a circular import. You can fix this by moving one of the imported things out to a separate module, and then have both of your current modules import from there.
I find that drawing simple graph diagrams with actual pen and paper helps me visualize dependencies like this (or relationships between services in a distributed environment), without having to wrestle with drawing software or graphical markup.
 
it just 1 file that i need to pull and all it has is those few lines

`from datetime import datetime
from dataclasses import dataclass
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
from app import db

db = SQLAlchemy()`

then classes

then nothing , it doesn't have any information on how python could execute that file at the end of it and i think that might be the issue based on what i read here, i could be wrong . https://stackoverflow.com/questions/744373/circular-or-cyclic-imports-in-python
 
And app.py imports this file?
 
not app.py ,( create_classes.py )
app.py imports them just fine
everytime i want to change the classes , i used to copy them to the create_classes.py file, and it works fine
but i just wanna know what is wrong.
 
For one thing, your comment about "it doesn't have any information on how python could execute that file at the end" is a incorrect concept on your part, and clearing that up might help a bit. Everything in that file is something that Python will execute. The imports, the assignment to db, and the class definitions themselves. The Python runtime actually runs all those statements. Python isn't like languages like C where things like includes or structs are just compile-time definitions.
Python actually runs that module when it gets imported.
 
4:29 PM
thanks for clearing that up.
 
Shifting that mental model might help you think through how circular imports can occur.
And it may be that its not a simple "A imports B" and "B imports A". It might be a circuit involving modules A, B, and C.
 
i tried to import classes from app.py into create_classes.py , i got the same issue.

app.py can import classes and classes can import db from app.py , but create_classes.py can see either of them.
@PaulMcG maybe because classes depends on app.py ( it pulls db from it ), do i need to add app.py as well ?
 
So app.py depends on classes? Then what is it in app.py that the classes require? Whatever that is, try moving to classes, or to some separate module that both can import.
 
hey I think i got it fixed
 
@PaulMcG gosh, that's them really putting a boot in when you're already paying a toll! :P
 
4:38 PM
so app.py does also import another model that is passlib.hash in it.
so once i imported that into create_classes.py before classes.py, it worked.
@PaulMcG thank you for helping me understanding what is going on :)
 
This sounds totally borked btw. Why do you have models/classes in app.py?
 
@roganjosh When I was in school this man was Secretary General of the UN - but I don't think we are talking about him.
 
There's a reason that we split things out into routes.py and models.py because it adds some structure
 
@roganjosh lol i don't , in app.py i pull data , so i need the models/classes here.
i just import them using from classes import *
 
18 mins ago, by LoopingDev
it just 1 file that i need to pull and all it has is those few lines

`from datetime import datetime
from dataclasses import dataclass
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
from app import db

db = SQLAlchemy()`

then classes

then nothing , it doesn't have any information on how python could execute that file at the end of it and i think that might be the issue based on what i read here, i could be wrong . https://stackoverflow.com/questions/744373/circular-or-cyclic-imports-in-python
What is "then classes"?
 
4:40 PM
yes
 
lol
This is crazy
 
I believe it is a bunch of class definitions.
 
@PaulMcG that is exactly what it is, it's like a group of all the class definitions , it helps alot
it's like splitting the app into an organized categories/groups.
 
I said you shouldn't have models/classes in app.py, you said you don't, then I asked what "then classes" means and you agree that it's a bunch of class definitions
So, what is it?
 
I don't think we are looking at app.py here, since it does an import from app
 
4:44 PM
It should be app.py though, because that's where they're initialising the db?
Actually:
from app import db

db = SQLAlchemy()
^ That doesn't make sense
 
yes that is not app.py
that is classes.py
 
OKAY I was about to say something similar
 
well i kinda needed db to define classes.
 
:P
@LoopingDev no, the structure is all over the shop here
 
@LoopingDev Also note that the code is executed only once. If a module is already present is sys.modules then that reference is used rather than executing the code a second time.
 
4:46 PM
you mean i should import SQLalchemy in classes and just reference to it in app.py?
 
Flask plugins come with an init_app() method. It's a requirement (IIRC) that they provide this interface
You should be instantiating the db at the place that you create the app itself
 
that is what i did
it's instantating on app.py
 
Not from the code you've shown you've not
 
The classes might use the db as method args, or may get initialized with the db, but they should not reference the db as a module-level name. That's probably where this circularity is coming from.
 
but i have imported it in classes.py
 
4:48 PM
You're importing and defining it
 
`from app import db`

app = app.py , db was defined there.
ohhh, isee now
 
Please follow the Flask Mega Tutorial. I can already tell that this isn't the end of your issues on this one
 
I'm bowing out now, since Flask and SQLAlchemy probably have standard structures that address all these, and I haven't looked at them in detail for a while.
 
Absolutely, I'm sprinting in this project and I'll definitely spend time cleaning it up before release.

but right now i need to make progress , it doesn't need to be in perfect condidition
 
Flask-SQLA is well established. It will wrap the app object and you'd normally initialise it in an app factory so that it can teardown sessions. Models defined with Flask-SQLA cannot be used outside of an app context, though, so it has limitations
@LoopingDev it needs to be in an extensible condition though, right? Are you going to go back and rip your whole structure apart once you clear the immediate hurdle?
 
4:54 PM
@roganjosh pretty much if i had to lol
 
ugh
Then your rushing is a false economy
 
Hello
 
Hello
 
it depends on whom you're working with, some would invest in quality, others just want a quick start, up an running yesterday, they don't understand anything but what they can see with their own eyes.
 
Error: 500 is attractive, I'll give you that
 
4:59 PM
lol
 
Beats 404 any day
 
yeah, I'd say ^^
 
How can I read the 7z (single csv per zp example: syslog.7z) file from a minio bucket and then write that as a text file so that I can call it leter.
 
@DarkStar Install pyunpack and patool
https://stackoverflow.com/questions/41191991/how-can-l-read-and-transform-7z-file-into-csv-using-pandas-python
 
@LoopingDev you haven't known me for very long. Had you, you'd know that I break a lot of rules at companies where I work to deliberately get something visual that shows value in what I want to do. I still think you've got a broken setup here
 
5:04 PM
nope, not here , this a charity group and they are in need, really
 
ok, thanks let me try @LoopingDev
 
@DarkStar you are welcome
 
Well then it's even worse, no? There are two things; breaking rules and making something that works, and they are distinct. You have neither, @LoopingDev? Rules here are not data-protection-type rules but managers telling me that I shouldn't get involved in certain kinds of systems because they're "fine"
@DarkStar please see our formatting guide for chat
@LoopingDev Do you have this on a github that's open? What does the charity do?
 
@roganjosh yeah it's definitely different that what they do here.
the charity involved in providing medical aids, food , clothes anything they get from donors they try to provide help as much as they could, and you guessed it, this covid, they were got busier than ever.
 
Hello @LoopingDev, I can not create a question? could you please tell me why?
 
5:19 PM
@roganjosh i don't use github at the moment as I'm not supposed to share the source code as part of the contract.
 
I tried to use py7zr instead of pyunpack, is it the same?
 
@LoopingDev why are you on a contract for a charity?
 
@DarkStar i'm sorry i have no experiences with this package, Just try to read the document and start with the example on there website.
 
I was just going to say that I would try get things in line for you while I have an hour spare, but clearly it's not quite as charitable as you've made it out to be
Well actually, I can see reasons why you wouldn't want to open-source it, so I take that back. But it's still odd that you don't use github
 
@roganjosh because they are worried about the data of their members and donars.
that is quite generous of you , thank you so much but I don't want to be abusing someone else's kindness and drag them/him with me into this.
 
5:25 PM
@LoopingDev And this is what I expected to get to the source of. Are you sure you know how you're going to protect their data?
 
@roganjosh after Facebook data sale , i don't trust anything over the internet in general, apparently hearts could get corrupted as well just like governments.
@roganjosh i'll do my best, I'll research everything as much as i could before I release anything out there.
but right now in testing phases, I will not crowed my head with security concerns
 
This.... sounds like a really bad idea. But ok
 
they just need to see it running, because they have a huge knowledge gap.
that is my biggest concert.
 
Not really, because then they will come back to you and say "yes" (in your best-case scenario) and you have no idea how you'll secure things for them
 
@LoopingDev MUCH easier to build a system that's secure from the start. Retrofitting security never gives the best results.
 
5:30 PM
So they've just been mislead that you can deliver something that you don't know how to do
 
@roganjosh why you called it mislead?
@holdenweb right now i just don't check the users inputs, I'll add that later.
brb
 
@LoopingDev Do they know that you've not built an app before?
 
6:34 PM
Anyone have experience with aiohttp? I've switched from requests to aiohttp and now I get semi-regular ServerDisconnectedError exceptions. Is that normal?
 
Why did you stop using requests?
 
7:13 PM
I needed something async
 
@roganjosh absolutely but other alternatives are quite expensive, so I was able to help I would be grateful, and I think I could provide at least a semi-stable app.
 
7:42 PM
Hi, what would be another string "multiplication"? apart from multiplying their charsums? Can be anything and not restricted to numbers. But can't think of something. With "addition" it's easy, just put them together.
 
@SAJW hello. What do you mean? And why do you think there should be a meaningful operation like that?
 
"addition": "dad"+"mom"="dadmom", I just thought maybe there is such thing as stringmultiplication
 
Just to throw in some math babble: in my head strings are essentially vectors in a vector space: you can add them and multiply them by (integer) numbers. But you can't multiply vectors in a vector field in a general case; you need something like a number field for that.
 
lets say for simplicity a=1, b=2, then a*b=2, where a and b are strings
 
you could construct an outer product of two vectors, but the result is not a vector in the same vector field
 
7:51 PM
i mean "a" and "b", sorry
 
@SAJW well. If you can define a function that maps any two strings to another string you're free to call it string multiplication.
it doesn't hurt if it's associative, though
 
associative means ab=ba right?
 
no, that's commutativity
(and that's easy)
associativity is (a * b) * c = a * (b * c)
 
ah, I understand
 
And if you want to be extra correct you'd want your multiplication to be distributive over addition: (a + b) * c = a*c + b*c
 
7:54 PM
but I couldn't proof it right now, my study time is long ago
 
You have nothing to prove yet, right? You'd first need a function that you claim is a multiplication.
 
yeah the simplest would be: "ab"=1+2 and so on, which is already proven, but don't know if it works with the actual charvalues (I think the letters begin higher than 1)
 
I have no idea what you mean
but I might not be the only one
 
"ab"=1+2=3, "cd"=3+4. "ab" times "cd"
 
yeah, I have no idea what that means
"ab" is a single string, which is somehow equal to the number 3
if that's not what you mean, don't say that
 
7:59 PM
If I have a string, I just add all chars and have a sum
which can be multiplied
 
so the order of letters in the string doesn't matter at all
 
mmh, that could indeed be a problem
 
@Aran-Fey I'm sure you'll already know that I keep suggesting requests-futures
It's just simple and clean with callbacks too. Outdated? Yeah. But effective
 
Just like a guillotine.
 
And Dbeaz hasn't convinced me that any advancements in async is worth gripping onto
 
8:03 PM
@roganjosh Not the kind of async I need :(
 
Just bump the major version of AranLib and deprecate async functionality. Easy. Next!
 
Oh, you're that deep, eh?
 
Is it always that the times symbol is all of the three, associative, commutative and distributive over addition?
 
@SAJW no, but multiplication usually is
but you might note that string addition is not commutative, because it's not really addition
what I said about vector spaces would only hold if adding up 'a' and 'b' gave you a single-character string with a higher code point
that's also how multiplication by an integer would have to work
 
I think I've heard quite enough about async at this point to not even bother prodding it with a stick. At most, I'd wanna bombard a server and I can do that just fine without my entire codebase being async
 
8:07 PM
My dominant impression of async is that whenever I see "async" I imagine someone saying "I think" with a very thick accent
 
can character addition ever fullfill that it gets to a higher codepoint? I mean theres just so many chars, so if you add the last 2 in the list, what you get? rollover?
 
@SAJW that's left to you as a designer. The world is your canvas.
 
sort your data :P
 
Josh - aged 33 and 1/3. That's what I did with my canvas
I mostly kept the crayon inside boundaries. Pretty proud of that one
 
8:15 PM
@roganjosh how does that even happen, hahaha
 
Typoing on the column you sort the data by :P
 
correct points, wrong lines
 
recbg
 
Sounds odd to me that a graphing library would ever create lines like that
 
I never did it, so, is it possible to upgrade your Python or is deinstall and install the new version the way?
 
8:18 PM
@Aran-Fey they all plot what you tell them to. If you plot([1, 3, 2], [0, 1, 2]) it shouldn't silently sort your data for you
 
@Aran-Fey it will join each point given with a line, in order. If you sort it incorrectly and jumble the date (x axis) then you always get a scribble
 
not all charts depict functions, for instance
 
@AndrasDeak and a function can look like that ^ :D
 
Hmm, I see
 
it is a parametrized function for mapping T to X, Y <3
 
8:20 PM
yeah, but I meant Y of X as it should have been obvious in context :P
 
9:19 PM
@SAJW There should be no such thing as "your Python." Using virtual environments you have loads of Pythons.
 
9:35 PM
recbg
my python is the one that is activated :D
 
pyenv i guess?
 
not touching it with a stick :D
 

« first day (3802 days earlier)      last day (1150 days later) »