« first day (3560 days earlier)      last day (1380 days later) » 

1:44 AM
Hello! New here, any recommendations of best python books for begginers?
 
2:32 AM
@anafitch Natural Language Processing in Python
@anafitch It explicitly starts with beginners in mind and then you're off to doing something interesting
requests_html is looking very usable right now
I want something simpler
What's the shortest number of steps, from import to print, to get the links put on a page by Javascript?
In contrast, here's the just html links. This will get you all of two links, and we know there's more than that on an Amazon page.
import requests_html
session = requests_html.HTMLSession()
r = session.get("http://amazon.com")
for i in r.html.absolute_links:
    print(i)
 
 
1 hour later…
3:57 AM
Tensorflow library is written in cpp right?
@anafitch don't go with any book, go for YouTube tutorials and start practicing.
@JohnnyApplesauce he is a beginner, and you are advising NLP to him?
 
4:46 AM
Hello!!
I posted a question on main site, its been 2 days and I didn't get any solutions,
Please give me some suggestions regarding this.
https://stackoverflow.com/q/62862439/12955442
 
I saw that initially in the queue but neglected to point out that 1) the code you posted was not correctly indented 2) without clear instructions on how to reproduce the issue 3) without a proper MCVE it does not give any incentives to even attempt to answer.
there is also no traceback provided that show the exact error for the other cases, so I can't be certain that's even the issue. Also it could be a difference with the default codec, have you tried passing the encoding argument to open and force that to be utf-8 to assist with testing/reproduction of the issue from outside pyinstaller?
 
5:02 AM
I'm sorry, I'm not aware of the indentation.
I will try passing the encoding argument to open.
 
5:21 AM
@metatoaster I tried this `f = open(dir_val.get() + os.sep + fname,'r',encoding="utf-8",errors="ignore")` and its working.
I will do more research and be more clear before posting a questions, from now on.
Thank you!!
 
if you ignore the error, it may introduce subtle issues later with mismatching data, unless you are sure replacing the malformed bytes is an intended behavior for dealing with text for your users.
 
 
1 hour later…
6:49 AM
@anafitch Honestly, I'm not big on books so I can't really recommend much on that side. We have a page with some links (though, I might need to look and see how relevant they are now - davidism did edit it in 2019 so I'm guessing it's still curated)
 
 
1 hour later…
7:53 AM
Hello. I've got a .bat file that executes a python "-c" command but it says "'python' is not recognized as an internal or external command" even though I have it installed and have the path set as well
 
@VioAriton on windows, python is usually run using py, not python.
 
News to me :P
 
@MisterMiyagi both py and python seem to work on Windows
It works when I do it in the terminal it just doesn't work in the .bat file
 
In that case it's probably better for someone with an actual Windows in front of them to help.
 
I only pretend to know what I'm doing in Windows. Does this help?
 
8:01 AM
Yeah I don't use Windows as well, I just have this .bat
@roganjosh Thanks. I will try it.
 
The sad part is that I'm almost exclusively on Windows :P
 
Sam
@roganjosh i'm so sorry
 
I like the icons and the clicky stuff. the icon for .bat files is spooky enough, I'll just leave those things be
(It's kinda unacceptable for me at this point not to understand .bat files, I'll have to schedule in some time to learn)
 
@roganjosh Nope, doesn't work. Now a box pops up saying that windows cannot find 'python'
 
How big is the file? Is it something that can be dumped into a dpaste or something, enough that I can try recreate the issue on my end? I may as well jump into the learning now
 
8:09 AM
I don't think I can share it since It's work related, but the line I'm talking about It's just a python "-c" command
the people who wrote it are away & I don't use windows or python, just C
 
what is preferred http status codes or custom codes in json response?
 
Hmm, the first thing I need to work out is how to keep the terminal open. Give me... a while
 
Sam
200 for OK
 
yes i know what are the common status codes are
the thing is the ui guys want us to move codes to message response
 
In which case, what is your specific circumstance?
 
8:12 AM
because they have predefined processors for it and return 200 for all requests
 
Sam
@RE60K that sounds very dangerous.
 
Why would you return 200 for all requests?
 
something like {status:0, message:blabla, data:the actual response}
because they want it so
and they parse status from body
 
Sam
But if you're doing that, then I guess you can just make up your own custom responses... no need to try and conform to any standard at this point.
 
my manager just agreed to it
he says it will only take 1-2 days to change our code
 
8:14 AM
This sounds... fun
 
this just demotivates me to work further on the project
feels like an obligation
 
Sam
@roganjosh semi-organised chaos :D
 
i don't know how i can convinve him
 
@VioAriton I already can't repro this :( It's complaining that I didn't give further arguments, but it means that Python was at least found
 
Sam
@RE60K Your UI and backend should be agnostic to each of its inner workings. If you change the "response code" from your backend, the UI will break. and thats not good.
 
8:15 AM
seems like a setup problem with python in path
they are starting to build ui, we have already created all backend apis
 
Well, when I do python --version it works
 
they just want us to change our apis to their format
 
What libraries are involved here, @RE60K?
 
flask gunicorn nginx docker
@VioAriton try using full path like /usr/bin/local/python3
 
Ok, and do you have custom error handlers registered on your flask app?
@RE60K they're on Windows
 
8:17 AM
no custom handlers
 
I've ticked the option for the installer to set the path themselves
 
Ok, so do you have any custom control over the code that you send back?
 
yes i can create a cusotm handler to map these http status codes to their status codes
but mapping may not be one to one or handlable
 
@VioAriton our Windows guy will usually come online in a few hours. He may or may not pick this up. If it was throwing a strop for me then I could have a go at debugging, but I didn't do anything special to make bat files run and I'm not getting the issue, so I'm at a loss on how to debug sorry
 
That's alright. Thanks for helping.
Mhmm... weird. When I do 'python' in the terminal in the folder that .bat is, It says It's not recognized
 
8:22 AM
@RE60K Is my understanding correct here; you don't have to send 200 codes, but you need some custom error?
Such that, your flask app could send a 500 code but you need to send some more info that the other guys in the middle will transform to a 200 code
 
Hi RE60K, As discussed I am proceeding my development assuming 200 Http Response for all the success scenarios
I am Assuming that response will be in this format
{
"code": 0, // 0 for 200 success
"message": "Ok",
"data": {
Success object
}
}

thanks
ShXYZ
 
It's too early for my brain to be thinking this way :S
Actually, ok. If we're just going for 200 codes (which are sent implicitly) then your routes just need to jsonify the response in the format given
 
@RE60K Wait, that implies 200 only for success instead of all requests, doesn't it?
 
yes
 
That wasn't what you initially suggested
 
8:31 AM
but from the discussion they want invalid password etc. to be also 200
i.e. success
but show appropriate message
their understanding of success is all that is not 5xx
 
Well, there is in principle a difference between the error codes for the request and the error codes for the payload of the request.
 
i would prefer to use 401/403
 
Sure. Well, my own server will send back a 200 code for an invalid password if I'm updating the front end. It wouldn't make much sense in an API, but it does if I want the site to say "invalid username or password" because I correctly caught the invalid credentials
 
hmm
 
Would you want your site to re-direct to some 500 error page or something every time someone entered bad credentials?
 
8:34 AM
@roganjosh You can say that about every request, though. "418 shouldn't be an error because I correctly identified myself as a teapot"
The only error code where something actually went wrong on the inside is "internal server error"
 
Ok, but if I was using jQuery to update the front end to say that I've identified as a teapot, I'd send a response along with a 200 code such that the success handler would run
Hmmm. Maybe I should have had my server erroring all this time and instead updating a div using the error handler
 
Hmmm. Depends on the context, I suppose. Like, if send a "please make me a cup of coffee" request to your teapot, then 418 should be an error. If you're sending a "please identify yourself - are you a coffee maker?" request, then you shouldn't send a 418
 
For an API, yes. What about the site itself? Do I just redirect to a catch-all 418 page?
 
even with 4xx we can send a specific message that can be show in ui
 
Hm, for all the evilness we are doing, separating the API layer from the actual business logic has proven to be a good idea in our case.
The major question, @RE60K, would be "what is a success scenario" in your case?
 
8:41 AM
@roganjosh Sorry, not really following. What is the site doing that caused a 418 response? I'm not sure why you would need to design your API differently for the sake of a website
 
what is the common norm for a success scenario
 
This calls my own practices into question (which is fair). I have a phonecall to take shortly but I'll try cobble together a dpaste
 
It's entirely possible that I'm missing something obvious, considering that I've never written a website myself
 
@RE60K There really is none. It depends on what success scenarios you even have. I'd assume The Other Personâ„¢ who suggested this scheme has some in mind.
 
Something like this. Both front-end and back-end validation, and all scenarios will result in a 200 code.
 
8:50 AM
why do people explicityly use jsonify, in my case flask does it implicity
though I get your point
all logical errors will be 200 and server errors 500 accr. to my ui guys
 
After a circuitous route, I think I'm agreeing with them
 
typo/minor issue. OP created a list of string names of dataframes, instead of actual dataframes stackoverflow.com/questions/62910938/…
@AndrasDeak That 'reactions' feature test got +152/-1235 downvotes... and no we do not want thumbs-up feature and emojis next.
 
9:16 AM
Ugh. My call isn't for another 45 minutes. Stupid daylight savings, why is someone in the UK scheduling a call with me in GMT? :P
 
@roganjosh GMT makes me nervous. Z is hard to notice. If they call it UTC it's fair.
 
To be fair to them, they did state GMT but it was just a general chat and I'm semi-programmed to read GMT and think "that's where I am!" so I tucked the appointment away in my brain for the wrong time
 
That's why I'd avoid GMT. I can never remember if it's UTC or British time. Just use UTC...
 
It should be interesting, anyway. I've been invited to join a closed roundtable on the use of tech in industry (I'd be more specific, but the programme scope is vast). At the moment, I think my main contribution will be "I like Raspberry Pis" and then sit back down. I have until October to flesh out some stronger opinions, though :)
 
9:38 AM
it's going to be one of those days... smashes head into desk... :p
 
@JonClements it is one of those days... goes looking for a new, unsmashed desk... :P
 
@MisterMiyagi heh... you'd better hurry up your looking... there may not be many left for ya :)
 
I'm encountering problems with datetime module of pandas
How can I standarize the date format?
 
@JonClements We're on an office rotation, so I have three times as many desks available for smashing than usual. :thumbsup:
 
I tried with arguments as well, still it's messing up the format as whole
 
9:42 AM
@JackDaniels you'll need to be more specific about the issue. Can you give a MCVE?
 
Yeah sure, let me put my code here
 
If it's going to be a big block, please post off-site and post a link here
 
It's not a big block, hold on let me figure out formatting for chat. I can't recall how to do it.
 
Good job we have a guide for that and there's also the sandbox :)
 
@MisterMiyagi lucky you!
 
9:48 AM
I'm stupid. Nevermind.
 
@JackDaniels oh boy, this question shows that you have a lot of learning ahead. There is a good article written called something like A long history of measuring time. Which is a great read on the subject
But I can't find it anymore sadly
 
Datatype error
I thought I was getting datetime dtype from source, and I didn't bother checking myself. It was a string.
 
@JonClements Well, I woke up to find 10 mails of Critical Things Burning For No Reasonâ„¢ in my inbox. The day has gone downhill since. Those desks are needed...
Not enough head desks / scratching posts / puppy places in your office?
 
@MisterMiyagi I suppose I could resort to the stress relieving cabbages? :p
 
10:07 AM
mmm
Jul 1 at 13:46, by Jon Clements
@roganjosh Awww... but look at me... I'm a cutey wutey little puppy wuppy... I wouldn't do that to anyone... meep meep
 
10:24 AM
@roganjosh it was an evil cabbage, okay? :p
 
Sure. You practically did a public service by dispatching with it :)
 
Exactly... just to check though... one can't be accused of genocide when it comes to cabbages, right?
 
Cruciferocide?
I don't know if that's a thing, but I know I'm against it
 
ugh... confusing me with words... :p
 
We have a weekend crossword club so I know all the best words. The bestest words. When you're less tied up about cruciferocide, you need to stop slacking on Slack for a bit :P
 
10:42 AM
ooo... am I missing some gossip or something then?
 
I think there are some cabbages that need handling :P
 
"handling" - yes... that's the word...
 
 
2 hours later…
12:47 PM
What's an equivalent to requests_html.HTMLSession().get("http://qux.com").html.absolute_links for JavaScript links?
 
What are you classing as a "JavaScript" link?
 
Links placed by JS actions (I assume React) rather than part of the static page
 
you'd presumably have to use the javascript rendering and then try the extracting?
that or work out what the javascript does and then recreate links yourself...
 
Which module makes that most convenient?
 
10 hours ago, by JohnnyApplesauce
requests_html is looking very usable right now
I want something simpler
What's the shortest number of steps, from import to print, to get the links put on a page by Javascript?
In contrast, here's the just html links. This will get you all of two links, and we know there's more than that on an Amazon page.
What are you optimising for, exactly?
 
12:56 PM
Convenience
highlevelness
 
I can't believe cv2.imwrite(img_path, img) this fails silently if the folder doesn't exists or if the filename contains :, because windows can't have : in filenames. Like how can cv2 be so big an popular, but a simple write can fail silently
 
leasteffortness
 
For who? Just you? Do you have something that actually works first?
 
@Hakaishin Popularity is often decided by feature breadth, and it's a lot easier to provide many features poorly.
 
1:15 PM
@Hakaishin ever used LAPACK?
 
@AndrasDeak haha, no, but I guess everything fails silently?
 
Only 50% of cases. The other 50% are segfaults.
Yet it probably acts as a foundation to all scientific code. It's great, but a huge pain to use. That's why we have higher-level libraries that abstact away some of that.
Arguably cv2 could do that very abstracting, but it's written in C++ so it's their judgement that defines the API
 
Yeah I would expect a function as simple as a write to tell me if it fails. Maybe that is why the other day I saw somebody checking the return code of ls :D
and with tell me I mean ofc an exception not a return code
 
1:35 PM
cbg all, bugrit.
 
cbg
 
Is it just me, or has the general quality of SO Python questions dropped considerably in the last three months?
 
It's not just you
 
it's very much not just you
 
It's got to the point for me where I scroll through two or three pages looking for a questioner with some semblance of a clue. Most of it seems to be o the level of "How can I HTTP pictures with Django so my users can buy things?"
Then I give up, and post morosely about it here. I think that brings you up to date.
 
1:41 PM
Web interfaces are cool and stuff
Jun 27 at 22:11, by roganjosh
Is it just me or is Flask the new flavour of the season? I feel I'm doing some heavy lifting :P
 
Ah yes, the FrontPage effect. "Anyone can create their own web site." Complete with data injection bugs and with no thought to information architecture or design. I'm putting my fees up.
 
So, the django/flask divide can be closed over by the common "WTF" ground :P
 
Hey, I just hired into a Django environment. When I ran the shop we used Flask. But there are many bridges to cross before that becomes a practical possibility.
 
tanstaafl is a lovely acronym. Have to send it to greedy and gullible people from time to time, when they ask me if something is a scam or not. I feel like the economics so should have a bot, which autoreplies with yes if it detects the word scam in a post
 
Yes
Or, alternatively, yes yes
 
2:22 PM
@roganjosh WTForms? They sounds useful indeed.
 
Yep, those
 
2:39 PM
Is there a way to split for (mode, fields) in [list(ele.items())[0] for ele in self.conf.get('update')]:in 2 lines in a way that PEP8 leaves me alone?
flake8 is giving me the E128 error: flake8rules.com/rules/E128.html
 
@Neoares what are your attempts?
you could try running black on your code to see what it does
 
I tried to split it from the for ele in self... and indenting at many levels
what does "running black" mean?
 
pip install black -> black .
 
Not "running black", "running black"
 
wait I don't know if that will pass my company's compliances xD
ah nevermind I missreaded something :)
I'm gonna give it a try, thanks!
 
2:48 PM
TypeError: cannot unpack non-iterable NoneType object
Hmm, has that error always looks like that? It's not familiar at all.
It's 3.7 so probably yes
 
Sam
3:03 PM
General question around the Python ecosystem. Suppose I have an empty list which I want to fill with a series of dictionaries. At any given point, depending on some value, I might want to follow a different path of dictionaries to add based on conditional logic. For instance, "if male add first name then if first name = sam add surname" "else add surname". We can see that if the first condition was male I converge from the flow from if it was female.
My question is, is some type of DAG (say airflow) complete overkill for this? I want to avoid having a whole bunch of nested conditionals in my program
 
Side note: if that's an actual example don't treat gender as a binary choice
 
Sam
This diagram might help explain: pasteboard.co/JhMlq3a.png ... at certain points I'll want to diverge and then converge at a later point.
@AndrasDeak Just an example, but appreciate you speaking up
 
I think I understand what you're asking but I have no idea how to answer :) I'll let the proper programmers respond in time
 
Sam
When I think of DAG systems like Airflow I think large scale "jobs" whereas in this instance its simply adding dictionaries to a list. Not sure if it feels a bit overkill
@AndrasDeak hehe, I guess its quite subjective, but interested to here some of their thoughts
 
For what it's worth 3.9 will have topological sorting docs.python.org/3.9/whatsnew/3.9.html#graphlib
 
3:27 PM
@roganjosh I think there are just a lot of us trying to learn now lol
 
@Kwsswart That's fair enough, I've just noticed a big increase in questions in this area. Don't pay too much attention to my comment, I was being a bit flippant :)
 
Sam
3:53 PM
In the spirit of trying it first, here is a possible solution I've just whipped up which define configurable dictionaries to control the flow. It's not elegant, but its v1: repl.it/repls/VerifiableGrimCalculators @AndrasDeak how far away is this from something you'd of expected? ;)
 
does_suffice = eval(condition_string)?
How can you need to call eval on something in the same scope as you define the string?
 
Sam
Because the logical operators I define in the schemas are strings. So I add them together to form a concat string and eval the expression
 
mm, ok. I can see that now. I get a strong sense that this has gone off course but it'll take me time to understand it
 
Sam
It might be helpful to view the pasteboard image I put in
 
My immediate sense to your male/female discussion earlier was "why are they even bothering with this?" and the code you've produced almost satisfies the expectation that the solution would be over-engineered... and now we have eval in the mix
 
Sam
4:04 PM
Maybe the example was poorly chosen. Think of a dynamically rendering form where the next question may change depending on the previous answer to another question
 
Sure. I do that a lot. It doesn't take any fancy data structure, I just filter the database on the previous selection
 
Sam
OK but if the structure is complex, the number of filters you'd need to apply becomes huge right?
 
I think I'm being put off by the initial example sorry
 
Sam
I think a good example is (hopefully): consider filling out a form and the question is: "how long have you lived at your address". If you answer "less than 3 years", you'll get asked to fill in your previous address before moving to the next question "how old are you". If you have lived in the address for >=3 years, the next question will be "how old are you"
So there's conditionals which cause the flow to branch off, before meeting back at some place.
A configurable approach like the one I proposed does 2 things (I think). 1. extensible. 2. avoids repitition in having to have a python script full of conditions which will be a nightmare to test
 
mm, but I hate the eval. I get the problem but I'll need to stew over it for a while :)
 
Sam
4:15 PM
@roganjosh I'm happy that you are questioning me though, as I don't know the right answer :D
@roganjosh Yeah it did upset me writing it
 
:)
Ok, so firstly, I'm not sure that Airflow is useful here. It itself works through DAGs but it doesn't mean that that's the way to set up your own
 
Sam
I can represent the problem as a DAG, but yeah I'm not sure if Airflow is overkill
 
Let's say that you did do that. How does it translate to Python vs the code you gave?
Or haven't you implemented that yet?
@Sam I'm actually really interested in how this gets implemented but I'm probably not going to be any use in the short-term. I'd appreciate you pinging me if someone picks it up and you get something working, though.
 
Sam
I think the difference would be I would no longer need to track the current HEAD value, therefore removing the while loop. The state change conditions would still be a cause for concern though
removing the complexity of a while loop might not be worth the added complexity of Airflow
@roganjosh Sure, no problem. It might be a good question for code review?
 
4:32 PM
@Sam I don't know the site well enough and people may just jump on eval. <shrug/>. I can't say whether or not that will work
 
Sam
Is eval generally considered bad in Python?
 
@Sam it's considered bad everywhere
 
The main issue is safety, which is not a problem if you're in charge of its inputs, but even then it leads to undebuggable code
imagine if you have a bug 145 characters deep in an eval string of length 1500
 
Sam
the good thing is I am in charge. im basically building an "instruction tape" for a selenium bot to follow
 
4:37 PM
Ah, of course, web scrapping. I should have known :P
 
Sam
lol
 
@AndrasDeak boo.
 
Hello everyone
 
*startled*
 
@Bruno hello :)
 
4:51 PM
I heard you could help me with Python.
 
@Ffisegydd Please see the room rules before asking
 
Heresay
 
Wheresay?
 
Theresay
 
Okay just read the room rules. My issue is that I try to write Python but it just comes out as Typescript. What can I do?
 
4:53 PM
@Ffisegydd replace the chair complete with contents
 
I've also got this weird rash, if you can help with that.
 
that must also be typescript
 
No that's php.
 
<glad that Andras is already dealing with things. Time to put the kettle on>
 
Just kidding, I don't use php, I have some standards.
 
4:56 PM
@AndrasDeak I don't even know my own language :'(
I'd reverse time and say "hearsay" but there's that matter of a rash and I've already shirked that one
 
I think Fizzy broke English too
 
It's because I'm Welsh.
 
Sam
@Ffisegydd ditto
 
@Sam huh!
 
Sam
I'm Welsh :D
 
5:04 PM
Hello, I need a Python help
 
I can help with typescript.
 
You mean Python 3.12?
 
Is typescript like mypy? My problem is with mypy. Anyone good at mypy?
I'll just go ahead and post a link to the question I created a while ago on the main site. I'd check whether this violates the room rules, but I have a condition where I can't see the rightmost 370 pixels of my screen.
And anyway it's urgent, which makes it OK. Like parking in handicap spots or copy-pasting code without reading it.
 
Okay that's enough for this year.
 
5:46 PM
@Sam Have you ever used decision tables?
@Sam It's about as bad as we realised self-modifying assembler code was in about 1969 ...
@roganjosh That was a bit rash.
 
@holdenweb At least back in those days you could blame the need on 64 kB of memory
 
Anyone give me a hand with a Javascript problem? [ducks]
 
@holdenweb that's just heresay :P
 
@AndrasDeak Ah yes, the grand days of overlay programming: subroutines were addressed indirectly through a mechanism (usuall referred to as "entry points") that would page them in if necessary before calling them! You could always tell when your overlays started paging ...
@roganjosh I was only making SmallTalk.
 
gah, you win this round, sir
 
5:53 PM
@holdenweb because Joe would come in, open the box and start flipping through two-meter-high blocks of metal?
 
@AndrasDeak No, because performance took a nosedive once disk traffic started. It was the pre-virtual-memory equivalent of page thrashing.
For some reason a large number of fruit flies have taken it upon themselves to drown in my whisky and water. I may have to retire inside.
@AndrasDeak But it amounted to much the same thing.
 
Time flies like an arrow, fruit flies like whisky
 
Therefore I am a fruit fly.
 
6:12 PM
Deductive reasoning wins again
 
6:31 PM
Anyway I came inside, finished the whisky and am now chasing it with a Sam Adams Boston Lager.
 
Sam
@holdenweb I thought that was just a testing thing
 
Not at all. People have written programming languages based on decision tables (RPG, IIRC, for example). Well worth a look if your decision-making needs clarification - it beautifully isolates the actions from the decisions.
 
Sam
Sweet. I’ll take a look at them now
It’s quite interesting trying to figure out reasonable ways to solve my problem
 
rosettacode.org/wiki/Decision_tables#Python - also maybe investigate flow programming, but that's really overkill for the problem you were describing earlier.
 
Sam
Did you manage to look at my solution?
If I can manage to replace the eval :p
 
6:52 PM
No, sorry, went away, came back, time for dinner. Rhubarb, all!
 
rbrb. I have some time to think of a punny comeback :) Enjoy
 
7:20 PM
off-topic, NAQ, seeking recommendation, subjective stackoverflow.com/questions/62922175/…
@roganjosh Seven letters, rhymes with 'MUSTARD', isn't 'BUSTARD'...
 
Custard?
 
Sam
@roganjosh so looks like I can probably get rid of eval and make use of the operator package
 
@Sam now that you mention it, I'm not sure why I didn't suggest it. I like this much better but I still feel we're missing something. Something feels... off. But it's no use going by my gut instinct
 
Sam
Just remember, v1 ;D
 
7:36 PM
Oh, in that case, I expect some prose talking about how roganjosh helped you build the prototype at the top of the module. I can prepare the text, if you wish? :P
 
Sam
hahah, expect no less
 
Make sure I don't look silly at the point we fought the Hydra. I typo'd but we vanquished it all-the-same
 
 
2 hours later…
9:33 PM
Hey guys, I have a somewhat stupid question, but I don't know what to google for. I want to be able to set default values in a template in flask and pass it to a view so I can receive it
try:
    days = request.form["days"]
except Exception:
    days = 7
mask = df["datetime"] > (datetime.now() - timedelta(days=days))
something like the above. But what I saw is to put arguments into the query string, but I don't want that, I want my url to look clean
I would have a input where I could select x days. But I need to pass this info before pressing the submit button. I guess I need to store the info in the cookies? Or what other place can I store info instead of the query string?
 
There's so much to unpack with your question (curse opening chat just before going to sleep :P)
The "arguments in a query string" are GET requests. You're probably looking for POST requests
As for submitting the number of days, I'm not sure how you want that to work. If you want to remember a choice, then you could put that in the session, which may or may not be stored in a cookie, depending on how you've configured things
Otherwise, it's just a standard form input
 
no i want to do a get request
 
In which case, that's at odds with making your url look "clean"
 
i want to visit my_site.com not my_site.com/days=x
oh, so I can't really do what I want?
couldn't I somehow save the x in a cookie and then pass it along hidden with the get request?
 
Nope. You have to pass the parameter somehow
 
9:47 PM
but is the only way to pass data along a get request in the url?
 
Ugh, give me a few mins. I'm on my mobile so I can't type fast enough
I'll fire my laptop back up
 
haha thanks
your the man :9
 
Also, cig first since you've brought me back from just-about-to-sleep :P
 
ah I'm sorry.
 
Don't be. Has my overbearing presence in chat not suggested that I've been bored for the last couple of days? :P
Anywho, laptop is fired up
 
9:56 PM
haha alright.
I would love to have a default value set in the template, being passed to the get request, but not in the url and also to have an input field where I can manually change the default value
i have the input field, and that isn't a problem, but the initial get request is
 
Well, you can't have everything. So you can drop the idea of passing something in a GET request that doesn't affect the URL
 
ah man, why? I feel like other sites can do it too, somehow, I'm just not sure how :P But maybe I never really look at the url of other sites
 
Why are you so adamant that it needs to be a GET?
 
I mean I just want to visit 127.0.0.1:5000
@app.route('/')
def home():
    return render_main_template()
and in there I got data selection based on date and a bit of grouping and stuff. I mean could I make this a post?
 
Totally reasonable. Why do you expect to be able to change the defaults with that request?
@Hakaishin no, landing on a page is a GET request
 
10:03 PM
try:
    days = request.form["days"]
except Exception:
    days = 7
Ok, I think I got it
 
Yes, but no form has been submitted. You literally just visited the landing page
 
yeah, that makes sense. So when I change it I will just persistently store the value somewhere and replace 7 with it
Thanks :)
 
You'll store that in the session
 
oh, that is even better than what I had in mind. I just wanted to store it in a file
hmm but can I have sessions without a login? I want the same session for everybody visiting the site. Which is only me
 
Well, it may still be :P The session is actually pretty small (I wanna say 4KB but I may have made that up) and it's also stored in the browser. You can use something like flask-session to store the data server-side
It doesn't require any login
Once you use flask-session or kvsession then it's more secure and you don't have the size limitations
 
10:15 PM
wuhuuu :) Thanks it works. That's exactly how I imagined it. Yeah session was the right keyword. I was going on a total tangent with my search terms
 
:)
 

« first day (3560 days earlier)      last day (1380 days later) »