« first day (2403 days earlier)      last day (2563 days later) » 
04:00 - 17:0017:00 - 23:00

4:45 AM
Cabbage :-)
 
 
2 hours later…
6:46 AM
cbg
@Coder117 The chatroom rules are mentioned here - sopython.com/chatroom
 
7:03 AM
I have a parent class "Experiment" with a list of names. I have a function which pops a chosen name from the list.

I then have a class called Trial, which inherits the list of names. I call the child class multiple times. How can I get each instantiation of Trial to pop from the SAME list in Experiment?
 
cbg
 
@MichaelAnderson What do you mean by "inherits the list of names" ?
 
7:20 AM
```
class Experiment(object):
def __init__(self):
self.sectornames = generate_name_list()

class Trial(Experiment):
def __init__(self):
super().__init__(self.sectornames)
def poplist():
pop(Experiment.sectornames)
```
The idea is that I could call Trial over and over again, and each time that I pop a value from sectornames in each instance of Trial it would affect one single list object.
 
7:34 AM
then you need to set the list on the class, not the instance
ie class Experiment(object): sectornames = generate_name_list()
you can still access it via self.sectornames from within methods, or use type(self).sectornames if you prefer to be explicit
 
 
3 hours later…
10:06 AM
@PM2Ring So far, so good, thanks. Doing some planning today ...
 
10:54 AM
cbg
 
cbg
 
How are you, @PM?:)
 
@AndrasDeak Not fantastic. I need to find a new place to live, and I'm not having much luck so far.
 
oh, I'm sorry to hear that:(
You mentioned that you're trying to stay in the neighbourhood...I assume that's not going well then
 
Well, there's not a lot of places available around here within my budget, and when they become available they tend to go pretty quickly. Or they're total dumps.
 
11:01 AM
Is that a general feature there, or more of a local thing where you live?
(there= ~ cities in Oz)
 
I'm living near a small city / large country town, so there isn't a huge supply of housing. Also, there's been a lot of work going on around here for a few years upgrading the highway, so a lot of the places suitable for a single guy have been taken up by the road workers.
 
that sucks :/
 
I haven't tried to rent a place for almost 25 years. I can't remember it being this hard... That was back in Sydney, but I bet it's a lot harder there these days, due to a massive influx of population, even though it's the most expensive part of the country to rent or buy a place.
Hmmm. That last sentence may not make a lot of sense. :) People keep moving into Sydney because that's where the action is. It's become very crowded, and the traffic problems are chronic, but still they keep coming...
 
(I think I understood)
I'm sure there are fewer caravans of burning-gasoine-spewing metal bands in Sydney
Assuming that my image of Australia based on the Mad Max movies is accurate
My impression is that people have become very mobile in recent years (I don't know if that statement makes any sense on a global scale...). So I can imagine that wherever you try, it would've been easier 25 years ago
at least here it seems that there's much larger fluctuation in housing
then again, 25 years ago we were still commies :P barely a republic
edited
crap, time flies
A few years ago "25 years ago" used to mean <1990
 
11:16 AM
I've just spent the last couple of hours on a website that's supposed to make rental applications easier. You enter all your personal details & ID documents, and then each time you see a new property that you like you can quickly create a standard tenancy application for it. A lot of the real estate agents accept these applications electronically.
At first I was impressed with the website, but after the 1st page it got really slow, so you'd type stuff into a field & wait half a minute for it to become visible.
 
it's probably not webscale...
 
Definitely not! :) At the top of the slow pages it says "Automatically saves every 40 seconds". I thought that would make things faster, not slower. But at least I've got it done now.
I was hoping to electronically submit an application for a nice-looking place I saw on the Web today that's well within my budget. But it won't accept it unless you've inspected the property. :( Currently I've got 4 places that I want to look at; 2 of those are a little bit expensive, but I guess I should check them out anyway.
 
And how deadly are those inspections? I know for instance in Switzerland they call 3-4 interested parties at the same time to inspect the same place...sounds ugly
 
For an apartment, they generally schedule 10 or 15 minute inspections and a bunch of interested parties show up. The 1st one I went to, 5 parties turned up, and the place was gone 2 days later, before I had a chance to even lodge my application. But at least I've got all the necessary info & ID documents together now.
But anyway, I'm sick of thinking about this stuff now. I need a break! :)
I know, let's talk about Python! :)
 
Sure thing:) Yesterday I realized that callable is a builtin name :D
A built-in function even. I should look into what it does when called, later.
 
11:30 AM
@AndrasDeak Oh yeah. I'd forgotten about that one.
 
OK, it's just callable_eh() in Canadian notation
 
@AndrasDeak It just returns a boolean telling you whether its arg is callable or not.
I'm a little disappointed that there isn't a simple, fast way to do pixel-based graphics using the standard libraries, I guess Tkinter is now (kind of) a standard library.
 
graphics doesn't seem close to the original mainstream path of python to me
then again I guess that's one of those areas where it's much harder to be portable
 
The Tkinter Canvas lets you draw polygons, ellipses, images, and lines. But all canvas elements are objects that can be moved or have various other attributes modified. That can be handy for certain kinds of graphics, but if you just want to plot a simple line graph, or simulate a planet's orbit you need to draw a zillion 1 pixel lines, and because each of those lines is an object that adds up to a lot of wasteful overhead.
TKinter also has a thing called a PhotoImage. It's normally used to hold image data from an imported image file, but it's also possible to set individual pixels (or rows of pixels). However, for some reason as you add more pixels to the image the slower it gets. At least, that's what happens on my machine. DSM ran my simple test program the other day, and he didn't notice a slowdown.
 
I assume it's much more convenient for vector graphics(-esque) manipulations
yeah, I skimmed your discussion about slowdown
Won't PIL cut it either?
 
11:46 AM
PIL doesn't have a way of displaying dynamic images that get updated while you're watching. In fact, PIL doesn't have an in-built way of displaying images at all: it has an Image.show method, but that just calls a system-dependent image viewing program, eg if you have ImageMagick installed it uses its display utility. IIRC, on Windows it uses MS-Paint.
 
hmmmm
matplotlib? ;)
don't know how well that would work with dynamic stuff
 
It is possible to convert a PIL image to a Tkinter PhotoImage. It's not very fast though. It's ok if you're updating a whole bunch of pixels at once, but if you're just doing it 1 pixel at a time it's a bit slow.
I've also tried using Numpy + PIL + Tkinter. With single pixel plotting I get almost 50 pixels per second. I.e., it takes over 20 seconds to draw a horizontal line across a 1024x768 window. OTOH, if I were plotting orbits of say 20 planets it'd run at almost the same speed.
 
Do the pixels have to be actual pixels? Or just raster graphics?
 
I'm not fussy. :) My main restriction is that I want it to run without needing any 3rd-party libraries. I originally tried turtle, but it was a bit slow, and I figured I could get more speed using Tkinter directly, since turtle uses Tkinter to do its stuff... or maybe it interfaces more directly with Tk/Tcl. :checks docs: It looks like it uses the Tkinter Canvas.
 
ah, third party...
all the stuff I use are third party :D
 
11:57 AM
I expect I could do it with pygame, but I've never used it.
The weird thing with the PhotoImage slowdown is that if you blank the PhotoImage it speeds up again. But I can't understand why that would happen, unless it builds up a huge list of references to each pixel you set. Or something...
 
that sounds reasonable
 
I've used pygame for pixel manipulation before. It's pretty fast since it's fairly close to the metal compared to Tkinter or PIL.
At least, that's my impression.
 
Also, the slowdown is much less dramatic if you increase the time delay between drawing operations. I guess that kinda makes sense: if you render too quickly you end up with a big queue of rendering events. But it's still weird that it can start out really fast and then drop to a snails pace.
Give me a minute & I'll put my latest pure Tkinter code on a Gist. It prints timing stats so you don't have to guess if it's slowing down. :)
 
Is there a way to set a renderer or something? It should be reasonable to expect that once you paint over a pixel, you need not worry about it anymore
I'm grading some mid-terms so I can easily let it run to see what happens
 
12:07 PM
on what time scale does it slow down?
 
Comment out the stuff under # Test the effect of blanking the PhotoImage to see the full slowdown effect.
 
I'm pretty sure there's a way to get a handle to the window object allocated by the OS' windowing API, at which point you can blit things onto it manually. But at that point you may as well just skip Tkinter entirely.
 
Rendering speed is set in self.root.after(5, self.update). Change the 5 to 1 for maximum initial speed & maximum slowdown. If you set it to 40 or so, the slowdown is very gradual.
 
neat
What are the numbers? Speed or time?
whooooah with 1 it was very drastic
 
@AndrasDeak The 1st arg to the .after method is a time delay in milliseconds.
 
12:10 PM
I mean the printed timing numbers... but apparently it's speed
 
@AndrasDeak Yeah. It's pixels per second.
 
Interesting. On my machine, it trends downward, but not monotonically.
333.25  327.36  288.45  328.62  288.92  306.89  291.70  289.95  271.22  255.24  241.10  211.03  223.26  240.49  230.34
216.88  220.94  214.43  208.18  202.07  172.30  194.78  190.52  183.64  164.98  170.05  144.11
 
try with 1
654.46	790.75	806.88	781.08	789.57	799.56	786.30	761.39	771.66	767.50	757.45	742.05	738.24	730.25	729.57	724.65	692.51	694.35	703.96	708.13	694.45	690.47	656.50	697.51	703.07	684.67	680.27	690.41	654.98	671.95  673.08	661.25	125.54	84.26	81.77	77.46	74.22	74.13	76.23	75.81	72.54	68.94	68.93	63.39	64.76	66.86	64.34	63.48	63.31	63.50	63.11	62.62	63.49
 
This is with 1.
 
oh?
mine plummeted as if it hit a mountain
 
12:12 PM
As usual, my potato of a laptop fails to measure up to everyone else's fancy 650 pixels-per-update monsters
 
The very 1st number printed is inaccurate, because it uses the time the PGrid was created as the initial time, but subsequent numbers should be valid.
 
well mine is an 4x2-core workhorse, it's supposed to be reasonably fast
@Kevin I don't think you should expect strict monotonicity
 
Agreed. Not on a multitasking OS.
 
@PM2Ring it seems to me that the bg is black, so any non-black pixel is additional info to be updated
if it paints every pixel on every .update(), it's only expected to slow down as more and more non-bg pixels are around
am I missing something?
 
On my single core 32 bit 2GHz machine, this is the kind of output I get for delay of 1 with no blanking:
345.29  344.72  259.44  193.66  156.05  143.91  128.60  110.69  102.69  92.01   58.86   79.88   72.76   66.71   64.80   61.67   56.32   55.49 46.41    48.96   48.17
With blanking, it's like this:
321.35  317.56  245.98  202.34  167.42  142.21  126.00  102.77  99.72   91.03
503.68  344.70  256.04  195.46  167.51  130.46  126.56  109.16  100.97  92.70
447.58  363.28  240.13  189.49  164.98  144.57  126.07  95.15   59.46   91.25
487.30  313.40  258.72  199.66  168.27  143.75  122.66  101.51  100.51  90.65
491.98  363.96  235.02  193.10
 
12:17 PM
I don't know if "it paints every pixel on every update" is accurate. I can't speak for Label widgets, but the Canvas widget only updates dirty regions.
It might be different for PhotoImages.
 
"dirty" as in "which has changed since the last update"?
 
Yeah.
 
huh
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 1539 user       20   0  968904 191596 133848 R  99.3  2.4 176:33.90 Xorg
 
@Kevin Thanks for that link! I'm kinda familiar with the low-level details from GTK, and I've even done a little bit of stuff directly in X windows in C.
 
Aside: I've looked at four different independent sources of documentation for Tkinter and none of them mention any of the methods supported by PhotoImage.
 
12:21 PM
> Some background: the Canvas widget uses a straight-forward damage/repair model. Changes to the canvas, and external events such as Expose, all update a single “dirty rectangle”.
 
@Kevin I discoverd the .put and .blank methods by accident. They are minimally documented in help(PhotoImage), though.
 
oh nevermind, my point was going to be that with diagonal zipping lines the rectangles are huge; but we're calling update way more often for that to matter
 
Yeah, if it's rebuilding a fresh pixmap every time a pixel's set in the PhotoImage that's going to be slow. But that by itself doesn't explain the slowdown. Unless it maintains a list of painted pixels and repaints the whole yamming thing from scratch every time you add a new pixel.
 
that was my uneducated impression, but I literally don't know anything about tk
I found it a bit weird that xorg is the one grinding CPU, but that might just be due to the whole thing going on in a tk window
 
morning everyone
 
12:29 PM
Morning, corvid.
 
morning
 
and, morning cabbage
 
cbg
 
Ah yes, mr.doob, that guy does lots of JS based graphics things
 
I think he's the one who did the sketchy thing
 
12:36 PM
I'm not sure if you mean "sketchy" like creepy or "sketchy" like describing drawing
 
Why not both?
 
I have to admit that doing graphics in JavaScript with a HTML5 Canvas is rather nice.
 
I really like it actually, after going to school at UofU, which was heavily game-development oriented, I am so tired of making my own render-loops
 
did all that work render you tired of it all?
 
The other day I looked at the source code for 2048 to see how they handled the movement of tiles from one position to another, and the gradual color change of tiles as they merge, etc, and AFAICT all of that is handled by the HTML rendering engine itself because I didn't see anything hand-made relating to tweening or state machines or whatever.
Must be nice to have high level abstractions like that
 
12:51 PM
I'm looking forward to the takeover of htlm5 because I'm tired of firefox constantly badgering me that flash is insecure and I'm stupid for using it
 
You just do tile.position = whatever and instead of instantaneously popping into place it gradually moves there over the course of many frames
 
Another fun way of doing graphics in a browser is with SVG. But it's best at high-level stuff, I've never tried one-pixel-at-a-time stuff with it.
@Kevin Yeah, that's pretty easy to do with SVG + JavaScript.
 
cbg
 
I thought about writing my own abstraction layer for non-instantaneous rectangle moving, but I couldn't decide how to implement it. In particular, I didn't know whether I should have movement have a constant speed, or a constant time-to-completion.
If I do a constant time-to-completion, then when I set the position of two squares, and one's path is longer than the other, then it will move faster than the other so they arrive at the same time. This is undesirable in the specific case of writing a clone of 2048, because you want all the tiles to slide along the board at the same rate.
 
12:59 PM
I'd go with constant change in momentum, assuming the mass of each pixel is inversely proportional to brightness.
Also cbg
 
But I don't know if I like constant speed either because if the user presses a key button while the animation is halfway done, then the position of the square will change again before the old animation is done, and if the user really mashes the arrow button then the square will end up taking this long circuitious path that will take like half a minute to resolve because I have no way of telling it to speed up because the speed is constant.
 
just block arrows until blocks are done moving :P
 
In real 2048, you can mash the keys without any such bogging down.
 
during transit the state is ill-defined anyway
 
On reflection I guess backlogging would also be a problem if I did time-to-completion.
I thought about implementing logic like "if the position attribute updates and the movement animation hasn't yet completed, then teleport the square to the second-most-recent position and start animating from there". But that's impractical with my current model logic.
 
1:04 PM
it looks wonky too
 
cbg all,
I know most of you aren't newcomers, but I just found this, and it is super helpful.
 
Because when the user presses the arrow key, the model calculates the movement of the squares in a discrete fashion. If the square at (0,0) is going to move four spaces right, then the movement calculation reports that as "square at (0,0) moves right once. Square at (1,0) moves right once. Square at (2,0) moves right once. Square at (3,0) moves right once"
And right now I just iterate through the report performing all those updates in a batch. Thanks to backlogging, the four position updates all execute sequentially in the right order.
If I implemented position update interruption, then the square at (0,0) would teleport to (3,0) and then gradually move to (4,0). Not desirable.
"Just change the report so it says 'square at (0,0) moves to (4,0)', and then you can have your position update interruption cake and eat it too". That would be nice, but I need discrete position updating because otherwise the time-to-completion based algorithm would give different speeds to different squares.
 
That comes with a smooth transition, irrespective of the exact implementation used for the transition. Right?
fundamental 2048 problem
 
I've never actually tried to implement anything like this, and have no knowledge whatsoever of TkInter, but couldn't you do something along the lines of distance_to_move_this_frame = distance_still_to_move * frame_index / total_frames_in_move
That way you'd cope with changes in final position during the move, and it'd look somewhat natural.
 
That's pretty much what I'm doing.
 
1:18 PM
Here's a little SVG anim I did a while back. gist.github.com/PM2Ring/fbe0ea1cb434602ca3a90060e4c55493 It's all done with vector graphics so you can rescale it without it getting pixelated. You can view it directly on the Gist page, but it probably looks better if you show it in its own tab.
Your browser may allow you to do that via the "Show Image" context menu, but it does that by converting the image to a data: URI, so if that doesn't work, just save the .svg to disk & open it in your browser.
 
The voice of reason inside me says "these sort of problems have already been solved by a multitude of frameworks designed explicitly to aid people working on the thing you're working on" and I know this is true but the more sophisticated frameworks I use, the less I feel like I'm creating anything new.
 
Also, the more sophisticated the framework, the more you feel like you're being directed to do things their way. But I guess that applies to any framework, not just graphics.
 
Monday cbg on this fine morning \o hope you've had a wonderful weekend.
 
rhubarb for now
 
2:06 PM
monday cabbage all
can anyone (Sir David Lord?????) recommend a good tool for generating Flask REST API docs?
did some research of my own already, just wanted input from you guys
 
@Jfach I'm not David, but have you looked at : stackoverflow.com/questions/14295322/…
 
@MooingRawr yes, I was just looking at that :)
it looks like Sphinx could be nice, I have only ever used Swagger and it was a real PIA
 
Strange... Can subprocess not execute batch files?
import subprocess
#create an empty batch file
file = open("test.bat", "w")
file.close()
subprocess.check_output("test.bat")
#result:
# Traceback (most recent call last):
  # File "C:\Users\Kevin\Desktop\test.py", line 4, in <module>
    # subprocess.check_output("test.bat")
  # File "C:\programming\Python27\lib\subprocess.py", line 566, in check_output
    # process = Popen(stdout=PIPE, *popenargs, **kwargs)
  # File "C:\programming\Python27\lib\subprocess.py", line 710, in __init__
    # errread, errwrite)
I thought maybe that an empty file isn't technically a valid batch file (even though it runs fine from the command line). But googling around I don't see any obvious headers/shebangs/whatever I need to include
 
try popen or does that give the same result. I remember vaguely that batch files should be able to be executed with subprocess... don't remember details tho
 
Popen gives the same result.
 
2:14 PM
werid... one sec let me try on my machine
 
@Kevin what if you try subprocess.check_output(["test.bat"])
 
I'm trying to help out Sending “any key” to a subprocess called from a Python script and I'm trying to refute the first answerer's assertion that the "press any key" prompt gets magically added by Python or the OS
But I can't do that unless I can actually get a batch file to run properly under subprocess
@Jfach No change, same error.
 
yeah I don't understand what the first answer is stating ...
 
yeah I just looked at it too, bizarre.
 
Probably he read somewhere "when writing a command line application, it may be good to add a final input prompt at the end to keep it from closing prematurely" and misunderstood it to mean "The OS will automatically insert a final input prompt to keep command line applications from closing prematurely"
 
2:18 PM
There is no way that a final prompt is added automatically LOL
 
well it could be, if it was a custom dev tool.. but that's besides the point I guess..
 
I won't go as far as saying that no shell anywhere does that. I'm just saying the default command prompt doesn't do that.
This is frustrating because I'm pretty sure the answer is two lines of code using communicate but I can't nail down the specifics unless I can replicate the environment
 
Good point, I hadn't considered that. But the way the answer is phrased makes it seem like its an OS thing that always happens
 
99% chance that the batch file itself is the thing putting up that prompt and you only need to send it a newline or whatever via stdin
 
I spent 12 hours driving 600+ miles this weekend and starting this friday I'm going to do 3,000+ Q_Q
 
DSM
2:27 PM
Morning cabbage.
 
\o morning, lovely weather we're having.
 
@MooingRawr What result did you get?
 
DSM
Yeah, i spent most of yesterday in LargeCanadianCity outside. When the wind can gust enough it makes it hard to stand upright it's a lot of fun.
 
@KevinMGranger reminds me of this post from /r/ProgrammerHumor i.redd.it/7nuba9qu2owy.png
 
@Kevin same as you...
 
2:32 PM
Software Engineer == Truck Driver
 
I'm inclined to think that the OP isn't sharing his complete code with us. Mostly because C:\wildfly\bin\jboss-cli.bat isn't a valid path because you can't have backspace characters in directory names.
 
@Jfach bahahaha yes
 
@Kevin p = Popen("test2.bat", cwd=r"C:\Users\mooingrawr\Desktop\stuff") works though
 
DSM
I typically call out OPs on issues like that. When people use expressions such as "like this" it always worries me and makes me think they mean "doing something similar to" instead of "exactly as described in the following".
 
Even specifying the cwd, I get the same WindowsError. I think I'm giving up on this question. Even if I made a little test batch file and confirmed that I could send newlines to it via communicate, I have no way of knowing whether jboss-cli.bat is waiting on stdin data to terminate, and not doing something dumb like monitoring literal keystrokes
Actually the odds are pretty good that it's not anything like an input call, since those require you to press Enter, not any key.
 
2:38 PM
They're already running both java and windows so that's two strikes against them already
 
DSM
Life is short. Spend your time wisely.
 
I'm beginning to wonder if when we 'w' to the file are we creating some junk symbols in the file ? I should open the file in byte mode and see what's wrong with it
 
Sometimes I wonder if answering questions on stack overflow counts as a Good Deed (tm)
Sure, I'm helping my fellow man. But on the other hand, it's more of the "give a man a fish" variety most of the time, which just means they'll starve tomorrow. On the other hand, throwing starfish into the ocean may seem futile, but it's not futile to the ones you throw. On the other hand, receiving imaginary points in exchange for help makes it more like an economic transaction than an act of charity.
 
It depends upon what the asker is working on. What if they can't get the controller for their doomsday device to compile?
 
@Kevin Did you try the shell=True arg?
 
2:47 PM
Some moral frameworks indicate that it would be a net good for the universe if the Earth vanished completely, so even debugging doomsday devices might be good.
@PM2Ring I did half an hour ago, and it didn't help, but then I tried just now, and the error went away. Peculiar.
Maybe I forgot to save last time.
I wonder if OP is also doing shell=True and forgot to mention it.
 
Apr 26 '16 at 14:44, by Kevin
> In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move.
 
Another possibility: Does Windows have a command named start that you can use to open a file with its default application? Eg, subprocess.check_output('start test.bat') ?
 
DSM
Honestly? Yes, I think helping others on SO is a good work. I don't think it's as good as the corporal works of mercy such as feeding the hungry.
 
I'm a little baffled why shell=True would be necessary since I thought that was only necessary for, like, piping one command into another, or really anything more complicated than running a single program and not doing anything special with the output
@DSM Yeah, definitely different orders of magnitude, there
 
@Kevin I think it it's a win win scenario, you are getting better at coding and you are feeling good about helping people, while OPs are getting answers and possibly learning. You are training the next generation to fill your place when you go. Part of the cycle of life.
 
2:53 PM
I'm getting better at writing ten line sample programs, but I'm evidently not getting any better at designing nontrivial square tweening frameworks
 
Tkinter slowdown issue update. I put the PhotoImage into a Canvas instead of a Label and it's a minor improvement, but the slowdown still happens. So I got rid of the PhotoImage and tried just plotting small circles directly on the Canvas. That's even better, but as the Canvas gets crowded the slowdown kicks in. I also tried using 1 pixel lines, which is slightly faster than the circles.
If I push the after delay upto 15 or 20 the slowdown is very gradual, but it still happens. If I run the program with the window iconified the slowdown doesn't happen until you un-iconify the window, and then it kicks in with a vengeance.
 
DSM
I can't remember-- which OS do you use?
 
I wonder if you could do this: after N updates to the PhotoImage, save the image to disk, then delete the PhotoImage and load a new one from the file you just saved.
I assume PhotoImages can be saved, although I can't verify this thanks to the poor state of Tkinter documentation
 
@Kevin Indeed. According to docs.python.org/3/library/subprocess.html#popen-constructor On Windows with shell=True, the COMSPEC environment variable specifies the default shell. The only time you need to specify shell=True on Windows is when the command you wish to execute is built into the shell (e.g. dir or copy). You do not need shell=True to run a batch file or console-based executable.
 
3:10 PM
cbg, guys
 
@Kevin I don't think that'd help, and it'd be slow, although I guess I could use a BytesIO instead of a disk file. I think it just goes slow when there are lots of rendered pixels in the PhotoImage or Canvas.
However, PhotoImage has a .copy method, so yesterday I tried periodically copying the PhotoImage, del-ing the old one and setting the cloned PhotoImage into the Label via its .config method. THe copying process made the whole thing slower, and did nothing to help the slowdown issue.
@DSM Linux. An ancient abandoned Debian derivative named Mepis.
 
In an MVC context, should the model be responsible for saving itself, or should the database object take a model and save it?
I'm leaning towards the second one.
The thing I like about the first one is that the frontend doesn't have to care about the database object, it can just instantiate the model based on the passed JSON and then save it.
But it means I need to make a save method on each model instead of just having a generic `save_model` function on the database.
 
guys, i have a question. i have defined a function, which tests for many different rules (in the form of 'if this ...') and does something in each case. Now sometimes to check which of the rules matched, i put in a print statement inside all the if statements, with the print output being different in each case. (CONTD...)
(CONTD...) Now, other times, i dont need this printing, so what i have to do is to manually 'comment out' all these print statements in all the conditions, and 'comment in' all of them again when i need to check which conditions match. is there an easier way to do this?
code - pastebin.com/k331Xaw5 (all the commented out lines are what i am talking about)
 
3:28 PM
Lazy solution: print = lambda *args: None at the top of the function
 
Slightly less lazy solution:
verbose = True
def put(*args, **kwargs):
    if verbose:
        return print(*args, **kwargs)

put('show', 'me')
put('a thing', 'more', sep=', ', end='***\n')
verbose = False
put("don't", 'show', 'me')
verbose = True
put('bye')
#output
show me
a thing, more***
bye
 
@PM2Ring, @Kevin, thanks. but my if conditions are of the form - if re.search(r'(The object of this study was to identify genes transcriptionally upregulated.*?downregulated)', s1):. So, i dont understand what you mean by args here
 
You could replace the standard print, like this, but that's probably not a good idea:
def print(*args, **kwargs):
    if verbose:
        return __builtins__.print(*args, **kwargs)
 
@user1993 The conditionals have nothing to do with the args parameter. You don't need to pass in anything new, or anything.
 
3:34 PM
def f():
    print = lambda *args: None
    if True:
        print("foo")
    if 2+2 == 4:
        print("bar")
    if len("") == 0:
        print("baz")

f()
Result: no output.
 
DSM
Are we just re-inventing logging here?
 
yeah
During this conversation I've been frantically scanning through the logging tutorial to see if there's a command line flag or something that specifies whether logging.info shows up in stdout, but I haven't found anything like that yet
 
I was just about to say "But perhaps you should consider using proper logging here" :)
 
@Kevin Kevin, it gives 'invalid syntax' at print =
 
Oh, I'm guessing you're in Python 2.7, where that's a syntax error.
 
3:37 PM
yes
 
@user1993 So def put(*args, **kwargs): means you can call put just like you call print, and it will pass those args onto the real print.
 
This is why you shouldn't assume someone is using 3.X just because they put parentheses around all their print arguments.
 
absolutely. actually my Spider has 2.7 but my Atom has 3.0, so i do this
 
@user1993 You need this at the top of your imports so you get the print function instead of the print statement.
from __future__ import print_function
 
@user1993 I suppose you could put from __future__ import print_function at the top of your file, but honestly this approach is so brittle and hacky I can't recommend using it since it's already caused more frustration than it's worth.
Whoops Kevinned
 
3:39 PM
Even better:
from __future__ import print_function, division
 
(disambiguation: when I say this approach is brittle and hacky, I mean the approach of reassigning print, not the approach of importing from the future. There's nothing wrong with importing from the future)
 
ok
@PM2Ring got it
 
@user1993 Using the print statement with all the stuff you want to print wrapped in parentheses is not a great idea. It means you're printing a tuple instead of the individual items, so when you run the code on Python 2 you end up seeing those parentheses, and the commas, but more importantly you get the __repr__ of the items you're printing instead of their __str__. So you really should use the from __future__ import print_function and use the proper print function syntax.
 
oh! didnt know that
 
In Python 3 the from __future__ import print_function is totally harmless.
 
3:44 PM
Obligatory: "What you should really be doing is uninstalling 2.7 and installing 3.X"
 
i think i'll finally get to it
thanks a lot guys
 
No worries.
 
Fish given today: ||
 
If you're on a Linux system, it's probably not a good idea to un-install the system Python. But you can easily install Python 3 and have it co-exist with Python 2.7.
 
i'm on windows
 
3:46 PM
cbg all
anyone know why, when isalpha() is used on an integer, it returns an error? Isn't that the point os isalpha?
 
Nah, the point of isalpha is to disambiguate between alphabetical characters a through Z, from all other characters, like "#" and "&" and "-"
 
@user1993 In that case, you can safely ditch Python 2 unless you've got a bunch of 2.7 code you need to run. But I guess it's handy to be able to test code that needs to run on both versions.
 
If you want to determine whether an object is a string, use isinstance.
 
DSM
@user1993: for Windows users I recommend using conda. It makes it easy to install scientific software which is otherwise a little frustrating on non-linux architectures. You can also easily create python 2 and python 3 environments and have them live side by side in harmony.
 
3:49 PM
Or, embracing EAFP principles, just assume it's a string and try to use it as such, with fallback logic for all other cases occurring in the except block.
 
@toonarmycaptain .isalpha is a method of strings (and bytes). It should be obvious why integers don't have that method. ;)
 
@DSM i think i will do that. thanks!
 
I'm second-guessing myself now: does isalpha return true for anything beyond the ASCII letters? Accented characters, Cyrillic, etc?
I would test it myself but it's a pain getting accents into the REPL with this american keyboard
 
DSM
Just use chr..
 
That would work, if I knew ahead of time the ordinal value of an accented letter. Which is actually something that would come in handy in the future, so I'll do that now.
 
DSM
3:54 PM
But all you do is need to see if it returns True for anything beyond the standard letters, not to know which ones in particular are accented.
 
Too late, I've already undertaken the herulean task of remembering that 'é' is 0xE9.
>>> chr(0xE9).isalpha()
True
Incidentally.
 
i love how you answer your own questions :D
 
Now for a catchy mnemonic... "to get a thing over your E, simply use two hundred thirty three". No, the meter isn't right.
 
DSM
Accent aigu over the E / is chr two hundred thirty three
 
print([(c, c.isalpha()) for c in bytes(range(160, 256)).decode('latin1')])
Output:
 
3:57 PM
Debate: should chr be pronounced "C.H.R." or "churr" or "character"?
 
DSM
Dec 17 '15 at 20:36, by Kevin
Clearly it should be pronounced "chruh"
 
Past Kevin is deranged and should not be listened to.
 
In [1]: '\N{SNAKE}'.isalpha()
Out[1]: False

In [2]: '\N{PILE OF POO}'.isalpha()
Out[2]: False

In [4]: '\N{KATAKANA LETTER A}'.isalpha()
Out[4]: True
 
Ignore all of my messages above this line:
---------------------------------------------------
 
Oops. The output was too big. Take 2:
print(''.join([c for c in bytes(range(160, 256)).decode('latin1') if c.isalpha()]))
#output
ªµºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ
@DSM Or just use a compose key...
 
4:02 PM
looks like it's actually pretty convenient for letters:
 
@Kevin churr or cherr as in err...
 
import unicodedata
def isalpha(chr):
    return 'LETTER' in unicodedata.name(chr)
at least with a smattering of unicode, that's accurate
 
@MooingRawr I usually pronounce "chr" as "churr", a bit like the "cher" in "archery"
 
That will work until the Unicode emoji expansion gets really out of hand and occupation-specific icons include \N{BLOODLETTER}
 
@PM2Ring Oh that's a good example, it's for me too, but sometimes I pronounce it as char as in to lightly burn something.
 
4:08 PM
@Kevin well, I just tried this out:
 
@MooingRawr I guess that's acceptable in Python. But in C, "char" is a type name.
 
In [12]: for n in range(0x10ffff):
    ...:     try:
    ...:         if chr(n) ^ ('LETTER' in unicodedata.name(chr(n))):
    ...:             print(f'Seems {chr(n)!r} is special')
    ...:     except:
    ...:         pass
didn't print anything out, so, assuming my boolean logic is right there, and the upper bound was right then it looks like that holds true for the unicode set
 
I think you need an isalpha() near that first chr call, if I understand what you're trying to test for
 
ooh, right
yeah
 
@WayneWerner You could call unicodedata.category ...
 
4:10 PM
there's a lot more, then, lol
 
I didn't say it would be easy. :)
 
(with the .isalpha)
In [17]: exceptions = 0

In [18]: specials = []

In [19]: for n in range(0x10ffff):
    ...:     try:
    ...:         if chr(n).isalpha() ^ ('LETTER' in unicodedata.name(chr(n))):
    ...:             specials.append(chr(n))#print(f'Seems {chr(n)!r} is special')
    ...:     except:
    ...:         exceptions += 1
    ...:
    ...:

In [20]: len(specials)
Out[20]: 102541

In [21]: exceptions
Out[21]: 992064
In [24]: unicodedata.name(specials[10])
Out[24]: 'MODIFIER LETTER DOWN ARROWHEAD'
for one
In [26]: specials[-1]
Out[26]: '\U000e007a'

In [27]: unicodedata.name(specials[-1])
Out[27]: 'TAG LATIN SMALL LETTER Z'
for another
 
Curious, when I have both the append statement and the print statement, it prints about 20 items, but len(specials) is still in the hundreds of thousands.
(Not that exact print statement though because I haven't upgraded to a 3.X that has format strings yet)
... Oh, it's probably raising an exception after appending but before printing.
Yep.
 
4:29 PM
listen peeps :D i asked a question and it has passed some time and there is no further questions ( if there is something that is unclear or planeout wrong ) or answear.
http://stackoverflow.com/questions/43921785/python-bmp-dib-byte-slots-compression-slot

would you be so kind to checking it out , and if you have some solution or question ask. I am stuck on that problem for some time now.
 
Air
Accio cabbage!
I applied for a devops job on Friday! Three cheers for mixing a little proactivity with my kvetching!
 
DSM
I'll admit I had to google that greeting. I'm kind of happy about it. ;-)
And good luck!
 
Air
Don't waste your luck on me, I almost certainly won't get the job, but taking the first step is always nice, right
It also may or may not be a cult
 
DSM
I have plenty of luck to spare! And while the first step is nice, the most important step IMHO is the interview. If you can trick convince someone to interview you, you're getting really important practice for free!
 
Air
My sentiments exactly. One of the things I'm really missing in this whole process is some idea of where I stand in this other industry that I'm not yet a part of, so even bombing an interview would be really valuable if it tells me what I'm missing.
 
4:35 PM
good luck :D just be confident. I bet you will get it
 
"Are there some sorts of standardised codes for image compression?" Not really.
"Can anyone give me a solution?" Solution to what?
"Does anyone have any link or book that can guide me further in this quest?" Stack Overflow isn't really suited for giving resource recommendations.
 
I tricked my way into my position :D can confirm
 
@PM2Ring maybe, but I'm looking it to return False if the value is an integer. Is there a better to way to test if a letter/number in a list is letter abc or integer 123?
 
Tnx @Kevin I guess the "can anyone give me solution" is a bit vague. I was wondering how can i know if file has compression and what compression type is by reading its bytes. There is on 34 byte place of 4 byte length compression slot in DIB part of the header.

as resources... how do you know then what is what? i guess that there is some book , article or something where everyone gets their information ?
thanks for the comment
 
@Danilo Check out the table just below "The compression method (offset 30) can be:" on the Wikipedia page. It tells you what number matches up to what compression method.
Also note that it's at byte 30, not 34
I'm pretty sure you're reading from the image size field right now
I wrote a little bmp file decoder back in '05 or so, and all the bmps I tested it on had no compression at all. This was on a Windows machine.
 
4:57 PM
Hollyyyy.... (cbg) I did not take that under advisment since OS/2 2.x ( i thought that did not work for windows ) but i guess i was wrong. But on byte 30 there is Planes slot , and on byte 32 there is Bits per Pixel .... i guess there is either error in wiki or error in my thinking ( i guess it is the other one ).
Tnx Kevin
 
Yeah, pretty sure there's a fencepost error in your thinking. You don't add the byte offset of the field you're looking at when determining its address. For example, File Size is four bytes but you don't add four when determining that it appears at byte 2.
 
04:00 - 17:0017:00 - 23:00

« first day (2403 days earlier)      last day (2563 days later) »