« first day (2335 days earlier)      last day (2838 days later) » 

15:01
Is it possible emulate pointer behaviour in python so as to write a "safe" function def assign(var, fn): exec("global {}; {} = {}".format(var, var, repr(fn())))?
Which assigns at the scope at which it is called
Do you have a good reason to want to do that?
Short of doing unholy things using CPython's undocumented behavior, I don't think it's possible to do it exactly as you have described.
I was about to say 'But if we relax the constraints to "is it possible to create a variable in the local scope, given a string representing its name, and a value?", then you can just do locals()[name] = value', but now that I try it out, it doesn't work. I guess this is why they say you should treat locals() as read-only.
>>> def f():
...     locals()["bar"] = 42
...     print(locals())
...     print(bar)
...
>>> f()
{'bar': 42}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in f
NameError: global name 'bar' is not defined
dynamic variable names are baaad
I wish to set arbitrary variable to some default value, then wrap a cpu-costly function in a wrapper which puts the return value into a queue, have a thread in the original process wait for the queue to receive that value and update the original variable with that value
Basically fn() would run in multiprocessing.Process
I suspect it's doing name resolution at compile-to-bytecode time. It doesn't see any name "bar", so it doesn't even bother looking in the local scope at runtime.
Actually, hmm, if that were the case, then I'd expect exec to fail with the same error, but it actually works...
>>> def f():
...     exec("bar = 42")
...     print bar
...
>>> f()
42
15:10
@SebastianNielsen Code times out because the algorithm needs to be faster -- look at the size of the problem constraints
For locals() doc says NOTE: Whether or not updates to this dictionary will affect name lookups in the local scope and vice-versa is *implementation dependent* and not covered by any backwards compatibility guarantees.
So locals should work in local scope?
@Mirac7 I think you should just use a mutable object.
Pass a list* in to the expensive function, and append the return value to that list at the end of the expensive function. The original thread can then see the new contents of the list
or use a dict holding the original variables, in which case you can just return the value and mutate the original dict on the caller side
(*Doesn't have to be a list)
@Mirac7 That documentation does not imply that locals() should work in local scope, no. It's saying that you can't depend on updates to do anything, in any circumstance.
Yeah, I misread...
15:17
I'm still not entirely clear what the use case for this is, anyway
I want to write a wrapper which would asynchronously assign a return value from a function executing on a separate cpu core to an arbitrary variable
Is it something like "I'm periodically running code in the main thread which partially depends on the return value of the cpu-costly function, but it can also operate without it, albeit less effectively. So the code runs whether or not the cpu-costly function has finished executing, and it uses the variable's default value when the cpu-costly function's return value isn't available yet." (con'td)
"I want the cpu-costly function to seamlessly update the variable without the periodic code having to do anything on its end"?
If you're thinking "no, the periodic code depends completely on the cpu-costly function, and so it shouldn't ever run until the cpu-costly function returns", then you don't need seamless variable assignment at all. You just need to make the periodic code do my_variable = results_queue.get() and it will happily wait for the cpu-costly function to finish
@Kevin I would actually be interested if you managed to calculate where I took that photo from ^_^
Howdy stranger
15:22
@Kevin the first one
I managed to make it work by creating a class Variable which has get(), set(value) methods and this is passed to assign function instead of raw values
That's pretty much exactly what I was going to suggest.
Possibly there's a built-in type that already does that somewhere in the threading module or related modules, but idk
Cabbage
cabbge PM
15:30
Did a little googling to see if there's an idiomatic solution for this but all I could find was stackoverflow.com/questions/15668591/… which just suggests the approaches we already thought of: use a mutable object such as a list or a custom class with set() capabilities
@Mirac7 I haven't paid close attention to what you're doing, but when you do weird stuff to try and make Python behave like some other language, then you're probably Doing It Wrong.
It only has one upvote so I assume that it doesn't have the full weight of community consensus behind it
@PM2Ring His use case is fairly legitimate. It only looks wonky because it involves threading and threading always looks wonky :-P
TFW your set and dict code out-performs the code of the core dev who was a major contributor to setobject.c and dictobject.c (under certain conditions) stackoverflow.com/a/42674001/4014959
ugh...really big <redacted> open source project working on a new version is explicitly set for py27 only
this is so not cool
@idjaw ugh... do they state a reason for that?
15:38
@JonClements When I finish reviewing this change set, I'm going to ask, actually.
@Kevin Sure, I've only done a tiny bit of threading / async stuff in Python, but I know what you mean. I was mostly talking about the attempt to manhandle locals()
Prolog is cool
@khajvah complex prolog is hard :(
Yeah, I can imagine
15:50
simple prolog is hard too if you're not used to it
@KevinMGranger My slight experience with functional programming helped
unification stuff is similar to pattern matching
All I can remember when I learned it is loves(raymond, X). and there was something called a "cut" and no one understood how it worked but we needed it for our assignment
I took ai and advance ai both using prolog.... I feel like getting into ti was fun and all. Seeing the advance stuff was daunting. Thinking of solution was fun though.
Another newbie successfully rescued from variable variables stackoverflow.com/questions/42675507/…
@KevinMGranger IIRC it cut was use to limit backtracking and commits to choices...
wim
wim
15:53
@Mirac7 sounds suspiciously like a descriptor ..
I know some of those words
I am solving a simple maze yet, haven't touched the hard stuff
TL;DR Prolog is very good at back tracking to make choices. Sometimes you don't want it to backtrack at certain "fork" of choices. so you choose to tell it to make a choice and commit to it. cut the backtrack off..
wim
wim
@PM2Ring surely there must be a good variable variables duplicate by now
if not, someone should self-write one. it's probably the most common n00b mistake we see
We've got one or two targets on sopython's common questions list
wim
wim
15:58
I try to avoid those questions because the OP often seems attached to their stupid plan and scared of redesigning anything
In general, you're not going to get a lot of gratitude by answering "how do I do X?" with "You don't want to do X, you want to do Y, and here's how"
@wim Probably. The commonly used target is crap because it has answers showing how to make dynamic variables using globals(). But it's late and I'm on my phone and don't feel like doing a tedious search.
"Use lists instead" is not, strictly speaking, an actual answer to "how do I dynamically assign variables?"
@Kevin Fair point, but that OP seems happy enough to learn about dicts.
Maybe I'm overly cynical about how OPs are likely to respond to answers that aren't "sure thing, here's the code"
16:03
@Kevin Oh yeah. But that's a PITA to get at on the mobile interface.
just googled a question I had, found the stack overflow, copied and pasted the answer. Tried to upvote, turned out it was my answer...
wim
wim
@Kevin sometimes you have to see the question behind the question
It makes me very sad to see the accepted check next to something like this stackoverflow.com/a/42654352/674039
Q: How do I do <insane thing>?
A: You can use a metaclass!
But first, we have to understand parallel universes.
16:23
I get that reference.
Are there any references one of us make that the other doesn't?
Are you guys Kevin-channeling right now?
@wim I knew it was going to be that question even before I clicked the link. :)
@KevinMGranger Possibly chat.stackoverflow.com/transcript/message/35662758#35662758 but in fairness I don't think you were in the room at the time
Never seen it, but it does look enjoyable.
16:34
rb folks
@nedbat @zeffii Oh. Let's try. >>> lambda:_();_()
Yep, it does what you think. Cool.
I spent all evening playing Nier: Automata yesterday, and I'm going to do it again today. So good.
oooh nice. Good to know
Breath of the Wild is good too, but Nier is that plus way better action.
Final Fantasy XV wishes it was Nier.
16:43
Video game chat? Video game chat. I'm now 15 hours into Hollow Knight and have only just determined what the plot is supposed to be.
In a good way or a bad way?
I bought TF2 because it was on sale for $24, have been enjoying it. I also bought BotW special edition and got the second to last one... but I don't own a switch nor do I intend to get one until their next run or second edition
@davidism Good, I'd say. It signals that it's the kind of metroidvania that doesn't want to railroad you into a predetermined sequence of events.
I probably could have gotten there a lot faster, but I had the liberty to explore several non-essential levels first
Added it to my Steam wishlist, which grows ever longer.
@KevinMGranger TF2 = Team Fortress 2 ? If so, isn't that game for free ?
16:47
It's interesting to me that most of the power-ups don't have a huge impact in combat, so there's not many places that are like "I better get twelve more heart pieces before I try going into the Valley of Almost-Certain Doom"
Everyday I wake up and ask if it's the 17th :( one day I will get to play Nier: Automata
The other big game was Horizon: Zero Dawn, which I hear is actually really good, but I wasn't impressed by the hype.
@MooingRawr Titanfall 2, I realize that's ambiguous
I've also been dabbling in Tharsis and Steamworld: Heist, both are fun. The earlier being challenging to the point where I think it's a little too rng-dependent
It's apparently on PS4 also, I was sort of tempted, my friend really liked the single player.
Oh I see. I think the news of Titanfall 1 playing with a mix of AI and real players turned me off from the franchise. :(
16:49
Which isn't to say the difficulty curve is flat amongst different areas. The City of Tears has more difficult enemies than Fog Canyon, for instance. The principal mechanism in getting stronger is identifying the attack patterns of enemies so you can hit them without getting hit back.
In this way, the game is reminiscent of Dark Souls. (Uh, I think. I've never actually played dark souls. I watched a bunch of Let's Plays though)
The Castelvania game I'm waiting for is Bloodstained: Ritual of the Night.
By the creators of Castelvania.
^^ that just gave me a rush of giddy nostalgia
I want that
I remember reading a review about Hollow Knight and how it was the 2D version of Dark Souls...
@MooingRawr It was around the second boss, when I was trying to find a gap in the attacks that would give me an opportunity to heal (an action that leaves you defenseless for several seconds), before I thought "this feels really familiar..."
Momodora: Reverie Under the Moonlight is the "2D Dark Souls" I'd heard of.
From the one handed speedrun during AGDQ.
16:53
Do the hit boxes make you feel good when you pixel dodge something ?
"Gotta use my estus flask soul focus before I get squished by this monster"
Dark Souls is basically the line of "2spookey4me". Not looking forward to seeing any VR jump scares in any game :(
@Kevin Do you just roll combat roll around to move :D ?
Hollow Knight is not nearly as brutally difficult (so far), and the art style is basically "Gothic, but PG-rated"
The scariest thing I've encountered so far is a little batlike thing that hangs out in dark ceilings, and when it sees you, it shrieks at maximum volume and dive bombs you, exploding violently on contact.
16:57
Can't wait for the new Zelda game to be in an "_GDQ" event. If it's a speed run-able game that is.
@MooingRawr There's a dash move, but you don't get any invincibility frames.
wim
wim
new to . do we have to open and close a session every time we want to get a row from the db?
To a degree. You don't want to hold a global session open across threads.
wim
wim
how much extra overhead is there in doing something like this?
@contextmanager
def session_scope():
    session = SessionFactory()
    try:
        yield session
        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()
I thought I was being clever, but now my code has tonnes of with session_scope() as session: blocks all over it
17:00
Pretty sure sessions are already context managers. There's also sessionmaker and scoped_session for factory stuff.
wim
wim
hmm, thanks, looks like I need to RTFM
I'm having trouble deciding whether this is an interesting question badly expressed, or just a bad question:
1
Q: How to pass property methods as arugments in Python

Andreas BengtssonFirst, let's consider this working example using get and set methods for the variable x class Foo: def __init__(self): self._x = 0 def set_x(self, x): self._x = x def get_x(self): return self._x class Bar: def __init__(self, set_method): self._s...

it's usually the latter:P
There's a definite whiff of code smell (and misunderstanding of what properties are for) about it, but maybe there's the kernel of something actually useful there? Alternatively, I might just not have had enough coffee yet.
but you might have a counterarugment
17:03
Also, I like "arugment". Sounds like part of Trump's morning routine.
What they're doing is strange. I smell an XY problem
Yeah, definitely a bit XYy.
wim
wim
It's an "I don't understand the descriptor protocol" question
Speculation: they want a bunch of bound callbacks, and it's non-obvious to do that with properties
wim
wim
Please nobody show them how to do b = Bar(lambda v: Foo.x.__set__(f, v))
17:14
That's ridiculous, clearly you should do Bar(Foo.x.fset.__get__(f))
wim
wim
yes, thanks for polishing that turd
^^ you. Long time no see. Hope you're well Mr. @JRichardSnape
Hi @idjaw
o/
Yeah, I'm OK. Not on here as much as I once was. Turns out a real job takes more time than a PhD
Well - an academic. As close to a real job as I want to get right now.
17:31
cbg
cbg(all(room_six))
lazy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'bool' object has no attribute '__cbg__'
hahah..wrong window
@JRichardSnape What kind of stuff you working on?
@AndrasDeak You have failed to define your cbg correctly. Not my problem :)
@idjaw Mainly loads of teaching is taking the time. Also occasional research into modelling the effect of embedded renewable electricity generation on a smart grid.
I need to subclass bools
17:35
Which is fun, but I have no time to do it. Next 10 days - marking!
Deep Joy
def cbg(condition):
    if condition:
        print('It\'s a Cabbagey day')
    else:
        print('No cabbage for you, you user of PHP!')
You're welcome
yes, I am avoiding work. And now, I will go home to avoid it more comprehensively.
I apologise for the last line of my function on this, International Women's day. I should have been more thoughtful.
haha
@JRichardSnape I was sure there must be a word for the repetition of a syllable in a phrase ("you, you u[ser]"), but the best I can find is Palilalia.
I bet there is one, though. Writers love coming up with words for things.
Ooh, I love palilalia, especially with shrimp
wim
wim
>>> all(room_six)
False   # Because of Zero Piraeus
17:55
@KevinMGranger oh you
I love Firefox's "have I visited this page before". stackoverflow.com: Yes, 46,117 times. And that's just a year on my laptop.
Is that a thing? I have to see that
add-on?
Click the little info button next to the url, click the arrow, click "more information".
D:
I never click those things...
sometimes they are different icons and animated, etc...
it's all magic
Today is your day! Be on of the 10ks
18:01
16,574 times for chat
59,987 times for main
(page info -> security tab)
brb, reloading SO 13 times
@MooingRawr \o/
:D -confetti falling from the roof while music is playing- \o/ you did it.
Chat's way lower (2,776) for me for some reason. Maybe it's counting pinned tabs differently.
18:25
@davidism You get a chance to try Nier: Automata yet?
2 hours ago, by davidism
I spent all evening playing Nier: Automata yesterday, and I'm going to do it again today. So good.
:)
I've also been reading / watching this great series on Nier: something-very-special.tumblr.com/table-of-contents. Author does a 100% run and also has a bunch of essays on the game.
zero just needs 11 rep to attain trusted user
I see him at 20k :D
18:36
I see 20K now
Pineapple on passing 20k, @ZeroPiraeus!
9
Now get 35k so you have all 30 delete votes.
WTG @ZeroPiraeus.
Hey, cool :-)
@davidism I dunno, I kinda like the idea of using strategic bounties to hover around 20.5k and thereby gaining a perverse smug sense of moral superiority.
@ZeroPiraeus make that 35k
When I hit 40k I thought I might hover there forever by giving away bounties, but then I forgot about that plan and now I'm halfway to 50k so I may as well trudge onwards
18:45
Heheheheheh:
If you really want to go crazy jamming logic into a listcomp, def chain_unique(*args): return [v for v, z, _ in map((lambda x, s=set(), o=object(): (x if x not in s else o, o, s.add(x))), chain(*args)) if v is not z] works ... I tend to agree with @wim that this isn't pythonic, and you should at least explain what's going on if you're going to exploit these kinds of tricks. — Zero Piraeus 1 min ago
wim
wim
I will hit 100k sometime soon
Is it against terms of service to transfer all your points to another user via bounties on their answers? That could be a fun magic trick
yup
23
Q: What exactly is "artificial inflation of reputation", and where is the line?

Tiny GiantThis is in reference to a chat discussion prompted by this meta post. The backstory here is simple: a high-rep user on Stack Overflow recently decided to start offering bounties on questions with the express intent of increasing specific authors' reputations so that they could use it to modera...

that's a suspendable offense
Would be pretty slow anyway, given the various time, quantity, rep limits on bounties.
I really don't like that the whitespace one is secret. Whenever I fix whitespace in PRs I have to put the edited link in myself, and even then people miss it and critique code I didn't write.
Although I haven't had to do that in ages, I guess
wim
wim
18:58
the file finder one is great
open up any github repo and press "t" , start typing a filename ...
I love GH keyboard shortcuts. "t" is one of my favourites
j and k are great too for browsing through with your keyboard
those are my favourite keys
j/k
@kevin also sir since I can't post another question on here for a while, can you email me if you can, or do you have a github? Mine is gethbonow on gmail, please consider help me if you have time! — user7680242 2 mins ago
Think I'm bout to get cyberstalked because I answered 1/4th of this guy's question in a comment
no you're not
@kevin ugh sir since you are good with Python, is there way I can hit you up on google hang out? My gmail is temporary account I've created, so your privacy will be safe. So please consider help me if you have time. Since I can't post screen shot or too long code on here, I have to wait 90 minutes to ask a new question. — user7680242 56 secs ago
you're safe, dude
Incidentally, seeking a dupe target for the question linked through that comment. I'm sure "How do I fix UnicodeEncodeError?" has been asked appx one million times already
19:10
I'd comment saying "you can always [edit], but I don't want to get involved in this
@AndrasDeak you........I know what you did
It's okie, Kevin, he just wants to be one of your interweb friend :D
It's dangerous to go alone! Take this.
I don't think I can handle that level of commitment
I typed a word so much, because of c#, it's starting to look wrong... thank god for tab completion :\
19:19
Man my Internet is real flaky today. 5+ second delays on every message I submit.
Hello
I try to use subprocess with threading, so I have
thread.start_new_thread(subprocess.call(['python', 'run.py']))
Prime opportunity for everyone else to make jokes and observations that I normally would submit first a second ahead of them
but new_thread need two args "TypeError: start_new_thread expected at least 2 arguments, got 1"
@IsabelCariod I don't think that's the correct way to start a new thread.
@IsabelCariod well first of all, the "thread" module is outdated and you should be using the "threading" module
19:21
In general, start_new_thread(f(a,b)) will call f(a,b) in the main thread, then pass the return value of f to start_new_thread
if thread is anything like threading, you need to pass the function object independently of the arguments.
I'm guessing something like start_new_thread(subprocess.call, (["python", "run.py"],))
But also yeah threading is better than thread
I'm afraid to ask, but... what's the point of starting a new thread that does nothing but start a subprocess?
It's good that Kevin verified Rawing's claim. First I thought that it was cronyism (Rawing better than Raw, etc. ;)
sorry, it's a long day
wim
wim
@Kevin ^ for you
19:25
I think I recall this problem from yesterday. Isabel wants to execute a gui's mainloop while simultaneously executing run.py. I already suggested using import run instead of using subprocess on it, but that didn't seem to take
if at first you don't succeed...
...then skydiving is not for you.
wim
wim
...destroy all evidence
@IsabelCariod I probably shouldn't have suggested threading yesterday. You can get non-blocking behavior in subprocess simply by using Popen instead of call. My bad.
thread still exist in python 2.7 and works :D
wim
wim
19:27
@KevinMGranger back on sqlalchemy
(this is assuming you're still dead-set on using subprocess, which I still don't condone)
wim
wim
those docs say
> When you write your application, place the sessionmaker factory at the global level. This factory can then be used by the rest of the application as the source of new Session instances, keeping the configuration for how Session objects are constructed in one place.
@IsabelCariod so does exec, but that doesn't mean you should use it
wim
wim
but doesn't it mean that the engine is bound at import time? how does that tie in with your test suite, when you want to have the engine bound somewhere else?
The <> operator still exists in 2.7, but that doesn't mean we won't slap you with a herring for using it in serious code
19:29
@wim you can override it with the bind kwarg
holy cow it really does. never knew python had a turbofish
wim
wim
only ā™¦ mods are allowed to use the <> operator
It's a stoperator. Whenever you think you want to use it, stop, because you don't
wim
wim
other obscure python 2.7 feature, using `backticks`. if you haven't seen it before, 10 points for guessing what it does ..
Makes your editor use a non-monospace font for that block of code?
wim
wim
19:33
haha
that would be hilarious
something tells me I've seen that before...
wim
wim
0 points for you, then.
\o cbg Marcus
@wim I tried it and I'm still unsure whether I've seen it
I probably have...
people on PPCG still use it sometimes
19:40
<> is only useful for creating syntactically correct ASCII fish of arbitrary length
>>> 1 <>~~~~~ 2
True
that's a tadpole
wim
wim
I'll have a syntactically correct ASCII fish of length 1, please
<technically right .gif>
I Came Out to Have a Good Time and Iā€™m Honestly Feeling So Attacked Right Now
wim
wim
Please don't use ā€™ for ' , it crashes my computer
19:43
I'm still trying to make something like ><> work, but the unicode >-like characters are invalid variable names
wim
wim
well, if you're going to bring in unicode you may as well just šŸŸ
I always get a kick out of the occasional post from users that use "smart quotes" and don't understand why they're getting a syntax error
That's what you get for writing code in Microsoft Word I suppose
I wrote print(sum(int(i) for i in pix[i, j-1])) # pix is a list -> Python responds with TypeError: 'int' object is not iterable
What's wrong?
pix is a list, but what is the type of pix[i, j-1]? Because that's what you're iterating over.
Incidentally it's probably a bad idea to refer to the variable name you create in the for clause, in your in clause. It's going to use whatever value the name had before the loop started.
Maybe they were using google docs to collaborate on some code and copy+pasted it.
19:49
And if it didn't have a value at all, you'll get a NameError.
>>> pix = [[0,0],[0,0]]
>>> j = 1
>>> sum(int(i) for i in pix[i, j-1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'i' is not defined
wim
wim
@Kevin that could be intentional (summing over major axis in a list of lists)
Sure, and it might not even cause an error or unexpected behavior, but overshadowing is still a shady practice
Why can't python print which element it means, instead of printing 'int' object
Hi guys, a question from a noob programmer. I have a sql query that finds out how many records there are with a name 'test' for example. In my database there are 4 records. When I print out the query it comes out as (4,) how do I get rid of the brackets and comma? sorry is this a stupid question.
Wild guess: Maybe they're worried that the object's __repr__ implementation might itself raise an exception, which would be a double headache to resolve. May as well just print the type, which is much safer
19:52
@simons21 you can parse it, you can find out what object type it's returning and maybe edited the __repr__ of it, etc... many ways of doing it but your question is too broad.
@simons21 Hard to say without seeing the code, but generally, you can turn a one-element tuple into a scalar by sticking a [0] at the end.
Or just slap a [0] on the end
oh come on
>>> x = (4,)
>>> print(x)
(4,)
>>> print(x[0])
4
I rebooted my router :-)
Now only half of my messages have a five second delay
and it worked, thanks guys (y)
unless x is a str where '(4,)' then you get ( back :D
19:55
Noooo, i missed the SQL question
I'll probably have another one soon, don't worry
@MarcusS blog.wolfram.com/2013/10/08/a-response-to-falling-with-helium if it interest you... Wayne got me hooked on xkcd's what-if, and the author got banned from wolfram alpha, which led to that blog posting on the math side of one of the comic...
opens a new tab with google ready
@MooingRawr Yeah, we don't have the full information needed to definitively diagnose here. I was just going by prior experience with SQL-y questions, where people were surprised to get a tuple when they expected something else
@Kevin I agree with you, and I don't want to undermine you. Just wanted to add another layer of information
@Orange wasn't really a sql question tho :(
19:58
Adding "well, technically..." postscripts is a vital part of room culture ;-)
@MooingRawr I would of still been able to say slap [0] on the end :D
A: Our nation has strict punishments for pedantry. B: Are they imprisoned or flogged? A: We toss them down a well, actually.
Considering getting Witcher 3, but I never played the first 2

« first day (2335 days earlier)      last day (2838 days later) »