« first day (3751 days earlier)      last day (1181 days later) » 

12:30 AM
hi everyone (again because I joined this room a few days ago) and I need help with this thing: stackoverflow.com/questions/65836344/… Making a pygame and sounds are weird
 
yeah, I know this isn't a perl chat
 
12:43 AM
@J.L.Louis so don't ask
 
cabbage
 
 
3 hours later…
4:10 AM
Cbg guys, I kinda stumbled upon a problem. I was creating a folder based on song album name(with python) but the name contains ':' and hence windows cant name a folder with ':' in it. So i was making a list of invalid characters but then found out that I cant include '\' in it, as \' gets flagged as an escape character. Anyway to overcome this?
 
@CoolCloud "\\" would work
 
It means same as a single backslash?
@python_user Yep sure it does.
 
yeah, it is called escaping a sequence, like "\n"
 
Thanks mate
 
no mention, I have been there
 
4:42 AM
Yet another barrier. Is it possible to remove all mentioned items from a list? Like using list.remove(x) only removes the first instance right?
The loop doesnt loop through the duplicate entries
invalid_char = ['/','\\','.',':','*','?','""','<','>','|']
def checker(name):
x = list(name)
for item in invalid_char:
if item in name:
x.remove(item)
print(x)

print(checker('////123')) #expected '123'
Is it because item is just present once? I think looping should be avoiding and I should choose recursion?
The indentation is just messed, ugh, sorry, check this:
def checker(name):
    x = list(name)
    for item in invalid_char:
        if item in name:
            x.remove(item)
            print(x)

    return ''.join(x)

print(checker('////123')) # expected '123'
 
a quick solution would be name = name.replace(item, '') instead of x.remove
there might be faster / better options
yeah this should do return ''.join(x for x in name if x not in invalid_char) make invalid_character as set instead of list and its the best I can think of
 
Hmmmm both works, dunno which I should choose :p
 
the second one is faster, and doesnt create new strings for every iteration
 
Okay, that it is, thanks again :p
 
5:51 AM
is there a reason globals and locals are functions? calling then gives a dict so why have functions that take no args? cant they just be globals and locals?
 
 
3 hours later…
8:48 AM
@python_user locals produces a different dict depending on where you call it, and often has to create an entirely new one. As for globals, there's consistency and I guess the PyPy people are pretty happy that the language does not dictate how modules work.
Plus, these really are not important enough to warrant keywords.
 
your locals explanation makes sense to me, I didnt think of that
 
9:28 AM
@AndrasDeak but monads!
 
10:22 AM
And a good morning re-cabbage to all.
@MisterMiyagi And globals are only global to the module whose namespace they inhabit. The closest thing to a true global namespace is __builtins__, but those who tweak that risk awakening dragons.
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>> __builtins__ = None
>>> dir()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable
 
10:51 AM
Cbg fellas
 
@holdenweb sometimes makes me wonder if global isn't a misnomer in Python.
 
11:55 AM
Semantics. Module-global would be more accurate.
 
HME
12:06 PM
Anyone that help me on my way with regards to reactive programming? Specifically handling streams from websockets?
 
12:36 PM
@HME asking too broad, narrow it down
 
12:58 PM
@HME might want to check out autobahn... crossbar.io/autobahn
and cbg all :)
 
cbg :)
@JonClements ooh, that looks nice...
 
@MisterMiyagi barely have to use it for the work I do... but when I have I've found it quite nice indeed :)
 
1:16 PM
we have way too much homegrown stuff at work, so it's always good to see proper standards. Even if the push takes a while...
 
I wonder: is it a terrible idea to think about creating a self-activating-virtual-environment python package?
 
I'm not sure what that is supposed to be, TBH
 
I'm creating a (backup util) cronjob for synology. And I like to keep the shell commands to a minimum - ideally just calling the python script.
However that would mean the python script is called with the host OS python version/libraries - instead of using the virtual environment.
 
are you aware that you can just use the venv's python executable and it will automatically use the venv?
 
Is that exactly the same?
then i coudl indeed just do that lol
 
1:30 PM
it's not 100% the same, e.g. it won't see the PATH changed and such. But it will use all libraries as per the venv; a well-behaved Python program should see no difference.
 
Important to realise the differences for debugging later.
 
Directly calling the executable will not set the environment variables PATH, PYTHONHOME, PS1, and will not create the deactivate function
 
user13727121
1:59 PM
I have a question regarding the len() function in Python. Say that I have three elements in a list, list_1 = [11, 12, 13], and I want to loop over the elements using while loop and have them printed in three separate lines. Would it be better to give literal value like while i < 3: or should I use while i < len(list_1):
 
user13727121
Is the latter more appropriate to use if I have like hundreds or thousands of elements in a list?
 
is there any reason why you want to use a while loop in the first place? that one seem inappropriate already.
You should just do for element in list_1: print(element) – iteration via index is very rarely needed.
 
2:20 PM
That's the answer to X. As for Y: don't use magic numbers. Use the length of the list. If it's fixed, you can check it once before the loop.
 
user13727121
@MisterMiyagi no, not really, it's just for a practice to use index and while loop, I came across this example and was wondering if I should be using len() rather than giving the literal value in a list that has more elements than the one I specified.
 
OK, I don't understand the question after all
 
I wholeheartedly recommend using len. Do not hardcode things unless that is your explicit intention.
If you want to learn "how nice things work", building your own listiter as a generator (or class!) wrapping around while can be rather educational.
 
user13727121
2:36 PM
@MisterMiyagi Understood. I always try to avoid overcomplicating things but sometimes I found myself analyzing a piece of code with no understanding of its functionality, I do that hoping I might pickup something new.
 
user13727121
@MisterMiyagi Might have to look that up. I think I might stick around loop lesson longer than the other lessons. It's...it confuses me a lot, frustrating even, sometimes, to understand how things work, especially when it combines with some other codes inside a loop. Also, thank you.
 
2:53 PM
is it possible to pass both a fixture and parametrize to a test function in pytest?
 
3:13 PM
I cant query plastic scm plasticscm.com/documentation/restapi/… example: GET localhost:9090/api/v1/repos/myrepo/branches?q=id > 50 .my query=> ..../branches?q='parentId' = '8044'"
I tried all the alternative versions of parentId = 8044 or '8044',
Nevermind my question, I found the error
 
4:10 PM
@Adam sure, it gets resolved over the function parameter names
 
cbg
 
@pytest.mark.parameterize("args, expected", [("inp", True)])
def test_foo(client_fixture, args, expected):
    assert client_fixture.foo(args) == expected
if that's what you mean, it just works. or do you mean if you can parametrize a fixture between different tests?
because that also works, but it's more complicated
 
5:10 PM
cabbage
I just discovered assertLogs and now I am lamenting the untold hours I spent trying to mock Logger ... #HeadDeskMoment
 
5:29 PM
you're using unittest and not pytest?
 
6:10 PM
Hey there!!
Does anyone know the best method to get all libraries and their versions used in a Jupyter file??
 
6:40 PM
@Arne legacy FOSS project. I'm in the midst of transitioning -- practically rewriting -- every single test case into pytest. But at this point, it's still using unittest. Or nose2, to be exact.
 
 
1 hour later…
7:59 PM
@pepoluan noble endeavor o7
 

« first day (3751 days earlier)      last day (1181 days later) »