« first day (3025 days earlier)      last day (2147 days later) » 

03:54
Okay sure
 
4 hours later…
08:07
@AlexanderReynolds Hammered.
cheers, ty for the additional comment too.
No worries.
Hopefully, the OP understands what we mean. :) The answer of the dupe target is great, but it's a bit general, and it might be a bit overwhelming for a newbie. So it's good that you gave that info to help them with their specific question.
In some cases, it may even be necessary to post an actual answer to help the OP apply the info at a dupe target to their particular case, but if it can be done in a comment, that's better, IMHO, although some members will complain that it's an answer in a comment. OTOH, the same people will downvote you for answering a dupe...
08:27
Yeah my philosophy generally for this is help explain in comments how the OP can apply the dupe, or give them some background, but the point of marking a dupe of course is to have "one place" for answers to coalesce and I generally agree with that principle.
Of course the original question or answer can always be edited to make that page a better resource for a wider audience when appropriate, though that doesn't seem to happen often (not sure if thats a good or bad thing lol)
@AlexanderReynolds Indeed! Although it is ok to give them a new answer if it's warranted. Even Martijn Pieters will answer a question that he subsequently hammers, from time to time. Although I think it's better if the answerer & hammerer are different people, otherwise you leave yourself open to accusstions that you hammered it to monopolize the rep from the new question.
Sunday cbg!
@AlexanderReynolds Some old dupe targets have outdated high scoring answers, and better newer answers languish at the bottom of tje page, or on subsequent pages. We do try to clean stuff up, especially on popular targets, but a total cleanup would be impossible, with over a million questions in the Python tag(s).
@shad0w_wa1k3r Cbg!
09:24
hi, Is there any way to conver image to binary like this: turn black parts to white and black other parts
in opencv
10:08
@saha with OpenCV you can use inverted = cv2.bitwise_not(binary_image) to invert a binary image.
@saha if you want to make the black parts of an image white and turn all other colors to black, you can use cv2.threshold() on a grayscale image or cv2.inRange() on a three-channel color image.
 
2 hours later…
12:38
I would like to reshape the output of a.extend((value1[index1], value2[index2], value3[index3])) to three columns and n rows. Currently "a" puts each value on a row. Any idea?
Define "row" and "column" in case of a list. But probably a.append([value1[index1], value2[index2], value3[index3]]).
but if you're using numpy you probably have other options
thanks, but i read that .extend is faster than .append
what other options are there with numpy?
with your history of vague and incomplete problem statements we can get back to that with a full problem specification of what you really want to do (down the line) and an MCVE :)
@user2153702 del is fastest
12:54
nested loop through a very large dataset, extracting the 3 values through long calculations and saving them to a csv file with 3 columns, n-rows (np.savetxt statement)
there might be even better options, but you could at least use extend as you had it and reshape after the loop to shape (-1, 3)
tried the reshape but didn't work. How faster extend than append?
i suppose, i will stick to append then!
of course if you ask a quantifiable question rather than "is an orange better than a tomato" we might be able to reach exact conclusions
>>> %%timeit a=[]
... a.extend([1])
...
...
106 ns ± 1.52 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
>>> %%timeit a=[]
... a.append(1)
...
...
56 ns ± 0.627 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
12:57
can you give me an idea on your statement "there might be even better options"?
Wow
The relevant claim is that one call to extend is usually faster than the equivalent n calls to append. Don't take vague statements at face value. Performance comparisons never work as generalities
@user2153702 if the sources are arrays you might be able to use vectorized operations (advanced indexing)
thanks
there is a "#" at the beginning of the header in this line np.savetxt('File1.csv',a, header="value1,value1,value3", delimiter=',', fmt='%s')
how can i remove it
I don't understand what you're asking
the np.savetxt adds # at the beginning of the csv header. The header is
# value1,value2,value3
ah, I see
13:05
why the # and how can i get ride of it
comments : str, optional

    String that will be prepended to the header and footer strings, to mark them as comments. Default: ‘# ‘, as expected by e.g. numpy.loadtxt.

    New in version 1.7.0.
if you search for # on the doc page you can easily find that
@user2153702 It makes it easier for simple parsers to distinguish header lines from data value lines.
how can i remove it
@user2153702 really?
add comment=''
13:08
try and see
13:42
cbg all
I was examining the _getframe() function in sys and the current frame from the frame object gives me <module>:
import sys
frameobej = sys._getframe()
print(frameobej.f_code)
The last line is print(frameobej.f_code.co_name)
I know that <module> is the name with which the code object was defined. But I still don't understand how the name <module> was assigned?
If I do some more function calls that add more code objects to the stack, then I often see the function name as the name for the code object but always the bottom of the stack I get <module>
14:23
@amanb <module> is the toplevel module outside any function
Thanks @AnttiHaapala. That's a higher level explanation..is there any link or resource that can give me a more detailed explanation?
14:38
I think basically modules are nested inside each other, and <module> is the topmost one, which all others are nested under. Which is why you don't see <module [some_module]> Hence Antti says it's toplevel because that's probably all you need to know
@ChuckIvan nope.
@amanb when the code object is created it is not known which module it is compiled into... so it ends up being <module>
it could be known but it isn't there.
and... the co_name reeaaaally means the function name...
@amanb note that it is not specifically documented much anywhere, because the frames etc are just an implementation detail of the CPython
hello everyone :)
I have a question about a piece of code I'm writing to practice python, and i got stuck. i was about to post a question on the forums but realized that i dont really know what exactly i am looking for or how to formulate it in a forum appropriate way. mind if i ask it here to get some clarity? :D
14:59
well you might ask, then it is up to the people online if they might answer :D
@mn2609 welcome. Sure, just ask.
(and minor note: Stack Overflow explicitly doesn't call itself a forum in the usual sense)
@mn2609 Let's see the question
alrighty then: im trying to build a cows and bulls game(for everyone not familiar: en.wikipedia.org/wiki/Bulls_and_Cows#The_numerical_version). It works fine besides on problem: i use a for loop to check whether the a digit from userguess is in the random number. then i check if i should attribute cow or bullpoints. if it should be bullpoints, this happens(this is where im unclear as to how to ask)
heres the for loop: dpaste.com/3NKEQY1
example: the random number is 7667, user input is 6453:
cow count would be (rightfully) 0, but bull count is 2, when it should be 1
i tried to check for duplicates in the user input after the elif bull statement, but cant for the life of me figure out how to do that
well i could figure out how to do it, it just looks clumsy as hell
I think that's because you're using in. Checking if 6 is in the user_guess twice will resolve true, even if there's only one 6 in user_guess
dont i have to do that to then do further checks with the if-statements?
15:17
For the case of a=7667 and b=6543, you will make a check for 6 in b twice, and both times the position of b in 6 is in the wrong place. Do you see that?
@Chuck
@mn2609 first of all, I hope you're using strings instead of numbers ;)
then you can split the string into a list of characters.
so first you'd check bulls, and turn the bulls in the list into None's say.
second time you'd check cows, again carefully just replacing one to None per cow...
Also I'm reading the wiki link you gave us and it says:
'On a sheet of paper, the players each write a 4-digit secret number. The digits must be all different.'
But you gave us a random number with repeated digits in the 7667 example
15:22
@mn2609 this game is also known as mastermind, might be easier to find matches with that. I hadn't heard bulls and cows ever before
@mn2609 You may also be running into trouble because you are making invalid secret numbers. The rules you shared explicitly say not to do this. I can see the ambiguity issue there
actually forget all that
@ChuckIvan yes. I guess thats what i tried to find an alternative for but couldnt find any. as to the the non-repetition of numbers: i am using examples from pythonpractice.org, where they didnt specify that. i didnt know how familiar people here are with that site, so i just googled for a quick explanation from a maybe more known website. (i do not know yet how protective you guys are when it comes to sharing links on here :')
@AnttiHaapala i generate ints using the random module and then convert the whole 4-digit number to a string
according to the code written, wouldn't you agree that an input with two 6s is checking 6s twice, leading to a fairly valid answer of 2 mismatches?
and you can extend that to the following issue. 7667 with a correct answer of 1634.
regardless, you'd have to take a "design" decision first.
@ParitoshSingh That's the first thing I said
15:27
what should happen in these cases?
and then just write it in
aye. @ChuckIvan i just wanted to specifically challenge why "count is 2, but should be 1" is a design decision mismatch using what you said.
Exactly. 2 Really isn't an issue except a headache to the player, and that's probably why the game designers said don't repeat elements
@ParitoshSingh well it should be 1 because the idea is that the cow and bull count helps the player to achieve the correct answer finally. therefore my code should focus on the user input, not the ...........ooooooooohhhhhhhhh
:)
your code is whatever you tell it to do. the code is never wrong.
only we sometimes have a mismatch between what we "want" and what we "wrote"
(i should say, code is almost never wrong but edge cases aside)
ill take another look at it. thanks guys, you have been really helpful :)
16:26
@AnttiHaapala, yes this kinda makes things clearer. The code object name is the function name. If there are multiple function calls in a stack, the stack at the deepest level has <module>, which maybe coming from C-compiler. The other question that comes to my mind is why is this always the current frame. I've been exploring CPython source for this.
wat?
the module level is the outermost frame, not the current frame
the current frame is where you call sys._getframe()
But when I run the following code I get <module> and `sys._getframe()` without any arg has depth 0 which returns the current frame. The SO answer link and the docs also state that.

>>> import sys
>>> frameobj = sys._getframe()
>>> print(frameobj.f_code.co_name)
Hey all, is there somewhere to find reliable automation contract work anywhere online? I'm not looking for anything fancy or super-high-income
@frank, please don't do that
@amanb which, find work online or ask the question in this chat? :P
16:39
@amanb means your current frame is also the outermost one
@frank, This chat is only for discussing Python related topics, questions and other relevant stuff.
@amanb I don't really agree that the single non-harrassing question they posted is a problem, but anyway we won't be able to help here
@amanb it's not
@amanb frank isn't looking for contract work in this chat, they're asking for places to find it. It's fine
Thanks guys; once I find the website I will leave you to python :)
contract_site=input("please let me get back to your lives by halping me kthx")
16:41
ok, I agree with y'all. @frank, mate don't have anything with me. All the best with your search.
Even if there were a stackexchange site to find such things, I would post there. Idk if there is such a thing
nope
this sounds more like reddit/craigslist/whatever
That's a good point, actually, thx
( @AndrasDeak )
good luck
I think I've seen you around SO, too. Thanks for helping keep this great site running!
16:45
happy to help :)
I've seen @AndrasDeak around since I began coming to this chat and one of the most helpful mates here.
I'll bookmark this for when next time someone objects to my draconian rigor :P
For anyone looking to solve the problem I mentioned, reddit.com/r/workonline . Idk how reliable the pay will be; everyone fights over shekels like wolves
also @AndrasDeak sometimes that's what's needed in tech. Important to copy a quick code snippet and get on w/ my life; sometimes saves me 1 hr+ of debugging
@frank, I'd suggest doing good projects on your own..contributing to exiting projects and create a website...promote yourself on social media and you shall have a good chance...
it seems we're missing a duplicate for "how do I create numbered variables"
17:00
isnt that the same boat as creating variable names dynamically?
where the answer is, just use a dict?
@AnttiHaapala we do have a dynamical variables dupe
Any ergonomic advice for someone developing tendinitis? Personal experience advice if you have it
ergonomic keyboard and mouse
huh, thats a cool link
the very first post there is something i didn't know about.
Wife has a kinesis freestyle and she loves it. And there are plenty of simple and cheap ergonomic mice.
17:09
makes me wonder though. does tee create copies in memory of the entire list?
Thanks. I also think I need to use a laptop less and get with the separate monitor and mouse
@ParitoshSingh I think it consumes the items as they are first needed, but yes, then it has to store it in order to pass it around
@ChuckIvan Yeah, laptops are bad for that. I'd expect a non-erginomic mouse to be worse than a touchpad
prev = some_list[0]
for curr in some_list[1:]:
    #stuff using prev and curr value.
why would tee be preferred over that?
17:12
context?
I don't see any need for tee there
no context as such, just wondering based on sopython.com/canon/16/…
I prefer a desktop with a large monitor, a good mechanical keyboard with backlight(to code in the dark), and I just bought a gaming mouse that is so comfortable for long term use. I actually prefer keyboard use more than mouse. With Linux, you just need a keyboard anyway.
@ParitoshSingh that recipe seems like one that's applicable to generators
for a list you don't need that
@noɥʇʎԀʎzɐɹƆ: No, it doesn't work on every iterable and makes an unnecessary copy when used on lists. Using functions is pythonic. — Ry- ♦ Oct 24 '17 at 16:13
the copy is a good point
@ParitoshSingh, maybe a generator function that yields a value is more appropriate
you could skip a copy with it = iter(some_list); prev = next(it); for curr in it: ...
17:16
Hello everyone, I've a question about deploy of a gunicorn web server. I've read several articles but cannot explain myself a bottleneck I'm sticker with. Does anyone have some time to give me a hand? Is this a suitable place?
@MattiaGalati welcome. It's OK to ask as long as you're within the room rules. Nice pup ;)
@MattiaGalati, sure. What kind of app are you deploying on gunicorn? Is it Flask..?
alright cool. yeah, im not seeing any benefits of using tee and *moving away from the way i prefer iterating through lists when i need to use prev and curr values.
thanks for the sanity check
the answers there are good but I'd have posted them on a different question
@amanb Would I be wrong that you use emacs? I need to get a separate monitor and an ergonomic mouse at the least
17:21
monitor won't help with your tendinitis assuming it's in your wrist
@Chuck, I use vim, but I want to try emacs
@AndrasDeak ooh. this is nifty. thanks! issue being slicing creates a copy right?
@AndrasDeak Thanks
@ParitoshSingh for lists and tuples, yes
Actually a medical professional told me the tendons in your wrist connect to your shoulder and scapula. I've felt this when I stretch my shoulder and get a tingling feeling down my arm. So the idea would be I don't crane my neck downwards, which messes up something in my neck and shoulder, and then indirectly wrist. In layman's terms
17:23
(things like numpy arrays return views that use the original memory)
sweet, thanks a ton
But at that point it might be called something other than tendinitis
@ChuckIvan Hmm. Could be. I knew that if your tendinitis is messed up enough it can cause pain up to your neck. I don't know about the problem going the other way around.
Anyways this is good advice. Obvious but I wanted to hear it from people who code
I guess it's kind of like an undirected graph :P
graph of pain
My stack is NGINX in front of Gunicorn which start a Flask application. I've configured Gunicorn with 5 sync workers, since my server at the moment has 2 cores.
A typical flask request does this task: 1) collect user data and validates it, 2) does some simple math like calculating sums, 3) produce a PNG file (a receipt) and stores it on a remote bucket (GCS), 4) Store data to a remote RDBMS 5) Store relevant data to a no SQL DB.
In my server there are also much simpler tasks, like retrieve data from RDBMS and send them to users. During heavy load, my stack receive approx 8000k requests per hour (3 or 4 requests per sec) and the tasks of retrieving SQL data, which spends 1 or 2 seconds only to complete the query, are queued and started only after 10 or 15 seconds, causing a bottleneck which I really don't know how to handle.
Spinning up some threads (gthread) per worker helps a little, but does not resolve. Only thing that has a relevant effect is to increase the workers, but this is considered an antipattern from G
17:32
@ChuckIvan, I just couldn't stand using a mouse to move around GUI's so frequently when most of the time I'm using a keyboard to code. I stepped into Open Source Unix recently just because it is the best env to code and has tons of shortcuts and hacks for keyboard use. Before, this I was a Windows user and had a shoulder & back pain due to a bad computer chair. So, I changed that too :)
@amanb Thanks. I also need to get with the keyboard shortcuts
Less strokes = more hopes
Also you might benefit from dvorak/colemak if you're on qwerty
I've been thinking about that too. qwerty is a sore spot in computing history that I might be paying for
Thanks all
@MattiaGalati, the Gunicorn docs say: "Gunicorn should only need 4-12 worker processes to handle hundreds or thousands of requests per second." Have you tweaked in this range?
Also, I'd suggest using asyncio workers. Gunicorn has support for these : http://docs.gunicorn.org/en/stable/design.html#asyncio-workers
I think the best config would be to use a docker container. Although, it has a steep learning curve but once setup, it's worth the effort.
At the moment, when the web server hit the maximum load, starting 12 workers mitigates the problem. I have to run up to 30 workers to reduce the response time to the effective amount needed by python ho handle it, avoiding queuing requests.
At this point I don't know if I'm facing a design problem of my application (ie, a different workflow to manage the data sended to external APIS) or it's time to horizontal scaling my application.
@amanb with "asyncio" you mean workers like gevent or eventlet? I'm aasking because I've tried it (without changing my application, but only gunicorn config) but without better performance...
17:51
I think the problem with your app could be the request/response management. You should wait your current threads at the right time till the previous request completes. asyncio does not affect performance as much as helping with asynchronous thread handling. asyncio is a separate library https://docs.python.org/3/library/asyncio.html.
You should also do some sort of profiling for your code to see what is taking too much time.
There are also Async Workers available based on Greenlets: docs.gunicorn.org/en/stable/design.html#async-workers
@amanb Just to better understand: if I want to use AsyncIO or Greenlets, I must change my code or I can test the existing one? Sorry, I don't know much of them.
You can use either of them in your existing code. But you should learn how to use them. I worked with asyncio to fix a similar problem with a script that used to make 10000 requests per second. That's not too many but the script used to error out every so often due to request/response clogging and used to take 15-20 mins. With asyncio, my code never errors out and the performance improved by 5 minutes, no much though.
i.e. you have to change your code to use it.
I think you should profile your code first..that's where I started and surprisingly got this advice right here in this chat :)
a few months ago
@amanb Many thanks for your advices, I will profile and retry the config.
Thanks to all, this community is priceless
18:05
@MattiaGalati, use cProfile: https://docs.python.org/3/library/profile.html#module-cProfile
That's what I used.
Happy to help:)
18:37
hey guys
cbg, Andy
@AndrasDeak hi Andras, long time no talk
happy new year btw
thanks, you too
@AndrasDeak cheers
I'm missing the code
cbg everyone :)
cbg @AndyK
18:42
@amanb \o
debugging and developping, learnt a lot and yet, I felt like I learnt not much
on another topic, Michel Legrand passed away yesterday. I'm fond of his music especially that one
19:07
cbg
I can see that on Wikipédia Français
@ChuckIvan hey
That's where I get what little news I read from. And my assuming he's French worked out. Sorry to hear
English featured article is about a mushroom, France's about a terrorist. Can't beat Wikipedia
but I think for my generation, that was that one and that one where he struck big, spawning a wide interest in Sciences.
I would click but I added Youtube to /etc/hosts blacklist :( Maybe I will comment it out so I can have a listen...
why did you do that?
19:18
@ChuckIvan unlucky
Because I have no self control over these things
I find YouTube highly addictive
just open nyan cat on 10 hour repeat and you won't feel the need to click
:)))
19:20
@ChuckIvan aha
Speaking of French-anime-with-space-theme I should watch Daft Punk's Interstella 5555
I can't get that song from Aha! "Take on me" out of my head..its such a stress buster and my gf likes it too. the video is great too
Or 10 hours of nyan cat...hmmm...
I usually have the 80's or 90's playlist playing on Youtube while I work.
@ChuckIvan that one is so great
last time I watched it was 5 years ago
19:24
@AndyK The album is a classic imo but I've never seen the videos
@ChuckIvan big classic
if you have time, go for it
Will do
got to go back to my learning. Catch u later
20:06
hmm anyone got any idea why I couldn't update pip (using python -m pip install upgrade pip) from pycharm's terminal window? It errored out and after rebooting it said "already latest version", while "pip --version" showed it was an outdated version.
I "fixed" it by calling the upgrade command from another command prompt. (on window, within a virtual environment btw).
20:22
@amanb Good suggestion. I'm working on a startup right now; just looking for temporary, flexible income, ideally that leverages my skills and teaches me new stuff!
 
1 hour later…
21:46
@AndrasDeak I am afraid some RO is abusing their powers. I've kept quiet until now but it's become a little too much. This chat message of mine, I clearly remember seeing it starred before my very eyes. It was starred for at least a few hours, and then it was removed, so it had to have been done by an RO. Now, obviously it was just a star. My question is why an RO felt the need to remove it from the starboard.
could have been starred by a bot/other used that got banned later on, or deleted their account, too
😱
I don't think stars get preserved in that scenario
This is not the first time I've seen that happening
or that person could have unstarred it (not a few hours later, but maybe you got the timing wrong)
also, while it is confusing and possibly a bit rude, I wouldn't consider that abuse, or a considerable form of abuse
but I also don't know what happened, so I'm out
21:49
@vaultah you're doing a great job as an RO at making other users feel welcome, thank you.
Thanks for the positive feedback!
So, I'm afraid ROs have no way of seeing who star or unstar messages. To the best of my knowledge, of course
@vaultah I think it's alt+f4
Ooh, totally tricked me there
can't tell if being sarcastic
I'm not pointing fingers at anyone, but you can understand that behaviour like that does not do a great job of making users feel included or welcome here, regardless of how trivial you think the action was, can't you?
PSA: I am all for removing stars from comments that are not in line with the mood/rules of the room. But please at least let the user know if there is a problem with the comment. And please don't remove a comment from the starboard unless you actually have a valid issue with it. I can't believe I have to say this, because I thought it was obvious.
22:04
@coldspeed it's been said plenty of times that we regularly unstar things. It's not abuse, it's use. The fact that it was removed doesn't mean anything was wrong with it per se. It might have just been not popular+entertaining enough. I've been cancelling stars all week, salutations and smileys have been getting stars for no good reason. We curate the starboard to make important and entertaining things more visible. It's not about you.
We also have no way of verifying that a particular message (like that message of yours) was even starred in the first place
I think I saw that one get starred a while back
But this is anecdotal
Kevin is the only one among us who needs stars for sustenance, so nobody else should get attached to chat messages.
Not that it matters but I often clear fresh stars on my own messages when I find them needless
22:25
@AndrasDeak I can understand where you're coming from. Although, the message in question was not a smiley, or a salutation either. Plus, the message was not given enough time to be on the starboard to determine whether it was popular or entertaining enough, so I can't really buy that argument either. I understand ROs try to remove fluff from the starboard but please be cognizant of where to draw the line? That's all I ask.
@coldspeed and I understand you. You rarely post things that people star. And now one such message was unstarred. I completely understand why you're frustrated. What I'm saying is that this happens all the time, and it's nothing personal
I'll pass on your grievances
22:53
rhubarb
rhubarb?
@AndrasDeak thank you, you really do understand. But "it happens all the time" is not always an excuse to let it keep happening. Ill drop this issue for now, but if it happens again, I'm going to have a hard time keeping quiet about it...
@roganjosh peas
I don't know an appropriate response in Salad
23:07
I think a sprout is due
I'm not sprouts for linking the resource :P
or did you mean you're mushroom about a banana response in Salad?
I'm done
Banana
I'd have expected sopython's language to be Soup
I better porridge, ttyl
23:42
How do you make async requests?
106
Q: Asynchronous Requests with Python requests

trbckI tried the sample provided within the documentation of the requests library for python: http://docs.python-requests.org/en/latest/user/advanced/#asynchronous-requests with async.map(rs) I get the response codes but I want to get the content of each page requested. out = async.map(rs) print o...

doesnt seem to work
Don't use grequests, use requests-futures
@roganjosh want to update that answer?
Update how?
edit it. Current information is out of date.
stackoverflow.com/questions/40872671/… is my experience with grequests.
23:48
ok
also how do I do an entire async function
I have nothing to edit, the library is just unpredictable from my experience
prepend async?
async def?
No, you don't need that with requests-futures
Supply it a list of URLs and it will send async requests for you
But what if I dont want the request to be async but an entire function
If that's not what you need, you need to clarify
23:50
scratch the idea of async requests
I just have a method that I want to run asynchronously
How do I do that?
async with Python is something I haven't used so I'll back out
ok
thanks for help

« first day (3025 days earlier)      last day (2147 days later) »