Hey all, looking to figure out if it's possible to monkey patch a CPython function globally? I can't seem to find anything on the matter in my SO/Google Fu searches.
Lists of animals Lists of aquarium life Lists of biologists by author abbreviation Lists of cultivars
into:
* Lists of animals * Lists of aquarium life * Lists of biologists by author abbreviation * Lists of cultivars
Would I be better using split, or replace?
The Automate text states: https://automatetheboringstuff.com/chapter6/ "The \n newline characters in this string cause it to be displayed with multiple lines when it is printed or pasted from the clipboard. There are many “lines” in this one string value. You want to add a star to the start of each of these lines.
You could write code that searches for each \n newline character in the string and then adds the star just after that. But it would be easier to use the split() method to return a list of strings, one for each line in the original string, and then add the star to the front of eac…
It's still two instead of four lines. Would there be a reason to use the split method instead? I wrote the replace code before I followed down to what the Automate guy talks you through, and didn't understand why what he wrote would be better/simpler, apart from the special case point.
Yeah haven't got to that yet. I thought he'd mentioned replace but either way I'd seen it, and it seemed simpler to me than what it turned out he talked you through.
As they were last night when I sealed my fence (or some thereof). There weren't today, although it was pleasantly cloudy when I ripped out the bushes in my sister-in-law's front garden. Maybe I've to active to be a programmer...
@AndrasDeak Beware of ending strings with an odd number of backslashes: the final backslash escapes the quote, even in raw strings.
@toonarmycaptain FWIW, strings also have a .splitlines method, which is probably slightly more efficient than .split("\n"); also, it takes a boolean arg that allows you to specify whether you want to retain the line endings or not.
Let's say I have a pandas dataframe groupby that looks like this: df.groupby(['pk', 'model']) the column names on this result are like so: pk, price, model, manufacturer, quantity, transaction_amount I want to, using `df.groupby(['pk', 'model']).sum()` calculate the totals in both the `transaction_amount` and `quantity` columns. I've tried googling it, but the best I got was `axis=1`, which is kind of what I want, but I don't want ALL of the columns aggregated. And I read the docs, and it doesn't work with `numeric_only=True`, either.
@PM2Ring I guess splitlines would be better. I just queried why the author took the student through it that way when a student (well, this student) at that stage of the text came up with an arguably simpler/straightforward method that was different to his. [Usually there's a reason why they do it differently from what immediately occurs to me...]
@toonarmycaptain Well, using replace to put asterisks at the start of each line is slightly messy, since you need to handle the first & last lines as special cases. But I guess he showed it mostly because it's often a good way to deal with line-oriented data.
Of course, if you have a huge text file, it's often desirable to process it line by line, rather than reading the whole thing into RAM.
@toonarmycaptain But bear in mind when reading older books (or books by older authors) that some of us learned on systems with much smaller RAM than modern machines, and so we were trained to be very frugal of RAM. It's still good to know how to process files in lines or small chunks, but it's often more convenient these days to just read the whole thing in one hit. But some of the old-timers sometimes forget that loading a few MB of data is nothing these days. :)
@toonarmycaptain That looks ok to me. And readability is a relative thing: the more you use a particular syntax, the more readable it becomes. So although Python's str.join seems strange at first, you soon get used to it.
@PM2Ring Understood. Personally, I think some software companies could do with looking back to the days when getting the codebase as small as possible, and as CPU/RAM light as possible was more of a priority. But my family goes back to punchcard days, and the early computers, along with the Gemini and Apollo flight computers/software, are fascinating to me.
@toonarmycaptain Cool. I used punchcards for my first 4 years or so of programming. An old friend of my family was the "head computer guy" in Australia for some of the Apollo missions; he has some great stories of the good old days.
I suppose he probably would've been based at Parkes, since we didn't have much infrastructure capable of data transmission back then. I guess they could've been using telephone lines to transmit data, although that would've been tricky: this is before STD, so long-distance calls were trunk calls, manually placed with the operator.
And so if they'd used the phone line to transmit data continuously then that would've blocked a big chunk of the phone service in western NSW. :)
@toonarmycaptain I'm the only regular non-expat Aussie here, although there's a guy who lives in northern NSW who drops by from time time. Wim (the guy with the badger avatar) is an expat living in the States, originally from Melbourne but now in Chicago, IIRC.
@PM2Ring I'm not content to call myself an ex-pat yet, as the PLAN is to move back. Although I suppose I was an expat when I was living in Australia in the first place.
I guess I have an Aussie-British accent? I get picked for an Aussie here, but in Australia they pick me for a Brit. I tend to reflect the accent of my audience for ease of comprehension.
I think Cherry Ripes are? You can't get either here. Flakes are from the UK as well. As apparently is Strongbow, which is in stores here now, and I assumed was made in Australia.
@Cauterite It just amuses me that we brought back product for people in the US, who would have originally got it in Africa imported from the UK.
You don't get fresh seafood inland here like you do over there. In WA anyway, they truck/fly seafood in fresh to a lot of places daily. Which explains the awful excuses for fish and chips here.
I've rarely been to a butcher here. There aren't many because for some reason most malls don't have food shops, and Walmart, Target and the other standalone food shops corner the meat market.
@Code-Apprentice Yes, I can't remember one without one. They're really based around them in some respects like malls in the US are based around department stores.
I mean the malls will have department stores too and be setup around them, but some malls don't have any, just a grocery store or two, and smaller specialty stores.
Target and KMart are department stores in Australia, and I've never seen one outside of a mall. Come to think of it I've never seen a KMart in the US myself.
The one in my home town shut down within the last 10 years.
Walmart pretty much put Kmart out of business
Here Kmart and Walmart are considered a department store, but is always in its own building, not a mall. Also, they are much less expensive that department stores like Macys.
Well I'll probably be keeping windows on it for the moment. I don't really need something highend, apart from running Kerbal, and making it last a few years.
We will stop accepting contributions to Documentation on August 8
On behalf of everyone who worked on Documentation, I want to thank all 15,451 users who contributed. We particularly want to acknowledge the 294 people who tested the private beta and the 2,361 who pounded on the public beta in ...
@AndyK And rightly so, when it's an obvious homework dump with zero effort made by the OP. Especially for a problem that can be answered with a line or two of very basic code.
Some of us try to encourage women who're interested in programming, but there are plenty of guys who aren't very welcoming to women. It's a complex topic, and it doesn't just come down to male chauvinism.
@khajvah Due to my own incompetence with React I feel that the whole "universal apps" is a bit of a lie. Setting it up for a nontrivial web "app" seems like a huge hassle.
In my class when we started there were about 30 % women, that's pretty good to be honest. It has been much worse. The dropout rate is higher for women though, but this is only one school and one program. I guess a lot of girls feel like there's a sort of silent discouragement.
A century or so ago, upper/middle class ladies were encouraged in mathematical studies, and so we get people like Ada Lovelace who's often cited as the first programmer. But then we had a century where mathematics was seen as a boys' subject, and girls didn't have the right kind of brain for it.
But in the last decade or two here in Australia a lot of effort has gone into smashing that attitude, and now many of the top maths students in senior high school are girls, in some cases the girls are in the majority. Sure, maths isn't the same as programming, but there is a sizable overlap of the required mental faculties. And a bit of maths knowledge doesn't hurt if you want to be a good programmer. ;)
FWIW, I haven't done much formal programming study, but when I did, 2 of my programming teachers were women. In the mid-late 1970s there were quite a few women going into programming. But for various reasons that tapered off.
@Victoria On the xkcd forums there used to be a forum regular who was doing an engineering degree. In that field, in her experience, the discouragement wasn't always silent. She found it wasn't easy to get the men to take her seriously.
I haven't, but some do. There are plenty of groups for girls in my school and I think they are pretty good for getting to know other girls.
A lot of my teachers are actually women, I think that is one of the best ways to encourage the women already pursuing a degree because it gives you good role models early on.
Yeah, I find it's a little bit weird in a way. A lot of people remarks on stuff I do and belittle it, it's really annoying. On the other hand I think it seems better when trying to find a job because a lot of companies want to have a better balance in their work force so they try to hire girls.
@marsouf Unfortunately, Python has a bad reputation when it comes to proper handling of timezones. The standard datetime module originally had terrible timezone support. It's a bit better now, but it's still not good. There are various 3rd-party modules which attempt to improve the situation, but as far as I know none of them is perfect. Antti Haapala can probably give more details about the merits of those modules.
@Victoria That's good, but I'm sure it's not easy working with a bunch of guys that aren't used to working with women. OTOH, the only way to break the cycle is to make sure they get the opportunity to work with women. Of course, if things don't work out so well, that can put a lot of pressure on the women.
@IljaEverilä yeap, too much stuff to worry about while you gain little. Once you set up your beautiful react web app, you start to worry about SEO, start mixing server side/client side rendering and end up with overly complicated stuff.
I have never met a guy who belittles somebody's work just because she is a woman
@PM2Ring Well to be honest I feel like it's a bit unfair hehe. I would prefer not to feel like my gender influences what kinds of jobs I can get at all.
@khajvah My thoughts and experience so far exactly. I've a feeling that React is nice in moderation, but pain for anything bigger than a 2 view SPA or such. YMMV.
@Victoria Oh, it's very unfair. But the world is what it is, and we have to deal with this sort of stuff the best we can, making little changes when we have the opportunity.
hello, i have key (0010, 0010) and I can acces to him by [0x10, 0x10] this is works :D but how can I access to (0010,1010) for example or how can I convert (0010, 0010) to [0x10, 0x10]
@khajvah Guys who aren't used to working with women can have a tendency to not be fully accepting of the woman as an equal team member. Of course this is a generalization, but it does seem to happen a lot, in a wide variety of fields. You'd think it wouldn't be an issue in a more intellectual pursuit like programming, but it is.
@khajvah are you looking for it though? Or perhaps your tolerance threshold is lower? I think it's easier to forget insults from idiots (because they're idiots) than things like being treated differently by a group of regular dudes.
One of my first job was in a datacenter a few years ago. It was a guy-guy env, very rough , guys shouting at each others, rarely but coming to hands from time to time, and then came a few womens and the atmosphere get more relax.
One of them, M, was fantastic, she did a great job. Very reliable
That question isn't fantastic, but I have to give him points for effort. I'm not going to write an answer, but if someone here does, I'll probably upvote it. ;)
TIL - not all strings that are .isdigit() can be converted to int using int:
>>> c = '\xb2'
>>> c
'²'
>>> c.isdigit()
True
>>> int(c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '²'
@PaulMcG Yes, it's slightly annoying. I guess you can always just do EAFP, but it's not so efficient if you expect a lot of the strings to raise the ValueError when you try to convert them.
BTW the os module includes a number of system methods that will let you do things like pwd without having to spin up a process with os.system. Try os.getcwd()
If you are on a recent Python, using Path from the pathlib module: print(pathlib.Path('test.py').exists())
With python each interviewer has a couple of puzzles (Which i of course fail at cracking), I can see that the quality of python programmers is much better than that of Java or .NET
I also feel like I might be actually bad at the language
I am generally good with googling my way out of problems and stuff but I guess that wont cut it.
I like how they don't want to admit that it just failed. "We still think Stack Overflow Documentation is a good idea." ... " Unfortunately, we can't afford to work on the problem at the moment."
@Victoria I agree. I think in general, the younger they are to exposure too, the better. I have children, and I'm already noticing certain stereotypes being played, and unfortunately this even comes from educators. A lot of it needs to come from home too to build that character to know what to stand up for. But, society also does a good job at influencing.
I'm hopeful, and I try to do as much as I can to help my children and help anyone else I can (I've mentored to help encourage and promote)
those who really believe and encourage change try to make a difference and we need more of those people.
@vaultah omg .. it was posted today only, and over the years I thought of contributing all little interesting things I learned (and forgot due to non usage) :(