« first day (3550 days earlier)      last day (1381 days later) » 

4:00 AM
I was told to refer the "Zen of Python", and There should be one-- and preferably only one --obvious way to do it. makes me ask the question, Why are open() and close methods on file present if one can use the with statement?
stackoverflow.com/questions/11373502/… something that came across in my google search
 
4:33 AM
@AndrasDeak That's not what I said, and I'm not talking about python. It was a stupid templating language. if x or y worked exactly as you'd expect, but z = x or y always set z to true.
 
4:49 AM
@python_learner because with is simpler many times but not all times. When I build parsers or programs which need to perform async file operations: open and close within methods sometimes makes more sense than with (because there might be a long list of complex operations I will perform between opening the file and then appending to it or just closing it). Other times, using a with that just calls the functions within its block makes more sense.
The Zen of Python is a great guide but its just a guide - its never going to fit all situations perfectly
 
5:46 AM
@python_learner The with statement was introduced in Python 2.5. You still need to call the open method explicitly when you open a file in a with statement. But the context manager calls the file object's close method implicitly when you exit the with block. It couldn't call that method if it didn't exist. ;) Note that the Zen of Python says "Explicit is better than implicit", OTOH, it also says that "Practicality beats purity". :)
TIL, Tim Berners-Lee is a SO member.
 
 
2 hours later…
7:48 AM
@python_learner Note that having one obvious way does not preclude having other, non-obvious ways. If you want to scope a file to a block, the obvious way is with (since it represents a block). If you want to explicitly manage a file, the obvious way is close (since it is called explicitly).
It is also defined somewhat in contrast to languages with other culture. PERL comes to mind with Tim Toady.
Having less than five well-known ways is pretty close to having one obvious way, practically speaking.
 
8:39 AM
Phew, took a while but I was finally able to organize my pandas canonicals. I used the same topic arrangement as in the user manual, fits pretty good. Hopefully it becomes more useful as a resource/dupe target locator. cc @smci
If there's interest we should make a larger list of stack overflow dupe targets (not just ones written by me) organized in the same way, I'm sure it'd be super useful for closing dupes faster
 
8:58 AM
thanks for that info guys, didnt know these before
 
9:39 AM
Which protocols can be implemented with more than one dundermethod? I can think of 3, am I missing any?
1) bool: __bool__ or __len__
2) iter: __iter__ or __getitem__
3) !=: __ne__ or __eq__
 
__repr__ __str__ not exactly the same, but will they work?
 
good call
 
so __bool__ is called when __len__ is called or otherwise? I can only think of how #3 works havent played around much with these
 
@Aran-Fey might be an edge case, but instantiation: __new__ or __init__
@python_learner the "default" for __bool__ is __len__() > 0.
@Aran-Fey AFAIK augmented assignment falls back to the regular operators. e.g. +=: __iadd__ or __add__
Depending on the point you are trying to make, __hash__ is tied to __eq__ - defining only __eq__ disables hash.
There's also a.b: __getattr__ and __getattribute__. Though it's implied that the latter explicitly calls the former.
 
Oh wow, this list is getting pretty long
 
9:54 AM
@Aran-Fey OK, that makes a lot more sense. And ugh
 
All of __get__, __set__ and __delete__ magically mix together for the descriptor/data-descriptor stuff protocol thingy.
I still haven't figured out whether isinstance may use both __instancecheck__ and __subclasscheck__. AFIAK not, but need testing.
operator.length_hint can use both __len__ and __length_hint__
reversed uses either __reversed__ or __getitem__+__len__
 
Is mapping unique?
 
the in operator uses any of __contains__, __iter__ or __getitem__
 
> class.__instancecheck__(self, instance)
> Return true if *instance* should be considered a (direct or indirect) instance of *class*.
Blergh. This is like one of those "Tom has 3 apples. Mary steals one. How many apples does Bob have?" math problems. Thanks, python docs.
 
in principle, every operation that has reflected methods, such as __add__ and __radd__, can be implemented with either.
 
10:03 AM
Oh, that's a big one!
 
int, float, complex: __\1__ or __index__
okay, the number special methods have quite a few of these fallbacks...
EOFError: EOF when trying to find more special method fallbacks
 
What, did you write a script for this? O.o
 
Salad language lacks SYN, ACK, FIN and friends. :/
 
10:38 AM
@PM2Ring I wonder if it really is him? If we're moving towards a social-media type situation, it'd be nice if we could have verified accounts :)
 
lol... looks genuine :)
 
In that case, tis a shame it's a Go question and not Python :P
 
 
1 hour later…
12:15 PM
Hi guys, is there any tutorials that show how to limit panda pivot table output. right now when i index a catagory column, its showing multiple value columns when i only want 1
 
@msulol well, how are you using it, what do you get and what exactly do you want? Are you using pivot_table or pivot etc...?/
 
df.pivot_table(index="col1")
output has that as index, with multiple other cols (value columns )
basically, i am trying to do a basic value count in a pivot table at this time, i am trying to replicate this. df['col1'].value_counts(), but using Pivot_table
 
Err... pivot and value_counts aren't really synonymous though... if you were trying to do the equivalent of a groupby it'd make more sense...
 
12:32 PM
Please don't ask fresh questions from main, as per the room rules
 
df.groupby(["col1"]).count() seems to show count of all the other cols, is there anyway to limit the groupby to output only col1?
 
oh ok
 
@msulol if you only want the frequency of values for a single column - that's what value_counts() is for... I'm still not sure what you're trying to do here... if you don't want grouping then don't use pivot or gorupby
 
hi, i was hoping to get other colums of data added in as well but wanted the primary count of the original index. also anothr goal of mines is to slice the pivot table data (filter by date ranges), so i thought Pivot_table was best approach for output on excelsheet
 
@msulol you're going to have to come up with a [mcve] to clarify exactly what you're after... There's also a useful post on the site explaining how to ask good pandas related questions - it'd be worth having a look at: stackoverflow.com/questions/20109391/…
 
12:50 PM
how are typos on the help pages reported? the closed questions page duplicates the "Needs more focus" message for "Opinion-based" again.
 
@MisterMiyagi meh... that's not a mod editable page - so you'd have to post on it MSO and I can slap a status-review tag on it to push it into the staff's tracker thingy...
 
 
8 hours later…
8:48 PM
I don't understand why this question was treated so badly
-4
Q: How to remove a random watermark text from a picture

NukeXLCan I remove watermark.text from the picture and leave only the main text? sample picture

There is an answer to this question, and was able to answer it within minutes. The title might be slightly unspecific but overall the task was clear, and I was able to provide a good answer.
 
@NicolasGervais effortless question that needs a lot of work, and it has sketchy motivation. There's no reason not to treat it badly.
"learn how to do OCR" is not an answer to a good question
 
ok, what is this sorcery?
>>> class MyList(typing.List): pass
...
>>> MyList.__mro__
(<class '__main__.MyList'>, <class 'list'>, <class 'typing.Generic'>, <class 'object'>)
>>>
>>> types.resolve_bases((typing.List,))
(<class 'list'>, <class 'typing.Generic'>)
>>> type('MyList', _, {})
TypeError: Cannot inherit from plain Generic
How does that make any sense?
 
@cs95 Yeah I got a flurry of notifications. Lemme get back to you after my deadline next Wednesday.
 
@NicolasGervais if text is d['text'][i] == 'Watermark.text': looks wrong in more than one way. Chaining an is and a ==? And using is on strings?
 
@Aran-Fey you're right, i had another way before and forgot to remove it. another reason why i'm amazed that it ended up working
I changed it now
 
9:20 PM
In [832]: all([])
Out[832]: True

In [833]: any([])
Out[833]: False
tried to rationalize this but can't figure it out
all -- looks for the first falsy value otherwise returns True. any -- looks for the first truthy value, otherwise returns False
but that seems ... wrong
I'd imagine there should be some corner casing logic for empty containers
 
there aren't any truthy values in an empty list
 
@MisterMiyagi that's awesome, thanks for sharing. TIL - all([]) is vacuously true but any([]) is not
 
@cs95 all means "there's no element to the contrary". Any means "there is an element that qualifies". If there are no elements the former is true, the latter is not
 
@AndrasDeak got it! that's aptly summarizes it
 
9:35 PM
you can also rationalise these inductively. Starting with some container, removing those elements which does not decide the outcome obviously does not change the outcome. E.g. removing a True from all([..., True, True]) -> all([..., True]).
That means all([True, True]) -> all([True]) -> all([]) must have the same result.
 
9:52 PM
Sounds like a non-sequitur to me. You might as well argue that all([False, True True]) -> all([False, True]) -> all([False])
...you know what? Let's pretend I didn't say anything
 
10:33 PM
PSA: tonight there's a full moon with Jupiter and Saturn nearby. I could see 4, maybe 5 moons of Jupiter with a 10x pair of binoculars
 
10:53 PM
@AndrasDeak Wow that's really cool. I was wondering, what the two bright start next to the moon were. I wish I had a telescope. One day I'm gonna get one :)
 
@Hakaishin there's google sky map, an app which shows all the yam up there
 

« first day (3550 days earlier)      last day (1381 days later) »