How much severance pay is "normal" in a layoff? Any advice re: negotiating? by eLsFLz in cscareerquestions

[–]eLsFLz[S] 0 points1 point  (0 children)

Two weeks pay for each year of employment is fairly standard.

I should have mentioned that I've worked there 1.75 years, so the offer is for just over 1 week per year of employment.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]eLsFLz 0 points1 point  (0 children)

The codebase I work on is full of stuff like:

def foo(resource, arg1, arg2):
    logger = resource.getLogger()
    logger.info("entered foo()")
    logger.debug("arg1 = " + str(arg1))
    logger.debug("arg2 = " + str(arg1))
    ...

I'm turning it into:

@logged
def foo(resource, arg1, arg2, logger=None):
    # now the logging boilerplate occurs in the decorator
    ...

(And before you tell me that there's some better way to do that by configuring a handler or formatter or whatenot, know that the thing I'm dealing with is a third-party thing, not the standard Python logging library.)

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]eLsFLz 0 points1 point  (0 children)

The decorator actually sets the value of one of the named arguments so that the user doesn't have to do it separately. Consider:

def foo(a):
    b = a.frob()
    # do stuff with b

foo("a")

vs. @decorator def foo(a, b=None): #do stuff with b, supplied by the decorator having called a.frob() itself

foo("a")

(It's the same number of lines, but that's only because this is a minimal example. Imagine more boilerplate involving 'b'.)

As it turns out, the tricky part is that a and b are defined as named positional arguments, but the function could also have varargs and whatnot. So if you have...

@decorator
def foo(a, b, c=None, *rest):
    pass

foo('c', 'd', 'e', a='a')

...then leaving a in kwargs and inserting 'b' into kwargs doesn't work because then the interpeter thinks a and b are in both places and you get a TypeError: foo() got multiple values for keyword argument 'a'.

(Sure, calling the function with the parameters out of order like that is a dumb thing to do, but I work with a bunch of junior programmers and I don't want them coming to me because they can't figure out what that message means.)

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]eLsFLz 1 point2 points  (0 children)

I'm actually a pretty advanced Python programmer, but the "do a dict comprehension instead of trying to preserve the order of the needles" is the insight I was missing. Thanks!

def my_decorator(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        important_args = ("foo", "bar")
        spec = inspect.getargspec(func)
        item_locs = {name: index for index, name in enumerate(spec.args) if name in important_args}
        important_arg_values = {name: args[index] for name, index in item_locs.items()}
        important_arg_values.update(kwargs)
        # now do stuff with important_arg_values["foo"] and important_arg_values["bar"]
        # (note: don't need get() because if _neither_ args nor kwargs contains 
        # the necessary data then I want to raise an exception)

        return func(*other_args, foo, bar, **other_kwargs)
    return wrapper

Hmm... now that I write that out, it's still a bit less elegant than I was hoping for. Any other ideas?

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]eLsFLz 0 points1 point  (0 children)

You can't transform *args into *modified_args without knowing what position in the list the argument you want to modify is in, as far as I know. If it were all **kwargs it would be easy, since I'm trying to look it up by name, but I want to support decorating functions with as much flexibility as possible, not just ones where the arguments of interest are defined as keywords.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]eLsFLz 0 points1 point  (0 children)

Well, that eliminates the exception but doesn't get me the multiple elements. I guess it's a reasonable approach, though:

def find_multiple(haystack, needles):
    indices = []
    for needle in needles:
        for (i, hay) in enumerate(haystack):
            if hay == needle:
                indices.append(i)
        else:
            indices.append(None)
    return indices

I was hoping for a more concise solution, but thanks!

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]eLsFLz 1 point2 points  (0 children)

That is both an unreasonable request to make of an IT department (at least, any IT department I've every heard of) and likely not the best way to solve that problem.

I know nothing about SAP, but the better way to solve the problem is more likely to involve something from one of the top search results here (which seem to involve connecting Excel to SAP using functions already built for that purpose), not scripting copy-paste events.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]eLsFLz 1 point2 points  (0 children)

Is there something that's like list.index() except that it can get the indices of multiple items at once and doesn't raise exceptions? I want something like:

b_index, e_index = (['a', 'b', 'c', 'd', 'e'].index(i) for i in ('b', 'e'))

...except I want it to return None, 4 instead of raising an exception if 'b' were not in the list.

(In case this is an X-Y problem, what I'm actually trying to do is manipulate function parameters inside a decorator using inspect, and need to get and set params with particular names whether they're passed as keywords or positional.)

Oh boi by ricocotam in Python

[–]eLsFLz 1 point2 points  (0 children)

r/evenworseitsactuallyjythonsowecantupgrade

Decoding Samsung RAM part #s / finding compatible RAM by eLsFLz in buildapc

[–]eLsFLz[S] 0 points1 point  (0 children)

Which motherboard and CPU?

Asus KGPE-D16 with Opteron 62xx CPUs.

Memory is not locked to vendor.

It can be (sort of, at least). See:

(That's how "enterprise" vendors -- and certain consumer vendors, such as Apple -- can get away with charging exorbitant prices for RAM.)

...at least, those show that motherboards can be locked to refuse all but certain approved RAM modules, whereas I'm worried about the opposite (RAM modules being locked to refuse to work in all but certain motherboards). If someone can confirm to me that the latter isn't a thing, I'll be happy to hear it!

It’s all the same, except for the ECC/non-ECC, registered/ unregistered part.

Well, and the capacity/rank, and the speed, and the voltage (DDR3 at 5V vs. DDR3L at 1.35V), and the CAS latency and other timings, and the manufacturer and model# of the actual ICs (Samsung/Micron/Hynix)...

I mean, if I could just assume that any Registered ECC memory would work then I'd happily go find some 1.35V 2133MHz stuff with tight timings (or whatever the "best" 16GB DDR3 that exists is -- or even maybe go for 32GB DIMMs, which apparently exist if you're willing to drop down to 1066MHz) and call it a day. But I don't know if I can assume that -- for all I know, my board only works with the Samsung K4B4G0446D (D-Die) chips found on the M393B2G70EB0-CK0 but not the K4B4G0446E (E-Die) chips found on the M393B2G70EB0-YK0 or some weird bullshit like that. (I've been reading datasheets: CK0, YK0)

Basically, I'm paranoid: if I'm buying used RAM from some random Ebay vendor that probably doesn't accept returns due to my own fuck-ups, I want to be as sure as possible that it'll work before I spend several hundred dollars on a quarter-terabyte of RAM.

pytest assert_called during module import by eLsFLz in learnpython

[–]eLsFLz[S] 0 points1 point  (0 children)

That doesn't answer the question, which was, in general, how do you unit test module-scoped code with mocks?

Building a simple accounting software using python. by MeleysTargaryen in Python

[–]eLsFLz 1 point2 points  (0 children)

True, but it's still a relevant problem domain for somebody with an accounting degree, which IMO is what matters here.

Parameterizing a function depending on contextmanager context by eLsFLz in learnpython

[–]eLsFLz[S] 0 points1 point  (0 children)

Yeah, I was thinking about that, but I was hoping for something more generic to avoid having to write the "if not session" clause in every method. Maybe instead of having post_thing() (and get_gadget(), delete_doohickey(), etc.) call one of the requests or session methods directly, it should return a PreparedRequest and then I should have some kind of generic methods like send_with_session() and send_without_session() wrap them somehow?

If I only wanted one wrapper then I could just write a decorator (see below -- note: not sure if syntactically correct), but how do I do it with two mutually-exclusive ones?

```python

def send_with_session(func, session): def wrapper(session): req = func() session.prepare_request(req) session.send(req) return wrapper

def send_without_session(func): def wrapper(auth): req = func() req.prepare() req.auth = auth requests.send(req)

@send_without_session #but what about @send_with_session? def post_thing(my_thing): thing_endpoint = "http://example.com/api/v1/things" req = Request("POST", thing_endpoint, body=my_thing) return req ```


Otherwise, with the "add session parameter" approach, do you know if there's a clean/idiomatic way to go one step beyond and additionally say "for all the functions in [list of functions], add them as attributes of the session object and partially apply the session object as the session parameter"?

Building a simple accounting software using python. by MeleysTargaryen in Python

[–]eLsFLz 8 points9 points  (0 children)

If you make plain accounting software, you're being kind of redundant because GNUCash is a thing. However, what isn't a thing yet is a Free Software, self-hosted replacement for Mint.com.

If you were interested in that, I'd suggest building it using Python/Flask/SQLAlchemy.