« first day (3387 days earlier)      last day (1778 days later) » 
00:00 - 18:0018:00 - 23:00

00:03
Hmm I know I'm probably the only one using Typing, but is there a base type that support any other type (objects or primitives); but is covariant, as it accepts anything "in" but nothing "out"?
00:42
@JonClements Popping in to justify my recent absence - I've had jury duty. expect a return to normalcy next week.
00:53
I can "pop" off the right most binary digit with n >> 1. But how do I pop off the left most binary digit (assuming the left most 1, not 0). This is a cheesy way int(bin(n)[3:], 2). Is there a "better" way?
 popleft = lambda n: n & 2**int(math.log2(n))-1
that makes sense... but
%timeit int(bin(12345)[3:], 2)
%timeit 12345 & 2 ** int(math.log2(12345)) - 1

# 302 ns ± 0.278 ns
# 404 ns ± 0.456 ns
What if you do log2 = math.log2 in advance?
popleft = lambda n, log2=math.log2: n & 2**int(log2(n))-1
Those . attribute lookups take time
Meh, didn't make much difference for me.
02:14
hmm is there any documentation on what virtual environments actually do?
I'm running docker-compose through a virtual environment, and notice that I cannot change the built dockers with a docker-compose call later.
subprocess.run(['sudo', 'docker-compose', 'up', '-d', '--build'])
if I then manually run sudo docker-compose up -d --build at a later point it doesn't recognized the built dockers. (And complains about dockers having conflicting names).
@PaulMcG Does it make a different if you do from math import log2 instead? I read somewhere that different scopes have different speed lookup?
It might have been function scope vs .attribute now I think about it.
02:58
@PM2Ring thanks. So I get to meet with the CEO. What does a successful meeting look like? Realistically, what do you want me to be able to say after the meeting? - considering that if he asks me to keep anything private, I'll have to do so. In fact, we'll probably agree on an "allowlist" of things we'll talk about afterwards.
This question is to everyone here, of course.
wim
wim
03:19
I think int(math.log2(n))-1 is just n.bit_length()
bah, is only slightly faster than the string domain
>>> timeit n & 2**(n.bit_length()-1)-1
758 ns ± 50.8 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
>>> timeit int(bin(12345)[3:], 2)
794 ns ± 14.8 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
 
3 hours later…
06:23
From stack overflow community :- All community users belongs in this group given suggestion to follow that please post questions manually in stack overflow questions group.
user10984358
do you guys have any suggestion of a library that acts like Task Scheduler or cron? My end goal here is to schedule programs from a python script. So far I have considered dynamically creating commands and using that to call the task scheduler as a subprocess, currently looking into this apscheduler.readthedocs.io/en/stable/userguide.html, my requirement is windows only but I wouldnt mind a cross platform option
Cabbage
06:46
hi all. I have this code to summed up all the characters in all rows of a column:
sum(list(map(lambda x : sum(len(y) for y in x.split()), df['column2'])))
cbg guys o/
@smci I thought of using only one function for that purpose, now made multiple functions. BTW Isn't SQLAlchemy is only for MySQL? For me database is MongoDB.
@codeMagic Please forgive me for my sins :D
any ideas how to get all characters of column2 and return for each row in column3?
@smci I am not using any ORM though
when we use clustering algorithms like DBSCAN we have to give parameters like Eps and min points and tweaking this enough will give us the number of clusters we want from the data, However, I am only able to accurately give these parameters once I visualize the data , it somehow feels counter intuitive..
@JackZakiZakiulFahmiJailani which column2 thu
06:53
I mean, Whats the point of the whole clustering algorithm if you are looking at each data and telling it the eps and min points..
kk thu
Ideally The algorithm should only take in the data and tell me on its own how many clusters it think there are no?
this is how my column looks like:
`column1        column2                                                               column3
amsterdam      school yeah right backtic escapes sport swimming         2016
rotterdam        nope yeah                                                            2012
thehague         i now i can fly no you cannot swimming rope           2010
amsterdam      sport cycling in the winter makes me                      2019`
ok, please post this one as question in stack overflow thu. I will define the answer
06:56
Its will be useful for all users thu.
@SaisivaA what is "thu"?
please ask the questions revolve around the subject thu.
i think short of thank you :D
07:07
@anky_91 Oh
But he is adding in his every senetence.
dict.get_argument('name','def')
how to do the same for nested args?
user10984358
dict is name you have for a dict or the built in dict?
lets assume dict_name is lol
@TheLittleNaruto yeah , no idea I just guessed
user10984358
given an input how do you want the output to be?
07:13
var_dict = { lol: 1, kwargs: { 'handler':'form', 'lol': 'x' } }
need to get the handler,, but kwargs might now alwys exist
i dont want to use if has-key kwargs
116
Q: Python safe method to get value of nested dictionary

ArtiI have a nested dictionary. Is there only one way to get values out safely? try: example_dict['key1']['key2'] except KeyError: pass Or maybe python has a method like get() for nested dictionary ?

done
user10984358
if (t:=var_dict.get('kwargs')) is not None:var=t['handler'] for lols
user10984358
didnt see that you didnt want to use if, sorry
07:35
@Kevin D:
@TheNamesAlc I use APScheduler to automate every daily/hourly task on my website at work. So far it has worked great but it doesn't make a system task so it does rely on the script running 24/7. It's cross-platform
user10984358
i dont want the script to be running 24/7 I just want my script to add it to the job and then not care about it, is there any way to do this? I saw another scheduler library and that didnt work for me (same reason needs to be running all the time)
@TheLittleNaruto No, SQLAlchemy is not only for MySQL. Part of the appeal of the library is that it connects to various RBDMS and translates the queries as appropriate. You "flick a switch" and your code stops relying on MySQL and now works with Postgres etc. However, it does rely on SQL-based DBs
@TheNamesAlc In that case I don't have anything to suggest, sorry :/ That's not to say that I don't think it's perfectly reasonable to want something that doesn't want a .py script running permanently :)
user10984358
when i asked why re invent the wheel when windows task scheduler is simply better and "just works", my boss said he wants to keep everything in one app
07:52
Right or wrong, that's what I did. I had 4 separate processes originally to make the app work reading CSVs that get updated at various intervals. I bundled them up as tasks in my main flask app
user10984358
I really like when I am given creative control, appreciate the help though :)
I'd be curious to hear what you implement. The last meeting I had with my boss was 4 months ago so that's the result of my creative control :)
user10984358
lol, I will probably stick with doing a subprocess call to schtasks.exe unless I find some library that does it for me, I am guessing the win32api might have something
08:36
@roganjosh So even with that switch, I can't use it with MongoDB. I think you had told me same thing last time as well.
<shrug/> I say lots of things and just about to make my first cup of tea of the day so I'm not yet receptive to deju vu even if we did talk about it :P
I do remember the discussion about SQL/NoSQL in general, though. I guess you've stuck with Mongo for the project
@roganjosh :D
Do you take milk tea?
Milk, 1 sugar please
earl grey ofcourse :P
Nooo, PG Tips (or Breakfast tea)
08:47
@ParitoshSingh Never had that one.
Ah, colour me surprised @roganjosh !
@TheLittleNaruto Honestly, Me neither i think :P
I've seen it a lot in London though.
If any physicist wants a mental breakdown, this letter to a local newspaper is beyond words (adblocker may go a bit wild because local news has to scrape a living)
@ParitoshSingh I never been to London. :(
@TheLittleNaruto you're lucky
I'd badmouth it but that might not go down well :P
Or..oh. :)
It has its moments. when the sun is out for that rare 5 minutes every year or so.
08:51
@ParitoshSingh I'm Mancunian, slate it all you want, I'll just amplify it :P
Haha, i see! that works out
@ParitoshSingh Oh what's that?
@roganjosh I want to visit that museum where Kohinoor is kept
@TheLittleNaruto an apparently ill-attempted joke about london weather i suppose :P
@roganjosh Union[LOL, WAT]
@TheLittleNaruto That's the Tower of London, isn't it?
08:54
@roganjosh I mean that famous diamond.
is there any builtin func which can shift a 2D array by referencing a list/tuple?
Yeah, but it's in the tower of london, kinda a museum, but not like the British Museum
Oh sorry I wasn't knowing that.
@MisterMiyagi Can you guys look into this please? It's serious business
@anky_91 "builtin" and "2D array" generally don't mix
08:55
Museum wise, i really liked the natural science and history museums.
@roganjosh Nah, it's fine. refuels escape scape ships
might have gotten the names slightly wrong
@roganjosh You saw that diamond?
@MisterMiyagi right, thats just a usecase
@TheLittleNaruto yes, many years ago
08:56
Nice :)
found this but i was wondering f I am missing something
@MisterMiyagi I follow "Angry People in Local Newspapers" on FB for these gems. Normally it's people squatting and pointing at potholes and their ridiculous comparisons to prison camps etc. The primary response to that article was "You're not qualified to ask the question" :P
@anky_91 if you mean "builtin of numpy", that's usually worth explicitly saying.
ahh got it gotta be more specific :) Thanks
@roganjosh Well, the snooker comparison was very convincing.
09:03
A fantastic thought experiment. The balls should probably be moving at the speed of light for an incontrovertible proof
link dupe of clone/copying list
That was fast
^ closed.
09:55
@Anarach The travelling salesman problem would be a good example. If I have 3 vehicles, splitting the data into 3 clusters helps kick off a solution
^ closed
Thanks :)
wasn't me :P
youre welcome
:D
I was just yelling into the void for interested parties to take my gratitude :P
10:21
Hello there
Ugh, I didn't anticipate this edit though. Why was that approved when I already removed the django tag? :'(
Hello :)
@roganjosh :facepalm:
It is actually very hard to answer questions in Python to get some point
Disagree
lol
@roganjosh why didnt you roll it back?
@alkasm I'm tempted but I think it'll just bump the question and I'm not sure if it has benefit to remove them
10:25
do closed questions get bumped? i dont even know :p
The problem is with the people approving these edits. That one is plain dumb. I'll roll it back
I wish rolling back edits was more productive, in the sense that I wish there was a feedback process for it
@alkasm I think it's "recent activity" depending on what feed you're looking at
@roganjosh i dig your new site
@alkasm No, closing a question doesn't bump it, but reopening it does.
10:30
@PM2Ring cool, ty for the info
@alkasm Oh, cheers mate. I've sorta half dumped the layout at home to improve it but I haven't got round to finishing it. My new laptop has a different resolution to my old one and that in itself has thrown up some interesting issues with the screen looking like it's having a fit
My CSS is... lacking
eh the design is one thing, but the interactivity is well done.
@SaisivaA Please try to write in clear coherent English. I have no idea what you're trying to say in that post, and most of your other messages following that one aren't much better.
Just use materialize like everyone else, problem solved :P
10:34
lol
Pandas users may like to comment on this question, or answer it: meta.stackoverflow.com/q/393290/4014959
@PM2Ring :)
@PM2Ring I'm confused about what it's asking. I don't think it's possible to make such a feature? It's either a) attach the data as an actual CSV or b) just do the decent thing and make some code to generate the df locally. The pandas tag is often painful as it is :/
Jan 19 at 19:49, by roganjosh
I've already built it now :)
It sounds like they want what is a GUI for tabular data. Like excel but with 0 functionality.
An actual SO feature that could be implemented that would be helpful here, is a list of resources that pop up whenever certain tags are added to your question.
Like, if you go to a tag page, you normally get a lot of helpful resources. But I wonder how many newbies know tags link to visitable pages full of helpful info?
10:50
<licks finger and sticks it in the air> 0
@PM2Ring downvoted
@roganjosh why did you delete your answer?
@AndrasDeak I think I misunderstood. I'm not sure they're suggesting the ability to bulk-upload data?
I think just some tooling where you can copy in data. But if an asker can't be bothered to add a sample dataset that can be imported then the question should be closed.
@roganjosh I'm not exactly sure what they want, either. It's probably something like what alkasm suggests. Maybe try to get some clarification in the comments.
absolutely no need to special-case pandas here
(of course this is all moot, no substantial development will happen on main anyway)
11:02
Lol. Well I have a couple of things to do and then I'll re-formulate my answer shortly
@AndrasDeak if we're gonna have anything i vote for mathjax
the speed penalty is ultimately unfortunate though.
<we're not going to have anything>
@alkasm yup, and even then most mathjax-needing questions are off-topic
@AndrasDeak Yeah. Better to teach OPs that they can post tabular data in a triple quoted string. I often do that in my JSON answers.
@AndrasDeak eh, maybe.
11:04
I'm pretty sure I voted to close 95% of questions I've seen with formulae
lol i answer quite a few
41
A: How do I use OpenCV's remap function?

alkasmThis is just a simple misunderstanding of the documentation, and I don't blame you---it took me a few fumblings to understand it, too. The docs are clear, but this function probably doesn't work in the way you expect; in fact, it works in the opposite direction from what I expected at first. Wha...

is my most updooted answer
I guess that doesnt really need it lol, bad example
I don't see any formulae in the question
I have a dataframe in python and I have a column which takes the value "Red 1", "Red 2" , "Red3" etc.. It also takes other colors and I want to keep all the ones that have "Red" and "Yellow". How do I do that? I essentially want to use the str.contains but I dont know how to do so with 2 filters or more
@alkasm MathJax is nice, but it's rarely needed on SO. And it can slow things down. Loading pages with lots of MathJax on the Mathematics or Physics stacks can get very sluggish. Eg, the main MathJax tutorial page is a PITA to load.
@Vasilis Use the bitwise or operator |
11:07
str.startswith might be faster if your example is representative
@AndrasDeak agreed, read_clipboard is already creating issues with some questions , especially the dfs having lists
Case in point
i.e. df['col1'].str.contains("red") | df['col1'].str.contains("blue")
@alkasm thank you, but in general if I have later on 10 filters, is there a more efficient way to do it?
what do you mean by efficient
11:08
I tried to make a list and check in it, but for part of a string it didn't work
not having to type all of them separately
like in execution speed? Yeah....replace strings with something more computable.
but if you just mean typing efficiency...
you could generate all the cases in an iterable and pass them to (or reduce them with?) np.logical_or
@AndrasDeak Maybe, but Yaakov has been dropping lots of hints that more goodies are on the way. I suppose they might just be little things, like the new Timeline icon. But he did say something about improvement to the dupe handling machinery.
@PM2Ring I expect cosmetics
11:12
Most of the time formulae is needed in my answers I am able to link to offsite resources. Overall I try to stick to wiki or something that will likely be around for awhile, but of course there's no telling when a page may be edited and my link ultimately useless. It would be better to provide formulae in-answer.
LaTex in an answer is not a smell. In a question it is.
fair
why am i still in this chatroom
i need to go to bed
goodnight yall
@alkasm You could use CodeCogs, and upload the image, as discussed here: chat.stackoverflow.com/transcript/6?m=43036403#43036403 Eg,
@alkasm night
11:38
@AndrasDeak edited
12:00
Thanks
12:42
I propose that, to be more animal friendly, we replace the metasyntactic variables "spam" and "eggs" by "tofu" and "quinoa", respectively.
spam doesn't harm animals
You should go join the BBC or SO. There's probably some good commission to be earned with this nonsense
@AndrasDeak ?
I'm not even sure it's organic (as in organic chemistry)
Err spam. It definitely has meat in it
@AaronHall "What does a successful meeting look like?" I'm not sure, I don't have much experience in talking with CEOs of big companies. If you can reassure us that SO Inc is in good hands, and that you're optimistic about the future direction that Prashanth wants to take us, that will be great. I'm just pleased that he wants to speak with a dev who is intimately familiar with how SO works.
12:47
@roganjosh definitely allegedly
@AndrasDeak The important thing is that it's not chlorinated. Whatever it is.
hopefully also asbestos-free
It's probably the EU that forced us to remove all that stuff. It's a good job we have global warming to counteract our loss of insulation
I get the feeling that the CEO & most of the rest of upper management don't realise how fragile the SO knowledge base is, and how much it depends on the hard work of the power users to curate it. They think it's like gold in the vault, whereas in reality it's more like a wine cellar. Some of the vintage info will age well, but some of it has a short "best before" date. And all of it is in danger of being lost in the flood of low quality questions and low quality answers.
@AaronHall On a related note, upper management seem to think it's a bad thing that so many devs use SO via Google (etc) without logging in & participating in voting and writing questions or answers. So they're trying to figure out how to increase the participation (and retention) of both newbies & experts.
But I think that's a little misguided. I was using SO for 3 or 4 years before I signed up. And I didn't sign up to ask a question, I did it because I decided I ought to contribute, to pay forward the help I received.
But that neglects the culture shift. You already had experience with programming and you're not of the new generation where answers just get farted out by google; there is definitely a sense that SO can just be a programming Google
13:05
@roganjosh what do you think a successful meeting looks like?
@AaronHall That's a really interesting question. I'd really need to think about it in context and get back to you. I'm in the camp of saying "that won't work" at the moment and that's not helpful
by not "working" there must be a goal in mind. The goal may be unrealistic. Maybe we shouldn't focus on a goal, and instead talk about the systems.
@roganjosh True enough. OTOH, I do use SO as a programming Google, but I've got reasonably good searching skills, so I can almost always get useful info by searching existing questions. Newbies, especially those just learning their first language, may not be so good at doing that. But I agree that there's a culture shift in that the younger people are less likely to put in sufficient effort in their prior research.
My goal is exactly what I thought the site was when I joined; to be a repo of canonical questions and answers. I had a really rocky start, for sure, and I also asked crap questions. But, ultimately, I sucked up the close votes or dupes
Social media has added a lot of weight to upvotes/downvotes. There's no way that people can't take that system personally. As for its replacement.... ??? ... profit?
I'm looking for a puzzle I saw online. It advertises itself as something like "95% of Harvard grads can't solve this!". It's a simple-looking equation along the lines of "A/B + B/C + C/A = 1". The puzzle actually understates its own difficulty, because the only solution has 150 digits and you need a phd in elliptic curve geometry to find it. Does anyone know what I'm talking about?
13:13
If Aaron walks out of the meeting feeling that both he & the CEO have learned important stuff, I'll count that as a positive outcome. OTOH, if he feels that the CEO just spouted a bunch of corporate speak buzzwords, and isn't genuinely concerned about the well-being of the knowledge base and the people who've each invested thousands of hours creating & maintaining that content, I will be sad.
@PM2Ring I use it as a Google in-so-far-as I find the Q/As that have come before. I was talking more about people that ask questions. It's really wonky. There's plenty of questions where you could just c/p the title into Google and get the response, so they wasted their own time asking, and ours reviewing it
@Kevin is the NSA recruiting?
@Kevin I think it's called "Quora".
Ah, writing the description of the puzzle down clarified enough details in my memory that I could find it... I was thinking of thousandmaths.tumblr.com/post/165586298459/…. See mathoverflow.net/questions/227713/… for a lot of math that I don't understand.
@roganjosh Yes, it is wonky, and you're right, it does seem to be a generational thing of people expecting the Internet to be a genie that instantly grants their wishes.
13:22
That's what leaves me at a bit of a loss on how to tackle the issue :/
Another issue is that we're regulars in the python chat room. Given the traffic, it's enough to suggest that we're not "normal" site users
However it is the people in this room, or similar, that try to hold the site together
I think of us as the band members on the titanic that played as the ship sank
I don't know the best way to tackle it either. Just providing better documentation isn't sufficient,
because those people don't bother reading the Help pages and familiarising themselves with the site mechanics & culture before posting their 1st question. And partly it's because there *is* a steep learning curve to the site. For some of these people, it's hard enough for them to even find the right place to post their question: every day MSE gets "lost soul" questions that should be posted to SO, or some other main site.
We cannot get out. The end comes soon. We hear drums, drums in the deep. They are coming.
13:40
I like the titanic metaphor better, because at the end our skeletons become vibrant ecosystems for small undersea life c:
@Kevin Wow. That's pretty crazy! I kind of understand some of that maths, but a lot of it goes way over my head. I know there are ways to produce other rational solutions to elliptic functions, given 2 solutions. But finding integer solutions (without a brute force search) is a lot trickier. Also, proving that a Diophantine equation has no solution is equivalent to the Halting Problem: that's Hilbert's 10th problem. en.wikipedia.org/wiki/Hilbert%27s_tenth_problem
I am pleased to live in a universe that contains very simple questions with very hard answers
I'm reading a book that asks "why does the universe exist?" and I think that's a pretty good example of that category
@Kevin Judging by the last few questions on main, we're already sunk.
After 5+ years I'm completely desensitized to all "SO is dying" chat so I'm just going to keep doing what I've been doing
Aug 2 '16 at 16:41, by Kevin
I call dibs on being the last person in the room, wistfully gazing in the dim light of dusk at all the chairs upturned on the tables, and turning the lights out and climbing the stairs to the entrance, while the credits roll and a tinkling minor-key version of the intro music plays
13:56
Wow that sounds so sad haha
@Kevin That feels like reading a novel
I think I was ripping off of Cheers specifically at the time, so less "novel" and more "well-regarded TV show"
@Kevin Fair enough, but do you have a message for the CEO, considering we have a channel? I'm annoyed with myself for not having a solution but, perhaps, your optimism can be passed on
"Please make backticks work on multiline chat messages"
hahaha
14:05
I've pontificated enough about site culture over the years to conclude that it's a hard problem and my usual approach of "aggressively apply high school level mathematics to everything" is ineffective. Do we have a Sociology stack exchange? Ask them for advice.
14:25
cbg \o
thinking if i should trust codidact with a generated account or should i log in with github
The monkey's paw curls one finger up... Backticks now work, but every neophyte that uses them does so in a way that mangles all whitespace
`if True:`
    `print("Hello, world!")`

Becomes

if True:
print("Hello, world!")
        Hey guys. Before I post my question on SO, I wanted to hear if it is stupid question so to avoid a lot of downvotes. So my question goes like this: "What is the deal with self.name in descriptors?"

    class OneDigitNumericValue():
    	def __init__(self, name):
    		self.name = name

    	def __get__(self, instance, owner):
    		if instance is None:
    			return self
    		return instance.__dict__[self]

    	def __set__(self, instance, value):
    		instance.__dict__[self] = value
The question could probably benefit from some context. Did you write these classes yourself? Are they from a tutorial somewhere?
14:40
Uhm, I wrote the last version myself.
I thought that might be the case. What about the first version?
I came up with it myself -- I just thought it was weird that you had to instantiate the descriptor with a name.
So I removed it and found that my new "descriptor version" works just as the old version.
Just better -- because now you don't have to type in the name on instantiation
But of course, there must be a reason why people don't just do that .. right?
How do you know that you have to instantiate a descriptor with a name? Is there a tutorial or documentation that says this is mandatory?
Well, the reason why __set_name__ was introduced in python 3.6 was to avoid having to instantiate descriptors with these annoying "names", so I guess it was a widespread way of doing it before __set_name__ was introduced
I am not sure though.
This is the blog post where I got the first version from: realpython.com/python-descriptors
@SebastianNielsen usually, descriptors needed to know their name because they actually used it. If you pick an example that doesn't, it shouldn't be surprising that there is no need for it.
14:46
+1
@AaronHall to see how the site has gone astray with different communities this. I really hope nobody votes on that because it's a perfect, organic, example. 4 upvotes; I can barely get that if I threw all my numpy-foo at a problem
The descriptors4.py example on that page has that self.name code because it wants my_foo_object.name to evaluate to the descriptor object instead of a number. If you don't care about whether the descriptor object is inaccessible*, then you don't need to do anything with the name.
the PEP has an example that actually uses the name.
(*or, at least, harder to access. You can still get to it with __dict__ trickery... I think)
Note that __set_name__ also passes in the owner, which allows a descriptor to initialise itself for that specific owner.
e.g. setting a default value, adding storage, etc.
14:52
Okay, thank you guys.
Or, hmm, now that I run the code, it doesn't do what I expected
Disregard my previous statement while I play with this
I mean, the only difference between the first and second version is what key is used to store the value in the dict of the instance.
your examples use the exact same key -- self
which by the way isn't a good idea, since __dict__ keys should only be str
Oh, that's a bumber
The first version should had used "self.name" as the key
This is how the two versions was supposed to look
Uh, I didn't know that dict keys should only be str
that must be why people prefer the first version
Hmm, but why is that the case?
@SebastianNielsen dict keys only need to immutable
15:00
@SebastianNielsen __dict__ keys are normally attribute names, which are always strings.
Not sure whether to interpret "__dict__ keys should only be str" to mean "if you put a non-str key in __dict__, then something bad will happen", or "Straightforward and logical designs put only non-str keys in __dict__, so doing otherwise means your overall design isn't as good as it could be"
The latter I agree with, the former I find dubious
Uh, I interpreted what misterMiyagi said as the first one. Good thing we just cleared that out.
@SebastianNielsen __dict__ often isn't a dict but some wrapper around an internal storage. These usually have a fast path/optimisation when keys are str.
user10984358
How does one apply a "bitwise mask"? If context is needed I am trying to do this docs.microsoft.com/en-us/windows/win32/taskschd/… , lets assume task_obj is where I want to do this mask
They will still work with other keys, but can have performance and memory penalties.
15:03
@Kevin I think you meant "Straightforward and logical designs put only str keys in __dict__"
Ok, "it's not as fast" is a satisfactory instantiation of "something bad", so that works for me
@MisterMiyagi Okay, that explains a lot.
@PM2Ring Oops, yeah
@TheNamesAlc There are a number of ways to interact with a bitwise value. They usually involve the bitwise operators &, |, ^, >>, <<. For example, if you do WeeklyTrigger.DaysOfWeek & 0x20, then the result will be zero if the trigger does not occur on Friday, and 32 if the trigger does occur on Friday.
(keeping in mind that 0x20 == 32)
@TheNamesAlc bitwise operations in Python work practically the same as in other C-derived languages, including C#
You can determine the status of any day of the week by &-ing the property against the corresponding number shown on that table. The result will either be zero, or the number.
user10984358
15:09
I was meaning to ask that how can I know what is set
@roganjosh Sebastian's actually talking about the special __dict__ attribute of a class instance, but he forgot to use backticks. ;) But anyway, in general the keys of a dict must be hashable. Python doesn't prevent you from using hashable but mutable keys. However, if you do mutate such keys, Bad Things are likely to happen.
If you want to change the property, you might combine together values using |. For example, if you want the task to trigger on Monday, Wednesday, and Saturday, you might assign to it like WeeklyTrigger.DaysOfWeek = 0x02 | 0x08 | 0x40.
user10984358
that is what I am trying to do, how does one decide whether to | or &, I have never done bitwise arithmetic, any reference ?
@PM2Ring an important distinction, thanks for pulling me up on it :)
No worries. :)
15:16
@PM2Ring Hi, welcome to my mutable string class. Usage: `import mutable_string as evil; str = evil.
@TheNamesAlc en.wikipedia.org/wiki/Bitwise_operation goes over the topic in some depth. You can probably also find a number of tutorials by googling "bitwise operations". They work nearly the same in most mainstream languages, so don't sweat it too much if the examples all start with public static void main.
It may also be worth reading en.wikipedia.org/wiki/Mask_(computing) to get an idea of what a "bitmask" is. TLDR: It's a single number that represents multiple boolean variables.
@TheNamesAlc I just found this, searching for bitwise arithmetic tutorial. It looks ok. hackerearth.com/practice/basic-programming/bit-manipulation/…
user10984358
thanks guys, I will look into these now
If you've ever used chmod, the number you give it is effectively three consecutive bitmasks. "7" means "read, write, execute", "5" means "read, no write, execute", etc etc
So I'm taking Google's IT Automation with Python Professional Certificate on Coursera hoping to learn something...and they're using os.path instead of Pathlib for managing paths...is there a good reason why?
user10984358
15:25
ahh, never realized that till now TIL
...because I can't think of one. Especially if this is your first foray into Python or handing files and paths.
I use os.path instead of Pathlib because I can't be bothered to learn both
It is written, "There should be one-- and preferably only one --obvious way to do it."
@TheNamesAlc Good luck! It's hard for me to judge what's a good tutorial for this stuff. I've been doing it for so long that it's kinda hardwired into my thought processes. :) A closely related topic that's worth Googling is "truth tables".
user10984358
the only bitwise hack i know is to use XOR on two lists to find which element of a list is not present in the other list, assuming each element appears once and only one element is missing
@toonarmycaptain Maybe that Coursera stuff is old, predating the pathlib module. Also, IIRC, Google tends to be very attached to Python 2.
15:30
When working with bitmasks, XOR doesn't come up as much as AND and OR. You can use it to toggle a bit in the bitmask without knowing what its original value was, but I'm struggling to imagine a scenario where that would be practical
@PM2Ring It might be, but it's supposedly a brand new course. Some of the dates in the videos indicate filming sometime last year.
@Kevin Nothing wrong with that, but pathlib.Path has some very helpful methods, and you don't have to worry about getting separators right nearly as much as if you play with the strings yourself.
Ok, I think I understand the descriptor problem from an hour ago. The name property is useful because it's typical for a descriptor to store data relating to the object instance. A logical place to store data about an object is in the object's __dict__. But the descriptor object doesn't know much about how the instance object will be manipulated by the rest of the code, so it can't just pick an arbitrary string value for the __dict__ key.
If you invent a key like "DescriptorActualValue"`, then there's a small chance that another completely different descriptor will also use that key, and one will overwrite the other. That's bad.
The safest option is to use the descriptor's class attribute name -- in a sense, the descriptor "owns" that name and any code that tries to manipulate that name is probably aware of this. And there's no chance that two descriptors will have the same class attribute name*, so a collision is impossible
(*unless you're doing something wacky with, like, inheritance or nested descriptors or something)
15:48
@PM2Ring wait is there a known reason on why google prefers Py2 over 3?
@Kevin Exactly. And also the fact that it is faster to store key-value pairs where the key is of type string in __dict__, as it apparently doesn't work exactly like a dictionary.
16:07
Note that there is no constraint that the strs one puts into an object's __dict__ must be valid identifiers. You just can't access them using '.' notation, but getattr() can still pull them out.
class Z: pass
   ...:
z = Z()
setattr(z, 'a', 1)
setattr(z, '%', -1)
z.__dict__
Out[24]: {'a': 1, '%': -1}
vars(z)
Out[25]: {'a': 1, '%': -1}
z.a
Out[26]: 1
getattr(z, '%')
Out[28]: -1
'%' even shows up in dir(z)
Yep. So if your descriptor chooses an arbitrary key like "%$!#$!#@descriptor actual value", then the chance of collision gets smaller, since code that creates/accesses attributes in the normal way won't overwrite the value. The chance is still greater than zero, since the hypothetical other descriptor accesses the __dict__ directly, so it's still worthwhile to use .name
To minimize chance of collision, choose a variable name that contains today's date, your full legal name, your bank account number and PIN, and one secret that you've never told anyone
@MooingRawr Maybe my info is a bit out of date. I know that a couple of years ago some Google APIs were still Python 2 only (there are Stack Overflow questions about it), but I think that's changed recently. Also, they converted a lot of their internal Py 2 code to golang. See github.com/google/grumpy
if {1:
    2}:
    print("OK")
I wrote this for a comment on the main site and my brain segfaulted
16:23
I knew about GoLang, I think it's time for me to pick up goLang
I wonder if the cookies are spherical. Couldn't tell from the picture.
That would explain why it takes longer to bake them, since heat permeates a disc faster than an orb [citation needed]
Acid trip come true
I blame reduced convection inside the oven. Warmer air only goes up if there's an up
@Kevin heat permeates a disc faster than an orb (you can quote me on that)
Unless it's a superfluid
@AndrasDeak would it be more correct to say that cooler air goes down then? because isn't it gravity attracting the denser cooler gas more than the less dense warm air?
17:08
@Code-Apprentice the important part is that cool and hot air swap places. Nothing happens with just cool or just hot air.
@Code-Apprentice potato potato. Fluids position themselves according to density
Yes, so if you spun your space station like the one in 2001, then the resultant "gravity" would "pull down (outward)" the colder air, so that the warmer air "rises/moves inward".
@AndrasDeak Let me rephrase my question: do fluids rearrange themselves in this way in the absence of gravity?
@Code-Apprentice gravity is needed to define "up" and "down"
ok, that's my understanding,t oo
17:13
What if the fluid was gaseous iron, would a cooler/denser region of gas be more attracted to a magnet, and so displace the warmer/less-dense iron gas?
it works for any force and charge.
I recall some discussion of there being an element of different structures forming within the dough due to the absence of compression provided by gravity, and that it took more time for these to turn into those in what we'd regard as a cooked cookie?
@Code-Apprentice no, hence my original remark
info on the oven in question. It doesn't use convection, for reasons that we have guessed
That's why flames are weak and spherical in space
17:22
The packaging in which the cookie dough sits is more obviously flat in these pictures, so I'm now inclined to say the resulting cookie is not an orb
@PaulMcG atomic iron is probably paramagnetic, not ferromagnetic. My vague guess is that a typical magnet is too weak
I wonder how hard it would be to combine the oven with a centrifuge so it has artificial gravity
If I'm reading the formula from en.wikipedia.org/wiki/Artificial_gravity correctly, a 0.25 meter radius cylinder only needs to rotate once a second to get 1g of artificial gravity
@Kevin A podcast I listened to suggested that this had been considered, and that rotational speeds required wouldn't be all that high.
Why would convection be so difficult in zero G? Maybe I missed something, as I assumed that was more a safety issue/that oven's really small.
@Kevin I believe the suggestion was that, as has been suggested for human habitation on the moon/mars, the full 1g might not be necessary.
I wonder if it would make a difference that there would be a substantial difference in apparent gravity at the boundary of the cylinder compared to points closer to the center*. I might expect particularly fluffy recipes to be disproportionately denser at the base.
Compare to on Earth, where the force of gravity at sea level and the force of gravity 25 cm above sea level are effectively the same
(*... Or at least I think apparent gravity gets weaker as you approach the center. I haven't done any math, but it seems right)
@Kevin Get a larger cylinder? I imagine a 'full size' oven for a crew of several on the way to Mars might be a meter plus rather than a foot in diameter. My home oven's not far from that, corner to corner.
17:33
@AndrasDeak yes, I'm coming full circle back to that
@toonarmycaptain Yeah, that would help. The larger the cylinder, the less obvious the gravity gradient. Of course, the bigger the oven is, the more expensive it becomes to put it into orbit.
@toonarmycaptain Hmm, perhaps there is a terminology mismatch going on. "Natural" convection as described in en.wikipedia.org/wiki/Convective_heat_transfer occurs thanks to bouyant force, which doesn't exist(?) in zero-g. Other kinds of convection can use other kinds of forces. Conventional convection ovens use fans, for instance. I suspect fan-driven convection would work fine in space.
Perhaps there is also an unspoken assumption that conventional convection ovens use both fans and natural convection, and so they would be less effective in space. Unclear to me how much each kind of convection would contribute.
@Kevin Apparently they already use one up there, but it only goes to 80C or something. Presumably because their meals tend to be pre-cooked and so they're really just warming.
17:49
print "hello world"
I know that waste heat dissipation is pretty hard for space stations, since you can't convect or conduct in a vacuum. I wonder if that's a concern. Or maybe having an oven at 425 for a few hours is peanuts compared to the heat generation of all the other systems, idk
nasa.gov/pdf/473486main_iss_atcs_overview.pdf tells me that the "PVR" can radiate 14 kW of heat into deep space, and the ISS will have four of them. Somebody math this out.
@xitas SyntaxError: Missing parentheses in call to 'print'
00:00 - 18:0018:00 - 23:00

« first day (3387 days earlier)      last day (1778 days later) »