« first day (3638 days earlier)      last day (1293 days later) » 

1:04 AM
How to extract pixels from a jpg file?
 
Use the Pillow package (clone of the discontinued PIL). You can open a jpeg and then access the pixels in the image. (All the instructions you need will be in the docs.)
 
1:27 AM
libraries are required ?
is it possible to exact pixels(R,G,B) from image file bytes to a 3 d matrix ?
 
user13415013
1:52 AM
Guys one question, when loading function, inside function does it saves memory or it is good to delete it to save memory
 
user13415013
def some_func(file):
    df=  pd.read_csv(file)
    ## some transformations to df
    new_df = ....
    return new_df
 
user13415013
like this, would df would take memory or only new_df after calling function
 
3:27 AM
guys. why sqlalchemy so confusing. i'm quite good with SQL but this sqlalchemy module twist my head
is there anyway i could query like normal
 
3:40 AM
nvm figured it out
 
@Janith This method in the Pillow docs may be helpful: pillow.readthedocs.io/en/stable/reference/… and here is a link to their main page: python-pillow.org
 
3:59 AM
yes. Just read the image using opencv. something like

import cv2
img = cv2.imread("path_to_img", 1) #1 is for reading in BGR format
print (img)
# img is nothing but a 3d array. remeber the order is BGR not RGB
 
 
2 hours later…
6:03 AM
The PyLance extension in vscode is pretty good: marketplace.visualstudio.com/…
Still in preview but the intellisense seems to work great
 
 
3 hours later…
9:09 AM
Hello everybody,

I'm working on a project that is using offline machines only. Each of our clients gets their own computer to work on. But every once in a while all the results will be stored in our central system. So now I'm running into the problem of duplicate id numbers. I'm using auto increment at the moment.

What would be a proper solution to this problem?
1. Assign each client a block of id numbers.
2. Use unix epoch as a time stamp. (This gives a unique timestamp every millisecond)

Option 2 seems like the easiest one to implement. Just grad the current time and use it as the id.
@RoadRunner PyLance rocks! If you are using VSC you need to get it. Also makes it very easy to set the source folder of your project
 
9:32 AM
@nerd when the function returns it's as if you deled its local names, so that's not necessary.
That's partly why we use python
 
user13415013
10:27 AM
oh thanks, i was worrying if defining multiple dataset would take memory while using function, unlike in just i had used del() to delete data if it is not needed previous
 
@nerd it takes memory when the function is running
 
user13415013
may be ive to manually change function stucture so that it would take less memory.
 
maybe
 
user13415013
yes :), I was just worried about memory but with no problem :)
 
@CyberFly Another option would be to create a hash based on the time stamp and a unique id for every machine. This has a much lower chance of collisions than your option 2. See also this question
 
user13415013
10:42 AM
Hi anybody , know where can i find Stackoverflow duplicate dataset
 
user13415013
I found question releted to it stackoverflow.com/questions/49513076/… but it doesnt provide much information of file location, same data dump method
 
11:01 AM
hi
 
@IvoMerchiers Good idea, thanks!
 
in django form template how can I define form.as_div instance of as_p or as_table
and add widget attribute at div parent not child
 
11:46 AM
is it work authenticating a phone number in an application if you don't plan to use the number for communication? or is it better to just use email
 
12:06 PM
morning cabbages, folks
 
12:48 PM
TIL: I can edit deleted posts
 
1:00 PM
I think you can even reopen them
 
1:13 PM
Hi, is there any way on python, if a condition occurres, not to read specific lines coming after it?
 
if not <condition>:
    <lines to ignore>
like that?
 
 
1 hour later…
2:31 PM
Why does https://pastebin.com/ettpXRhU throw "TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
" error
 
2:44 PM
Hard to say without a stack trace
 
Should I post it here?
 
Sure
 
Traceback (most recent call last):
  File "flask_server.py", line 325, in <module>
    check_db_exists()
  File "flask_server.py", line 74, in check_db_exists
    db()
  File "/usr/local/lib/python3.8/site-packages/cvplay/db_create.py", line 82, in main
    conn = create_connection(f)
  File "/usr/local/lib/python3.8/site-packages/cvplay/db_create.py", line 36, in create_connection
    conn = sqlite3.connect(db_file)
TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
 
The stack trace you have does not match the code you provided. Presumably create_connection(f) calls create_connection with a file-like object, whereas conn = create_connection(database) calls it with a path string
docs.python.org/3/library/sqlite3.html#sqlite3.connect confirms that connect's first argument should be a path string, so I advise not passing f to create_connection
 
2:55 PM
@inspectorG4dget cc @nerd, MattMorrison... hope to meet you
 
looking forward to Saturday's meetup :)
 
user13415013
cool, i have alot of questions to ask :D
 
@nerd You could add them to the list of talking points...
 
user13415013
Yes :D , I am adding, ok guys, meet you soon,
 
please remember that the list of talking points is not meant to be an official agenda of any sort. It is simply a list of ice-breaker topics that we /could/ discuss in case the room becomes really quiet
 
user13415013
2:59 PM
got it brother, :)
 
@nerd So just speak up if you wanna raise something ;)
 
user13415013
yes , before i met you guys first time and didnt know how to talk and listening english language was quite different even i know it :D
 
curious: what is your first language?
I'm from south India and speak Tamil as well
 
user13415013
Nepali :)
 
user13415013
paulMcg who is ?
 
3:09 PM
what does this chat made for? is this a new feature in stackoverflow ?
 
It's been around for like ten years
 
OOH, it seems I've been out of the world, LOL
 
@MohamedSamir Not at all, it's a totally unofficial informal chat/hangout for anyone from Python room 6, whatever topic (Pythonic/non-Pythonic/serious/frivolous) each of us wants to talk about.
 
Hmm, I may have misunderstood the question.
If the question is, "is chat.stackoverflow.com a new feature of stackoverflow?", no, it's quite old. If the question is, "is the October 3 hangout a new feature of stackoverflow?", it's a new thing we're doing but it's not endorsed by StackOverflow
 
@smci Okay, thanks
@Kevin thanks for your clarification
 
user13415013
ok guys, i've joined, cool topics from me, would be great if get meet with @AndrasDeak :) Take care
 
user13415013
gn
 
@nerd don't hold your breath
 
Hmm, my work environment tends to have pretty flexible deadlines, but this "replace all Flash elements by 12/31/2020 11:59:59 PM" task is probably one we can't bury in the backlog forever
Maybe it will be like Y2K and Flash will continue working forever?
Let's revisit the issue on 6/1/2021 and take stock there, no need to be hasty about this
 
cbg,I finally got to answering a question here but the question has changed now, should I still post the solution to the edited question?
my answer was accepted but they have made an edit, I have the solution for the edit but I am not sure if i should go ahead with posting it
 
3:36 PM
Changing a question after it's already been answered isn't allowed. Those changes should be rolled back.
 
I am not sure when the question was changed or when the answer has been accepted (before or after change)
 
It doesn't matter when the answer was accepted, what matters is when it was posted
 
3
A: Making an ordered list from a list of dictionaries by custom rules in python

python_learnerWill this work? Use the key parameter to perform your sort t=[{0:[(0,0,1,3),(0,1,1,3)]},{1:[(0,1,1,3)]},{3:[(0,0,1,3),(0,1,1,3),(1,0,4,1)]}] sorted_t=sorted(t,key=lambda x:len(list(x.values())[0])) result=[list(i.keys())[0] for i in sorted_t] print(result) # [1, 0, 3] Breakdown sorted_t=sorted(t...

 
In my opinion, your obligation to do anything at all ends once you get the accept. That said, if you want to continue helping out of the goodness of your heart, I don't see any problem with editing additional information into your existing answer.
 
If someone goes out of their way to solve your problem for you, don't go changing the question to a different question. That should be basic courtesy
 
3:39 PM
This is true.
The ideal situation is that you solve their original question, you get the accept, they ask a follow-up question in a totally new post, and you get the accept for that too
 
that would be more upvotes for me, maybe I will just post a 3.8 only long one liner, I still solve it :p
while coming up with a solution I however came across having to use list(dict_seq.keys())[0] to get the first key, is that how one does that? or is this just now how dicts are supposed to be used?
same goes with values
 
You can do next(iter(dict_seq.keys())) instead
 
OP claims "StackOverflow doesn't let me create a post with a similar topic", which at least explains their edit-oriented approach. I advised them to complain about the dupe detector on Meta, although honestly that's as likely as not to help
 
I did some google search and 2.0 had indexing, seems like a fallback to me
 
I agree that it's inconvenient, but fortunately it's something you rarely ever need to do
 
3:48 PM
I'm half expecting them to succesully post a new question, but only by using a title like "sorting a list of dicts? Extra words go here to trick the dupe detector rutabaga giraffe cellar door"
 
correct horse battery staple
 
I just added in "New Solution as per edit" and posted a new one that works (90% sure)
 
4:01 PM
@python_learner In Py2, keys(), values() and items() returned lists, so using [0] to get the first element was fine. Now in Py3 you get dict_views, which aren't even iterators, so you have to wrap in an iterator and then run next() on it. Or just make a list from it. So you say "fallback", others would say "intentional incompatibility in the name of science".
@nerd Just to set your expectations, from the few minutes that I attended the last session (I'll read the timezones correctly this time!), the discussion was mostly social, not technical. So if you have code to discuss, you might be better off posting in chat like usual.
 
laurel, the only python2 vs python3 difference I know is print was a statement and not a method
 
@Aran-Fey yes, courtesy and (unofficial?) rules too
@Kevin probably exact same title
 
Probably the most glaring difference, but far from the only one.
 
Andras, Yeah -_-
 
@PaulMcG nor the most important
 
4:07 PM
Oh yes, the str/bytes/unicode thing was a biggie
 
I used to know dozens of Py2/3 differences, but I've forgotten most of them because I don't need them any more
 
now it's the realm of archaeologists and historians
 
And the Turing Completeness Police
 
I did revisit some old code of mine because i couldn't remember how to download image data with requests, and it turned out to use urllib2
 
range vs xrange. print vs print(). All the generators in py3. myDict.keys() is this weird thing called a view, now. That's what I can think of off the top of the ol' noggin
oh! '' > myInt > None no longer works
 
4:14 PM
some module reorganisation: Tkinter, urllib stuff
Backticks for repr?
 
It's strange to me that requests doesn't have an out-of-the-box solution for downloading non-html resources. You have to futz with streaming and chunks and shutil etc. Maybe I misunderstand what request's core purpose is.
I want requests to be a swiss army knife for all things web related. If requests wants requests to be a simple HTTP interface, then it's more understandable that they're not interested in abstracting away the actual HTTP
 
user13415013
4:29 PM
:D, @PaulMcG are you same person on machine learning coursera
 
If I am, I haven't logged in in years.
 
user13415013
:D you are also on deeplearning.ai slack
 
Paul is kind of a big deal
 
I had no idea I get around so. I do run into other Paul McGuire's with alarming frequency.
 
user13415013
oh sorry, I thought you are him but anyway :)
 
4:36 PM
I have had intentions to stray into the whole ML and DS milieu, but learning those two acronyms is about the extent of it so far. (I did do some multivariate analysis a while back, when I was doing semiconductor process analysis and control consulting. But at that time, numpy was still just a twinkle in Travis Oliphant's eye.)
 
5:03 PM
talk about ancient history
 
@Kevin - have you looked at httpx? I started following it a while ago on GitHub, but they've posted several releases since the last time a dallied with it.
 
5:31 PM
Hmm interesting
 
I wonder how that shapes up against requests-futures?
 
6:08 PM
Hey guys do you access the data from wtforms Selectmultiplefield the same as you do for normal select field with "dict(form.choice.choices).get(form.choice.data)"
 
What happens when you use that?
I know that without wtforms it won't work and you'd need to use getlist (or something similarly named), you can google around that
 
 
1 hour later…
7:17 PM
stackoverflow.com/q/64161821/4799172 dupe, and their output is no repro
 
7:59 PM
@PaulMcG so how is it different from requests, other than the type annotation and test coverage? Does requests not do async?
 
I think the async version of requests is a long-standing open issue for that project, with some notable prior fumbled attempts. Also httpx is addressing HTTP/2 protocol (which was what got me interested originally in httpx, but now I couldn't tell you why).
And according to Wikipedia, HTTP/3 is coming along Real Soon Now.
 
@MattDMo I don't think base requests does? Async that is. I thought the library was always blocking
 
@roganjosh I'm not sure, I've done very little async work in general. It's probably something I should look into more.
 
Hi guys , i made a class and inside one of the methods i said self.dim = .... and later on im importing that file on to another file and i create an object of the class, say obj, and say obj.dim, it gives me AttributeError: 'ToolTip' object has no attribute 'dim', can you help me here?
 
@MattDMo I told a lie. They have docs for async requests. I'm not sure how long that's existed for
 
8:13 PM
@CoolCloud you have to call that method. Ideally only __init__ should create new instance attributes which usually gets called on object instantiation.
 
@AndrasDeak oh so like obj.method() then how to access the instance variable?
 
@CoolCloud with obj.dim. But until you set that attribute on that instance the instance doesn't have the attribute...
 
so basically saying self.dim is not enough?
 
Well, you said that and it didn't work, right?
What do you think self.dim should be before you told python what it should be?
 
undefined?
 
8:18 PM
@AndrasDeak that's an old version of the docs, though. Is async a reserved keyword now, or is that in the next release?
 
@CoolCloud that's javascript
@MattDMo misping :)
@CoolCloud if you want obj.dim to be None until you say otherwise in a method, set self.dim = None in __init__.
There's no magic. Something will have to set that attribute. Python can't read minds.
 
Ideally you should not be trying to access an undefined value
 
Oh i get it, since its undefined during __init__, it wont show up unless that method which creates that instance variable is run right?
 
@CoolCloud it's not "undefined" during __init__. In that vein literally any valid keyword would be "undefined during __init__". That's the wrong way to think about it.
 
@AndrasDeak oh okay i see, ill take a look, thanks mate
 
8:22 PM
So the logic is this: until something sets obj.dim it doesn't exist. And one of few methods that get called automatically on object instantiation is __init__ so this is the right place to put this.
 
>>> import keyword
>>> "async" in keyword.kwlist
True
 
>>> async = 42
  File "<ipython-input-189-1d38f6f80d95>", line 1
    async = 42
          ^
SyntaxError: invalid syntax
:)
 
@AndrasDeak thanks mate, fixed it
 
yay, I remembered something correctly!
 
Bit of a semantic gray area whether "undefined" and "doesn't exist" are different concepts. I do think it's useful to acknowledge that before it's assigned for the first time, self.dim is exactly as real as a self.foobarbaz that never shows up in the program at all
 
8:25 PM
@Kevin I agree with that, but that undefinedness is not constrained to __init__.
 
True
 
My issue was with "there are no pink elephants in the west wing's bedroom"
 
Hmm, makes sense. Attributes too much special meaning to the bedroom, when in fact pink elephants don't exist anywhere.
 
9:07 PM
Folks, I need a URL for a negative test. Is there a commonly known URL that's guaranteed to not exist?
nonexistent.com cousin of example.com
 
perhaps you could use one of the reserved TLDs from tools.ietf.org/html/rfc2606: .example, .test, .invalid, .localhost
 
@NickAlexeev I'm not sure that makes sensd
What error do you want it to raise?
 
www.example.invalid certainly fails to load anything in my browser
 
I want to make a request to a non-existent URL and get an exception.
@Kevin Would that request even go to DNS? I wonder.
 
why do you need to send a request at all if you just want to raise an error?
 
9:13 PM
@roganjosh Why do people run negative test cases?
 
Beats me.
 
nslookup -debug www.example.test Tells me *** cdns01.comcast.net can't find www.example.test: Non-existent domain which leads me to believe that it's really sending the dns request upstream rather than eating it locally
and likewise for www.example.invalid
 
I've totally lost what we're trying to do here
 
@Kevin Thanks. Network skills is my blind spot.
 
I only know enough to have gotten a C+ on the topic in college :-P
 
9:19 PM
cbg
 
@roganjosh I'm thinking it's something like "I want to make sure my program fails gracefully if it gets passed a url that 404s, and it's easier to write my unit tests with a real 404ing url rather than mock out the http-interfacing call, for reasons"
 
I might be getting caught up on "for reasons" :P It's not difficult to break an endpoint
 
im dabbling in information retrieval and I came across the inverted index, which seems like a decently optimized first pass through at this problem. But it doesnt really look like there's a nice way to represent it as an array/dataframe due to the heterogeneous lengths and the fact you'd be storing a df of indexes and lists (and optionally a word frequency ). Am I wrong about that and there's a good numpy friendly represenation I dont know aboutt
 
Usually when I unit test I'm quite keen to give it actual input that would make it fail, if at all possible. Mostly because I don't know the mocking syntax by heart
 
Make a URL route that throws the exception? I'm confused how that differs from using an external source that's only going to throw HTTP error codes back at you
 
9:32 PM
As in, configure your own website so you have a page that you know 404s? That seems fine if you have one. But if you're writing, say, a web crawler, that might not be the case.
 
What does the 3rd Party do that you can't incorporate into your unit test?
That's a genuine question btw. I've launched my web server... why do I need to test against some random resource vs. something I could just build myself?
 
Suppose you don't want to integrate a web server into your project, though.
 
OK, now I see. I can't help but think that's lazy but, then again, I'm not great on the unit testing front :P
I also really dislike scrapers so I'm gonna gracefully back out and not elaborate on my ideas
 
9:57 PM
@Skyler I don't know what an inverted index is, but if it's heterogeneous in shape then yeah, numpy is a no-go
@NickAlexeev I'm pretty sure you'd want to mock the request and lie to the testing code yourself that the target doesn't exist
my hunch is that ideally no requests should be made during testing, valid or not
case in point: CI systems leading to DDOS
 

« first day (3638 days earlier)      last day (1293 days later) »