« first day (3842 days earlier)      last day (1092 days later) » 
00:00 - 17:0017:00 - 00:00

12:00 AM
I'm difficult in many ways, sure, but I didn't pick up on the sarcasm on that at all.
 
"No idea what I'm supposed to take from that". I have a hard time believing you had no idea they were soliciting a pat on the back. I thought there was some sarcasm in your response, so I poked back.
 
@12944qwerty neither newline nor screen erasure
 
it acted like a newline
 
@Dodge Oh. Horrible misunderstanding :) I still don't understand that link, though.
 
It's not horrible, just bad humor on my part. You are, objectively, a nice and helpful person.
 
12:06 AM
@roganjosh it's just an idea i wanted to make
 
Kevin mentioned roguelikes and zorklikes earlier, if that helps
 
yeah, i decided i'll try out a zorklike
wait
omg, weirdest idea, but a Little Red Riding Hood zorklike
 
@12944qwerty zomg, can you try being a bit less energetic?
 
@12944qwerty I think it might be better that you go and figure some of this stuff out. To put it bluntly; we don't really care about the specific project. You're welcome to ask, but not just an endless stream
 
@AndrasDeak lol
 
12:11 AM
I'm not laughing
 
Nor am I
 
... nvm
 
I gave you an invitation to ping me, but you're just keeping going with no research (I rescind that invitation btw).
 
I'm only laughing by how confused I must have made rogajosh becuase I didn't realize he was not there when Kevin asked 12944qwerty to make a rougelike or zorklike.
 
Asked might be a weird way to put it
 
12:14 AM
True
 
Kevin suggested
 
Challenged maybe
 
@roganjosh I'm taking a break from that topic for now
 
Indefinitely, as far as pinging is concerned
 
oh-
 
12:20 AM
Hello!
 
Cabbage, Jerry!
 
How do I make a variable with multiple values?
 
a = (1,2)
 
alright, thanks.
 
There's got to be more to this than just that. Why do you ask?
 
12:22 AM
Hello!
Would like to know if anyone has an idea about something I’m trying to get. 
I have an input image (png) and a filter (.tif file). Basically, I want to place the .tif file over the input, and for the resulting image, the .tif file would be like a filter that would allow you to see through it the input image in the background. For this 

I was multiplying both images using ImageChops, but realized that when the input image is black, the filter is not visible (since it is multiplied by 0).
 
@lorelayb Typically with images you can make a mask and use bitwise operations to mask portions. I can't view the tif and hesitate to download that file.
 
How do I make my own chatroom?
cant find the option
 
here you should be able to see the .tif as a png online
https://www.linkpicture.com/q/filter_1.png

Tried making a NumPy array also as a mask to substitute the filter, but was not able to replicate a similar effect as the filter until now. Also had the same issue related to multiplying the input and the filter because the black color remains unaffected, I think I need to use another approach
 
@Jerry click on my profile picture
look under Actions
 
then? @CupOfJava
 
12:36 AM
start new room
 
doesn't have the option
 
go to the bottom of the all rooms page
bottom right hand corner
"create a new room"
 
alright
 
Jerry needs more rep for that
 
ohh. alright.
it says i only need 100 rep. which i have
 
12:44 AM
Give it an hour to percolate through
@lorelayb is the transparency mask binary? Or greyscale?
 
@AndrasDeak it is greyscale (ranging from 242 to 255, but not uniform)
 
And what does it mean if you have a black pixel with a semitransparent green pixel above it? What is the expected behaviour?
I imagine for a white background you'd want a green that's 50% brighter
If you can give me an exact formula to determine the result pixels I can tell you how to implement that with numpy
 
@AndrasDeak ohh, wow/\.
 
1:08 AM
In case the input is black for example, I'd want the black pixels (or any color) to have different opaque tones, the output would vary from black to different tones of gray in this case.

This is the desired effect if the filter is applied to black solid image:
https://www.linkpicture.com/q/Screen-Shot-2021-04-22-at-8.53.04-PM.png

for example it works pretty good If I multiply the .tif to the input using Pillow, except for black color because multiplying by 0 returns 0 (black) and there is no opacity added for the pixels.
 
1:19 AM
def validfile(parser, fn):
    if not os.path.isfile(fn):
        parser.error(f"File {fn} Doesn't Exist")
    else:
        return fn




parser.add_argument('tickers', help='File Include Tickers', type=lambda x: validfile(parser, x))
what do you think about the previous code. is it better than using type=argparse.FileType('r') which will load the entire file into the memory at once.
as am reading a big file which i will iterate over it later under async iterator
 
1:38 AM
I'm thinking about this. I don't have a formula to get the result I want to get yet. Basically what I'm trying to get is that any image would seem as if the filter of the .tif would be placed transparently over the original image as a mask, so the colors of the original image would seem opaque (brighter) from some pixels.


The .tif is compound by pixels from 242 to 255, but majority of the pixels are 242 or 255.
 
2:29 AM
May I ask if I have a project with 2 files root/SubDir/file1.py and root/CurrentDir/file2.py

and file2.py needs to access a class defined in file1.py, what is the correct import statement to write in file2.py? I'm not using any Python frameworks for my project
 
 
3 hours later…
user13727121
5:11 AM
when importing a module and assigning it to a variable, should I make the variable a constant. Example:
 
user13727121
import string

ALPHABETS = string.ascii_lowercase
 
user13727121
since i can't change it, it's no issue right if I make it a constant
 
6:38 AM
@PrashinJeevaganth from ..SubDir.file1 import Foo
 
7:02 AM
@Aran-Fey Does that work for you? I got the following error message "ImportError: attempted relative import with no known parent package"
 
@CoreVisional I would just leave it as ascii_lowercase but if you want to bind it to another name you can use from string import ascii_lowercase as ALPHABETS
 
@PrashinJeevaganth Then either you're missing an __init__.py in some of those packages, or you're running your script incorrectly. You can't use relative imports in the script that you execute
 
@Aran-Fey Is it correct to say that for the script you're running, you need to import the functions from a file that already uses the relative import, like init.py instead of the putting the relative import in the running script itself?
 
Sorta. It doesn't matter what kind of imports the other file uses. But you can't use relative imports in the __main__ script.
 
@Aran-Fey OK thank you
 
7:50 AM
@PrashinJeevaganth Be sure to run your files via the -m switch to make them aware they are part of the package. python -m root.SubDir.file1 instead of python root/SubDir/file1.py, for example.
 
8:11 AM
how to convert SQL statement in Sqlalchemy ORM statement
 
@dmitriy_one I dont know SQLAlchemy but you will have better luck if you can describe what is the error you get
 
8:36 AM
@ParitoshSingh Thanks a lot for digging these up. We've also tried pyright --createstub – as you might guess, none worked for our case. They're all just statically inspecting the source, failing at *-imports + transforming list-comprehension. :/
For the time being, we've settled for manually writing a .pyi with the few types/functions we use most, gradually adding as needed.
 
8:55 AM
It should be easy to write a piece of code that writes a stub for every function/class/constant in a module, no? The only problem I see is that it has no way to find out the parameter and return types (unless they're annotated, of course)
 
9:12 AM
I do feel like that should be a thing too. instead of purely statically inspecting source, perhaps do it at runtime to get the available modules. i suppose star imports are the real problem, but can't we just inspect the code at runtime and see it's own signature/annotation?
and if something isnt type hinted or annotated, it should fail to be registered in a stub (or registered as Any...do we have an equivalent of Any in our type hints?). So i don't even see that as a problem.
 
@dmitriy_one This is very confusing. Firstly, please see our formatting guide.
You will also need to describe the error you're getting
 
Any suggestions on how I would approach the problem to create a function that would find the maximum number of repeated letter, in a given string? What I did was, looped through all the letters and then checked if letter is there in the list, then used count on the list with the found letter and appended to a dictionary with key as letter and value as number. But how would I get it to return the highest repeating letter?l
def repeater(n):
    all = string.ascii_lowercase
    lst = [x for x in n]
    frequency = {}
    for x in all:
        if x in lst:
            count = lst.count(x)
            frequency[x] = count

    return frequency

print(repeater('damn lets see'))
This is just my approach, but it seems lengthy
 
Looks like all you need is a return collections.Counter(n)
 
It works same as mine right?
 
Well, it returns a Counter (which is essentially a defaultdict(int)) instead of a regular dict, but otherwise yes
 
9:31 AM
Anyways to optimize my function? Making it efficient? Or someother approach. This seems like im doing it the hard way
 
before answering that, do you know the time complexity of lst.count(x)?
 
@CoolCloud you can make it efficient by using collections.Counter
 
@AndrasDeak I am just trying to practice looping and algorithms, Andras
 
Like your previous question that was fundemantally broken and you left it broken because you thought your code was haunted.
If you ask how to make your code better you'll get answers that tell you how to make your code better. Reinventing the wheel more efficiently is not better.
 
I mean python literally has everything I am trying to make, already :p
 
9:38 AM
@CoolCloud Have I told you yet that patience is a non-renewable resource?
 
hm, no i suppose i understand the endavour Cool Cloud is going for. I think just phrase it better. instead of trying to beat around the bush, change your outlook a bit @CoolCloud Essentially, step 1 is recognizing that there's a builtin that does it well. step 2 is understanding that that means you have an answer key provided to you. use how the builtins do it, build your solution, and then compare it against the builtin. instead of bypassing them, use them as guidance.
 
@ParitoshSingh I'm taking into account history as well
 
However, step 0, you need to start thinking about time complexity. these conversations will not go anywhere unless you can yourself answer when your code is suboptimal
 
if it were this one question I wouldn't be this prickly
 
@Aran-Fey @ParitoshSingh I also expected something like this to already exist, but haven't found anything. It is reasonably easy to get classes/functions/... of a module (we tried that), but just annotating them as Any wasn't very useful. Getting class attributes and function signatures is doable; getting instance attributes, no idea how; getting existing .pyi annotations for imported things, no idea how. :/
 
9:40 AM
@AndrasDeak Yes I do need to understand time complexity. Ill look into it, thanks :D
 
@AndrasDeak roger, no questions there, but wanted to give some input that i hope helps.
 
sure
 
@MisterMiyagi For instance attributes, are there any downsides to just seeing it's class, and pulling the class's attributes and signatures?
 
I can do hashlib.sha256(b"H").hexdigest()[:8 ] but if I want to use a variable var = "H" how do I do the b"H" part?
 
for getting existing .pyi annotations though, i don't have any thoughts or ideas at all. Just dont know enough about it
 
9:45 AM
@ParitoshSingh You can't figure out the attributes set inside __init__ or any other method. Which should be most of them. ;)
 
I can't write bvar
 
@MisterMiyagi oh! touche
 
@Anush var = b"H"?
 
var.encode(something)
 
I suppose we would need an actual instance to inspect. and even then i dont know how we'd be able to capture unions if any attribute allows being set to multiple datatypes
 
9:47 AM
Ja. It's a tad rabbit holy.
 
Ja :D
 
@AndrasDeak thanks. That's a pain. Do you know why it is necessary?
 
@Anush yes
Strings are not bytes.
If you just want to compare hashes you can always go with utf8
That might be guaranteed to be the default but I'm not sure.
 
thanks
 
OK, utf8 is the default. You can do var.encode() docs.python.org/3/library/stdtypes.html#str.encode
Unless you have non-utf8 characters in there, of course
(Not sure if that's possible in python or elsewhere)
 
10:43 AM
thanks
 
 
1 hour later…
11:54 AM
@roganjosh Looks quite promising, I'll give it a run and see.
Pointlessly difficult additional challenge that does not actually come up in my real problem: suppose baker's yeast costs 10 quatloos at the store, but if you already have some, you can cultivate another serving of it with one quatloo's worth of labor...
 
12:26 PM
You probably could with PARTITION (at a complete guess) but I think I'm done with SQL learnings for at least a couple more days :)
We're having a grand old time here with a merge conflict - apparently it's the entire file :/
 
Now imagine that you can only get GMO yeast at the store, which has been crispr'd by monsanto so that it mutates into a 20 story blob monster if you cultivate more than nine units of it...
 
I think our in-built editor in our workspaces has a different opinion about whitespace than VSCode
 
Cost of defeating a blob monster and looting 100 units of yeast from its remains: 1e6 quatloos. Cost of overthrowing monsanto and claiming their dark throne: 1e12 quatloos.
Anyway. Your script's output precisely matches the output of my non-sql prototype, so I declare this implementation functional and good.
 
A little bit of my code made it into Kevin's code base <wells up>
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Basically, don't come chasing me if it goes boom :P
 
[I click "I agree" without noticing the subclause where I owe you a dollar per query]
Things going boom simply get expensed to the monsanto blob monster liability fund, even if monsanto can't be proven to be responsible. Pretty standard practice in my industry.
 
12:51 PM
I'm still playing around with a bottom-up approach that involves tagging each food with its "complexity". And egg has complexity 1, just like everything else you buy from the store. Frosting has complexity 2, because all its ingredients are complexity 1. Cake has complexity 3, because its most complex ingredient, frosting, has complexity 2.
Formally, complexity = lambda food: 1 if len(food.ingredients) == 0 else 1 + max(complexity(ingredient) for ingredient in food.ingredients)
I don't actually know what I would use this number for but I'm 75% sure it's useful somehow
 
1:10 PM
1 + max((complexity(ingredient) for ingredient in food.ingredients), default=0)
 
!
I didn't know max had a default. Teriffic.
(I might have known yesterday, and I might have remembered on my own by tomorrow, but these are besides the point)
 
1:25 PM
Yo Kevin. Do you remember how you suggested the zorklike game i should make?
I started making one... can you just preview it so I can make sure I"m on the right track :P
 
morning cabbages, folks
 
@12944qwerty Sure
 
@lorelayb OK, I don't really see how one could do that. I could imagine mixing the colours of the background with the mask using the transparency as weight, but this would mean that a black pixel with a semitransparent green overlay would get a greenish tint.
 
Interactive fiction is a versatile challenge because the simplest approach is just a function for each room*, but you can also go totally ham and make state machines and store game state data in a database and put everything in classes and develop your own scripting language
(*this will almost certainly cause a stack overflow** after the user executes 999 commands, but you can work around this by having a grue messily devour the player on turn 998)
 
tragedy was narrowly averted when I caught myself just as I was about to pur my coffee into my cereal
 
1:40 PM
(**ok, "maximum recursion depth exceeded", not a real stack overflow. Same thing, kinda)
 
@inspectorG4dget Maybe that would have been one of those stroke of genius accidents like Charles Goodyear spilling sulphur into his rubber. Caffeinated Cheerios, yes please!
 
1:57 PM
@Kevin here you go :D
 
How do you make your room gain popularity?
 
Good question, I also want to know
 
My room is about math.. so it might grow in the future.
 
@Jerry Do you have a room> What is it called?
 
@Dodge Math
Need me to invite you?
 
2:01 PM
Ok
 
@Jerry fill it with awesome folks
 
@Jerry math is not on topic here
 
I think factors that have helped us are:
- Be based on a popular topic (Python is #3 on Tiobe index, woo)
- Be very willing to help out random newbies
- Have enough interesting intermediary-to-advanced conversations that you attract a core group of expert regulars
 
There's a math room on chat.stackexchange.com
 
I know for sure there are more than 500 rooms on SO and only 20 that have hit critical mass. You have about a 3% chance of making it.
 
2:04 PM
Fair enough
 
@AndrasDeak Thats a different website. Technically. does that still mean anything?
 
I don't understand the question
 
Don't be afraid to find an existing room and slowly gain clout in it until you're respected for some reason, that works too
 
nevermind
 
If the question is "since stackexchange chat and stackoverflow chat are different sites, isn't it fine to have the same room in both of them?". I think that's ok... Provided the room is on-topic for both.
So that loops back around to the problem of math not being very on topic for SO
 
2:07 PM
@Kevin yes, Grammarly didn't help.
 
@Kevin if that's the question then yes. But my point is that it will be hard to garner popularity for a topic that's typically off-topic here. One might always try. But Jerry will probably end up with all sorts of programming homeworks and code requests.
none of this is my problem, mind you
 
Kevin, did you check it out?
 
@12944qwerty Oops, I got completely side tracked. I'm looking now.
 
ok thank you lol
 
you're eligible to Kevin's money back guarantee
 
2:11 PM
Ooh, multiple colors
 
@AndrasDeak I could use GitHub. I honestly don't need help with math because I rarely code anything that requires math
 
@Kevin that took almost an hour lol
 
@Jerry Use... github?
 
idek why i made it multiple colors
 
It's an expensive day for Kevin. He still suspects he's only paying $1 per run of my query. <laughs heartily>
 
2:12 PM
For the swag obviously
 
😏
 
Unnecessarily elaborate console art is peak aesthetic for DOS-era indie devs
(and cracking groups)
 
@AndrasDeak yes, using discussions.
 
I really need to add time.sleep though....
 
2:15 PM
why does bin(int.from_bytes(hashlib.md5(symbol.encode()).digest(), "little"))[2:] always start 0b1 no matter what symbol is?
[bin(int.from_bytes(hashlib.md5(symbol.encode()).digest(), "little")) for symbol in string.ascii_letters] for example. They all start 0b1... why?
 
Because it's probably supposed to be uniform for the computer?
 
ugh
 
if it's uniform then half of them should start b0 and half b1
unless b1 has a specific meaning
 
no, it does not
[2:] does not start with 0b1
 
no it starts with 1 always
are all the leading zeros just removed?
 
2:19 PM
yes
[bin(n) for n in range(2**4)]
 
I think the answer is bin(...)[2:].zfill(n)
 
Answer to what?
 
I need a fixed width binary number
 
Where did you say/ask that?
 
I haven't said that before
 
2:20 PM
I see
 
@12944qwerty I like your writing style :-) Rather reminiscent of the "choose your own adventure" books from back in the day. I like how once you listen to the radio, or open the chest, you can't make that choice again. It lends a certain air of permanence to your decisions.
 
I think I encountered a bug. Even though I had the bullets and the sword, when I encountered the zombie I still tried to attack it with bare fists. I suspect this is because "sword" in [("sword", 1), ("bullet", 5)] evaluates to False.
One possible modification that might help would be to use a dict for your inventory instead of a list. "sword" in {"sword": 1, "bullet": 5} evaluates to True -- in other words, a dict makes it easy to use the in operator to check for the presence of items
I also notice that if you open the chest before going upstairs, it says that you put your sword in the scabbard, but this is strange because you don't have a sword yet. This is fairly easy to solve, using the same "do you have the sword yet?" logic that you employ when fighting the zombie
 
oh
i forgot i made it like that
I changed it but I forgot to change the conditions
but yeah
those are not complicated
 
2:36 PM
You could even make it into a little puzzle -- if the user goes upstairs first, say "there is a sword here, but it's so unwieldy, you can't carry it without a scabbard", and the user can't take it until they open the chest
I think the next significant challenge would be to incorporate a puzzle that requires you to traverse multiple screens to solve. For example, maybe upstairs has a locked door leading to the attic. To open it, you need to go outside, defeat the zombie with your sword, and take the key in his pocket.
 
Mugging dead people now? That's low.
 
good idea
i'll think about it
 
Ok, revision: before landing the final blow, the zombie shouts "Wait! Your masterful flourishing of my beloved sword has restored my memories. As thanks, take my attic key, with my blessing"
 
and then he dies of tetanus :(
 
More generally, it would be good if the player could go back and forth between multiple rooms as many times as they want to, with the game remembering what things were like when they left (e.g. whether they listened to the radio or not, whether they fought the zombie, whether they unlocked the attic door)
Don't be afraid to have a big old collection of flags like defeated_zombie_swordsman = False, that's basically how old school text adventures tracked things
(but consider using a single flags dict rather than a ton of globals, since that will keep your namespace cleaner and also make it much easier to implement save/load functionality later)
I've got a friend who's on a Sam & Max binge lately, and I've been meaning to surprise him with a little game in that style... But dang, is it hard to think up scenarios and puzzles and whatnot!
My experience in coming up with weird imaginary situations, doesn't quite translate easily into actual creative writing, because I usually don't have to plot out the logical structure of anything beyond one and a half paragraphs
If I mentioned offhandedly that Bam and Sax are vampires during the graveyard puzzle, I have to remember that ten puzzles later when they're at the beach on a sunny day
 
3:02 PM
If someone calls you out on it, just claim they were wearing a ton of sun screen
 
Hello, everyone , I hope u'all are having a wonderful almost weekend ^^
 
I'm also flummoxed by my design requirement that the game be an actual sincere instance of the genre, and not a parody or subversion of expectations or whatever. Sincerity is... Not my default mode.
 
does anyone knows how to connect a db to flask-Sqlalchemy correctly ?
do I need to use Engine ?
 
Yes, but it's also documented so you'll need to explain the issue
 
sure, It's an old issue that I have just realized that i was wrong about lol

so basically I have a very simple function that queries `id` 1 from the database as a test every second
on the 10th i get this error " QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30 "
I don't socket io or anything that is too fancy, I think I just setup the database incorrectly and it doesnt know how to close the connection
 
3:10 PM
What's spooking me is that this is the second time someone has raised this exact error to me, both at work and here, in 3 days - having never seen it before
 
my current setup to the database:
app.config['SQLALCHEMY_DATABASE_URI']= "postgresql://postgres:USERNAME@HOST:PORT/DB_Name"
it's not very new, it's quite popular out there and looks like its related to how the db is setup
I think I should use the engine ? not sure though.. but I have

@app.teardown_appcontext
def shutdown_session(exception=None):
    db.session.remove()
 
No, you don't need that. The whole point of flask-sqlalchemy is that it handles the teardown for you
 
and that didnt help at all.. also adding
`db.session.remove()` didn't help
 
I'm currently speaking to my colleague that's getting the exact same error. I'm now suspecting the latest release of sqlalchemy might have a bug
 
@roganjosh yeah I understand but looks like it is not doing a very good job isn't it ? ^^
 
3:15 PM
Has anyone asked about it on Stack Overflow? Might make a good question.
(Although be emotionally prepared for the post to get closed if the answer is "this is a bug with sqlalchemy release x.y.z and is fixed in x.y.z+1")
 
inb4 vote to close, duplicate, cannot repro within the first 3 minutes with about 2 downvotes
 
^ that. We should check github first at the very least
 
Including the exact version number gives your question +5 resistance to close votes
 
@ParitoshSingh Perhaps. I advise an ample smearing of elbow grease to make sure there are no dupes, and you can convince the reader that it's a real problem, etc
 
@Kevin the crux of the problem is an MCVE
bugs are not off-topic
 
3:17 PM
oh,

well I wont recommend basing your conclusions on anything I do, I'm really new ^^
but yeah I think i have seen a topic that might help
31
Q: Sql Alchemy QueuePool limit overflow

QLandsI have a Sql Alchemy application that is returning TimeOut: TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30 I read in a different post that this happens when I don't close the session but I don't know if this applies to my code: I connect to ...

 
@AndrasDeak Oh? I thought they get closed as "no longer reproducible" once the latest public release fixes the bug. TIL.
 
Probably depends on the temperament of the close voters. I wouldn't close it.
 
@LoopingDev I don't think this is relevant
 
but the setup was very unfamiliar to me, I'm not sure if it's the same thing, but someone answered it and its marked as resolved.
 
just make sure the question is versioned properly
 
3:18 PM
oh ok
 
I guess it's still valuable to document bugs specific to Vx.y.z for the same reason we still have questions about Python 2.7's quirks
 
+1, bugs shouldnt be closed, they're useful documentation on SO
 
I was researching this only 2 days ago. If there is a bug, it's not in flask-sqlalchemy but sqlalchemy itself
 
well I wanted to try using the engine before claming its a bug, because my setup didn't include the engine... maybe that is why it didn't know how to close the connection?
 
yep, do your due diligence loopingDev. if the engine approach solves it for ya, great!
 
3:20 PM
It shouldn't be done like that with flask-sqla. That's the point of the wrapper
 
rip.
i'll just stick to my sqlite. looks at all wrappers with suspicion
 
does anyone knows how to set it up correctly though?
 
I don't <:-)
 
@ParitoshSingh sorry, I didn't mean to be so blunt
 
@roganjosh not at all! you're fine. if that's blunt, stay blunt :P
 
i found it here and it looks quite simple if you read the first line `engine = create_engine('mysql://scott:tiger@localhost/test')`

but then if you keep reading ..
from sqlalchemy import text

with engine.connect() as connection:
    result = connection.execute(text("select username from users"))
    for row in result:
        print("username:", row['username'])
 
@LoopingDev wrong docs. You know that Flask-SQLAlchemy is a separate library, right? You haven't set up the connection incorrectly. There might be nothing in this, but it's now very suspicious to me because flask-sqla will handle sessions for you
 
you are right
https://flask-sqlalchemy.palletsprojects.com/en/2.x/api/
that should be the right document.
 
It is. But the error does come from SQLAlchemy itself and I didn't understand it when it was raised at work, and I don't understand it now with this issue either. It suggests that connections aren't being terminated correctly
All you have to do with flask-sqlalchemy is give a connection string and it will tear the connection down for you. It would be very odd that it didn't do that unless you were monkey-patching it or something (which I highly doubt)
 
3:33 PM
@LoopingDev If you can come up with an MCVE that replicates the error and uses sqlalchemy and not flask, I'd be interested in experimenting with this. But it needs to be an A Plus grade MCVE, I'm not good enough at database stuff to do any manual setup.
In the meantime, accept my good vibes and well wishes
 
I'll also probably have a look at this later, I just don't have time right now. It's pretty hard to break this @LoopingDev but an MCVE would be good anyway in case you really are doing something funky and the two occurrences of this error are unrelated (we're actually hammering an API on our side)
 
If you're thinking "writing an MCVE just to enlist the aid of someone who literally just said he's not good at databases, doesn't sound like a good use of my time", that's valid ;-)
 
The other thing you can do is downgrade sqlalchemy a bit @LoopingDev
 
@roganjosh that is what I'm thinking as well.
@Kevin unfortunately, I really cant, Flask-sqlAlchemy is a very nice and short wrapper.. Sqlalchemy on the other hand is much more complex
 
I've made a strong point of the differences between flask-sqla and sqla itself because certain discussion points rely on that distinction. However, they're basically the same thing - flask-sqla doesn't exactly do a tonne of work
 
3:39 PM
@roganjosh I'll try, but I wont promise anything.. hopfully we are not the only ones in the world who ran into this and maybe someone ... out there have a solution for it
@roganjosh yeah it's a wrapper.
 
I'm not asking you to promise anything?
 
I suppose I would also be fine with a flask-sqlalchemy based MCVE, as long as it was quite straightforward to set up whatever flask environment is necessary to get the thing running. The ideal scenario is, it doesn't require any flask environment stuff, other than pip-installing it
 
@roganjosh you didn't but I just don't want you to count me on something I'm not sure of , but I'll do my best
It's not our first bug is it?, that is what we do everyday, isn't it ?
 
good pep talk. We are strong dignified programmers and this bug is just like the ten thousand other ones we zapped this month.
 
@Kevin yeah I think I can do that, I will make a simple function that keeps calling the database every second and elemenate everything in my application one by one and see if that is relevant to the issue or not
 
3:43 PM
I strongly suspect that the best first step is to downgrade sqlalchemy a couple of minor versions
 
I do like diagnostic steps that don't require me to rewrite any code :-)
 
@roganjosh definitely will try it out
 
@12944qwerty I wrote a very small Zorklike as a pyparsing exercise (so that the parser would recognize sentences like "throw dart at dartboard"), and when I posted it on reddit, I immediately got feedback from those who are familiar with Interactive Fiction conventions. This sheet has a list of common commands. Here is a link to my game, you can use the buttons to fill in your command, or just type it in.
 
Re: "I just don't want you to count me on something I'm not sure of". I hope nobody feels like we're forcing them to write an MCVE for us, or provide sample data etc etc. Most of the time, these requests aren't edicts like "if you don't give us <thing>, you go on the Naughty List", they're offers like "if (and only if) you give us <thing>, we'll give you superior assistance"
 
We do have a Naughty List?
 
3:53 PM
Busted
 
Not formally, but we remember people that consistently ask low quality questions
 
Like "Do we have a Naughty List?"?
 
-1 in my mental checklist
 
Which leads me to the scenario that encompasses the counterpart of "most of the time": sometimes we have to get a little firm and say "you've been frequently asking questions without proper due diligence, please improve your question quality or take a less active role in the room"
It should be fairly clear to somebody when they're trending towards that zone, so it shouldn't be hard to distinguish requests vs edicts
 
@PaulMcG wait, so it would work if i said throw dart or throw dart at dartboard and you didn't actually hardcode each answer?
 
4:06 PM
@PaulMcG If you're comfortable with sharing, I'd be interested in seeing the the comments for that reddit post
 
"Throw dart" gives a snarky response like "Hey, watch where you're throwing that!" There is a lot of snark. Also, the game responds to repeated commands with different answers.
@Kevin It was quite a while ago, maybe archived off to tape in a salt mine by now, but I'll look.
 
Ok, don't go to too much trouble :-)
I'm interested in the philosophy of interactive fiction design, and even if the commenters only discuss low hanging fruit and newbie pitfalls, I think that's valuable
Pareto Principle... Activate!
 
Hi, can anyone suggest how to set up a "database" for a demonstration of an API? I don't want to connect a db so I'm trying to use a json or txt file. It would just store simple json POST requests.
 
@feners why not use an actual lightweight database?
the lightest end of the "not a database" spectrum is a dict :P
 
@AndrasDeak could be an option, was thinking of what's the easiest for someone to whip up my flask code and test out functionality..
 
4:13 PM
Sometimes I use shelve when I need the laziest database in the world
 
I'm working on a project where a lot of objects will load/generate data on demand. For example, I can instantiate a Book(url), and when someone accesses book.title or book.isbn, I scrape that info from that url. So naturally, after all the attributes have been loaded, the book no longer needs the URL. I also need to save my books in a DB, and I'd like to avoid saving the URL if it's not needed. Can anyone recommend a DB that can handle this in a convenient way?
(Of course I could just set the URL to NULL, but I actually have a whole bunch of Book classes with distinct attributes, and I'm looking for a DB that doesn't require me to create a separate table for each kind of Book)
 
@feners a MySQL or SQLite DB should be easy enough to set up. The latter ships with the standard library already.
 
TL;DR: I'm looking for a DB that can conveniently handle objects of various types with distinct attributes
 
I feel like any engine that plays nicely with @property decorated fields could be coaxed into doing what you need... Perhaps also look into "triggers" or "interceptors"
If you instantiate a Book via url, and the user accesses title but not isbn, what should be stored? Something like {"url": the_url, "title": the_title, "isbn": None}?
 
@Aran-Fey Do you actually need to do DB actions on the Books? If not, I'd go for just a DB storing the URLs and a runtime cache. If yes, I'd skip the transient state and directly load Book data to the DB; if downloads are a bottleneck, might want to keep a separate table for unprocessed Books.
 
4:24 PM
It depends on the book (or rather, the url). In the majority of cases, all the data will be scraped at once, so most books will either look like {'url': the_url, 'title': None, 'isbn': None} or {'url': None, 'title': the_title, 'isbn': the_isbn}. But in theory, a book with two separate urls for the title and the isbn might exist
 
I wonder if a non-relational db is an option... Things are getting farther away from the homogeneity that sql-likes love
But then you lose out on all the select-y goodness that queries give you
 
@MisterMiyagi Hmm. I do think I'd prefer to store the data locally in a db rather than fetch it from the internet every time. Otherwise my program will probably take a long time to start up if you have a lot of books in your library
I'm not planning to make any complicated or performance-critical queries. I think all I need is the ability to load a book's metadata (title, author, genres, whatever), and the ability to load every page in a specific chapter of the book
 
@feners you can just use SQLite as I did with an example yesterday here. I wouldn't suggest doing it in memory for flask, though
 
I don't know what kind of scope or scale we're aiming for, but I'll just say that in my personal projects I've gone a long way by serializing to/from regular old json files
Especially if the entire data set can be loaded from file in under a tenth of a second, which is often the case for me
(But if not, that's not necessarily a showstopper, if you get creative)
 
Why can't all the books be stored in a single table with foreign keys to different classifications?
Every book will have an ISBN so you store that in the books table and you have a foreign key to a genre table
 
4:39 PM
@Kevin Not a bad thought. I've worked on a similar project in the past, and back then I found jsons to be uncomfortably slow. But thinking about it now... my largest data set had what, maybe 10k entries? That doesn't sound like a whole lot. Maybe I screwed something up back then. I should probably give jsons a shot
@roganjosh So I would have one table containing things like title, isbn, author that every book has, and then for every optional attribute (like url), I'd have a separate table?
 
Hot tip: call json.dump with indent=None to sacrifice some human-readability and improve file size and I/O load times
We're talking, like, a 5% improvement, impressive right
(0% if you were already calling dump without specifying indent, since the default is None anyway)
 
@Aran-Fey I'd even store the url in the books table because it's unique to that entry. The only thing you'd need (well, want) another table for is attributes that can be shared across book entries i.e. genre
 
If one book can have multiple urls, then you may need to bust out a one-to-many design
 
Agreed. But there might also be pagination on the url?
 
I think I see what you mean, yeah
It boils down to "depends on your requirements" IMO
 
4:47 PM
I've potentially made our last two suggestions seem more linked than they are in my head sorry
 
Even if "put the url in the books table" turns out to be awkward for certain kinds of corner cases, I think it wouldn't be too hard to change the table design and port over your non-corner-case data, so we can invoke YAGNI a little bit here
 
So the thing is, I have a lot of Book classes with an arbitrary number of urls or other attributes, and I don't want to invest a lot of work into the DB layout. I don't want to update my database tables every time I implement a new Book class with a new attribute. I don't want loading a book from the database to require a 10 line SQL statement with 3 joins. I want something as simple as possible, ideally like db.store_this_thing() and db.load_this_thing()
 
That would then be an ORM in my mind, which wouldn't be any more difficult than a dict update
 
Your wants are reasonable and valid, and I want those same things in most of my projects.
 
I mean, some work has to be done
But you can make use of things like ON UPDATE and ON DELETE and have it "cascade" through the tables
Otherwise, I think you really are looking at something like JSON if that's too much. You could use MongoDB for that, but it's an abuse IMO
 
4:57 PM
@roganjosh I think have some news, it's not SqlAlchemy itself.

I have a failing attempt that could eliminate lots of things

is there is a prefered way to share a big code?
 
You can put it in dpaste and link to it here (or a gist or anything else)
 
My problem with an ORM is that (as far as I know) it would require me to describe the layout of every Book class in a language it understands. But I guess I could write a wrapper that automatically does that for me based on the class's type annotations?
 
00:00 - 17:0017:00 - 00:00

« first day (3842 days earlier)      last day (1092 days later) »