« first day (2722 days earlier)      last day (2451 days later) » 

01:33
@Aran-Fey Spoiler alert: it is possible
recbg
Aha, looks like you did it already
01:47
Does anyone have any idea how to disable mouse integration in VirtualBox?
You'll have to switch off your VM and then go to Hardware Settings, I think?
no joy
 
3 hours later…
04:59
exhausted cbg
05:26
cbg
going to watch something and go to bed. rbrb @JGrindal
hasta la taco.
 
1 hour later…
06:56
I am getting this error one positional argument required if I wrote these lines as
class A:
def __init__(self):
pass
def func(self):
return 20

k = A(1)
l = A.func()
print(l)
but if i wrote like this then there is no error
class A:
def __init__(self):
pass
def func(self):
return 20

k = A(1)
l = k.func()
print(l)
anyone give some insight
Yes, that's because k.func() is calling a method on the k object, so k is self.
But A.func() is calling the method on the class. There is no instance to be passed as self. (You can pass one manually, by calling A.func(k), but that's not usually something you want to do.)
A().func does not make any object in the backgrund?
A().func() would create a new object, but you didn't do that, you did A.func().
ohhhk right
my bad i did not know this difference thanks for the help
i really mixed c++ in this concept
This is actually identical to C++, except than in C++ you'd have to write A::func() instead of A.func(). For A().func and k.func() the syntax is identical for the two languages.
I think you may have been confused because you've stripped your example down a little too far. In a real-life class, instances actually have some meaningful identity and state, and methods do something with that. For example, it's pretty obvious that you can't call read on the file class, only on a file object.
07:08
in c++ its like use A obj to create an instance but here as you mentioned obj=A()
Well, C++ has multiple ways of doing the same thing. If you want to call the default constructor, you can write A k; or auto k = A();` or auto k = A{}; or A k = {}; or a fw more things, but of course not the most obvious thing A k();, because that declares a prototype of a function returning an A.
but in case of c++ constructor call its same, you are right i stripped down example so much
That's one of the tricky parts of using Stack Overflow—you need to strip something down to a minimal example to get help, but it's easy to get so minimal that it becomes too abstract to think about clearly…
07:37
List initialization is not the exact equivalent of calling the constructor using the standard call syntax, is it?
i.e. there are cases where the two behave differently
That's kinda irrelevant to this discussion, meh
@AndrasDeak hi Andras, why should not we not use it, pls?
cbg
@vaultah next time for the election
08:02
I'll pass on the next one
08:56
@cᴏʟᴅsᴘᴇᴇᴅ Nope, I don't know how to make it work :(
@vaultah I voted for you.
also, morning cbg everyone
I think I now own every Python book that O'Reilly publishes.
And I'm not sure if I'm proud or embarrassed about that.
Turns out I still can't comprehend what Martijn's trying to tell me in his comment even after a good night's sleep. Great. Time to give up on trying to read the source code and bring out the debugger...
09:13
There's no problem that a debugger can't solve!
I'm tempted to edit my answer into "You can't do that" just so I can stop reading pprint source code
They should update the documentation to say that no PrettyPrinter customization is supported. The things going on in there are just gross
09:47
lol
10:10
I give up. It's actually easier and cleaner to reimplement the whole darned module.
10:51
@AndyK because oneliners are overrated and "smart" oneliners are unreadable. Use multiple lines in python, or use awk
 
1 hour later…
12:05
hi, i have string, ex. q = '''CONCAT(first_name, " ", last_name) AS "FullName", field1, field2''' and i want split it so ['CONCAT(first_name, " ", last_name) AS "FullName"', field1, field2] , can u help me?
>>> s = '''CONCAT(first_name, " ", last_name) AS "FullName", field1, field2'''
>>> s.rsplit(",", 2)
['CONCAT(first_name, " ", last_name) AS "FullName"', ' field1', ' field2']
"Ok", you think, "but I don't want the field names to start with whitespace".
>>> [x.lstrip() for x in s.rsplit(",", 2)]
['CONCAT(first_name, " ", last_name) AS "FullName"', 'field1', 'field2']
@Kevin thx, there may be no fixed points, ex, string can be mixed,
If you're now thinking "but that gives me ['CONCAT(first_name, " ", last_name) AS "FullName"', 'field1', 'field2'], I want ['CONCAT(first_name, " ", last_name) AS "FullName"', field1, field2]. See how there's no apostrophes around the final two elements?" you can't have a string inside a list that has no quote marks when you print the list. You would have to create a custom type that overrides __repr__.
>>> q = '''CONCAT(first_name, " ", last_name) AS "FullName", field1, field2, FUNC_NAME(message,"File Name: F:*, File Type: *,") AS file_name, file_extention | CONCAT(file_name, ".", file_extention) AS "file"'''
@Droid Please take a look at how to format code in chat
12:13
You might have to write your own parser. If a string contains parentheses pairs and you want to treat data inside parentheses differently than data outside parentheses, then that's a classic red flag that ordinary string manipulation approaches aren't powerful enough to do the job
@Droid +1
Or more generally, tokens having context sensitivity is a big deal breaker. In other words, you can't say "any word immediately after a comma is a field name" so any solution based on searching for commas will necessarily have a ton of extra logic stapled onto it
@Kevin okey, thx
12:43
How to find all the numbers in the following string in python is a curious question; OP spent 58 characters in a comment explaining that data_spe is the name of their list, when they could have done it in 9 characters by just sticking data_spe= in front of their first code block
next level waste of bytes
Jimmies moderately rustled that I wrote a beautiful answer for that question before noticing that they also need "23 42 blah" to get matched as "2342" which I'm pretty sure means that there's no solution that's just pure regex
13:26
hihihihihihi
Why are you laughing in Hungarian?
13:40
spoiler - I'm Hungarian.
double spoiler - I'm you from the future
triple spoiler - Yes the world was taken over by Lego
13:55
cbg everyone!
Do we have a canonical for questions about escape sequences in file paths like "C:\folder"? Need it for this
Hmm, my chat tab stopped anti-aliasing text
OK, it's firefox itself
11
Q: Python windows path slash

sarbjitI am facing a very basic problem using directory path in python script. When I do copy path from the windows explorer, it uses backward slash as path seperator which is causing problem. >>> x 'D:\testfolder' >>> print x D: estfolder >>> print os.path.normpath(x) D: estfolder >>> print ...

Not sure if it's the canonical
@vaultah I guess that works, but it really needs an answer with raw strings
Oh, that's better. I should've thought to look there. *facepalm*
Yeah, me too
/canon is quite small collection of questions, and I rarely look there
phew, restart worked
A recent question asks "how to compare the values of two objects, not their type?" and it made me madder every time I looked at it so I had to close the tab
yeah, that makes two of us. It's even worse because it's a unit test.
14:18
3 and "3" do not have the same value in the sense that they are stored as the same sequence of bits in memory. If you discover a method that magically compares two object's values while ignoring type, and expect magical_compare(3, "3") to return True, you're going to have a bad time.
how about u"\u00B3"?
:D
If you want to determine whether two objects compare equal when they're both converted to integers, that's fine, but you should ask for that and not this
Just use javascript
15:03
javascript solves all problems
use jQuery
(cbg)
wim
wim
This is actually a useful task for IDEs etc to know how to do.
rb-cya guys
A re-indentation algorithm seems like a fairly big project even if you're allowed to simply crash in ambiguous cases. If they want someone to write a solution, it's too broad; if they want to know if a solution exists out there somewhere, it's a resource rec
I am happy to be proven wrong - if anyone has an implementation on-hand that can fit inside an answer, I'll cast a reopen vote
that does not look like an easy problem
15:20
I recommend the brute force approach
run through indentation levels and break out once one works without error
:)
The problem is, even code like:
if a:
b
if c:
d
if e:
f
that would give you a solution, wouldn't check ambiguity
Has a lot of possible legal indentations
and don't tell me that anyone who's using this script would be aware of the level of ambiguity in the source...
And who's to say that "use the least amount of indentation" will give the intuitive answer most of the time. Or any other simple heuristic along those lines
I don't doubt that an indenting algorithm is possible, but I do doubt that it would be useful
15:24
Then maybe that should be the answer?
"it is not possible because X" qualifies pretty well as answer IMHO, better than closing it for the given reason
wim
wim
15:48
^ agree
just because a tasks seems difficult is not a reason to close
I've seen people solve some seemingly difficult problems with sometimes very simple and elegant ideas on here ...
e.g. user2357112 solved a similar problem using tokenizer module.
If there is a simple and elegant solution, we should reopen. If the answer is the straightforward, sweaty implementation of an arbitrarily constrained interpretation of the question, we should not
Cool, a sockpuppet ^
morning cabbage
from now on I vow to follow the WET principle: write everything twice
@vaultah who's sock? Was there someone in here earlier with that same question?
@Code-Apprentice You already failed. Or does that only apply to code, and not chat messages?
16:02
That's the kind of forward thinking we need here at the Department of Redundancy Department
@vishnumc welcome, please read our room rules: sopython.com/chatroom, in particular don't post recent questions, especially with no further context. Also, don't create multiple accounts.
Write twice, submit once
@Aran-Fey I had code in mind, but I can apply it to chat if you want
hmm...apparently I can't repeat a reply twice in a row
@Aran-Fey I had code in mind, but I can apply it to chat if you want
No, no, that's alright, thanks :p
I am here for help. Will you please help me with that question?
16:05
No. Please read the previous message.
Yeah ok
@vaultah I feel like this has happened more often lately.
It's a well written question with a clear example. If anyone wants to help you, they will from the main site.
@davidism dunno, I didn't notice
@Code-Apprentice they're a sock, and also found a duplicate with a quick search for "unittest after assert fails"
16:10
Its ok thanks. I think you all know the answer. Because urgency i posted here and sorry for breaking the rules. c u
yah, I should have thought about looking for a dupe
For the auto-indent thing, there's an even bigger issue than chained ifs as @Kevin mentioned here or for/if/else as I mentioned in a comment on the question. Even this is ambiguous: 'if a:\nprint(1)\nprint(2)\n'. Is that second print part of the if or not?
The only option is to always guess rightward unless it's illegal. And if you want to see how that works, try pasting any code character-by-character into either iPython or emacs python-mode.
@vishnumc Assuming that we all already know the answer seems highly unreasonable. We would have to do the same google search that you can do yourself. Google knows all the answers!
"Because of urgency, I didn't search for pretty much the same thing I wrote in the question, and instead got other people to do that."
wim
wim
@vishnumc the answer is, don't do that
put the two asserts into different tests
16:16
@Code-Apprentice google is not an intelligent guy. It just become intelligent through us. Google can provide knowledge which is on any server and it may written by you or me or anyone else. As you said " google knows all " , thats why i am here :-)
wim
wim
as a rough guideline, you want one assertion per test
that's the "unit" in unit tests.
Please take discussion about that question to the main site.
wim
wim
..because it's recent question?
Google becomes intelligent through people posting intelligent things—e.g., writing good questions and good answers on StackOverflow. It becomes stupid through people posting useless questions that make the good questions and answers harder to find.
@wim yes
wim
wim
16:18
ok
@abarnert I'd never thought of it like that. Interesting.
@wim I just have put those in one testcase because the test condition was same for the two assertions.
@wim Haven't you ever seen a question on SO, thought "Oh come on, that has to be an easy search", done the obvious search, and gotten back the same question you were answering (or another, worse, dup of the same thing) higher in search results than the relevant docs page, blog post, or canon SO answer?
morning cabbage
wim
wim
maybe a few times
@abarnert I haven't done that, but I have searched for a question, found the answer on SO, tried to upvote either the answer or the question only to get the message, "You can't vote for your own question"
wim
wim
16:21
if i think a question is an easy google search I generally skip it
I get that occasionally. It's usually a good indication that the question doesn't have a duplicate, but I try a couple other phrases first just to check.
@WayneWerner I've done that too. I also once tried to downvote an old answer that really wasn't even very good for its time and got the same error message…
hahah. Nice
16:43
Mbps = float("%.1f" % Mbps) ...*sigh*
@davidism right, I'm working my way through that tutorial. Do grammatical mistakes count as "bugs"?
16:51
Absolutely.
@AndrasDeak but why
@cᴏʟᴅsᴘᴇᴇᴅ I made a PR so you can add review comments: github.com/pallets/flask/pull/2676
ah okay... I'm compiling a small list as a go along.
great
@excaza not my code :P
I feel like there's better ways to round a number :X
16:57
that's uh.... well, I guess it's reliable?
17:10
Mbps = 0. because it’s hard to get rounder than 0 in just about any sense of the word.
it depends on your font
0 isn't very circular and "roundness" is how closely an object's shape approaches that of a perfect circle
True, but Mbps = • raises a SyntaxError, and i saw someone using 0 instead in some StackOverflow answer, and that made my error go away for some reason, so it must be the right answer to my problem.
Mbps = u"\u2022" is now going in all of my code
Or maybe Mbps = u"\U0001F31A"
17:37
Is the Moon less oblate than the Earth? If not, you probably need to use isclose somewhere to deal with rounding errors.
I think it is
I can't wiki it right now
The moon rotates ~30 times slower than the earth, so if oblateness is caused by centri(petal|fugal) force, I'd expect the moon to be rounder
But I guess it doesn't matter how fast it rotates now, but how fast it was rotating while it was still molten
And tidal locking happened pretty late in its life cycle I think
yup, it's complicated
Wikipedia says that Earth has a flattening of 0.0033528 and the Moon has a flattening of 0.0012. I'm not sure what either of these numbers represent.
maybe it's a scale of 0 = sphere, 1 = pancake
it's probably a ratio of b-a to something, probably a or b or (a+b)/2
or we could wiki it :P
17:47
It's (a-b)/a apparently
Which means the moon is more rounder by a factor of 3
I'm wondering how much I like that "by a factor of 3" :P
both are almost completely spheres, so "this is rounder by a factor of 3" sounds weird
perhaps "the Earth is three times flatter" which is almost the same, but then we compare the small flatnesses
Yeah I don't think those are numbers you can cleanly divide and get a sensible measurement of anything real
Maybe because they're dimensionless
I remember learning in geo 101 that the earth is an ovoid, not a sphere
@Kevin the only things giving you sensible measurements are dimensionless
well, I suppose that still is round... checkmate flat earthists!!!!
17:53
"it's small" only makes sense if you give it a scale of the same dimension. "1 millimeter" is not "small". "pi" is "not small"
@cᴏʟᴅsᴘᴇᴇᴅ *oblate spheroid unless I'm mistaken :P
@cᴏʟᴅsᴘᴇᴇᴅ The Earth is almost an oblate spheroid. Technically it's not even that, but then technically it's not even an ovoid; every overhang on a cliffside means there are lines that intersect the Earth at 4 places instead of 2.
whatever it is, it's not flat... depending on who you ask :D
we have both the Himalayas and the Mariana Trench so it's all a moot point
Physicists have a sliding scale of "featureless sphere -> featureless oblate spheroid -> complicated not-entirely-solid with mountains and people and stuff" that they move up and down as befits whatever math they're doing
but mostly the first
17:57
With a secret unlockable "featureless point mass" setting when doing gravitational systems
I think physicists mostly stop at the first one, except geophysicists. If they can assume a spherical cow… (But of course for topologists, that isn't even an assumption; the Earth is a sphere the same way a coffee mug is a donut.)
Geophysicists do care about the deviations from roundness, but that's because most of them get money from oil companies instead of from government grants, and for some reason oil companies are interested in calculating where there's liquid between the surface and the mantle.
silly oil companies
"for some reason"
According to my one acquaintance who's a geophysicist, the worst thing about the job is that you have to work with oil company execs, scam artists like dowsers, and, worst of all, geologists.
as if being a geophysicist wasn't enough *ducks*
18:07
No, no, ducks are studied by biophysicists, not geophysicists.
3
Hey, a PR of mine for Neomodel just got merged to master :)
@RobertGrant nice, congrats!
@abarnert I learned about that when a friend/co-worker was calculating distance between two points on a map and he learned that there are heckin ways to do that, and they can all be wrong for some reason or another
Tried, tested, works on human puppers as well
Dirty tricks
human puppers? eugh, sounds like that homunculus dog from Full Metal Alchemist
shiver
FMA also had a second dog homunculus who lived a rich fulfilling life, so the lesson is not "dog homunculi are bad" but rather "don't let second-rate alchemists experiment on your children; first-rate only"
there's another important life lesson...
Ah, I see @vaultah's had a complete makeover with his dp
That's a pretty bold change, adding a white line
18:29
@abarnert The existence of the geoduck complicates this delineation. (content warning: Earth's grossest looking animal)
@cᴏʟᴅsᴘᴇᴇᴅ I'm experimenting
It looks like you're beginning to crack a smile... an evil, evil smile
Don't go overboard, or you might get hernia from all that experimentation
@Kevin it isn't a duck!
18:35
@piRSquared Is there a subtle message hidden in that picture? (observe the person's fingers)
@cᴏʟᴅsᴘᴇᴇᴅ sometimes, if you're going to say something, best deliver it in as sweet a way as possible
18:52
I want to log into a site (SO actually), I found this post, I converted it into Python 3 syntax and from the code I do not seem to have logged in. I am wondering what is wrong.
Here is my code: dpaste.com/30M8P89
@abarnert Geophysics is black magic
@wim our dog loves veggies
If your friend is a geophysicist, I hate to break it to you, but we're gonna have to burn your friend at the stake over a pool of black gold.
@Simon I'm 99% sure your code is doing a GET request instead of a POST
bleh, urllib. Use requests.
19:00
geophysicists? the guys studying stones?
no, those are geologists
so what are those then?
Earthquakes, tectonic movement?
What's a gemologist then? Synonym for geologist?
geodynamo, core density, whatnot :P
19:01
Geophysicists study how oil moves underground.
=)
that too
> A geophysicist is someone who studies the Earth using gravity, magnetic, electrical, and seismic methods. Some geophysicists spend most of their time outdoors studying various features of the Earth, and others spend most of their time indoors using computers for modeling and calculations.
> Some geophysicists use these methods to find oil, iron, copper, and many other minerals. Some evaluate earth properties for environmental hazards and evaluate areas for dams or construction sites. Research geophysicists study the internal structure and evolution of the earth, earthquakes, the ocean and other physical features using these methods.
That description was quite nice. Source: earthquake.usgs.gov/learn/kids/become.php
it's magic, and you can do good and evil with it
@Aran-Fey Sorry I went away. Ok thanks, I will check it out.
That would explain it
So this is not an explicitly Python question, more an algorithm one
But I've been using quicksort on a structure that allows me to track indexes (sorting by value)
What happens is that when more equal elements exist
Qsort sort of... jumbles them together, doesn't preserve all the indices
Can I change the implementation or just use a different sorting algorithm?
19:12
You need to make your sort stable, that is, preserve the relative order of elements.
Since you're asking in the Python room, the answer is to not write your own sort. Use sorted.
IIUC quick sort isn't stable, but heap sort and merge sort are (?)
Yeah I'm not doing Python, this chat was just active lol.
I see so that's what stability means
That's not how chat works.
Seems I gotta use merge/heap
Please read our room rules: sopython.com/chatroom
19:14
Not gonna bug you anymore :)
or Tim
Yeah, don't bug Tim either
begginning to think it's just a bad quicksort lol, it's not that indices aren't within relative order, they are being merged/eaten up
19:45
For a pretty wide class of real life problems either Python’s hybrid “timsort” or Java’s variation on it will beat any of the stock sort algorithms.
Unless compares are a lot cheaper than moves, which they never are in Python or Java.
20:18
"Let's just do it in JavaScript" has to be my least favorite phrase of all time.
OK, instead of doing it in JavaScript, let
let's write a custom XML language.
Cabbage
@abarnert I'm not actually going to flag that as offensive, but let's pretend that I did
6
20:39
OK, if you can write it in Forth, we can just print to PS or PDF and read the results back out of that.
We may need an OCR system to read the results, but we can train a deep learning network for that, right?
the deeper the better
Never thought I would hear those words from Andras...
What if we port TensorFlow to Forth? Then we can get rid of the computer and just run everything on a laser printer/copier/scanner. If we include enough paper trays we can get massive parallelism.
 
1 hour later…
21:56
Does anyone know any libraries that generates random and reproducible raw byte data quickly?
use the builtin random with a custom seed?
Nevermind, I don't need an answer for this.
I wish more people on the main site had that attitude...
But they're more like "I want to do this horrible thing and I absolutely need an answer for this, because I don't want to write actual good code"
22:12
@Aran-Fey Sometimes, explaining to them how to do it is the best way to show how horrible it is. (As long as you leave some gaps in the implementation as an exercise for the reader, because otherwise they'll just copy and paste your horrible code into whatever they're working on, and the next thing you know your bank account is broken, along with a million of your closest friends.)
I have another question.
For quick data validation, I'm currently using crc32. What would be the reason to switch to adler32 or just python's builtin hash?
quicker*
Adler32 is simpler and at least potentially faster. Python's hash function is harder to collide with pathological data (but still not a strong crypto hash).
Hello everyone, just heard about this updated requests module youtube.com/watch?v=gKT_tg87H5Y from sentdex, has anyone used it?
On the other hand, if your data is mostly made up of short messages, Adler32 is next to useless, and CRC32 is still pretty fast.
At most, the sizes will be 1 - 2 MB, at minimum they'll be less than 1 KB
I think i read that adler was bad when you have less than 1 KB
22:25
I think that 1KB isn't quite small enough to break Adler, unless there are common prefixes to many of the messages, but you'd probably want to look that up instead of trusting my guess…
The issue is that you need 256 bytes to traverse the whole sum space once, so at 1K you're probably getting a wide enough distribution.
Is anyone good at using subprocess to launch and manipulate vlc?
yeah, some of the objects could possibly be less than 256 KB, so that could be somewhat problematic
Not 256KB, just 256 bytes.
sorry i meant to say 256 Bytes
What are the downsides to python's builtin hash function? For reference, I'm using python 3.6
It's slower. And it's not repeatable, unless you disable hash randomization, in which case it's not much less collidable than CRC32 with pathological inputs.
What are you actually trying to protect against? Is it just error correction for rare disk errors or transmission errors or the like?
22:31
It's not for protection really, it's more just for quick error checking.
It's really not that important, I should just stick with crc32.
I was just curious after looking up the topic.
I guess error checking is protection against error faults, so in that sense my statement was wrong earlier lol.
Yeah. that's fine. If CRC32 is fast enough, I'd stick with that. If you want to work out your exact reliability requirements and do the research to come up with the fastest thing that meets them, I'm sure it'll be faster than CRC32, and it could be that Adler32 is fine (or maybe Adler32(x) if len(x)>CUTOFF else Fletcher32(x) or something?), but it's probably not worth the effort.
Actually, from a quick check, binascii.crc32 actually runs a bit faster than zlib.adler32 on 1MB strings on my laptop, and almost the same speed on a Google Cloud instance. And we're talking single-digit microseconds for 100K-1M strings either way. So… yeah, I'd just CRC.
22:49
Haha, I didn't notice binascii had this too. I'm using zlib.crc32.
Ah, on my laptop, zlib.crc32 is actually not as fast as binascii.crc32. Weird. Maybe that's because zlib is built against the system libz.dylib, and Apple didn't bother to optimize it, but binascii is using code in Python that is a bit optimized?
(My GC instance is Ubuntu, and it seems less likely they'd include a less-optimized libz.)
Google Cloud.
ah!
I suspected it's not garbage collector...
23:13
on my windows VM, binascii runs 2x slower. On a linux server, I get around 3-4x slower with binascii.
Is that a physical linux server? I could imagine most linux distros have a zlib that's better optimized than Python's binascii, while Apple has one that's worse optimized, but meanwhile on my cloud devbox I'm not getting the advantage of most of those optimizations for some reason? (I've seen some weird stuff, like the CPU claims it does AVX2 but when you try to use it things go slower instead of faster…)
hey all! does anyone know how to make an open array in numpy?
k terrible question, actually. I am trying to make a numpy array that excludes certain indexes within the array
23:31
Yeah it's a physical linux server. It's Ubuntu 16.04 with a little bit of my company's flavor to it, but I doubt zlib was changed on this machine.
23:43
@AlexanderBiel I'm pretty sure I can help you if you do a better job at explaining what you are talking about.
@AlexanderBiel you may or may not be looking for a masked array, i.e. the numpy.ma submodule
I'm guessing that's it then: Linux zlib (with either default configuration or Ubuntu's configuration) probably takes advantage of SIMD or other useful stuff on real machines, but is smart enough to know not to try it on some blacklist of virtual setups, while Python's implementation probably hasn't been updated in years, and Apple's is probably forked from an ancient version of FreeBSD and also not updated in years…

« first day (2722 days earlier)      last day (2451 days later) »