« first day (3458 days earlier)      last day (1482 days later) » 
00:00 - 12:0012:00 - 00:00

wim
12:21 AM
yeah line break (which is weird, I just copy pasted the title from the pdf)
 
 
1 hour later…
1:35 AM
yeah.. the op can see them
 
1:53 AM
@PM2Ring actually the question is duplicated. I've just typed a simple comment which hold a very short answer and then flagged it as duplicated. @AndrasDeak told me before to @αԋɱҽԃαмєяιcαη when that happens you don't write an answer. You vote to close as unclear, or a duplicate. and even said that i should stop posting answering to duplicate questions.
noted btw
 
2:06 AM
sometimes I think that people flag some questions as dups, when they have some important difference
 
 
2 hours later…
4:02 AM
=D .. my little fs driver can mount youtube playlists to the linux filesystem and I can browse and download with my file browser
I can mount any of the filesystems provided by the fs module
 
user10984358
4:54 AM
Nice work @Todd
 
user10984358
What is it written using? C?
 
all python and cffi
made a cffi interface to fuselib
for remote filesystems with poor bandwidth, I have a caching strategy so listing files doesn't bog each time I open another folder
used functools.lru_cache for that
 
6:00 AM
how to change the list length by a function in python in a "call by reference" way.
Like:
 
say what
 
a = [1, 2, 3]
changeLen(a, 5)
print(a)
[1, 2, 3, 0, 0]
I thought .append() would do the job, but I was wrong, tried list comprehension, deepcopy.
 
you want to extend it and fill with 0's?
 
Yes. :)
 
a.extend([0] * 8)
or a += [0] * n
 
6:07 AM
Oh, this is really wierd. .append() is also working.
 
a.append([0] * n) will append a list as an element
careful with [obj] * n... it will create a list of references to the same object
if you want to extend a list with unique references, it's better to do a comprehension: a.extend([Foo() for _ in range(n)])
 
6:31 AM
No module named 'numpy.testing.decorators'
numpy version numpy-1.18.2
 
6:56 AM
btw @AjayMishra, it's more efficient to do a.extend(0 for _ in range(n)) than a.extend([0 for _ in range(n)]). The former creates a generator that is iterated over once. The latter creates a list, then iterates over it.
 
@Todd Good point, but it is safe to do a.extend([0] * n). It's certainly not safe to do stuff like lst = [[[0]*3]*5], though.
 
but we should be careful with [obj] * n because it creates refs to the same obj.
 
Yeah, but so does lst = [0, 0, 0, 0], and that's not a problem.
 
right.. it's good to point it out though, because I know people learning python hit this conundrum
 
My last list contains 4 refs to the same zero int object.
 
7:07 AM
for instance, "what is going on with my list?! a = [[]] * 3; a[0].extend([1, 2, 3]) ==> [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
right.. refs to primatives aren't a problem
 
@Todd Well yeah, that's why I originally said that you made a good point. :) But it's good to know when list multiplication is safe, when it's dangerous, and why. And if you're ever unsure you can make a small example and test it to make sure you don't get unexpected behaviour.
 
always a good thign to do
 
FWIW, here's the canonical dupe target for this stuff: stackoverflow.com/q/240178/4014959
 
that's a good reference
something related to this that I think everyone eventually hits early on: def foo(a, b=1, c=[]):
trying to specify a list as the default value for a param
 
Yep. And I wouldn't mind a dollar for every time it's been used as a dupe target. :)
@Todd Sure. Let me find the canonical for that...
 
7:17 AM
you keep a bookmark folder for all of these?
hehe.. that one's funny.. dramatic design flaw
 
Mutable default args can be useful, if you know what you're doing. However, many people have been bitten badly by them in their early days of using Python. So they have a bad rep, and lots of Python coders avoid them, and may even consider them a flaw in the language.
 
@Todd Not exactly. I just know the right keywords to Google them with. :) But I'm pretty sure both of them are in the SO Python collection.
 
I haven't found a use for them yet myself
hi @HeavyLoadCollection
 
@Todd A mutable default list or dict can be used as a memoizing cache. It's faster than any other caching technique.
 
7:22 AM
ah okay.. i'll have to mull that one over
 
The SO Python common question collection: sopython.com/canon
 
i wonder if functools.lru_cache uses that technique
 
@Todd Give me a minute & I'll find some old timeit code of mine.
 
alright
i'm overjoyed.. i fixed a problem with my new filesystem driver.. now I can load youtube playlists in a second.. it was taking a horribly long time earlier
 
@Todd I don't think so. I have looked at the lru_cache source, but that was a while ago, and I'm hazy on the details. But I do remember it's not pretty. :) The LRU machinery is partly to blame for that, though. FWIW, Antti Haapala is not a big fan of lru_cache... but he's rather critical of a lot of the cide in the stdlib. ;)
 
7:29 AM
i'm not a big fan of decorators myself because it just introduces levels of indirection.. but they can make code simpler
 
Here's that timeit code, which runs on Py 2 & 3. stackoverflow.com/a/34036910/4014959
 
@Todd it doesn't. It uses a custom ring buffer + lookup implementation.
Pretty useless now that OrderedDict is fast.
 
yeah.. i see the code now
 
@Todd Oh, I use lru_cache myself sometimes. One nice thing it does is that you can get cache hit stats from it. Decorator syntax is cute & compact, but that extra Python function call can be a killer in time-critical loops. Python function calls are notoriously slow.
 
@PM2Ring I've stopped doing that completely these days. Automatically makes a function non-concurrent for practically no benefit.
I mostly don't consider mutable default argument a bad design decision anymore because to me there are exactly zero use-cases left where I'd mutate a default.
 
7:36 AM
@MisterMiyagi That's only a problem if you need concurrency. :) But sure, don't use mutable def args in situations where they will cause chaos.
 
like marriage
i'm going to have to learn how to package modules up after I migrate my latest hobby project to macos and windows
looks like wheels is the thing to use
 
@PM2Ring Yeah, I admit I might be doing a wee bit more concurrency than the average Pythonista. ;)
 
could always rlock it
make the mutable param use the context interface
 
The last time a mutable def arg bit me was when I was using code I found online for Knuth's Algorithm X, which solves Exact Cover problems. Knuth's implementation is commonly known as Dancing Links, which uses a 2D pointer structure. The Python code I found uses dicts. A list arg is used to accumulate solutions.
The code works properly if you pass in an empty list, but it can misbehave if you use the default arg list and then try to call it multiple times. I'd used that code several times before I even noticed that little bug...
Here's an example of that code, complete with the def arg list. It's safe because I pass an empty list in, but I better fix that. :) stackoverflow.com/a/42871384/4014959
 
7:57 AM
that's some cool stuff
 
@Todd I'll have to take a look at your filesystem stuff. It sounds intriguing.
@Todd Thanks!
 
i want to get it all packaged and on pypi soon
i'm having a blast browsing youtube playlists from my file browser =)
 
I guess packaging it will be a bit tricky, due to the cffi stuff. I know next to nothing about packaging in Python, but there are a few room regulars who seem to know a fair bit about it.
 
yeah.. the cffi stuff might be tricky
i have to build it for each supported platform
 
8:13 AM
Hi Folks,
I had a question about type annotations
 
@Todd RLock is not safe for concurrency now that we have both thread and async concurrency.
 
@MisterMiyagi retag please
 
That one bit me hard
 
If I had something like following

    def foo(x: int, y: str) -> None:
        pass

    def bar(*t) -> None:
        foo(*t)
 
retagged
 
8:15 AM
what do you mean @MisterMiyagi
 
@MisterMiyagi Hammered
 
What would be the type annotation of t in bar?
 
@Todd An RLock blocks the current thread of execution. If your concurrency is coroutine based, it will block the entire event loop. Including the other task holding the lock. That deadlocks all tasks.
 
@DeveshKumarSingh *t: int
 
8:17 AM
well.. that doesn't deprecate rlocks.. you have to know what you're doing
 
But I have a str argument as well @MisterMiyagi
 
@DeveshKumarSingh oh, missed that. That's *t: Union[int, str] then.
 
rlocks are still very useful, and threading isn't going to be deprecated by async
 
@Todd It means they're not a general "make concurrency safe" hammer anymore.
 
heh.. i never viewed them as a panacea anyway =)
 
8:18 AM
@Todd Not denying that, but code should not assume it is run by some specific form of concurrency.
 
@MisterMiyagi I tried the same, and then checked my annotations using mypy. It complaints with Argument 1 to "foo" has incompatible type "*Tuple[Union[int, str], ...]"; expected "int"
 
@αԋɱҽԃαмєяιcαη I don't use Beautiful Soup, but your dupe target doesn't look like a close match to me, so I didn't hammer it. And because you deleted the dupe comment it's not easy to see which dupe target you nominated.
 
you have to be careful with these thing and give careful consideration to how and when the locks will be hit by concurrent tasks
 
@DeveshKumarSingh Where does the Tuple come from?
 
I am trying my hands with mypy for a open source projects, it's not easy to understand some of the errors being thrown
 
8:19 AM
Ah, yes.
That's because *args isn't ordered.
 
@MisterMiyagi I am not sure, I just did def bar(*t: Union[int, str] ) -> None: foo(*t)
 
It will accept both :int, :str and :str, :int.
Nothing you can do about that. You have to assert or cast it.
 
how do I assert it?
 
give me a moment to check what mypy currently supports
 
Thanks a lot :)
 
8:25 AM
# option 1: unpack and assert
a, b = t
assert isinstance(a, int) and isinstance(b, str)
foo(a, b)
# option 2: cast
t = cast(Tuple[int, str], t)
foo(*t)
 
holy crud.. I just realized that CNN has some super long playlists.. the one I just tried to load is over 4K long
 
@MisterMiyagi Thanks @MisterMiyagi I didn't know we could do that via typing
 
kill -9 my poor driver =(
 
@Todd soon it's will be kill -*
 
heh
 
8:30 AM
Sorry @MisterMiyagi one more question, If I had **kwargs instead of args like so
def foo(x: int, y: str) -> None:
    pass

def bar(**kw) -> None:
    foo(**kw)
 
i've had to restart my system a couple times today already =)
 
How would I cast kw?
 
cast?
 
@Todd this is wrt to my earlier question, casting types
 
ah.. mypy is a type checker module.. interesting
 
8:35 AM
@DeveshKumarSingh Can you perhaps clarify why you'd want to do that? It might be easier to just # type: ignore that, since it isn't strongly typed anyways.
# option 3
foo(**t)  # type: ignore
 
I am actually trying to add some missing type annotations in pip's repo, that's an open issue there
The question about how to typecast *args and **kwargs was related to that, we have base and derived classes with such behavior
 
so mypy doesn't add runtime overhead during execution? It's just an analysis tool like lint?
 
And yes, # type: ignore, or even Any is an option as you pointed out, but I was wondering how would I cast **kwargs
 
Both cast and ignore tell Mypy "pretend this is so", so there isn't much point in making these too precise.
@Todd There is some minor overhead for re-ifying the types in the source code (e.g. Tuple[int, str] is an expression that gets evaluated) but type checking itself completely static.
Hm, a TypedDict may be appropriate
 
@MisterMiyagi True, but they atleast honor the order of expressions, so t = cast(Tuple[int, str], t) works and not t = cast(Tuple[str, int], t)
 
8:41 AM
so it only adds a little time for loading then?
 
@DeveshKumarSingh But they are completely made-up. Mypy doesn't know whether t is actually Tuple[int, str] or Tuple[str, int].
It's just an exercise in manually duplicating the signature. You don't gain type safety from that.
# option4: TypedDict
class FooKwargs(TypedDict):
    a: int
    b: str


def bar(**t: Union[int, str]):
    k = cast(FooKwargs, t)
    foo(**k)
 # option 5: recommended
 def bar(a: int, b: str):
     foo(a, b)
 
@MisterMiyagi I was thinking that on cast(Tuple[int, str], t), the tuple knows that first argument will be int and second will be str, and that's how the function foo is defined
 
cast is a noop at runtime.
cast(Tuple[int, str], t) won't even check if t is a tuple, much less the number and type of arguments.
If you can exactly define what *args and **kwargs are, you don't actually take *args and **kwargs.
 
check at runtime or check when you run mypy?
 
You take a: int, b: int but don't tell anyone.
 
8:48 AM
So is Any also a good option?
 
@DeveshKumarSingh neither. the runtime does nothing with it, Mypy says "oh, if you say so"
@DeveshKumarSingh Any is never a good option.
if you want to pass one type check point, use # type: ignore. If you want to pass all type check points, use Any, then ask yourself why you are using type checking in the first place.
 
@Todd Yes, it's an analysis tool like lint. It runs rather slowly, on my old machine.
 
So this worked @MisterMiyagi
from typing import Union, cast, Tuple
from mypy_extensions import TypedDict

FooKWargs = TypedDict('FooKWargs', {'x': int, 'y': str})

def foo(x: int, y: str) -> None:
    pass

def bar(**t: Union[int, str]):
    k = cast(FooKWargs, t)
    foo(**k)
 
argh...
 
I got the namedtuple like definition from pip's source code, they had an example
 
8:56 AM
Just... don't.
 
@MisterMiyagi Sorry I didn't get you
 
Please use option 5. For the benefit of everybody using pip, use option 5.
 
hehe, to give you more context, we have this base class, base_command.py, similar to foo
And I was trying to add mypy type annotations here: completion.py , similar to bar , hence the questions @MisterMiyagi
 
that might be pretty useful for group projects.. but I wouldn't want any runtime artifacts from it in the code
like casts
probably better to not use it strictly
 
@DeveshKumarSingh seriously, why? What's the purpose typing these like that? If you know that super(CompletionCommand, self).__init__ will always be Command.__init__, then you are not taking *args and **kwargs. If you don't know, then you cannot type it.
 
9:05 AM
So you are saying that Command.__init__ have fixed parameters already defined, so we should use them in super(CompletionCommand, self).__init__ directly, instead of trying to use *args and **kwargs and jumping hoops typecasting them?
 
yes.
see option 5.
 
Sorry I am new to annotations, so I was trying out different things, pardon my ignorance on such things
I will anyways not commit any code with option 1-4 before asking the maintainers :)
 
No worries. Just saying, knowing that you are new to this, always consider option 5 first.
@DeveshKumarSingh Don't rely too much on reviews here. There's only so much experience with typing in the community yet.
 
@MisterMiyagi Yes being explicit is always good. But does that mean that typecasting *args and **kwargs is a bad thing
@MisterMiyagi Yes, hence I will take other opinions as well
 
cast is a bad thing.
 
9:08 AM
Or I should say trying to assign type annotations to *args and **kwargs is a bad thing?
 
Using cast means you are dealing with unchecked/un-inferrable code. Always prefer making your code checked/inferrable over casting.
I know it's painful at times. Kudos for taking on this task.
 
Haha, I am aiming to improve my open source footprint this year, starting with python
pip has a good community of folks to help out, so I started there
 
@DeveshKumarSingh The problem here is that the function doesn't actually take *args/**kwargs. The arguments are not variadic (as in "I take any number of args") they are merely unknown (as in "I take some number of args").
 
So by fixing the number of args in the base function, you are incorrectly using args and kwargs
 
Exactly.
 
9:14 AM
So it's not a good coding practice
 
In untyped code, nothing is wrong with that. But typed code necessarily defines the signature, so one should define the signature at the proper place.
I'd hope that the typing craze will eventually lead to some "inherited attributes" pattern, but don't count on it anytime soon.
 
lol, I had another question, acc to the function output for difflib.get_close_matches
The return type is a list of strings, so it's type should be List[str], but when I do reveal_type on it
The output shows builtins.list[typing.Sequence[_T-1]]'` as the return type
So is the return type a list of sequences?
So the string is considered as a Sequence.
 
note that strings are sequences of strings
does difflib take both str and bytes?
 
The document says word is a sequence for which close matches are desired (typically a string)
So it should take bytes as well
 
9:29 AM
then it's basically Sequence[T] in (e.g. strings aka sequence of strings) and List[Squence[T]] out (e.g. list of strings aka list of sequences of strings)
 
Got it thanks :)
 
regex how to match till the end }
 
what do you think RE would mean after I run tests on my code?
 
do you have any context to that question? like, what kind of tests? a unit test framework such as unittest or pytest?
 
9:46 AM
i think its runtime error
im on google code jam
but code works in my ide
but not on their system
 
so another coding challenge?
 
@MisterMiyagi what else
 
i like competitive programming
 
Now it's google, so instead of leetcode it's extra haxor leet code
 
@AndrasDeak Sun is shining, birds are singing, my cats are watching their lunch. Got carried away by optimism.
 
9:50 AM
In a few more weeks Permian will be a renowned expert in asking for help with code challenge problems
 
The thing I don't get is why these challenge sites are so hell bent on hiding debug information.
What's the point in shortening a nice traceback to RE?
That's a type of train where I come from, not an error report.
 
What's the point in forcing you to use terrible style? Incompetence.
Then we'll have all these leet people spewing yam code happily
Hopefully interviewers don't start expecting class Solution
 
I felt rather embarrassed by association when in an interview for a Python/Java job, the interviewer hesitated to ask about public/private because my CV was basically just Python.
So don't joke about these things unless you are absolutely certain us savages don't get associated with that. :P
Wait, you were joking, right?
prepares for emergency hug
 
Well, all this time, Room 6 has been unwitting participants in perhaps hundreds of coding challenges
Something for the CV...
 
its ok
 
10:03 AM
@Permian Look, I don't think people have a problem with still helping out on coding challenges every now and then. But please consider how your requests look to others. We have absolutely no idea what you are doing, what your code is doing, what your tests are doing. If you don't know what RE stands for, how should we?
 
@MisterMiyagi ok ok
i just really enjoy these problems
 
And that's not a bad thing. But if you want us to help you, then help us help you. That itself is a great skill that is worth learning and will benefit you a lot.
 
what's yam code
 
@Todd It happens to be word of the day in salad
 
okay.. hold on
ah
 
10:14 AM
:)
 
@MisterMiyagi and there seems to be no progress along the debugging learning curve. That's my real issue with @Permian's problems.
 
@MisterMiyagi ok
@AndrasDeak ok
 
i can't stand developers who don't know how to use a debugger
i've had to work with oldtimers who look down their noses at debuggers and say stupid stuff like, print statements and logs are all they need
 
<collects his prints and backs away slowly>
5
 
@Todd if they can debug it's alright
What matters is being able to effectively debug.
 
10:26 AM
imo anyone who thinks they can debug effectively with just print and logs is seriously gimpped
 
@Todd OK
 
it's incompetence to not know the tools of the profession if you do it professionally
 
Obvs
 
like this old guy I worked with was almost 70 and been developing for almost 50 years.. he didn't even know how to use gdb.. and his code was utter crap
 
@Todd perhaps your brain is making illogical causational links?
 
10:30 AM
it's like working construction with power tools all around with a guy who insists on using a hand saw to cut every piece of wood
 
Kevin'd. You're running the risk of taking the competency of individuals and tying it to particular tools that they use, or not, as the case may be
 
I'm OK with you being wrong though. Breakfast is more pressing.
 
i'm basing my evaluation on the guy on his general lack of understanding the technology that he's been working with for years. and part of that lack is due to his reluctance to learn simple things like how to set breakpoints with an IDE and understand how the stack view works to trace the path of execution..
the unfortunate thing is, he lacked the framework to understand how limited his skills were.. dunning kruger effect
but he'd been working for the company for years and just squeaked by with consistent but slow work
 
I was going to say that the next logical step is "you can't write good code without an IDE" and then "you can only write good code in <your pet OS>" :)
 
there's dozens of IDE's .. heh.. he could write his code with notepad++ for all I care.. just as long as he knew how to debug
 
10:35 AM
bit arbitrary
 
it's arbitrary expecting other developers to know how to debug?
 
8 mins ago, by Todd
it's incompetence to not know the tools of the profession if you do it professionally
Surely that ^ includes IDEs too
 
yeah.. one should know how to use IDEs
 
@Todd ah, hold on. "Know how to debug" and "use a debugger" are different things. Nobody has said people shouldn't know how to debug
 
@Todd I never said that. There's a not-so-subtle difference between "debug" and "use a debugger"
What he said
 
10:36 AM
it's better to know how to use them, and have a range of IDE's you're familiar with
but i'm not religious about one particular one
nor one particular OS
a developer should be comfortable on several
 
@Todd so it's just debuggerianism?
@Todd ah, interesting
 
heh
 
Fortunately breakfast is done
 
it really needs to be said. if you think that it's okay not to know how to use the features of debuggers is okay and print statements and log files are all you need.. you're part of the problem
if you develop professionally, it's jsut not okay
 
Noted
 
10:39 AM
ERROR: opencv-python 4.2.0.32 has requirement numpy>=1.17.3, but you'll have numpy 1.16.4
which is incompatible.
running on my local but error on server
 
@Mannya update numpy?
 
i can't update numpy
i need 1.16.4 numpy , problem is running on local but not on server
 
What is the conflict if you update numpy?
 
numpy decorators method
 
Sorry? I'm not sure what you're referring to
 
10:44 AM
4 hours ago, by Mannya
No module named 'numpy.testing.decorators'
numpy version numpy-1.18.2
Never heard of it
Do you really need it?
 
It appears to still be part of 1.17 and the requirement is only for 1.17 in the error, not 1.18
 
@Todd I practically don't. Have to consult the manual every single time. It's all static verification and automatic testing for me.
 
I will pray for you
 
Actually I am using lexnlp
 
11:01 AM
@Mannya Ok, so what does that change? You're not making it easy to help you; both Andras and I found sources showing that you could upgrade numpy to 1.17 and still have decorators
 
seemed to have been renamed to dec by 1.19 numpy.org/devdocs/reference/routines.testing.html
 
I am unable to install lexnlp in python 3.8
 
hmm...
 
I Can't figure out any solution for that
how to install lexnlp in python 3.8
 
Bit of whack-a-mole for a Saturday morning (and, oh dear, I just had to check the calendar :/)
 
11:08 AM
please help me
 
@Todd You do that. I don't feel comfortable being to familiar with tools that mean I messed up.
 
@MisterMiyagi heh, that's also a weird notion
 
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='codeload.github.com', port=443): Read timed out.
 
@Mannya if you ask that question one more time I'll kick you
@Mannya Going forward: there's no point in repeating the same question only a few minutes later. The same people will see the question, it won't affect your chances in any positive way. It only makes you come across as needy. And you wouldn't want that. Please be considerate to those who spend their free time on a weekend helping people. When and how they feel like it.
 
I have taught many other developers how to use debuggers, and one was so happy that she proclaimed it had changed her life and she was finally able to conceive children with her husband because of her reduced stress at work, and she went so far because of this to name her first child after me.. and the second one too.. even though they were girls.. and my friends, that is how important debuggers are
true story
 
11:14 AM
Sounds like a good conclusion to the debugger story arc. Nudge nudge wink wink.
 
rides off into the sunset
 
do i really need to use r while compiling a string directly without meta-chars?, without it, i still getting the same output. I know it's necessary to use it while passing meta chars and that actually covered how meta-chars interpreted within python process.
 
you talking about regular expressions?
 
it doesn't hurt to do it out of habit.
 
whenever I sit down to work out a regular expression 'r' is the first thing I always type
 
11:20 AM
@Todd I just want to confirm if it's have no meaning while searching for string directly?
import re

test = "testah"
pattern = re.compile("ah")
print(pattern.search(test))
 
i don't think it has any meaning if you have no backslashes
 
No, you don't need to use a raw string for a regex that doesn't contain any backslashes. But it won't hurt, and developing the habit of always using raw strings for regexes means that you won't forget to use a raw string when you do need it.
 
@αԋɱҽԃαмєяιcαη Wht even bother using regex for that? The plain str method will probably be faster.
 
@MisterMiyagi boo!
 
11:22 AM
is that cheating?
 
that's true
 
I'd love it if at least the docs stuck to "raw string literal". Calling them "raw strings" leads to the usual question of "how can I turn my string into a raw string?"
once the string is created it's just a cigar string
 
how do you uncook a string
 
@PM2Ring I just giving example to understand if it's doing something while searching string directly. just was passing through a youtube video while the guy saying it's must
 
The only downside is when you're doing regex stuff in another language, and you realise just how handy Python's raw string literals are. ;)
 
@AndrasDeak I keep any knowledge about such confusion locked away in my head, behind a 12 inch imaginary impenetrable wall of doom. The alternative is crying myself to sleep every night.
Or making a PR to the CPython docs.
Do they accept trivial doc PRs?
 
they probably do
 
you still have to sign the CLA though the first time
you might have already done that
@Permian if it's a list don't call it array
 
given an array of numbers, insert brackets so that if the number is 2 it has two brackets to the left of it and two to the right
my code idea is right but outputs a mess
 
11:26 AM
@Permian that's unfortunate
 
@AndrasDeak Since I mostly work with Python versions that other people only find behind their fridge, I haven't felt up-to-date enough to feel like contributing.
 
whats the best way to loop through a list whilst inserting into it?
because i think you mess up the order as you insert and iterate over the list
 
@Permian yeah, the best solution is not to do that
you could iterate over a copy of the list for instance, or build a new list from scratch
 
Here's an actual example from a few years ago:
Jun 9 '16 at 11:35, by PM 2Ring
import re
pat = re.compile(r'\\\\(\d+),(\d+)')
data = r"bla bla bla\\123,456hey hey hey\\789,987bye bye"
a = pat.findall(data)
print(a)
#output
[('123', '456'), ('789', '987')]
 
you shouldn't modify a list while you're iterating over it
 
11:28 AM
Jun 9 '16 at 11:39, by PM 2Ring
Note that if we don't use a raw string for the regex we need 8 backslashes in a row: '\\\\\\\\(\d+),(\d+)' That's hard to read and too easy to mess up.
 
you can create a loop, and within that loop modify another list
 
i cant think of another way
@Todd ive learnt this now haha
 
And actually those \d should have double backslashes in the un-raw version.
 
the backslash-backslash escapes in raw strings is strange
 
11:30 AM
@PM2Ring those would probably "work" and raise a warning in modern python
 
@AndrasDeak Yep.
@Todd And even raw strings won't help if you find yourself in the unfortunate situation of needing an odd number of backslashes at the end of a string literal.
 
it's confusing
 
that's new for me too
 
I tend to use implicit string literal concatenation in that case: r"some [funny] \d regex" "\\" That makes it obvious in the code that something weird is going on. :)
@Todd The raw string docs try to explain it, but IMHO it's one of those things you just need to experiment with until it sinks in. ;)
 
the majority of raw strings don't involve escaped backslashes thankfully
 
11:43 AM
I've seen a link before by @AndrasDeak where it's searching the room when said by from/to . i couldn't find it. i only see that
 
there's no to, just from
 
ah ok. my bad memory then :P
 
00:00 - 12:0012:00 - 00:00

« first day (3458 days earlier)      last day (1482 days later) »