« first day (3891 days earlier)      last day (1040 days later) » 

12:46 AM
cabbage
 
 
1 hour later…
2:06 AM
Hi guys, I would like some suggestions on how to achieve this loop:
Basically in my dataframe, I want to go through each date and do some processing based on the string value of a certain column of the dataframe...
day_type_labels = ['cloudless', 'mostly_cloudless', 'broken_clouds', 'cloudy']

date = df.Date.unique()
ind_date = df.Date == date[0]

for i in range(len(day_type_labels)):

    if df_final[ind_date].Day_type.all() == day_type_labels[i]:
        print('s')
but the issue is that when for example the if condition fails the first time, it jumps out of the loop,,
I tried using
else:
continue
but that also doesn't work..

I am open to any suggestion :)
 
2:20 AM
Nevermind guys, I made typos in the labels I was checking against. :P
Works now
 
 
1 hour later…
3:31 AM
When people say "runtime" what are they talking about? The interpreter that executes your script or the interpreter that executes your script plus the OS state at execution?
 
4:17 AM
it's one of those ambiguous terms that they need to clarify - it could be all of the above.
 
Thanks. There is an SO post on it that I found which clarified somewhat but it was for C++. I kind of get it.
I always use venvs so, to me, the runtime is just whatever venv I'm using
 
well, it would be the python interpreter that is currently executing inside the venv being the runtime, typically it won't be just an environment sitting around
 
Your saying the specific instance of a venv, aka a single enviroment, I see
 
to be clear, both your initial examples involve an "interpreter that executes" - a runtime implies an execution of some tasks - the "execution of some tasks", with the emphasis of execution (i.e. the thing that runs that execution), typically is referred to as the "runtime"
so in the context of Python, it can be the Python interpreter, the Python interpreter plus the script it is currently running, and so on so forth down, and also back up (i.e. including the OS state, hardware state, though typically it isn't considered that far up).
hence the ambiguity
 
Ah ok, I see
 
4:28 AM
or heck, there is a literal SO thread on this stackoverflow.com/questions/3900549/what-is-runtime
 
Yes I saw that. I do appreciate your input as well
 
4:51 AM
Habanero! runtime, library, framework, etc
 
 
1 hour later…
6:11 AM
Hi everyone, I am trying to connect to something called AppTweak and am getting the following error
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.18.0</center>
<script id="IntercomSettingsScriptTag">
Does anyone know how to get started in debugging this?
The authentication creds are correct
 
6:34 AM
cbg
@RaphX I believe this would indicate its not on your side but rather an error server end... then again I may be wrong
 
so there is nothing I can do ? @Kwsswart
 
Don't think so unless it has something to do with the proxies you are using, once again potentially somebody else here knows more but seems like it developer.mozilla.org/en-US/docs/Web/HTTP/Status/502
 
7:29 AM
Is it safe to say that say that every tkinter widget is a subclass of the Widget class ? So Widget class is the superclass ?
 
7:53 AM
Is there some way to use Python's new parser? Ideally the meta-parser itself, not just the specific one for Python source? I see that the old parser module is being deprecated but there doesn't seem to be a replacement.
 
@RaphX You probably can't. 500-based errors are server-side. Unless you've passed your credentials in a borked way that upsets the server so much that it can't handle the request, that's likely to be the end of the line in debugging
 
8:43 AM
@CoolCloud "The Widget class is not meant to be instantiated, it is meant only for subclassing to make “real” widgets (in C++, this is called an ‘abstract class’)." docs.python.org/3/library/…
 
Hmmm every widget does inherit from the Widget class, so does it not make this class the superclass?
 
from what I know of abstract class, they are meant to be inherited (which I believe makes them a parent) and override the abstract methods in the child, but I know nothing in specific to tkinter
 
Hmmmm because a basic isinstance(tk.Button,tk.Widget) returns True.
Anyway thanks for that, I learned/revised what abstract class is, today
 
@CoolCloud yes. A inheriting from B means that B is a superclass of A and that A is a subclass of B.
 
just checked, that isinstance(B(), A) is indeed True when B is a child, A is abstract
 
8:50 AM
Cool Cool
@MisterMiyagi Nice, I probably have to start diving into intermediate tutorials for python
 
on that note Any body got handy ideas to practice and become familiar with closures and decorators that would be easy to incorporate within everyday work
 
what are closures?
for studying decorators, just try to understand chat.stackoverflow.com/transcript/6?m=52199937#52199937, after that you should know everything there is to know about decoration
on a serious note, reading the pep would be a good starting point python.org/dev/peps/pep-0318, and realpython has some slightly better examples of a good use cases: realpython.com/primer-on-python-decorators/…
 
9:26 AM
@Arne nonlocal variables.
 
so becoming familiar with them in python means "when I write a name, where will the interpreter look in order to resolve it"? or things like lambda x=x: x stuff?
 
10:09 AM
@Arne o.O
thanks for that will definitely read through the pep and realpython
 
Anyone got an Idea whats happening here?

`docker build --build-arg "date=$(date)" --build-arg "version=$(git rev-parse --short HEAD)" -f Dockerfile_optimized --tag test_1 .`

and with docker inspect:
`>"version": ""`
It doesnt parse my bash command :/
Fixed it... Sorry.
 
10:55 AM
Please read how to format code here
 
11:25 AM
cbg , I am trying to captilaize the latter half of any given string using the function below.However to my suprise the function works only with the string : "geeks for geek" ; the string : "apples" remains unchanged.Can anyone explain why is this happening?
def func(str):
    "Capitalizes the latter half of the string"
    for i in range(len(str)):
        if i == (len(str)//2):
            str2 = (len(s)//2)
            str3 = str[str2:].upper()

    print(str[:str2]+str3)


s = "geeks for geek"
s2 = "apples"
func(s2)
func(s)
 
len(s) should be len(str)
 
@Aran-Fey Thanks :)
such a silly one
 
11:51 AM
Do we have a good canonical duplicate for people writing x=1,y=2 when they need x,y = 1, 2 (or just two separate assignment statements)?
 
I don't think I have come across that ever, is that a common beginner mistake?
 
@TanishSarmah you don't really need the loop in this. str[:len(str) // 2] + str[len(str) // 2:].upper() should do.
@user2357112supportsMonica I assume most such questions end up as typo closed.
 
Isn't x=1; y=2 same as x,y = 1,2 ?
 
Good morning everybody
 
@CoolCloud yeah but the question is about using a comma instead of the semicolon
 
12:00 PM
Oh, okay.
 
It's pretty common. int x=1, y=2; is how you would declare and initialize two int variables in languages like C or Java, so plenty of people end up trying the same thing in Python.
 
12:16 PM
@TanishSarmah note that using str as a variable name shadows (supresses) the built-in str, so you shouldn't use str as a variable name. It's not too bad here, because you only used it within a local scope, but something to keep in mind.
 
thanks @roganjosh
recbg
 
@Don'tAccept Please read our rules here before asking question.
 
What according to you all is the best tool to automate workflows? For example, Airflow, Luigi etc.
 
@Don'tAccept It looks like you already got help. The link even points to one of several answers.
 
@CoolCloud, okay I'll. This is the first time I entered the room that's why
@MisterMiyagi, yes I have received the answer, and all the answers are indeed good, I was just wondering if there could be even a better answer
@CoolCloud, where can I find the rules?
 
12:29 PM
Ummm I linked it there?
 
@CoolCloud, oh yeah. I got it
 
1:11 PM
@user2357112supportsMonica I suppose, but then they instantly get SyntaxError: cannot assign to literal, so I expect quite a lot of them think "I guess that's not something I can do, then" instead of asking a question about it.
On the other hand, if they're wondering why x = y, z = 2 gives them TypeError: cannot unpack non-iterable int object... That's not as easy to figure out on one's own
Hmm, and x = y, z = [1,2] runs with no error at all... I must write that one down in my underhanded techniques notebook
 
let's hope no one is unfortunate enough to try x = y, z = [1, 2] without realising...
 
I rub my hands devilishly
 
@Kevin I was able to complete the conversion of the script but sadly the results from the template matching are quite different from the original script. Have the patience and time to revise it one more time with me?
 
I'd like to say "surely it's not too common for even newbies to accidentally write x = y, z = [1, 2], because it's common sense that x = y is not very useful even when it works", but I've seen enough counterexamples to know better
@butexa Sure, I can take a look. I fear that we're reaching the limit of my Java and OpenCV abilities, but I'll give what tidbits I can
 
@Kevin Thanks again! I am already in the chatroom
 
1:36 PM
I have constructed a small assembly-like language that is unremarkable except for a maybeCall <addr> instruction, which only jumps to addr half of the time*. Much to my surprise, it has actually solved the problem I was working on.
It's very Quantum I think
 
1:50 PM
I'm curious what problem this could solve
 
I'm still playing around with parsing Context-Free Grammars. If your grammar has optional elements, then it's convenient if your parser can maybe try to parse that element, and maybe not.
 
@Kevin I use that construction from time to time. But I usually write the tuple in parentheses to make it a little clearer: x = (y, z) = [1,2]. Or comment it.
 
As a simple example, consider the grammar that matches the language "one or more A's, followed by the same amount of B's": s := 'A' [s] 'B'. In my fake assembly language, this translates to:
call parse_s
expect $
exit_succesfully

parse_s:
expect A
maybe_call parse_s
expect B
ret
the "expect X" command means "if the next token I haven't inspected yet is equal to X, then remove it from the 'not inspected yet' stack. Otherwise, exit the process with an error code".
So if I want my parser to match "()", then in the first parse_s call, I want maybe_call parse_s to skip calling parse_s. If I want it to match "(())", then it has to call parse_s the first time, and skip calling it the second time.
Generally, I need it to recurse into parse_s N times, then skip it the N+1th time, if it's going to match N instances of A followed by N B's
My first prototype simply flipped a coin using random and used that to decide whether to skip. It correctly parsed "AB" half the time, and "AABB" a quarter of the time, and "AAABBB" an eighth of the time, etc. Not terribly practical.
My current prototype is more deterministic. When it encounters maybe_call, it clones the assembly-like program's entire state into two forks. The first one moves on to the next instruction, the other one calls the function.
Essentially my program splits into a million different parallel versions of itself, and I patiently wait until one of them calls exit_succesfully, or all of them die.
If you're thinking "this is all very silly because you could easily do this without parallel universes if you simply decided to call parse_s based on whether the next uninspected token is an A or not", then that's true, but it's not as fun.
And also it doesn't necessarily work for more complicated grammars, for example the language "any string that contains the same number of A's and B's"
 
2:25 PM
Ah, so it's not so much a "maybe" as it is a "do both", I see
 
maybe and both are the same thing in the Quantum Zone
[spooky theremin music plays]
 
Kevin's opened The Scary Door
 
2:52 PM
We're at the beginning of act 2, we're I'm all proud of my crime against nature. Now I will slowly grow concerned as my tests on more complicated grammars yield unusually high CPU consumption, then in act three I am undone as I encounter the O(N^4) worst case behavior that was lurking in the shadows the whole time
 
Not to worry, evading the clutches of the O(N^4) beast is simple. All you have to do is sidestep it once, then you're safe because O(N^4) never stops running.
 
Well, O(N^4) is the worst case if you properly design your grammar so it doesn't have a particular kind of inefficient structure. If you don't do that, and ask "Is the string 'B' matched by the grammar s := [s] [s] [s] [s] A?", then it's O(infinity)
 
3:15 PM
pandas dataframe and seaborn heatmap: I want to slice/reduce a big heatmap (150 rows x 150 columns) into a smaller heatmap (20x20). Is there any way to sort a pandas dataframe for this? I want to preserve the higher cell values.
 
Do you want to crop a single contiguous 20x20 rectangle out of this, or can we cut rows and columns out and glue the remaining halves together?
I suspect the first one is plausible, and the second one is quite expensive
 
Something like:
df.sort_values('your_corelation_column', inplace=True, ascending=False)
df = df.loc[:20, :]
Then your df has the to top 20 correlations from the correlation matrix
or however many you want
 
@Kevin the second one. Cut and glue :)
 
that won't work I guess because if there was a column with the correlations of all columns to other columns the top 20 would be all the correlations of 1 where columns are compared to themselves
 
Well, you can find the completely optimal solution in (150 choose 20)^2 comparisons, which is, let's see... Oh, that's quite a lot of zeroes.
Hmm, I may be misunderstanding the question... I need to read up on correlation matrices
 
3:26 PM
There are not that many comparisons in the heatmap. That's the what is being reduced to 400 right
 
If I understand the question, then right. If I don't, then I don't know.
Don't let my pessimism dissuade you from looking for solutions. My opinion is best taken with a grain of salt when data science is involved
I know, it's hard to believe that I could be even more uninformed than I usually am, but it's true
 
There are 22500 comparisons in the map. The user wants the top 400 or top 20 relationships. If the user has a dateset that describes the map skimming the to 20 R values of comparisons that are not to self seems easy, in principle. The problem is the user has a dateset of 150 columns and needs to create a dataset with 22500 correlation values and the columns from which they are derived. That would allow the filtering and then re plotting.
Probably some super simple way in Seaborn that I am not aware of
Or less complex way in general. My mind often finds a path, not always a good one. I offer this while we wait for others to chime in on the matter
 
Ok, good explanation. I'm getting the feeling that I'm thinking about the problem at the wrong level of abstraction, so I can't see the potential optimizations.
 
4:05 PM
What if you made a column that was the sum of all the original columns, and sorted on that? (confidence that this is even related to the goal: 70%)
Since each row has the same number of self-correlation values (i.e. one), they should all cancel out (?)
 
Not sure. Maybe I misunderstood correlation matrices :D because I don't have self-correlation values. I compared 150 documents with 150 other documents. By this I received 22.500 comparison results. Higher value means the documents are more similar.
 
Ok. I don't think my idea works, then. I will retreat to my contemplation chamber.
 
I had to drop off, rhubarbs
 
Let's try playing with a smaller example. Suppose we've got this 3x3 matrix...
[
[0.5, 0.5, 0],
[0.5, 0.5, 0],
[0,   0,   1]
]
 
 
4:19 PM
And the goal is to cut-and-glue it into a 2x2 matrix. What is the desired result?
 
I sorted the input values.
 
On one hand you could say "1 is clearly the hottest value, so that should be in the result for sure", and then you'd end up with [0.5, 0],[0,1]. On the other hand, you could say "I want to have the highest total heat possible, so I want as many 0.5s as I can get", and then you'd end up with [0.5, 0.5],[0.5,0.5]
Giving you a total heat of 2, much better than the 1.5 that you'd get from a result that contains the 1
@matt Interesting, I guess this implies that papers are more likely to be similar if the first letter in their title is the same. I can imagine a couple reasons why that might be the case, but I'm surprised the effect is so strong.
 
@Dodge df.iloc[:20, :20] thanks :)
 
Another satisfied customer, although I didn't actually do anything
 
@kev
@Kevin thanks :) ... i think you're right, that there is not a real answer, because you will definitly miss some of the 'heat' in the heatmap. Thanks for your thoughts.
 
4:34 PM
What you're asking to do is to resample, no?
df.iloc[:20, :20] just gives you a slice, and all the rest of the data is thrown away
 
@roganjosh i recreated the DataFrame before the slice. In my new DataFrame the input matrix is sorted.
 
To your first sentence, my response would have been "ok, maybe 'thrown away' was too dramatic, but it isn't in your new df". The second sentence combined with the first leaves me not understanding anything of the point
Are you looking for a subset of the data (a slice, as you have) or a consolidation/crunching down of the whole dataset into a 20x20 matrix? I know it kinda seems to have been solved by others, but I'm concerned that you think what you've done is the latter, and it's not
 
5:00 PM
Yeah I think there's value here (and in general) in sitting down and thinking about what you really want your code to do. Even if you already have a working program that falls within the approximate boundaries of your objective
I'd say I have a fifty percent success rate for finishing a personal project, looking back on it, and askng, "... But does this actually satisfy my original problem/need/curiosity that kicked everything off?"
Clarification: I do not finish fifty percent of my personal projects. Rather, among the 5% of personal projects that I finish, 50% of them satisfy the original need.
Bringing my total rate of supreme victory down to 2.5%. Honestly, I'm happy to be above 1%.
 
5:17 PM
I'm pretty decent at naming my personal projects. That's like 95% of the effort. I'll go back and put some code behind them later
 
One thing I'm bad at is archiving my projects. If I think it's exceptionally interesting, I put it on Github. If it's moderately interesting, I put it in a Gist and/or C:/programming/projects. I have three things in my Github and about a million things in my gists and projects.
No hierarchy, no metadata, no sorting by topic or program vs library or anything else.
There's some code I wrote last year that registers global hotkeys for user-customizable actions, and I'd really like to use it for an idea I had yesterday, but I don't know where it is
 
@Kevin With 1% success rate, that's pretty decent.
 
Well, that's imperial milllion, not metric. So adjust your impression of me downwards accordingly
The actual value varies depending on the barometric pressure and the shoe size of the youngest direct male descendant of Norton I., Emperor of the United States, but it's somewhere around 50, if I recall the readings from our monthly newsletter
 
5:32 PM
In 64-bit systems, a 32-bit signed integer needs one bit for the sign, so it has 31 bits available. However, the biggest number is 2^30-1, not 2^31-1...why?
 
I think the biggest number varies from language to language. For example, tutorialspoint.com/c_standard_library/limits_h.htm indicates that INT_MAX in C is equal to 2147483647, which is indeed (2^31)-1
Python doesn't have a biggest number for (long) ints, because we're rad
 
To clarify my question, 2^30 is one byte larger than 2^30-1.
 
Ok, I agree with you there. I'll try rereading your query with that in mind.
 
That was the wrong ^ ^^
 
Silly question, but just to be sure: when you say 2^31-1, do you mean (2^31)-1, or 2^(31-1)?
 
5:42 PM
I mean 2 to the power of 31, then subtract one
 
Ok
 
Come to think of it: in what case is the biggest "32-bit" number 2^30-1?
 
Yeah, I don't think I understand the question :-(
 
Both 2^30 and 2^30-1 require 4 bytes of space or less. 2^30 specifically requires 31 bits. Then the sign is an extra bit. All 32 bits are filled. But Python's int tacks an extra 4 bytes...
 
That looks suspiciously like a CPython int digit on a 64 bit system.
 
5:44 PM
@MisterMiyagi I've re-read that several times two days ago
(I still have the tab open)
 
Nice. Then this is the perfect opportunity to point out where additional detail is needed. ;)
 
It begs the question as to why you need an extra four bytes as well for 2^60, when 2^62 fits perfectly fine in 8 bytes
Why should then 2**60 - 1 be the largest 2-digit number?
 
Python sometimes reports surprising values when you ask it for the size of objects, because there's overhead relating to the PyObject header and such. But perhaps you already know this, and have noticed a discrepancy not explained by header overhead.
If so, then I may get to go on a fun adventure through the source code
 
@JossieCalderon certain algorithms work better for sizes that are multiples of 5.
 
Thanks, that makes sense
 
5:47 PM
For example, "long_pow() requires that PyLong_SHIFT be divisible by 5"
 
How did you discover that 2**60-1 is the largest 2 digit (byte?) number? sys.getsizeof? deriving the value from the type definition? There are no wrong answers, I just want some insight on the process
 
sys.getsizeof
>>> import sys
>>> sys.getsizeof(2**30)
32
>>> sys.getsizeof(2**30-1)
28
 
Ok, cool. I'm seeing something similar on my machine.
If I go on a fun adventure through the source, I'll report my findings
 
Yes, please!!
 
@JossieCalderon Thanks for the inquiry. I've added a small notice to the answer (it's quite long already) that picks up this point and links to a source code comment with background information.
TBH, I didn't know the answer to that part before looking it up just now.
 
5:54 PM
You're welcome. Thank you as well for pointing out the relevant source code functions.
 
Just re-joined and catching up. This looks like a really nice use of chat
 
Currently exploring the implementation of long_pow to see why it wants digits with bit size divisible by 5. It starts by allocating a "5ary array" without really explaining why... I think I'm coming up on the juicy part because github.com/python/cpython/blob/main/Objects/longobject.c#L4242 links to a pdf in a university-owned domain
You know you're gonna see some Dijkstra level stuff if you see .pdf and/or .edu instead of wikipedia.org
 
@Kevin Maybe related: - the marshal code currently expects that PyLong_SHIFT is a multiple of 15
 
poking through the pdf... The introductory paragraph foir "exponent recoding" basically says "it's faster if you do it this way". Ok then.
 
@Kevin You just say that because you don't know where the saucy stuff is on .edu domains.
 
6:04 PM
.edu is a wild frontier
 
Actually, reading through that paper is pretty thrilling. Good find.
 
I'm following the general gist but I'm not getting any lightbulbs along the lines of "ah, that's why 5ary numbers are fast!"
They assert "sometimes exponentiation is faster on N-ary numbers compared to binary ones", which is reasonable to me, but the other shoe still needs to drop
 
1
A: Will ternary computers be faster than binary?

Tom van der ZandenIt depends. A number represented in base 3 will have fewer digits than the same number in base 2. Perhaps this means computations will be faster, since you have to work with fewer digits. However, perhaps the operations will become slower (since they're more complicated) so there might be no net ...

 
Random guess: 5ary exponentiation is fast when you're trying to calculate big round exponents, like 17 ^ 1000. In practice, most big exponents are also round. Therefore, using 5ary exponentiation improves the most common use case.
More generally, if your exponent is highly composite, you should use its most common prime factor for N, and choose the larger factor if it's a tie.
Thus ends my random guess.
 
6:22 PM
Hello, in file: aaa.py i open file: C:/Users/Χρήστος/Desktop/somefile.xml
This file may have relative path. How can i convert this relative paths to absolutes?
 
851
Q: How to get an absolute file path in Python

izbGiven a path such as "mydir/myfile.txt", how do I find the file's absolute path relative to the current working directory in Python? E.g. on Windows, I might end up with: "C:/example/cwd/mydir/myfile.txt"

 
@ChrisP this could have been googled very easily
 
This answers are not help me because the path are relative to the xml file not the cwd (aaa.py).
 
Then you've misinterpreted the answers. You can get the file path, again, very easily
 
@ChrisP Join the base path with the relative path.
 
6:31 PM
Signed digit representation is wacky, yet efficient. A fine addition to my collection.
 
They got me at "Algorithm 14.76 is simply Algorithm 2.143 restated in terms of an arbitrary finite abelian group G with identity element 1.".
 
Prior to this I thought the sign bit for each long integer digit was just junk data except for the most significant digit. TIL
 
path = os.path.normpath(os.path.join(os.path.dirname(self.playlist_filename), path)) works!!
 
Can anyone suggest a name to use for a variable that will denote if the dimensions should be measured in pixels or not
Now that I am thinking, is_pix?
 
I'll get the obvious one out of the way and propose will_dimensions_be_measured_in_pixels
I'm only 20% joking, because sometimes really long variable names are fine if you only use them on otherwise short lines
 
6:36 PM
is_unit_pixels perhaps
 
Hmmmm well, should have mentioned, this world be a parameter
 
Smaller proposal: dimension_unit, whose value is an instance of a ScreenUnit enum, or perhaps a string if you're confident in your typing abilities
 
@ParitoshSingh Hah I like it
 
perhaps make it a parameter unit with the value as a string.. edit: err..kevind
 
@CoolCloud make a separate type for each kind of dimension?
 
6:37 PM
Its just a matter of either pixel or something else
 
Nothing wrong with a two element enum :-)
 
^
nothing wrong with only 2 valid values for an input, if it makes sense it makes sense
 
Sorry, I'm not sure I follow, what is the suggestion again?
 
I won't say that it's definitely the best approach -- I use bools 99% of the time, myself -- but just give it due consideration
 
there's a few :P pick your poison
 
6:38 PM
I don't follow either Enum for a binary choice?
 
@Kevin Lets elaborate on this to start with
 
It's usually me that gets hit by YAGNI or over-complication, but this is just a bool?
 
@CoolCloud Effectively:
def frobnicate(x, unit):
    if unit == "px":
        foo(x)
    else:
        bar(x)
Assuming that your current code looks like this:
def frobnicate(x, is_x_in_pixels):
    if is_x_in_pixels:
        foo(x)
    else:
        bar(x)
oops hang on. There we go. Ctrl-c on this laptop fails half the time :-/
 
Oh I see
 
@roganjosh Hush. I want to see how deep the hole is going to get...
 
6:40 PM
soz m8
 
ctrl + c... i always press it twice now, i've gotten used to my work laptop doing the same
 
There's also a library on pypi, whose name I've forgotten, that lets you create numbers with units attached to them. So you could do if x.unit == "px":
I can't find the one I was thinking of, but it would be fairly easy to define a UnitfulInt class yourself, if you don't need to go crazy with bells and whistles
 
I'm sorry but I can't leave this one. What on Earth is happening here? Why can't there be a translation dictionary as a class attribute?
I'm happy to be shot down, but this is so overly complex for (in my head) nothing
 
whats a translation dictionary?
oh, and i think Kevin is just on a roll
 
2 birds, one stone:
class GeoHelper():

    def __init__(self,
                 config: Config = Config()):

        self.config = config

        self._dir_path = os.path.dirname(os.path.realpath(__file__))
        self._has_postcodes = os.path.isfile(
                                os.path.join(self._dir_path,
                                             'postcodes/gb_postcodes.json')
                                )
        self._postcode_map = {}

        self._conversions = {'min': 60,
                             'km': 1000,
File location and a unit conversion
 
6:51 PM
is this related to some context/messages from above? I might have missed the conversation if so
 
@ParitoshSingh I got a weird feelings it's about what I asked
Feel free to give your thoughts on this like before.
Seems like not so useful feature, but it might be handy for simple buttons like Login, Signup and so on
 
@roganjosh The thing is, a boolean isn't self-documenting. If you set use_pixels=True, then sure, it uses pixels. But if you set use_pixels=False, then it uses... what? Something like unit='cm' would make that obvious
 
But is that something to be solved by Enum? I'm not so sure on that one
 
I'd probably use magic strings tbh, but can't blame anyone for going with an enum either
 
6:59 PM
I'd buy the argument if it was in terms of databases, but why can't you just include an extra line in self._conversions?
I genuinely don't know how it's any more extensible to have a custom class that you'd have to edit anyway. Happy to be wrong
 
I might be missing some context here, but I don't see how that _conversions dict is related to the question? I thought we were discussing def func(use_pixels: bool): vs def func(unit: str_or_enum):
 
My bad, I did a mental leap sorry. is_x_in_pixels I was thinking about in terms of a bool, then thinking you could just have a dict of conversion factors. But now I'm really confused how Enum solves the problem
You can have a boolean switch of is_x_in_pixels or you can have a conversion dict where the user specifies the unit, ... or Enum does something I've not come across
 
It's just a matter of opinion whether you prefer func(unit='pixels') or func(unit=Unit.PIXELS). Under the hood, it doesn't really matter either way. You either do conversions = {'pixels': whatever} or conversions = {Unit.PIXELS: whatever}.
That's assuming you even need to convert anything. Who knows what they're doing with those units?
 
Ok, well I'm happy with it just boiling down to personal preference and not me missing a trick. Thanks :)
 
7:30 PM
Not sure if you were still talking about the five-ary hole; I thought it was Kevin that wrote the message...
 
7:43 PM
hi
 
Hi there
 
so what do we do here
 
8:05 PM
Anyone using the new Firefox? I noticed the tab bar slightly changes size whenever the "playing audio" icon appears/disappears and it's driving me nuts. Wondering if that only happens on my machine?
 
hm... best i can tell my tab size doesn't change, no
the text does shift to adjust. but no resizing of the tab itself.
 
Might be related to my text scale settings then. Thanks
 
8:24 PM
@JossieCalderon I like digging into the background of such things, so follow-up pings on these kinds of discussions are much appreciated. Thanks a lot.
 
@Wolf enough of that. Go be bored somewhere else.
 
Thanks to you, MisterMiyagi, for inspiring the research
 
Is leaving a comment asking the OP to choose a correct answer, after the question is answered and the OP has viewed it and still not even responded, a valid comment?
 
yes
In the end, just use NumPy for int if concerns exist over size. int64 supports between -2^63 and 2^63-1! np.int64().itemsize returns 8 and not an ungodly 24.
 
9:01 PM
@CoolCloud not worth the effort
 
so
 
This better be good...
 
 
1 hour later…
10:06 PM
@CoolCloud Something like: "Please consider accepting the answer that helped you the most", posted as a comment on the question, is acceptable. Preferably if you haven't written an answer yourself. ;) Such comments can be helpful to newbies, especially if they have a track record of never or rarely accepting. But don't bother if they aren't a newbie, they'll most likely just ignore you.
 
 
2 hours later…
11:39 PM
Cabbage!
 
11:53 PM
cbg
 

« first day (3891 days earlier)      last day (1040 days later) »