« first day (2888 days earlier)      last day (2053 days later) » 

abc
12:01 AM
Is this true? stackoverflow.com/a/52285599/1359058 I mean, if map() should not be used to apply the same method to a list of elements and list comprehensions should be preferred, when map() should it be uses? (Please note that it's not a question for talking about the other user or to whine or whatever, it's just for me to understand)
 
@abc: map should be used rarely. If list comprehensions had existed when the patch to add map was submitted way back in the day, map probably wouldn't have gone in.
Mostly, if you already have a predefined function that you want to map over an iterable, and you don't need a list, map is okay. For example, map(str, whatever).
 
abc
I see, thanks for the clarification
 
wim
1:06 AM
@Aran-Fey There were/are several things incorrect with it. The one that really sticks out the most to me is this: When not to use super / There are two cases in which I would recommend avoiding super: When your class inherits directly from object
In many cases, you should call super even if you inherit directly from object, otherwise it indicates you want to abort all other initializers. To give one example, the Mixin pattern (which the question explicitly mentioned but your answer didn't address at all), crucially relies on this - should a mixin which requires some initialization of the instance neglect to call super, then a sibling class (the one "mixed in with") won't get initialized.
 
Hello. Does anybody could help me with pandas?
Given a key, how to print only columns from 1 to 10 such that values are positive?
 
wim
1:52 AM
@Aran-Fey This may be more subtle than you're realizing. See the footnote 2 in my answer.
@Aran-Fey If a class and something else in the hierarchy defines a method foo, then super().foo is a bound method. Something like <bound method OtherClass.foo of <__main__.ThisClass object at 0xcafef00d>>. You can't know from within ThisClass which OtherClass that foo is bound too, because it's super's job to decide where to proxy that.
 
Trying to support complex multiple inheritance hierarchies always feels so pointless to me. Anything more complex than a no-initializer mixin seems like poor code structure, and mixins have always seemed like a poor tool for the job they perform.
It's like trying to support sawing off your foot and replacing it with a machine gun.
Maybe it's cool, maybe you've developed some really neat technology for it, but it doesn't seem like your life will actually be any better if you do it.
 
wim
2:07 AM
I think there's a Tarantino movie like that
 
 
2 hours later…
4:03 AM
hello guys...
like i have a large set of data lets say more than 200 rows and data are mainly simple nos within range of 1 to 100 and i have 2 columns basically.....which method would be best in python to compute or find a function which actually represents the data...
 
4:42 AM
@gadia-aayush first, you need to define more clearly what you mean by "a function which represents the data". Do you want a linear fit? Or a quadratic? Or a higher order polynomial? Or something else?
 
5:16 AM
@Code-Apprentice any function which actually like satisfies the data points
i have been thinking of interpolation like lagrange's or newton divided difference
 
 
1 hour later…
6:45 AM
Hello Anyone onlie to help
C:\Users\Admin\.PyCharmCE2018.1\config\scratches\shippednew\shippednew>scrapy cr
awl sachin
2018-09-12 12:06:31 [scrapy.utils.log] INFO: Scrapy 1.5.1 started (bot: shippedn
ew)
2018-09-12 12:06:31 [scrapy.utils.log] INFO: Versions: lxml 4.2.4.0, libxml2 2.9
.5, cssselect 1.0.3, parsel 1.5.0, w3lib 1.19.0, Twisted 18.7.0, Python 3.7.0 (v
3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)], pyOpenSSL
18.0.0 (OpenSSL 1.1.0h 27 Mar 2018), cryptography 2.3, Platform Windows-7-6.1.7
getting this error while trying to execute scrapy crawl sachin
 
7:05 AM
@wim Oops. I must've messed that up somewhere along the way; I initially had that phrased like "if you inherit directly from object, you are not obligated to call super. But it's not wrong to do so if you're designing your class for cooperative inheritance". If I fix that, are there any other problems with the answer?
 
@gadia-aayush When you say "any function which actually like satisfies the data points" you mean "exact interpolating polynomial", but for n=100 arbitrary datapoints that could have degree up to 99(!). Depends do you have any hypothesis about the order of the interpolating function, or conversely how much approximation error you can accept? What sort of data is it (sales? web views? genomics?), where did it come from, what is its underlying distribution?
 
 
1 hour later…
8:25 AM
cbg-ning
 
@gadia-aayush the first question is what you plan to do with the function afterwards. Odds are you're in an XY problem. (cc. @smci)
High-order interpolating polynomials are rarely the solution. Splines maybe.
 
9:22 AM
@smci @AndrasDeak...well, you pointed the correct glitch in interpolation, so i am thinking of applying least square regression after doing a bit of research.....
because the relationship is bound to be quadratic based on the data and from the source and their scientific principles which is obeys...
 
9:44 AM
Yup, sounds good. scipy.optimize has a few tools for fitting
perhaps there are more pandas-centric solutions
 
Hi guys. I am trying to make an auto-retry for an elasticsearch-scraper based on this answer: stackoverflow.com/a/23961254/4125622
But my script still fails without any retries or warnings:
def scroll_with_retry(sid, scroll):
    sleep_time = 2
    num_retries = 7
    result = None
    str_error = None
    for x in range(0, num_retries):
        if x > 0:
            print("Retry no {}".format(x))
        try:
            result = es.scroll(scroll_id=sid, scroll=scroll)
        except Exception as str_error:
            pass
        if str_error:
            sleep(sleep_time)
            sleep_time *= 2  # backoff (increasing wait period until no error)
        else:
            break
Do you have any idea why? Here is the beginning of the error

GET http://10.10.40.5:9200/_search/scroll?scroll=2m [status:N/A request:10.004s]
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1321
 
10:06 AM
Ok nevermind, works now :)
I used a while loop with no error-message assignment
 
are pip-tools any good?!
 
10:30 AM
Is there something more modern than this: stackoverflow.com/questions/972/… We need a dupe target for stackoverflow.com/questions/52292599/… but that old question is ancient, and it's not obvious which parts are relevant to new-style classes, let alone Python 3.
 
any chance to edit it in shape, or is it too popular for that?
 
10:43 AM
@Arne Well Aaron's answer is pretty modern, and fairly version-agnostic. I just left him a comment asking him to add some version info to it.
 
@PM2Ring I'm pretty sure the only thing that needs to be updated for python 3 in the accepted answer is the types.MethodType thing
Not even that, actually
 
I'd prefer if the accepted answer doesn't get changed much. People are still using Python 2. ;) Many of those REPL examples will print slightly different info in Python 3. It would be good to have an answer that makes it clear how method binding is a little different in Python 3. But I'm not totally clear on all the subtleties myself. :) It's a shame Martijn just wrote a comment or 2, and not a full answer.
 
11:00 AM
Hello guys I have a question about an implementation I want to make.
I have a function that takes a dict, that comes from a json_file. In this function, I have set a decorator that checks the values of my dict, such as : Is there a directory that exists, if no, create it, etc...
In some cases, I can change the values passed into my function, examples : I have a path that should be a directory, but the user forgot the ending / so I thought about correcting the mistake, and add a logging.debug() message to notify the change.
Now, in order to send a dict to my function, I need to load the json_file. And If I make changes to it, I need to dump the new version after my function has finished its work. It sounds like a good job for decorator ! Checking things before, loading them after.
So I thought about passing the json_path to my function, and the decorator would translate the json_path to a dict, and pass it to the function.
But that makes the decorator mandatory for the function to run, and it could be really messing with the brain of the one who read the code in some months, don't you think ?
 
@Aran-Fey Feel free to hammer it if you want. I guess it's unlikely for a more modern target to exist, and if it does, it probably got hammered with that one anyway.
 
I think I will just raise an error if I detect a typo error, and let the user change the json_file himself.
 
@IMCoins Yes, it does sound like it could get a little messy. And you also get the inefficiency of a double function call.
But it could be ok if there's a very clear separation of duty between what the decorator does and what the original function does.
 
So, how is everyone doing ? I've been kind of busy for the past few months. :/
 
hello there,
while reading this: https://docs.python.org/3/library/logging.html#logging.Logger.exception
it says I should do `logger.exception()` inside `except:` block. But what if I want to log exception after checking some condition. For this I always have to explicitly raise `exception` and then wrap it in `try-except` and then do `logger.exception()` in `except` block?
 
11:14 AM
Why can't you check the condition inside the except block?
 
I have plain code without any exception handling.
Say I check input. If it follows certain condition I want to log exception. So there was no `except` block earlier. I have to introduce one just for logging exception?

I want this:
if not input:
     #log exception
Should I do this:
if not input:
    try:
        raise Exception("No input provided")
    except:
        logger.exception()
 
Ah, I see now
 
whats the standard / preferred way?
 
I think you're supposed to use logging.error instead
 
with exec_info=True ?
if I want to have stack trace?
You seem to be right
 
11:20 AM
You don't have an exception, so you shouldn't pass any exception info. If you want information about the call stack, pass stack_info=True
 
ohhhhh!!!!!
 
Disclaimer: I've never logged anything in my life, and all the knowledge I have has been acquired in the last 2 minutes glancing at the logging module docs
 
lolz
but u still make sensible points
thats fine I always do new things first time in production xD
so stack_info is same a exc_info when there is an exception?
 
no idea, sorry
 
11:55 AM
Ok I'm kind of stuck with an error that occurs only after running something for a long long time.
2018-09-11 22:59:27.388548: finished run 44812; time: 9.392591s, total time 109533.292327s; 50 tasks done this run
handling tasklist, length: 48
2018-09-11 22:59:28.532167 start chunk
Traceback (most recent call last):
  File "C:\GIT\p_0320_bp\backend\BackgroundServer\venv\lib\site-packages\gevent\_ssl3.py", line 545, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:841)
As you can see from the first line this is during the 44813th repetition of said operation. Is such an error a "common fluke that I can expect" or does the `ssl.SLLWantReadError` mean there are bigger problems under the hood? (The most annoying part is that there is no stacktrace, so I do not know which actual query to a server causes this problem).
 
You might want to implement a logging system, so that you will know what happens. And why. :p
 
what is the point about "i am no robot" captchas?
 
If there is only one test, it is just testing if you are a robot.
If there are two tests or more, the first is to assert that you are a human. The rest is used to train some Machine Learning algorithm.
 
@IMCoins I have a logging system: it's just that this happens and then "during exception handling (logging) of this: memoryerror".. which is also weird..
 
12:07 PM
since on our production server the problem is not a memory error (memory stays stable at roughly 150 MB), but rather "some" infinite operation (logging, as well as productive behaviour just stops at some point yet the python process keeps happily "running" - at 150 MB)
 
The thread I have sent you talks about a supposed too large packet to handle. Hence the memory error ?
I'm just making random predictions.
 
@IMCoins I think the memory error happens due to debug run (since it does not happen on production server), or can it be from logging to console window?
 
I don't think there's a limited buffer for stdout, but I can be wrong.
 
But still, why after so many actually equal calls to a server...
If you would like to put a quick look, this is the full stack trace: pastebin.com/sfurmsWJ
 
12:25 PM
I honestly don't know though I have read it all twice.
I imagine there must be a huge loop you're not seeing in the stack trace unfortunately;
 
12:41 PM
what is the advantage of docstrings over comments in the sourcecode?
 
@Null formalizing it, and thus tools can pick up on those.
 
@Null Docstrings get compiled into the bytecode, which makes them easy to access. The help function wouldn't be able to work on compiled code otherwise, unless it also had access to the source, and even then it'd have to parse the source looking for comments, and that would be inefficient.
 
12:57 PM
should i docstring every function in programs above a certain size?
 
And docstrings let you do stuff like doctests, although I must admit I rarely create doctests.
@Null It's a good idea to give every function a docstring unless it's totally obvious from the function name what it does and what its args are for.
And of course every class should have a docstring.
 
Puzzle time! Delete a variable without using del or globals
x = 5

... # your code here (not limited to 1 line)

print(x)  # make this throw a NameError without using `del` or `globals`
 
Lots of code on SO doesn't have docstrings because its just simple example code, not production quality. And the accompanying text often explains what's going on. But maybe that gives newbies the wrong idea that docstrings aren't needed.
 
Closing another loophole: Redefining print doesn't count.
 
@Aran-Fey Beats me. Assuming redefining print is cheating. ;)
 
1:07 PM
I think programming should be a passion. And therefore, a good developer will have the curiosity to seek how to make good comments on its own.
 
Writing good comments is hard, but not as hard as naming things. But you get better at both with practice, and by reading good code.
 
Can we redefine x ?
 
that was my first thought
 
What would that accomplish, though?
 
@IMCoins Yes, but I'm not sure how that'll help you
 
1:11 PM
It's not like you can do x = undefined
 
Hint/Warning: The solution doesn't work in python 2. Not 100% sure if it works in all versions of python 3
 
	x = 5

	class f():
		def __repr__(self):
			raise NameError()

	x = f()
	print x
 
@IMCoins Hah, nice. Not what I had in mind though :)
The correct solution really deletes the variable.
 
You asked for a NameError. But you can still correct your question though haha.
But I don't have Python3+ installed on this machine, so...
 
1:16 PM
Spoiler: solution
 
Yeah, I tried this solution haha
I tried defining the error in x, doing x = NameError, but it didn't execute the error, just assigned x as the function call.
That's a nice trick though. And it also could be a good beginner example to explain how variable assignment works in these for/with/try/except blocks.
 
It's not very illustrative of how assignment works in for/with blocks, because this trick only works for the variable name used in the except clause
Variables created in ordinary blocks are accessible outside those blocks
>>> for i in range(10):
...     z = i*2
...
>>> z
18
 
pfft I traced the error back to gevent's internal monkey patched ssl3 validation.
in /sitepackages/gevent/_ssl3.py the following snippet:
def do_handshake(self):
    """Perform a TLS/SSL handshake."""
    self._check_connected()
    while True:
        try:
            self._sslobj.do_handshake()
            break
        except SSLWantReadError:
            if self.timeout == 0.0:
                raise
            self._wait(self._read_event, timeout_exc=_SSLErrorHandshakeTimeout)
        except SSLWantWriteError:
            if self.timeout == 0.0:
                raise
            self._wait(self._write_event, timeout_exc=_SSLErrorHandshakeTimeout)
if I add raise SSLWantReadError() in the while loop the same crash occurs after a while. -- However this is still strange because the serve shouldn't error constantly, especially since I know it won't error as I can still manually connect.
 
1:34 PM
\o cbg
oh Aran looks like you got the answer I wanted to give :D
 
A friendly reminder! 😉
 
^^ flagged 2 (not needed) comments there and CVed.
 
1:49 PM
That OP seems to be having a bad day :\
 
seems like it, but that doesn't help his cause.
they edited their question. It seems better now, but not sure if I still understand it completely, given that I lack Rails knowledge.
 
is there a special name for a list that is ordered other than "ordered list"?
 
sorted list? :-p
 
hmm what is the best approach if I accentally worked in the wrong git branch?
 
do you want your changes in another branch ? are the two branches the same version? can you just cherry pick the commits you want from the wrong branch to a new branch ?
 
1:55 PM
[off-topic] If you haven't committed anything, you may simply try moving to the other branch.
 
I have not pushed the branch itself, but a lot of work is already being done inside it, can I move "merge changes done by me after commit xyz but ignore all changes before commit xyz"?
 
In that case, cherry picking would be better.
 
DSM
Midweek cabbage for all.
 
recbg
 
DSM
1:57 PM
@shad0w_wa1k3r: in common usage "ordered" is different from sorted. Consider an OrderedDict, for example.
 
sorted as initial :-p
but yeah, two are quite different smacks head, slowly
 
"Flask is not Rails. Send comfort." Why am I getting sucked into this comment discussion?
 
May not be my place, but you should just avoid some predictable outcome discussions at times. It's quite healthy :)
OP isn't clear anyway about most of the requirements, and like you said, sounds like a rant more than a cry for help.
 
I usually do.
 
2:10 PM
@Null If you have a list where the positions have special meaning, eg [latitude, longitude, altitude]. then maybe you should be using a tuple instead. Although a tuple is immutable, and you might not want that.
 
All gifs should be perfectly looped, then you can have some of them as "white noise", but might still get a little annoying later on. Sounds are better.
 
But in any case, the name for such a thing is "heterogeneous list".
 
DSM
Hmm. I tend to think of heterogeneous in terms of type, not semantically, but I guess it works for both.
 
@shad0w_wa1k3r if anyone wanted an HD source - reddit.com/r/aww/comments/9eo51b/just_enjoying_his_life
 
>>> x = 42
>>> import ctypes
>>> refcnt = ctypes.c_long.from_address(id(x))
>>> refcnt.value = -1
>>> x
42
free(): invalid size
Aborted
@Aran-Fey ^ so close...
 
2:26 PM
Nice try
 
Of course I should've realized that it won't work, because it's the name we need to kill and not the underlying object. Not a bad example of the separation of concepts though :)
 
2:43 PM
@gadia-aayush there are infinitely many functions which satisfy a finite set of (x, y) pairs.
 
Is the US really a third world country in regards to natural disaster management? As in: hardly any budget for prevention, building without taking disasters into account/not building everything disaster proof and the standard procedure with disaster is "evaction and cleanup afterwards"?
evacuation without a backup plan (like making sure electricity is back at full level within a day after a hurricane)
 
@paul23 eh, you always manage to ask these things in an off-putting way. Again I'm not sure this is the best place for this
 
That will possibly lead to a political discussion, which we usually avoid here.
 
ok
 
2:46 PM
thanks
 
It's just that I kind of like to always hear what the common civilian thinks about it: when one asks this in places that are "about politics" you gravitate to people who have already been discussing this for more time and have already formed strong opinions. The ones who are not into dicussing such things are missed and hence you do not get a good opinion of the population when asking on reddits/politics.se.
That's similar to me asking here "why would you use python over javascript"
 
still, bringing politics to a largely politics-free community usually won't help
 
@paul23 not entirely, no.
 
one could discuss politics here, but you're not exactly a regular here and whenever you ask you seem to be asking from on top a high horse, which makes it extra cringey
this is only to say that it's not explicitly forbidden to have constructive political debate here, it's just that would be hard to implement and I don't think you'd be able to nail it
 
The only way to get an answer on what is better between python and javascript is by asking outside viewers who are not inside a single topic (ie ask that question in a C# room).
 
2:51 PM
@paul23 I tend to believe that that question is as meaningful as "should I learn German or French?"
 
disagree, you want to ask it to people who've moderately used both. Not people who haven't used any of them.
 
Because in a python community people would like python more and say javascript is bad. The opposite in a javascript room. - Where you often actually see that people say something is good or bad for exactly the same reasons, only one party says it's good and one says it's bad.
@AndrasDeak Which I can answer with reasoning as I've learned both yet have no opinion on the matter (thus I'm not in a room about french or german).
 
okay?
 
Similar for politics you shouldn't ask people what system is better if they have a strong opinion on the matter. Rather the people without a strong opinion might give much more nuanced responses.
 
or you should start asking answerable questions
 
2:53 PM
^ :D
 
the SE mentallity :P
 
shocking
 
I don't think it has anything to do with a supposed "SE mentality" here.
 
Hi guys! I'm sure glad to be in the SE.Philosophy chatroom!! Question what is the sound of one person chatting?
 
-.- (that was just a small joke aobut the strict ruling on stackexchange it being a q&a site and not a discussion site)
 
2:58 PM
(given that you have audio notifications enabled)
 
But what if no one is there in the room? Does it make a sound?
 
Super helpful thx @shad0w_wa1k3r.
 
couldn't help it, sry :-p
 
@paul23 What? Most of us here have some JavaScript experience (although I freely admit my JS is pretty rusty). We might prefer Python as a language, but we use them for different things. If you want to write code for a Web page that runs client-side, you write JavaScript. If you want to write a small CLI utility, JS isn't a great choice, although I guess there are CLI dialects of ECMAscript.
 
I mean, people here would be opinionated, and hence even subconsciously you downplay advantages of js and to turn everything into a positive way about python. Similar in javascript they would say the exact same things but rather put stress on the advantages of js and say the positive things about python are actually negative.
 
3:04 PM
@PM2Ring there are no dialects of ecmascript, but systems for cli, which take a browser javascript engine for other uses...
none support threading because the browser doesn't support threading.
 
I would actually strongly disagree. Asking outsiders of group A and B is a very safe bet that you are getting uninformed opinions out of what those outsiders heard or experienced themselves.
If you truly want good reasoning on A or B, you should ask those that are very familiar with both.
 
Just the other day, someone came into the room of js and asked why [(1, 2), (3, 4)] return [2, 3] This followed by people confusingly asking "what the hell is (1,2). And then "why would you use tuples those are just limited arrays and make a language worse". Give me an example why one would use immutable lists.
Of course I can't resist such a thing and I went into an explanation of 4 hours trying to "convince" people.
 
well, unfortunately lots of people think that a tuple is an immutable list.
 
@AnttiHaapala To put it frankly: from a higher level point of view it is an immutable sequence - what else?
 
your mistake was caring about what people in the JS room thought about python
 
3:07 PM
I always care.
 
Similarly, you shouldn't care what we think about JS.
 
@paul23 that's the problem, Python tuples do provide the sequence interfaces, but it is not a sequence of things.
 
But I do: because I believe that we can learn a lot by noticing why and how others think about things you do. It gives you the possibility of noticing new ideas you haven't thought about yourself. The only opinion I don't care about is my own.
 
how to put it into words... a tuple is an element from cartesian product of domains
 
I’m confused what you are actually trying to say
 
3:10 PM
heck I spent a lot lot of time reading blog posts or large newspaper opiniates (or how you call those things in english, when someone writes an a1 piece about his opinion on a matter).
 
@Antti *rolls eyes*
 
@poke it started as an analog for political debate...
scope creep
 
Meh I just like hearing people's opinion on everything, especially their natural opinion before they have thought about it for a long time.
 
@Andras Yeah, I know and since it has shifted from one topic/example to another without any coherent story
 
I always have fun when foreigners tell how good or yammed up Finnish politics are, I guess the feeling is mutual when I tell them what I think about their country.
anyway, for tuples:
how cool would that be, to have {1, 2, 3} * {*'abc'} in Python =>
 
3:14 PM
Yes but does that "official" wording have any meaning for the rest of python?
 
@Antti I don’t consider that helpful. Sure, mathematically that’s correct, but you can apply that to any data type.
 
@paul23 well it doesn't, because silly people always consider tuples as immutable lists...
 
@paul23 Why are you quoting “official”? Who said something about “official”? I am confused. What wording? What meaning? What are you talking about? Is this still about tuples?
 
wow quora to rescue
 
Oh I quote words when I'm not sure about the correct translation into english, this is a literal translation but if I translate it back it isn't correct.
official not as in 'by a governmental body" but as in "due to a formal mathematical background".
 
3:16 PM
cbg
 
@paul23 would the javascript guys say that a namedtuple is useless :D if not, then they didn't understand what a tuple is about.
 
stackoverflow.com/questions/52298284/… too broad and OP just keeps re-stating the same issue over and over
 
quoting BDFL BDEVIL:
> Tuples are for heterogeneous data, list are for homogeneous data.
Tuples are *not* read-only lists.
 
Isn't that BDEVIL from that ancient april 1st thing, when FLUFL started? Or are people reusing it now that he's no longer BDFL?
 
That BDEVIL thing has really caught on eh. Sounds nice though (without any disrespect of course) :D
 
3:19 PM
@AnttiHaapala I personally dislike named tuples as I found everywhere they are used, using formal classes makes things easier, and only when you need both the sequence as well as names, named tupples have any merrit (but those situations I find rearranging code often easier).
 
@AndrasDeak it is
 
he's not the BDFL, so what else to call him, Guido?!
 
BexDFL
 
but then it's not life now :(
 
3:20 PM
Problem is: can we ever use the fact that lists are for homogeneous data?
 
although 572 vs B...
 
> But I'm basically giving myself a permanent vacation from being BDFL, and you all will be on your own.
Benevolent Dictator Emeritus Vacationing Indefinitely from the Language (BDEVIL).
fits
 
indefinite != permanent imo
 
wim
@Aran-Fey it should be reliable in all versions of python 3
IIRC the reason was they wanted to add the frame to __traceback__ on exception instance, without creating a circular reference, or something like that
 
wait can we now run for dictator?
 
3:24 PM
cabbage
 
When will the voting season start? Or do we go about it game of thrones style?
 
@poke who knows :D
 
wim
>>> x = 5
>>> import sys
>>> sys.modules[__name__].__dict__.pop('x')
5
>>> x
NameError: name 'x' is not defined
 
__import__('sys').modules[__name__].__delattr__('x')
 
3:28 PM
So many loopholes I didn't think of ._.
Next time I'll ban 2 consecutive underscores
 
DSM
Am I the only one who uses vars() rather than __dict__? All those dunders..
 
@AnttiHaapala I vaguely remember playing with a JS-like scripting language that ran in the command prompt of a Windows machine, 15 years or so ago. But my experience in coding on Microsoft machines is extremely limited. I tried to do it, but they always seemed so alien to me.
 
@wim that git post was awesome
@DSM vars can be a copy?
not sure
ah it works even with int, returning a mappingproxy
 
How did you find where the variables were stored WIM ?
I first looked out for this on Google, typing something like : how to access current stack python, but didn't find anything.
 
A question about atomic clocks on SE.Physics reminded me of this classic: leapsecond.com/pages/atomic-bill
 
DSM
3:38 PM
So my submission is vars().pop("x").
(inb4 hey, vars() is globals() outside a function, so that's cheating)
 
Can anyone help me regarding this Python question: stackoverflow.com/questions/52279699/…
 
DSM
@MiguelLambelho: I had a look at your question the other day but couldn't quite figure out what it is you were trying to do. In principle I could back it out from your code, but that was more work than I was willing to put in. :-)
 
wim
@AnttiHaapala yes, so many features!
good to see they are moving to SHA256 too
 
@DSM, I edited the question. I think now is a bit easier to understand. If you do not understand it yet... please tell me. This question is really important for me.
 
wim
3:44 PM
@IMCoins probably you should have googled "current module" or something instead, because that var lives in a module namespace
 
3:56 PM
@MiguelLambelho Is that a Pandas question?
 
@PM2Ring, yes. I use mostly pandas ( the for loop is a df.itertuples() )
It is mostly a performance issue. Because the code is built correctly. However, I think there must be a way to vectorize this problem. Unfortunately, I do not know how to do it.
 
@MiguelLambelho In that case, you should give it the tag so that Pandas experts are more likely to see it.
 
@PM2Ring, thank you for the advice. Just did that.
If some of you require any additional explanation. I am more than happy to provide it.
 
4:16 PM
Have you tried df[ df == your_value ] ?
 
Yes. Instead of using querys, I already tried to use:
vb = arr[(arr.Already_linked == 0) & (arr.hour < row.hour_aux) & (arr.Operator == row.Operator) & (arr.Terminal == row.Terminal)]
But is more or less the same
 
DSM
@MiguelLambelho: adding a description, in English (but complete), of what it is your code is supposed to do would be helpful. For example, comparing with (arr.hour < row.hour_aux) is a little unusual because it's date-independent. That could very well be what you want to do, but it's not what I'd have guessed. Etc.
 
Thank you for the advice. Will edit the question right away.
 
DSM
Take your time, and imagine you were hiring a programmer to write it in a language you don't speak and so whose code you can't check. What would he need to know?
 
Ok. @DSM, will follow your advice.
 
4:35 PM
I've got to go, but at first glance
You can get rid of the for loop with itertuples using the same logic of arr.
Doing another_arr = c[ c.A_D == "D" & c.Already_Linked == 0 ]
approximately, I did it by memory without testing
 
@IMCoins AND @DSM, I just updated the question. I think now it is more clear.
@IMCoins, I can not do another_arr = c[ c.A_D == "D" & c.Already_Linked == 0 ], beacuse the value in Already_linked may be updated in each iteration.
 
DSM
4:54 PM
@MiguelLambelho: your update amounts to "here is a dataframe, it changes, some columns are allocated (?) and some are updated". Say you were asking someone to do this *on paper*, with no dataframes or loops involved, just a table in a notebook. What would you ask them to do?

I'm expecting an answer like "First, look only at operator D. For any flight assigned to this operator, if there's another flight in the same terminal which starts before, add the first such flight's FlightID to a new column called 'a'".
 
wim
puzzle
hijack context manager exit
>>> class CM:
...     def __enter__(self):
...         return self
...     def __exit__(self, *args):
...         print('hello world')
...
>>> with CM() as cm:
...     ...
...     # your code
...
goodbye world
no patching out print or any lame hack like that
 
@DSM, will updated again. I am sorry, will do my best.
 
DSM
@MiguelLambelho: you don't have to apologize, but again, take your time, even if it means stepping away from the problem for a few hours. You might be too close to it right now.
 
5:08 PM
@wim Probably not what you had in mind, but... spoiler
 
wim
5:21 PM
@Aran-Fey that is exactly what I had in mind, but now the hard mode
 
@DSM why did you have to complicate it?! Now I am obligated to think )-:
 
Uh-oh... does hard mode include del CM.__exit__?
 
wim
yes :D
delete __exit__ from within context so that you cause AttributeError: __exit__ some kind of crash
 
Apple Watch Series 4 now takes an ECG... apple.com/apple-events/september-2018
 
@wim Like that?
 
DSM
5:31 PM
@piRSquared: I wasn't trying to, but I don't see your code as doing what OP is after. OP obviously feels differently. :shrug:
 
wim
@Aran-Fey hmm, that still replacing the code
 
Hmm, well then I'm out of ideas
 
@DSM, I did my absolute best. I explained everything that was in my mind when building the code. Hope it is a lot more clear know: stackoverflow.com/questions/52279699/…
now*
 
@DSM I'm thoroughly confused by what OP wants. I'd delete my answer if it wasn't accepted
Trying anyway... I flagged it asking for it to be deleted
 
5:47 PM
pfft I"m about to throw my towel in the ring
and go for the cannon to shoot a fly solution.
 
^ booyah! Neural Net to pick random.randint(1, 6)
 
wut?
 
Cannon <- Neural Net Modelling solution
Fly <- pick a random number from 1 to 6
 
6:17 PM
I have received two useful answers, however I still have the same problem. If any of you might help me, I would really appreciate it
9
Q: Python - For loop millions of rows

Miguel LambelhoI have a dataframe c with lots of different columns. Also, arr is a dataframe that corresponds to a subset of c: arr = c[c['A_D'] == 'A']. The main idea of my code is to iterate over all rows in the c-dataframe and search for all the possible cases (in the arr dataframe) where some specific cond...

 
> Can you instal esisting pythong scripts like openchain.org ?
Freelancing is great and full of good clients
@MiguelLambelho huh?
 
I am sorry, but I am not understading what you are saying.
 
That was not in reference to your question.
 
Oh, ok.
Are you able to help me with my question? I have been stuck on this for a few days... But I really do not know what to do more
 
6:43 PM
@vaultah
 
I've seen you linking that question three times so far. If I were able and interested in helping I would have already done so. (as would others, meaning you probably shouldn't post it the fourth time)
@MiguelLambelho and you should revisit our room rules regarding pings. sopython.com/chatroom
 
Ok. I am sorry! Will do
 
was going to joke but trigger happy pinky ruined the surprise )-:
 
Question - What do you get if you run this:
vars()['__builtins__'].TypeError = type('Foo', (BaseException,), {
  '__init__': lambda *args, **kwargs: [print('foo') for _ in [0]]
})
raise TypeError
 
TypeError: __init__() should return None, not 'list'
 
6:57 PM
foo
Traceback (most recent call last):
  File "python", line 5, in <module>
TypeError: __init__() should return None, not 'list'
 
Sam
@davidism thanks for sharing this: github.com/davidism/basic_flask. Helped me out loads
 
alright, same as me. follow up question: why is it able to raise a proper TypeError?
(I only have an online repl right now, so I was actually unsure if that output is regular)
 
@Arne raise TypeError fails with a TypeError, because TypeError's new constructor returns a list
 
CPython takes a lot of shortcuts; apparently not looking up TypeError in the builtins module is one of them
 
The actual TypeError probably just comes from C, so __builtins__ is not considered at all
 
7:05 PM
so place your hack at a Cpython level
import hacker; hacker.doHack(now); #profit ?
 
so it's back to forbidden fruit, then. Too bad they never ported it to python >3.3
 
@Sam you're welcome. The patterns it uses are somewhat out of date though, you might want to compare it to the current tutorial in the docs.
 
Sam
7:29 PM
@davidism I seen your repo had been forked by a user named jappeace with an updated version. Not sure how that compares with the current. Where can I find the most up-to-date version?
 
Anyone's allowed to fork and do whatever they want. The only official version of my code is my code, I don't pay attention to what forks do.
 
Sam
Well, it was helpful anyways
 
@RobertGrant finally merged that PR
I dream of Click's 0 PR day. Then again, Flask's only lasted a couple months.
 
Sam
@davidism are you referring to the user guide in flask.pocoo.org/docs/1.0
 
wim
7:48 PM
BDFL spotted still benevolently dictating :) github.com/python/cpython/pull/9100
 
8:19 PM
@wim So what's the solution for the hard mode puzzle?
 
8:48 PM
hmm... I wonder why importing NumPy spawns a zillion threads.
 
9:01 PM
it does?
 
I decided to actually try running NumPy under gdb to get a better understanding of what's going on in NumPy's % implementation, and I noticed a ton of thread startup notifications when importing a pip-installed copy of NumPy. The threads seem to persist until interpreter shutdown.
 
oh, nevermind, threads don't appear in ps, I'm just tired
 
Might be starting up a thread pool for parallelized matrix operations
 
I wouldn't expect even threaded blas to use more than 4-8 threads
 
Importing a manual build doesn't show the same effect. I'm not sure how much of the difference is build settings and how much is compiler choice. Apparently the pip-installed one is using OpenBLAS and my manual build has no BLAS at all, looking at numpy.show_config().
It's a lot more than 8 threads. Not sure how many.
Looks like 55.
 
9:13 PM
how about OMP_NUM_THREADS=1 etc?
 
wim
I got 24 threads including the main (numpy 1.15.1 Python 3.7.0 / GCC 8.1.0 on linux)
 
Setting OMP_NUM_THREADS appears to control how many threads are spawned. I don't know why it's defaulting to such a high value, though.
 
Is that envvar available from inside after importing numpy? I wonder what its value is if it's actually set to a default
 
'{}'.format(foo)
Today I found this in my code...
Note: foo is a string already
 
heh
 
9:28 PM
I think this originally had other things in the format then got reduced to just this.
 
wim
9:51 PM
I suggest '{}'.format(f'{str("%s")%foo}') just to make sure
 
10:01 PM
Am I the only one who tends to notice how much I overuse features once I learn them?
And then when I return later I think "oh god, what is this mess".
 
Apparently 56 threads is just the number of threads the machine I was testing on can run simultaneously.
 
OMP_NUM_THREADS = inf
 
wim
@paul23 probably your colleagues notice too.. ;)
 
Luckily I only work for a year now, before that it was just study and past time projects as well as personal interest in learning new languages.
(I love learning about programming paradigms and how languages are created)
 
10:17 PM
cabbage
 

« first day (2888 days earlier)      last day (2053 days later) »