« first day (3657 days earlier)      last day (1274 days later) » 

1:32 AM
^^ closed
 
 
2 hours later…
Joe
3:23 AM
Question. We had someone post a question on that refers to a question that I'm curious what people think of nowadays.
0
Q: How to make good reproducible SAS examples?

Bill HuangDisclaimer: The URLs of the Pandas and R example-making guideline posts I cited below (both highly recognized by the community) are on SO, not on Meta. I think there must be a strong reason for such posts to remain on SO, so I followed the de-facto status about where such "make good reproducible ...

It refers to this question: stackoverflow.com/questions/20109391
That question is very old, dating back to 2013
Is there a particular reason that is on stackoverflow.com and not on meta.stackoverflow.com?
On one hand, it is certainly a sort-of programming question
But on the other hand - it's not exactly not a question about StackOverflow
 
 
1 hour later…
4:43 AM
I know that the spacing for indents matters in Python, but does the spacing within the lines of code matter? I'm skipping this edit in the Suggested Edits queue but I'm wondering if count = 0 instead of count=0actually matters or is a style preference.
 
5:00 AM
its a style preference afaik
 
5:42 AM
does using map count as a "not using loops" solution, I can only think of recursion otherwise?
one question I was told is "print from 1 to n" without loops
 
 
1 hour later…
6:56 AM
Any idea why Flask won't display `footer`?
I am trying to add a custom footer but nothing will show. Typically, the use of `{%block footer%}{%endblock%}` should be able to do the work
 
7:21 AM
@python_learner It depends on how the person who asked this question thinks about it, I guess. 'map' eventually iterates over the iterable so it should be a loop by definition. Just my opinion.
 
8:02 AM
@Joe the only reason is that these can be used as dupe targets. I don't agree with that. These should all be on meta.
 
 
1 hour later…
9:24 AM
Has anyone ever heard of a situation where a Python program fails and then deletes all of it's own dependencies? Wide question I know but I'm just stumped about how this could even happen?
 
@BSMP Indentation is only leading whitespace. However, PEP8 has some things to say about idiomatic formatting. Using consistent PEP8/black formatting makes it somewhat simpler to read code for people used to it.
@JamesMcIntyre Do you mean that the "deletes its own dependencies" is an intentional error handling, or itself an error?
 
itself an error. I've definetly not created any code to delete the dependencies
as in the program gets 90% through and then stops, errors, deleting it's own dependencies
It's the weirdest thing I've ever come accross since entering Python
 
9:43 AM
I take it nobody else has ever experienced this or could see how it could ever happen?
 
so just to be sure: the program uninstalls some packages when it encounters an error?
that should not happen unless explicitly writing quite some code for it.
 
Scrap this sorry guys. My fault. I was being an idoit
 
what was it?
 
I forgot this was the one project I use which uses "compiled" exe file rather than a .py file which I use for all of my other projects now. Hence the dependeices where never there
 
10:03 AM
Hi everyone, I am trying to basically recreate a json structure
Now I know that a python dict cannot have a duplicate key
So if I am trying to create a json structure by appending to an empty dict how should I go about it?
 
@JamesMcIntyre that might happen with vigil
 
Any site you can link me to regarding this will help as well
 
@RaphX can json have duplicate key?
 
I think yes @AndrasDeak
 
weird
> An object is an unordered set of name/value pairs. An object begins with { and ends with }. Each name is followed by : and the name/value pairs are separated by ,.
hmm, I guess that does indeed say nothing about uniqueness
 
10:09 AM
hello, can someone let me know what is different between this two url path in django urls.py > url(r'^books/$', views.book_list, name='book_list'),

url('books', views.book_list, name='book_list'),
r'^books/$' and 'books'
 
10:38 AM
A JSON can have the same key multiple times the same way a Python dict literal can have the same key multiple times.
 
That's what I figured. There's nothing in the grammar specification forbidding it. But does it make any sense?
 
What that means is not in the JSON spec, and practically all JSON parsers seem to remove all but the last occurence.
@RaphX Are you sure you need the same key multiple times, and not just multiple values for a single key?
 
@MisterMiyagi I do need multiple values for a single key but it shouldn't be like 'id':[1, 2,3], rather it should be {'id': 1}, {'id': 2} and so on
 
that's not in the same object...
Do you really want to go from '{"id":1, "id":2}' to [{'id': 1}, {'id': 2}]?
 
Now I'm confused. Do you need a) {'id': [1, 2, 3]}, b) {'id': 1, 'id': 2, 'id': 3}, or c) [{'id': 1}, {'id': 2}, {'id': 3}]?
 
10:45 AM
this is sounding more XY each minute
 
could be Z...
 
(c) @MisterMiyagi
 
now figure out the input...
I'll leave you to it
 
Catch 22: None of these were valid JSON! runs off, laughing
 
Ok this is not a JSON then?
I have the input list here: dpaste.org/Jy2y
 
10:48 AM
@RaphX All of them are Python literals. JSON requires strings to use double-quotes.
 
Okk I didn't know that
 
Urgh... why is lru_cache.cache_info() a namedtuple, yet lru_cache.cache_parameters() is a dict? D:
 
 
1 hour later…
12:04 PM
I have a doubt about the triage review queue. Isn't my review on Triage 27424679 appropriate?
I selected Requires editing. and now I'm suspended from reviewing. Although that doesn't affect me in any way but I'm curious to know.
The message from SO tells me that I should've selected 'unsalvageable' but here is my point. The post can be better if the OP edits his question to include details that are needed, called as debugging details.
Shouldn't the options *Requires editing and * Unsalvageable have at least some flexibility between them. I mean even after the question gets closed for lack of details, isn't it better to ask the OP to include more instead of just shutting the question down without letting them know. There may be people who do not know what to include in a question and what not to. Am I missing the plot here?
 
Is there a good canonical answer to close questions like this one? I have seen these so many times and the answer is always the same...
 
12:42 PM
@PSSolanki requires editing means someone other than the OP should edit the question.
If information from the OP is required, that is not "requires editing".
Yes, that is totally non-obvious.
@Yatin Yes, there is. I've hammered the question now.
 
@MisterMiyagi thanks :)
 
Thanks to you for taking the time to bring this up. :)
 
"I want to build a Facebook, but for dogs" resists temptation to google for Facebark
 
12:58 PM
"Hold on, let's hear him out." [votes to reopen]
 
1:27 PM
Trying to work with a semi-documented API in an environment where I can't open a REPL or shell, but I can create a window with tcl... Someone hold me back until the urge to use eval() subsides
 
can you pdb.set_trace()?
 
@Kevin Go for it!
 
@NicolasGervais well, it's a redundant answer that came 30 minutes late
 
The earlier answer's approach of "fix your ValueError by overwriting your data with a useless static integer" is... interesting
 
1:38 PM
@AndrasDeak I gave this answer 30 min in the comments BEFORE someone else just copied it and posted it as an answer based on OP's feedback to my comments
 
@NicolasGervais so? Don't answer in comments.
plus posting answers here without any comment just comes across as fishing for upvotes, which I'm not crazy about
 
I have no idea how people survive writing hundreds of lines of code, yet fail to comprehend the difference between "a value" and "many values". Perhaps SO knows the answer...
 
Same
 
To be fair, "many values" can simultaneously be "a value" (i.e. a list, tuple, etc), so it's a bit more complicated than you're making it out to be
only a bit though
 
You are right. They'll get a one minute headstart before I release the hounds.
 
1:43 PM
*nods* that sounds fair
 
the hounds are actually called Poodles and Fuzzums, and they only do static type checking
 
Hey guys just a thought I am busy thinking of finding a way to run a load of custom validations over a database object before commiting it to the database. instead of doing it in routes I would like to send it to a separate function in order to keep my routes from getting messy, am I right in thinking I should be able to send the object to another function without issues
 
Objects can always be sent to functions
[I reset my "days since Kevin made an unqualified 'Always' statement" sign from 193 to 0]
 
lol
ok good just wanted to ensure my train of thought was good
 
It is written, writing more functions can solve anything except the problem of too many functions
 
2:06 PM
What if you write a function that writes functions?
 
There was a question on the main site yesterday asking how to do that
Something along the lines of "I want to repeat my code. Not with a for loop, I want each line of code to appear more than once in the source"
 
@AndrasDeak There is a romantic in me that thinks 95% of Python SO questions could be solved with static type checking. The realist in me knows that most of these questions are due to people fundamentally misunderstanding types to begin with.
 
My crystal ball indicated that they wanted to be able to do a = f(); b = f(); c = f() without having to write it out every time
 
Please tell me someone posted an answer that just said "Ctrl+C, Ctrl+V"
 
@Kevin Macros! Yay!
 
2:13 PM
I can't find the question now so its fate will be a mystery
 
@Kevin lol I just think its a good idea to have one liner that goes to another file than having loads of if statements in a route no?
 
Sure, I do things like that all the time.
 
@Kevin unless it's multiprocessing.Pool.map or similar where the objects need to be serialized :^)
 
I'm not backtracking on this one so just assume I reply "that doesn't count" to all the counterexamples
[I reset my "days since Kevin has been pointlessly obstinate" sign from 1 to 0]
[I reset it again, since I'm having a slapfight on the main site over what "long" means, but this is an idempotent operation]
 
3:00 PM
I wonder what the usual turnaround time is for the "ask the Python devs" thing. Submissions closed a while ago, right?
 
I was looking at this question and was wondering what "SoA" and "flat reference" are... Can someone just give me a very basic direction of what these things are... I looked up SoA and it says something about "Service-oriented architecture"... I just wanted to confirm that this question is infact refering to the same thing...
idk what a flat reference is though
 
Oh, it's today: "On Tuesday, October 20th, 3 PM US Central time, Python core developers will get together (online) and answer your questions. The session will be recorded and will be posted to The PSF’s YouTube channel." Radical.
 
@Yatin SoA might be "struct of arrays"
 
hm... how does structure of arrays increase speed?
I mean aren't NumPy arrays crazy fast themselves?
 
I'm pretty sure trailing [:] indices are always (essentially) no-ops in numpy
 
3:08 PM
SoA means you have something akin to {a: [0, 1, 2, ...], b: [0, 1, 2, ...]} instead of [{a: 0, b: 0}, {a: 1, b: 1}, ...]. The former has much better locality since all a's are together.
 
(they create nanometer-shallow copies)
 
Basically what they are asking is that they want the former as the in-memory representation, but index it to get a wrapper that looks like an object of the latter.
 
it might matter that the construct OP is using is called a structured array
 
So, get_wrapper = lambda idx: {k: v[idx] for k,v in soa.items()}?
 
OOh! all this seems like a completely alien concept to me.. will look into it in more detail... thanks for the direction :)
 
3:10 PM
uh, looks like I misinterpreted the second part.
 
I'm not gonna pretend that I can read numpy code, but I'm pretty sure that OP actually has an array of structures, not a structure of arrays...
 
I see a lot of neophytes independently invent SoAs by accident when they try to make an rpg or whatever. So monster_hps = [23, 42, 100]; monster_weapons = ["knife", "knife", "club"], and then they can't figure out how to pass one Monster object to another function.
 
@Aran-Fey agreed with both
 
@Kevin oh yeah I heard about this
A lot of data was lost because they were using an old version of excel to store data
not saying the excel is the best thing to store such vital data though :)
 
3:18 PM
@Aran-Fey it's an array that has a structured datatype (rather than a homogeneous numerical type)
 
Hmm, I may be confusing this with a different story. The one I'm thinking of, they ran out of space much faster than anticipated because they were storing each entry in its own column rather than its own row. The column limit in Excel is much lower than the row limit, so it went kaput after like 26^3 entries.
 
Could be a case of AoSoA, come to think of it...
 
I think I know what their issue is
 
a bad problem description?
How are those numpy thingies called where you slice but do not get back a new array? Are they views?
 
3:31 PM
Excel has ten times as many users as every programming language combined, we will never be rid of its dark influence
 
I guess that's one way it lives up to its name
 
You'll find it everywhere you go except in century old ships at the bottom of the ocean
 
@MisterMiyagi yes
that's the nanometer-shallow copy I meant
 
You might still find VisiCalc, and maybe the odd Enigma machine
 
3:36 PM
@MisterMiyagi yes. OP wants a writeable 1d view into their data, they just didn't express it very well that they can only do this for a 2d view
 
I wonder how hard it would be to make low-background steel by sealing the furnace off from the atmosphere and manufacturing your own air using, say, electrolysis.
Since steel production facilities are quite large (citation: Terminator 2), I'm guessing "hard"
 
What kind of background? Radioactive? It's hard to get rid of it in any kind of input material.
 
According to the wikipedia article, the iron we dig out of the ground isn't especially radioactive, it gets introduced to the steel because of the cobalt-60 hanging around in the air.
 
huh
How about the carbon?
I guess if it's mined coal it can be fine
 
3:54 PM
I'm guessing it's a solvable problem, but way more expensive than salvaging sunken ships
Contrast to, say, the gradual loss of helium into space, which we can't synthesize with clever chemical processes
 
4:09 PM
really?! Helium can't be synthesized?! I learned something new today
 
You can make it with nuclear processes by, say, irradiating lithium
 
real pros fuse hydrogen
 
If you have a lot of tritium hanging around, go for it
 
and technically alpha radiation is helium, but that's not very sustainable
 
I think I've read one too many scare articles about the irreversible loss of helium into space, because they led me to believe that we'd eventually* run out of helium and never be able to get any more, but in fact more is being generated in the lithosphere constantly thanks to natural radioactive sources
(*on a less than geological scale)
"All the helium atoms are completely gone forever" is different from "all the helium atoms are in the ground and there's not enough economic incentive to dig it up"
 
4:11 PM
five years ago or so experimentalists went through a helium crisis, when the isotope they needed for their cryogenic systems was at a global shortage
which you probably know, but others might not
 
I knew that scientists were scared about climbing prices, but I didn't know more detail than that
 
"crisis" is such an ugly word...
let's call it "lack of funding to offer bribes"
 
Yeah, I only saw the outcome: "we can't do experiments because we don't have helium and we don't know when we'll get some"
 
There's no crisis, capitalism allocates resources efficiently and it turns out society values balloons more than they value experimental research.
 
my blockers are of the "the A/C went down at the hpc center again" variety
 
4:25 PM
@AndrasDeak commandeer more HPC centres, then :P
 
4:36 PM
"research requiring cryogenics etc will become less common as He prices rise" is largely unavoidable, but we should probably do something about "a lot of experimentalists will be out of a job overnight when the He reserve drops to zero"
Let's try to flatten that cliff into a nice gentle curve so they have enough time to take a numpy bootcamp and jump the sinking ship
 
4:50 PM
Erm, we do... guess were half of the people on SO come from?
 
 
All Tiny Tim wanted for his birthday was a little floaty balloon giraffe. All was good with the hydrogen replacement until it came to the candles.
 
Luckily most of the partygoers escaped unharmed because they were attending virtually. Two crises cancel each other out! Many such cases.
 
5:20 PM
I am afraid , if someday my teacher asks me to write "blah...blah..blah" 100 times on the board for not doing homework I might
write **print(("blah...blah..blah\n")*100)
** :P
 
dang! I wish I had that kindfa presence of mind when I was younger. Would have totally driven my teachers crazy
 
@inspectorG4dget Haha :D
 
6:19 PM
 
6:44 PM
if I ever get called to the principal's office because my child did that, I'm totally high-fiving the kid
 
# my kid knows Python :)
for _ in range(500):
    print("I will not throw paper airplanes in class")
 
7:34 PM
# my kid golfs python
print(*["I will not throw paper airplanes in class"]*500, sep='\n')
 
7:59 PM
# my kid obfuscates python
print(vars().__setitem__('__', vars().__setitem__) or __("____", "decodebytes") or __("_____", "base64") or __("___", getattr(__import__(_____, fromlist=[____]), ____)) or ___(b'SSB3aWxsIG5vdCB0aHJvdyBwYXBlciBhaXJwbGFuZXMgaW4gY2xhc3MK').decode()*500)
 
y'all should stop having kids
 
@PaulMcG just... Oh my. All those times I've said to people that "it's not possible" to reasonably obscure a Python program that you distribute to other people. Honestly, I'd just give up and pay the license before working through that :P
 
If i have 5 folders with each having a test_ ... .py file. What ways does pytest provides to each one with the same config?
# woops let me try some more before asking
os.system('cls')
 
8:23 PM
I'm still giggling at that like a 14yr old at the school dance
 
9:11 PM
@PaulMcG I know you're a parsing wizard but I feel like you're generating this with some ease. I feel like there might be some simple principles (if you know them) like MRO guiding you?
When they're found together, it becomes hard to differentiate the basic steps. I know a wizard shouldn't reveal their tricks, but any hints? :P
 
anyone experienced in pyqt? i wonder how to setText() into "show details" button on QMessagebox. I'm afraid that I will get downvoted for this
theres no button role for showing details. beside there's 2 trigger. show details and hide details
I need to change the text to be familiar with my client's language. using the included pyqt translation function is just overkill and inaccurate mostly for my language (Indonesian)
 
9:28 PM
@roganjosh I started with:
print(bytes.decode(base64.decodebytes(b'SSB3aWxsIG5vdCB0aHJvdyBwYXBlciBhaXJwbGFuZXMgaW4gY2xhc3MK'))*500)
But to get around importing base64, we need __import__
base64.decodebytes -> __import__("base64", fromlist=["decodebytes"]).decodebytes
                   -> getattr(__import__("base64", fromlist=["decodebytes"], "decodebytes")
Knowing that __setitem__ returns None, we can use any() with a succession of __setitem__ calls to vars(), beginning with a defining "__" as vars().__setitem__.
Then, writing out a print statement as a boolean in 3 terms or'ed together, where only the last term evaluates to our actual string to be printed).
print((vars().__setitem__('__',vars().__setitem__) or
      any(__(_O,_0) for _O,_0 in (("___", "decodebytes"),
                                   ("____", "base64"),
                                   ("_____", getattr),
                                   ("______", __import__),
                                   ("_______", 500),
                                   ("________",bytes.decode),
                                   ("_________",b'SSB3aWxsIG5vdCB0aHJvdyBwYXBlciBhaXJwbGFuZXMgaW4gY2xhc3MK'),
Then just run that last bit all on one line, taking out as many space characters as you can.
 
Amazing, thank you so much!
 
the English translation itself is not actually inaccurate. it just not a common word to say in Indonesian (even google translate did this, there are so many words that not common for Indonesian folks). I highly prefer to change the button text myself if I could.
 
 
10:52 PM
cbg
ive observed something weird with numpy, and am kinda curious whats going on
a=np.array([[1],[0],[0]])
np.bitwise_not(a)
output is:
array([[-2],
          [-1],
          [-1]], dtype=int32)
what is going on here?
 
>>> ~1
-2

>>> ~0
-1
nothing to do with numpy
 
Looks like 2's-complement not.
 
wait, why is ~1 == -2
 
What should it be instead?
(I guess 0)
 
~ is not the same as not
 
10:58 PM
@PaulMcG that code markdown is barely visible, made me do a double take :)
I'd say that ~ is binary not is not logical not
 
ok, i guess that actually makes sense if you think about things in terms of signed ints
 
67
Q: Two's Complement in Python

JimIs there a built in function in python which will convert a binary string, for example '111111111111', to the two's complement integer -1?

 
is there a way of doing logical_not but not converting to bool
with numpy
 
Google reports that there is a logical_not method, can you use that instead of bitwise_not?
 
cuz i know you can np.logical_not(a).astype('int')
but i was wondering if theres a way to skip having to recast the whole array
 
11:02 PM
Oh, and you want 1's and 0's?
 
yea
its kinda weird that the default behavior is ints in bools out and there isnt a way to make it int --> int
 
@Skyler the fact that ints and bools intermix is largely C's fault
 
(x + 1) % 2 will convert 0's to 1's and back. Can you do that in numpy?
 
you can
or you can use np.where, or logical indexing, or...
 
I just noticed that
 
11:04 PM
fair, that is basically the most natural representation of what im trying to do anyways so I guess the fact they didnt name out a function to do it explicitly seems reasonable
 
ad absurdum you can probably use .astype(bool).astype(int)
Just ask yourself whether you really need an array of ints rather than an array of bools. The answer might surprise you.
 
i suspect sklearn will be smart about the bool arrays in most contexts
just didnt want to kick the expectation down the line in case the code I was working on got reused
i know they are not identical though since:
np.logical_not(a) is (a+1)%2
returns False
 
eh, that's almost never True in python
"I know there are pink elephants because this wall is blue". Yeah, it is blue, and there probably aren't pink elephants, but that's largely coincidental.
 
what I mean is that I dont know the extent to which they differ, but if this expression returned True I'd know there is nothing at all to worry about
 
@Skyler arr[:] is arr will also fail even in numpy
 
11:11 PM
i saw a really interesting and unintuitive case of this evaluating to True earlier today
 
>>> arr = np.array([1000])
... arr[0] is arr[0]
False
oh noes
 
cuz these are referencing two different instantiations right
 
Mine does. Yours compares two completely different arrays.
 
hmm
btw, i know you can set an __eq__ method in objects, is there any kind of __is__ method you set
or basically is just gives like an object hash of some kind
 
@Skyler no, that's the point. is tells you if they are the same object.
 
11:14 PM
oh
the way i say it used
np.invert is np.bitwise_not
I think that evals to True
 
yes, those are the same functions
Yet np.invert(arr) is np.bitwise_not(arr) will always be False. Even np.invert(arr) is np.invert(arr) will always be False.
You'll also see np.newaxis is None. These are called aliases.
 
yea, is an alias as simple as assigning bitwise_not in the same module like:
`bitwise_not=invert`
 
yes
 
and since basically all assignment is by reference in python that means that unless you are assigning to output of something callable like a function bitwise_not=invert type things should eval to True right
 
I don't understand that question, sorry
 
11:20 PM
but the second you call something (is it fair to say accessing an numpy element is calling it?) then you should expect Falses
so bitwise_not and invert are references to some underlying function
 
bitwise_not and invert refer to the exact same object. it's one function object with two labels. Yes.
The second you call something you get a return value. What that is depends on the function. The function could choose to return a previously returned object, but I know for a fact that vectorized numpy functions have no reason to do that for non-trivial inputs.
And yes, subscription on a numpy array calls __getitem__. But that's tricky because there's underlying data it returns. Whether or not that's a new object depends on the implementation. Of both numpy and python.
 
yea, ok, im starting to get a bit of the internals a bit better
hmm, if I had a generator with some kind of cyclical output of like n length would I expect object 1 and object n+1 output by the generator to come out as True if I did the comparison?
 
Depends. If you return the exact same object then yes. If you return something that's only equal, then depends on the implementation.
 
ok, ok. Thanks for the food for thought
 
If you have an infinite loop and you yield iteration % 4 then you get the same 4 values repeating, yet they are not guaranteed to be identical (but in CPython they will be). If you use something like itertools.cycle they'll be the same 4 items, I expect.
 
11:31 PM
I think the question Rounding floats with f-string should be allowed stand closed as duplicate:It's title and explicit tag are much better, clearer, wording, legible and better search keyword coverage or duplicate than "Convert floating point number to a certain precision, and then copy to string". So we should definitely leave this stand, closed but not deleted (cc: @vaultah, trying to at-mentiion)
AndrasDeak and RO's: does @mentioning vaultah like this work ^ ?
^^ the apostrophe police: I mistyped "It's", sigh.
 
If his name appears in a tooltip then yes. And it does.
 
@AndrasDeak Ok. I wasn't clear if a user being on hiatus can suspend that.
 
11:47 PM
the rules are a bit complicated
 
@Skyler Is your input array supposed to be bools or integers, and what does it represent? Show us more of the code if you want to rewrite it.
 
the (a+1)%2 method cleanly solves what i needed and leaves the ambiguity out so it seems like im all good now
 

« first day (3657 days earlier)      last day (1274 days later) »