« first day (3587 days earlier)      last day (1344 days later) » 

12:07 AM
The explanation they give is really misleading too. String concatenation is optimized only under very specific circumstances. If I'm remembering old threads right, it's primarily that there can be only one reference to the string.
 
12:57 AM
@AndrasDeak It's hard to tell, and with these types of question, it's starting to seem more sensible to go seek guidance at the monastery...
 
 
2 hours later…
3:19 AM
I'm confused about sphinx, does it just generate a template that I'd still need to write docs for or does it actually create content too? The autodoc thing implies it's automatic which would make sense because it can access all my functions and their docstrings but also it seems like it just allows me to insert docstrings as I write rst files
(is there a way to automatically generate docs?)
 
4:14 AM
You must run autodoc to automatically create the docs for you. Sphinx just compiles whatever docs there are.
Personally, I‘ve switched to manually written docs that just use the autofunction etc. directives to pull in docstrings. Example: github.com/maxfischer2781/asyncstdlib/blob/master/docs/source/…
 
5:02 AM
@aadibajpai Assuming your code has docstrings (in the right format) on its classes, methods, members, it autocreates doc from those. See the doc for details and tutorials.
Public Service Announcement: I wasn't aware of the useful SE site SoftwareRecommendations till now, although it's been mentioned occasionally.
@aadibajpai: you can always manually massage the doc that sphinx autocreates, but that's frowned upon, because you should be able to do most of what you want with docstrings. Some people say otherwise about sphinx, I'm not an expert so that's everything I know. While you're at it you might like to also add unittests.
 
5:42 AM
sphinx: converts rst to HTML
autodoc: adds `autoclass`, `autofunction`, etc directives that turn your docstrings into rst
apidoc: automatically creates rst files containing `autoX` directives from your source code
 
6:28 AM
Hello everyone. Greetings! Please help me with drag and drop a search list value to any random place of the page using selenium web driver. Let me share the link for elaborating the problem stackoverflow.com/questions/63313099/…
 
 
3 hours later…
9:17 AM
Hey everyone,
I have a django app which will store users and authenticate them when provided with credentials. I'm using django default authentication module for that. but when i call authenticate(usernmae="uname", password="pass"), this method is returning string instead of user object.. please help me with this peoblem.
 
9:27 AM
Hullos,
I'm trying to nest my endpoints in DRF.
I have two URLs
r('profile') gives profiles
r('notificationsetting') gives notification setting per profile

I'd like the latter URL to be like this:
/profile/{id}/notificationsetting

What would be the best way to about this?
 
 
1 hour later…
10:43 AM
If I have to obj.channel.recv_exit_status() to get the return code (I have more than one object), is it ok to have a lambda like so get_ret_code=lambda x:x.channel.recv_exit_status() or is there any other way? Down the line I can do get_ret_code(obj_1) and so on
 
ah, if you want to have obj change, then not really
although a named lambda is generally considered bad practice
def get_ret_code(obj):
    return obj.channel.recv_exit_status()
 
I thought lambda was for one line expressions
 
no, lambda is for when you don't want to bind it to a name, as in sorted(seq, key=lambda obj: obj.channel.recv_exit_status())
You will often see one-liners as lambdas bound to names, but as I said that's controversial style.
 
ok, I will prefix it to a _function then, thanks
 
What?
 
10:48 AM
I mean def _get_ret_code
 
Ah, OK. But if your original name didn't have an underscore then this shouldn't have one either.
 
I know the _ there doenst do much but I read it is practice to name modules with a single underscore to note its internal
 
I mean in that case you should've done _get_ret_code = lambda ... because once the function is defined they behave the same way
you can define the function right where you would have put the lambda if you don't want to expose it to the global namespace
but yeah, you can also put it in the global one with a leading underscore
 
function inside functions, I remember talking about this in this room
 
@python_learner yes, there's nothing wrong with that (although they are rarely needed)
I've used nested functions in similar situations. Defining a function right before using it as a key or other similar function for interpolation, integration etc.
 
10:52 AM
I had this lambda defined inside a function so I would rather nest it
 
@AndrasDeak what you mean by named lambda?
 
@khajvah what they just did: binding a lambda to a name
@python_learner I figured. You're free to do so.
write it out and see if it reads well
 
oh okok, I thought you meant defining a function for what should have been a lambda
this is kind of a big deal to be honest. that lambdas are one liners with all the functional stuff that's getting popular
 
just changed it, kinda looks explicit now, people wont ask me where it is defined lol
 
@khajvah functional stuff doesn't belong in python very well.
and lambdas have limited functionality
nothing stops you from writing the same functional code with proper named functions
 
11:01 AM
it's not cute tho
 
A lambda is not a one-liner. It is an anonymous function of a single expression. The former is not an advantage, and the latter does not restrict the size at all.
You should only use a lambda when you need to define a function as part of an expression. In any other case, a lambda declaration is inferior to a def declaration.
 
recbg
 
I tried to find a good looking multiline lambda in our codebase to prove my point but was unable to find it, so eyah
 
11:25 AM
I use named lambdas occasionally. Usually only when the stars align, and:
- the function is sufficiently simple that the limited functionality of lambdas is irrelevant
- I'm only calling the lambda on lines very close to its instantiation, so readers are unlikely to be confused about where it was declared
- readers are ambivalent about whether it looks better (I am frequently my only reader, so this is easy to achieve consensus on)
 
stars_aligned = (lambda * x,
                        **y: print('like so?'))
 
As much as I love to campaign for gratuitous alignment in line continuations, yuck
 
I have the feeling this calls itself infinitely and also I see many times the same output in the log
    def __init__(self):
        signal.signal(signal.SIGINT, self.exit)
        signal.signal(signal.SIGTERM, self.exit)

    # noinspection PyUnusedLocal,PyUnusedLocal
    def exit(self, signum, frame):
        self.running = False
        while self.running_collecting_data or self.running_classifying:
            time.sleep(1)
        print("Finished waiting for threads to close. Closing gunicorn server")
        os.kill(os.getpid(), signum)
The question is then, why does it ever even stop? Does python have some way to break this self calling signal handler?
 
11:41 AM
Is there any reason why the signal handler re-raises its own signal?
it looks like this code is lacking some super() calls.
 
My original problem is that gunicorn hangs and doesn't close. And I thought that is because I catch the signal and gunicorn doesn't receive it. But I just found: github.com/benoitc/gunicorn/issues/1256 which claims to be fixed after 19.5. But I am experiencing it in 20.0 so I think it didn't get fixed properly
 
How do you actually stop this? Do you just send SIGINT/SIGTERM to it once? Do you have some init service killing it?
 
I use supervisor where I press stop, which I assume sends sigint? sigterm?
according to the doc it sends sigterm
 
if there's no option to resume it's probably sigterm
you could probably write a small script to test this
 
Actually it is sigterm, I just checked
but still, why does gunicorn take so long to close? It closed now after around 210s
my timeout is 300 and gracefull shutdown is 30s
so I don't get what's going on
 
11:52 AM
needs moar sigkill :P
 
haha well the purpose of writing your own signal handler is exactly to shutdown gracefully not to kill everything :D
Ok I just tested it again. It is consitently 150s. I wrote 210 above, but that is because I can't do math. 2.5min = 150s :P
 
12:07 PM
You guys are not gonna believe this. For some reason gunicorn takes timeout/2 time to shutdown. I would understand timeout. But why divided by 2? I just tested it 4 times with 300s, took 150s every time and 4 times with 30s takes 15s every time. Wth is going on ¯_(ツ)_/¯
 
Factor of safety? I.e. taking Software Engineering too literally ;)
 
hmmm for 10s it doesn't work. There might be other factors for low timeouts I guess
 
Not a gunicorn expert, but does it have to actively check for shutdown? Your above code doesn't call anything, it just sets self.running = False.
Deriving a sample interval from a timeout, e.g. sample = max(timeout/2, 10) isn't uncommon.
@Hakaishin Are you sure that's all it does? Various service managers will send sigterm at first, then sigkill after a delay.
 
12:23 PM
@MisterMiyagi that is for my own threads. I assume gunicorn somehow gets the signal
@MisterMiyagi no clue. But I give up. I thought it's maybe the gracefull shutdown, but that also seems random. Well since the values are low it shuts down relatively fast 15-20s. compared to 150s. But this still seems so high.
 
@Hakaishin Since you've replaced the signal handlers, it should not.
 
Then why does it shutdown at all?
 
Sorry, no idea. All I'm seeing is a code snippet that doesn't make sense in isolation, and the not-exactly-readable gunicorn codebase.
 
yeah, sorry. I will just let it be. I got the shutdown time from 200s to 20s. Which makes it usable for now. Thanks for trying to help
 
12:50 PM
wow. gunicorn is really a zombie. I removed my signal handler and made supervisor send a sigkill but it still stays alive. How :O?
 
@Kevin that's just because if you do the splats on one line, then the stars are aligned anyhow
lambda *a, **kw they're pretty much in conjunction there.
 
My crystal ball says to blame zombie processes on threading
 
@Hakaishin is it the same process and not a new one?
 
gunicorn creates 2 processes on startup. One closes relatively fast 1 stays for a random amount of time open
is psutil good?
 
I don't think it has a natural alignment toward good or evil
 
1:01 PM
psutil is chaotic neutral.
Usefulness highly depends on the OS you are running on.
On Linux, it's lawful good.
NB: It's usually the OS' "fault" for not giving access to the required data.
 
After thirty minutes of experimenting with signals, I have decided that I do not understand signals.
 
@Kevin yes
@MisterMiyagi good :)
@MisterMiyagi the best alignment :D
lol now gunicorn hangs already for 10min
I don't get it. psutil + kill it is
 
You can in fact compose a signal handler that calls itself until the process crashes with RecursionError. you can also write one that looks like it should overflow the stack, but doesn't. I think the difference is whether you're using signal.raise_signal or os.kill respectively
 
@Kevin Seems like an important signal for your learning process.
 
I don't want to understand how operating systems interact with processes ;_;
I want my programs to execute in a perfect empty abstract void
 
1:13 PM
Finished waiting for threads to close. Closing gunicorn server
Killing process with pid and name: 8053 gunicorn
Killing process with pid and name: 8056 gunicorn
Finished waiting for threads to close. Closing gunicorn server
Killing process with pid and name: 8053 gunicorn
Killing process with pid and name: 8056 gunicorn
Finished waiting for threads to close. Closing gunicorn server
Killing process with pid and name: 8053 gunicorn
Killing process with pid and name: 8056 gunicorn
Looks like I'm fighting some restarting of the process
grrrr
 
Sorry for the interrupt, but do you guys know a good place/link/video to master python classes methods and objects? where did you learn these?
 
It looks a bit fishy that the processes have the exact same PID. Are you sure the process is actually dead?
 
yeah, I don't get it. It doesn't make any sense. This output shouldn't repeat at all....
 
I learned Python's OOP model from the official docs, but I didn't need much tutoring on the topic since I had experience with several OOPy languages beforehand. so YMMV.
 
@Kevin It's fine, lots of people don't. Those that don't but try anyways are a good part of my job security. And electric chainsaw sales.
 
1:15 PM
    def __init__(self):
        signal.signal(signal.SIGINT, self.exit)
        signal.signal(signal.SIGTERM, self.exit)

    # noinspection PyUnusedLocal,PyUnusedLocal
    def exit(self, signum, frame):
        self.running = False
        while self.running_collecting_data or self.running_classifying:
            time.sleep(1)
        print("Finished waiting for threads to close. Closing gunicorn server")
        for pid, name in search_procs_by_name("gunicorn").items():
            print("Killing process with pid and name:", pid, name)
 
I'd decently sure that os.kill(pid, signum) is wrong.
 
how?
 
It will raise signum for your process, which has self.exit as the handler for signum, which will raise signum for your process, which has self.exit as the handler for signum, which …
What class are you inheriting from? You're only showing __init__ and exit, not the class declaration.
 
Maybe you already know this, but signal.signal returns the previous handler of the signal. If you hold on to it, you can call it at the end of exit and e.g. get the usual "print a stack trace for keyboardinterrupt and then quit" behavior that ctrl-c usually triggers
 
@Daniel That's a bit like asking "how did you master numbers?". Classes, methods and objects just are. There's nothing to master about them, other than knowing some definitions.
 
1:18 PM
Passing the signal up the handler chain feels like a more robust approach than calling kill() on your own
 
@MisterMiyagi to be fair, children "master" numbers at some point. It's just a very lax word to use
 
I don't think SIGTERM has a handler, though, so that might only work for SIGINT specifically
 
Hm, that's true. Learning the numbers themselves still seems mostly memorising, though.
 
I would understand "mastering" to mean being able to perform common operations for which the objects in question were made. Like additon, multiplication and so on. So mastering objects and classes involves operation one performs with them to do usefull stuff. But it's a broad question
 
@MisterMiyagi I think I should be more specific where did you learn how to code more "pythonic"?
 
1:21 PM
Learning what numbers are is something a kid can learn in kindergarten. Learning how numbers are useful is something that we give out Nobel Prizes for.
 
@Kevin That was what I meant, how did you learn they are useful and used it efficiently in your project?
 
My code became more Pythonic after I spent about a year being nagged by the guys in here about my heretical use of camelCase instead of underscore_case
 
The challenge is to learn when not to use these things.
 
Not sure if this is helpful, but I learned good programming from my own mistakes... over the course of a decade
...and I'm not quite at the goal yet
 
I learned when classes are useful by spending a lot of time writing inefficient/inelegant programs, thinking "this sucks, isn't there a better way?", and carefully considering whether anything I'd learned up until that point could improve things
 
1:29 PM
@Kevin How long did it take? also what do you mean by "camelCase" and "underscore_case"?
 
It helps if you've seen what good code looks like. For me, that was when I saw how incredibly self-documenting code can be when every function is only like 5 lines long
4
 
strange. using stopsignal=Kill in supervisor doesn't work. But using my own weird code to kill the process with kill works. Well I give up
 
Let's see... I've been coding for 20 years, and let's be generous and say I got good at it 5 years ago.
 
If you are looking for some hard rules, there are various tools to check the objective quality of your code. flake8 and black are rather straightforward, and ensure the basic Pythonic feel.
 
@Kevin I'm in the middle of it. I thought classes suck and I will make my code functional and it's better. Boy was I wrong. now I got to rewrite the mess :(
 
1:34 PM
Painful lessons are the most instructive ones :^)
 
Thanks guys.
 
talkin about good code
used to be 10k a year ago so good progress I guess
 
Semicolons are optional in Python. Saved you a character ;-)
The curly bracket can stay, as I assume it's the end of a dict or set literal that started on an earlier line
 
It's JavaScript
 
needs details (or even a question to begin with) stackoverflow.com/questions/63359459/…
 
1:47 PM
shh, let me have my fantasy...
 
also, technically it's inside one single function
lol
 
Semicolons are optional in JavaScript... Sometimes?
I'm not clear on the specifics but I've had at least one JS program whose failure or success depended on a ";"
 
yea but it's unjavascriptic
 
could be brackets
 
When will the government stop your sinful hand, etc
 
1:51 PM
@MisterMiyagi print([def(x) { <- oof (remaining code omitted to preserve the reader's sanity)
 
I don't know how JS devs resist the urge to run their code through a minimizer that reduces it to one very long line, and triumphantly inform management that they've reduced LOC count by 99.9999%.
 
@Aran-Fey while there are some warts in Python that I'd like to see fixed, I'm impressed by just how far people can overshoot the target.
Then again, PEP 622. :/ D: :(
 
PEP 622... is that a new bad idea or one I've already seen...?
oh, the pattern matching one
 
Created 23-Jun-2020 so it's fairly new
 
@MisterMiyagi and if you have to switch to another language, use proper indentation
 
2:03 PM
that's doesn't look too bad to be hones
 
I saw an amusing tweet where the author claimed to prefer an indentation style like:
        def hello(verbose=True):
    if verbose:
print("Hello, World!")

        hello()
I wonder how hard it would be to fork CPython and modify it so it can parse uoɥʇʎԀ
Just rename DEDENT to INDENT and vice versa, how hard could it possibly be
 
Just prepend everything with max indent tabs and treat \r as an indent?
You can probably write an import hook for that in one day.
 
2:34 PM
Today I had a somewhat obscure problem. I googled it, and was surprised to find a stack overflow link. I clicked the link, and was surprised that the top answer had 300 votes. I read the answer, and was surprised that 15 seconds of critical thinking is all it takes to notice the glaring security hole in the provided code.
At least the comment saying "this is obviously insecure" has 60 upvotes, so I know I'm not crazy
Ah, upon closer inspection there's a single line in the answer saying "edit: or, instead of this, you can use the SecureSplineReticulator library". Too little too late I'm afraid.
In any case SecureSplineReticulator is a PITA to use, which is why I was looking for alternatives to begin with
Why can't C# be like Python and periodically engulf useful third partly libraries into the stdlib, preferably with an improved interface ;_;
 
these safety disclaimers should be at the start in <blink> tags
 
Does the main site support strikethrough? I'm tempted...
 
I think so...
but only with <s> tags, and not in comments; something like that
 
@Kevin it does, I often use it, in answers, that is.
 
Crossing out the majority of a popular-but-wrong answer would require levels of passive agressiveness that I can barely conceive of
 
2:46 PM
@Kevin Python does? It seems like many common tasks should not be done via the stdlib, e.g. requests and testing.
 
To give an absolute dinosaur of an example, re
 
Somebody implemented regex as a 3rd party module? That's some dedication O.o
 
Yes, regex is a thing. One thing I know it has in addition is \K
 
I may have misread the history, but IIRC re (nee regex) was a third party library incorporated into Python 0.9.5
1.1 introduced tkinter and curses, those kind of count...
Finding an example from this century left as an exercise to the reader :-P
 
but there's also a 3rd party regex today
 
2:56 PM
True
 
unittest was new in 2.1
April 2001 :')
 
I think I was thinking of 1.5.3's regular expression module:
> The new regular expression engine, SRE by Fredrik Lundh, is fully
backwards compatible with the old engine, and is in fact invoked
using the same interface (the "re" module). You can explicitly
invoke the old engine by import pre, or the SRE engine by importing
sre. SRE is faster than pre, and supports Unicode (which was the
main reason to put effort in yet another new regular expression
engine -- this is at least the fourth!).
 
Looking through the changelogs, 3.4 was the last version to add modules I'm significantly using, namely pathlib, enum and typing. Of these, typing would have been better left third-party (which is why we have typing_extensions).
 
Since then the regex module is fairly explicitly copyrighted by Secret Labs AB. Relatively third-party, by my reckoning
One might inquire as to whether the library was written specifically for the purpose of including in Python, which is an interesting question that I have no information about
At least we know that Secret Labs AB isn't simply a semi-independent skunkworks that only churns out stdlibs, because PIL was written by the same company and guy and PIL is not in the stdlib
 
PIL might just be a ploy to throw you off their trail.
 
3:09 PM
@MisterMiyagi oh yeah, pretty sure enum was third-party too
 
Which explains why they stopped developing it, assuming that the trail was too cold to follow... Hmm
Frederik is now living in Argentina under an assumed name. It's the only way to escape from people with regex problems
I wonder what's worse, help seekers who say "my regex doesn't work, your engine must be broken", or ones who say "my regex doesn't work, it's probably a simple mistake on my part but I like to get my troubleshooting from the most authoritative source I can find"
 
probably the people with "my regex doesn't work. I'm trying to parse HTML"
@AndrasDeak indeed. it's one of the examples I find quite appropriate for an stdlib, though
Random question of the day: Why is the syntax for generator expressions expression comp_for when for comprehensions it is assignment_expression comp_for?
note that (a:=b for b in range(12)) is valid
 
3:26 PM
My guess is "they forgot to update it"
The syntax described in most of the reference is something of a polite fiction in any case. docs.python.org/3/reference/grammar.html is where the sausage actually gets made. If I'm reading this right, both generator expressions and comprehensions use namedexpr_test, which is allowed to start with an assignment expression
 
hm, that one also has the weird quirk where an asspression seems not to be defined recursively.
So (a:=(b:=0)) would not be valid.
 
I think the parens let you hit atom and loop back up to the top. I'd expect (a := b := c) to fail, though.
 
good point. Didn't catch that.
 
that's responsible parenhood
 
4:17 PM
Good day guys, I do have a small task just wanted to consult, if I do have a large XML file (treasury.gov/ofac/downloads/sdn.xml) I do need to save it in database, then I do need to track from time to time what has change it and update database. How should I store this XML ? Should I use RDS for it? How do I track all the changes? Do I do it by comparing XML(so then I would need to save previous versions)?
 
5:03 PM
Low effort, high CPU approach: every time you download the XML, drop the entire database and recreate it from scratch
 
Yeah, i thought about it, but what if I need to find changes for XML file between 2 versions.
 
I'd probably keep a copy of the previous version in that case.
I notice there is an xmldiff module on pypi that might come in handy there
A database might not be necessary at all, if you merely want to know what changes between versions
 
5:25 PM
Thanks, Kevin, will definitely look at this.
 
if the XML files are formatted consistently then even stdlib difflib might help a bit
but I agree that a dedicated XML thingie is certainly better, if reliable
 
generate some kind of checksum from the xml file and store it along with the xml in the db. generate the checksum if you download it as well, only update the db version if the checksum is different. you don't even need to parse the xml for that
 
It might also be worthwhile to check the response headers of the http request you're using to get the xml
Ideally the server will keep accurate track of the last time the file changed, and tell you via the Last-Modified header
 
every single time that I wanted to check the modification date of an element on a webpage it was "right when you asked for it"
but perhaps APIs with XML-laden responses are different than random webpages :)
 
Yeah that "ideally" is doing a lot of work there ( ͡° ͜ʖ ͡°)
 
5:34 PM
worst-case scenario: the XML is assembled on demand
 
Based on no evidence, I usually expect high-profile .gov sites to adhere more closely to best practices than your average site
 
they'll do whatever they can, given their windows XP server farm
 
Oh, thanks again, will definitely look at that!
 
"Go ahead, turn on Strict mode in IE 7, we can take it B-)"
Acid1 compliant, baybee
Wait, that joke doesn't make sense because Acid1 is an outdated test of web browsers, not web sites. Or is it even funnier that the speaker cluelessly thinks their page passes a test that doesn't even apply?
This page is 100% GMO free
 
user13415013
5:57 PM
Hi guys
 
user13415013
I have specific question problem that is,
 
user13415013
I have a tuples (a,b,c,d) given as argument in function, without knowing how many tuple are in there , how can it can be automatically get their things in separate required variables
 
Why do you need to separate them? If you want to refer to the second tuple, just do the_tuples[1], no need to name it "b"
 
user13415013
I am working in problem like activations=None, family='vgg19' now i cant know what user is giving activation func like (F.relu,F.selu). So i need to use in the for loop which i cant use other methods like indexing
 
Over a span of how many years did u guys rank up to above 10K
 
6:11 PM
@nerd that's not very clear, but I suspect an XY problem
you should specify an API that users adhere to, and the specification should be unambiguous
 
user13415013
It might be xy problem, i have to get it
 
@CoolCloud About 15 months. FWIW, one new member hit 10k in 8 weeks, although they're currently serving their 2nd suspension for alleged voting irregularities...
@CodyGray Good point. I keep forgetting about the 10k tools. I really ought to make an effort to use them more...
 
6:27 PM
they aren't very usable, alas
 
That's why I never paid much attention to them.
 
6:42 PM
@PM2Ring god in no way im trying to cheat, just trying to get upto 10k, completed 3 months. 1 yr to goo
 
@CoolCloud Sorry, I wasn't suggesting that you wanted to cheat!
 
Hello
 
user13415013
i've got the problem what i was asking
 
user13415013
problem is too long
 
6:59 PM
Can I put a selenium web driver question which I am having trouble with!
 
@ruchiyadav you already have I think
13 hours ago, by ruchi yadav
Hello everyone. Greetings! Please help me with drag and drop a search list value to any random place of the page using selenium web driver. Let me share the link for elaborating the problem https://stackoverflow.com/questions/63313099/drag-and-drop-a-value-of-a-list-to-random-area-of-the-page-is-not-working
the people active here might be different than those 13 hours ago, so you might get a response this time
I did look at your question when you linked it, but I know nothing about web things
 
user13415013
I have this variable 'vgg16':[64,64,'M',128,128,'M',256,256,256,'M',512,512,512,'M',512,512,512,'M'], , now i have some this given length of activation (act1, act2,act3 .....) , now i want to apply it in loop..,
 
@nerd yeah, that's not going to help. Please try to put together a few lines of code that demonstrates your problem clearly. You can put the code in pastebin or similar, and post the link here
 
Ohh , I see more active people this time so thought to get attention towards it. No issues. Will keep seeking helping hand
 
hand-waving descriptions of your problem will not help us understand it
 
user13415013
7:03 PM
This is loop:
for layer in layers:
    if isinstance(layer, int):
        conv2d = nn.Conv2d(v, layer, kernel_size=3, padding=1)
        if batchnorm:
            layers+= [conv2d, act(nn.BatchNorm2d(v), inplace=True)]
        else:
            layers += [act(conv2d, inplace=True)]
 
@ruchiyadav yeah, it's fine. I just spared you asking it again :)
 
user13415013
now what i am going to do is put those activation lists in those layers, but with each at a time
 
user13415013
but my brain cant comprehend complexity to do this.
 
user13415013
like for example
(act1,act2,act3) should only be applied layers by layers as in layers+= [conv2d, act(nn.BatchNorm2d(v), inplace=True)]
 
Is len(layers) == 3?
if so, you can do something like this:
acts = (act1, act2, act3)
for act, layer in zip(acts, layers):
 
user13415013
7:08 PM
yes, zip
 
user13415013
act1,act...) should be only apply to layers not 'M' , how can i solve it
 
user13415013
oh but i can solve it.
 
How does the code relate to the list and tuple shown earlier?
 
user13415013
Thanks @Code-Apprentice , @AndrasDeak, see you later
 
user13415013
oh, list and tuple cant be zipped
 
user13415013
7:13 PM
It can zipped
 
user13415013
but serious problem was It doesnt work on different sizes of two variables.
 
user13415013
oh i found iter() might work
 
Ugh
Things being fixed by applying iter() is unlikely.
But since it’s still totally unclear to me what input is supposed to be transformed to what output...
 
user13415013
It might work,
 
user13415013
because those acts=(act1,act2...) are only applied to conv layers, and as in my for loop it is iterating whenever it finds int and apply iter, and again use next for next .
 
7:23 PM
Okay.
 
user13415013
Thanks, good night guys. Hope you'r doing great.
 
9:08 PM
I'm not sure if I'm crazy or just doing it wrong...
from unittest import mock
import os

class Blarp:
    def fnord(self, a, b, c):
        print(42)

b = Blarp()

with mock.patch.object(b, "fnord"):
    b.fnord(1,2,2,2,2,2,2,2,2,2)


with mock.patch.object(os, "listdir", autospec=True):
    os.listdir('hello', this='is', supposed='to fail')
when I autospec on fnord, it fails correctly. But os.listdir doesn't fail
it doesn't seem to matter how I mock - just patching, patching the object... every single autospec seems to just shrug at me and go, "meh, looks good enough"
 
Man, changing other's people's neural networks is such a unfortunate and time consuming procedure in Pytorch. For example, I'm trying to use a bolt an EfficientNet onto a UNet but hooking the outputs from the layers requires addressing the internal layers of a per-trained model, which requires disassembling the pretrained model and calling everything step, by, step.
I'm almost thinking that a graphical version of this like VHDL or Labview would be faster to use...
 
9:26 PM
Anyone know how to optimize this function (i.e. avoiding the for loop) that forces a (possibly ragged, nested) list into a numpy array?
def to_array(a, shape):
    a = np.array(a, dtype=object)
    b = np.empty(shape)
    for index in np.ndindex(a.shape):
        b[index] = a[index]
    return b
 
9:47 PM
Aug 6 at 23:39, by Andras Deak
numpy and ragged arrays don't match
which is to say there's a high chance that you have to use a loop
 
10:32 PM
@PM2Ring The posts with pending delete votes is pretty much the only thing useful in the 10k tools.
There are a couple of things in there that mods might use, like recently created tags. But the rest of the list items just don't scale to a site the size of SO.
 

« first day (3587 days earlier)      last day (1344 days later) »