« first day (3564 days earlier)      last day (1384 days later) » 

3:09 AM
cbg, I am doing a PyQt app and given a set of links (assume 10 links) in a text field it is going to download the images and show them as thumbnails in a main window, thats all the app does, but my problem comes when I thread this, it waits till all the links are downloaded, how can I make it so that each image appears as it is downloaded?
 
3:26 AM
@AndrasDeak Agreed, making C++ look like Python is a terrible idea.
@python_learner We'd need to have more information about how you're currently handling the multi-threading. Generally, what you'd do is spin off a separate thread for each image that is being loaded, and then as each worker thread completes, it would send a message to the main (UI) thread to display the image.
 
ohh ok, I just have a for loop and use a threaded function for download so that ui is not blocked
i dumped the whole loop into a thread, I must spawn a new thread, I see
thank you
 
Well, you can also download them all in one thread. But you need to make sure that you notify the main (UI) thread (e.g., by sending a message) to update once an image has downloaded.
Having a thread for each image download will theoretically allow you to download them faster, but you'll have more overhead because of the additional threads, and you'll be practically bottlenecked on your Internet connection. So your design might make more sense.
You just need to make sure that the worker thread talks to the main thread.
 
I am using QThread to handle this, I am aware that it can send a signal when the thread is done, need to look into how to send signal on each iteration
 
 
3 hours later…
6:26 AM
Hi
 
 
2 hours later…
8:17 AM
Is there a way to find out which __new__ will be called when creating an instance of some class? e.g. int, tuple, collections.namedtuple("Foo", []), and some custom class that doesn't define its own __new__? inspect.getsource just flails its hands in OsError and tells me that it's a builtin method.
 
8:58 AM
anyone knows if I can give a typehint for "this requires any dataclass class"
i.e. I have a method "dataclass_from_dict" and I wanna give it typehints :D
def dataclass_from_dict(class_: Type[T], d: Dict[str, Any]) -> T:
    return class_(**{field: d[field]
                     for field in dataclasses.fields(class_)
                     if field in d})
so is there a way how I can ensure that the Type[T] also constrains it to a dataclass?
@Arne like so?
>>> tuple.__new__
<built-in method __new__ of type object at 0x9040c0>
>>> hex(id(tuple))
'0x9040c0'
@Arne or maybe
>>> tuple.__new__.__qualname__
'tuple.__new__'
>>> x = collections.namedtuple('Foo', 'a b')
>>> x.__new__
<function Foo.__new__ at 0x7fddf7618430>
>>> x.__new__.__qualname__
'Foo.__new__'
if on Python 2, migrate.
 
9:38 AM
This old pandas question really needs someone to tell em about string extension types
@AnttiHaapala "if on Python 2, migrate." preach sir, preach.
 
I am always for solving the root cause of things.
@MattDMo that's even better than h-t-t-p-colon-slash-slash-slash-dot-dot-org
 
@AndrasDeak not sure if invented :D
google Withakay and you will find Eric Withakay, Erik Withakay, and Kris Withakay and that's 'bout it
oh and Rebekah Withakay :D
surely if it were a real surname, it would then have Robert Withakay and Elizabeth Withakay?:D
 
10:23 AM
Forest Withakay
@AnttiHaapala a druid's name might be invented, yes
 
10:42 AM
Hi All
I have one question
i have dict like below
dict1={1:{"partname": 'part1_item1' , 'archname':'sca_item1_rev1.0.jar','rev: '1.0', 'compname': item1},
2:{"partname": 'part1_item2' , 'archname':'sca_item2_rev2.0.jar','rev: '2.0' ,'compname': item2},
3:{"partname": 'part1_item3' , 'archname':'sca_item3_rev2.0.jar','rev: '2.0' ,'compname': item3}}
i am trying to add only values to another dictionary
look_up={}
for k,v in dict1.items():
look_up={v['partname']+v['rev']}
but the above only display only one value
{'part1_item110'}
i wan to display full value list
can any one help me
 
11:11 AM
Hello, everyone I need help with tkinter and cx_freeze anyone willing to help?
I'm working with python 3.x
 
11:40 AM
@thamizharasan there's no need to repost that badly formatted wall of text, thank you
@SiddharthPilli if this is about your new question on the main site please wait 2 days before asking here
 
 
1 hour later…
12:59 PM
Oh man, my 1st priority for this election is leaving the network :(
 
I feel like that has happened before and it will happen again
 
Can't even keep the votes for symbolism, they'll be reallocated anyway.
 
1:30 PM
what is a nice and safe timeout value for requests in general? I feel API requests would only take a few ms but webpages would take longer. But then people might have slow internet connections and stuff so I'm not sure what is a good value. aiohttp default is 5m which seems way overkill
 
@AnttiHaapala you can write a dataclass protocol: stackoverflow.com/a/55240861/962190, but it still isn't implemented properly in mypy. It does work in pyright though.
@AnttiHaapala I meant it in the sense of looking at the source code, or at least learning where to find it.
It's about writing an answer to this question that has just a lot of confusion flying around. My idea was to write something along the lines of "this is the code that will be run during new, and this during init. Stop trying to draw too many conclusions from benchmarks."
With the obvious problem being that I have no idea how to find out which lines of code will be executed in the __new__ of some given class, in particular ones that have a metaclass different from type.
 
2:05 PM
@AnttiHaapala Good grief, I haven't been to that site in ages. I used to follow it religiously back in the 90s, but then it just sort of devolved into suckiness following increased attempts at monetization and corporate-types not paying attention to the community.
I'm having this strange feeling of déjà vu all of a sudden...
 
2:47 PM
@Arne not sure if it actually helps me... :D now that I think of, I want to parametrize the Type[X] with something... and have constraints for the typevar...
and the most awful thing of all naturally is that in Java this would be trivial... :D
 
3:30 PM
@aadibajpai The scale of timeouts depends largely on your setup. We're regularly running into problems because some wiseguy thought testing our 40GBps network with a 10MB transfer is fine with 1m timeout – well, not if you expect 10k to 100k transfers through that network.
@Arne Sounds like a job for a debugger/profiler/tracehook.
As long as the thing is in Python, mind.
 
3:51 PM
@MisterMiyagi I see, I'm going with 10s for API requests because I saw the server responding in ms and even the slowest internet I could find (2g in India) had it not timeout for him in 1s
btw I am getting a weird error in mypy, I have a timer to start a browser Timer(1.25, open, args=[url]).start() and mypy throws error: Argument 2 to "Timer" has incompatible type "Callable[[str, int, bool], bool]"; expected "Callable[..., None]"
I'm definitely following docs so I'm not sure what to do here
looks like typeshed did fix it github.com/python/typeshed/issues/3782 but mypy is lacking
 
4:16 PM
nvm I am dumb, they did do it (I needed to update mypy)
 
 
1 hour later…
5:18 PM
@python_learner You can probably use a Queue. See docs.python.org/3/library/queue.html
 
I have theoretically read that queues can be used for communication between threads, but it never occurred to me here
noob question but how does one identify to what message a reply was? PM 2Ring replied to some message of mine (I knew the last message from memory so I knew for what he replied), it highlights if the message is in the same page, what if its not in the same page?
 
@python_learner click the little arrow on the left
if the message was too long ago a new tab opens showing the transcript
 
ahh, little things I fail to notice
 
5:34 PM
"Windows Defender scanned 401583 files. No new threats were found." Okay, and how many old threats were found?
 
Are actual viruses still a threat? I remember during my school days of Windows XP, I dont even run scans anymore :3
I am aware there are keyloggers and stuff, but virus as in creating exe's in removable drives and locking control panel type
 
I got some adware once. I've also voluntarily installed a bunch of adware in the form of "free" software, especially antiviruses
 
laurel
 
6:08 PM
cbg
what is the best practice when configuring __init__.py for flask , define static_folder=staticpath similarly template_folder=templatepath or let flask read the folder named static? sorry it may be a noob question but couldnt find a canon , Just wanted to know the best practises and if there is any SO question you are aware of .. thanks :)
 
6:27 PM
@python_learner ransomware are a thing these days
 
@cs95 I don't have the energy. There are hundreds more old obsolete pandas questions., from pre-1.0.x We don't have a or , and I don't think we should create one either. So, please continue tag/edit/encourage OPs to edit the pandas version into (say) the first line of their questions. I think that's the best that can be done.
 
@anky I don't typically define either. Whether that's "best practice" is debatable
Maybe it would be a better approach to ask why you think you need to define a static folder explicitly?
 
debugging help, offtopic, needs details, not a Python issue anaconda navigator not opening even after updating conda to all
 
And finally, this and the answer above it to give some idea on why you'll want the application factory pattern
 
@roganjosh thank you so much :)
i was biased on the path approach since it would handle path conflicts
so better ask experts
thanks again :) will give them a read tomorrow morning :)
 
6:43 PM
What path conflicts are you anticipating?
The static folder is a default path and it's relative to your app's entry point. Not defining it manually doesn't mean that it's not defined :)
 
incase the tree isnt as expected.. templetes inside application for instance
but may be that's for a noob ;)
 
Nah, I think it's a reasonable question :)
 
great :)
rbrb thanks again :)
 
7:10 PM
@smci closed
 
7:31 PM
@MisterMiyagi with my current knowledge of debuggers, I can't see it. Maybe I am motivated enough to learn more in order to answer this question, depends on how busy this week is
 
 
1 hour later…
8:41 PM
@smci pandas is pandas. While I think it is important for answers to state the pandas version they're operating with, I don't think that's a requirement for a large majority of the questions. Ones asking about deprecations and buggy behavior are definitely exceptions and need to mention their version to avoid question closure.
As for that particular question, I've already got a handle on it ;-)
 
9:00 PM
I took davidism's advice here, https://stackoverflow.com/questions/31358578/display-image-stored-as-binary-blob-in-template, and put the a path to an uploaded jpg into my SQLite database. I was wondering how to serve that in a flask template, specifically in a for loop. Below, `image_path` is the path to my image but `img src=/home/ubuntu/final/freeood/dan3.jpg` is being returned. I know images should be in the static folder but I would really prefer for this small to be able to call the image the way davidism recommended. Any direction would be super.
 
hey there
anyone knows django here?
I'm stuck at figuring out how to compare two text files in Django
 
@ArthTyagi does the text file comparison have to be done by django?
 
yeah
 
I see
 
i'm trying to build an autograder
it's kinda like when you solve a coding problem on some websites and you upload your output, it gets autograded based on the similarity of your text file and the actual solution text file.
 
9:11 PM
@ArthTyagi I don't think "comparing two files" is a django specific issue though
 
no i didn't to ask how to compare two files in the essence of it's logic
i do get how that's done in python
 
@SozDaneron where is your route? I'm out at the moment but can take a look when I get back
 
I'm not able to get how to request files from my model's filefield and compare it with another model's filefield
 
you should lead with that
 
my bad
 
9:27 PM
@roganjosh I hope this pastes correctly, I don't want to put too much code (also I am in Ireland and unfortunately heading to bed soon so no rush. Any advice would be helpful.

@app.route("/ads/<int:image_key>")
@login_required
def ads(image_key):

rows = db.execute("SELECT * FROM food WHERE image_key = :image_key", image_key= request.args.get('posts'))

posts = []

for row in rows:
DICT = {"image_key": row["image_key"], "title": row["title"], "description": row["description"], "county": row["county"], "area": row["area"], "image_path": row["image_path"]}
 
9:48 PM
:49974592 You got me thinking and...
`<dt><img src='{{post.image_path}}'/></dt>` returns a broken image icon. I have another instance where calling the images from the static folder works with something like this

{% for ad in ads %}
<img src='/static/images/{{ad}}'/>
{% endfor %}

but for this part of the template, I would really like to call a specific picture at a specific time. I guess I could change the name of the image but I want to see if it could be done the way described.
 
@SozDaneron You've bundled everything into a single comment so it's really tough for me to respond to separate lines
The first thing to note is the code formatting guide
Second, rows = db.execute("SELECT * FROM food WHERE image_key = :image_key", image_key= request.args.get('posts')) just circumvents the ORM, so that's thrown out
 
@roganjosh Thanks. 1) I swear I read that and thought I was doing everything accordingly 2) yes correct, thanks for catching that
 
I feel that you've misinterpreted the advice
(separately from my previous comments)
 
@roganjosh Rats, again you are right. I did misinterpret the advice.
 
It's nothing to do with the format of the db. What davidism is (I think) suggesting is to make a unique identifier for your database
So. Are you using flask-sqlalchemy?
@SozDaneron let's fix it :)
 
10:05 PM
:49974922 No I am not using sqlalchemy, just flask
app = Flask(__name__)
I may put a bounty out on this because it is the same problem I have had for a while, https://stackoverflow.com/questions/62621838/do-i-need-a-generator-maybe-sqlalchemy-for-flask-loop-when-querying-sqlite
 
Please do read that formatting guide btw
 
one thing's that missing still is that directed replies will also break code format
 
I should've tried in Sandbox anyhow, apologies
 
yup
 
Ok, I'm backing up to try fix this. Why do you think that this needs a bounty?
 
10:14 PM
if I initialize a value as 0 but later assign a timestamp to it which is float, mypy gives an error. Is the convention for initializing floats 0.0?
 
@aadibajpai yes, 0 is an int and 0.0 is a float literal
(I can't speak for the typing initialisation aspect)
 
cool I basically do something like last_updated = 0 for a token and then update that global variable whenever a token is refreshed
never had to worry about variable types until now :P
 
@roganjosh because it was not answered.
 
Okay. So we can probably ditch Sqlite out of the window here
Unless you have some burning suspicion that it's relevant
 
My end goal is something like any site that has "product" information and then the image of said product. It's to recycle food basically. The user is uploading the image, along with title and description, etc., so I thought this would be a sleek solution. To have all of the items variables in one location so you can loop through them.
 
10:29 PM
(Again my interpretation) - Upload the image with a unique identifier that you can store in the db.
I'm still lost on:
{% for ad in ads %}
<img src='/static/images/{{ad}}'/>
{% endfor %}
 
Right, maybe best to ignore that. That is a solution I have to display the image but it is in the static folder then. I would prefer to not upload the image to the static folder if it could be avoided.
@roganjosh I may end up uploading the image by the unique identifier
 
What you probably want is a one-to-many relationship
 
It's basic but I think the database schema is sound
 
You're missing the photo id
 
Wouldn't the image_key suffice?
I guess yes maybe there should be a food_id and then an image_id
 
10:45 PM
You'll perhaps forgive me for not seeing that in the schema
Anywho. I guess you meant image_path but this is becoming very obscure
 
Well the image_path is where the full path where the image is saved.
 
I was wrong on this, apologies. That's my bad. Let me thing about it. Genuinely sorry for that
Somehow overlooked the highlighted text. Ooof
 
@roganjosh I appreciate the chat and you taking a look at it. I gotta hit the hay though in Eire. No worries. The link that I pasted to the post a bit earlier should have all the details if you wanted to take a stab at it. Cheers!
 
11:04 PM
walrus operator documentation wraps the expression in if in parentheses as in if (path := gstr.search(hit['result']['path']))but pycharm flags them as redundant
are they necessary or nah?
local example works w/o it too 🤔
 
@aadibajpai only one way to find out
(and it depends on the situation)
 
@AndrasDeak yes it works locally but then I don't get why docs add it for a similar re.search example
 
11:26 PM
@aadibajpai two possible reasons I can think of are 1. it's a good habit to always parenthesize because in many situations the parentheses are mandatory, 2. even the people responsible for asspressions don't know how to use them
 
11:50 PM
@aadibajpai 3. In initial planning the precedence (order) of evaluation might not have been set in stone and docs like that still exist because that's how they originally started writing the docs (with the idea that if it changes this will still work)
^ I have not seen this with walrus but have done similar when building systems before
 

« first day (3564 days earlier)      last day (1384 days later) »