« first day (2882 days earlier)      last day (2290 days later) » 
00:00 - 16:0016:00 - 00:00

wim
wim
00:28
neat
00:57
Nice, looks like it stabilises after some time
lol i made a pythonscript that prints its own sourcecode xd
f = open("test.py","r") #opens file with name of "test.py"
print(f.read())
f.close()
 
1 hour later…
02:09
@Null congrats!
wim
wim
print(open(__file__).read())
^ easier quine
02:27
@wim quit showing off
@AndrasDeak What if you take the hallways as the space in question rather than the walls.
02:43
if a string contains only digits, can it be used in calculations?
or otherly asked: can i apply number operations to a string that contains only digits
like +1 or the like
@AnttiHaapala They "fail" by raising an exception. It's just the parent doesn't recognise this until all the processes have finished and re-joined the Queue which can take hours.
@AnttiHaapala ideally I'd like the the child's exception to be recognised by the parent and nicely exit as soon as it's raised.
I have awarded a bounty on question I had asked a week ago that still has no answer. The only answer on that question is completely wrong with regards to the question and doesn't answer the question to begin with. However, as it is the only answer on the question, I worry that it will get the bounty anyway. Can a moderator look into this?
8
Q: how is total loss calculated over multiple classes in Keras?

JonathanLet's say I have network with following params: fully convolutional network for semantic segmentation loss = weighted binary cross entropy (but it could be any loss function, doesn't matter) 5 classes - inputs are images and ground truths are binary masks Batch size = 16 Now, I know that the ...

i think one can flag an answer to be not an answer
but yeah if time is a factor...
I've flagged the question as well. But it's still pending.
flagged the answer*
I thought bounties were only awarded to accepted answers?
03:03
BUt if no answer has been accepted, then the answer with the most votes takes it, I believe. Which in my case is the answer with the -1.
i think bounties will fade if there is NO answer
it's sort of marketing your question for a week
so if noone else answers the question AND the other answer gets deleted, you gain nothing
@Null no, in Python strings are not automatically converted into numbers when you try to do maths with them. You need to convert them explicitly.
@Code-Apprentice thanks
@Jonathan I think the answer with the most votes and a positive score gets the bounty
@Null of course, you can always try this kind of thing yourself. Type "python" at the command line and start typing code
for example:
>>>> "123" + "46"
i see " and ' used for strings, are they interchangable?
03:14
I see, thank you. If I had more bounty to offer, I would. But i'm already low on rep, so I don't want to waste it too quickly. But the question has received good amount of attention. It'd be nice if one of the big dogs could add some extra flavor in there.
projecteuler.net/problem=23 oh man, i can't understand the question, reminds me of my math study. wall of textes :D
and this is an "easy" rated problem
don't know what to expect of hard problems :o
04:52
can someone look over my code? for problem 5."Modify the previous program such that only multiples of three or five are considered in the sum, e.g. 3, 5, 6, 9, 10, 12, 15 for n=17"
n=input('Give me a positive integer please.')
b=2
c=0
while b!=int(n):
    b=b+1
    if b%3==0 or b%5==0:
        c=c+b
print(c)
it gives the correct result but is it coded ok?
seems good to me
as you learn more programming, you will also learn what constitutes "clean code"
but for now don't worry too much about it. Just make programs that solve the problem at hand
05:09
mmh, i get an error:
hi any one here who could help me
for this code
import math
a=input('Give me a positive integer please.')
n=int(a)
b=input('Do you want to calculate the sum(1) or the product(2) of 1,...',n,'?')
c=int(b)
if b==1:
    print('The sum of all numbers from 1 to',n,'is',n*(n+1)/2,'.')
else:
    print('The product of all numbers from 1 to',n,'is',factorial(n))
"Give me a positive integer please.6
Traceback (most recent call last):
  File "C:\pythonprojekte\adriann\Elementary\6\1ton.py", line 4, in <module>
    b=input('Do you want to calculate the sum(1) or the product(2) of 1,...',n,'?')
TypeError: input expected at most 1 arguments, got 3"
hello Code-AAprentice can you help me
just post your question @sachinsafale
I have a website which has huge data of doctors and other specializations. For example when i search with a city, it found 300 results but it only show up 90 results. 90 results is the maximum number for a search for for a city. Sample link of a city: https://www.jameda.de/search/stadtbergen/aerzte/innere-allgemeinmediziner/fachgebiet/

It shows only 90 results which i can scrape but dont know how to scrape the entire contents like the 322 results
05:16
pinging everyone is a quick way to get yourself banned from this site
or at least to get muted^^
ok sorry but was in real need for a help
annoying other people isn't a good way to get help
I have a function called remove_pattern(hastebin.com/lebadunifi.py) that I've profiled and would like to see if it possible to optimize this a little further. Reading from a file of about 30,000 lines, it took about 5 seconds and most of those 5 seconds was on the re.sub method; That part of the function was called about 9000 thousands time. So that is where optimization needs to happen. Any ideas?
@Null your line 4 function input() argument should be only 1.
'Do you want to calculate the sum(1) or the product(2) of 1,...' is one argument
n is one argument
'?' is one.

if you want to show n value in the input prompt, you can do the following
b=input("Do you want to calculate the sum(1) or the product(2) of 1,...,{},?".format(n))
user6344468
05:18
@sachinsafale It seems like the page uses lazy loading. You need to click "Mehr anzeigen" (meaninig "load more?") button. So the HTML does not contain the whole list of results. You may need to use headless browser, not simple scraper.
@Null i have clicked Mehr anzeigen and gives 90 reusults only after that there is no option to Mehr anzeigen load more
@ThuYeinTun thank you
@Null please use a paste site for future code snippets
@Code-Apprentice ok, i thought it was "short" enough, but i will in future
user6344468
@sachinsafale So that's what the page provides. The website is built for human, not for scrapers. Limiting the number of search results can be the specification as humans rarely enumerate all the search results often.
user6344468
05:25
and I'm not him (at Null)
@umainyosu so is there any way out where i can get all the records. and sorry for wrong tagging
user6344468
@sachinsafale How the data are shown is controled by the website owner. You may need to ask the website owner to how you can get them all. But if they decide not to give you the all data, there are no legal ways. It's not a technologial problem. Or find another website/dataset that allows you to collect similar kind of data. In US or Japan, local government provides some data (so called "open data"), so you may want to check it out.
ok thank you @umainyosu
05:44
good-o evening-o
how can I print this multiplicationtable nicely with tabs but without the nasty effect that my lines are too big?
oh lol nevermind
i failed to realize you can maximize the console of python =)
I found a serious contender for the worst python tutorial: youtu.be/N4mEzFDjqtA Jump to anywhere in the video and you'll most likely find some awful coding practices. This thing is worse than LPTHW.
06:02
does mathematica give me any insight on learning how to program or is just a nice way to make oneliners?
06:23
can someone review my code for "Write a guessing game where the user has to guess a secret number. After every guess the program tells the user whether their number was too large or too small. At the end the number of tries needed should be printed. It counts only as one try if they input the same number multiple times consecutively." pastebin.com/nTHuP5gh
i think it is doing what it should do
First of all, you should use more descriptive variable names than a, b, c and n
Secondly, you don't need b. If you want to exit a loop, use the break statement.
like:
else:
break?
And finally, you may want to add some error handling around int(input(...)). Show a nice error message if the user input isn't an integer
This is how I'd do it: pastebin.com/8eLqfYwj
Hi guys. Do you recommend me doing Open World FP Shooter game in python and are they any platforms on py?
is this valid?
if guess != last_guess:
        guesses += 1
i mean exactly the "+=" part
(just asking, could be a typo)
06:35
You could try it and see if it works
yep it works
but never heard of += :D
i guess it means guesses=guesses+1?
++ doesnt work in python?
+= started in C, I guess :D
06:49
a+=2 works as +2, nice function indeed
is LPTHW really that bad?
07:21
cabbage
@KoboldMines yeap and it was originally even written as =+ :D
> For example, B introduced generalized assignment operators, using x=+y to add y to x. The notation came from Algol 68 [Wijngaarden 75] via McIlroy, who had incorporated it into his version of TMG. (In B and early C, the operator was spelled =+ instead of += ; this mistake, repaired in 1976, was induced by a seductively easy way of handling the first form in B's lexical analyzer.)
is this a good solution for "Write a program that prints the next 20 leap years." pastebin.com/mSKVSzf4 or can i somehow circumvent the need of "a"?
07:36
There you go again with your undescriptive variable names
oh sorry
i didnt remember
But no, I don't think there's a way to do it without that variable
The only obvious improvement I see is to get rid of the break and use while a < 20:
Slightly. If you use a while loopbreaker < 20: loop, it's obvious that the variable is used to exit the loop. What's not immediately obvious is that the variable counts the leap years, so I'd name it num_leap_years or leap_year_counter or something like that
ah, makes sense!
at the elementary problems number 11: adriann.github.io/programming_problems.html will python have no problems since its arbitary precise?
07:47
Well, you can use the decimal module to get "infinite" precision, but I don't think you have to. Just use a float; I don't think anyone cares if you lose a few decimal places
mmh, how is the variabel under the summation sign called again?
i can't remember the term
wait lol, this is PI as i now see it :D
(i forgot to multiply by 4)
08:04
taken from "https://en.wikipedia.org/wiki/List_(abstract_data_type)" does "countable" in "that represents a countable number of ordered values," mean countable in the sense of mathematic? i.e. the list can very well be infinite
08:23
i need some Django rest framework help regarding authentication, REGISTRATION WORKS FINE, but LOGIN doesnt work.
I think the problem is in *serializers.py*. The error thrown is {
"errors": {
"error": [
"A user with this email and password was not found."
]
}
}
Meaning the authenticate() method doesn't work ,
09:10
can a list be of a dimension higher than 1?
is there any clever way to map a function on one property of an object from the list?
e.g map([(1,2),(3,4)], lambda x: x[1] = f(x[1]))
I was thinking something like Haskell's traversed Lens
so my desired syntax would be something like map(traversed(xs, << some way to express x[1] >>), f)
There's itemgetter(1), I guess you could manage to get something together with that.
09:26
@coldspeed it's a Fourier expansion of a single step of the Hilbert curve construction, so it should converge, just like any other reasonable Fourier series
@Code-Apprentice yeah, I realized that's how it's meant in a labyrinth context
@Null wrong answers are answers. "Not an answer" flags are for garbage or link-only answers. Mods don't handle technically wrong content (cc. @Jonathan)
@BartekBanachewicz But on the other hand why not just [(x, f(y)) for x, y in ...]?
@IljaEverilä only works for simple tuples
@Null no and no
why is this not working as intendet? pastebin.com/fHfUuYB8 the crucial part is "range (0,size_of_list):" does make the same as "range (0,0)"
the goal is reversing a list
754
Q: How can I reverse a list in Python?

Leo.peisHow can I do the following in Python? array = [0, 10, 20, 40] for (i = array.length() - 1; i >= 0; i--) I need to have the elements of an array, but from the end to the beginning.

09:37
L.reverse() works also for arrays, nice one :)
in the question array = [0, 10, 20, 40] is a list. Don't let wrong terminology mislead you
oh, are all lists arrays, but not all arrays lists?
There are arrays in python but lists aren't that
Lists are lists, arrays are arrays
There are no array literals
ah ok
@BartekBanachewicz You can use iterable unpacking to support longer tuples:
>>> your_list = [(1, 2, 3, 4), (11, 12, 13, 14)]
>>> [(a, f(b), *rest) for a, b, *rest in your_list]
[(1, 'f', 3, 4), (11, 'f', 13, 14)]
09:48
@Null true arrays are bytearray, array.array (both stdlib) or numpy.array (third-party)
@Aran-Fey interesting, but still doesn't help with e.g. dicts
and especially nested structures
@BartekBanachewicz define a function that does what you want?
Well, a recursive structure's gonna require a recursive function. Python doesn't have a builtin recursive map or anything of the sort
10:08
also how can i circumvent the manual input?
I don't understand the question. There's no list of strings anywhere in your code.
10:49
@AnttiHaapala honestly bro, how do you know that. did u really have interests and read all that stuff about B C Mcllroy and other theories? :D
here's a tip: calling people "bro" on Stack Overflow will usually not work as intended
is this a good function for "Write a function that returns the elements on odd positions in a list." pastebin.com/8CcYXKd5
Does it work?
yes
@Null it depends what you mean by "odd positions"
11:00
0 being the first position
0 is even ;)
yeah but listing[0] yields the first item of a list
0 can't even
hence better be clearer with your terminology
I sure love using hence now.
Would you say it enhances your speech?
11:12
i'm sure there exists something like total(some_list) but i made my own function in case i ever have to show that i can. so, is this function ok for "Write a function that computes the running total of a list." pastebin.com/YVj58WPh
It's ok, but it could be better. Don't use range to iterate over a list. You don't care about the indices, so just iterate over the list directly: for x in some_list: total += x
Or just use sum
thanks @Aran-Fey
11:43
@Aran-Fey does "for x in some_list..." mean : for all elements of some_list ?
(do that)
jpp
jpp
0
Q: Generic "Don't Do It" Answer

jppWe see many questions each week, often multiple questions a day, asking to use a library / tool / language / feature in a non-recommended way. According to this Meta SE answer, "Don't Do It" with an explanation is a valid answer. Specific case I'm focusing on pandas to demonstrate the problem, ...

Thought I'd share as you guys might have some comments
if a file contains multiple functions, can only one be imported by a pythonscript?
(if for example i only need one specific)
absolutely
e.g. from random import randint
That's a valid question, sorry
@Chillie That'll import the whole random module anyway, though
11:59
are those imports impacting the filesize of a compiled program?
You can't import a part of a module without importing the entire module
well, i could imagine an importfunction which can:
@Null what do you mean by "compiled"? How do you compile Python code?
oh, is that impossible?
@vaultah how is everything else inside the module treaded? does it not enter global namespace?
* treated
12:03
anyway, the new importfunction would do this: read(big_module)-> search(small_module)->save(small_module_to_file)->import(file)
but thats retarded xd
@vaultah i thought its possible as google suggests :/ google.com/…
There are different types of compilation, hence my question
ah, i'm not really into compiling, so i can't say
i just think of it "make me a standalone program of that glibberish i wrote down"
@Chillie it just doesn't enter the namespace that you imported the module from
(as in the caller)
@vaultah so if i have module.mod in the same folder as the python script, can i import it by writing "import module.mod"?
Usually, yes
12:19
"When I import one function from a module, why does Python have to interpret that entire file instead of just that function, and the functions / global values that function depends on?" is equivalent to asking "why can't Python solve the Halting Problem?". You can't tell at parse-time what variables a function will require, so the only safe option is to include all variables.
@Kevin ah i didnt thought of modules where functions are building on each other
how can i add a second argument in a definition of a function, simply this way?:       def coolfunction(argument1,argument2)
Try it and see
Hello, simple question: just these two lines, no more code for time being:
import smtplib
server = smtplib.SMTP('smtp.gmail.com:587')

Result:
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

last line of the traceback. This attempt of connecting to GMail's smtp is taken from some example snippet, so I guess sonmebody did just that and it worked for him. What am I doing wrong?
I don't trust the average snippet of example code found online to actually run
Possible explanations:
-The code never worked, and the guy just made up a random url without checking it
-The code used to work, but the url changed
-The url hasn't changed, but that server is down for maintenance
-the code works on that guy's machine, but not on yours because they're configured differently
12:37
I tried other url for the SMTP (other email service provider) and the situation is the same
server = smtplib.SMTP('smtp.gmail.com:587') works on my machine, so the "configured differently" explanation is probably the real one.
I wonder if gmail (and other service providers) limit smtp access by country. Are you in the US?
I'm in Poland, I'm really a noob in networking, but I guess if mail client (the built-in one for Windows 10) works fine with this SMTP setting...
If software other than Python can connect to that mail server, then that implies it's not an IP-blocking problem. hmm
(unless that other software is quietly establishing a proxy in another country and making requests from that, but I doubt it)
OK, maybe someone has any other idea? The thing is I'm trying to write a really simple script monitoring the content of a file downloaded by curl and if it changes, it's supposed to notify me about it. Maybe instead of trying this solution that sends and email with smtplib I should jasut try some other solution, maybe it would be faster that way? Any ideas?
12:52
I tried also
server = smtplib.SMTP('smtp.wp.pl:465')
(a polish email service provider) and the result is the same:
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

This could rule out region blocking
If this was an HTTP question and not an SMTP question, I'd blame the user agent string. But I don't know if smtp has anything equivalent to that.
Maybe smtplib.SMTP() constructor tries some initial authentication by default?
@Null If it runs and produces the correct output, yes. If not, no.
@Kevin hehe :D cbg for you :-d
Perhaps you're thinking "well yeah obviously, but actually what I was asking was 'is this the most concise/idiomatic way to solve this problem?', which I can't verify on my own". That's forward-thinking of you, but perhaps puts the cart before the horse. I think it's OK to write imperfect code when you're still learning the ropes of basic syntax. It is written: perfect is the enemy of good.
That said, if I was tasked with printing the perfect squares between 0 and 400 inclusive, I'd probably do something like for i in range(21): print(i**2) and forego writing any functions or importing things
array in particular, you should almost never need to import. Remember that arrays and lists are very different things.
12:59
i just learned how to make a function which handles multiple inputs
the printing was inefficient i agree
anybody here knows to use Django?

I want to have a query something like this

Find all the tests where the category is banking and display is either 'open' or 'register'

I am not sure how to do that "OR" part. This isn't working either.

tests = Test.objects.filter(category = category, Q(display = 'open') | Q(display = 'register'))
@Null Ok, now that I actually read the problem, no, your code does not satisfy the requirements. on_all is supposed to call the funtion on every element of the list, but your on_all implementation doesn't do anything with some_list at all. You just call the function on every number between 1 and number. Your program only produces the correct output by coincidence, between some_list also happens to contain every number between 1 and number.
@Kevin why do listcommands work on arrays?
I should be able to call on_all(perfectsquares, [23,42,99]) and get back 529, 1764, 9801, for instance
13:05
@ShubhamNishad tests = Test.objects.filter(category__in = ['open','register'])
@Kevin indeed
was a misunderstanding by me
BWHAHAHAA @ "django has such good documentation": when this is the most thorough documentation for Q objects
@Null What's a listcommand? Incidentally, I notice that although you import array and call array.array('i'), that doesn't have any impact on the rest of the program. range still doesn't return an array, for instance.
@Chillie, do you mean tests = Test.objects.filter(category=category, display_in=['open','register']) ?
yup!
13:07
@ShubhamNishad no, it is display__in
the double underscore is important
@ShubhamNishad you should read this
@Kevin oh i think i misunderstood arrays and lists
reading Django ORM makes me sad and happy at the same time. Makes me feel sad that so many people are stuck with that pathetic excuse for an ORM that calls a SELECT query that contains an OR in WHERE an advanced query
13:10
Gotta go fast
I think @ThiefMaster wanted to be pinged if this kind of thing happens, right?
@Chillie thank you buddy. It worked :)
are files technically a list if they contain x lines? or are they just raw input?
Files let you iterate over their lines, so they're iterables. But they're not lists. Lists are a different kind of iterable.
13:17
There are many types which behave like lists in some ways, and do not behave like lists in other ways. For instance, strings are iterable in the same way lists are: for c in s: print(c) works regardless of whether s is a string or a list. But strings do not support indexed assignment the way lists do. my_list[0] = 'A' works, but my_string[0] = 'A' doesn't. File objects are another type that shares only some behaviors with the list type.
@ThiefMaster You wanted to know about the spam, right?
You can determine whether an object is a list (or an instance of a subclass of list) by doing isinstance(obj, list)
@Null has somebody had an "everything is an object" talk with you yet? :D
@Chillie no hehe
>>> isinstance(open("test.py"), list)
False
>>> isinstance("foobar", list)
False
>>> import array
>>> isinstance(array.array("i"), list)
False
>>> isinstance(range(10), list)
False
>>> isinstance([1,2,3], list)
True
13:21
@Kevin oh, the obvious test hehe
didn't thought of it
@Andy let it be noted that the said user wants a one year ban ;)
why doesnt this work (as intented): 0bin.net/paste/… i want the characters to be shown, not their asciicode
Not all characters have a printable representation.
For instance, "\x01" is the "start of heading" ascii character. You won't find that on the average keyboard.
hehe^^
can i make a function that correctly interpret as many arguments you want? like crazyfunction(1,2,...,n) while n is going to infinity
271
Q: Can a variable number of arguments be passed to a function?

David SykesIn a similar way to using varargs in C or C++: fn(a, b) fn(a, b, c, d, ...)

13:32
*args and **kwargs also described here
is function(list1,list2):list1+list2 a cheat to "Write a function that concatenates two lists"
or is adding lists a basic operation?
Define "basic operation"
If you're saying "isn't it kind of pointless to write a function to add two lists, when I can do it effortlessly with just the '+' operator?", yes, it pretty much is pointless. Sometimes you get pointless assignments when they're written without a particular programming language in mind. What is easy in one language may be very hard in another.
what does seperate the + in 1+1 from the one in (1,2)+(a,b)?
the on_all method from your previous problem is similarly pointless because Python already has the map() function
@Null As in, how are they conceptually different? They aren't.
forgetful cbg \o
13:41
i hope i won't ever need to learn assembly :o where everything is a huge pain in the ass lol
well actually i guess you can import there too, so its just a pain at the beginning
@Null in one case it's 1.__add__ and in the other case it's (1, 2).__add__
If you want to see which arguments are defined on an object, you can get them with dir(some_thing)
14:01
if i change the base in which i store numbers can i calculate bigger numbers than before?
well this question probably doesnt belong to python
Python has arbitrary-size integers already, so you don't need to do anything special to calculate huge numbers.
@Null the question doesn't really make much sense :D most computers are binary-only computers and store binary numbers only. If you were to store in some other base, then you're only going to use more space, however it would work...
And anyway there's no way to change the base in which integers are stored. "But I notice I can do both x = 23 and x = 0b10111. Doesn't the first one create a decimal integer, and the second one create a binary integer?" you hypothetically ask. No, both of them create the same integer. The base that you specify when you write an integer literal does not "carry over" into its internal representation.
but if i want to save a huge amount of different numbers in a file, its better to choose a good base for it or?
ah ok sry then
you don't store 111110000000000000000000000111110010010101010010100101 in file like that :D
14:06
ah well if one cares about filesize one can always compress i guess
Serializing the data to a file is another matter. If you're saying "isn't it inefficient to store a number in a file using only the characters 0-9? Then I'm only encoding 3.3 bits of data per character, when they can theoretically store eight", that's a valid observation.
@Null you should read a book. or 10 of them,
cbg @AndrasDeak
then you will make better questions.
14:07
what Antti said
using the room as an online tutorial service only works to a point, and I feel we're getting way past that point
@AnttiHaapala a theoretical book?
when I learnt programming, I was kid 10-15 years old, I didn't have anyone at all that I could have asked questions.
I went to this thing called library and the shelf that had the sign 61.39 PROGRAMMING and read books from there.
@AnttiHaapala You sound like an old man complaining about the new generation :P
he is, but that doesn't imply he's wrong :P
@Aran-Fey <span class="attention" style="width: 0" />.
14:09
Why is your span a singleton tag? :P
0
Q: Python built-in base-256 to base-10 conversion and vice versa?

W. AlbuquerqueI want to store large numbers (200-300 digits +) in a text file, so I want to know if there is either a built-in function that converts base-10 numbers to base-256 equivalents and vice versa in Python, or whether there is a module that supports this (much like the default hex() function).

^One possible way of getting the maximum utility out of a byte in a file
Hmm, is there anything wrong with defining an __radd__ method like this? Any risk of endless recursion or anything like that?
def __radd__(self, other):
    return self + other
hi, I have a doubt
Is the init method in python a constructor?
Effectively.
Oh - and self is the same as 'this' in java right?
14:18
Technically it's an initializer. The constructor is __new__
self and this serve the same purpose, more or less.
Although Python lacks the magic implicitness that allows Java to access this without requiring it to be passed in as an argument
@Aran-Fey but ____init____ does the same as a constructor does, right?
AFAIK most other languages don't even separate the constructor from the initializer like python does, so... I guess?
@Aran-Fey Might lead to endless recursion if other also implements __radd__ in the same way, and if neither class implements __add__
If I had know this, I'd never have struggled to understand what 'self' was. It just confused me that self had to be passed as a parameter.
14:21
>>> class Fred:
...     def __radd__(self, other):
...         return self + other
...
>>> class Barney:
...     def __radd__(self, other):
...         return self + other
...
>>> try:
...     Fred() + Barney()
... except RecursionError:
...     print("oops")
...
oops
@Kevin I guess I should've mentioned that, but my class implements __add__. If it didn't, my __radd__ would be quite nonsensical (:
I notice Fred() + Fred() merely raises a TypeError, which I am a little confused about
Fred and Barney are ostensibly identical, so why does Fred() + Barney() have a different outcome than Fred() + Fred()?
what is radd ?
@Aran-Fey I'm 95% sure it's safe if you implement __add__.
it's for making your objects raddical 🤘
3
14:24
@UmeshKonduru "reverse add". Called when you add two values and the first value has not implemented the regular __add__.
Lol, to be honest, I do not what ____add____ is either
FWIW I decided to change my __radd__ to return self.__add__(other) simply because it gives a better error message.
class Foo:
    def __add__(self, other):
        return NotImplemented

    def __radd__(self, other):
        return self + other

class Bar:
    pass

print(Bar() + Foo())
# TypeError: unsupported operand type(s) for +: 'Foo' and 'Bar'
(Notice how Foo and Bar are swapped)
See also: docs.python.org/3/reference/datamodel.html#object.__radd__. Which also answers my Fred/Barney question. radd doesn't get called if both objects are the same type.
@Kevin I thought it was "right add"
@AndrasDeak Maybe. The documentation isn't explicit on the matter. The only relevant R-word in the description is "reflected", so that's another candidate.
14:28
I just checked out - I guess it is supposed to be "reflected"
I can't think of any other words it could be
That might make a good trivia question. "when do two classes with identical implementations have different behavior?". Not sure how to word it to disqualify answers like "print(Fred()) and print(Barney()) have different outputs" though
You could just say "aside from repr or print", unless there's other examples like that. I can't think of any.
Or just "disregarding anything to do with the class name itself", unless the class name is also used for some edge case
@KevinMGranger __name__ and __qualname__ and id
It's also a little tricky to make it clear that "Fred() + Fred() crashes with TypeError and Fred() + Barney() crashes with RecursionError" is the intended solution
14:34
And __code__.co_firstlineno
... Since the reader is probably thinking that you have to replace all instances of Fred with Barney in your sample code or else it doesn't count as "using one in place of the other"
Fred()+Fred() naturally has the same behavior as Barney()+Barney()
If you say "you're allowed to replace only one instance of Fred with Barney if you want, btw" that's kind of giving away the game
You could phrase the question like "In what scenario does replacing an instance of class A with an identical instance of the identical class B change the behavior of the code"
We can add clarifications and exceptions until the cows come home, but a good trivia question is concise, so we've already lost
wim
wim
^ I feel like I'm missing some kind of "fat diagonal" utility function in numpy
is there such a thing?
DSM
DSM
You could look at it as a Toeplitz matrix, I guess.
In [135]: scipy.linalg.toeplitz([1] + [0]*(n-k), [1]*k + [0]*(n-k))
Out[135]:
array([[1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 1, 1, 0],
       [0, 0, 0, 0, 0, 0, 1, 1, 1, 1]])
(Too lazy to check whether I have an off-by-one error there or not.)
14:44
Hope you guys don't mind that I gave that user what they asked for..
DSM
DSM
Looking at your comments I'm not sure I agree that summing a bunch of matrices is "needlessly inefficient", wim -- I've found it's often the cleanest way to assemble a custom matrix from the collection of matrix construction tools at hand, and it's almost always 0% of the time taken.
I came up with [[int(0<=i-j<k) for i in range(n)] for j in range(n+1-k)] but I find it rather opaque so I don't want to post it
DSM
DSM
Also maybe np.triu(scipy.linalg.circulant([1]*k + [0]*(n-k)).T)[:n-k+1], which is fun but hideous.
Someone else can do it if they want to take the heat from commenters asking about maintainability
@MartijnPieters Nope, won't miss 'em. Thanks.
DSM
DSM
14:53
I actually don't mind your listcomp. The int(0<=i-j<k) part seems actually pretty clear.
Incidentally, does anyone else get irrationally worried about the relative precedence of plus and minus, and go out of their way to write A+B-C instead of A-C+B, just in case the interpreter goes crazy and reads the latter as A-(C+B)?
DSM
DSM
No.
Really I think it's more for my benefit than the computer's
Remembering that plus and minus have the same precedence takes 1ms of brainpower, so it's optimal to arrange terms so I don't have to fetch that piece of information to begin with
Gotta keep my mental cache stocked with actually useful information
As usual, the fact that I spent more than ten seconds talking about optimization means that I've already lost all the time I would accumulate from using that optimization over the course of a year
DSM
DSM
I do tend to use unnecessary parentheses, but I do it to group terms conceptually. Various members of my team say I use too many local variables but I like to give things names..
Unnecessary parens are very necessary for me when it comes to more obscure operators, whose relative precedence is less obvious than plus vs minus.
15:07
oh shiny new tool SO rolled out. stackoverflow.com/jobs/salary Makes me kinda depressed on my salary since I would be placed in the 5% of lowest income
can't be depressed because they don't have my region ¯\_(ツ)_/¯
AD's star'ed Hilbert Curve my god.... that last one was so nice to look at.
Not going to click that salary link, as I can already get my daily intake of sadness without having to intentionally seek it out
Umm... we've got a fair few groupby's... anyone happen to know one that'd cover stackoverflow.com/questions/52207120/… ?
That Hilbert Curve is interesting, but I wonder which is the case:
1. There is something special about the Hilbert Curve that makes it especially easy to construct in this way
2. You can construct pretty much any image you want, as long as you plug in the right parameters
15:13
cabbage
(Not necessarily mutually exclusive. Maybe the parameters for the Hilbert Curve are much more elegant than what you would require for the average arbitrary picture)
user10043886
Hi, you guys have a really nice website: sopython.com/chatroom! May I know who maintains/hosts the site? :)
I seem to recall one to group "non-empty" strings which is basically the same - just so it shows some criteria and then using the if k bit for it...
@Blue do you mean who wrote it (it's available on github) or who edits it ?
user10043886
@JonClements Both :P
user10043886
I was wondering if we could create a similar site for the Physics SE main chat
user10043886
15:16
Is the source code available in the public domain?
user10043886
Also, is someone paying to host the site?
well...mostly davidism for developing it in the first place... but in terms of content such as the wiki and common questions and stuff... that's done by editors that are generally regulars here/otherwise generally enthusiastic python askers/answerers on SO
@Blue Let's see... It's not licensed under public domain, but it does have a sort of "copyleft" license that lets you modify/redistribute it under certain terms. Check the github page for more information.
user10043886
Thanks, checking out the GitHub page :)
15:19
IIRC, yes, someone is paying to host the site. It is written: No such thing as a free lunch.
user10043886
@Kevin Ah, makes sense
15:56
@JonClements well, to be frank, I am pretty sure the editors are enthusiastic/or not answerers, period. :D
okay Frank :p
there are not that many people who are enthusiastic askers more so than answerers beyond newbies...
00:00 - 16:0016:00 - 00:00

« first day (2882 days earlier)      last day (2290 days later) »