« first day (3527 days earlier)      last day (1420 days later) » 

12:00 AM
@Aran-Fey I see this somewhat frequently from users that don't understand SE's markdown and only indent the first n lines until the code block pops up 'right'. But indenting the last lines is a first...
 
@wim While I fully endorse this suggestion, coming up with witty names at 2AM is even harder than thinking about array decay. :/
rbrb
 
@Peilonrayz It's common on SO, sure. But making that mistake in a tutorial is on a whole 'nother level
Guess I'll also go get some sleep. Rbrb
 
12:23 AM
@MisterMiyagi Thanks for explaining def and lambda, these are new for me. I'm looking generally to learn how to leverage spaCy tags for tokenized text that is located in a dataframe. To do that, I'm starting with a simple approach of just filtering out stopwords and putting that into a new column.
 
 
5 hours later…
4:55 AM
Top of the morning cbg!
 
5:52 AM
Can someone please suggest on alternating characters solution if we have N defined int input and we need to alternate '+' and '-' N times? If N = 4, then the output is '+-+-' and if N = 3, the output is '+-+'
 
''.join(islice(cycle('+-'), N))
 
thanks though I'm getting this error "NameError: global name 'cycle' is not defined"
```
from itertools import islice

def solution(N):
k = ''.join(islice(cycle(['+', '-']), N))
print(k)

N = 5
print(solution(N))
```
 
# Another
lambda N: '+-' * (N // 2) + ('+' * (N % 2))
 
thanks, wondering how to incorporate it into the first solution
into a function
 
@Eugene_S Please take a look at the code formatting guide – malformed posts remove indentation, which does not work well for Python code. There's also a sandbox in which you can practice.
 
6:08 AM
@ MisterMiyagi pardon me, is there a way I can modify it at this time?
 
6:39 AM
@Eugene_S no. Messages can only be edited for up to 2 minutes. Also, please note that stars don't work like upvoted on main; they are shown on the main starboard (on the right) to everyone, so we try reserve them for things that are interesting or humorous to all :)
@Eugene_S you also need to import cycle from itertools
 
7:06 AM
@PaulMcG I don't think that sizeof should be there...
 
7:20 AM
I guess it's just for demonstrating the concept. I was taught arrays/pointers improperly, it took me a while to realise that the compiler already knows the offset of elements.
 
arr[i] is literally just *(arr + i) I think
 
yeah, but only because arr is typed.
 
Which is why i[arr] also works
 
that's the stuff I did not get for a while, "why doesn't *(arr + 4) drop me in the middle of some 8-byte number", for example.
 
I see
 
7:26 AM
@AndrasDeak Yup.
 
@AndrasDeak Yes, but the sizeof is still there... It's just there in both. An array is always indexed or a pointer is always incremented by the size of its underlying type.
 
I also haven't quite yet grocked how *(arr + i) works for both pointers and arrays even though arrays are not pointers.
 
arr is the memory address for the first element in the array. Incrementing the memory address of the first element in the array is going to get you to subsequent elements in the array, because items in an array are stored contiguously in memory.
 
@CodyGray No, it is not, in the sense that arr[i] would translate to *(arr + i * sizeof arr[0]). Pointers know the size of their target.
 
@IljaEverilä Right, so the sizeof is there in both array indexing and pointer incrementing.
In other words, both people are right. arr[i] is identical to *(arr + i) as a construct, but interpreted with an implicit sizeof.
 
7:30 AM
In a way, but not literally. The addition on pointers is defined so that it points to the next T, if you add 1.
 
Yeah, you're right, it's defined as part of the semantics.
Unlike assembler, pointers know the size of their underlying type. If you want to increment by 1 byte, you have to cast to a char.
 
Exactly.
 
I've always wanted to cast myself up a car, but that didn't work. :-(
 
@CodyGray Here's the standard text on how the addition is defined: port70.net/~nsz/c/c11/n1570.html#6.5.6p8. It's a bit dense.
The interesting result of that is that subtraction between pointers (to an element in the same array) returns the array subscript difference.
 
Good morning
How can I open an mp3 file with the default application (example: vlc)?
os.startfile(filename) fails
 
7:41 AM
fails how?
 
AttributeError: module 'os' has no attribute 'startfile'
 
are you on Windows?
 
No, that's the reason.
 
@CodyGray But anyway, I suppose I was preaching to the choir a bit? :)
 
7:43 AM
 
@IljaEverilä Right, that's also the big advantage of using zero-based indexing.
 
@Aran-Fey works
works also for windows?
 
no
 
The mp3 is playing and in console:

error: XDG_RUNTIME_DIR not set in the environment.

(totem:55173): Gtk-WARNING **: 10:45:55.315: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node slider owner GtkScale)
I run os.system("xdg-open \""+filename+"\"")
 
7:50 AM
that's normal, gtk always displays a ton of warnings
 
8:01 AM
GTK is shows warnings to I think save you from bugs?
 
Yeah, it is not a vice decision to ignore warnings
 
Sam
8:29 AM
pytest has monkeypatch for mocking module imports and environments... what is the right way to mock out a specific method on a custom class? Is monkeypatching used here or is something else?
class MyCustomClass:
  def __init__(self):
    #...
    pass

  def myCustomMethod(self):
    # do something
    pass


class TestMyClass:

  def test_one(self, monkeypatch):
    monkeypatch.setattr('MyCustomClass.myCustomMethod', someMockMethod)
I don't think something like this would work.
 
monkeypatch.setattr(MyCustomClass, 'myCustomMethod', someMockMethod) should work
 
Sam
Ah OK I'll give that a shot. Although just looking at those signatures I would have thought the two would resolve to the same thing?
 
Um, well, setattr needs 3 arguments to work, so...
 
Sam
I think you can get away with using the full path on the first argument. At least that's what I've observed in my tests
for instance monkeypatch.setattr("my_module.nltk.pos_tag", mock_pos_tagger_object) works for me
 
Curious. I looked at the docs and didn't see any mention of a 2-argument form
 
Sam
8:38 AM
Which I guess is the same as saying monkeypatch.setattr("my_module.nltk", "pos_tag", mock_pos_tagger_object)
@Aran-Fey I guess the latter is a more explicit way of showing the actual method you wanna override, but I would imagine the first operation inside setattr is to bind the two arguments together
 
do yall know the general idea of setting up try-except to handle filenotfound errors?
i have an if-else statement inside a funtion
 
try: ... except FileNotFoundError: ...?
 
9:30 AM
is it possible to edit a text file without adding any library?
 
@aaa28 yes
 
Sam
@Aran-Fey Yup just verified, both implementations will work, with and without the additional arg
 
yes, just open it.
 
how about edit an specific line?
cause I only know of append mode, and it writes a new line at the end of the file
 
you can file.seek to any location in a file.
Note that files do not actually have a native concept of "lines", so "edit a specific line" will need some bookkeeping on your side.
 
9:37 AM
best do readlines followed by writelines instead of even attempting any r+ and seek shenanigans
 
E.g. if the line gets longer/shorter, you have to move the remained of the file accordingly.
I didn't have my morning coffee yet. Might still be stuck in technically correct help mode. :/
 
@aaa28 I bet there are a hundred duplicates for that
 
Do you folks know the feeling when you are absolutely sure that ludicrous-request-by-new-user is not actually what they want to do, but the challenge of finding an accurate answer is tempting?
 
10:33 AM
Only in a malicious way. "ask a dumb question, get a dumb answer" style
 
malicious compliance is best compliance
 
 
1 hour later…
11:46 AM
@AndrasDeak You are right, in actual C code it doesn't.
 
12:37 PM
inexact dupe but close enough stackoverflow.com/questions/62342225/…
 
^ that title is pure gold...
 
Sam
Sounds like some relationship book title
 
Welcome, @Zorglub29 :)
That comment thread was getting a bit noisy (due to me)
 
Cabbage
 
Thanks for the invite! And sorry for the strange title, I had some fun there ^^ :)
 
12:52 PM
It was perfect, no worries :D
 
Should be relatively effective in SEO if someone has the same issue.. squashing, was it? :P
 
Smooshing
 
A posteriori it was of course stupid of me not to be able to debug this by myself, I should have checked the type, getting really lazy working with interpreted languages all the time... That's when I miss a good compiler ^^ But still think that this may confuse quite a large part of the user base.
If this is a known issue, do you think it would be reasonable to issue a warning when calling squeeze on a matrix type for example? :)
 
@Zorglub29 it's a tricky problem, don't beat yourself up over it
@Zorglub29 I'd be surprised if this hadn't been suggested yet, I can try looking around
I agree a no-op-by-design method is pointless if not dangerous. You squeeze for a reason.
 
:)
 
12:56 PM
The main counterargument is probably duck typing still...
 
@Zorglub29 No worries! It's much better to have a title that makes people smile than one that makes them frown.
 
@Zorglub29 hmm, can't find anything relevant-looking at github.com/numpy/numpy/issues?q=is%3Aissue+matrix+squeeze
won't try searching the mailing list from mobile :)
 
hehe no I understand :) I can open an issue there :)
 
wait
It coerces to a row matrix...
So your suggestion won't fly
 
Ok, nice pick :)
 
1:03 PM
Better to just weed out np.matrix from your control.config :/
 
That's annoying. Do you think there is a way to still help the user? Still think maybe a simple warning (example: "you are using squeeze on a matrix, this may produce unexpected results, for more information see [LINK_TO_DOC]") could help, what do you think?
Yes, maybe the best, I agree. At the same time it is true that the output should always be 2D. The problem is also that a np.array * np.matrix remains a np.matrix, this is maybe a bad idea. I means for many users, 2D matrix * 1D vector = 1D vector (or the transposition of all of this) is the expected behavior, right? :)
 
If you intend the method to be called, throwing warnings is not OK
 
I was just going to say, it sounds like that would become the equivalent of Pandas' SettingWithCopyWarning which drives me nuts
 
Ok, what do you mean? :) That it pollutes the terminal output?
 
@Zorglub29 only if you don't know that subclasses are sticky ;) You wouldn't want your subclass to just disappear because you multiplied it by a parent instance, right?
@Zorglub29 yeah, annoys the user during valid use.
 
1:08 PM
Mmh, I see.
Ok. But the thing is, the valid use for squeeze on matrix is very thin / unlikely, don t you think? :)
 
But you'd anticipate that the script will be run more than once, no? In which case, you'll get it on each run
 
@Zorglub29 Someone bothered to implement it, so no. You can still raise an issue, no harm in that :) Just manage your expectations.
 
Ok, sounds good :)
 
The good solution would be to scrap the matrix class
 
What about displaying the warning only if the matrix actually has a dimension singleton?
 
1:13 PM
That has different semantics. That could apply to ndarray as well.
Calling squeeze on your matrix is not misleading because of the shape, but because of the type
Arguably users should know their types ;) Unless libraries play tricks.
 
hehe ^^ :)
Will open an issue anyways and see what folk there think.
 
if there's any conclusion I'd be interested to know
 
Thanks
 
1:29 PM
Ah, yes, there's already a warning, but that doesn't show by default. I mentioned that in my answer I plugged in your question
 
cbg
 
cbg
 
cbg
 
1:46 PM
seems the employees are starting that community-a-thon thing on Tuesday
my predictions are not good for this event but then I'm a Murphy's Law kinda guy ;)
 
2:16 PM
Grr, 30 minutes now trying to find a repo I found by accident yesterday that fixed my issue. Time for some Stevie Wonder to try summon yester-me.
 
2:29 PM
Hey guys, I got a question about character encoding. I got the following string

string = u'T\xe5get \xf6ver B\xe4lt (fragment)'
If I print it, it becomes more readable: Tåget över Bält (fragment)

I'm not sure how to formulate my question but, how can I store 'Tåget över Bält (fragment)' in a variable?
`
 
2:40 PM
^ the way you just did? Python handles unicode just fine
 
Okay, let me be a little more specific. I need to use the string to create a url
from which I want to get the html page using beautifullsoup. But if I make the link the characters \xe and such get put into the link, which breaks the query
Is there a way to encode it for urls?
 
beautifulsoup has a .encode('utf-8') function (and decode)
 
I'll go try that
THanks
 
If you mean an actual URL you'll have to do some work yourself though (you have to use percent encoding per the RFC (you cannot have raw unicode in urls) but HTML5 complient apps tend to perform that translation automatically (so you can - in a sense)
@MitchellvanZuylen If you mean you needed to make an IRI into a URL then use urllib with url = urllib.quote(url.encode('utf8'), ':/')
 
2:57 PM
':/'
 
@roganjosh thanks, that looks really elegant and works fine
 
Well, it was really Ilja Everilä who answered for you, I just told you where the missing import comes from :)
 
3:21 PM
@AndrasDeak I don't know why I picked that.....because I usually have to build the URL piecemeal (cause '?' will get encoded too) and combine for actual use with soup, I guess
yes, I realize that will encode the same (no percent encoding needed)
 
3:45 PM
thanks to @IljaEverilä and you as well anyways :)
 
heh, my wife is mad at me that I'm working on stuff for my classes next year (not under contract until August - no summer this year)
 
4:47 PM
Do you think users who post questions with triple quotes are aware that their code haven't been formatted at all?
 
depends, if your not used to markdown (or just html/xml) it can be hard to get used to right away (also even if they realize it - they don't always know how to fix it)
The wizard isn't exactly that clear (doesn't even meantion code til step 3 - I agree with that but I mean - always include code should be the default message):
 
@LinkBerest yeah, he doesn't specify what kind of swallow he's asking about
 
@AndrasDeak ?
 
Then when you try to input code - the "code" button just hints at how to do it and the bracket (which adds the correct tags) is kinda hidden at the top (circled in blue)
 
@AnnZen I've edited the message to clarify
 
4:58 PM
Monty Python quote 'cause Python room - from FAQ
 
I just saw an answer that goes like this: `x = input("Enter a expression\n")
print(eval(x))`
 
Let me guess - they are writing a calculator program
 
yep
 
@LinkBerest python 2 link? Tsk-tsk :P
 
yeah, cause its historic (honestly I was looking for the Python 1 link)
 
5:01 PM
but it works with 3 too... (I checked)
 
Right above that answer is another answer:
s = "5 + 6 - 7"
print(eval(s))
 
@AndrasDeak when looking for historical reasoning the older document is usually the best choice - I stand by my choice ;)
 
I accept your rationalization thoughtful reasoning :P
 
also - I have not clicked on "ask a question" since the new wizard - that is hard to use
 
you can opt out I think
 
5:04 PM
When I just started programming, I used python 2, and was so confused as to why tutorials can use input() while if I use it, strange things happen.
 
If I ask a question it would be a failure on my part (typically...at least on SO) so I don't care for myself just saying I didn't realize quite how it had changed
 
yeah, it was a big deal
 
isn't ned the one who wrote the dangers of eval - I usually just link that in a comment (yes, yes it was him)
 
Why I started writing plusminus but it has gone a bit beyond just a safe eval now.
 
granted you then get the comments "eval is perfectly safe for trusted-input" which makes me laugh and sad at the same time
 
5:12 PM
How can I write an iterator for this generator? https://termbin.com/2va9
Strange thing is, the iterator should get the yielded variable, then "send back" some data to the generator then generator should replace this value as its original yielded value
 
wim
I've been busy thinking about a name for lambda x: foo(x)
if the cat file + pipe is called "cat abuse" then maybe the extra stack frame could be called "lamb abuse"
 
Department of Redundancy Department
 
@Zeta.Investigator That sounds more like recursion (actually it almost sounds like currying) - are you sure you want a generator for this?
 
@LinkBerest it's from a finished contest
I want to know how to do it.yes via generators
def guess_generator_iterator is mine which is wrong
i'm not sure whether I should use send. this was suppoded to be the 3rd hardest out of 5
 
Yes you should use send its using a yield expression within the generator function
This answer has an example of a changable_count generator which might be easier to understand (as it shows how send is used)
 
wim
5:41 PM
@LinkBerest why laugh? it's true, no?
@AnnZen in good company stackoverflow.com/…
heh, one of the results is @Kevin
 
@LinkBerest thanks
 
@wim its true for definitions of "trusted input" (which is something which is fun to explain to junior devs after a server crash from some trusted input that suffered from injection) :)
 
6:01 PM
stackoverflow.com/q/62333411/4799172 needs more detail/needs debugging detail (forgot the latter existed in my previous cv-pls)
 
cv-pls made me think of sil-vous-plait
 
Pretty much :) It's our tag for calling for things to be closed
Ooo, that needs editing to be in-line with the permanent 3-vote-requirement
Both closed, thanks
 
6:50 PM
Late to the party but since there are some Flask users in the room, I've just noticed FlaskCon
 
 
1 hour later…
8:06 PM
Hello!
What's up?
 
Does anyone know a good, official documentation of Python's indentation rule? I've just sent a poor soul to the lexical analysis.
 
@MisterMiyagi do you expect multiple places of official documentation?
 
does anyone have any idea how to use qtermwidget/qtermwidget5-data in python3.8 (pyqt5) I am lost and documentation is scarce
 
@MisterMiyagi What exactly do you mean by "rule" here?
 
8:21 PM
*rules. Sorry for the typo.
 
As I read your question, I think you're just referring to PEP8, and you could use tensorflow as an example that throws that "rule" out of the window. Or, you're talking about something that's probably out of my depth
 
Basically anything that says "blocks must be indented, yo! for, while, ... must be followed by blocks, yeah!". Give or take valley speak.
 
He's talking about the not-so-trivial rules that determine how indentation levels are parsed
or so one might think :P
 
:P
 
3.1M	just_things.tar.gz
216K	just_things.tar.xz
wow, why didn't anyone tell me that ^ sooner
 
8:29 PM
"since the LZMA format is now legacy, XZ Utils compresses by default to xz" someone forgot sending a memo, it seems.
 
@MisterMiyagi I'm really curious about what you're trying to settle here. Either the OP accepts that this is intrinsic to Python, or they'd be interested in the link you gave. It seems an odd case where you'd need to prove that indentation is important - have they argued back against something you've said?
 
@MisterMiyagi hmm? Does that relate to gzip?
 
@roganjosh It was a recent Q where the OP posted code without any indentation, and their confused question about receiving IndentationError: expected an indented block leads me to believe they have indeed no clue that Python needs indentation.
While the lexical analysis section is technically correct, it seems to be only totally-unhelpfully-parser-gibberish'ly correct.
 
In that case, I don't think there's anything official to back it up that would make sense to them
 
@AndrasDeak it relates to the utility formerly known as LZMA utility, which my ageing brain actually knew about.
 
8:35 PM
Did that also create .xz by default?
Or was your message mostly unrelated to mine?
 
@AndrasDeak they created .lzma, which are now superseded by .xz, which are kinda-similarly but Wikipedia refuses to tell how.
I still have fond memory of wasting improving some student's life by investigating the effect of using LZMA compression instead of GIZP (or similar, my memory is clouded, here) in our file format.
 
Hello :)
 
Hello
 
@ILoveStackoverflow Hello
 
8:46 PM
@roganjosh That is unfortunate. Puts another dent on my track record for trying to help even the most losted'ly of lost people.
Quicker, easier, more seductive mindless downvoting is, indeed.
 
@MisterMiyagi I mean, I'm not an authority here, but I'll perform some Ceremony of Absolution if it makes you feel better?
 
@MisterMiyagi go with the times. Mindful downvoting!
@ILoveStackoverflow please don't bring problems here that have nothing to do with python, as per our rules
 
Ok sorry :)
 
In a for loop i have Buttons.
When i pass iteration number as argument in commad function i can't.
Because it's passing the last iteration number every time.
 
8:52 PM
Any help?
 
2 messages moved from Python Ouroboros - The Rotating Knives
@ChrisP google for "python lambda late binding" (and read relevant-looking search results)
it's not specific to lambdas but that's where this behaviour usually arises
 
Thanks!
 
@ChrisP We don't need that, you need that.
 
9:28 PM
@MisterMiyagi I've re-read my response to your comment and I think it comes across as too flippant, despite me assuming you know my intent to be light-hearted. I've seen a lot of comments from you on questions and the dialogue ends constructively with an answer. Anecdotally, I'm trying to get alembic to work with flask without flask-migrate and it took over an hour before I switched to "I should actually understand this". All of us can become too accustomed to answers already existing
So, leaving naive questions might prompt people to not try take the easy route
 
user13640482
10:03 PM
I have had a problem with tensorflow for 2 weeks. I really need help.
 
user13640482
If you can help me break the deadlock it would be nice
 
@LucySmith that is not 2 weeks old, that's 8 hours old. We ask that you don't ask for help here with fresh questions on the main site. And please don't post text as images in your questions.
I understand that you're stuck but you should let people on the main site answer first.
 
The answer to that question is almost always "no"
this is probably a partial homework dump
 
11:11 PM
Good night.
Have a nice day in America.
(Greek time: 02:11)
 

« first day (3527 days earlier)      last day (1420 days later) »