« first day (3292 days earlier)      last day (1639 days later) » 

12:01 AM
@thesecretmaster That question is very unclear, and the OP was unable to clarify it in the comments. You're lucky that it's closed - if you posted an answer based on your guess of what the OP is really asking then there's a good chance that your answer would be downvoted.
 
@PM2Ring That's true, I guess I just can't think of a clearer way to ask "What's an instance variable and how does it work" without already knowing what an instance variable is, so I think it's as clear as it can be. But you're both right that it should be closed either way (although maybe it should be a dupe of this instead).
 
@thesecretmaster My feeling is that the OP needs something more than a simple Q&A at this stage. They need a tutorial, or at least some kind of dialogue. It's hard to do that stuff in the Q&A format.
But maybe you can have a brief dialogue in the comments that will result in an answerable question. If you want to do that, please feel free. You could just edit the question yourself, but I think that'd be putting words in the OP's mouth.
The 1st edit after closure will send the question to the reopen queue. But you're also welcome to post a reopen-pls request here if you do manage to get it fixed.
 
@PM2Ring Yeah, the reason I wanted to post here is because it looks like it got a tag only edit right after closure, which I think kicks it into the queue even though it hasn't changed.
@PM2Ring You're prolly right about that, it seems like they're looking for a tutorial about classes. Which makes it close worthy for a 3rd reason :/
 
12:16 AM
@thesecretmaster No, I already checked that: stackoverflow.com/posts/58459952/revisions ;)
@thesecretmaster Some of us (including AaronHall & me) do occasionally write mini-tutorials. But even then we need a fairly focused topic, otherwise the answer ends up being huge. :)
But for something as broad as "How do classes work, what's an attribute, what are classes for, ..." they need a proper tutorial / textbook & probably dialogue with a teacher.
 
Ah yeah, I just commented and they said the question was about how to modify an attribute. Now let's see if I can make a reasonable edit...
@PM2Ring What do you think of this edit? Does that seem to clarify it?
 
12:36 AM
@thesecretmaster That's better, but there's a typo "be be". And a & lol should be in backticks, not quotes. But let's see what the OP thinks.
 
Thank you for your help by the way. I don't do things on SO that much, so I'm a bit unsure of myself.
 
My pleasure!
Also, it looks like the OP is using 5 space indents. You should fix that too.
 
Ah good point. I should've been more careful the first time around, since now those edits alone don't get me over the character minimum :/
 
@Paul
there is a c function in R
which is used to combine values into a list
 
@thesecretmaster I think they would, but I'll do them. It's just slightly painful on the phone...
@thesecretmaster Done. Now let's hope the OP approves. ;)
 
12:50 AM
OP seems both agreeable and responsive, which is nice
Anyways, I guess it'll work its way through the reopen queue now (or maybe not, I hear the queue is long), and then hopefully OP will get either an answer or a useful dupe closure. Thanks for the help again!
 
No worries. I've casted a reopen vote. But I hope the OP posts a comment saying they approve of the changes.
Ah, I see the OP approved your edit. I guess that's good enough.
 
1:22 AM
cabbage gentle people
 
 
4 hours later…
5:23 AM
@PM2Ring it's opened now
 
 
1 hour later…
6:31 AM
TIL def foo(*, **kwargs) is a syntax error
 
6:48 AM
@PM2Ring yea
 
 
1 hour later…
8:08 AM
So I've totally herp-de-derp'd this script and not sure where to go next. Why is life hard? :D
 
8:25 AM
Oh god I'm an idiot tooooooo hahaha
 
8:37 AM
If I open a file in one function, which calls another function - is the file available there too, or do I need to pass the object?
I'm presuming I do, but i'm clearly a bit dim this morning!.
 
try it and see what happens
 
or think of how you'd be using that file without passing it
 
8:56 AM
@AndrasDeak o_O?
 
What would you do with the file, assuming it was accessible?
how would you use the file object?
 
Hey guys, quick question. How do I combine the following 3 regular expressions:
re.findall(r"\n+[0-9]+[0-9]*\n*[^\.]{5,}\.",text_clean)
re.findall(r"\n+[0-9]+[0-9]*\n+[^\.]{5,}\.",text_clean)
re.findall("\n*[0-9]+[0-9]*\n+[^\.]{5,}\.",text_clean)
 
So "a newline on at least one side"? I think the middle one is already redundant
 
"combine" meaning what exactly?
the combined regex should match if all 3 of those patterns match? Or if at least one matches? Or if all 3 match one after another? Or if it's a tuesday?
 
Actually, I need one of those matches.
 
9:07 AM
@Aran-Fey I hope it's the tuesday one because then we have another day to figure it out
 
What is a tuesday lol?
 
Good question, considering time zones and stuff.
 
-_-
 
I've got a question here elligible for a bounty, which is about using threads for popens, anyone want to take a shot? stackoverflow.com/questions/58451493/…
 
(?:\n())?\n*\d+(?:\1|(?!\1)\n)\n*[^.]{5,}\. should do it, though I wrote that without testing
 
9:11 AM
@Aran-Fey I didn't know you could use matched tokens in lookaheads, that's nice. (I didn't know you couldn't use them)
what is the purpose of ()?
 
that lets me check whether the pattern matched a \n at the start or not
 
hmm, okay, I'll have to unpack that later
 
because there has to be at least one \n either at the start or in the middle
>>> re.match(r'(?:x())?foo(?:\1|(?!\1)x)', 'xfoo')
<re.Match object; span=(0, 4), match='xfoo'>
>>> re.match(r'(?:x())?foo(?:\1|(?!\1)x)', 'foox')
<re.Match object; span=(0, 4), match='foox'>
>>> re.match(r'(?:x())?foo(?:\1|(?!\1)x)', 'xfoox')
<re.Match object; span=(0, 4), match='xfoo'>
>>> re.match(r'(?:x())?foo(?:\1|(?!\1)x)', 'foo')
>>>
^ that's what it's doing, basically
(?:\1|(?!\1)x) is basically "If I found an x earlier, I don't have to match anything now. If I didn't, I have to match an x now."
 
@Aran-Fey Thank you
 
Morning guys ! Quick question regarding REGEX. I want to get the image url using regex, how I can do that and is this smart ? "https://img.test.com/IMAGENAME-1.jpg&nw=43" &nw=43 is the unique thing that I think i can use it to get the url...other than beautifulsoup...any ideas ? what would be the easiest way to get the image url ? Sorry if question is too broad.
 
9:21 AM
You want to extract "https://img.test.com/IMAGENAME-1.jpg&nw=43" from a bigger text?
 
@Aran-Fey yeah, from a page source, and &nw=43 would be unique value to get the exat url of the .jpg files
 
Something like (?<=")[^"]+&nw=43 I guess?
 
9:33 AM
i'm trying it here : regextester.com and can't get it to work
:(
 
reader = csv.DictReader(data) - I need a copy of reader.... but copy.deepcopy cries at me
unless ican actually itterate on it more than once, and it's something else that's broken in my code :(
 
@Andie31 choose python's flavour :P
@djsmiley2k-CoW itertools.tee can replicate iterators for you, just make sure you really need it
 
I'm not sure I do, but I think this script I'm doing requires some major restructuring and I didn't make a backup before breaking it >_<
/me feels stupid now
 
@AndrasDeak hehe, which one :) spicy one ? :)
 
At the same time, the 'backup' would be a copy of a broken script anyway so...
 
9:39 AM
try finding "python" in there
 
@AndrasDeak no luck
:(
 
indeed
 
used this one : pyregex.com
 
try regex101.com
 
also no luck
 
9:42 AM
if it doesn't work there (with the python flavour) you'll know it doesn't work
 
@AndrasDeak nope :(( regex101.com/r/jsbXRv/2
 
Since it's HTML, I assumed there would be quotes around the url.
 
24 mins ago, by Andie31
@Aran-Fey yeah, from a page source, and &nw=43 would be unique value to get the exat url of the .jpg files
you are not trying to match a page source
 
still no luck :( can't ge it :) Mondaaaay
 
you'd also have to switch to ' rather than " to avoid the syntax error
(options to the left of the pattern on regex101)
 
9:58 AM
pffff....so confused :)
better use beautifulsoup instead ? :)
 
it usually doesn't hurt to try parsing HTML with an HTML parser, yes
 
@AndrasDeak thank you ! Last question. There's an image url parser or an easy way of doing it without figuring out all the div....span...ul....li tags ?
 
@thesecretmaster Hey, stackoverflow.com/q/58459952/4948732 has been reopened now, so you can post an answer... or a dupe target suggestion.
 
What does "figure out the tags" mean?
 
10:23 AM
@Andie31 You have two options. 1 Use a proper HTML parser, and that will handle all the tag stuff for you. 2 Use regex, and don't worry too much about the HTML structure, just focus on the actual URL patterns that you're trying to extract. Option 1 is generally the best plan. Using regex on HTML is almost always a bad idea.
 
10:34 AM
Occasionally have a skim to see if there's anything interesting on various sites... but wasn't quite expecting this one
 
Sam
Guys, I have a problem
I dont know how to explain it
 
then come back when you can
we can only help if you can explain it
 
Sam
It's just - you know when you talk to Siri and Google Assistant, it captures every word before you complete your sentence?
Do you guys know what thats called?
Like if you say hello how are you, when you say hello hello appears, when you say how how appears, etc etc
 
10:53 AM
@Sam I don't use that stuff, so I don't know if there's well-known jargon for that, but I'd call it something like "word by word speech recognition" or "single word voice to text".
 
@Sam there are a bunch of techniques to get autocompletion/autosuggestions to work. For chat applications, markov chains are popular because they are quite powerful, everybody knows them, and they only need a very narrow pool of suggestions. For index lookups like google's suggestions you'd do tricks with DAGs because they are crazy fast.
in other words, if a corpus powers your lookup engine, use markov chains. If a database powers it, use DAGs.
 
11:18 AM
I'm trying to compile generated function code into a function. I can get it to work except for decorators. Is there something simple I can change?
>>> import types
...
... def doubler(fun):
...     def wrapped(*args, **kwargs):
...         return 2*fun(*args, **kwargs)
...     return wrapped
...
... source = """
... @doubler
... def square(val):
...     return val**2
... """
... co = compile(source, 'tmp.py', 'single')
... fun = types.FunctionType(co.co_consts[0], globals())
... fun(3)  # undecorated: 9; decorated: 18
9
currently I'm just decorating fun manually at the end (which is not a huge deal)
 
You get the source code as input?
 
yeah, but I control it
And the real decorator is more like functools.lru_cache; can't just amend the return value
And I can't just exec because this goes inside a function
 
Not following. execing it in a new scope and grabbing the function from there would've been my first idea. Why can't you do that?
 
If you mean by passing a local dict to exec then yeah, that's an alternative. I just figured it would be cleaner to create a function object directly, since I want these to end up as attrs of a class
I guess that wouldn't be much worse than what I have now
 
class Scope(dict):
    def __init__(self, globals):
        self.globals = globals

    def __getitem__(self, item):
        return self.globals[item]

    def get_function(self):
        func_name = next(name for name in self.keys() if name != '__builtins__')
        return super().__getitem__(func_name)

scope = Scope(globals())
exec(source, scope)
func = scope.get_function()
print(func(3))  # 18
 
11:34 AM
that...would basically create the functions in the global scope, right?
Ah, no
It has access to globals as an attribute
Thanks, fancy
 
I was gonna use a ChainMap instead of a custom class, but exec only accepts dict subclasses...
 
Is the only downside to d = {}; exec(source, globals(), d); func = d['fun_name'] the use of 'fun_name'?
 
Hmm, yeah, actually it is
 
Because I already have and need the name. So I guess I can go with that. Thanks :)
 
If we wanted to pass both globals() and locals() to exec then we'd need a wrapper dict, but for a function definition we don't need locals() anyway
 
12:31 PM
cabbage
 
cbg
 
12:50 PM
after pondering the meaning of assigning special methods on instances for, oh, a few days, today I realised that I've taught the Python Object Model completely wrong for years. Bonus points for the official documentation being equally subtly wrong.
resumes meditating about the meaning of life, the universe and POM
 
you can't just drop a bombshell/cliffhanger like that and just continue meditating! Mr. Miyagi, we must know!
 
@Paritosh patience Daniel son :)
 
cbg
 
There is no special method lookup. Either look up a method you do, or not you do and just stumble upon something that was derived from looking up a method you may.
cbg
it appears my Yoda.foo is weak today.
meditates on Yoda.bar instead
 
1:08 PM
With each sentence I read I get more confused
 
@MisterMiyagi not the traditional new style classes always do it on the type rather than the instance thingy?
 
I need help... can anyone think of a decent way to write this as a one-liner?
def implements_dunder(cls, method_name):
    for cls in cls.mro():
        try:
            method = vars(cls)[method_name]
        except KeyError:
            continue
        else:
            return method is not None

    return False
 
@Aran-Fey the TLDR is that the entire "special method lookup" discussion is mightily misleading. if you are doing c.__len__ instead of type(c).__len__.__get__(c, type(c)) you are not looking up a method, at least not anymore than you are looking up a property, slot or attribute.
@Aran-Fey that looks like a job for any
 
any would be wrong - I only want to look at the first thing I find
can't find a non-convoluted way of doing it with next though
 
takewhile perhaps?
 
1:24 PM
not sure how
 
def any_dunder(cls, method_name):
    return next(
        vars(mro_cls)[method_name] is not None
        for mro_cls in cls.mro() if method_name in vars(mro_cls)
    )
doesn't exactly get a +1 on readability from me
perhaps add asspressions to the mix?
 
Umm.... next((True for k in cls.mro() if vars(k).get(method_name) is not None), False) ?
 
I need to actually compare the thing to None, not just check if it's there
 
Cabbage all
 
1:28 PM
@PM2Ring I'm not finding a quick find for a dupe target. Which surprises me. So I posted a quick demo answer.
 
@MisterMiyagi Hmm, that fails if no class in the MRO defines a method with that name... so something like next((vars(c)[name] for c in cls.mro() if name in vars(c)), None) is not None
That's actually not too bad
@JonClements That's still incorrect because it doesn't distinguish between a class that doesn't implement the function and a class that's assigned None to it
 
okay... looks like you might have got it then... :)
 
>>> class Iterable:
...   __iter__ = lambda self: iter('abc')
...
>>> class NotIterable(Iterable):
...   __iter__ = None
...
>>> next((True for k in NotIterable.mro() if vars(k).get('__iter__') is not None), False)
True
 
bah, I spent half an hour figuring out some vector directions when rotating around a weird axis in 3d, and I just realized I actually have to perform a much simpler rotation :(
 
at least it's only half an hour :)
 
1:43 PM
okay, actually, I messed up what I did and accidentally did what I was supposed to do...with 20 minutes more work than necessary
 
@toonarmycaptain I am still unclear about what exactly confused the OP. They are already adding something to the class (instance, actually) in __init__.
 
I'm not sure if that makes it better or worse
 
@MisterMiyagi I think they maybe didn't realise that that have to reference self.a rather than a in their method.
Or maybe understanding that they can reassign the instance attribute like any other variable?
 
@toonarmycaptain That looks ok to me. Let's hope it's what the OP is asking about. ;)
 
@PM2Ring I just edited to clarify that self.a is assigned the value of a, and that value can be altered by altering the value given to self.a. But I really have no idea what OP is really wanting. I'm also shocked there isn't a canonical dupe out there.
 
2:00 PM
Hi all. I'm trying to run popens in separate threads, on a VM with 16GB of RAM and 6 CPUs. However, none of the threads are actually completing and I have no idea why. I've tried moving the sigints on line ~20 in thread_client(...) out of the while loop and not having it at all and it still crashes and I have to restart the entire VM to try again
 
hello
 
The threading code is the first method and is called on lines 77
 
user11867329
Morning.

Guys, what's the best Mind Mapping software (iyo)
 
@OTLT-LCar Hello. I don't know what that is but it doesn't sound very python-related
 
@rshah your threads all run an infinite loop...
 
user11867329
2:05 PM
@AndrasDeak it's somewhat related. I'm actually surprised you don't know what a Mind Map is(?)
 
cabbage, folks
 
@OTLT-LCar And I'm surprised that you're surprised. Now it's the two of us.
@inspectorG4dget cbg
 
user11867329
@MisterMiyagi A quick fedora tip to your Yes Man profile picture, btw.
 
@MisterMiyagi I'm changing the value of time_reached = True when the time has elapsed, so all threads while loops should finish right?
 
user11867329
@AndrasDeak you buggin'
 
2:06 PM
@rshah your code literally says while True:
no amount of changing variables makes this not loop forever
and I don't see any variable named time_reached in the code.
 
I have an odd problem: anyone know how I can monitor the bandwidth usage of my 15proc (multiprocessing) python code? I've written a parallelized uploader and I want to make sure I'm saturating my bandwidth
 
you can read the interface data from /proc, if you feel like it
and are running on Linux
or try psutils
 
I'm on OSX, so I should be able to read /proc. But wouldn't that tell me the overall bandwidth usage and not just for the procs I care about?
 
OSX doesn't have /proc
 
2:12 PM
Just don't download anything else while you're monitoring ¯\_(ツ)_/¯
 
also, psutil looks yamming great! Any way I can filter for specific PIDs?
@Aran-Fey rofl
 
(/proc would give you access per PID)
 
if you want to find out what is actually going through the interface, doing that per-process is rather tricky. network works with packets, not processes.
 
@MisterMiyagi my bad sorry! Here's the code gist.github.com/ryankshah/c610bf247d565a3d23e05feec6d55277
That was an old gist in paste history
 
if you just want a rough estimate, have each process report the len of the bytes it sends
@rshah can you please post that as a .py? syntax highlighting helps immensely.
 
2:15 PM
@MisterMiyagi refresh the gist, I edited the type
 
@AndrasDeak See en.wikipedia.org/wiki/Mind_map The terminology is relatively new, but as Wiki says, people have been doing that sort of thing for ages.
 
hmm... thanks. I'll just have to listen to music off my phone, then
 
@PM2Ring ugh
 
While I consider mind maps themselves useful, I've always thought it a bit highfalutin to give a specific name to the concept of "drawing a graph of concepts"
 
cbg
 
2:18 PM
Here's my mind map:
[mind maps] -> [highfalutinness]
 
@rshah you need to declare time_reached as a global in runExperiment. otherwise it just updates a variable internal to that function.
I still don't see how mind maps are related to Python. Can someone draw me a mind map, perhaps? :/
 
Just at the beginning of the function?
 
def runExperiment(policy, port, device_id, level):
    '''Run experiments with n clients and m servers'''
    global time_reached
    ...
 
Cool
I'll give that a go :)
 
python -> programming -> software development -> developer tools -> conceptualization tools -> mind mapping software
 
2:21 PM
global ouch
 
take note that a threading.Flag would be more approproiate
 
@MisterMiyagi even with that change, the program is still not ending.
It runs the java program for the client once
But it should loop
re-run the client program*
 
if it's running only once, how is it not ending?
also take note that each iteration takes at least 9 seconds, but you only wait 10 seconds after starting threads. if starting the client and sending the signal takes more than 1 second, you only get one iteration.
 
So would the solution here be to either remove the sleep for 9 seconds or shorten it?
 
since I have no idea what your program is doing or why you are waiting 9 seconds, I have no idea
I cannot tell you how to reach desired behaviour when I don't know what behaviour you desire
 
2:29 PM
That popens[client].send_signal(SIGINT) line looks strange to me. Doesn't SIGINT usually kill a process? Why would you start the client and then kill it?
 
The java program is outputing a read time for what it does to the command line, the python program is reading these and writing to a file
 
@Kevin SIGINT is ctrl+c, it suspends execution
you can often continue afterward
"often" might really be "when inside gdb", but close enough for me
if you want to kill it you'd use SIGKILL or SIGTERM
 
Keep in mind that the conditionals of while loops are only checked at the beginning of the block. If time_reached changes to True while time.sleep(9) is executing, Python won't "notice" it yet, and it will go on to execute popens[client].send_signal(SIGINT). So if your desired logic is "sleep for nine seconds, and send SIGINT only if time_reached is not yet True", then the code you have won't accomplish that
@AndrasDeak Ok, that assuages my fears a little bit.
 
@rshah so you just want to read one line from stdout and then kill the process?
 
I want to continuously read lines from each of the clients (as they keep running) until the time_reached is true
 
2:35 PM
according to the docs, you get regular Popen instances. These already support stdin/out and timeouts.
is there any reason why you are rolling out your own file based communication?
 
Would it make sense to call popen exactly once for each worker thread? Maybe you shouldn't have a while loop at all.
 
cbg
 
@Kevin so I guess it turns out that UML diagrams are just mind-maps?
 
does anyone have any idea how long itll take for numba to release a wheel thats compatible with python 3.8?
in terms of a rough timescale
 
@3141 that's pretty much something that only they can tell
Have you checked if they have a mailing list or gitter or something?
 
2:36 PM
What I'm envisioning is: the worker thread calls popen once, then pauses. Meanwhile, the main thread sleeps for ten seconds. Then it tells each worker thread to unpause. The worker threads do so, and then call SIGINT on their processes, and then terminate themselves.
 
ahh ok ill take a look
i was just wandering if anyone knew roughly how long these kinds of things take from experience
but thanks im looking right now
 
if there's a mailing list odds are this has already been discussed in the archives
 
I would just expect something akin to stdout, stderr = client.popen(...).communicate(timeout=10). no loop, no adding processes to long-lived dictionaries and overwriting them.
 
I'm not sure what threading control object one might use to have one thread send a message to all of its child threads... threading.Event, maybe?
 
I think the first time I used numba was yesterday so I don't have long-term experience with their release schedules. And I've been using numpy for a long time and I don't know theirs either. But it comes up on the mailing lists around releases.
 
2:38 PM
@MisterMiyagi the popen will run the client program once, whereas I want to run it for each client host until the 10 secs is up
 
@MisterMiyagi Ah, not a bad idea. Then you don't even need an Event.
 
thanks andras, im searching now
 
but you are running each program once for each client host. then you rerun it again for each client host depending on some unstable timing.
 
Yeah, I'm growing increasingly uncertain about the purpose of the while loop here
 
But wouldn't the popen close once the program has finished executing?
 
2:43 PM
I suppose. Is that bad?
 
since you are explicitly sending a SigInt, I was under the assumption it does not finish executing.
 
The purpose is that the clients continue to run the program until, say 10 seconds or 60 seconds is finished, by which point the pmonitor for the popens will run
 
I have no idea what a pmonitor is.
 
Its a generator
 
I mean conceptually. does it need the process to be alive? does it need to process to be stuck handling SigInt?
 
2:45 PM
When you say "run the program until 10 seconds is finished", what should happen if the program finishes in less than ten seconds? Run it a second time? If so, why?
 
So I can get more output times from the client programs
Effectively simulating n active connections over 10 seconds
 
But if you run the client more than once, the second popen object will overwrite the first one in the dictionary. Won't the output of the first execution be unrecoverable, then?
 
but you only run them for 9 seconds.
if you are looking for a congestion in a 10 second window, your processes should run longer than 10 seconds.
to account for startup time.
 
@3141 this might be relevant github.com/numba/numba/issues/4071
 
I need a dup for mylist = [[0]] * 2; mylist[0][0] = 1; print(mylist) 😲
 
2:48 PM
you'll probably sooner get experimental wheels than proper ones; the 0.46 release that's soon out still supports 3.7 at most github.com/numba/numba/issues/4679
 
@Kevin for that I could just make the value for the client key a list and append to it
 
thx AD
 
@rshah but why not run one process per client long enough?
 
I can do, but each client is still only running the jar once
 
2:50 PM
replacing processes won't be instantaneous, you are just going to introduce an error.
@rshah I don't see a problem with that if the jar runs longer than your data taking window.
 
@rshah Ok, makes sense.
 
The execution time of the jar should be irrespective, like if it takes 30ms then this is captured in the popen, and the jar should be run again and so forth until the overall time (i.e. 10 secs) has elapsed
 
aren't you measuring network congestion?
 
No, I'm measuring the times for the client to send a request to the server and receive a response
that's what is recorded in popen
 
plus, if it really takes 30ms to run the jar -- then each client isn't doing anything for at least 8070ms
 
2:54 PM
Yes
So I want the client to run again
Until the entire time has elapsed
 
I wonder whether it would make sense to use check_output instead of Popen. Then you don't have to juggle a bunch of semi-living client objects.
 
@Kevin the Mininet API seems to only have Popen.
 
Oops, I thought we were using subprocess. Oh well!
It might still make sense to make it the responsibility of the worker threads to extract the output from each client and kill the client in a timely manner.
 
yeah, that's why I'd recommend .communicate
 

« first day (3292 days earlier)      last day (1639 days later) »