« first day (4279 days earlier)      last day (652 days later) » 

1:20 AM
stackoverflow.com/questions/14229433 The question seems to have been motivated by an untrue premise? Should anything be done here?
 
1:56 AM
stackoverflow.com/questions/2629198 Answers from here might be mergable into the canonical
 
2:26 AM
whew, I really just spent over three hours on a sunday night collecting a list of questions about comprehensions and generator expressions.
 
 
6 hours later…
8:54 AM
https://meta.stackoverflow.com/questions/370415/where-shall-we-let-the-community-update-xcode-download-locations/370472#370472

I just had the epiphany that the masterpost I keep wanting to make about list comprehensions... could just go in the [tag:list-comprehension] tag wiki.
except it seems clear that the few other people involved in that, don't want it to be Python specific.
(which is entirely understandable)
it's notable that e.g. the regex masterpost gets to be an actual question, instead of the regex tag wiki
also, even the JSTL tag wiki is getting a tiny fraction of the views of the most popular questions.
 
9:37 AM
Can you duplicate towards a tag wiki? Otherwise I'm skeptical of how many people would actually see it
 
per the link: you can link the tag wiki in answers. I agree that this is not exactly as good
(and in comments I guess)
 
 
1 hour later…
10:42 AM
Wow... just found github.com/Textualize/textual - being built by the same person as the rich library... it's looking promising...
 
Looks impressive. Thinks of use case to justify an hour or two's procrastination
 
Oooo... rich-cli is also kinda funky... this guy has an obsession with terminals... I like him! :p
 
 
2 hours later…
12:57 PM
Umm.. we must have a dupe for stackoverflow.com/questions/72857092/… ?
 
@JonClements Same idea, but perhaps needs one think-corner: stackoverflow.com/questions/8356156/…
 
ummm
 
This one has the right answer but a lot of fluff: stackoverflow.com/questions/53712256/…
FWIW, I think your question is actually pretty nice a canonical base.
 
now they're asking something else though
I've answered that several times but trying to find a reasonable question for it...
 
"reasonable question" and "regular expressions"... :/
 
1:06 PM
point taken :p
 
 
2 hours later…
3:14 PM
I have different code segments that I want to select and run at random. So I was thinking of putting the code segments into separate functions and pick a random function and call it.
functions = [lambda x: x + 1, lambda x: 2 * x + 3, lambda x: 4 * x - 5]
import random
print(random.choice(functions)(6))
This is how I could do it if the code segments were only one-liners, but what do I do if the functions are longer? If I have to def f1, def f2, ... and then functions = [f1, f2, ...] that seems tedious. I'd have to name the functions and then again keep the list of function names updated too
function = random.randint(0, 4)
if function == 0:
    # code
if function == 1:
    # code
...
If I put the code segments into if conditionals then I don't have to name functions but I'll still have to keep track of the number of functions
(In JavaScript I'd just put all - unnamed - functions into an array and pick one)
 
okay... there's other techniques but they're going to be more complicated than just maintaining a list
 
@rattlesnake you could use a decorator to store each function in a list
 
functions = [
    """
        print("1")
        print("hello there")
        # an some other code
    """,
    """
        print("2")
        print("goodbye")
        # an some other code
    """,
    # and more functions here
]
import random
import textwrap
exec(textwrap.dedent(random.choice(functions)))
This seems very evil too :P
 
@Zerotoinfinity please don't ask for help here with fresh questions on the main site as per our rules
@Zerotoinfinity that's also way too much code for chat
 
3:29 PM
@AndrasDeak--СлаваУкраїні Sorry, I will take care of that.
 
@AndrasDeak--СлаваУкраїні Hmm yeah I could do that. But I'd still have to name the functions
 
@Zerotoinfinity no worries
@rattlesnake you could call them all the same thing if you're feeling uninspired.
 
@JonClements Only complicated, but still elegant? ;)
@AndrasDeak--СлаваУкраїні True
 
you can't spare defining the functions, so it's a bit weird to me that you're trying to cut down on the def foo(): part
 
@rattlesnake tio.run/##K6gsycjPM/7/… name your functions
ah i see you called that tedious now...
 
3:32 PM
Yeah i don't know
It's not like I'm trying to "cut down" on that part
It's just that if I name function I want to give them a good, meaningful name
 
@rattlesnake sounds like a good idea... why not do so? :p
 
Because that's the tedious work I'd like to skip ;)
It's sometimes hard to find good names for something that does something very simple
There is no need to name them other than to be able to name them later in the list again
 
Like I said: use a dummy name, e.g. _, and append in a decorator. Weird, but your requirement is weird too.
 
Oh yes, yes. I saw your suggestion. I'm already trying it out :) Thanks
 
Alternatively, but I think that's a lot uglier, have one function that contains all the cases in one big if, choosing via a keyword parameter.
sounds like something a lot less maintainable
 
3:46 PM
I'm confused about why defining your functions with names and adding all the names to a list is tedious, but having a list of lambdas isn't? If theyre simple functions just give them simple names
 
I'm confused why you need to do this at all. Is this just for curiosity?
 
How would you name lambda x: 2 * x + 3? def times_two_and_add_three?
 
Having problems to name things usually indicates that there isn't much purpose to having them.
 
@rattlesnake you said you had functions that don't fit in a lambda
 
Yup
Some do, some don't
 
3:48 PM
so you just have to name the big ones :P
 
How often do people want to multiply by two and add three? Surely it has some kind of meaning in the context of your program beyond a literal statement of what it does?
 
XY problem? xyproblem.info
 
doesn't really sound like one
 
4:12 PM
Yeah, no. The issue just came to light when I did some scripting. (Quick and dirty - not an actual engineered software project.) And it's not like I wasn't able to solve it - but I figured maybe there's a different way how to solve it a bit more "Pythonic" like Andras suggestion with decorations for example. I was just a little curious. :) Thanks a lot for your help everyone.
From a Python-outsider's view, it's maybe just a little unexpected that while functions are just regular objects, I can't just "itemize" them in a list. Like why is there even lambda - why not have def work "in-line", too. Like function in JavaScript. (Not an actual question right now, I'm sure I can find some articles about it.)
 
442
Q: No Multiline Lambda in Python: Why not?

ImagistI've heard it said that multiline lambdas can't be added in Python because they would clash syntactically with the other syntax constructs in Python. I was thinking about this on the bus today and realized I couldn't think of a single Python construct that multiline lambdas clash with. Given th...

 
the usual reason is "Guido didn't like the idea"
And it kind of makes sense: imagine a multiline anonymous function stuffed inside a list literal.
 
The real limit are the wetware parsers.
 
@AndrasDeak--СлаваУкраїні ¯\_(ツ)_/¯ Why not
 
@rattlesnake Not to discourage you, but IMO the Pythonic approach is not to end up in this situation in the first place – hence various people trying to drill down on the ifs and whys to get to the task behind it.
 
4:20 PM
@rattlesnake it might work for you, but language designers have to consider the utility of a feature against the ways it could be abused to write unreadable code too easily. Just consider assignment expressions. No, wait, that's the counterexample.
 
Still, there is nothing wrong in writing a decorator for this – it is inherently similar to property, functools.singledispatch, and various other register-several-functions utilities – but you have to write it yourself. There isn't much else to say about that approach until you hit a specific roadblock that you need help with.
 
My OANDA account was approved and is ready for funding. Take another spin; only this time I'll write the trading algo in Rust, so it'll be totally different this time round!
 
Gives a new meaning to the borrow checker.
 
Hahaha
To be fair, I never went mad on it last time, it was just a bit of speculative fun and nobody could deny the markets aren't all over the shop now. Gives me something to code against
 
 
1 hour later…
5:54 PM
Hi Everyone,
My apologies if this is not the correct place to submit this query.
I came across this thread and trying to build the same -https://stackoverflow.com/questions/57280470/soap-digital-signature-verification-failure
I am new to python and need help
 
6:15 PM
What help do you need?
 
I am trying to sign the soap message using the method mentioned in that thread. Initially I got some VC++ 14 higher required error- I installed that and now I am getting
constants.c : fatal error C1083: C
annot open compiler generated file: '': Invalid argument
I am trying to install the xmlsec lib
@roganjosh thank you for your help in advance
 
Not sure how much help I'll be; but we will give it a shot if we can in the room (this is the right place to ask)
Can you post the full traceback on something like dpaste please and link it back here? Also what is your OS?
 
My python ver is 3.10
Os : Win 10 pro
here is the link - to trace
 
Perfect, thanks. I always like the "note: This error originates from a subprocess, and is likely not a problem with pip." messages - PIP quickly throwing up its hands - "Nothing to do with me!!"
Try pip install xmlsec --no-binary=xmlsec?
That's from its pypi page
Other thing is just upgrading pip since it looks like it's actually trying to compile it already anyway
Actually, seemingly downgrading pip
 
6:37 PM
thank you , i tried that command as well pip install xmlsec --no-binary=xmlsec? failed with same error.
could you please tell me how to downgrade PIP?
 
python3 -m pip install --upgrade pip==21.3.1 (assuming that the two libraries are facing the same issue)
 
@roganjosh thank you I will try that
 
The other thing is that it seems to be on conda so that might be another approach rather than pip
 
@roganjosh thanks for the cmd, I was able to downgrade it
Collecting pip==21.3.1
Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 22.1.2
Uninstalling pip-22.1.2:
Successfully uninstalled pip-22.1.2
Successfully installed pip-21.3.1
 
6:55 PM
That was completely speculative, but easily reversible if it doesn't work. It's not easy to track pip between its different versions
Also, maybe it's just some kind of bias but it does seem like 3.10 is throwing up lots of issues that I didn't get by a passing bump to 3.9 a while back
 
@roganjosh with that downgraded PIP version, I am getting error
C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-install-e00kp071\xmlsec_2c2a0812a0bc4eae99d0ccf88df1cb7d\src\constants.c : fatal error C1083: Canno
t open compiler generated file: '': Invalid argument
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.32.31326\\bin\\HostX86\\x64\\cl.exe' failed with
exit code 1
----------------------------------------
ERROR: Failed building wheel for xmlsec
Failed to build xmlsec
ERROR: Could not build wheels for xmlsec, which is required to install pyproject.toml-based projects
 
That's the same error. It might be worth using conda
 
I saw somewhere that it is because of very long path name
how do I do that using Conda? I am so sorry for asking this basic question
 
conda is something you can look up online. The only way a "long path name" would affect you (that I know of) is if you tried xpath to append to your path, which truncates and only tell you after it's done it. Did you do that?
 
this is error is actually coming when I am trying to install xmlsec running - pip install xmlsec --no-binary=xmlsec
 
7:11 PM
Just to check - are you using python3 -m pip install xmlsec?
`C:\Users\Public\Documents\Wondershare\CreatorTemp\pip-install-e00kp071` I think there's something missing from this...
Yeah, there's stuff I don't understand here at all: "Requirement already satisfied: lxml>=3.8 in c:\all\python 3.10\pythondev\venv\lib\site-packages (from xmlsec) (4.9.1)" is in your original log. That is, in itself, a virtualenv so I'm not sure what you've done here
 
7:31 PM
@KarlKnechtel awesome
 
8:26 PM
Do programmers in languages other than Python ever show the misconception of expecting a function to "return a variable"?
(I should say, beginning programmers)
I wonder if it's a consequence of the syntax (in particular, the lack of manifest typing) or bad pedagogy or what
 
@KarlKnechtel how? Returning a variable as a string?
 
But functions do always return a value?
 
Surely not
 
Surely
 
That is the point of the Karl's question?
 
8:35 PM
@Marco no, I mean all the questions that I want github.com/zahlman/so-workshop/tree/master/… to address
 
If it happens to be None, that's different to not returning. The classic mistake that I think Karl is talking about is that people assume something mutated inside a function always returns to the same name as the caller
 
no. I'm talking about when they write
def foo():
    bar = 3
    return bar

foo()
print(bar)
 
So that's a scope question. There has to be a dupe for that around scope and not return values
 
you'd think so, but I know from extensive experience that it usually isn't
first off, from how they talk about it
and second because the follow-on code is often in a separate function
but more importantly, treating it as a scope issue inappropriately encourages global abuse.
 
8:40 PM
part of a broader picture, but unfortunately I can't close questions as a duplicate of ned batchelder's talk
 
@roganjosh I agree
 
this one isn't talking about return at all.
 
And I do disagree with "inappropriately encourages global abuse.". No, it wasn't that long ago that I was learning almost entirely from SO alone and enough red flags exist for global - if someone wants to take that "shortcut", then let them
 
global? shudders
 
but consider e.g. one of the examples in the workshop is https://stackoverflow.com/questions/16043797/how-do-i-pass-variables-across-functions

notice how OP even passes (inadvertently, the global) list as an argument to the second function, expecting it to instead be the thing that was returned from the first. The global list seems to have been intended as a declaration more than anything
 
8:45 PM
Umm... not sure what to do with stackoverflow.com/questions/72861846/… - almost seems like another scoping thing :p
having shuddered at global - at least it's more obvious than how nonlocal works...
 
then there are more esoteric attempts like stackoverflow.com/questions/19326004. It seems evident to me how the mental model works: the asker mentally models the function as containing its local variables, and seeking to "access" them.
@JonClements this is straightforwardly a failure to understand the details of the import syntax
oh, wait.
 
May 25, 2020 at 12:35, by roganjosh
Wow, I've just had a flashback to my totally bonkers logic about how while True: works. It's evaluating deep philosophical concepts about reality and assumes that the loop should run while we consider our existence to be real
 
yeah, maybe a reference for builtins?
 
Lesson - just correct the person. It doesn't have to be duped all the time; maybe an explanation would be helpful
(I genuinely mentally debated that before I understood properly)
 
okay... so his next comment is a bit more meaningful... just not sure if we've got something that already describes it...
 
8:54 PM
amazing; I can't actually find a proper canonical for "how does len work"
@roganjosh I'm confident that a large number of people misunderstand in the same way, and furthermore that it's not the way they're commonly believed to misunderstand.
stackoverflow.com/questions/19674992 Huh. this is a lot closer to what I'm looking for (but for javascript)
stackoverflow.com/questions/70424243 not too far off, in c++ (except OP didn't even try to call the function first). I guess it does happen in other languages.
the other thing I want to highlight about my two examples is that in both cases, OP explicitly indicated a desire to avoid globals (and yes, I checked the revision history)
 
9:10 PM
They knew that globals are bad but not how return works? How does that even happen
 
that's what I'm trying to say, it happens a lot. It is, per all the evidence available to me, a common misconception. Not a lack of a mental model; an actively wrong one.
if you only ever see (or attempt) examples of the return EXPR grammar where EXPR is a simple variable name, then you never have a reason to consider that it's the result of evaluating the expression being returned, as opposed to, you know, the thing that you wrote immediately after writing return. That was "a variable", so that's what you're returning. Right?
 
Ruby-esque ?
think VB did the same thing as well
 
there are similar problems on the call side. I've lost count of the times I've seen confusion between arguments and parameters; the times I've seen functions that completely ignore their parameters in favour of asking for input locally etc etc
people don't get that the parameter is a name that the function will use for a value that is passed in
a lot of the time they expect that the argument not only has to be a variable, but has to have a matching name
the VB quirk that I know about is assigning to the function's own name in order to indicate a return value
(I think it sets the value that will be returned if control flow reaches the end?)
 
@KarlKnechtel just need to explain that is necessary to do bar = foo(), and print(bar), or just do print(foo()). Motive: scope.
 
stackoverflow.com/questions/4601498 ruby seems to have some kind of implicit "floor" variable that will be returned
but it's still returning a value afaict
@Marco well yes. the point is that there are countless extant explanations, scattered across low-quality SO questions
 
9:24 PM
def cabbage
	2 + 2
end
think ruby allows stuff like that
 
@KarlKnechtel That's why we need canonical questions
 
@KarlKnechtel yup - that always struck me as odd but apparently that stemmed from elsewhere
 
likely from perl (see $_, also the inspiration for the _ name maintained by the Python REPL)
stackoverflow.com/questions/51422967 there are countless variations on the theme.
that's what it looks like when they aren't asked in a completely junk way.
 
@KarlKnechtel though shalt not speak the name of that language... we don't want to summon Cthulu just yet! :p
 
I wouldn't want to hastur, I mean, hasten our demise
 
9:31 PM
@KarlKnechtel oh God
 
stackoverflow.com/questions/37088457 another example. "I didn't want to use globals but it was the only thing that worked, how am I supposed to do it?"
and the same wording. "not able to access the variable from the function"
I didn't actually use the word access in my DDG search for this, btw.
 
jon@minerva:~/development/testing$ ruby
def f
    2 + 2
end

puts f

4
yup... so my memory isn't that dodgy
 
the problem seems to occur in python, javascript and - weirdly, c++
but not in java or c#
 
@JonClements wow
So all variables are globals in Ruby?
 
oh, I sort of found a java example. stackoverflow.com/questions/41364257
 
9:36 PM
Python-like behavior, right?
 
op passes an argument to a matching-name parameter, modifies that parameter and returns it, and expects the callers' already existing (after all, we aren't trying anything dynamic here) variable to be modified.
nothing about the language's behavior. I'm talking about the pattern of a thought process that beginners seem to have.
 
@KarlKnechtel problem or "problem"?
 
@Marco nope
 
the conceptual problem for the programmer. Not a quirk of the language.
 
@KarlKnechtel Java doesn't behave like Python?
@JonClements what is occurring, then?
 
9:38 PM
@KarlKnechtel so in C++ that'd be automatically updated references?
 
well, it's not entirely clear in this question what OP's mental model was.
 
eg: everything with the same name exists once so the name a can only exist once and every change made to it is always reflected across every other variable named a kind of thing?
 
Everyone who answered, explained about the need to assign back, but didn't try to examine why OP expected it to work
oh I see what you mean, I think
yeah, this also exemplifies what I mentioned earlier about calling functions
and it's at least conceivable that OP had a mental model that involved pass-by-reference (including for primitives)
but most people, like, don't ever get around to trying to put their mental models into words, let alone communicate them actively
 
yup... I think you're right that it's not the nuances of languages - it's more failure to communicate exactly what their mental model expects to happen
not sure what can be done about that though
don't forget though - there's a fair few questions where the OP isn't even sure what they're trying to do anyway - they're more just mashing the keyboard and trying things hoping it works
 
9:44 PM
 
then you get people just posting something like that and saying "how do I do this?" :p
 
well, yes, but we have separate processes for dealing with that.
 
I did another mentoring session for 2 hours today with a guy that's really trying his best... he sends over what he's trying to learn and what his attempts are, and then we spend time going through it together, so I can find out what his thought processes are and his understanding of it
I know I've mentioned it before here, but it's worth mentioning it again, as I find it's actually a good learning experience for me as well
@KarlKnechtel yeah... I generally hit close immediately followed by delete :p
 
10:05 PM
I feel like stackoverflow.com/questions/32822473 may be the version of the question best suited for making the canonical. Although the wording is awkward and OP didn't mention return anywhere - it's pristine, and simple, and has some good answers, and seems like the most amenable to being given a full reference set of answers
exactly *because * it doesn't try return or globals or anything, and doesn't report any errors. It's pure "how do I access the information", which allows answering with all the ways to get the information.
 
def f(a):
    f.a = a
    return a + 1

x = f(3)
then print(f.a)... that's always "fun"
 
 
1 hour later…
11:31 PM
yep. showing off two things at once, there.
function attributes are actually quite useful; e.g. the functools.wraps decorator uses one to cache the original, in case you need to access it later
pretty sure functools.cache uses them too
 
11:46 PM
yup
Python has dark magic available - but you never really need it
 
on the topic of dark magic, was hoping someone could give me a stern recommendation for an AST library I'm working on
Suppose there are many nodes in the AST. There are a few ways to create a visitor class that allows you to visit those nodes, classic parser stuff. The problem is how clever I want to be:
1. Have some metaclass hook or __init_subclass__ magic to detect the existence of nodes and create those functions dynamically (pro: pretty easy to do, con: IDE's will not find this)
2. Use the same thing above^ to codegen a python file containing the visitor (pro: IDE's will find this, con: autogen code is more work and the build steps will require autogen before packaging)
3. Don't be lazy and specify all of the nodes myself (pro: readable and predictable, con: I am a human, missing nodes to visit is somewhat expected)
I know ANTLR opts for 2), but they also have a full fledged parser grammar, has multiple language targets, and is much greater of an effort than what I'm working on. :shrug:
 
why don't you try all of 'em and see what works best for you?
 
I would ideally like to do that but there's some time constraints - I took some PTO from work to play around with this toy project and PTO is a finite resource :(
the visitor is a means to an end, and I'd like a one-shot recommendation and understand its quirks and unknown tradeoffs later on. If that's significant tech debt I can always come back and redo it in another option
 
sure... how much are you paying for our consultancy charges so you can toy around it? Our free-time is also a resource :p
 
:shrug: i don't know, have a fixed rate you're interested in?
My expectation was that the python SO chat would be people eager to give out advice without some monetary compensation in mind (I've lurked here about 4-5 years ago), but perhaps that prior has become less accurate over time
 

« first day (4279 days earlier)      last day (652 days later) »