« first day (3419 days earlier)      last day (1518 days later) » 

12:00 PM
I do a lot of web scraping contract work and while it's certainly possible - that's not a job I'd want to take on :)
 
Yes I am having knowledge in web scrapping I need a road map for my requirement to achieve
can you people just guide me
 
Best we can probably do is advise you learn css selectors and possibly xpaths... a little bit about how websites work regarding form submission and ajax stuff and then just persevere and try and scrape one site... learn from that and then try another...
 
yes I know css selectors I already worked on scrapping olx website
 
Open your browser's dev console, go to the "Network" tab, manually perform a search on the website, look at the HTTP request your browser sent, then write code that sends similar requests
 
what I didnt get you @Aran-Fey
 
12:06 PM
Visit directory.apps.upenn.edu/directory/jsp/fast.do. Press Ctrl+Shift+K. Go to "Network". Enter a name and an organisation. Press "search". Look at the HTTP request that shows up in the browser console.
 
Hi all, I am fairly new to coding. I am investigating on Rutger's Python simulation of the Ising Model. They use weave in their code which is not supported in scipy nowadays. How do I manage to run the code? Detailed question here: https://stackoverflow.com/questions/60339957/alternative-for-weave-in-ising-model
I tried to change the environment to Python 2, but that didn't help. Thanks!
 
For example I am having file with names like a,b,c and I want to scrap emails for a,b,c from this directory udapps.nss.udel.edu/directory/search how can I write a script can you people show me any example if you dont mind
 
@codinggirl weave is standalone now: pypi.org/project/weave
 
@Aran-Fey there are many http requests
 
Find the POST request
 
12:14 PM
How can I find Post request can you guide me @Aran-Fey
 
No, I can't teach you web scraping, sorry
 
@codinggirl python 2 is never the answer!
 
@Aran-Fey ok
but really here I cant find post request thats why I asked
 
@AndrasDeak What major version of Python originally released in October 2000 and had its final release in Dec 2016 should one ideally not be using these days?
 
I'll take "trivialities in modern programming" for $500, Jerry
 
12:24 PM
@amcgregor Yeah, it's not guaranteed to return a class that can be instantiated. I don't think there's a way around (manually) creating a mapping of abstract types to concrete types. It's not even possible to detect "abstract" classes reliably, much less find a concrete type that matches a given abstract class.
 
@Aran-Fey Yes I finded the post url please guide me
I had the post url now what should I do
 
What Aran has already mentioned you do... reproduce that request in Python... you know how to make get/post requests already, right? So - you use what you know there to reproduce the request you've found the browser making
 
Take a look at the url, the headers, the parameters, etc and the response the server sent. Then you can write code that sends similar requests and processes the results. And that's all I'm gonna say about the topic, I'm not going to teach you every detail
 
can it be done using bs4 and requests or any other library
 
yes it can - give it a try
 
12:30 PM
ok
 
@JonClements When I tried to install weave on Pycharm (it ran 'pip install weave'), it threw out an error telling that Python 2.6 or 2.7 is required
 
The Pypi page for weave confirms it's 2.x only. Unfortunate.
 
recbg o/
 
12:49 PM
cbg \o
 
I just pip installed weave in my own 2.7 environment with no apparent problems, so that at least confirms that it's still available for download
@codinggirl Have you tried to install weave while using the 2.7 environment?
I know in your question you wrote that you tried changing the environment to Python 2 in Pycharm and installing weave with pip through the terminal, but I wasn't sure if you tried both at the same time, or one and then the other, or what
An additional complication: each Python install will have its own independent pip, and running one directly from the terminal will install to that specific version regardless of what version Pycharm is currently running. (or, at least, that's how it works on my machine. YMMV for non-Windows boxes)
It may ultimately be less of a headache to use Pycharm's built-in package manager, which presumably knows which pip to use
 
1:23 PM
@Kevin cbg and AFAIK you can specify with python to use on Windows as on Linux - c:\my\py\env\python -m pip install something_completely_different
 
1:50 PM
Hi everyone quick question i'm a python noob literally just installed it for the first time and i'm trying to hash some variables that i got by user input but i can't seem to get it in the good format always getting an error msg
import hashlib

manu = input("Enter the manufacturer: ")
model = input("Enter the model: ")
serial = input("Enter the serial number:")
drive = "/dev/sda"

res = manu + " " + model + " " + serial + " " + drive

hashlib.new('md5', res).hexdigest()
TypeError: Unicode-objects must be encoded before hashing
 
How to pass an empty tree(implement by class) into a function?
 
Say Ive got a dataframe that has some values here and there and mostly NaN's. I want to replace each value with a unique index going row by row. I'm thinking of using pandas.stack(dropna=True) and then somehow replacing the 'list' that rolls out with a range of the length of that list. Is it possible to replace a stacked dataframes values with a list of the same length?
 
@claeys It's telling you that you have to hash res.encode()
 
@AjayMishra Presumably the_function(Tree())
 
@AjayMishra The same way you pass anything else into a function?
 
1:55 PM
Cbg
 
@Aran-Fey like this? res.encode(hashlib.new('md5', res).hexdigest())
 
hashlib.new('md5', res.encode()).hexdigest()
 
I think I need to take a break
 
@Aran-Fey right now or in general?
 
Relatable
 
1:57 PM
@Aran-Fey minutes or days/weeks?
 
days
 
@Kevin but the problem is that it has to be empty.
 
Using a word processor after coding a lot the last couple of years: trying to Shift+Tab to outdent, and irritated that tabs aren't four spaces...
 
@Kevin thanks!
 
No problem, I am done.
Thanks for responding though.
 
1:58 PM
@Aran-Fey Why do you need a break?
 
@Arne every now and then. Now's one of those times
@Dodge Too many people asking... ahem... easy questions
 
ah, I see
take care and rest well, then
 
thanks
 
Grrr why can't I place the cursor in multiple places in OpenOffice/MSOffice? Why?
 
relating to the passing things into a function question my first thought was, "you can pass anything into a function", but is that right? what causes an error if passed into a function?
 
2:10 PM
Too many args
Unexpected keyword arg
 
@toonarmycaptain Because It ain't an IDE.
 
You can pass any object into a function.
 
@TheLittleNaruto Yes. But surely there's many many use cases. I mean, within 5 minutes of opening it I'm finding them.
 
There's no, like, self-destructing object that 100% always crashes the function you pass it into
 
@PaulMcG That came to mind (because everyone has experienced that) I was thinking of objects, which appears to be unlimited
 
2:14 PM
Yes, if the function signature is func(*args, **kwargs), then you could pass anything into it.
Wait, what if the function is async?
 
@Kevin Is an unassigned variable name/text string without quotes not counting.
What about passing sys.exit(1)
 
I'd say none of those count since they crash before the function gets called
 
2:33 PM
@Kevin I tried to run the code in the Python 2.7 environment having weave installed through pycharm (success!). Now it tells me Matplotlib is not installed properly...
 
@codinggirl but at least you've got a different problem now, hey? :p
 
Error: RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X.
Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
@JonClements yeah! halfway through!
 
That's just tempting fate... you might end up realising you're only a third or a quarter (or worse...) way through :p
 
I'd rather be optimistic!:)
 
@PaulMcG Unless you pass a position argument after a kw arg.
 
2:39 PM
I wonder why would one work on Python2 when it's already a dead man.
 
It doesn't sound like it is by choice - I think there is some coursework involved using a Python lib written years ago and not kept up to date.
 
Too bad!
Any anime users here?
If yes, you might find this video funny:
 
programmatrum de mortius - those who code in dead languages
 
@TheLittleNaruto I use to be more so, but now more of a occasional social user ;)
 
2:47 PM
Still you can watch shared video lol :)
 
@mtbrands Something like this?
df = pd.DataFrame({'a': np.array(['c', None, None, 'd', None, 'e']),
                   'b': list('uvwxyz')})

df['a'][df['a'].isnull()] = np.arange(df['a'].isnull().sum())
 
I managed to do a df_stack = df.stack(dropna=True)
new_df = pd.Series(range(len(df_stack)), index=df_stack.index).unstack()
 
That looks like it gives the opposite result?
In my example, that replaces the letters in a with numbers and creates Nans but maybe it's to do with datatype
 
Could be that my explanation was wrong
 
Oops, nope, I read the requirement backwards! Sorry
Easy enough to flip my example around: df['a'][df['a'].notnull()] = np.arange(df['a'].notnull().sum())
I'm curious how that could be made to work for multiple columns, though, so maybe stack is the best approach
 
3:01 PM
@TheLittleNaruto I'd watch the heck out of that, TBH
 
Great :)
 
Also, literally me right now:
 
@WayneWerner you broke your keyboard and your wrist :p
 
@WayneWerner Hey you got that mechanical keyboard. Did you buy the assembled one?
 
but at least he got the solution he needed :D small price to pay, maybe?
 
3:03 PM
@Dodge That keyboard is one of the best one imho
 
It's the UHK - I don't think there's a non-assembled version :P
it's entirely worth it
ironically, now that my mouse is in my keyboard I use my mouse way more often than I used to
 
Atreus sells the unassembled one
 
275 bucks... ouch.....
i mean it's cool, i would consider using it at work, but idk if I want to pay that much for a keyboard.
 
That one looks like the keyboard.io one - oh yeah, it's an ortholinear keybaord
 
Everyone's hands are different and works differently. Based on that fact there are many type of mechanical keyboards.
 
3:07 PM
@MooingRawr yeah, I got mine when it was $250. And to be fair, I also saved up for over a year
(thanks, Simple)
 
Would you say it was worth every penny ?
 
If you work a lot on computer; for example a professional blogger, then it's worth to buy one.
 
Absolutely
(or, a professional programmer ;) )
 
that too, indeed
 
i find myself typing on the keyboard with my fingers slanted on a regular keyboard so maybe..... do you know if they ever go on sale?
 
3:09 PM
I want to buy Atreus keyboard, they are very cool
 
Not AFAIK. At least they haven't. I had been saving up for this lego set, which was at Toys R Us, but by the time I saved up, they went out of business, oops.
 
@MooingRawr If you're in India, MECKEYS would be good option. they go on sale sometimes.
 
Not in indian, too hot for me. Wayne, sounds like the last time I was saving up for dual lands and by the time I reached 100 bucks (when I was in university) they jumped an extra 50
 
I'll use any keyboard that doesn't have half-sized up and down keys
 
I wasn't entirely sure if I was going to get the UHK or an ergodox - at the time it wasn't 100% positive that the UHK was going to ship. I was following them on... crap I don't remember the site
Oh, crowdsupply
 
3:13 PM
smaller keys on a keyboard makes me relate to Mr. Incredible typing on a regular keyboard when he was cramp in his office at his day job
 
@MooingRawr Too hot? Not every places. There are some places where temperature don't go beyond 0-10C
 
anyway, they were working on a bunch of different issues with like... electric emissions, and actual noise from the keyboard.
But they got all of that sorted out, and started shipping, so that's when I pulled the trigger.
I did expect my keyboard to be closer to the SO orange
turned out to be a mustard yellow :P
Re: price - yes, the keyboard is expensive, but I also expect it to last until I'm dead. And beyond.
I realized that basically every other industry expects folks to supply their own tools. And a nice set of tools for a mechanic can run upwards of $1k
 
ergodox base is 270 bucks... mmm but they have options to be shiny, and I do like my shiny keys
 
backlit? Yeah, the UHK hasn't done the backlit thing yet. The board supports it but you have to wire things yourself.
I know there are plans to start producing a backlit version
 
@WayneWerner been a while with no bumping into :) How's things?
 
3:22 PM
Hey @JonClements :)
Going well - I realized in the last while that I was much more active on SO when I wasn't working professionally with Python or at a good company (:
 
As long as you're enjoying it :)
 
working with a great team reduces my requirement for other tech friends :)
But... you know, trying to still be around here and there :P
speaking of here and there, rbrb
 
@mtbrands If you're ok with the number starting at 1 instead of zero, I've come up with a 1-liner that is faster for bigger dfs here. You could also subtract 1 from cumsum() to make it equivalent but I think that will slow it down due to having to make another assignment
 
The empty path didn't match any of these. What's going on?
 
@superv No stress, slightly busy, so will reply once I get time. Kindly ping me with your new dpaste link.
 
3:30 PM
@WayneWerner au revior!
 
path("", views.project_index, name="project_index"),
that's included in my urls...so why isnt it matching?
 
@roganjosh What are you guys trying to do?
 
@JonClements starts here
 
@JossieCalderon What's the exact message... at what point can't it be resolved? (in a template, in a view etc...)
 
This is literally the problem I have: stackoverflow.com/questions/58268663/…
 
3:34 PM
@roganjosh ahhh thanks... and your dpaste there gives the right results?
@JossieCalderon I get what the problem is but the question I asked was to get more information regarding solving it... you need to be more specific where the lookup is failing
 
@JonClements I assume so, I just went off the approach they they posted which I called multi_line. cumsum is off-by-1 though, they haven't clarified if that matters. tbh I just got a bit bored and wanted to see if it could all be chained :P
 
okay lol
 
For some reason I thought cumsum had a starting value offset parameter, but I'm not sure what made me imagine that
 
@JonClements I added " path('',include('projects.urls'))," and it suddenly worked, but I have no idea why.
    Using the URLconf defined in personal_portfolio.urls, Django tried these URL patterns, in this order:

admin/
projects/
The empty path didn't match any of these.
@JonClements
 
I heard yeah... got other things on at the same time ya know - patience please :)
 
3:48 PM
Didnt know you saw it
 
Anyway... that still doesn't help... is that error being raised in a view or a template or... that's what I've asked twice already :)
You get a much more detailed exception and traceback than those lines...
 
It's in personal_portfolio/views.py
 
keep going...
 
4:05 PM
Sorry, I'm wrong. It's NOT there. it's in personal_portfolio/urls.py.
personal_portfolio/urls.py:
urlpatterns = [
path('admin/', admin.site.urls),
path('projects/', include('projects.urls')),
]

projects/urls.py:
urlpatterns = [
path("", views.project_index, name="project_index"),
path("<int:pk>", views.project_detail, name="project_detail"),
]

The empty path IS contained! when the path('projects/', include('projects.urls')) is called, it should call projects/urls.py. then the empty path is there. Why do I need to include path("",include('projects.urls')) personal_portfolio/urls.py?!
 
@JossieCalderon - please format code using fixed font, preserves indentation which is important when reading Python code
 
I tried but then it indents all of the text
 
I would rather see text in fixed font than code without indents
 
I can't even delete it here. But I've asked here now. @PaulMcG with the indents stackoverflow.com/questions/60398899/…
 
You only get 2 minutes in chat to edit or delete a post
Then it gets transcribed onto stone tablets for all posterity
 
4:22 PM
The line path('projects/', include('projects.urls')), when removed, doesn't impact whether the program works or not.
L0O0O0O0OO0OL
I was typing localhost:8000, instead of localhost:8000/projects! L0000000000000L
 
Just shows that if you take a step back, take things step by step with the information you're given and look at each bit, you can solve these things by yourself! woohoo!
 
I was using bogo sort to solve my problem
 
4:39 PM
Hmmm, this sklearn package looks suspicious. I wonder if they're parking the package name themselves to prevent something malicious?
 
re-cbg
 
re-cbg
 
is there a way to make argparse do a --list without set_false?
 
parser.add_argument("--list")
 
dang! I'll elaborate
 
4:44 PM
set_false? Not sure... but I think what you're after is: parser.add_argument('--list', action='store_true') ?
 
Yes, you will probably need to provide further information
 
Interesting. I wonder what this thing is. 1.7M iso... has some vb6 (?) in it.
definitely some kind of hax attempts
> IMGBURN V2.5.8.0 - THE ULTIMATE IMAGE BURNER!
DHL_FEB_.EXE;1
 
I have a CLI that runs a bunch of models. I want to list the available models so that I don't have to read sourcecode. I'd like to do this with python myfile.py --list. However, the only way I can think of to implement this is with args.add_argument('--list', dest='clist', action='store_false') and then if args.clist: print(stuff). But I was wonder if there's a way to insert a lambda or such into the add_argument to shorten this
 
> \VB98\VB6.OLB
interestingly enough there are a lot of 0's in this
 
wim
@roganjosh it is a shim with a dependency on scikit-learn
 
4:50 PM
@inspectorG4dget seems like that should probably be a sub parser? So you have something like: program action ... so program list just lists stuff... and then program whatever --option1 etc...
 
wim
IMO it's a bad practice, and PyPI should ban it
 
Ah thanks. It's kinda what I expected but it would have been nice if they could have explained that like bs4 did
 
@JonClements dang! that's what I was afraid of. Thanks puppy
 
Oh, that's clever. Pretty sure all this padding is in here to fool scanners
 
@WayneWerner Ummm.... "Scanners" - haven't seen that in ages... might have to see if I can find/have got a copy somewhere... quite enjoyed that :)
 
4:54 PM
oh that's amazing I didn't know that was even a movie
that's freaking glorious
 
Yeah... classic Cronenberg :)
 
@wim well that's BS
 
Like "The Highlander" though - it's best to pretend there's no sequels @Wayne :p
 
lol
man I loved that show
 
The film or the TV series they did?
 
5:04 PM
Yes.
 
And here we aaaare, we're the princes of the univeeeerse
Queen makes everything better
4
 
No lies detected.gif
 
Is there anything similar to Py3.9 functools.TopologicalSorter available for earlier python versions?
I've found a few packages on PyPI but it's hard to tell which ones are actually usable.
 
toposort and networkx come to mind
-1,000,000 quatloos for those that toposort a graph stored as links in a dataframe ("doesn't everyone use pandas?")
 
toposort looks nice, but it's suspiciously frozen in a state when py3.5 was the newest rage.
 
5:21 PM
I normally go for networkxs there... as I generally have that installed anyway to do other bits for stuff I work on
 
You don't need to use f-strings
 
Yup... and I think sometimes they're over used f'{x + 1} - {y}` or something I think is lovely... but when you end up with f'{abs(x * -y) + something(3, 2)}' I groan somewhat
 
Hi all, is it possible to use Python to get the coordinates (live) of the green and red lines from this page? fxstreet.com/rates-charts/…
If so, how would I get started into doing so?
 
Umm... starting to wonder if we've put an ad. out that this room is a how-to scrape the web resource :)
 
5:41 PM
@JonClements Even better when the something() method has side-effects
 
Well... sometimes f-strings can just look rather php-ish
(but if doing simple ops on a variable, then it's nicer than using .format(...) and creating multiple (named) args)
 
anyone have a good source about email attachments in Python3? I'm using MIMEText and adding as an attachment to an email but trying to iter_attachments gives me MIMEText object has no attribute is_attachment
 
wim
@PaulMcG +2
 
@PaulMcG picked toposort now, fits exactly what I needed. TY.
 
Looks like this is another assignment to put people off learning to program sighs
 
wim
5:52 PM
IIRC there is one from Tim Peters on pypi too
 
@wim that wouldn't surprise me... fairly sure GvR had an (quite old now) example of using a dict to represent a basic graph and a demo. of how to use that for an A* jobby
 
Ah, interesting... looks like it just turns it into an EmailMessage Hm
 
@Wayne are you creating a base EmailMessage and then using its methods to add the multiparts?
 
@wim AFAIK topsort is from Tim. Ruled that one out due to lack of docs.
 
Yeah - msg.attach(MIMEText(...))
(I mean, my code is more, but fundamentally that)
I was able to do msg = parser.parsebytes(msg.as_bytes()) and the MIMEText turned into an EmailMessage
 
wim
5:56 PM
the pypi page is weird pypi.org/project/topsort
no release files hosted?
maybe this was imported from a truly ancient pypi when they still only hosted links to code (hence the cheeseshop joke)
the Download link is a 404 and the Homepage link apparently takes you back in time
 
Typical... I'm sure Martijn's probably written a bloomin' good answer for things like this but can I find it :)
 
6:11 PM
@JonClements Tough job; Good luck Man!
 
6:36 PM
@TheLittleNaruto yup... good to see you hanging around more :)
 
@JonClements hammered with abarnert
 
lmao... that couldn't be a more of a duplicate if it tried could it...
 
Wow, the exact same problem code... what ar the odds?
(was going to fix that typo, but decided to leave it in in)
 
6:51 PM
what arr the odds
there was a third meh dupe with again the same code...ended up duping that to the same target
 
Puts the "overflow" in StackOverflow
 
it should come as no surprise to me anymore, that my capacity to clever is far outperfomed by my capacity for being stupid
 
Brain! Stop stupiding!!!
 
I really wish I had that API call
sometimes I can solve it by shoving carbs down the hatch
 
@inspectorG4dget is there a clever? Or is it just our anti-stupid abilities out-weigh our stupid abilities now and again? :p
 
6:56 PM
pull the (c)lever
 
@JonClements much like darkness is the abssence of light, and cold is the absence of heat, I think clever is just the absence of stupid
6
 
Apply cleverage, not stupidage
 
7:13 PM
In-so-far-as SO has gone for a helpdesk model, I really wish we could get more questions like this. A genuine attempt and it seems like quite a few people are learning from it just from landing on a question, not searching for a specific issue
 
wim
why do so many people type "web scrapping" ?
is it any more than a common typo of "web scraping"?
 
typo/misassumption of the correct continuous* spelling
huh, i don't actually know what it's called.
continuous form?
 
favourite python function lads?
 
groupby
 
7:23 PM
mine has to be a bit of lambda
 
@wim the word "scrap" is more common than "scrape", and they don't know there's a difference. See also Scrappy Do.
 
@wim I do a lot of work regarding web scraping and stuff... even the most well informed clients I have still ask if I can: "scrap a website"
 
plot twist, you say yes, and then DDOS the website to oblivion.
 
Some of the more curious stuff I've had recently is "Can I screen scrape a website?"
 
7:28 PM
Why can't I combine a lambda function and super together?
 
@Govind75 closing as no MCVE
 
@Govind75 Why would you want to and what do you even mean?
 
also probably "shouldn't"
 
Because I've inherited a class and I want to use a method of that class
In tkinter
 
need for MCVE intensifies
 
wim
7:31 PM
even the PyCon 2020 talk schedule had listed a talk "Distributed Web Scrapping in Python" :D
 
Does MCVE mean you need more context? I'm new to this room.
 
wim
sorry, confusing term. you need a ruprecht.
 
mcve: minimal, complete, verifiable example. Essentially, the smallest amount of self contained code that can show what you're referring to. keeping in mind it's complete too. Also, use a code paste service if your example is too big, dpaste, github gist, etc
 
puppy's taking off his ninja costume and going back to that happy little crazy looking yellow thing (that's missing a leg) :p
 
wim
7:34 PM
I am morbidly interested to see this super lambda combo
like slowing down to look at the car crash on the highway
 
be nice
 
Well...I'm a bit of an amateur so don't destroy me all at once
 
@Govind75 it's alright, we can help. Ignore the snarky badger.
 
self.RFButton = Button(frame, text = "right forward", command =lambda:super().rotate_right("forward"))
 
@Govind75 have you tried with self rather than super()?
 
7:36 PM
I have and it worked, I just wanted to know why this doesn't
 
What error do you get? ;)
it should probably work with super(<this class>, self) instead of a bare super()
 
that's what I was thinking
> Also note that, aside from the zero argument form, super() is not limited to use inside methods. The two argument form specifies the arguments exactly and makes the appropriate references. The zero argument form only works inside a class definition, as the compiler fills in the necessary details to correctly retrieve the class being defined, as well as accessing the current instance for ordinary methods.
 
Should I be doing that for all 'super''s
 
please use super() wherever it works
 
Alright
 
7:41 PM
And where it doesn't work, don't use it
 
@Govind75 Presumably the use of super in any context would be to call a method defined on a parent class. Do you really need to call rotate_right on the parent class?
 
The short form was introduced because most people just don't get the two-argument form. Your code is much more maintainable when the short form "just works" because you can't mess it up.
 
wim
I don't get why you use super at all here
why not lambda: self.rotate_right("forward")
 
take note: whenever you use super() to invoke a method other than the one you are currently in, your inheritance is likely messed up.
 
@Govind75 this feels like a case where you're going wrong in design... you shouldn't even be using super here... as the responsibility of .super()/not will be coming from your call to rotate_right - all you need to do is pass the call to that and then let that do the needful
 
7:43 PM
When should I, and shouldn't I be using super?
 
wim
when you understand what it does
 
Yeah that's what I'm trying to get at.
 
wim
fair enough :)
 
Can someone maybe explain it to me?
I use super previously in the code - it worked fine but should I do without it?
 
Do you know what "method resolution order" is?
 
wim
7:45 PM
suppose a parent class implements something that you want to reuse
but you need to do something slightly different
 
No :/
@MisterMiyagi ^
 
wim
rather than copy-paste all the implementation from the parent class again, you can use super to call it, and then just add in the custom stuff afterwards. that is the most common use-case, there are a billion others.
 
Ah I see
 
@wim whoops, completely misread that somehow, sorry
 
So something like this:
 
          super().__init__(9,["Red","Yellow","Green","White","Orange","Blue"])
      super().initialise_cube()
      super().redef()
      super().displaying()
 
And if your class does not override a method, you can just call self.method(), and it will automatically call the one in the superclass
Is this in __init__?
 
Yeah
 
I feel bad now about referring you to Hettinger's article about super... can I ask what you took home from reading that? It kind of seems like you've read that and thought you need to use it?
 
wim
for the first call, yeah, the later 3 could just be self
 
7:48 PM
You would typically only use super() to call the parent in the method you are overriding. The other method calls should be self.initialise_cube(), self.redef(), etc.
 
@JonClements I probably misinterpreted...
But at least I understand now (I think), cheers.
 
wim
I forget which came first, super-harmful or hettinger's article
 
if you haven't already - can you show the code in a pastbin/gist/etc... @Govind75?
 
The whole code?
 
how large is it?
 
7:50 PM
@Govind75 The idea of "method resolution order" is: When you call self.foo(), but type(self) does not implement foo, Python looks at it's parent class, and then the parent's parent class, until it finds foo. That's the simple form method resolution, where direct inheritance provides the order.
 
It's 3 files - a database, an interface and the actual program thing.
The one I was copying and pasting was the interface
 
super(some_class, self) means "search methods starting at some_class in the method resolution order of self".
@wim IIRC super-harmful was there first
 
@MisterMiyagi Ah okay
 
I think Hettinger's article was something of a rebuttal, sort of "oh come on, it's not that harmful if you know what you're doing". Plus I think super-harmful predated the no-argument syntax.
 
wim
@MisterMiyagi I like this comment because it doesn't make the claim that super ever works at all ;)
 
7:55 PM
Ok @Govind75, now for the quiz: inside your class's __init__ method, why do you call super().__init__ and not self.__init__?
 
I generally like super, but I've seen people accidentally misuse it heavily – so I generally only recommend it to people who understand how Python classes work.
I also feel it's a major design problem that super can be used to call methods other than the one it's used in.
 
@MisterMiyagi well then you don't use it and be explicit
 
@JonClements your face ohmygod something happened to it
 
wim
the no-argument super is one of the grossest hacks in CPython, IMO
very shakey implementation
 
Does it use locals() to find self or something?
 
7:58 PM
nah, it's compiled to use certain cells.
but you can override these cells, and then all hell breaks loose.
 
wim
it uses a check at compile time to inject a "hidden" variable
 
@AndrasDeak home again :)
 
I've only seen the ninja
 
seriously?
 
yup
I started on SO in 2015 and here in 2016
 

« first day (3419 days earlier)      last day (1518 days later) »