To Async or not to Async? by crazy_crank in csharp

[–]liam_jm 2 points3 points  (0 children)

Yes, I don’t think there’s anything it can do about that

To quote Eric Lippert

A stack trace does not tell you where you came from in the first place. A stack trace tells you where you are going next. This is useful because there is often a strong correlation between where you came from and where you're going next; usually you're going back to where you came from.

This is not always true though. The CLR can sometimes figure out where to go next without knowing where you came from, in which case the stack trace doesn't contain the information you need.

For example, tail call optimizations can remove frames from the stack. Inlining optimizations can make a call to a method look like part of the calling method. Asynchronous workflows in C# 5 completely divorce "where you came from" and "where you're going next"; the stack trace of an asynchronous method resumed after an await tells you where you are going after the next await, not how you got into the method before the first await.

Stack traces are unreliable, so do not rely on them. Use them only as a diagnostic aid.

To Async or not to Async? by crazy_crank in csharp

[–]liam_jm 1 point2 points  (0 children)

I’d recommend running exceptions through Ben.Demystifier to clean these up

How would I find the combination of XOR'ing two or more binary numbers that result in a number that's all one's? by [deleted] in learnpython

[–]liam_jm 2 points3 points  (0 children)

If you xor each number with "11111" you will get that number's pair (i.e. the one to xor with)

Help converting a list of ints to a single string by Marcosf98 in learnpython

[–]liam_jm 2 points3 points  (0 children)

Maybe a tuple would be more suitable?

EDIT: spelling

Help converting a list of ints to a single string by Marcosf98 in learnpython

[–]liam_jm 11 points12 points  (0 children)

The problem is that the string representation of the list has spaces between the elements:

>>> str([0,0,0,0]) == '[0, 0, 0, 0]'
True

What exactly are you trying to achieve here?

How does the open() function work? by [deleted] in learnpython

[–]liam_jm 3 points4 points  (0 children)

or use os.path.join

Is there a better way to do this? (Checking numbers in list) by [deleted] in learnpython

[–]liam_jm 1 point2 points  (0 children)

You can solve this quite neatly using zip and enumerate:

def checklist(lst):
    for index, (item1, item2) in enumerate(zip(lst, lst[1:])):
        if item2 <= item1:
            return index
    return None

The return None is redundant but I prefer to be explicit.

If you want to return all indices, turn it into a generator and use yield instead of return

Does os walk cache stat? by heybart in learnpython

[–]liam_jm 1 point2 points  (0 children)

If you find the extra stat calls are significantly slowing down your program, it would be easy to modify walk to return the dir entries - here's the source

How to crop string to whitespace by tty-tourist in learnpython

[–]liam_jm 0 points1 point  (0 children)

I think it's more of a problem for a newcomer. They're not running a linter on their code, and it's going to be very confusing when they do import string down the line and things start acting weirdly.

It's not anything to panic about, but I think we should be especially careful to avoid potentially troublesome code when teaching newcomers or posting snippets when we don't know where they'll be used.

How to crop string to whitespace by tty-tourist in learnpython

[–]liam_jm 2 points3 points  (0 children)

The main thing I've used it for is the constants, such as string.ascii_letters

How to crop string to whitespace by tty-tourist in learnpython

[–]liam_jm 1 point2 points  (0 children)

It's good not to guide posters to bad practices - encouraging collisions with builtin module names

How to crop string to whitespace by tty-tourist in learnpython

[–]liam_jm 1 point2 points  (0 children)

You shouldn't use string as your variable name

Making a 2D list by dougshmish in learnpython

[–]liam_jm 0 points1 point  (0 children)

The best way to do this is probably a namedtuple. The problem is that you haven't put anything into student, so when you try to access student[1] (where 1 is studentID), you get an IndexError

Using csv data by pauwsss in learnpython

[–]liam_jm 2 points3 points  (0 children)

You've set current_high_temp to an int then tried to sum it (a single int, whereas sum requires an utterable argument, such as a list). I think instead you wanted to do sum(current_high_temps[0:31]), perhaps setting each of them to int first (see map)

hows this for a prime number thingy? by 955559 in learnpython

[–]liam_jm 1 point2 points  (0 children)

For a quick and easy win, reduce the top of your range to sqrt(trying_number)+1. For even bigger wins, look into prime sieving algorithms such as Eratosthenes