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
> 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:
@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.
@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.
"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
@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.
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?
@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"
I 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...
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"
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!!!"
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.
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)
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?
$ 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
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.
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
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
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.
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
@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
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
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
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))
@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.
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