« first day (3898 days earlier)      last day (1033 days later) » 

12:43 AM
@holdenweb Fix what??
 
1:04 AM
Yo Yo Yo
I'm back
Is there a way to alias a global function in python with a single argument substituted.
 
you mean with a single argument already set?
 
yeah
So basically have a function with like 20 arguments and I need to generate a shortcut that invokes that function with one of the arguments set
 
you can try functools.partial there was a slightly related discussion regarding that here
 
binary_op(op,a,b)
add_op(a,b)
is there something terrible wrong with it?
 
def foo(a, b): return a - b

from functools import partial

a_is_5 = partial(foo, a=5)

print(a_is_5(b=3))  # 2
 
1:17 AM
Yeah now I remember, what was terribly wrong with it?
 
I am not so sure, but you have to explicitly pass the args as b=5 and so on, you cant just call a_is_b(3)
or you can also use closures, the example you have shown is what I saw in a tutorial for closure eg: pastebin.com/etMLFV4P
I missed from operator import sub there but that is how it goes
 
 
6 hours later…
6:56 AM
@python_user The calls for a partial function can use positional arguments: the issue is that you defined the first argument.
>>> def foo(a, b): return a - b
...
>>> from functools import partial
>>>
>>> a_is_5 = partial(foo, a=5)
>>>
>>> print(a_is_5(3))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() got multiple values for argument 'a'
>>> def foo(b, a): return a - b
...
>>> a_is_5 = partial(foo, a=5)
>>> print(a_is_5(3))
2
 
7:13 AM
@holdenweb wow, did not know this, melon much :D
 
@holdenweb Arent both the examples same?
 
is there a reason partial is not smart enough to guess that the argument a has already been defined in the partial function? so in partial(foo, a=5)(4) the 4 can be somehow inferred to be the value for b?
 
7:30 AM
@CoolCloud look carefully at the arguments in the function definition
 
Just realized he changed the order
 
@python_user Seems kind of pointless? If the first argument is a, why would you write partial(foo, a=5) instead of partial(foo, 5)?
 
7:46 AM
ok consider this, I would expect partial(foo, b=2)(1, 3) 1 and 3 to be a and c somehow, I know now I can do what was suggested by holdenweb though @Aran-Fey
def foo(a, b, c): return a + b + c
from functools import partial
partial(foo, b=2)(1, 3)
 
Okay, good point. It would be nice if you could do that
 
I now understand how this works, I was just expecting partial to do some magic
 
8:03 AM
This was surprisingly tricky to hack together... Thank god for whoever implemented this awesome introspection module ;P
Actually, I'm not sure if the to_varargs method already exists in the latest published version
 
introspection is not std lib?
 
nope. inspect is the stdlib version
 
will have to setup it up later and give this a shot
introspection.signature and introspection.Signature, PascalCase for class names is really evident here
 
Here's a version with an implementation of to_varargs included
 
nice, I will trace this and see how this works
 
8:25 AM
omg, you wrote introspection
" Thank god for whoever implemented this awesome introspection module ;P" this makes a lot of sense now
 
8:36 AM
@python_user It's often not possible to infer that properly, or at least really complex. Matching arguments to parameters is rather complicated in Python. partial would have to do some effort on each call (since function objects are mutable), and it might still not be correct all the time. Better to raise an error than to guess.
 
@Aran-Fey Yes, things stay easier when you don't match positional args with keyword params or vice versa.
@python_user Yes, but here you aren't saying it's impossible to do something in Python, you're saying it's impossible to do something the way you'd like to.
 
 
2 hours later…
10:54 AM
Hello, i'm interested in building a GUI for my applications and looking into Qt instead of tk and i'm unsure how to properly set things up. The Qt for Python Getting Started page states it is building Qt from python from source and requires packages like CMake 3.18+, libclang, Python 3.6+, Git 2.0+, Qt 6.0+. But it also notes if only pyside6 is needed just do pip install PySide6
I am able to make windows using pyside6 without setting up Qt for Python from source so i'm not sure which stuff I really need.
I know pyside6 uses Qt6 but pyside6 seems to work with just installing via pip so does it mean pip installed Qt6 with it?
 
hey guys I have been stuck on this for a couple days now does anybody see why this program would by constantly building memory until the machine shuts down? dpaste.com/4WV4TEUJB
 
@Kwsswart I see beautifulsoup, I hit Ctrl+F, and get no results for .decompose()... so, that. Always decompose your soups when you no longer need them.
 
hmmm I did not know that
@Aran-Fey I have incorporated this within, however still seems to be consuming massive amounts
 
11:24 AM
I don't see any other problems
 
is so strange how its using so much memory
 
@Pherdindy I found it easiest to manage PyQt implementations in conda environments, where the dependencies appear to be well-defined.
 
@holdenweb thanks any advantages of using PyQt over PySide?
The only difference people always note is that you cant distribute stuff made with PyQt without a license
And PyQt is more popular but not sure if that means i'll have access to more learning materials or it'll be easier to come up with something
 
11:44 AM
@MisterMiyagi thanks MM and @holdenweb that clears some doubt I had
@Pherdindy from what I know, PyQt has some license stuff that makes it difficult to use with commercial code
ok you have already mentioned that, my bad
 
Yeah installing is a drag since i'm quite new to it and their pages from doc.qt.io have 3 pages titled: Qt for Python Quick start, Qt for Python Getting Started, Getting Started on Windows
One only installing PySide6 and already testing sample code and two notes installing some other packages
@python_user More or less that's the difference the web pages I look into usually talk about and a few minor differences
My understanding from downloading from source is not relying on package managers like pip right? So if I do pip install pyside6 I don't really have to think about installing other packages like CMake, Qt, Git, and libclang?
Since if I do pip list it only displays pyside6 and shiboken6 in the environment but I also tried something like pip install CMake and pip install libclang and it does get installed by pip but maybe within pyside6 they already bundled it together?
 
12:01 PM
cbg
 
12:17 PM
cbg
 
 
1 hour later…
1:45 PM
Pyside is effectively the new name for PyQt, I reckon. No advantage to using it except it's the newest and shiniest kid on the block and will therefore likely last longest. Plus it's maintained by Chris Tismer, who gave the world Stackless Python, but that's another story .
 
Hmmm is there any change on the commercial license? Apps made with Pyside can be sold without buying a license?
 
1:59 PM
pypi.org/project/PySide says it's LGPL license, the TLDR of which is, you can sell your app for money without giving money to PySide.
LGPL is a slightly more permissive form of GPL, which was designed with a philosophy of "The FSF argues that free software should not place restrictions on commercial use, and the GPL explicitly states that GPL works may be sold at any price."
 
2:12 PM
If I'm reading riverbankcomputing.com/commercial/license-faq correctly, this is freer than the terms of PyQt's hybrid GPL-and-Riverbank license, which does expect you to pay them for commercial uses.
Qt also has its own licensing for commercial purposes, which you'll probably have to deal with whether you use Qt or PySide qt.io/faq/2.5.-why-and-when-do-i-need-a-license
 
Well I thought just use Pyside and no need to buy a license :P
 
"[This project [Qt for Python, aka the project that contains PySide] is available under the LGPLv3/GPLv3 and the Qt commercial license.](doc.qt.io/qtforpython/#project)";. So, yeah, you need to pay Qt.
Hmm it occurs to me that I've been interpreting "licensed under A and B" to mean "you must satisfy all the demands of both A and B", but perhaps it means "you must satisfy the demands of either A or B, not necessarily both"
Then the latter interpretation implies that if you satisfy LGPL's copyleft by licensing your own code under LGPL, and releasing its source code, etc etc, then you can ignore the "pay us money" terms of the commercial license
My confidence that any of my assertions are correct have dropped to about 70%, so I encourage you to ignore everything I've said and draw your own conclusions
 
2:30 PM
@holdenweb Based on what I read there was a conflict/disagreement so there is PyQt and Pyside but Pyside is the official bindings for python but eitherway sticking with Pyside just to get started.
 
2:43 PM
@Kevin My understanding is that if your Qt program is freely available, that's ok. But if you make money off it, they want their cut. However, IANAL, and I might be wrong. But I originally chose to learn GTK rather than Qt because of the murkiness of the licensing issues related to Qt.
 
 
1 hour later…
that question is kinda confusing
 
@smci The target would surely involve a defaultdict?
Oh, 2 upvotes to an answer that doesn't even give the right output. Main is just a silly place.
 
4:03 PM
Both answers do the same thing, though? Which one's incorrect?
Hmm, I guess returning a defaultdict instead of a regular dict could be a problem
 
cbg guys, is there someway in python (any library) I can create a flowchart and make it interactive? like draw.io but i need some blocks to be interactive / clickable (call a python function after getting user input)
 
I've dabbled in flowcharts a bit and I couldn't find any Python-specific library that satisfied my requirements. Even branching out to language agnostic software like GraphViz, the output I could produce felt pretty primitive
 
maybe I will check graphviz and see if it has python bindings or something
 
4:18 PM
thanks that should make things easier, my use case here is to walk though a flow chart with someone, so when that someone asks what does this block do, I would want to click on that block and that block would have a function that would execute, makes sense?
 
While you're looking at graphviz, peruse graphviz.org/resources too. You might find a tool built on top of graphviz that matches your goals
 
@roganjosh No it doesn't need a defaultdict, just plain old dict.get(). It's just dupe-farming, needs to be closed as dupe ASAP.
 
^ done
 
You might want to look into a UI package like Kivy. It seems pretty straightforward, and is built for this sort of thing.
 
@Kevin sure I will check this now
 
4:22 PM
@python_user This sounds an awful lot better-suited to JavaScript with callbacks
 
I was going to say that, but then thought better of it
 
ok thanks to you guys, I now have three routes to explore, graphviz, kivy, JS and something that I can find in the link shared by Kevin
 
@roganjosh Good grief, then the OP edited it to make one dictionary four dictionaries... sigh... anyway it's been closed
 
though I might take the JS route if all else fails, I mostly have to learn JS just for this
 
Java Script
 
4:25 PM
If you're doing everything from the ground up, I'd say Javascript and Python are equally suited to making boxes and lines that call a function when you click them.
Pretty similar interfaces, even, if you compare the tkinter canvas to the HTML5 canvas
 
@smci Yeah, I think I've lost all energy for main now. Your reply to me before this comment was fair, too.
 
I know a website where you can learn java scipt
 
@Wolf What is even the point of comments like this?
 
this would hopefully be a long time project, as in I would need to create multiple interactive flow chart, so I might need to end up spending a lot of time on this
 
@python_user Do you want to render this in a webpage, or just local GUI?
 
4:28 PM
@Wolf If you thought you were correcting me on how I typed JavaScript, you're wrong. You're also continually a source of noise in the room when you do interact with us. Quit it.
 
that is up to me, I only want the outcome of a clickable flowchart, which is why even a full blown gui (like kivy) or a web ui would also work
thanks for the suggestions guys, I will look into these hopefully over the weekend and figure it out
have a nice day / weekend
 
@python_user I know it's up to you, that's why I asked you which way you wanted to go. You could also use Enthought Tool Suite: traits, chaco etc., maybe graphcanvas
 
@smci thanks for the links, btw I meant "that is up to me" as in I am open to any suggestions, in case that came out as rude
 
The reason I say "JS in browser" is because it's been done already, so all the components should be readily available. And ultimately you'll probably appreciate the ability to render it in other people's browsers.
@python_user Sure, no worries
@roganjosh The pain in main is plainly not our gain...
5
 
That leaves me with "Hurricanes hardly ever happen in Hampshire". What am I supposed to do with that?!
 
4:43 PM
@roganjosh Sell insurance? Learn to kayak? Hoard storm lamps? Choose your own adventure. Then turn to section 592...
 
In any case, that's star-worthy stuff. I doff my cap
 
@roganjosh The verb 'becalmed' does not get out as much as it deserves...
@python_user also convert the python dictionary output into a flowchart suggests converting to dot file, then use the Tk export of graphviz
@roganjosh ...strains the brain...
 
You're definitely going for the easier of the two examples. Get something that rhymes with "hurricane" and "Hampshire" and I'll be very impressed!
 
@smci I now definitely have more options to explore laurel, at least now I wont be blindly googling
 
5:05 PM
@PM2Ring Never having wanted to create anything chargeable with PyQt the licensing was ever an issue for me. I'm fairly sure Tismer will be on the right side of the open source line.
@Aran-Fey So return dict(the_defaultdict)?
 
Easy fix, yeah
 
@smci Possibly because "becalmed" is an adjectival participle?
 
5:37 PM
@holdenweb ...derived from a verb.. weighs the same as a verb... is made of wood... burn it
 
6:09 PM
cbg folks
 
Hi I have a question about if my actual question would be down voted, as it seems silly yet I am still puzzled and what the pythonic way would be. I do not think it will have a definitive answer but it isn't an opinion question either but rather a question of how people go about this.

Generally it is about how do you make sure that no one will access dicts that you have loaded from e.g. JSON-Files with the wrong (e.g. Typoed ) keys
In other languages you would create (generate) dedicated classes, but I have seen that e.g. with data frames you do not tend to do that but use the string key right away which seems sensible. yet maybe I worry about "Connascence of Name" too much here
so yea maybe it is an opinion question after all
 
I don't think there's a sane way you can do that
It also seems like such a fringe case, I think you're better off not worrying about it
 
well it happend with us in a two people team where at some point we had a typo in incrementing a counter d['counts'] = d['count'] + 1
after some time you notice this but it "runs" fine only the output is not what you'd expect
 
6:26 PM
That's an issue with variable naming then
 
yea kind of ... well I just thought that maybe there is a pythonic way or linter that tells you which names are off (e.g. by existing only once or being very similar to other names) or makes sure it will error in the first place when accessed falsely ...

I found https://stackoverflow.com/questions/12465588/convert-a-json-schema-to-a-python-class
which I guess will utilize once the schema is defined but it still needs to be run through several people
 
Proposal: use d['counts'] += 1 to reduce your chance of bad key names by 50%
 
@Kevin yea it was a standin for the true code , but thanks
 
I thought that might be the case, but I elected to be obtuse anyway
 
well as said it is just a worrysome subject and maybe we worry to much
 
6:39 PM
Sometimes when I really do not want string literal typos to go unnoticed, I define my literals as constants at the top of the script, for example COUNT_KEY = 'count'. Then if a typo occurs in the body, like d[COUNTS_KEY] = d[COUNT_KEY] + 1, then it immediately crashes with a NameError rather than silently assigning a value to an unused key and continuing as if everything is fine
 
yes.
for the time being i have created a reference module where i throw in all the keys and access them like that. making sure there is no chance for mistyping plus IDE will help with that too. But it doesn't seem very pythonic to me even though I do not know what that means :shrug:
 
Why not use a frozendict-like custom class?
new keys may only be assigned to during __init__
It might be as simple as storing the allowed keys at the end of __init__, then making __setitem__ raise if the key is not in the allowed keys tuple. Just make sure that __init__ uses dict.__setitem__ or something.
there are probably smarter alternatives as well
 
I was thinking of a "dict subclass with restrictions" approach too. I feel like there are a number of ways to enforce adherence to a schema, and they don't necessarily require you to substantially diverge from a json-like design
 
but this is a different angle than helping the linter
My hunch is that either the linter will catch issues and it's impossible to use the wrong key, or the dynamic keys will raise. Probably not both.
 
Perhaps the bare minimum would be, compose the data structures using perfectly ordinary dicts and lists and such, and then when you're done, iterate through it and make sure it doesn't have any unapproved keys or types.
 
6:45 PM
yes, well at some point we hopefully have a final json-schema
there is already a question about that .. but it seemed very Class-oriented like
https://stackoverflow.com/questions/12465588/convert-a-json-schema-to-a-python-class
 
I guess the advantage of generating full-fledged classes is that your IDE might be smart enough to notice when you're creating a class with invalid parameters
So I guess, what Andras said
 
@Kevin yes ... but I take it there is no designated pythonic way ?!
 
Not that I'm aware of ¯\_(ツ)_/¯
 
@Summer-Sky python doesn't even have designated frozen dicts
 
@AndrasDeak so thanks and this helped me .. as I was mainly wondering how it "should" be done ...
@Kevin so thanks and this helped me .. as I was mainly wondering how it "should" be done ...
it is completely fine for me ... i only wondered if i just was doing it wrong as there were some (maybe self proclaimed) python gurus along my life path who said there is a pythonic way and a wrong way
 
6:53 PM
I wonder that myself quite often
 
@Summer-Sky arguably what's easy to implement in python can often be called pythonic. And it probably wouldn't be too painful to implement this.
(aside from more common programming patterns where there are clear beaten paths)
it's easy to implement a "print items on separate rows" using a list comp, yet that's bad form
 
Uh oh >_>
 
i thought list comprehension is pythonic
 
@Summer-Sky are classes pythonic?
 
in citing john oliver "I do not know"
 
6:58 PM
Why not?
 
because pythonic seems to me undefined ...
 
exactly
well, after your edit, less "exactly"
 
List comprehensions can often appear in Pythonic code, but their presence does not guarantee Pythonicness
 
But you can't point to a syntax element and say it's a good pattern to use.
List comprehensions, just like other elements of Python syntax, can be used properly and can be used wrong. When you use them properly it's pythonic. When you use them wrong they are an anti-pattern.
 
-.-
 
7:01 PM
A masked man jumps out of my closet wielding a steak knife, and I say "Ooh! Are you here to cook me a steak?". But no, this is not his goal.
 
import sys
from PySide6.QtWidgets import QApplication, QDialog, QLineEdit, QPushButton

class Form(QDialog):

    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.setWindowTitle("My Form")
Isn't this style of using super for Python 2? does it work the same way as super().__init__(parent) if in Python 3?
 
@Summer-Sky the headlines look OK. But some things are missing. Like "Using assignment expressions".
 
@Pherdindy Yes and yes
 
I also think yes and yes
 
7:05 PM
@AndrasDeak i have done all of those intuitively "correctly"
 
Thanks strange how the docs in PySide6 still uses that
 
@Summer-Sky that's good
 
In doc.qt.io rather. Also their docs have quite a bit of errors and their tutorial files have some missing modules
 
shouldn't ''super(Form, self).__init__(parent)" also be valid in python3?
 
@Pherdindy I recommend this guy over the Qt docs - mfitzp.com
 
7:09 PM
I'm pretty sure super(Form, self) is still valid yes
 
@Summer-Sky Yeah it still works I would just rather remove it if it was equivalent. I just came across it today and confused why it had arguments so I had to take a look
@MikeDriscoll Thanks a lot will take a look
 
@Summer-Sky I found this in an answer on Stack Overflow:
def group(d):
   _d = [(a, list(b)) for a, b in gb(sorted(d, key=lambda x:x[0]), key=lambda x:x[0])]
   return [b if not (j:=[l for i in k if (l:=i[1:])]) else {a:{b:group(j)}} for (a, b), k in _d]
Note: please don't anybody every do this. Eye bleacn can be found in the kitchen.
 
@Pherdindy I would use super().__init__(parent) in Python 3. It does the same thing
 
-e s/every/ever/ -e s/bleacn/bleach/
hard to type with all this bleach in my eyes
 
@MikeDriscoll Right thanks a lot never really used python 2
 
7:15 PM
@AndrasDeak That is some ugly code. I recommend breaking long / nested list comprehensions over multiple lines and using good variable names over single letters
I know that's an example you grabbed, but it's painful to read
 
well ... I had to create a fixture once and the least typing way was to write

[' '.join((
('skip' if sid % 2 == 0 else 'add'),
str(sid),
str({'someId': str(sid)})
)) for sid in [1, 2, 3, 4, 5, 7, 9]
]
 
@MikeDriscoll check out what my message was a reply to
@Summer-Sky you went wrong when "least typing" was a concern. That's for Code Golf
and f-strings alone would make that more readable
 
but how to format here ?
 
the formating guide sais there is a button yet i dont see that
i indented also
 
7:19 PM
@MikeDriscoll I like how his page is very specific to PyQt and PySide very updated too
 
@AndrasDeak I don't think I can scroll back far enough, but that's okay
 
@Summer-Sky it also says the button appears when you input a newline
@MikeDriscoll directed replies have a little arrow in the left corner. If you click that you get the original message.
 
@Pherdindy. The reason I like that guy's site is he is constantly updating it
 
yea i made that indentation in the code lines

code lines
 
@Summer-Sky please practice in the sandbox, not here
 
7:21 PM
although I do know the PySide devs are trying to get their tutorials up-to-date as well
 
@AndrasDeak kk
@AndrasDeak i meant I obviously was one (multiline) message and it is futile to point out that there is no indentation "Indenting only the lines of your message that you intend to be code. This does not work. Every line must be indented; you can’t mix plaintext and code in a multi-line message." (I know that now)
 
I don't understand, sorry
 
@MikeDriscoll They should the first few pages of their tutorial already have inconsistencies which are quite easy to spot
 
@AndrasDeak ok, anyway thanks ... and good night
bye
 
Bye
 
7:37 PM
Hi! 
Would like to ask your thoughts/ideas on this. I’m placing an RGBA image (foreground image) over another RBG image (background image), at a given x,y point using numpy arrays at the moment (but willing to use any other tool as needed).

However, the foreground image (0,0) coordinate is placed above the background image x,y position. Instead of this, I’d like to place the foreground image over the background image centered on that x,y position, but unsure how I could implement it that way. Any advise/ideas?
 
sounds like simple arithmetic
instead of background[x0:x0+h, y0:y0+w] you assign to background[x0-h//2:x0+h//2, y0-w//2:y0+w//2] give or take fencepost errors
and you should first check that (x0, y0) is not too close to any edge of the background
 
8:03 PM
You can use Pillow to merge two images together instead of NumPy: stackoverflow.com/questions/5324647/…
 
 
3 hours later…
11:05 PM
@Kevin Additional proposal: if you know in advance what the keys are then consider making them attributes of an object rather than keys of a dict.
 
11:23 PM
@Kevin I thought my mind was terrifying...
 

« first day (3898 days earlier)      last day (1033 days later) »