« first day (2522 days earlier)      last day (2409 days later) » 

12:02 AM
yeah, it works in py2
py3 has a cocmplete rewrite of the library though @Idle001
 
 
2 hours later…
2:12 AM
I am using kivy, anyone know how can I center that two textinputs?
I am using boxlayouts
I don't know if this is necesary, but this is my .py code.
 
2:35 AM
mmm, this is the solution. Put the TextInput01 (login and register) inside a AnchorLayout?
 
 
2 hours later…
4:32 AM
@Rawing shutil.copyfileobj
However you'll have to create the target file-like object yourself
Umm, it doesn't do anything clever
 
@Rawing
 
@vaultah Ah, but that copies everything every time. I'd much rather read the contents lazily whenever I need more data
Most functions will read no more than ~10 bytes before throwing their exception, so creating a full copy of the file is quite a waste
 
@Rawing ah ...
then you'd subclass the IOBase...
 
4:55 AM
That looks pretty similar to what I came up with. Except I didn't add a sanity check that dumps everything to disk if the size is too large...
 
5:25 AM
I have a dream, that one day I'll learn to write code without three layers of abstraction...
Image wraps BackendImage wraps PILImage/imageioImage/etc
 
why not?
though, instead of wrappers, write adapters
 
what's the difference?
 
51 Goto NumChkE:Data'?.E1N.E,NumChkE:Data'?."-".N.".".N
N F %=2:1 S Y=$E(X,%) Q:"+-"[Y G 1^%DT:$E("NOW",%)'=Y

I Y="" S %H=$H G RT

S X=$E(X,%+1,99)

I X?1.N1"H" S X=X*3600,%H=$H,@("X=$P(%H,"","",2)"_Y_X),%=$S(X<0:-

1,1:0)+(X\86400),X=X#86400,%H=$P(%H,",")+%_","_X G RT

D DMW G 1^%DT:'% S @("%H=$H"_Y_%),%H=%H_","_$P($H,",",2)

RT D TT S %=$P(%H,",",2) D S S %=X_% I %DT'["S" S %=+$E(%,1,12)
MUMPS totally takes over PERL as the number one unreadable programming language.
 
5:41 AM
Wait a minute... I could just yammin' inherit from the wrapped class; then I wouldn't need to write so many wrapper functions... *facedesk*
 
5:53 AM
cbg
 
6:10 AM
@Rawing no.
(rather emphatically)
 
Ah, yes, I guess that sounded like a stupid idea, huh. It's ok though, I incorrectly said it's a wrapper class even though it's actually not.
Image really is just a subclass that adds functionality to BackendImage; and BackendImage is kind of an adapter for PILImage, but it only adapts 2 or 3 functions
Basically BackendImage adds save/load functionality to PILImage, and Image adds events to BackendImage to make it observable
 
6:30 AM
cbg
@AnttiHaapala :P
 
Cbg all
I know that when you import a module twice in a function it does not gets loaded twice ref[https://stackoverflow.com/questions/19077381/what-happens-when-i-import-module-twice-in-python]
But what if module is imported twice but within different script like below.
Script A:
`import request`
Script B:
`import A`
'import request'
 
cabbage
 
cbg-ning
 
@The6thSense The module isn't reloaded.
 
@Rawing Thanks wanted to know that :)
 
6:48 AM
You can see that it's the same module if you do print(request is A.request) in B.py - it'll print True
 
@Rawing Yes it does thanks.
 
@The6thSense it is installed in sys.modules...
 
7:16 AM
@Rawing very cool
 
 
2 hours later…
9:01 AM
How to write a unit test for this code
 
Cabbage
 
I am new to python language
@JRichardSnape caggage :)
 
@JRichardSnape o/
 
How are things in the world of Python? I see @Antti has found a way to hack the star board :)
 
Cabbage!
 
9:15 AM
Only another 26 stars and it will look very impressive
Cbg poke
 
@JRichardSnape I wish he had added a space before the second comma as well.
 
cbg, JRS :)
 
@poke Indeed, you can't get the attention to detail in programmers these days. Tsk! ;)
 
9:27 AM
hi everyone :)
I keep wondering: is there any good reason to use named tuples over a class?
 
I'm currently reading this book goodreads.com/book/show/25893850-the-city
 
Reason 1: your class should be a tuple </list>
 
@paul23 good news: namedtuple builds you a class
 
I've always wondered the benefits of using tuples instead of list. List is almighty, tbh
 
9:29 AM
@AndyK keys in dictionaries.
 
This is my first python program that I am using tuple. I struggled a lot to sort the names finally got this solution. Any improvements are accepted
 
there's also SimpleNamespace
 
I think he's asking why make your class inherit from tuple when you could just as well use SimpleNa- Kevin'd
 
@AndyK there's the usual argument that lists should be homogeneous, tuples can be inhomogeneous
 
@AndrasDeak yes, but that violates the "one way only" - why would I define a (local) tuple when I could just as easily define a small class. -- Similar to how function definitions vs lambdas are used.
 
9:31 AM
@paul23 "there are already ways to build a wheel, let me invent a new one"
the existence of these methods violates the "one obvious way" principle a bit; that doesn't mean you shouldn't use them as you see fit
 
Hello
 
namedtuple is an iterable wheel with a length, however.
 
it all boils down to this: what do you want your object to be able to do?
and decide accordingly
 
I have created several pandas DF, I want to call all these objects to iterate with a function... but I can not find the way to call them or to create a list of this objects and iterate trough a list
 
@AndrasDeak a = [1, "a"] ?
 
9:33 AM
I have a .txt file with a list of names. I want to read, sort them and finally write them to a new .txt file
 
@AndrasDeak Wheel 2.0 - now even rounder!
 
@AndrasDeak I just can't think of a reason why I would see them as "better than a small class".
 
@AndyK "should be"
 
Presumably a tuple is way more efficient
 
there "should be" one obvious way to do things
you "should" know better
@paul23 then your imagination is atrophied
 
9:36 AM
@AndrasDeak fair enough. I "should" understood your point
 
Well yes, but that's why I ask: I'm not perfect so maybe someone else knows more :).
 
Imagine you're implementing a Point class. It needs an x and an y attribute, and I want to be able to do x, y = Point(1, 3). That's perfect for namedtuple.
 
yes, but paul is asking why not define a class with those properties yourself
for me automatic property lookup is more than enough to bother with defining my own namedtuple
then again last time I used a namedtuple I didn't know about SimpleNamespace; that's probably enough for my typical use case
 
...that's what he's asking about? That's really reinventing the wheel then.
 
I'm not sure; you know how it is with the Dutch :P
if he doesn't want to reimplement the functionalities of namedtuple, he doesn't actually want a namedtuple
in which case "why would I need a namedtuple if I don't actually need a namedtuple?" changes the highlight of the question
 
9:43 AM
Yes, I thought that's what the question was about, actually. I've seen plenty of SO answers use namedtuple to create a class with attributes, when it made absolutely no sense for that class to be iterable.
So I figured the question was "is there a reason why people use namedtuple so much"
 
Hmm so basically it is if you wish to iterate it? To be frank I kind of think of x, y = Point(1, 3) as terrible :/ -- it seems so error prone since there's no indication of order. (Why would the x value come before the y? y before x is just as logical)
 
that's why it's a tuple
you're thinking of dicts
named tuple = tuple with also labels
tuple ∈ ordered containers
>>> from collections import namedtuple
>>> Point = namedtuple('Point', ['y', 'x'])
>>> p = Point(1,3)
>>> p
Point(y=1, x=3)
if you don't want to iterate over it, you need a dict with perhaps property lookup -> probably what SimpleNamespace does?
OK, SN only has attributes, but it's not a dict subclass
>>> from types import SimpleNamespace
>>> sn = SimpleNamespace(**{'a':2,'b':3})
>>> sn
namespace(a=2, b=3)
>>> sn.a
2
>>> sn.b
3
>>> sn['a']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'types.SimpleNamespace' object is not subscriptable
 
Well I guess that's what I find "strange": once I start using labels to organize things I immediately (in my mind) discard the "ordering"... Point being actually the perfect example: once you label the axes why would you ever use numeric indices.
 
then why would you use a tuple? :P
use a dict.
it organizes things with labels
 
Even if you would then need an order (for a point), the only order that is important is the relative order (to see if it's a right or left handed system).
 
9:49 AM
python ideological discussion
 
I'm not sure I understand that statement
especially the bit about handedness
 
@AndrasDeak Which brings me back, I can't think of anything that uses both "labels" and "order".
 
yes, but that doesn't mean it doesn't have valid use cases
 
@AndrasDeak oh I'm just saying, you wouldn't ever need to access a point class by "first axis", rather by "next axis after the 'x' axis"
 
unless you want to unpack the point coordinates? :P
for instance, to move from a list of Points to list if x/list of y logistics
 
9:51 AM
Naaah, you don't need order for that. Just do x_or_maybe_y, y_or_maybe_x = Point(1, 3)
 
Explicit is better than implicit....... Meh I guess I'll just have to see it.
 
you might not have a good use case for it; that's fine, just use what fits your use case:)
dismissing a tool for you not needing it is a bit weird to me
this is not to say that namedtuples are good or useful; I don't have a strong opinion on the matter, and the build-source-and-exec strategy that creates them reminds me of the Great Old Ones
 
one use case that's certainly valid is in python's stdlib. Functions that used to return tuples in old versions now return namedtuples instead.
 
ah, like version tuples
 
it doesn't break compatibility with old versions, and if you don't care about supporting old versions, you have a cleaner interface
 
9:54 AM
>>> sys.version_info
sys.version_info(major=3, minor=5, micro=4, releaselevel='final', serial=0)
good example
 
sys.version_info is what came to mind? I was thinking about inspect.getframeinfo. I wonder if that could mean something...
 
it's not very hard to out-stdlib me :P
you often dabble in advanced stuff; I rarely do
 
In this case I think you won - I probably use introspection too much :p
 
@AndrasDeak Would you know without looking through details of a documentation what sys.version_info[2] would mean?
 
probably yes; but anyway I'd want to be able to do sys.version_info >= (3,4)
 
10:02 AM
Oh that's actually a good thing.
 
yeah? :P
 
10:20 AM
question for you statistics-oriented guys
I have discrete events arriving at certain timestamps,
how do I calculate ~average (moving window, exponential decay whatever), using as little data as possible for the events per second?
how about events per minute, hour
 
depends on how precise you want to be
 
preferably just store the last value and last timestamp only
for each of these counters
 
if it's regular, you need 2 timestamps
 
this is a toy
 
actually, the best you can do is note a first event, a last event, and the time interval in between
from that you can compute an events/second, and from that whatever other unit you want
the longer your baseline, the smaller your error
so you need
1. t1 starting event timestamp
2. t2 ending event timestamp
3. n number of events but you can just increment it with each event
if n includes both start and end, you have (n-1)/(t2[unit]-t1[unit]) events per unit
I mean, your use case is a bit unclear: are you trying to show a "frequency of events right now" kind of diagram that varies with time?
first I thought this was a probability question but now it indeed seems more and more like statistics (which I don't know :D)
 
10:42 AM
@faceless try rpc with ssl http://rpyc.readthedocs.io/en/latest/docs/secure-connection.html lemme make a wild guess .... you are remote-coding from work.
 
11:16 AM
@JRichardSnape
@poke this is "works for me :D"
 
:P
 
and there is space before the latter "comma", and those aren't commas
and no, increasing the number doesn't really help, as there's a fixed-width padding.
 
hello
 
hello
@AnttiHaapala mine looks better
 
@marukobotto welcome :-) if you're new and you want to ask a question, check out the room rules!
 
11:22 AM
"better" or "different kind of wrong", pick your preference
 
SO IS BROKEN!!!!!!!1111111111
 
this is what I do every day
go argue with silly jetbrains guys
a friend told me that the only way to get issues actually fixed is to go argue with them in 'cons and give them free beer or sth.
 
how much time does it take to learn django properly?
 
@marukobotto too much, so better skip it altogether
use Pyramid / Flask instead :d
 
@AnttiHaapala I like how you say how it’s broken and they later use that explanation as the “official workaround” (or solution even?) for another user…
 
11:34 AM
@poke because i was just hit by this 5 minutes ago
I was showing "see how easy it is to install packages"
only this time the env was created by -mvenv
 
I meant the 2015/2016 part of the discussion
 
my later solution is better, because that's what's needed anyhow :D
holy tshi I reported that 2 years ago
 
Antti: “It’s broken, the reason is X, if you do Y it works so my assumption for X is correct”
Other user: “I also have the same problem, it’s annoying”
Member: “You need to do Y”
 
Instead of “Yeah, you’re right, we should fix X”
 
11:38 AM
don't fix what ain't broken has a workaround
9
 
@AndrasDeak omg :D
I had to check from history. somewhat surprisingly I didn't see four ----lights---- dashes but just 3.
 
the number was right, there was a missing space that borked the markdown
 
oooh :D
 
Abstract methods are abstract enough to be ignored by the type checker
Anyone can think of a smart modulo calculation that visits the numbers 0, 20, 40, 60, 80, 100 and then loops back?
w = 0
while True:
    w = (w + 20) % 100
skips 100
 
11:49 AM
mod 120
then 120 -> 0
 
wow.
what is wrong with me
 
not enough coffee ;)
 
I tried this with a start number of 1—which obviously didn’t work, so I scrapped the idea
 
@poke or...
from itertools import cycle
 
No itertools in JavaScript
 
11:51 AM
 for w in cycle(range(0, 120, 20)):
@poke closing with "no mcve"
that's not js in your example
 
I did provide a (Python) pseudocode MCVE!
 
and I gave you a python answer.
so now you call python "pseudo code"
I wish there was a "mod-addition" operator.
 
well it's half supposed to be :P
 
No, I call my pseudo code “looking like Python”.
 
it would be very handy
 
11:53 AM
galois field operator
 
w += 20 (mod 120)
 
w +%= 20 120
 
20 120? :D
 
Python really needs some confusing syntax
 
we've been too easy on the parser
perhaps add yet another meaning to :
w +%= 20:120
 
11:56 AM
We could actually generalize mod operators
w +[120]= 20
So + is the short syntax for +[None] which means add without modulo, whereas +[n] means add modulo n.
 
and what about [2,3,4] + [120]?
 
space
 
oh, right, we love whitespace as syntax :D
 
Python is whitespace sensitive anyway.
Let’s go all the way.
 
11:58 AM
@AnttiHaapala that's an answer
 
@AnttiHaapala parse error, no close button found on linked item
 
close it anyhow
 
linked item has become unactionable
reject that edit pls
has an approve
hurry hurry omg
 
rejected
 
thanks
 
12:00 PM
reopen queue avoided!
sopython saves the day!
 
\o/
 
let's call it a day
 
need better questions
 
commute rhubarb
 
12:01 PM
I was a bit late, but I did my best
 
Speaking of better question, anyone wants to help me get rid of this? (spoiler: not Python)
 
@poke done
 
thanks <3
 
I tried but someone else got there first glares
 
It bothers me when questions sit on 2-4 close votes for so long…
 
12:03 PM
If you had to do a coding test, and you could fit an entire application comfortably inside 100 lines of code, would you do it all in one file, or break it out to show what structure you might use if the application were bigger?
 
A test as in “show that you can do this” and not “start project for this”?
 
@poke only for a month or so (close votes start to age away after 1 or 2 weeks)
 
@AndrasDeak I know, even worse.
 
@poke yeah - technical test for a job
 
One file it is
 
12:05 PM
(needs to be PEP8-ed)
 
As a practical example from my own life: I actually planned on writing some utility for myself a while ago. Designed the whole architecture some weeks ago and had really nice ideas to make it super good. I didn’t work on it at all because it was a burden. – Yesterday, I scrapped all those edits and wrote it in a way more compact (although with a way less exceptional architecture) within 3 hours.
 
Aug 24 at 13:28, by PaulMcG
Perhaps "peppate" will become a verb among Python devs, as in "You need to peppate your code before checking it in."
 
@RobertGrant That looks fine to me.
 
@poke yeah - TBH if this were a real project, other than the seed data part of it I'd probably actually do it that way until it needed to be broken out
Cool, thanks
 
@AndrasDeak Not happening on my watch.
 
12:09 PM
yeah, I don't endorse it either, just came to mind from Robert's remark :D
 
I like peppate. I'll rhyme it with "repartee" as well, to be extra irritating!
 
Early in my career, I worked in manufacturing systems, which went by the generic acronym CAM for "Computer-aided manufacturing". For two years, my wife thought I was saying "computerated manufacturing" - you know, it's on a computer so it's computerated.
 
Ah, finally a variable variables dupe target that actually recommends not using globals() in the top-voted post. generating variable names on fly in python
And by "finally" I mean "For the last seven years but I never noticed"
Although the line of reasoning "don't use globals() because globals are bad" is kind of a weak rejection of the idea. I would have preferred "don't use globals() and don't use locals() because both are bad independent of whether they involve global variables or not"
 
12:37 PM
Men invented lists.. so you don't have to do this. — adamJLev Oct 24 '10 at 23:45
lol
“Men” here means singular Guido, I guess.
@Kevin I prefer not mentioning it in the first place, but I guess that would make the question difficult to answer.
Also, are we gonna close this, or does anyone have a different opinion on this?
 
A bit surprised that no type(...) hacks are mentioned in response to the edit.
 
I wonder if the invention of the linked list is well-documented. Like, did some mainframe dudes in 1950 get together and be like, "You know what would be great?..."
The nice thing about one's profession being less than two centuries old is, it's well-documented.
 
I speak the same language as Ada Lovelace so I can witness the first debugging session as if I were looking over her shoulder. If you wanted to do the same thing as, say, a glassblower, you'd have to learn Latin and archaeology.
@poke Cool. I figured it was a 50-50 split between "it was invented by X, Y, and Z on this exact date, documented by these five research papers", or "linked lists are fairly obvious so they were independently invented roughly every two weeks by any number of randos with access to hardware"
Perhaps leaning more towards the first possibility, since I assume consumer-grade computers were not yet available in the 1950s, so the supply of randos was small
 
12:58 PM
good morning friends
why isn't this piece of code printing out the largest after a certain amount of values a put in?
#repeatedly read numbers until user enters done
#after done, print total, count and average of numbers

total = 0
count = 0
smallest = None
largest = None
while True:
   inp = input('Enter a number: ')
   if inp == 'done':
      break
   else:
      try:
         total = total + float(inp)
         count = count + 1
         if largest is None or inp > largest:
            largest = inp
         if smallest is None or inp < smallest:
            smallest = inp
      except Exception as exc:
         print('invalid input')
My input was: 10 , 4 , 2 , 1 , 0
my output was: largest == 4 and smallest == 0
 
inp ist still a string
You do convert it once using float(inp) but you never keep that result outside of the addition to total
 
Yep, simply calling float on a value doesn't cause that value to become a float in-place. This is a fairly common misapprehension.
>>> inp = "23.4"
>>> float(inp)
23.4
>>> inp
'23.4'
>>> type(inp)
<class 'str'>
Here we see that inp is still a string after passing it to float
 
cabbage
 
And the reason that this causes "4" to be reported as the largest is:
>>> "4" > "10"
True
strings are lexicographically ordered, so the string "4" is larger than the string "10"
 
Speaking of type conversions, I recently saw one like this: number = (int) (input())...
 
1:04 PM
:-I
 
Sorry, I'll keep the bad code to myself in the future.
 
ah that fixed the problem! Thanks @Kevin and @poke
i need to go google what lexicographically means lol
 
short definition: alphabetically, but for all characters, not just the alphabet
 
ah i think i remember learning this a while ago
so according to this table: 4 == 52 and 10 == 49 + 48?
 
1:08 PM
Well, you wouldn't add the values together.
 
Don’t use == there :S
 
:O
I meant as concatenation
or a representation of those decimal values
according to the table
 
For maximum pedantry I'd say "The string "10" is the character with ordinal value 49 followed by the character with ordinal value 48"
 
'4' == '\x34' and '10' == '\x31\x30'
 
ah so interesting
im saving this table, it looks like ill be using it a lot
 
1:12 PM
Hot tip: you can use the built-in function ord to find the ordinal value of any character, without having to look it up on a table on the internet
 
Whoops, the WebFaction hosting expires in 5 days, I should probably finish switching to Linode.
 
sweet baby back ribs, thats useful, thank you @Kevin
 
@davidism Hosting migrations on the last day are always the best ones
 
And chr turns the numbers back into characters. A useful pair of functions for making ciphers and such.
>>> s = "Hello, world!"
>>> "".join(chr(1+ord(c)) if c.isalpha() else c for c in s)
'Ifmmp, xpsme!'
(Yes, I know this code fails if the input contains a "z")
 
The hardest part will be figuring out the mail service, which I have no idea about.
 
1:16 PM
Those are definitely hot tips
 
@davidism I avoided that problem by going to a separate mail hoster who knows what they are doing. So I can have reliable email without the possibility of breaking everything if I mess up my webserver… (which will likely happen at some point)
If we only want to use mail forwarding (without actual inboxes), I might be able to provide that for the domain
 
Then again, no one except spammers hit the chatroom email anymore. Still probably good to have.
 
recbg
 
It's only forwarding one or more addresses to other addresses.
 
I have to check later, but I think I can do that
 
1:27 PM
Surely chr() and ord() are covered in most tutorials, no?
 
In any tutorial that makes you write a rot13 encryptor, surely. But some tutorials are more interested in drawing turtles on the screen or making very bad text adventures.
 
or something about regex
 
cbg
 
cbg
 
I prefer rot26. Twice the security, none of the effort.
 
1:34 PM
For maximum security you should have an algorithm that takes a nontrivial amount of processing time to compute. May I suggest rot141167095653376?
 
They'll never crack that one!
 
cbg \o
 
And next stop is chaining encryption: rot141167095653376(rot141167095653376(rot141167095653376(rot141167095653376(rot‌​141167095653376(PLAINTEXT)))))
 
Its power level is off the charts!
 
we should data-mine 141167095653376 to see whether it's consistent with a human using hands on a reasonable keyboard layout
 
1:38 PM
 
Appropriate since 26-triple-factorial is consistent with that show's history of endless threat escalation
 
Yeah it's like a computer game where you level up hugely...and so do even the most basic of threats
 
We're about 8 arcs past "foe that can destroy the literal entire universe", last I checked
 
Well, it's much worse if they delete the universe and also corrupt all the backups
 
Mild spoilers: the current plotline involves a fighting tournament between alternate realities, where the loser's universe is erased entirely, and the winner gets any wish. I wager 50 quatloos that the protagonists' universe will win, and they'll wish for all the erased universes to be un-erased, making the previous fifty episodes pointless.
 
1:47 PM
character development/confirmation :D
 
Perhaps they should just go nuts and wish for all the other universes' destruction
 
Goku is best friends with "The God Above All Other Gods And We're Totally Serious This Time Even Though We've Introduced Several Other Characters Before This One With This Same Title Who Turned Out To Not Be Above ALL Other Gods" so he could probably just ask politely if he wanted to destroy every other universe.
 
cbg
 

« first day (2522 days earlier)      last day (2409 days later) »