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

4:00 PM
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
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
4:04 PM
  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
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
Thanks. First one.
No sleep haha
Anyway good day to you all
Bye guys
 
4:05 PM
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...
 
4:09 PM
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 :-)
 
4:13 PM
@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
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
4:39 PM
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
4:41 PM
A what?
 
@Sam Huh? I know 6 ÷ 3 = 2. Is that what you mean?
 
Sam
Haha
Americans
 
garlic
 
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
4:42 PM
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.
 
4:58 PM
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"
 
5:01 PM
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.
 
5:10 PM
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.
 
5:21 PM
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
 
6:14 PM
@Kevin Here in Germany, I've learned all of :, /, and ÷ operators, before being taught to forget all that and use fractions instead.
 
6:31 PM
Hmm, is this not a Merkel emoji? :/÷
 
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
6:50 PM
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
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
@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
6:59 PM
^ 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
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
7:05 PM
hah, I was looking for the change but it got reverted
 
interesting
 
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
$ 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
7:11 PM
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
@Todd you wanted more than 12 years?
 
7:21 PM
@wim wait, that's still not gone? how do I scare people into updating code, then?
 
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
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
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
 
8:04 PM
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
@AndrasDeak yep
 
and then they suddenly have 'c:\User', and things mysteriously start to break, ugh why is python so confusing
 
wim
8:53 PM
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]
 
9:19 PM
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
 
9:52 PM
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
 
10:12 PM
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)
 
10:17 PM
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?
 
10:29 PM
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
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))
 
10:43 PM
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..
 
10:54 PM
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
Hello everyone.
Would a rollback be appropriate here? OP added what is essentially an entirely new question to the original post.
 
11:00 PM
@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
@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
11:03 PM
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
Let's agree to disagree, then.
 
11:24 PM
@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
 
11:29 PM
@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 (1495 days later) »