« first day (3782 days earlier)      last day (1166 days later) » 

1:14 AM
Is there a more efficient way to do the tuple a // b, a % b?
And which of the following functions do you see as more pythonic?
    def func(x, lst):
        if x in lst:
            return
        print("Hello")

    def func(x, lst):
        if x not in lst:
            print("Hello")
 
@AnnZen divmod(a, b), not sure if its efficient but it gives a tuple
 
it is
 
good to know, I saw somewhere math.pow is slower than ** and function call being slow so I thought that applied here
 
but two operators with a tuple to build all in python is bound to be slower
but even without performance considerations divmod is exactly the tool for that job
 
ahh make sense, if everything is a function call then ** triggers __pow__ why is that not a function call?
pow is like a wrapper and so the additional call is what makes it slower?
 
1:31 AM
math.pow needs looking up the math name (because it could be anything) and then looking up the pow attribute on the name (which could still be anything), and then calling the function from python. And there's special bytecode for **.
In [224]: dis.dis('x**y')
  1           0 LOAD_NAME                0 (x)
              2 LOAD_NAME                1 (y)
              4 BINARY_POWER
              6 RETURN_VALUE

In [225]: dis.dis('math.pow(x, y)')
  1           0 LOAD_NAME                0 (math)
              2 LOAD_METHOD              1 (pow)
              4 LOAD_NAME                2 (x)
              6 LOAD_NAME                3 (y)
              8 CALL_METHOD              2
             10 RETURN_VALUE
 
there is always some some special casing for things my mind logically relates :D
unrelated, I installed IPython and the tab completion box and ? (int?) makes it an instant catch
if only I can remove the in out side tags I will be replace my repl
 
1:48 AM
@python_user ipython --classic
There's also foo?? and %timeit and %%timeit etc.
But In/Out are actual dicts you can reuse
 
thanks, --classic is exactly what I wanted, I dint know those were dicts
 
In [228]: 'potato'
Out[228]: 'potato'

In [229]: Out[228] == 'potato'
Out[229]: True
I lied: In is a list, only Out is a dict
 
Even with --classic enabled one can use the In and Out dicts, it's just that it's hard to know which one to access. Also you can use _<number> as well.
 
so this is _ but for the entire run
 
yes, and there's __ and ___ too
 
1:53 AM
@AndrasDeak This can also be used as _228
 
ok ipython actually has more then, I didnt like the In Out things as they reminded me of jupyter notebook, I hate those
 
@SayandipDutta you already said that
@python_user jupyter notebooks used to be ipython notebooks
 
@AndrasDeak sorry, I wanted to quote the message, not reply to you. How do you quote here btw??
 
thanks for the help guys, learnt something new
 
@SayandipDutta either post a permalink to a chat message for a fancy quote of the message, or type whatever you want manually with >
there's faq/help links in the bottom right if you're on desktop
and there's the sandbox for practice
 
2:32 AM
@python_user Thank you so much!
@AndrasDeak Good to know. But I want to be sure, is divmod(a, b) really more efficient than manually entering a // b, a % b? I'm asking because I did some tests with time.perf_counter, and the results questionably differ from that statement...
 
2:53 AM
 
 
1 hour later…
4:13 AM
@python_user Oh, that explains it. Thanks again!
 
 
3 hours later…
7:16 AM
cbg
@AnnZen in general the first one, especially in longer or complex functions, since it doesn't increase the indentation level for the rest of the code.
 
8:12 AM
I hate it when someone says that they love python and then write a 140 line program which could simply be 14 lines if they actually knew some basic features/libraries of python
 
@AnnZen Why? Is this crucial to the performance of your program? Assembly language is generally faster than Python, have you considered that?
"Premature optimisation is the root of all evil in programming" -- Donald Knuth
 
cbg-ning
 
8:41 AM
@python_user fair enough
 
8:53 AM
@MeetTaraviya Bear in mind, though, that most programmers are reluctant, only programming because they have some underlying task they want to get done. You may find they love it because they can minimise programming time to a usable solution (and values of "usable" vary greatly over a programming career).
They aren't generally concerned about engineering sloppiness or inefficiency.
 
9:06 AM
@holdenweb this 100%, my current job showed me this
not that they love it, they just want to find a usable solution
 
that's the "duck tape and wd40" aspect of engineering :P
 
probably a dupe too
 
"similar to toString in Java"
 
9:14 AM
@python_user True of many aspects of (working) life. In my first job (age 15, trainee production engineer in a TV factory) I learned that most people don 't work in TV factories because they love making TVs - even though some do.
 
comment suggestion even better
 
@AndrasDeak Could work, if returning None is seen as intentional.
 
IMO that's a really bad dupe
 
So I prioritised work I was interested in, and I've been lucky to be interested in stuff that pays well by and large.
 
IMO that's a really bad question ^^
 
9:16 AM
@Aran-Fey both?
I can reopen it
for about 1 minute
Nevermind, Miyagi can too. I have to leave.
 
(I know I'm using it wrong)
 
how long should 'conda create --name XXXX' take?
 
9:31 AM
depends on the XXXX part i presume
 
Size of files?
 
yes, im assuming youre specifying package names. so it's got to do dependency resolution and download packages if they're not available and so on
 
Do I need to specify python=X.X.X ?
 
if you want to. you dont have to if you dont want to*
 
9:46 AM
Thanks! Guess I'll just let it run for a while and see
 
how many packages did you specify?
 
I don't think I did specify any, I added them to the library but the instructions give a line to add them after creating the enviroment?
Once env created: conda install ABC x12
I'm not sure if there is a way to check progress, my console is just running
 
it should probably have been done ages ago then
 
10:24 AM
If I create the enviroment from a console in a project will it auto load the library?
 
user12582392
pip3 install -r dependencies.txt is this wrong?
 
user12582392
i can't get it to install anything :-(
 
user12582392
ERROR: Invalid requirement: 'tabulate numpy pandas matplotlib' (from line 1 of dependencies.txt)
 
which python environment do you want to install it to?
 
user12582392
oops
 
user12582392
10:31 AM
3
 
user12582392
not using conda nor anything
 
so, your global python3 installation?
 
user12582392
yes
 
that might not be a good idea
 
user12582392
well i want people to download the script, and run it easily
 
user12582392
10:32 AM
it's the way I've seen it elsewhere, they put a list of dependencies you install before running :-(
 
without teaching them proper virtualization of python environments?
 
user12582392
yes
 
that's how you end up with this xkcd.com/1987
 
user12582392
ok thanks
 
but even if it is a bad idea, it should essentially work, I can't reproduce your error
pip install tabulate numpy pandas matplotlib
Collecting tabulate
[...]
Successfully installed cycler-0.10.0 kiwisolver-1.3.1 matplotlib-3.3.4 numpy-1.20.1 pandas-1.2.2 pillow-8.1.0 pyparsing-2.4.7 pytz-2021.1 tabulate-0.8.9
 
10:36 AM
does pip ingest a requirements file with multiple packages in 1 line?
 
should -r files list one requirement per line? The error suggests they're all on one line.
 
yeah that's my first guess as to what's wrong as well
 
11:01 AM
oh yeah, that seems to be it. duh
 
@Arne I never noticed that "python.org binary" and "$PATH" are not very likely to be on the same system
 
11:19 AM
"there's no async lambda, let's write a Monad to fix that" – Yam, functional programming has some trippy side effects.
 
11:44 AM
Hi guys,

I keep on getting this issue and the top fix does work but it just resets it for it to happen again a few days later. Can anyone guess at how to fix this perminently or work around what looks to me like an MS bug?
https://stackoverflow.com/questions/52889704/python-win32com-excel-com-model-started-generating-errors
 
One workaround is that perhaps you catch and log that error, and essentially automate the deletion of the folder whenever you catch this error perhaps. "band aid on a band aid". I have no idea about the issue or a permanent fix
 
is there any reason you are not using openpyxl or other python libraries for excel?
to me, win32com seems like the equivalent of using selenium to load a static webpage, so I am guessing win32com provides something others dont
 
your suggestion is a good one in general. it's nice to get rid of the middle-man and work with the data directly if that's an option. for some people, win32com may be necessary if they specifically need to interact and manipulate with files as how microsoft's office applications would.
so, as per my understanding, the things that win32com offer is a tightly coupled experience of using python in collaboration with microsoft office on a windows machine. Whether that's an advantage or a hinderance depends entirely on the actual use case
 
11:59 AM
that makes sense, so maybe they want to achieve something for which there is no API available in other libraries
 
yes, or say, you want to explicitly actually fire up the outlook application and generate the "draft" window for "final review" for example
where the idea is that you specifically wanted to interact with the outlook draft panel. just as a random example
 
more useful in automation testing then
 
aye, or for handing things off to non-tech savvy users
"double click this file and then just read the window that opens. it's a normal excel/word/outlook document. you'll manage that..right?"
and then coffee machine breaks down and all hell breaks loose. or something like that
 
that can come in handy, though I guess powershell would do that much like AppleScript on mac
you dont have to learn one more thing if using win32com
 
Looking for suggestions on how to name a helper that converts an Iterable[Awaitable[T]] into an AsyncIterable[T]. So far I just have some unwieldy things like await_each or short ones like awaits.
# original
for aitem in iter_awaitables:
    print(await aitem)
# how to name this vvvv?
async for item in MAGIC(iter_awaitables):
    print(item)
 
12:08 PM
asyncify_container perhaps
 
aiter as in iter? maybe you can even have a __aiter__ someday
 
I already have aiter to just call __aiter__ ;)
@ParitoshSingh the argument is already async'ish, so not sure if that fits
 
well my knowledge of async stops here to suggest anything useful anymore
 
my knowledge of async never stops. it's a minor sidenote that that's just a side effect of my knowledge of async never starting in the first place. :)
Perhaps it will one day. i'll wait.
 
async awaits you, Paritosh
6
 
12:13 PM
:D it's the future, they say.
 
Sorry, my internet went down.

There is at least one place where I don't see a way around using win32com which is encrypting xlsx files.
 
I knew my deja vu was tingling:
Dec 4 '20 at 18:51, by roganjosh
Are you talking about the following comment? Because the answer doesn't suggest that, it just references it from a linked thread
So, we have seen this issue before and (presumably) fixed it back then? Is this a new issue?
Essentially, I was referencing a comment on the answer that you linked, not the answer itself. It seemed like someone had a follow-up note to make in order to get the main answer to work
 
1:05 PM
@MisterMiyagi here's what I don't get. You said async is "a pretty good fit" for python. Yet I keep hearing that async is a clusteryam in python. What's the deal with that? Is it a good fit in principle with historically terrible implementations?
 
@ParitoshSingh and make it a reeeeallly loooooong riiiiight :D For ultimate snark xD
 
haha yep
ooh, i'd love to hear some insights on that, re async
 
@AndrasDeak async is technically very well-suited for Python, since it is single-threaded concurrency. It is semantically cumbersome due to the coloring problem. The latter isn't helped by the powers that be having refused to add some basic features like async lambda.
As a user of libraries, I still prefer the Golang approach that makes everything magically async in the runtime. Explicit async is only neat when you actually work with the concurrency yourself. If you just want to do I/O, async being infectious to all calling code is quite a chore.
 
1:24 PM
blocked link but i think ive read that before. it's talking about how you cant have sync functions contain async functions?
or the other way around.. i can never keep it straight
 
exactly. Only async may use async, so just using a tiny bit of async means you have to make almost everything async.
 
yeah, i did hear about that. sounded like a horrible chore to create even standard library components into essentially two versions, one for sync and one for async
 
I thought stuffing blocking code in loop.run_in_executor would let you run sync code?
 
the problem is the other way around: sync code cannot freely run async code.
 
ahh, I understand, which is why the whole asyncio.run things comes in
I once read an article that explained this, time to read it again
 
1:41 PM
@MisterMiyagi OK, so what you meant was "it's not as bad as it could be"?
 
async is the perfect solution to a problem you better don't have in the first place.
 
I'm doing great so far
 
async can fix that as well. :P
3
 
2:00 PM
laurel. that got an audible chuckle out of me
 
2:35 PM
I think I've stumbled upon the most terrifying SO thread I've seen to-date. Setting unsafe=True flags, chown and chmod 777 abound. I don't feel like doing any of this stuff :/
 
2:48 PM
that's why SO is 16-years and above restricted in the EU
 
3:20 PM
@MisterMiyagi sounds about right. I wanted to get into async and then realized it doesn't solve my problem :D
 
3:41 PM
That last time we didn't get futher than deleting that folder.

What I'm leaning towards now is to 'nest' the function to delete that folder inside the function that we use to run an automation when it's scheduled... I'm hopthing that might fix it once and for all but it is definetly a hatchet job
 
4:24 PM
Does installing ubuntu on 1 ssd in 1 pc and then moving the ssd into another pc prevent it from working? Because right now in the second pc ubuntu wont start up. I have a weird looking boot menu and no keyboard inputs are registering
I would expect this to work, but a coworker said I might have to do a fresh reinstall
 
I wouldn't expect that on Windows but I wonder if Linux compiles against a specific BIOS
In either case, I guess you'd be able to save the filesystem?
 
4:44 PM
Regarding CSRF tokens: I'm wondering if it's possible to replace them with a stateless (and thus less annoying to implement) mechanism. Say in addition to a session token, every user also gets a 2nd token, which can be accessed by JS. Every time a form is submitted, JS reads the value of this token, adds the current hour to it, and hashes the whole thing. The server does the same, and compares it to the value submitted by the user. Anything wrong with this concept?
 
The baseline CSRF implementation gives access to JS anyway in the DOM?
 
Ah, I should've explained better. The token is a cookie unique to the user and can always stay the same (Essentially a session token that isn't HTTP-only)
 
I still don't have what I feel is a stable grip on how this mechanism works. I'm happy to take ThiefMaster's suggestion on face-value, but it definitely set off the "I don't really understand the implications of what I want to do" alarm before that assurance
 
@Aran-Fey assumes the client and server are in the same timezone? :p (and the whole sending something at HH:59:59 that takes > 1 second)
 
Just use UTC or whatever. But yeah, the user's clock can't be off by more than an hour
If the hash doesn't match for the current hour, the server can check the previous hour as well
Honestly, the whole thing with time and hashing might be overkill. You could also just take the cookie and append a "foobar" to it. I'm just not sure if it's unsafe to use the same value again and again
In theory, any combination of a cookie + something that requires JS should do the trick
 
4:57 PM
Which was my quandary, because the default expiry time is pretty short, so I was wondering why it needed to expire
 
Not sure tbh. Seems unnecessary
 
 
2 hours later…
6:38 PM
o/ hi room 6. Hope everyone is ok.
 
@piRSquared \o/ - how's yourself?
 
good!
I can complain about a lot of things but my family is healthy and we're warm at night and have clean water so I'll shut up
 
@piRSquared that's a sensible attitude :)
 
@JonClements I love the avatar (-:
 
@piRSquared aww thanks... I had this for ages until I switched to the ninja puppy sometime in 2015 :)
 
6:47 PM
Hi all. I have question related to rollaxis in numpy. Who can help me?
 
@piRSquared \o/ so good to see you back!
 
Covid working from home had me working with a single monitor for quite some time. I finally committed the resources to reconfigure my at home workspace to include multiple monitors. That includes devoted screen space for chat (-:
\o @roganjosh
@YasinUÄŸur just ask and see if someone responds
 
I have 400x400 numpy array which is image. I just want to slice it to 64 squares with size 50x50. I don't know how to do it. I searched on stackoverflow and found that rollaxis is the best way to do it however it is not working.
 
@YasinUÄŸur Please give an MCVE
And, as per the room rules please host off-site and link back to it here if it's a giant block of code
 
Here I found that I can use rollaxis function. https://stackoverflow.com/questions/9006232/creating-a-4d-view-on-2d-array-to-divide-it-into-cells-of-fixed-size

In the first answer Sven Marnach used rollaxis but I did not understand what is 2 and 1 as a parameter. It is axis and start but which value I should assign if I need to slice it 8,8,50,50
np.rollaxis(img.reshape(8, 8, 50, 50), ?, ?)
 
6:56 PM
@YasinUÄŸur what shape do you want to end up with? (That's part of the MCVE.)
 
8,8,50,50 I said :/
 
img = np.arange(2*3*4*5).reshape(2*3, 4*5)
patchwork = img.reshape(2, 3, 4, 5).transpose(0, 2, 1, 3)
 
does anyone know how to implement the equivalent of pandas' df.pivot in postgres? Everything I find requires me to know the resultant column names beforehand (apparently, this is called a static pivot), which I cannot know.
Dynamic pivots seem to exist, but not without needing seemingly excessing effort
 
@inspectorG4dget umm... a bit more info.?
 
Hey puppy!
 
7:11 PM
heya doc :)
 
Without loss of generality, let's say my source table looks has three columns name, course, and grade (let's suppose I'm talking about student report cards here). Let's also suppose not all students take all courses. I'd like to pivot the table such that student names (assumed to be unique in this hypothetical) are the index/pKey, the column names are the course names, and the values are the grade received by the corresponding student in the corresponding course
in pandas, I'd do this: df.pivot(index='name', columns='course', values='grade')
however, to achieve something similar in postgres, I seem to require crosstab, which needs me to know the courses names in order to create the pivot'd output
this is apparently also called called a static pivot (whereas what I want is apparently called a dynamic pivot)
I found a couple of SO posts on dynamic pivots, which all seem to require trigger functions and some convoluted calls in queries that seem more complex than I think necessary
 
can you use one of the crosstab wrappers?
 
crosstab... wrappers? could you point me to some, please?
 
@inspectorG4dget section F.38.1.3. on postgresql.org/docs/current/tablefunc.html
 
7:31 PM
I must not be sufficiently caffeinated. The example in 38.1.3 relies on the computation of ct, which relies on knowing the column names (course names, in my example). Am I wrong about this?
 
@inspectorG4dget you've got me thinking now... I thought you'd just be able to do select * from crosstab3('select name, course, grade from your_table')... haven't had to do pivoting in postgres for ages though... so I might be leading you up the proverbial garden path
 
ooh ERROR: function crosstab3(unknown) does not exist. This is even weirder
I might just have to call it and do it in pandas
 
what version of postgres?
some of the tablefunc stuff is only 9.6+
 
PostgreSQL 12.3
 
7:47 PM
@inspectorG4dget should be okay then... have you actually done a create extension tablefunc; for the DB?
 
negative. Didn't know that was a thing until literally just now
 
8:10 PM
lambda x, y, z: anext(x + await y() + z for _ in '_') runs off giggling
 
I assume the penny is supposed to drop at some unspecified time in the future
 
@MisterMiyagi wait... you forgot your medication and straight jacket! :p
 
We did install the red panic button under the Room 6 desk, right?
Or, at least, the blast doors :P
 
@roganjosh of course... but we made it look so awesome and what with all the "don't press" warnings etc... we ran out of budget to actually connect it to anything...
looks bloomin' awesome though! (the consultancy charges on the exact colour of red etc... were definitely worth it)
 
Oh my. I think it's time for my break...
 
8:21 PM
don't forget your own jacket :p
uh oh... someone having subjected to terrible teaching methods by the looks of it: stackoverflow.com/questions/66322684/…
 
That sounds reasonable to me. No need to confuse complete beginners with special string syntax
 
It's a good job there were 8 people on-hand to post answers
 
Assuming we're talking, like, high school here
 
@MisterMiyagi wouldn't that lambda need to be async (assuming that anext was a typo for next)?
otherwise... I have no idea what's going on here
 
@Aran-Fey I'd so love to see the course materials these students have that lead people to ask such questions :)
 
8:36 PM
Are you not rightly able to apprehend the kind of confusion of ideas?
certainly str("string literal") is a pretty huge red flag
One of confusion, which could originate either from teacher or student.
 
Course materials aside, that person's problem is simple: They don't grok data types. Assuming they're a total newbie, that's really quite normal, no?
 
Kinda surprised they threw str at everything but the one thing that needed it.
@inspectorG4dget not a typo
 
@MisterMiyagi in that case, is that an asynchronous next you imported from... where?
 
from his own shed
he calls it "the corner of fun"
sometimes we hear screams
 
ooh! I would like to visit, but COVID... borders... :(
 
8:43 PM
Stachenblocken with chainsaws is tricky business. Let alone the async work
 
Yeah, it's probably screams like on a rollercoaster
 
And when we don't hear screams, we send someone to check if he's alright
 
meanwhile, I'm trying to figure out how to determine if a column name is mentioned in an insert, from within the pre-insert/update trigger
 
trying to figure out if the value was changed?
 
no. There's a column that could be null. So I'm trying to see if that column was mentioned in the insert. I have to handle that case differently
 
8:48 PM
ok, I'm out of my depth then
 
This is beyond ON CONFLICT DO I guess?
I mean, you could create a temporary table of all the values that are NULL and join against that?
 
do I understand you correctly that NEW.colname will be NULL if colname is not specified in the insert? For example:
create table Foo (
   a int,
   b int,
   c int
)
insert into Foo (b,c) values (1,2);
are you suggesting that a pre-insert trigger will see the value of NEW.a to be NULL in this case?
 
it should be null by default unless you specify that it can't be nullable
I don't know about pre-insert triggers, sorry
 
dang. Thanks anyway :)
 
I'm not sure why I would need to? Maybe I'll add this to my research list
Sounds very LBYL
 
8:56 PM
triggers are very useful for auditing... eg if a row is updated/deleted, you can duplicate the original along with info. such as who requested it etc...
as well as things like applying custom functions to the insert values if needed
if you're using a DB as a datastore store rather than more complicated workflow setup though... you generally don't need it
 
That makes sense. It's now on my list, thanks :)
 
a random example... say you have a list of categories for products... each category has an ID but you don't want to bother the front-end having to worry about that stuff... you just want to allow the front-end to be able to insert name='whatever', category='cabbage'... you can put an insert trigger in, that modifies the category to be the actual ID for relationships or creates a new row and adjusts it to that et.c..
a lot of that kind of stuff these days is normally handled by ORM like stuff and middle-man frameworks, but sometimes, as the DBA, you want a bit more control over stuff
 
Yeah, I was just about to say that I'd go through the ORM for that example... but I think it's handy to know about anyway
 
but definitely good for auditing... if the ORM/middle-man doesn't do it, but it's required, then you can have the DB do it, and set the access to those audit tables non-writeable/non-readable to the client-app etc... so they can't accidentally (or hopefully not deliberately) adjust those
other use is for building aggregate/summary tables that might be expensive to compute if you have to scan table(s) to compute those numbers... if you update a much smaller summary table based on what you know has been added/removed/updated based on some filters, then accessing that table can be very fast
(although again - these days, you'd probably use something like redis for that - but it all depends)
 
9:14 PM
redis to keep an edit log of redshift updates?
 
(and that's mostly because you want such tables to be dirty-readable rather than being held up by transactional update locks)
anyway... going to call it a night for now... had a 'mare of a day migrating data over to salesforce.com/uk/products
 
Night ninja-pup
 
yawns - nighty-night
 
gnight puppy!
@roganjosh confirmed. foo.a will be NULL
 
9:32 PM
As written in the room rules, please wait 48 hours before posting your unanswered questions here. You're almost there with your 49 minutes ;P
 

« first day (3782 days earlier)      last day (1166 days later) »