« first day (4239 days earlier)      last day (702 days later) » 

12:00 AM
The problem still exists.
 
 
1 hour later…
1:00 AM
@MisterMiyagi I think I was unclear. I don't mean a reference for how type construction works; I mean a reference for how the class statement works - in particular, the fact that it executes code immediately. (For that matter, a reference for the fact that def statements are immediately-executed code at the top level, just that the result of that execution is the compilation of the function object, rather than running any of the code therein)
https://stackoverflow.com/questions/72353341

so that I can better help people with this sort of thing in the future: I don't use an IDE myself. Do they generally integrate some kind of support to run `pip`, and ensure that it uses the same Python as it's currently using the run the code? Alternately, how are you intended to solve this problem when you do use an IDE?
(this is another example of why I'm on the anti-IDEs-for-beginners side of the fence)
 
1:29 AM
hey
I made some changes to a class in my project, and added a column and sense then I kept getting an odd and weird error referring to that column
class box(db.Model):

    id = db.Column(db.Integer(), primary_key=True)
    objCount= db.Column(db.Integer())
    serial = db.Column(db.LargeBinary(), nullable=False)#db.Column(db.String(), nullable=True)
    address= db.Column(db.String(), nullable=True)
    objects = db.relationship("object", backref='box')
 
ok, which column is added, and what is the error?
and what do you mean by "kept getting"?
 
the line I've added was "objCount= db.Column(db.Integer())"

and the error states : TypeError: non-default argument 'objCount' follows default argument
 
of course if you don't change anything and re-run the code, you should expect the same errors. If you try making various changes and none of them work, then it's only helpful to mention that if you explain what those changes were.
 
I did try to change the order of that line in the class, it didnt help
 
@Kevin Pyabd has a lot of functions. But it's not stable. Maybe because there is no maintenance for it more than 3 years.
 
1:32 AM
@LoopingDev please try to create a MRE and show a complete error message.
what you describe sounds like objCount = ... appears in the middle of a function call, where you expected it to be on a line by itself, as an assignment. This could happen because of a missing close parenthesis, but certainly not with the code shown here.
 
@KarlKnechtel pastebin.com/JPixZkv2
@KarlKnechtel if i remove the "objCount" line everything works
i'm trying to create tables using db.create_all() , where db = SQLAlchemy()
 
I got it fixed!

I pre defined few classes and it worked!, not sure why, the whole thing doesnt make any sense!
@KarlKnechtel yes it does!
thx a lot!
 
 
1 hour later…
3:12 AM
@LoopingDev wow
 
 
2 hours later…
5:21 AM
Is there a way to calculate the mean of a numpy array without having to copy it twice just to account for overflow?
>>> rgb_img = np.array([[[200, 200, 200]]], dtype=np.uint8)
>>> np.mean(rgb_img, axis=-1)  # gives floats instead of ints
array([[200.]])
>>> np.mean(rgb_img, axis=-1, dtype=np.uint8)  # overflows
array([[29]], dtype=uint8)
>>> np.mean(rgb_img, axis=-1).astype(np.uint8)  # correct but makes 2 copies
array([[200]], dtype=uint8)
 
6:00 AM
Can someone tell me why downgrading a particular alembic file is not working ? i tried alembic downgrade -1
ERROR [alembic.util.messaging] Can't locate revision identified by '8ead1201ab01'
  FAILED: Can't locate revision identified by '8ead1201ab01'
 
@Aran-Fey I doubt it
How would avoiding that work under the hood?
 
Just do the math with a large int/float and then immediately cast the result to a small int?
Instead of storing all the large ints/floats in an array
I guess it would still make 2 copies, but it would require far less RAM
 
@Aran-Fey sounds like something that would be hard to do with the ufunc mechanism, especially with arbitrary array shapes
You could use numba or something similar to do this manually yet fast
 
6:15 AM
Hmm, numba doesn't even need a compiler? That's pretty cool
 
I think it ships with llvm
 
I'll stick with numpy for now, since it is a bit of a premature optimization anyway. But thanks for the suggestion
 
Just define the operation with nested loops and slap numba.njit on it, and see if it's much slower
 
We'll see if my coworkers' computers blow up or not ¯\_(ツ)_/¯
 
The temporaries are only n_pixels large, right?
 
6:20 AM
Hmm, that's true, the float array is actually not that much larger than my uint8 image. I thought it was 4 times the size, but it's only 33% larger (since it only has 1 channel instead of 3)
Wait, it uses float64. So it's 2.3 times as large
 
Do you have gigapixel images?
 
They're pretty large, but not that large. Each image is approximately 2500x3500, and I'll likely have up to 10-15 of them in memory at the same time
 
But you have a single temporary array at a time, well, temporarily
 
True. But our work PCs constantly have problems because of low memory, so I want to save what I can
 
7:00 AM
@Aran-Fey in that case if you do arithmetic you should also know about numexpr
 
Yeah, you've told me about that before. Haven't needed it, thankfully. Except for the conversion from RGB to greyscale, I only deal with small rectangles and simple operations like counting or applying a threshold
 
 
2 hours later…
8:55 AM
Hi people, is it a normal git workflow to have to: git reset --hard origin/some-branch and git push --force regularly? It seems like this is not how things should be, but my colleague insist that it is. I'm talking especially after somebody else did a git rebase and then force pushed.
 
@Hakaishin no
"Never force push" is a great rule of thumb
 
@Aran-Fey This might not be relevant to your image processing, but just in case...
in Mathematics on The Stack Exchange Network Chat, May 15 at 5:17, by PM 2Ring
A simple example is the topic of gamma correction. Pixel colour values, eg in a PNG file use a non-linear encoding. But most image processing treats those values as linear. So any processes that rely on or modify the brightness of pixels end up with wrong values.
in Mathematics on The Stack Exchange Network Chat, May 15 at 5:32, by PM 2Ring
Here's an excellent article on gamma, and the errors associated with incorrect gamma handling: https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/
 
According to purists once something leaves your local setup, it's sacred
Potential exception: pushed secrets, for instance
 
@PM2Ring Thanks, but I don't modify the images. All I'm doing is look for specific areas of interest and feed them into an OCR program. I am technically handling brightness all wrong, but it works, so it's fine ¯\_(ツ)_/¯
 
9:05 AM
@Aran-Fey Ah, ok. You might find your thresholds easier / more accurately using the proper gamma, but it will take time to do the conversion, and your arrays will consume more RAM.
Here's a great demo (from that blog) of the difference between working in the proper linear space vs with gamma compressed values.
> incorrect gamma handling in 3D rendering is one of the main culprits behind the “fake plasticky CGI look”
 
I skimmed that, but the left column is fishy. Bottom one seems a lot shinier (more metallic in PBR, I assume), and I doubt that's due to gamma alone.
But perhaps it is, author probably knows their stuff. Still weird.
 
Incorrect gamma handling causes the size of the highlights (and deep shadows) to change.
There may also be some effects due to using more bits per channel in the linear version.
 
 
1 hour later…
10:38 AM
@Hakaishin Looks like your issue is in the "somebody else ... force pushed" so now everyone has to force-push. The remedy is that nobody should force push by default.
Once it's out there and used by others, don't forcefully change it.
 
@MisterMiyagi everyone could rebase
Unless you mean every fork but that didn't seem implied
 
11:28 AM
Not a fan of "everyone could do X when someone does Y", at least not by default.
Unless there's some horrible junk in the history, like secrets, there's no need to rewrite it.
 
I didn't mean that it's OK (in fact I said the opposite earlier). Just that a single force push could still be fixed locally (locally for everyone else).
And by fixed I mean avoiding cascading force pushes
 
11:49 AM
@AndrasDeak--СлаваУкраїні yeah, that's kinda the path we are taking now. I'm am so unhappy with the new employee, he is very stubborn
 
@Hakaishin did the new employee force push?
 
Yes. He says that is the normal workflow and wants me to use it too
 
Is he your boss? Or any lead in the team?
If one random person force pushes against the whole team this seems like a no-brainer. Nobody do anything until the remote is rolled back.
 
No. And here comes the problem. We don't have a boss really, which I like, but then things like this make it annoying of not having a boss. So I have to decide to either have to deal with annoying issues myself, but have more freedom, or ask the "boss" to step in and then have him potentially micro manage.
 
either the force push is part of policy and it's history now, or you i.e. the team decide to undo it
If it's just you and this guy then this is not a tech problem.
 
12:00 PM
A further issue is that the team was 2 people previously, now it's 3. The other dev got the new dev onboard and the 2 of them discuss a lot I think, but I'm not included in those discussion. It's a point I will bring up on a future meeting. In theory we have weekly meetings, to discuss such things, but we didn't have one in about 6 weeks. The problem is the other dev is ignoring the process suggested by the new dev and thus does not feel like the new dev is causing issues.
But I'm trying to follow the new process and it has well, issues
 
how can you ignore a conflict?
 
By working only on your own branch
 
@Hakaishin whose new process? Did you-the-team agree to the new process?
All of this sounds grossly mismanaged
 
No, we did not. He always says these are suggestions, but then it's suddenly a norm I should follow. Yes it is. Before we were a very lead back team, with little management. Which I liked and it worked perfectly fine, but now it's very frustrating.
I have to talk with the other dev about this whole situation, it's definitely not good
 
@Hakaishin in some way or another you must end up functioning in a team youtube.com/watch?v=EoMW8VYb_GE
 
 
1 hour later…
1:09 PM
Is there a way to send Ctrl+C to a subprocess. I'm running a REPL in a subprocess, and if Ctrl+c is pressed, it makes a new line. However, Ctrl+C in subprocess causes the parent Python process to quit, which I don't want.
 
If you send SIGINT to the subprocess, I believe it treats it like a Ctrl-C. Try using signal.
Or maybe subprocess has a built-in way to do signals? I haven't experimented in that area
Possibly I'm reading your question backwards.
If you want the parent process to send a simulated Ctrl-C to the subprocess, use SIGINT. If the subprocess sends a KeyboardInterrupt to the parent process when the user types Ctrl-C, try catching the KeyboardInterrupt and handling it in a more graceful way.
 
Yeah, I just used this answer: stackoverflow.com/a/842807
 
1:24 PM
Good, good
 
 
3 hours later…
4:39 PM
hello guys, I have this one question - "How can I keep a script running continuously". I couldn't find anything on this, that's why came to this chat.
 
Just use a while True: loop
Though you might want to consider what "continuously" means here, because that will burn CPU cycles so you might want small pauses on each loop. Is it a server listening on a port?
 
right now, I have a python Twitter bot, it keeps checking for the new tweets for an account continuously - time.sleep(60), every one minute it checks and dumps the result to the database.
I am doing this continuosly on my pc, with a while loop.
but at some point, the pc will be needed to shut down
 
Also, outside of the code, you might want to back it up with supervisor to pull it back up if something happens
Ok, then there's supervisor or cron - these are linux solutions, though
 
okay, so using both(supervisor or cron), things keep happening in the background, and at any given point, I can see a screen like terminal about what's going on with my program execution (print statements)
 
If I understand correctly your script already runs continuously; all you need is a way to start it automatically when the PC boots or the user logs in?
 
4:45 PM
no, there doesn't have to be any trigger point. once I run it, it never stops. if I terminate it manually then only it should stop
there shouldn't be like a restart at this particular time everyday, or anything like that.
 
If you're on windows, change the file's extension from .py to .pyw, and the terminal-like screen won't appear.
 
Then I don't understand the question. How is the current behavior of the script different from what you want?
 
I'm also fuzzy on that
 
yes, current behaviour is same @aran I apologize, I misunderstood. So, I press the execute button, and it doesn't stop, until I terminate it manually. Now, I can run it on computer, but I need something more reliable like a server
@kevin
 
Hmm I see
 
4:53 PM
any headway/solution if I can get, it'll be helpful. My pc is running for about a week now. but I don't know how long it can go like this. there are factors like power, internet connection, etc...
 
I hear AWS is a popular choice for running your code on hardware that's more reliable than your home PC.
For something that makes 1 web request per minute, you might even qualify for the free tier
 
okay. I'll see about that. thanks @Kevin
and what if I have two threads in a script, both making requests every .5 second (I am planning on a trading bot, after I can get successful with this twitter bot)
 
4 requests a second is about 10 million requests a month... That's probably outside the free tier
Fun fact: professional developers of high frequency trading bots will rent from whatever data center is physically closest to the stock market's servers, because the speed of light is a significant factor in making a buy/sell order faster than your competitors
I have a feeling the data center next door to the stock market doesn't have a free tier
 
to lose your money at a competitive rate
 
good to know that.
 
5:07 PM
Ultra-low latency direct market access is a set of technologies used as part of modern trading strategies, where speed of execution is critical. Direct market access (DMA), often combined with algorithmic trading is a means of executing trading flow on a selected trading venue by bypassing the brokers' discretionary methods. As defined by the International Organization of Securities Commissions (IOSCO), DMA arrangement is a process by which traders transmit orders on their own, without any handling or re-entry by another person, directly into the market’s trade matching system for execution. Because...
 
wow, okay. Been some time into trading, it's mesmerizing to know about this.
 
5:29 PM
@AndrasDeak--СлаваУкраїні unexpected lol
One thing to note is that I'm not sure AWS has hard upper bounds on their usage. So, you can potentially exceed your tier and not know about it... until the bill comes in
 
5:44 PM
okay
found this pythonanywhere.com when I was looking for AWS and similar services, making a test run @Kevin @roganjosh @Aran-Fey they have this console that keeps running even if I close the session, browser, and computer.
 
6:03 PM
Oh, I tried pythonanywhere once. I got it basically working, but I didn't have any cool ideas for cloud-related projects, so I sort of forgot about it
Come to think of it, maybe it would be useful for the extremely vague project idea I've had on my todo list for a month...
 
PSA: The ctx library was made vulnerable for a few days
 
> The ctx package, now removed from PyPI, is a Python library for accessing Python dictionaries using dot notation.
Well, it's slightly more sophisticated than left-pad, I suppose
 
6:30 PM
The hacker's explanation is quite eye-opening
TL;DR: The original creator's account (be it github, email, etc) dies, attacker yoinks it, profit
It's like the IT equivalent of social engineering, kind of
 
Man, I wonder why do technical people let their email domains expire to begin with? :/
 
using cronjob, if I choose "once per week" to run a script, let's say print("hello")
will i have this executed four times in 4 weeks? like 4 hello worlds be printed in 4 weeks
or is it going to start every day for four weeks, and print one "hello" every day?
 
Why would "once per week" mean "every day"? O.o
 
"once" means "seven times" in Isgian [citation needed]
 
6:56 PM
okay, that is correct. so if I mention once per month (0 0 1 * *), then will it start on 1st of every month
and so, would I be able to run that python script that I want it to keep running
it can restart every month.
 
you could have a powerout the day after that day happens in a given month
 
if I do it on cpanel?
 
If you're saying "ooh, a powerout, sounds cool. Can I enable that somehow using cpanel?", a power outage is a bad thing.
(Not trying to be flippant, just eliminating possible sources of ambiguity)
If you're saying "Would a power outage still be a huge disaster if I configured cpanel to somehow elegantly recover afterwards?", I don't know, I've never used cpanel
 
sorry, not being able to follow the point being focused on. I am thinking that what can be the downtime for a server, chances might be much less. aren't those? running the script on local vs cpanel server vs AWS (might be costly, not sure)
 
@DeepakVerma did you, say, search instead for "cron start job on reboot"? ... the thing you actually want it to do?
 
7:07 PM
will search for it.
 
Sure, AWS is probably less likely to have downtime than your personal PC. But this might not be saying much, if your PC has a 25% chance of crashing each month and AWS has a 2.5% chance. If a crash shuts off your process for 30 days, then even a single digit percentage may be too dire
Random googling has taken me to this document. I didn't read it all the way through, but I get the impression that you can achieve 99% uptime (i.e. 7.31 hours of downtime per month) if you have seven layers of fallbacks / countermeasures / recovery strategies.
 
[tag:cv-pls]https://stackoverflow.com/questions/72382780/typeerror-unsupported-operand-types-for-list-and-list-in-optimization#72382780
code is incomplete and cannot throw the error mentioned. asker refused to amend the code.
 
Speaking of how Indian English may differ from non-Indian dialects, I saw this in the HNQ: ell.stackexchange.com/q/315756
 
7:29 PM
Anecdotally, grammarly.com/blog/future-perfect-continuous-tense indicates that "On Thursday, I will have been knowing you for a week" is incorrect
I don't have much intuition for "will have [been?]" tenses so I try to refactor the sentence to avoid it
 
I just imagine that I'm in the future saying the same thing. If I will have said (:P) "I've known him for n years" then today I'll say "I will have known him for n years". But I'm not the native here.
 
On the topic of tenses, just this morning I was reading about historical present tense, which describes past events as if they were happening in the present. We see it all the time in here: "My program crashes on line three" does not imply that the program reached line three and crashed exactly as the person submitted the message.
 
Linguists trying to get English's act together by pretending these are formalised, named things...
 
And I posit the existence of an "aspirational present tense", which describes future events using present tense. "I am writing a program that gets all tweets from a particular user" does not imply that the program can successfully get tweets right now.
There's probably some fancy name already for a clause following the word "that", which precludes the need for my proposed tense
 
@Kevin It's sensible to do stuff like that, to keep the tense structure as simple as possible.
But it can lead to misunderstandings if the speakers haven't got matching "tense stacks".
 
7:47 PM
In Hungarian we have the one past tense. You can convey perfectness through verbal prefixes, but I don't think that counts.
 
en.wikipedia.org/wiki/English_relative_clauses is dizzying but perhaps it has some nuggets of wisdom
 
@AndrasDeak--СлаваУкраїні Are you Hungarian?
 
Here's an example I learned in primary of how tenses can get silly.
> Tom, where John had had "had", had had "had had". "Had had" had had the teacher's approval.
 
@Marco determining that is left as an exercise to the reader
 
Pretty hard exercise
I can only suspect that you are :P
 
7:55 PM
Let's just abandon tenses altogether and start using unambiguous timestamps
"My program crashes[on seventeen occasions between 2022/05/25 3:00 PM EST and now], does[now] anyone know[now] how to fix[between now and five minutes from now] a NullReferenceError?"
So clean and elegant
 
Looks good
 
It will look even better once written communication transitions from one-dimensional word sequences to abstract syntax trees
 
8:12 PM
Wow
 
8:56 PM
Any recommendations on a better Google Colab-like service (including the Pro service), considering cost-effectiveness? Not that Colab isn't good, but just to know
 
Is it possible that the waitkey method can be replaced by a button in cv2?
 
9:25 PM
How can I change this snippet to cycle through each row under a column? for index, row in df.iterrows(): I can't find an answer.
 
Wait, ignore that
for item in df['my_column_name']:
 
so if I wanted to iterate through a list that contains what columns to look at, could that be something like for elem in list1
 
df['my_column_name'] gives you a Series, which is just a numpy array wearing a cloak made from panda fluff
So you can iterate it like a list as you suggested, yes
 
Yeah, tried something like this: ` for name in models:
for item in df[name]:
if type(item[name]) == str:
merger.append(row[name])`
 
I suspect that we're not going to get to the bottom of this unless we flip the table and you ask about what you want to do
 
9:32 PM
I'd like to iterate through a list, use those elements to merge files indicated in rows under a column, where the column name is found in the list
 
9:42 PM
Well, I made a monstrosity to see if there was a nice way to filter by object type, and there isn't
import pandas as pd

df = pd.DataFrame({'a': ['x', lambda x: x],
                   'b': ['y', lambda y: y]})
print(df.dtypes)
df = df[type(df['a']) == str]
print(df.head())
If you hash the last two lines out, it works. So, I'm gonna default back to "don't have mixed types in columns" as the first port of call
My next question is - is there a reason that you have a column of strings mixed in with other types (that presumably aren't strings) but will be object types?
Actually, I also messed up my syntax there in that check. I think. This isn't something I've generally had to do
Yeah, I definitely created the wrong thing. I could try to fix it, but I would rather the question be answered first
 
Why eval("a=1") Didn't work (SyntaxError)?
But this a=eval("1") works?
 
eval can only execute expressions, not statements. (i.e. things that have a value)
 
9:57 PM
@ChrisP obligatory huge red blinking warning: never ever call eval or exec on strings that might contain evil input. This includes anything that other people have acces to e.g. by typing into a textbox on a website.
If this is just about converting textbox input to code on the same system, then users would probably be able to cause harm to their own systems anyway if they wanted to.
 
Well i have a sequence=[1,10,5] var, a value (parsed_playlist ) and one dict variable playlist.

And i want to execute ```playlist["items"][1]["items"][10]["items"][5]["items"] = parsed_playlist```
 
That means you need a loop, not eval
 
Yes but if i take a sub-dictionary into for loop perhaps i can't run the above statement.
 
I like the fact that the nested dictionaries have "items" keys all the way down
 
Speaking of, I recently used a database, and now I understand how SQL injection happens. It's easy to forget about those little ? placeholders when you have hundreds of lines of python code that dynamically generate SQL queries on the fly
 
10:02 PM
SQLite?
 
...I guess what I'm saying is I should've used an ORM instead of manually writing a cheap knockoff
@roganjosh Yep
Oh yeah, and also MS Access
 
The best, in my not so humble opinion, is to use %(my_variable_name)s syntax for parameterisation
 
Viewing this: stackoverflow.com/questions/2220699/… i can use exec(). Right?
 
And then pass a dict as a second argument to execute()
 
Is that a sqlite thing or do other dbs also support that? (pyodbc in particular)
sequence = [1,10,5]
container = playlist
for key in sequence:
    container = container['items'][key]
container['items'] = parsed_playlist
 
10:06 PM
conn.execute("SELECT something FROM some_table WHERE my_var = %(my_var)s", {'my_var': 'unicorn'})
 
@ChrisP ^
 
@Aran-Fey SQlite3 is the only db that I use that understands ? are placeholders, vs %s variants. But I think %(name)s is relatively ubiquitous
It was codified in the DB API spec but no wrapper is obliged to support them all (is my understanding)
 
Huh. The db api seems a bit messy
 
And the %s binding parameter is probably the biggest foot-gun going when it implies string formatting, yet is subtly different. Good job SQL Injection isn't a big thing
 
%s and %(foo)s remind me of python 2 :(
 
10:14 PM
%(foo)s is awesome in SQL Land. Please, come join us
 
But yeah, %(foo)s definitely doesn't trigger my brain's alarm bells quite as much as %s
I plan to leave SQL Land at the earliest opportunity :P
 
... somebody hasn't seen the cake
 
Yeah, this is ugly
 
I prefer "?" as placeholders
 
10:17 PM
%(foo)s is yamming-good syntax IMO
I prefer ? to %s too... but now tell me... say I have 5 CTEs that need the same value each time. How does ? hold up for that?
 
I had understood that you preferred "?"'s syntax
 
@roganjosh What's that a placeholder for?
 
@Aran-Fey :oh-rly:
 
@roganjosh Yeah, I got it now
"%(foo)" is better than "?" in this case
 
10:59 PM
stackoverflow.com/questions/72384579 Is there a canonical for this, or is it just something everyone writes off as a fundamental programming technique thing?
@roganjosh if only it could be {foo}. It's not as if the s really says anything useful; we're interpolating into a string, so stringification should be the default; and the % is already completely redundant with the ().
 
11:17 PM
Yeah, it's true
 
11:30 PM
Can playlist_item["original_path"] = item_original_path statement affects to playlist_item["original_path"] attribute? I ask it because when i run the statement the attribute value also change. Strange ...
Sorry mistake.
 

« first day (4239 days earlier)      last day (702 days later) »