« first day (3454 days earlier)      last day (1719 days later) » 
00:00 - 16:0016:00 - 00:00

16:00
its usefulness (or lack thereof) has come up here a few times
@AndrasDeak Without knowing much about it, seems like reinventing the wheel
you're looking at it wrong: I'm pretty sure array.array came first
breadcrumbs probably among chat.stackoverflow.com/search?room=6&q=array.array (warning: general search results page, nothing specific to link)
@roganjosh 'The Purge: Chocolate Cities' "In a world where central distribution systems have broken down..."
Sam
Sam
So now I have this:
if((ipaddress.is_global(args.ip) and (not is_loopback(args.ip)) and (not is_private(args.ip))):
	print(args.ip + " is not a supported IP address!")
Anything I can do better about this?
Why is formatting so darn hard in this chat.
array module has a mention of "deprecated since version 1.5.1` in its python 2 docs
Sam
Sam
16:04
  File "ip2location.py", line 39
    if((ipaddress.is_global(args.ip) and (not is_loopback(args.ip)) and (not is_private(args.ip))):
                                                                                                  ^
SyntaxError: invalid syntax
Certainly, the markdown system is not the most user-friendly piece of software.
Sam
Sam
There is an error with this and I don't know what. In every script I write I use notations like this.
We're all in the same boat, so let's try our best
@Sam count your parentheses, I suspect that's the problem
Sam
Sam
Thanks. First one.
No sleep haha
Anyway good day to you all
Bye guys
16:05
bye
Sometimes when I'm stringing together a lot of boolean conditions, I'll put them on separate lines, like this
if(
    ipaddress.is_global(args.ip) and
    (not is_loopback(args.ip)) and
    (not is_private(args.ip))
):
    print(args.ip + " is not a supported IP address!")
I'm getting PEP 8 indentation rules anxiety
I won't quibble about indentation particulars. My thesis statement is "multi-line conditionals are useful sometimes"
> This PEP takes no explicit position on how (or whether) to further visually distinguish such conditional lines from the nested suite inside the if-statement. Acceptable options in this situation include, but are not limited to:
phew!
I like my brackets lining up with the indentation level...
16:09
Comedy option:
if(
    ipaddress.is_global  (args.ip)  and
         (not is_loopback(args.ip)) and
         (not is_private (args.ip))
):
that's not even that comedic I think
# Add some extra indentation on the conditional continuation line.
if (this_is_one_thing
        and that_is_another_thing):
    do_something()
halfway there
I think the PEP does specifically frown upon adding whitespace just to make tokens line up nicely
I think it's the sad upside down smiley that trips up my brain
@Sam If you keep tripping over negative predicate function, you could define helper functions not_loopback, not_private and monkey-patch them onto ipaddress, thus your code could look like: if ipaddress.is_global(args.ip) and not_loopback(args.ip) and not_private(args.ip): ... It's really not Pythonic to have a sea of parens in an if-condition.
A dictate which I ignore with great vigor
#More than one space around an assignment (or other) operator to align it with another.
#No:

x             = 1
y             = 2
long_variable = 3
Oh good, it's only forbidden for assignment statements. So I can go nuts with every other kind of statement >:-)
There's no operators in my conditional example, so I'm good :-)
16:13
@smci The array module has simple goals, it certainly isn't trying to do what Numpy does. "This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers." So it can be useful if you want to store data that C would store in simple arrays. I guess that might be handy for people writing Python extensions in C. The arrays in the array module are definitely not fast, but they are fairly compact.
@PM2Ring Ah ok. But it would probably be good for that module doc to say "if you're doing serious numerical/scientific or data-science work, use numpy/scipy or pandas instead"
Hmm, odd that "Further indentation required as indentation is not distinguishable" in the context of line continuations within function headers, but further indentation is explicitly not required for line continuations within conditionals.
@smci Yeah. That page does mention Numpy, at the end, but it doesn't really say why or when you'd want to use Numpy. But for that matter, it doesn't say why or when you'd want to use array.array, either.
@AaronHall Ha. I haven't listened to it, yet. I just saw it in my feed and was thinking "I know that name..."
@Kevin That's exactly how black does it.
Sure could go for some cookies right now
/me drools...
Sam
Sam
Hey guys, me again
Not really a related question but may I ask something of encryption of you?
Umm... is it just me being daft... or can anyone guess what: Change anything that isn’t a date to a date. means?
We usually permit language-agnostic questions as long as it doesn't fit better in another room
Sam
Sam
16:39
Because I can't post my question elsewhere, this room really is the only active chat lol
Yeah I guess it fits to your terms
Okay so my question is:
You know 6 : 3 = 2 right?
What if you do encrypted : decrypted = key? Would such a thing work?
"I'm asking in here because the room where it would be on-topic is dead" is not a good justification. "I'm asking in here because it doesn't really belong anywhere specifically and this is the most active room" is OK
I don't think we're going to be able to help you with that question.
"You know 6 : 3 = 2 right?". No, I do not know. I'm not familiar with that syntax.
Try asking on Stack Overflow or another appropriate Stack Exchange site or chat room
Is this... modular arithmetic?
Sam
Sam
16:41
A what?
@Sam Huh? I know 6 ÷ 3 = 2. Is that what you mean?
Sam
Sam
Haha
Americans
garlic
Sam
Sam
Nono its what I mean yes
50 secs ago, by davidism
Try asking on Stack Overflow or another appropriate Stack Exchange site or chat room
Sam
Sam
16:42
OK sure thanks guys bye
@Sam Maybe, using an appropriate number field. However, what you're thinking about is related to a family of encoding strategies. See en.wikipedia.org/wiki/Arithmetic_coding
@Sam FWIW, most of the regulars in this room are not from the USA.
I'm curious in what cultures is the colon the primary symbol for division. I understand it in the context of ratios, e.g. 7:14 is equivalent to 1:2, but that's a fairly constrained use-case
Certainly there's no single objectively correct notational system. It's all arbitrary, and only seems otherwise when a large proportion of people all agree to use the same symbols.
16:58
Hii
Im using pyinstaller to create a python exe file, some exe files are working and some exe files are not running.
Is there any other ways to generate a python exe file.
I need to run the python exe file in a pc where python is not istalled.
Any suggestions please.
Sometimes I wonder how ancient Greeks would regard a modern mathematics textbook if it fell out of a time portal and scuffed the circles they were drawing in the sand. Supposing the English bits were untranslatable, how much of the purely symbolic logic could they make sense of?
I'm certainly familiar with the use of the colon to write proportions. I think some Europeans may use it for general division...
@Kevin there's a confusing lie-to-children here where division is presented in two names and two notations: "division" denoted with / and "~partitioning?" denoted with :
Did they even have the plus sign back then? I'm under the impression that a lot of proofs back in the day were written out longhand, e.g. "two plus two equals four" rather than "2+2=4"
17:01
76
Q: Create a single executable from a Python project

ShadowFlameI want to create a single executable from my Python project. A user should be able to download and run it without needing Python installed. If I were just distributing a package, I could use pip, wheel, and PyPI to build and distribute it, but this requires that the user has Python and knows ho...

So while the primary symbol for division is a slash, people would probably understand the colon as well
@Kevin Modern algebraic notation is fairly, um, modern. Traditionally, algebraic stuff was written in words, which made it rather unwieldy.
Modern ten year olds can get the hang of algebra with a couple months of work, but I wonder how much of that is dependent upon active tutoring and and a prevailing culture where it more-or-less fits in.
Maybe our predecessors would say "what's this nonsense?" and toss it out. Or maybe they'd be intrigued by it in the way we're intrigued by the Voynich Manuscript, and make about as much headway decoding it as we have
"There's pictures of circles everywhere, so it's definitely a math handbook, but damned if we know what ∠AB + ∠BC = ∠AC means"
en.wikipedia.org/wiki/%2B cites a 14th-century manuscript as one of the earliest documented uses; equals is much much newer still
Also, negative numbers weren't considered proper, so an equation would have to be split into various cases to eliminate the negative numbers.
17:10
uncouth numbers
Eg, there'd be a rule for solving equations of the form x² = ax + b and a separate rule for x² + b = ax, etc.
en.wikipedia.org/wiki/= says 1557 so older than I remembered
There's a real risk that they'll decode a good chunk of it, get to a part that 100% contradicts with their existing common knowledge, say "surely an author that thinks negative numbers exist can't possibly be worth listening to", and throw it out
"Just another prank from the heretical negative number faction across the symposium. Those mad lads never let up"
The scrollmakers' guild fishes the book out of the trash and says "a way of laying out information that lets you reach the middle contents without thirty feet of spooling/unspooling? This changes everything!!!"
Question: does Voynich have a "ch in change" sound or a "ch in Bach" sound at the end? Wiki for once doesn't help me.
It's kind of ironic, but it wasn't until mathematicians were forced to accept the validity of complex numbers (because they arise in the algorithm for solving cubic equations with 3 real solutions) that negative numbers were finally seen as legitimate numbers in their own right and not just a clever bookkeeping trick.
17:21
trippy
en.wikipedia.org/wiki/Wilfrid_Voynich spells it Wojnicz which suggests a "much" sound (to the extent that Polish sounds can be approximated in English)
Thanks, Polish is perfect!
I forgot to look up the namesake
Hmm, the List of Poles doesn't mention the South Pole
18:14
@Kevin Here in Germany, I've learned all of :, /, and ÷ operators, before being taught to forget all that and use fractions instead.
18:31
Hmm, is this not a Merkel emoji? :/÷
wim
wim
@alkasm what was it? gone now?
@wim yea gone now. It was JFF commenting to OP that VSCode is not a good IDE for Python.
wim
wim
18:50
I've heard good things about VSCode for Python. Haven't tried it myself yet
PyCharm is in that annoying place where it's not good enough to keep you happy, but not bad enough to motivate shopping around.. :D
VSCode certainly takes a bit of time to get into, it's not really something you can just give a whirl for 10 minutes
still recommend trying it though, it's quite different from pycharm
wim
wim
our frontend devs like it
I have a string such as " Apr 07 - 13" and I want to extract the first number 07 from it. I can do re.search("Apr \d+.*", text) but how do I get the number that matches?
wim
wim
@Anush google for regex capture groups
this particular case is probably better suited for strptime though
>>> datetime.strptime("Apr 07 - 13", "%b %m - %d").month
7
int(re.search(".*Apr (\d+)", " Apr 07 - 15").group(1))
wim
wim
18:59
^ looks ok, just put an r"..." on the pattern
otherwise \d is invalid escap
it seems to work nonetheless
AttributeError: module 'datetime' has no attribute 'strptime'
seems odd that it works without the r"..."
wim
wim
you probably have old version of python
won't work in more recent version!
Python 3.7.6
not very old!
that's seriously a syntax error? They would break backwards compat for that?
which version does it not work in?
wim
wim
19:05
hah, I was looking for the change but it got reverted
interesting
wim
wim
unpopular opinion, python should stick to their guns on deprecations
this collections.abc has been "the module that cried wolf" for too long now
What should that deprecate and how?
wim
wim
$ py -Wall -c "from collections import Iterable"
<string>:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
deprecated since 3.3!
Can't rush these things :p
wim
wim
19:11
it used to say "in 3.8 it will stop working", and in master it now says "in 3.10 it will stop working" :D
part of the problem is that deprecation warnings are squashed by default, so every time this comes up some luddite whines that they didn't have enough time
and then they give them another year, this can go on indefinitely.
umm... yeah... that's odd
@wim So it seems to me that in 3.8 '\potato' should have been a SyntaxWarning, not an error, and this is what was reverted to a DeprecationWarning.
they didn't give me enough time to know python2 was deprecated =(
The thread you linked suggests that it would have errored in 3.10 the soonest, doesn't it?
wim
wim
@Todd you wanted more than 12 years?
19:21
@wim wait, that's still not gone? how do I scare people into updating code, then?
wim
wim
@MisterMiyagi that's the problem, you are now the MisterMiyagi who cried deprecation :)
It's just his signature technique of making pupils practice upgrading code until it's in muscle memory
wim
wim
https://github.com/python/cpython/blob/v3.7.0/Lib/collections/__init__.py#L51
https://github.com/python/cpython/blob/v3.8.0/Lib/collections/__init__.py#L51
https://github.com/python/cpython/blob/v3.9.0a4/Lib/collections/__init__.py#L51
@AndrasDeak ^
whatever the thread says, if python itself keeps telling lies, eventually you don't take it seriously..
I meant the invalid escape string thing, see the directed reply in my preceding message
wim
wim
yeah I see. to me it's not much difference the discrepancy with DeprecationWarning and SyntaxWarning .. because I escalate DeprecationWarnings on my dev boxes anyway
surely there's a canon for accumulating to a dict of lists
huh, I wondered whether cancelling of PyCon might derail the 2.7 release
20:04
The escape string thing should've been done ages ago. It's something Python inherited from C, but since we have raw strings there's really no good reason to allow those invalid backslash escapes.
I'm afraid this sees the same kind of pushback that the str -/-> bytes switch had: people not realizing how they've been doing it wrong all along will be upset that now they have to think just a bit and write correct code
sup
wim
wim
@AndrasDeak yep
and then they suddenly have 'c:\User', and things mysteriously start to break, ugh why is python so confusing
wim
wim
20:53
Interesting: PEP 602 (accepted) makes mention of Python 3.10, 3.11, and 3.12. But PEP 563 (also accepted) makes mention of Python 4.0.
I wonder what will be the last 3.x?
3.∞
@Aran-Fey Gee, that's not going to cause any problems :p
Fun problem: Given a list of integers (length less than 9), I want to get a list of the integers that I use to "carry" when performing "long" addition.
For example, Consider this problem:
 1 2
-----
  314
+  15
+ 926
+ 535
=====
 1790
I want the list [0, 2, 0, 1]
21:19
Below is what I did. Just want to see what other clever things people might do.
def f(a):
    a = [0, *a]
    c = [0]
    while any(a):
        [*a], b = zip(*map(lambda x: divmod(x, 10), a))
        a[0], d = divmod(sum(b), 10)
        c.append(a[0])
    return c

f([314, 15, 926, 535])

# [0, 2, 0, 1, 0]
I'm stuck here because I don't think this can be vectorized
ints = [314, 15, 926, 535]
num_digits = len(str(sum(ints)))
digit_array = np.array([list(f'{i:0>{num_digits}}') for i in ints]).astype(int)[:, ::-1]
digit_sums = digit_array.sum(0)
since each carry could cause carries later on
"I want to get a list of the integers that I use to 'carry' when performing 'long' addition." is a weird way to put it
"list of digits" would help disambiguate
def f(nums):
    carry = 0
    while any(nums):
        yield carry

        total = sum(num % 10 for num in nums) + carry
        carry = total // 10

        nums = [num // 10 for num in nums]

    yield carry
actually I forgot to add carry to total
21:52
ceil(log10(sum(ints)))
@smci Not gonna lie, that's probably a horror film I'd watch. The tagline might not be so appealing for the general audience but it's hooked me. I'd have to watch the logistical effort through gaps in my fingers
22:12
i thought numpy might be faster than the built in math module.. but running log10() looks like it's horribly slower
using timeit
Numpy is designed to work on arrays, not scalars
right.. didn't expect it to be this slow though
turns out a hammer is a terrible tool for laying tiles
so.. running that formula for calculating the number of base 10 digits with timeit on a list of 100 random ints.. with timeit's default settings.. it takes about 20 seconds on my slow system for the built in math module.. but numpy takes nearly 500 seconds
So don't do that
time np.log10(your_list_of_ints)
22:17
i can't help myself
alright.. let's see how it does with that
and then check with 1000 and 100000 ints in your list
although it would be even better if you created the array before the calculation
Not sure how the timings work out otherwise. Using numpy for a single step in larger code usually makes things worse.
ah.. yes. np shines with performing the operations on lists
the math module doesn't have built in handling of lists.. so it has to rely on jumping in and out of python script to loop
also note that it's already 1.5x faster than itself for a 1-length array
>>> %%timeit val = 1324.0
... np.log10(val)
...
...
627 ns ± 4.65 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

>>> %%timeit val = np.array([1324.0])
... np.log10(val)
...
...
388 ns ± 4.78 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
and it becomes faster for a numpy scalar...so I guess that speedup is from returning early from np.asarray
was trying to see how pypy would do with math vs np.. but i think pip installs the non-pypy version of np
I'm not sure that pypy can help here?
22:29
it might be interesting to see how the math lib does in a loop with the jit compilation
probably worse than built-in math lib with ahead-of-time compilation
wim
wim
I wish there was a dedicated chat room for micro optimizations to move these discussions into ;)
yeah
the math lib did better under pypy with jit.. but i'm not sure if i should be running with a pypy tuned version of numpy.. i'm using the version I get when i use pip to install it
you're probably not measuring "the math lib" but the surrounding loop
that's what i'm saying. the math lib beats it on pypy doing calculations on a list in a for loop.. but i'm not using a for loop with np.. i'm just doing np.ceil(np.log10(num_list))
22:43
Does it change anything if you return x?
alright.. i'll see
now convert the numpy input into a list before passing it in for timing
I think the problem is with the performance hit that pypy takes when working with CPython C API modules
can't comment on that
i'm assuming that numpy is implemented partly in c..
22:54
largely
i thought there was a numpy version compiled against the pypy c api .. didn't see it
i guess the moral of the story is... don't migrate to pypy if your project depends on scipy
What are you actually trying to do?
just found it interesting comparing the two platforms
You might be able to use numba, or compile with Cython, or.. well, the list goes on
AMC
AMC
Hello everyone.
Would a rollback be appropriate here? OP added what is essentially an entirely new question to the original post.
23:00
@Todd Also try len(str(num))
heh.. yeah.. that actually was faster
hey guys, anybody know if there is a spectral fuzzy clustering algorithm library in python
@AMC edit is literally almost 10 years old. Close the tab.
AMC
AMC
@AndrasDeak So what?
So I won't even start to check how many answers that rollback would invalidate. Spend your time doing something valuable, like herding cats.
AMC
AMC
23:03
10 years is not old enough for it to be a valuable artifact.
an edit that hasn't bothered anyone for 10 years is fine
And you're on record screwing up a rollback about a week ago, so I'll go out on a limb and say you're overdoing it.
AMC
AMC
Let's agree to disagree, then.
23:24
@Todd 'vectors'. And arrays. A vector is a 1D array. Have a skim of the numpy Quickstart. Anyway, try to avoid ever needing to call numpy on a single value ('scalar'), for performance reasons.
yeah I know. did you see the metrics?
I've been meaning to ask: what does the "SOReadyToHelp" mean that I see in some user profiles?
@bad_coder nothing anymore, it was a thing a few years ago
@bad_coder It's a shoutout to suggest that they are willing to help
23:29
@bad_coder you could get a t-shirt back in 2015 meta.stackoverflow.com/questions/303721/…
@AndrasDeak How much do you reckon that cost? Quora (and Yahoo Answers) used to have budget for giving out swag before they jumped the shark.
no idea
I only started on SO a few months earlier so I decided not to participate, I wouldn't have felt it fair to snatch a shirt from someone who deserved it more
oh.. there's a numpypy??? @smci - I'll try and find it and see how it does.
@Todd Read the FAQ, bro... I never touched pypy but that's the first google hit.
I don't see this working out well. Just why?
00:00 - 16:0016:00 - 00:00

« first day (3454 days earlier)      last day (1719 days later) »