I would like to create an OrderedDict instance that can be shared across processes.
What I've tried
Intro
I've implemented a normal dict version, a multi-process dict version, as shown below.
import multiprocessing as mp
class BasicPen(object):
"""single process version"""
def __ini...
Hi all, is it possible to for someone to explain to me, how I can improve my questions as I feel I have been following guide properly...
however sometimes I still get no votes or down votes and am at risk of getting blocked, and don't want that to happen! For example is there something specifically wrong with this question that I did not get any votes for; question
@Seanny123 Thanks, so ideally after I attempt to solve the problem on my own I should give a thorough explanation on what the error is and how I am generating the error?
@IljaEverilä Thanks, after a while I did figure out I needed to use square brackets around the user table name. Normally I use mysql, I had to connect to mssql this time to someone else's database
@AshishNitinPatil Ah ok, I didn't realise this. I thought no votes as well are at risk of being blocked. As I keep seeing the "You are at risk of being blocked" when I ask a question.
Thanks everyone, I will structure improve my questions to meet these requirements from now on.
@mp252 I believe "risk of being blocked" should only come when you have somewhat consistently produced bad questions (or comments / answers) which were possibly flagged.
It's just speculation though, you should look up meta.stackoverflow.com for confirmation.
if a large chunk of your questions are deemed low-quality by them being closed and/or downvoted, and/or if you deleted questions not long after an answer has been posted to it, then you're at risk of being blocked
but lack of upvotes on your questions signals that you could do better
My decision to make my Vector class mutable is coming back to haunt me.
I designed an Observable class, which executes a callback function whenever any of its attributes changes. x = Observable(f); x.color = "red" will cause f("color", "red") to execute. But if the user does x = Observable(f); x.position = Point(0,0); x.position.y += 1, then f will only be called on the initial creation of position, and not for the update to position.y.
If I had enforced immutability, the user would have to do x.position += Point(0,1), which would trigger the callback
My solution right now is to politely ask my users not to mutate any attributes of Observable instances, but this is not entirely satisfying.
Trying to decide if it's worth it to create a Color class to represent RGB values, or if I should just use a 3-tuple, or if I should just use my existing Point class and hope it's understood that x y and z actually mean r g and b
>>> (255, 255, 255) * (1 - 0.3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'
Hmm, no luck there
One might suggest rewriting that expression to tuple(value * (1 - 0.3) for value in my_tuple) but in my actual code it is expected that that function work for Colors and Points and floats
#so I'd have to change this:
def interpolate(a,b,f):
return a*(1-f) + b*f
#to this:
def interpolate(a,b,f):
if isinstance(a, tuple):
return tuple(a_value*(1-f) + b_value*f for a_value, b_value in zip(a,b))
else:
return a*(1-f) + b*f
So really my choices are "use the existing Point class, which may confuse readers because the attribute names don't match their intended purpose" or "create a Color class, which will have identical functionality to the Point class except its attribute names are different"
Possibly I could make some kind of vector metaclass that creates classes that only differ by attribute name. Point = VectorClass("xyz"); Color = VectorClass("rgb")
If I'm trying to formally describe the structure I might call it a "list of lists of ints" or borrow "list<list<int>>" syntax from statically typed languages
The latter is especially useful for more complicated cases. Like, "a dictionary of tuples of integers and lists of dictionaries of strings and floats" is easier to misinterpret than dict<tuple<int>, list<dict<str, float>>>
Yesterday I discovered you can't use js to get a string containing today's date in "MM/YY" format unless you write twenty lines of boilerplate or download jquery.
Hmm, perhaps I am being uncharitable. You probably could do it in one line, but it would involve some unpleasant string manipulation. My core complaint is there's no arbitrary date formatting method.
If my boss comes in tomorrow and says "actually let's have it in YYYY/MM/DD format instead" I don't want to have to re-derive the string manipulation from scratch, I want to delete "MM/YY" and enter "YYYY/MM/DD" and be done with it
Yeah I'm leaning towards that although I'm reticent to modify the Point class since I have about thirty projects that use it as a dependency. I guess I could create a branch that's local to this project.
That doesn't help if the refs can't see the ball because of all the people pretending they've just been murdered who are falling down in cinematic fashion.
I wonder if required field strength scales linearly with desired cavity size, or superlinearly. The magnet we need might lift people up by their fillings and uproot manholes.
my educated guess it that the intensity of the resonance decays with ~1/r^2, and you have to create that resonance with another field in the first place
@Kevin nope
I mean, Ni is a ferromagnet
but metal fillings are usually amalgam (Hg+some noble metal?)
handegg doesn't really appeal to me... too many commercials. The super bowl seems like it was trying to sell me something rather than 2 of the better teams of the season facing off.
Hey @AnttiHaapala Do you have anything to add to this?
Your for char in z: w += chr(char) loop could be written more compactly as a list comprehension: ''.join([chr(c) for c in z]). Or you can decode it in one step like this: z.decode('latin1'). That works because Latin1 is a proper subset of Unicode. But IMHO it would be much simpler to write a separate Python 3 version that just uses bytes / bytearray rather than abusing text strings like that. Trying to do this sort of stuff in a way that works on Python 2 and Python 3 is a recipe for madness. ;) — PM 2Ring25 mins ago
I have a very simple thing I want to do, but for some reason I haven't found the solution yet.
I have a form in HTML
<form id="user_form" method="POST" action="/ProjectName/home/">
{% csrf_token %}
<div class="registerLabel">
Full name:
</div>
<div class="registerTextL...
remember how I was mildly annoyed with having to use someone's tool and he kept changing on how to use his tool? Well business came back to my team and told us that they wont be needing that feature. Pro: I don't have to deal with that tool anymore, also I learnt some lessons I guess.. Con: a week's worth of work just went into storage (until maybe business wants the feature again).
@PM2Ring I'm not @AnttiHaapala, but I would point out that ''.join([chr(c) for c in z]) is unnecessarily inefficient. Since str.join takes an iterable argument there's no need to instantiate the list, you can just write ''.join(chr(c) for c in z)
I think in this case it is more efficient, since join can rely on the length of the iterable. It's a balance though, depending on the number of elements.
Most of the time I wouldn't worry about it and just use the generator though.
I think we've benchmarked it in the past, and passing a list comp to join is a little faster than passing a generator expression. But is it worth the time you spend typing an additional two bracket characters??? It's hard to say, but the time we've spent arguing about it probably eclipses the potential savings by several orders of magnitude
.join has to scan the strings twice, once to determine the full length of the destination string, and then a second time to copy the strings. If you pass it an iterator it has to build a list. So it's better to just give it a list in the first place.
That. If you just want to background it no matter what, you can run it with nohup. If you want to do it in the python level, you'd have to make the root python process ignore SIGHUP
SIGHUP is the signal meaning "the terminal has gone away". Usually your shell passes this on and everything DIES. nohup ignores it, but you'll still have IO errors if the terminal goes away and you write to stdout, so nohup also captures the output.
making self-modifying code easier is one of those questions where I admire OP's grim tenacity in doing something odd for far longer than the average person would consider reasonable.
If by "it's a troll", he means "you, Kevin, are a troll", then he correctly identified my "technically correct, yet practically useless" commenting style that I use to needle OPs that irritate me
as in "nobody can be this stupid and this entitled at the same time", which is a fundamentally flawed assumption yet it might lead to the correct result in this case
is there a term or a theory for if I read about something (old or new, popular or unpopular) after reading/learning, the next little while, most of the comments/conversation/topics are on that subject I just read about ?
Cause like if I read about some theory on wiki, that isn't very popular, I would see a stack overflow question on it, and then when I get home, I would read a reddit topic on it ... and i find it weird...
ideas can be suggestive and contagious and they start living and mutating on their own (what "memes" should actually mean, rather than new-age lolcats)
maybe..... :\ but it bugs me... like "I just read/learnt about that just now. why am I seeing it everywhere now, before I didn't see it (or I would have looked it up)"
Don't forget the cognitive bias that makes you discard all sorts of almost completely valid information because you think it is riddled with cognitive biases
for what it's worth, knowing about cognitive biases is very useful, because it helps counteract some of the stupider notions hardwired into our way of thought along the millennia
Sometimes you really do see eight red cadillacs in a row, not because of the frequency illusion, but because the Red Cadillac Enthusiast Club is cruising around town
Basically just don't overdo it
To counteract my negativity towards js this morning, TIL that its let keyword allows you to bind values to anonymous functions in a loop. In comparison, this can only be done in Python using a variety of peculiar workarounds.
//javascript
callbacks = [];
for (var i = 0; i < 5; i++){
let x = i;
callbacks.push(function(){return x * 2;});
}
console.log(callbacks[2]());
//Result: 4
#Python
callbacks = []
for i in range(5):
x = i
callbacks.append(lambda: x*2)
print(callbacks[2]())
#result: 8
One possible fix for Python being callbacks.append(lambda x=x: x*2) but ugh
Good job js for having a feature that I wish I could have in Python. A rare feat.
It would explain my bewilderment at the world around me these days. Speaking of which, how are preparations going back in good old Blighty for the war with Spain?
Assuming that's not a rhetorical question, yes, the Shetland islands are part of Scotland, and 500 square miles is really small for certain definitions of small.
If it was a rhetorical question and part of some larger hilarious satire, excuse my boorish behavior, remembering that I am a dim American
Miniature horses are found in many nations, particularly in Europe and the Americas. The designation of miniature horse is determined by the height of the animal, which, depending on the particular breed registry involved, is usually less than 34–38 inches (86–97 cm) as measured at the last hairs of the mane, which are found at the withers. While miniature horses are the size of a very small pony, many retain horse characteristics and are considered "horses" by their respective registries. They have various colors and coat patterns.
Miniature horses are friendly and interact well with people. For...
Doctor Panda would create a miniature panda and paint it gray and tell you it's a hippo. Doctor Panda is untethered from the shackles of normative morality.