« first day (4434 days earlier)      last day (497 days later) » 

2:10 AM
@Code-Apprentice basically, positive step size takes a different implicit start and end position compared to negative step size. if you ask yourself how [::-1] works, you'll probably be able to piece together what implicit values it's taking, and that should clear it all up
 
 
8 hours later…
10:03 AM
def new():
    try:
        do_something_what_can_lead_to_exception()
    except Exception as ex:
        raise f"new exception: {ex}"
Hi, the linting tool complains "Change this code so that it raises an object deriving from BaseException." - what does it mean? I use a very generic Exception just to catch something.
I understood it is considered better practice to use explicit exceptions, but sometimes it is difficult to predict.
@Aran-Fey I agree 1[-2:][::-1] is more readable. But is it not also more computationally expensive than 1[:-3:-1]?
 
Probably, but who cares? It's only 2 elements
 
@Aran-Fey Apologies, see your reply only now. You mean one shall raise a function which for instance prints a string?
 
No, you have to raise an exception
As in Exception
 
raise Exception(f"new exception: {ex}")
I have been using raise to kind of stop processing, with some informing message
 
It's not a very good idea, makes it much harder to control the app flow
Of course unless there is a valid reason to raise an exception
abusing Exceptions makes them basicly goto-s
 
10:15 AM
Is the concern one could define raise on high level enough that it stops executing the code even though the exception is kind of not so important?
When I look at w3schools.com/python/python_try_except.asp, its first example uses something similar
try:
    print(x)
except:
    print("An exception occurred")
The only reason I use 'Exception as ex' is to be able to print out on program termination the reason
 
I'd say undefined variable is quite important and a perfectly valid reason to stop executing the code
 
What is not a valid reason to stop executing?
 
All depends on your program, but let's say you want a program to make a HTTP request and want to implement a timeout with reconnect attempts. First few timeouts you can just log and try again, but at some point you have to decide that it is not gonna work and stop the program.

The logic behind exceptions is that you want to catch them at the earliest place where you can actually handle them. And if it is not caught and stops the program that means nothing could handle the exception.
 
"you want to catch them at the earliest place where you can actually handle them" -- does this not imply a code full of try-except clauses?

Would your example be something like
try:
    make_request()
except:
    try:
        make_request()
    except:
        try:
            make_request()
        except Exception as e:
            raise f"3 request calls not possible: {e}"
(Putting aside it could be implemented as decorator with 3 repeats)
 
for _ in range(max_retries):
    try:
        do something
        break
    except TimeoutError:
        pass
 
10:30 AM
What if it is not TimeoutError which causes issue? Is it not safer to have something more generic, maybe as a second except?
 
I personally prefer LBYL over EAFP, exactly because I don't want to have a lot of try-excepts in my code
 
If it's not a TimeoutError, do you still want to repeat the attempt n times? Does it make sense for this specific usecase?
 
Granted, not all scenarios are well-suited for LBYL. Writing something like if can_make_request(): make_request() might be a bad idea, for example, due to race conditions
I/O and allocation of system resources are inherently exception-prone I suppose
 
@matszwecja If it is not timeout, how will you find out about the cause? You use except here for control flow, not for logging the reason for failure?
@Kevin thx, will read
 
I haven't read that article myself ;-) it's just the first thing that showed up when I googled "LBYL". Just glancing through it, it seems reputable. I too will read.
 
10:35 AM
You could add an else to the loop, which would be executed only if `break` didn't happen. This would let you raise another exception related to max attempts

Again, if any other error happens - can you handle it at this point? If not, what's the point of catching it? The exception should be passed to the point in which you actually know what to do
 
And if you do know what to do here, of course you can add another except and an appropriate logic there
 
I usually only raise Exception (as opposed to a more specific type, such as ValueError) when I believe the error is so fatal that no caller could possibly recover from it. Then it doesn't bother me that it's hard to catch the specific exception, since the process is already doomed no matter what they do.
 
Any reason as to why 2022-12-06 13:30:00 2022-12-06 13:30:00 are not same? Checking equality between these 2 datetime object gives False. Are there any hidden parameters that are taken into account when doing dt comparisons?
 
Microseconds, perhaps?
 
10:38 AM
types?
 
I think there is also a concept of naive vs aware datetime objects
 
Where is "2022-12-06 13:30:00" appearing, and how did it get there? Are you writing it to a file? printing to stdout? Have you called str or repr explicitly? There are no wrong answers, I'm just wondering
 
"For equality comparisons, naive instances are never equal to aware instances."
 
I think it is naive vs aware indeed
Django is supplying me aware instances and I am creating naive once or so
 
@Kevin Yep printing to stdout, but I realized the types were different at first, now that I changed it, still does not become True. But I think making both in the same tz will work
@matszwecja I tried printing one just before and it showed the RHS was indeed None
 
converting to/from TZ aware datetimes, scares the bejeezus out of me
 
Same :p
 
I never feel confident that I'm doing it right, and I worry that six months later it will turn out all of my log files are running on Japan time
 
datetimes are like pythonff's str all over again. Aware and unaware datetimes should be 2 separate classes
 
10:48 AM
Most answers for convert naive to aware shows the use of an outside library too
 
You do kinda have to add info that is simply not there to make naive dt aware
 
realpython.com/python-lbyl-vs-eafp -- Excellent article. After reading, I grew some appreciation for EAFP. Just the syntax is not so easy on eyes (maybe because one is not used to it).
 
11:03 AM
I don't really understand what makes the try ... except construct so unlikable. Is it just because it's 2 lines longer than an if? Or is it more of a psychological thing, not wanting to use exceptions for control flow?
 
still getting hits it seems :p
 
@Aran-Fey I think it is because people use if conditionals when speaking, probably very few express themselves via try-except :-)
maybe it also conveys some risk aptitude
 
try-except is psychologically damaging to me because it makes me aware that the system is fallible
 
11:19 AM
^
 
In my perfect fantasy world, open(filename, "w") never fails, ever
 
11:38 AM
What if the directory is restricted?
 
I have permissions for everything in my perfect fantasy world
Restrictions are for mortals
 
Another process has the file open? Kill it. Directory doesn't exist? Create it. Path is on a non-existent drive? Create a virtual one. Path is longer than the file system allows? Reformat. Path is an url? Hack the website.
 
Exactly so
 
12:03 PM
Unlimited resources, ah the dream
 
12:14 PM
Is it possible to start a non-blocking subprocess with callback on it finishing?
 
Non-blocking subprocess yes, callback on finishing no
Best you can do is start a thread that waits for it to finish
 
So basicly non-blocking Python subprocess that calls the target in a blocking way and does whatever I need in Python after it finishes?
 
I don't know what that means
 
nvm then, back to drawing board I guess
 
@matszwecja along the lines of what @Aran-Fey has suggested - might be worth taking a look at docs.python.org/3/library/asyncio-subprocess.html
 
12:28 PM
@JonClements yep, seems good, ty
 
I am having this weird pronlem, when I run the script, from VScodium (open Source Version), it says
ModuleNotFoundError: No module named 'numpy'
 
did you install numpy?
 
yes sir, and the script is working fine from terminal
 
Are they running same version of Python interpreter? (Did you install different Python versions?)
 
yes sir, same version
python3 all the way
 
12:42 PM
print(sys.executable) gives the same output for both?
And if yes, try that again with print(sys.path)
 
results are not the same,
'/usr/local/lib/python3.10/dist-packages' are missing
 
but sys.executable is the same?
 
yes, true
 
Weird. Sounds like your IDE is doing something stupid to sys.path
 
should I reinstall it?
 
12:52 PM
No idea what you can do about it tbh, I don't see any settings that would affect sys.path (in vscode)
 
maybe the installation path is not the same?
trying to install numpy again from vscodium, says,
Defaulting to user installation because normal site-packages is not writeable
'pip list' from vscodium terminal shows only a handfull packages
really weird
 
maybe you don't have permissions for site-packages directory?
 
 
1 hour later…
2:01 PM
@Kevin ah yes, my favorite mantra: try-expect-excelsior
 
2:28 PM
Welcome @rxFt20! One step closer to world domination - I've got a colleague to join chat. I'm just playing the long game with the master plan...
Also, all his complicated questions are now your problem. Kthnksbye
 
marks date in calendar Pitchtorches half price!
The end is nigh!
Wait, that was the wrong speech...
 
The days of lurking are over!
 
 
3 hours later…
5:40 PM
I can't believe I'm saying this, but does anyone know any good/decent module/package for downloading files in different ways? (eg: with multiple threads/connexion, continue/resume support, etc)
I tried to do it myself but getting stuck at the "multi thread/connexion" part...and I really want to finish this faster for some reasons
I don't want a wrapper for wget/aria2c/etc, but something in pure python if possible, otherwise I'll take anything else if there isn't any
 
I've also had the same problem in the past, and I also couldn't find a good "download manager" module
 
yeah, I recall you did I think
 
Which means, of course, that I've written my own... which changes nothing about the situation, there are still no good ones
 
do you mind perhaps sharing it on github? if not I'll understand
 
Well, it's not documented. But I can include a short usage example I guess
 
5:45 PM
:D
also sorry for the MRE, I'm actually lost trying to make multiple ones using different ways. It's not as straightforward as the last problem
 
@Aran-Fey "Which means, of course, that I've written my own". Wait a second... that would constitute a completed TODO item from your list. Something seems fishy here...
 
I also ended up somehow making my own screen recorder since OBS and other existing one are too slow on my Intel Laptop :/ I mean I'm happy because it's decently fast, although it doesn't support DPI scaling yet
I learned that the mouse on Windows actually is never part of a screenshot/video, but instead is taken separately and put in place by using it's position + image representation (using function that get the current cursor style, etc)
 
@roganjosh "world domination"!? No no no... that's mine... be nice and me and fellow puppies will be generous :p
 
That also explain why some screen recorder give you the option to not record with the mouse, and also why the mouse cursor sometimes flicker a bit...
I got an example video showcasing some tkinter stuff here: vimeo.com/manage/videos/778175703 if anyone is curious of the quality
 
@roganjosh It has loads of bugs and no documentation... and I don't like the architecture and API... so it was a learning experience, but it's nowhere near complete
@NordineLotfi Wow, I could never figure out how to do that. Mind sharing the code?
 
5:56 PM
@Aran-Fey Sure thing :) Right now it's using PIL, but it supports pyautogui too. It also supports mss which is admittedly faster than the other two, but I didn't find a way to make this one work with the cursor like the other two. It doesn't support recording with ctypes yet though...
if you look at the video, you'll see I made an example with tkinter, which is pretty basic. I didn't made it into a class or package yet, so it may look weird, just FYI
 
@JonClements <grabs the spray bottle> we shall see about that...
 
6:20 PM
@roganjosh */me eats the spray bottle - try the next one hooman :p
 
I am... defeated
 
it's okay... feed us well and we'll allow you to be deputy president of earth :p
 
I want to plot straight lines on a geographical map as something like a gif, with each leg of the tour being plotted individually. I'm tracking Santa moving around my city, stopping in each postcode region under various routing approaches (though, massively sped up as an animation). I just need straight lines between the locations so nothing fancy like leaflet routing machine (which I don't know how to make a gif of anyway) but basemap would probably look naff. Any suggestions?
 
I've seen it done but not sure how... sorry for no help there
 
Hahaha
That's exactly what I'm thinking, so at least it affirms my belief that there is something decent out there to be had, but I have no idea what it is
I can get the base tiles from OpenStreetMap/MapBox but the animation side, and packaging it as a gif has left me a bit stumped
 
6:36 PM
I'd be the same... be interested to how you work it out in the end though
 
@NordineLotfi Here you go. I hope I've included all the dependencies...
 
6:55 PM
@Aran-Fey :O Thank you!!! this looks pretty good
I'm trying to clean the code for the screen recorder right now, will upload before I go to sleep
btw, how do I attribute/give credit for it? do I just link to your github? (for your downloader module)
 
No need
 
@roganjosh Make a static image of the map, use it as a background and animate with something like matplotlib?
Might be hard to pinpoint exact locations but I guess you could geocode for coordinates and translate that to x and y axes on the picture
 
7:10 PM
Basemap would be able to do this, but I don't think it's the right thing. Maybe folium. I've just crashed one of my services so I got sidetracked in my search :P
 
7:20 PM
@roganjosh not directly related, but this might give ideas/inspiration: towardsdatascience.com/…
 
It's the animation and packaging I'm struggling to think about. I already can use maps - you can see it on my website
 
@Aran-Fey Why dropbox and not github?
 
Because it's undocumented and incomplete
 
I want something a bit like the animation here but overlayed on a decent-looking map (e.g. google maps) and not necessarily with every iteration of the solution approach, but an animation of the final route unfolding piece-by-piece over that map
Given the region size of a city, I might get away with a Mercator projection of the map underneath basemap, then animate it that way. It'll be a bit of PR, though, so I don't want it to look yam
"I just want an animation of geodesics over a photo-realistic map animated for my Santa project". Jeez, I think Marketing have gotten to me
 
 
1 hour later…
8:39 PM
@Aran-Fey github.com/secemp9/screen_rec not the most official way of handling things, but here you go
also, I just noticed now, but besides missing DPI scaling support, it also doesn't fully support the mouse (the mouse is there most of the time, but sometimes it disappears for some reason)...I need to investigate this later
I didn't include the tkinter example because I thought it looked too simple, but I can do it if you want (you probably don't need it since I'm sure you can come up with something better anyway)
mine was just using bind for each function
I also forgot to add some of the SO links/credit for some of the solutions I integrated. I need to dig through the gazillion bookmark and history I have, so I did what I could. Will do the rest later too
(I just noticed there is a lot of "do this later" in what I said above. Will improve that too, later :D)
 
9:03 PM
@NordineLotfi Thanks!
 
You're welcome :D
btw, by default, it immediately records your screen and saves it to a file called Recording.mp4. I left this there for testing, but you can change that if you want
 
How do you square that link with:
yesterday, by Nordine Lotfi
OOP is too complicated for me, as of right now, circa today, right now. Maybe it won't be later, but this now is the case
Seems to me that you used it exactly as intended
 
ah, well you see, the big class you see inside isn't mine (I mentioned that I didn't finish attributing everything to all of the stuff on SO I used). I did start to do it though (you can see I added attribution to a lot of the functions) but still working on it...also, yes I admit adding a couple methods to the class, but that's all I did on this one
 
It seems more to me like you're justifying your imposter syndrome, but ok. At the end of the day, you have a solution to an obscure problem
 
9:20 PM
imposter syndrome hmm, didn't thought I had it
 
You triple-justified your understanding of OOP :D
 
trying to make a benchmark for this will be weird though. Hopefully I'm right that the result is more than 14 fps, because visually this looks like 30+
@roganjosh I feel like, as long as making a class from scratch for a complicated logic (based on how I see things) will take me more than a couple hours vs making a bunch of functions, then I will keep on thinking I don't really get it yet. Maybe enough for editing a class or making a small one with static methods, but here I'm mostly talking about using self
alright, I admit I understand it somewhat, but I really don't feel like this is enough
 
9:45 PM
Hello, i am facing a little problem from morning.
I have a python script that: first create a mysql database and then some tables in it.
Second in this script i have insert some rows in settings table.

If i run the script the database was made, the tables was made, but when i try to insert data to table mysql 1146 (Table not found error) was oqqured.

After that if i run the setting insertion sub script manually (seperatly) then the insertion are done.

What may be wrong?

I am using windows 7, xampp, and python3.7
 
10:04 PM
@NordineLotfi but then you have to ask yourself "what is enough?". I wouldn't know half the stuff the others play with in the data model in this room, but it doesn't stop me being productive. A lot of it, to me anyway, is a curiosity
@ChrisP this could be anything as you didn't share code. My top guesses; you didn't commit the changes or you didn't grant permissions on the schema/table. We're off to a good start
 
I commit after mass sql creation.
Then i see another error related: Commands out of sync; you can't run this command now.
 
@roganjosh hmm, I get what you mean yeah. In retrospect, I guess I'm more productive than I was 2 years ago (when I only knew bash and some unix tooling) but I don't really know at this point. I'll try to reflect on this when I have more time though :)
 
Fantastic. So we now have a new error on top of a completely obscure description of the problem @ChrisP?
 
10:20 PM
0
Q: xampp - python 3.7 - mysql error 1146 table not found

Chris PFile: init.py import sys import time import importlib create_database = importlib.import_module("create-database") from settings import * create_database.import_tables_structure() time.sleep(2) import_settings() time.sleep(2) File: create-database.py import mysql.connector import sys import o...

 
That's an awfully long MRE
 
10:48 PM
@ChrisP hum, I don't think this is the same exact problem, but my hunch tells me this is related: stackoverflow.com/a/11696069/12349101
(aware this is for a different OS, but the logic can still applies, maybe)
there are other answers there that may work too, but I don't know enough about MySQL to judge
 
@NordineLotfi i finally solved it, using a sql parser and run one single query at once (then commit).
 
I see, nice
 
Thanks anyway.
 
maybe the problem was with locking the DB, which could explain why it worked with a single query + commit.
 
11:20 PM
wow, high contrast setting on Win10 is pretty good actually. Too bad it doesn't support syntax highlighting :/
 

« first day (4434 days earlier)      last day (497 days later) »