« first day (2385 days earlier)      last day (2553 days later) » 
01:00 - 16:0016:00 - 00:00

1:05 AM
Nevermind, I misread your question. Fortunately the kind free code writers didn't disappoint. — Andras Deak 46 mins ago
@AndrasDeak It's alright. I appreciate though you showing me the tolist function since I've never seen it before — Brenton 14 mins ago
fortunately my snark is lost on OP
 
user7102066
1:26 AM
I'm facing a strange problem,
 
user7102066
 
user7102066
the score function wont print
 
user7102066
my interpreter prints fine
 
user7102066
as a code by itself
 
user7102066
but when i run the full code, it wont print and crashes
 
user7102066
1:27 AM
Traceback (most recent call last):
  File "tictac2.py", line 226, in <module>
    p_vs_p(board,board_m,p1,p2,pp1,pp2,first,second,x,chosen)
  File "tictac2.py", line 205, in p_vs_p
    game(board,board_m,p1,p2,pp1,pp2,first,second,x,chosen)
  File "tictac2.py", line 146, in game
    player1(chosen,board_m,board,l,ll)
  File "tictac2.py", line 55, in player1
    score(l,ll)
  File "tictac2.py", line 121, in score
    print(chosen[0][0])
IndexError: string index out of range
 
l,ll,1...do you hate yourself this much?
 
user7102066
why do you say that?
 
wait, what's even going on there?
are you really asking your users to enter a score?
 
user7102066
whaaa...
 
I don't get it
something seems way off
 
user7102066
1:29 AM
its supposed to show the score on top of the tictactoe table
 
user7102066
and when the games is over, it will add 1 to the score board
 
def score(l,ll):
    print(l,ll)
    input('score')
    input('1')
    print('-------------------------')
    input(2)
    print('\n'+chosen[0][0]+': %s' %(0))
 
user7102066
oooooooooooh
 
user7102066
no
 
user7102066
so in order to see where the code crashes exactly, i place input(1) , 2 , 3 , and on
 
user7102066
1:30 AM
and when the code crashes I know which line its not passing through
 
>

Traceback (most recent call last):
File "tictac2.py", line 226, in <module>
p_vs_p(board,board_m,p1,p2,pp1,pp2,first,second,x,chosen)
File "tictac2.py", line 205, in p_vs_p
game(board,board_m,p1,p2,pp1,pp2,first,second,x,chosen)
File "tictac2.py", line 146, in game
player1(chosen,board_m,board,l,ll)
File "tictac2.py", line 55, in player1
score(l,ll)
File "tictac2.py", line 121, in score
print(chosen[0][0])
IndexError: string index out of range
it tells you right there which line's not passing
and calling your two input parameters "l" and "ll" is just asking for trouble
 
user7102066
I was just trying to get to the bottom of the problem, but I cant find it
 
user7102066
sometimes it tels you the problem while the problem being something else, you know...
 
The error is on line 121 in score(), because chosen[0] is probably an empty string. The function is called from player1(), line 55. Which is called in game(), line 146
@KOOLz sometimes you need to read and understand the traceback and the error message
 
user7102066
chosen is not empty.
 
user7102066
1:37 AM
I can print it just fine before the game starts
 
you should "print it just fine" right before line 121 in score()
because that's where the error happens
it's half past 3 and I'm impatient, so good luck
 
user7102066
woa
 
user7102066
where are you located?
 
Hungary
 
user7102066
wow
 
user7102066
1:39 AM
okay, well thank you very much
 
user7102066
hope everything goes well for you
 
thanks
 
 
5 hours later…
6:47 AM
morning cbg
 
7:40 AM
cbg-ning folks
 
8:02 AM
2
A: No Multiline Lambda in Python: Why not?

Samy BencherifA workaround to get multiline lambda functions (an extension to skriticos's answer): (lambda n: (exec('global x; x=4; x=x+n'), x-2)[-1])(0) What it does: Python simplifies (executes) every component of a tuple before reading the delimiters. e.g., lambda x: (functionA(), functionB(), function...

what a "workaround"
 
 
1 hour later…
9:09 AM
cbg
 
9:57 AM
This would make stackoverflow much less helpful for everyone still using Python 2. I know some think everyone should be using P3, but if people regularly did what you are suggesting it would be the opposite of helpful, not just to the original post (assuming it was a P2 question), but to people who come here for simple readable, pythonic code. Downvoted b/c of this. Also, people who code in P3 can typically translate really good answers from P2 to P3. If not, just write a new answer. I beg Python 3 crusaders: don't wreck beautiful answers!neuronet 2 days ago
pfft
 
10:24 AM
Cabbage, pythonauts.
 
@AnttiHaapala the bold point makes sense
 
10:46 AM
Cabbage
 
10:57 AM
@khajvah if the answer uses print statement, it is wrecked already.
anyone writing Python 2 should be fine with using print_function :D
 
@AnttiHaapala Like it or not, people will continue to run, write, and modify Python 2 code after 2020. I certainly agree that Python 2 Q&A pages should be updated, but I'm not comfortable with people changing existing Python 2 code. Either write a separate Python 3 answer, or add relevant Python 3 info to the end of the Python 2 answer.
 
if the question is about python and the answer is about python without any statement on whether it is 2 or 3, then I disagree with not editing it to be 2-3 compatible.
like an answer using .next() instead of next(...)
 
I think there's a vast difference between editing for compatibility and breaking the code in Py 2 by writing it in Py 3. I'm guessing no-one's suggesting the latter.
"vast different"? I've been away too long...
 
vast different... now imagine what would have happened if you had moved to Finland...
the argument there is that "since there are marginally more Python 2 users than python 3 users, then everything should primarily be answered in Python 2..."
in now everyone, including me is always using the C11 standard for answering all C questions.
 
11:13 AM
@AnttiHaapala I imagine my grammatical errors would have been less significant than my inability to pronounce any words :) I would have probably wandered around accidentally insulting people and appearing to be a radical absurdist.
@AnttiHaapala Which, I agree, is an entirely flawed argument.
 
because frankly the Python 2 users should be made aware of the changes needed for their code, but not the opposite... Python 3 users need not learn Python 2.
 
I still say that we should leave the existing code alone. Unless it's bad code that has somehow got a high score. But for existing good answers I think we should add new code blocks with updated code and leave the existing code alone.
Sure, it's often possible to make minor changes to code to allow it to function correctly on Py2 or Py3, but in many cases such code is not a good compromise: it runs slower on Py2 (or uses more RAM) and it doesn't take full advantage of Py3 features. But I guess in those situations we can add a Py2/3 compatible version and a pure Py3 version.
 
and stuff like print x vs print(x) both of which work in any python...
though the code in that meta-q was bad
 
11:39 AM
Hi All,
 
@AnttiHaapala I guess the OP just wanted something simple to illustrate the point. OTOH, that raises an important point. There's a lot of old Py2 code that works, and has good scores, even though it uses inefficient techniques. And if we're going to update such answers we really should improve it when we can, rather than just translate crappy code into a crappy Py3 equivalent.
 
in that case there should be a separate answer.
what I mean is that if there is a question with 50 upvoted answers and 51st one (the one that has 0 score) then works with Python 3 as is, that's not good either.
 
On a related note, I saw a Py2 answer to a new Numpy question last night. Someone commented on the answer that the OP's probably using Py3, so the author added a Py3 version which simply wrapped his map call with list. However, the Py3 version crashes with a TypeError; I guess there's also been a change on the Numpy side.
@AnttiHaapala Agreed. I guess we can add a link in the high scoring answer pointing to the Py3 answer.
The other night I was talking about motivating people to do this Py3 update stuff. Modifying existing high scoring answers makes the update visible, but it doesn't earn you any rep. And it may annoy the original author if they're still active. OTOH, if you write the 51st answer it may not receive any upvotes anyway unless it gets some "assistance".
 
11:54 AM
@PM2Ring I am always ready for some "assistance" :D
18
A: What is the most efficient string concatenation method in python?

Antti HaapalaPython 3.6 changed strings that have known components with Literal String Interpolation. Given the test case from mkoistinen's answer, having strings domain = 'some_really_long_example.com' lang = 'en' path = 'some/really/long/path/' The contenders are f'http://{domain}/{lang}/{path}' - 0....

 
cbg. I give to you incredible news
 
mine there has 18 upvotes already
 
WAT :D
@idjaw :b.......
I guess he doesn't care about kashrut
ah Goldblum follows "Eastern religions".[6] :D
I guess he plays himself in the ID4 :d
@idjaw jurassic park 5, he's now selling the dinosaur sausage
 
12:27 PM
cbg
 
can you tell which branch you are currently "branched off of" in git?
 
@idjaw Jeffrey???
 
@corvid is this you in the winter?
 
12:42 PM
frolicking hard
 
then gotta go to the vending machine after
 
I didn't know crows were smart
(no offense)
 
I'm not a very good indication of that
 
should have watched the youtube tutorial of vending machine earlier
 
I just asked the javascript room how to get the pinenuts out of the machine with shinys on it, they explained
 
12:48 PM
crows are very smart
 
@corvid by using JQuery?
 
they told me I should upgrade my build system, then twenty minutes later, told me a new build system has been released that's better
 
:D
 
Do crows have a moral framework compatible with human values? They can use metal hooks to extract treats from tubes, but will they do so if it's clearly indicated that the hook and treat and tube are my private property?
Basically I'm concerned that our crow overlords will not be just and merciful.
 
don't be silly, all crows are communist and do not subscribe to bourgeoisie ideas of property
 
12:51 PM
Guess I'm going to uplift octopi instead, then.
 
can crows be pets?
 
dunno
these are amazing even if the test subjects have some experience with the test
 
anything can be a pet if your will is strong enough
4
 
Anything is a pet if you're brave enough
10
 
lol
 
12:54 PM
Heh, Nice timing!
 
I am thinking of crows or pigs to cover up some murders
 
It's not often I'd link a drum solo, but the technique and feel on display here are phenomenal imho youtube.com/watch?v=Zir5rKm7AFY
 
if you have multiple crows, that doesn't cover up a murder, that makes a murder
 
@AndrasDeak I don't think many humans would be able to think that hack
 
Cabbage
 
12:56 PM
Cabbage @poke
 
Re-cbg all
 
Wow, all the awaypeople are here! Well, some of them:P
cbg @poke @JRichardSnape
are you all well?
 
Awaypeople?
 
who I rarely see:(
 
The awaypeople. They have lived in underground tunnels for thousands of years, biding their time before returning to the surface to claim what is rightfully theirs.
 
12:58 PM
Very well ta
 
you did post here 2 days ago, guess I missed that :D
@JRichardSnape awesome:)
 
so I have to make a decision
quit my job, fix my grades to be able to get into a masters program
or continue making money
 
making money
 
with shitty grades
 
cabbage all
 
1:04 PM
cbg
 
morning davidism
 
cbg
 
I'm trying to change my default program for .py files. Right now, it opens them with my 2.7 interpreter. I tried changing the default program by right clicking a .py file, choosing "open with -> Choose another app". I click "look for another app on this PC". I navigate to C:\Programming\Python 3.5 and choose python.exe. My program executes, but still under 2.7.
I know this is the case because the .py file's contents are import sys \n print(sys.version) \n input(), and it outputs 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)]
I'm sure that the python.exe sitting in the Python 3.5 directory is not a 2.7 interpreter. I double-clicked it and the REPL that appeared had a header Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
 
@khajvah are you sure you will be able to fix your grades? If you are slightly shaky, I wouldn't do it. Also, do you really feel better grades will get you a better job (if that's what you are looking for)? If so, then how good do they need to be? And how will you ensure you get them? Continue making money is not a great idea because it doesn't pay well in the long game,
IMO, but it really depends on your current level of expertise and if you are picking up along the way (I think I am doing exactly that, so I am not diving into a full time course just yet)?
I hope those are some good questions for you.
Not to mention, you have the answers, we can only give you somewhat good questions (if not the right ones) :-p
 
If I manually invoke c:\Programming\Python 3.5>python.exe c:\Users\Kevin\Desktop\test.py from the command line, it shows 3.5.1.
 
1:13 PM
@Kevin digitalcitizen.life/how-associate-file-type-or-protocol-program maybe? I am impressed by anyone who develops in Windows and doesn't have a weekly "I threw the machine out the window in blind rage" budget, tbh.
 
I sublimate the majority of my anger into despair.
 
@AshishNitinPatil dunno. I want to do smart stuff in future
like Math and shit
 
I went down the "intelligent crow" youtube rabbit hole. Don't come to rescue me, I'm happy here.
 
@AndrasDeak find corid
 
@khajvah And if you feel you need far more education for that, I would suggest you go for it as soon as possible (if you've got the finances somewhat right).
 
1:16 PM
@ZeroPiraeus I'm on Windows 10 so the steps don't translate perfectly. But I did find the default associations menu. I used it to set .py's association to Python 3.x. It didn't work.
 
@AshishNitinPatil to be honest, I am still waiting for that genius idea of a stupid app like snapchat that will get me rich
 
haha, aren't we all...
 
anyone here decent at matplotlib figure canvas?
 
"figure canvas"?
 
yeah when you plot something in matplotlib and display it to a gui
 
1:17 PM
Everybody on the "3.X is the One True Version" wagon should be rushing to solve my problem right now because if this doesn't work I'm not going to try upgrading again until I get a new computer five years from now ;-)
 
2.7 is the One True Version
just sayin
 
5 years is a little late for a new pc
 
Sorry, the "use linux" bandwagon comes first
 
@aramova wait for Antti
 
@JRichardSnape Sam's a lucky girl to have Ray as her drummer.
 
1:19 PM
No takers? All right, we'll reconvene in 2022.
 
@AndrasDeak ninjaed
 
I want to display some code and see if you guys can tell my why I'm being an idiot? I'm learning python, trying to become a productive member of stack overflow
 
"productive member of stack overflow"
 
lol
 
@Kevin python.org/dev/peps/pep-0397 seems to suggest a #!/usr/bin/python3 shebang will be respected, based on a 20 second instascan.
 
1:20 PM
there is the first problem
 
@Kevin have you tried turning it off and on again?
 
import sys
import os
from PyQt4 import QtGui
from PyQt4 import QtCore
import functools
import numpy as np
import random as rd
matplotlib.use("Qt4Agg")
from matplotlib.animation import TimedAnimation
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import serial


class CustomMainWindow(QtGui.QMainWindow):
def __init__(self):
super(CustomMainWindow, self).__init__()

# Define the geometry of the main window
 
@J.Stahl use dpaste or whatever
 
I have a standalone program that works great, but when I try and put it in a gui, it goes to hell
 
#!/usr/bin/python3 didn't work. But even if it had, odds are approximately zero that I would remember to put it in 100% of my scripts for the rest of time
 
1:23 PM
\o cbg
 
cbg
 
I now officially give up.
 
> Two .ini files will be searched by the launcher - ``py.ini`` in the
current user's "application data" directory (i.e. the directory returned
by calling the Windows function SHGetFolderPath with CSIDL_LOCAL_APPDATA,
%USERPROFILE%\AppData\Local on Vista+,
%USERPROFILE%\Local Settings\Application Data on XP)
and ``py.ini`` in the same directory as the launcher. The same .ini
files are used for both the 'console' version of the launcher (i.e.
py.exe) and for the 'windows' version (i.e. pyw.exe)
> For example, if an INI file has the contents:

[commands]
vpython=c:\bin\vpython.exe -foo

Then a shebang line of '#! vpython' in a script named 'doit.py' will
result in the launcher using the command-line 'c:\bin\vpython.exe -foo
doit.py'
 
Hey guys, any way to get self from a method reference of an already instantiated class?
 
@kevin is the last version of Python you installed 3.5?
 
1:27 PM
I tried ref.__class__, but that seems to get the reference to the class, not the instantiated object.
 
There's stuff about environment variables in the PEP too, but my eyes kinda glazed over by now.
 
@MooingRawr Yeah probably
 
did you install it through window's launcher?
 
The gist seems to be that there's a launcher installed with every version of Python which decides what actual executable to run, and has configuration options.
 
Let's see, I'm looking in the local settings directory...
c:\Users\Kevin\Local Settings>dir
 Volume in drive C is OS
 Volume Serial Number is 6E1D-CD3F

 Directory of c:\Users\Kevin\Local Settings

File Not Found
That's a new one.
 
1:29 PM
I remember reading something about making a py.ini file in C:\windows\ with the content:
[defaults]
python=3
 
I'll make a note to look for that in five years.
 
and you can always fall back on Windows launcher : python.org/dev/peps/pep-0397
 
That's a lot of text but if it's saying "you can just do py -3 test.py", I already know
 
Anyone have any ideas? I'm trying to get the class instance from a method reference.
 
@neet_jn do you have an example on what you are trying to do
 
1:35 PM
from unittest import TestCase

def runner(func, runs=5):
    for i in range(runs):
        setattr(func.__class__, '%s_%s' % (func.__name__, i), classmethod(func))

class Foo(TestCase):

    @runner
    def test_bar(self):
        print 'test invoked'

    def tearDown(self):
        print 'Teardown Invoked'
 
Sounds like he wants
class Widget:
    def foo(self):
        pass

x = Widget()
y = x.foo
z = #do something with y and not x here
assert x is z
Or, maybe not.
 
Trying to make my test run multiple times, at runtime.
So I'm propogating functions dynamically with the runner decorator.
 
To answer the question I think you're asking,
>>> class Widget:
...     def foo(self):
...         pass
...
>>> x = Widget()
>>> y = x.foo
>>> z = y.__self__
>>> assert x is z
>>>
 
user7102066
Hello everyone, soo...! Thanks to you guys I finished the TicTacToe game I was working on, If anyone feels like breaking the code: dpaste.de/1G3W :D feel free to do so, would make me very happy
 
@Kevin does __self__ work in 2.7? Or is that exclusive to 3?
 
1:41 PM
@neet_jn Yes, it does.
 
The documentation seems to indicate that __self__ is available in 2.6 and up.
 
I just tested it in 2.6.6
 
@KOOLz That looks a lot nicer than before, congrats :-) The thing that pops out is that you're creating a lot of variables in your reset() function for other parts of the code to use; that looks like a good opportunity to look into classes as a way of organizing state.
 
You're example works perfectly, and ideally is what I need. When replacing func.__class__ with func.__self__ in my example above, I receive the error AttributeError: 'function' object has no attribute '__self__'.
 
@KOOLz You've got some unnecessary parameters in the game function. It never uses p1, p2, pp1, pp2, first, or second, so you may as well not have them as arguments.
@neet_jn Well I'd expect func to be an unbound method, not a bound one.
I don't entirely understand why it's giving you an attributeError instead of just evaluating to None, though
 
1:49 PM
boom our redises got rekt
 
@neet_jn I don't think your definition of runner is right. Decorators are supposed to return a callable object, but your decorator doesn't return anything.
 
user7102066
@ZeroPiraeus I will look into classes right away. @Kevin you are right, did not realize at all, fixed it ! Thank you guys! :D
 
Would it make more sense to return the original method and setattr for range run_times-1?
 
If runner had a nested internal function like decorators usually have, I think you could access self from within that function quite easily
Example:
def doubled(func):
    def f_(self, *args, **kargs):
        print("Got reference to thing: {}".format(self))
        return func(self, *args, **kargs) * 2
    return f_

class Widget:
    @doubled
    def foo(self):
        return 23

x = Widget()
print(x.foo())
Result:
Got reference to thing: <__main__.Widget instance at 0x0304BDC8>
46
Here we see that the doubled decorator has a reference to the x object.
But only within the context of f_, because when doubled itself executes, x does not yet exist.
Looking at your code again, I'm not certain that you actually should be using a decorator at all.
Is there anything stopping you from doing this?
class Widget:
    def tearDown(self):
        print 'Teardown Invoked'

for i in range(5):
    def f(self):
        print 'test invoked'
    setattr(Widget, "test_bar_{}".format(i), f)

x = Widget()
x.test_bar_2()
I don't know anything about the TestCase class so I can't be sure that it's not doing something goofy during __new__ that requires dynamically-created methods to exist as early as possible, or what
That would at least partially explain why you're using a decorator, since it executes in the middle of the definition of the class, which is as early as you can get
It may be worthwhile to re-examine whether it's a good idea to have dynamically created functions at all.
There are valid use-cases, perhaps, but you've got to be sure that yours is one of them
 
2:06 PM
@Kevin thanks a boatload for all the info! I'll definitely revise my original plan. Learned a lot in our small exchange.
 
"I want to have five tests that are all identical except for a small bit of data which varies between them, and I don't want to cram them all into one test because then I lose granularity of reporting when only one of them fails" is perhaps a valid use case. But for small values of five, maybe just write them all manually.
 
cbg
 
2:21 PM
\o cbg bud
 
how do you start a conversation with just one person?
 
why do I have so many movies on my computer?
 
By talking to yourself, it's pretty easy
How are you, @Kevin?
 
@J.Stahl click on the user, invite them to a chatroom but you are already in several of them o.o
@KevinMGranger why didn't you put it on the same line :(
 
@KevinMGranger I'm in superposition until I can figure out whether I'm going to this meeting or not.
 
2:23 PM
According to my poor understanding of quantum physics, wouldn't that mean you're both in the meeting and not in the meeting? So you could be physically present, but not mentally present?
I guess that's just how most meetings are
 
I have a question I want to answer, but I'm not sure if my answer would be good enough. Plus there's a 3 upvoted comment that basically answers the question. But my answer is longer and basically an example to help OP understand it :\ don't know if i should post.
 
There's an outdoors grilling event at work today from 11 to 1. The meeting starts at 11:20 and continues indefinitely. If my boss' boss' boss is feeling argumentative today, I won't get to eat any hot dogs.
 
hot dogs are delicious
well, delicious hot dogs are delicous
there are definitely some hot dogs that are better used as fuel
 
Every manager in this company subsists entirely on coffee and forgets that mortals need to eat, I swear to G
 
@WayneWerner Is that a written rule to pizza too ?
 
2:26 PM
grilled kebabs > hot dogs
 
@MooingRawr Post it, and worst case you get downvoted into oblivion and you delete the answer
@MooingRawr absolutely
 
@WayneWerner I was thinking about that, but I'm also thinking if this answer was just me rambling on and on :D
@WayneWerner 'I reject your reality and substitute my own', delicious pizza is delicious, bad pizza is still delicious :)
 
@MooingRawr I personally have no problem with making an answer that does nothing but reiterate what's already in a comment. I usually don't get many points for it, though.
 
@MooingRawr I have some pizza that would put that to the test ;)
 
It's the commenter that is in the wrong. Comments are not for answers. Answers are for answers.
Anyway nobody has ever said "you just repeated what the comment said you filthy plagiarist" so I wouldn't worry about being villified
 
2:29 PM
@Kevin comments are for quick answers or answers that the answeree isn't sure about
 
Disagree and agree, respectively
I don't appreciate the unanswered questions queue being clogged up with questions that actually have answers by people who couldn't figure out which box to use
 
user7102066
How can I upload my TicTacToe game online so others could play it?
 
What is it? A python program? Just put it on gitlab / github
 
Ah, the ceremonial Dissapointment of the Neophyte when he learns how difficult it is to get your python program to work on other people's machines when they don't have Python installed.
 
user7102066
@KevinMGranger people who do not have any terminal experience would not know how to download and play it
 
2:37 PM
What's that one online IDE/REPL that has the code on the left and the interactive prompt on the right? That's probably the easiest solution here
 
I think there's some tool out there that turns python projects into a single bundled exe, but I'm not on windows so I've never used it. I also don't know of alternatives to it for Max and Linux.
 
Ah, I was thinking of repl.it/languages/python3
 
user7102066
 
user7102066
Yes! :D
 
user7102066
Thank you
 
2:43 PM
Should be serviceable for simple console projects that don't have any fancy dependencies. Once you start writing GUIs and/or start needing numpy/pandas/matplotlib, you'll need a more formal distribution plan.
Oh, repl.it has numpy installed. Rad.
 
repl has a lot of library installed including pil, but it doesn't show GUI or anything...
 
I was about to say "ok, so it's serviceable for console projects that only exist in one file" but I see it has support for multiple files. So I guess I'll go with "it's serviceable for console projects".
 
2:56 PM
It must be decorator season I've just answered 2 decorator questions: stackoverflow.com/questions/43659549/… and stackoverflow.com/questions/43653500/… But the one I did a couple of weeks ago about decorating recursive functions was trickier stackoverflow.com/questions/43432956/…
 
Oof, only decorating the top level of a recursive function is a can of worms.
Especially if the person is using the def main(): ... if input("Try again?") == "y": main() antipattern
 
Is worm-canning the opposite of yak-shaving?
 
@Kevin Indeed. It kept me busy for far longer than I expected. :)
 
Tkinter grievance #6. Widgets that primarily contain text, such as Text and Button, use a "character unit" for specifying width and height. You can't directly use pixel widths and heights.
 
I guess I should have hammered the one about decorating a method with a decorator function defined inside the class, but the proposed dupe only mentions it as a possibility and doesn't have any code demonstrating it, it mostly says that it's a silly idea and the decorating function should be placed in the module scope, not inside the class.
I did a quick search through linked and similar questions, but they didn't have good examples either, although I did find a couple that do crazy things to make @staticmethod work.
 
3:06 PM
It's reasonable to support character unit dimensions, but it's unreasonable to support it to the exclusion of all other possible units of measure
There is rately ever a time when you need to do this. Do you have some sort of unique constraint, or do you just not understand how to create well behaved layouts? — Bryan Oakley Feb 15 '13 at 19:04
Or perhaps he just wants the question answered. — rhody May 19 '15 at 23:27
Powerful sass is at work here.
 
Drop by the Python chat room if you want to discuss questions like this. Making decisions about duplicates is one of the things we're happy to help with. — davidism 2 mins ago
There was a meta question about a choice between two Python dupes, if anyone wants to take a look.
 
UI chat. Is it truly bad design to want a button that's exactly 256 pixels wide, as Bryan Oakley implies?
 
you've doomed us all davidism /s :D
 
"What about users with monitors smaller than 256 pixels?" you ask. I'm pretty comfortable throwing them under the bus.
 
@Kevin Well, it is a bit impractical to do stuff with pixel measurements if you don't know the font dimensions, and if you do know those dimensions it locks you into using a font with those dimensions.
 
3:09 PM
@Kevin why do you want it exactly that width? Are you sure you want it exactly that, or do you want it to be at least or at most that?
 
If you want to know what a UI framework looks like that allows you to specify dimension in pixels, points, percentages of font dimensions, etc, welcome to the wonderful world of CSS...
 
Ok, let's zoom out on this XY problem. I have a window with a number of buttons that contain dynamically generated text, which changes over the life span of the window. I want the buttons to maintain the same dimensions and position for as long as the window is open.
I can't speak for anyone else, but I find it moderately irritating when a window resizes itself constantly.
"Determine the largest text that each button can possibly contain, and set the button's size so that it can contain it, even if that largest text isn't its current text" is possible, but incurs some performance cost.
 
Ah, that's a fair use case
 
"Just pick a number that you're pretty sure will contain any text that is likely to exist" incurs no performance penalty, but evidently it will be bad if I pick a number that's too low
 
dejavu what does this mean?!?!?!
 
3:17 PM
("But that's basically what you're doing by specifying a pixel width; that problem isn't specific to a character-unit-based system" you say. Yes, I acknowledge this.)
 
hey i had a question about duplicate python-argparse questions. of the two questions the stackexchange advice is to "pick the better" question. but i'm not sure which question is better. so i was asking others: meta.stackoverflow.com/questions/348492/…
 
Welcome!
 
@MooingRawr It's French for "already seen". It describes the sensation you get when you witness something that's familiar but you can't explain why.
 
@Kevin I meant I just had a dejavu I should have clarify I'm sorry for the lack of MCE :D
 
3:18 PM
@KevinMGranger thx! this is my first stackoverflow chat (long time user since near the start)
 
People like to use it as evidence that we're living in a glitchy computer simulation but I think it's more likely that the glitch is in the person's brain, which is emitting too many chemicals that signal familiarity
 
Much in the same way that if your code isn't working and you suspect the popular third party library has a bug, you're probably wrong.
 
@TrevorBoydSmith earlier doesn't mean better :D Are you trying to flag a dup on one of them with the o ther ?
 
@MooingRawr i am aware of the "earlier doesn't mean better". i was just curious which one was better.
 
3:23 PM
@Kevin yeah it's probably a bug in the compiler
 
Tkinter grievance #7: the grid geometry manager's sticky attribute lets you create widgets that resize automatically with the window... But only if you call columnconfigure and rowconfigure on all your columns and rows first.
 
@TrevorBoydSmith I like this one better: stackoverflow.com/questions/15008758/…
The answers seem more informative. And it's got a lot more views, although that's not super important.
 
I feel as though they're technically separate questions
 
Ok, here's my compromise solution: the buttons will be sized dynamically in relation to the size of the window, which will only change if the user changes it.
I'll initially give the window a size which is likely to fit all the button's texts, and the user can opt to embiggen the window if a particularly large text occurs.
 
I think they're similar enough to be duplicates. Anyone looking for a boolean flag will find their answer as part of the boolean parsing answers.
Or you can just link them in the comments and not close either.
 
3:31 PM
If I had a bit more gumption, I'd also dynamically set the font sizes for each button, but I'm pretty sure that Tkinter doesn't have an easy way to test whether a widget can contain text at a certain font size without cutting it off
That may or may not become grievance #8.
 
I think, ideally, they'd be merged. "This is a simple way to accept boolean arguments" is a good answer, but so is "here is how to specifically take boolean arguments in the way you requested"
 
If anyone has pandas know-how, IF AND statement only outputs ELSE statement Python may appreciate a tip on removing columns from a dataframe that contain nothing but NaNs. I'm guessing there's an easier way than manual slicing.
If you're into answering the Y of XY problems
 
bye guys
 
I like Davidism's solution: just link them via comments. As Kevin M says, they are kinda separate questions. "Boolean argument for script" asks what's the standard way to implement a boolean arg (answer: as a flag), but the answers in "parsing boolean values with argparse" cover both the flag case and the various other ways to do it. If we really do want to dupe-close one, I'd say "parsing boolean values with argparse" should be the dupe target, mostly because it has more options.
 
3:51 PM
Hmm, Python/Tkinter: expanding fontsize dynamically to fill frame is exactly the problem I am trying to solve right now, but the answer looks suspect to me...
I don't expect reassigning self.font to have any change on labels using that font. It's just rebinding a name, not doing a mutation in any scope that matters
And irrespective of that issue, setting font height to equal the widget height doesn't guarantee that the widget is wide enough to fit all the text.
 
@davidism personally i like the answer given by stackoverflow.com/a/9183998/52074 but the question is not written as well. the other question is written better but the answers are IMO overly complex...
this one has the overly complex answers: stackoverflow.com/questions/15008758/…
someone else with more experience choose. i can't decide :).
 
@Kevin Somehow I ended out on TVtropes after clicking that link. Where am I?
 
Edit the question if you think it can be improved.
 
Oh nice, Font objects have a measure method that tell you how much width a piece of text will require. I retract potential grievance #8.
Still kind of a pain in the butt to find the largest font that fits. Best I can do is a binary search.
 
01:00 - 16:0016:00 - 00:00

« first day (2385 days earlier)      last day (2553 days later) »