« first day (3302 days earlier)      last day (1639 days later) » 
00:00 - 21:0021:00 - 00:00

12:53 AM
['Zimbabwe,ZWE,1988,16029460']
['Zimbabwe,ZWE,1989,16113653']
['Zimbabwe,ZWE,1990,15569294']
['Zimbabwe,ZWE,1991,15865346']
['Zimbabwe,ZWE,1992,16917418']
['Zimbabwe,ZWE,1993,16259101']
['Zimbabwe,ZWE,1994,17684463']
['Zimbabwe,ZWE,1995,15029425']
['Zimbabwe,ZWE,1996,14890560']
['Zimbabwe,ZWE,1997,14294211']
['Zimbabwe,ZWE,1998,14139636] .im working with a data of list which is in the format above in python. i need to extract all the data with three letter codes, and reverse sort it by years. any suggestions will be apprec
 
1:12 AM
@AndrasDeak This is where the fun begins.
 
wim
@Aran-Fey I made the lame puzzle better
# Make foo successfully call bar
class A:
    def bar(self):
        print("hi")

def foo(self):
    super().bar()

a = A()
A.foo = foo
# your line of code here
a.foo()
(answer remains the same)
actually scratch that I need an inheritance in here
there we go:
 
user11867329
Ok guys, updates on my project due to high demand:

I will manually insert 2500 commas in the file tonight!

Boss-man bought new type of coffee at work.
 
@wim Python 2 triggered
 
 
2 hours later…
user11867329
2:51 AM
@AndrasDeak Hey man is it actually possible that my thing's pretty undoable with regex/notepad++ and I'm just running in circle?
 
user11867329
Cause it'd need to transfer something like:

>>Dimensions (H x W x D): 17.5” x 13.6” x 9.6”
Colour: White
Motor: 125W
Container/Collection Volume: 4.8 gal
Intake width/ working width: 8.7 in
Voltage/frequency: 115 V / 60 Hz
Cutting size: 1/4"
Cutting type: strip
Cutting capacity (in sheets): 10
Security level: P-2/O-1/T-1/E-2
Cutting Capabilities: Paper, Staples & paperclips, Credit & customer cards, CDs & DVDs
Weight (lbs): 8.6

into this:

>>,"Dimensions (H x W x D): 17.5” x 13.6” x 9.6” Colour: White Motor: 125W Container/Collection Volume: 4.8 gal Intake width/ working width: 8.7 in Vol
 
user11867329
If yes/no, how would I do that??
 
user10984358
3:51 AM
Heya guys, a pretty much useless need for me rn, but is there a place where I can put “type=lambda x:print(type(x))” so whenever I type a new python code I can do type and get the value printed? One way I can think of is having this line in a file and then add that to my PYTHONPATH and then do import file and do file.type(), is there a way to achieve this without the import? I’m asking something like a bash_profile for python.
 
4:35 AM
@TheNamesAlc Please don't do that. Firstly, it's rarely a good idea to shadow built-in names. Secondly, your lambda won't do what you want because it will call itself in an infinite recursive loop... well, not exactly infinite because it will hit the recursion limit after about 1000 calls.
@TheNamesAlc Of course, you could use a different name, eg ptype. And define it using a proper def, not lambda. That way, the function will have a proper name. Do you just want this function available in the interactive interpreter, or do you want it in every script you run? If it's the former, see PYTHONSTARTUP; if it's the latter, you probably should import it.
BTW, there is a profiler in the stdlib, docs.python.org/3/library/profile.html but that's probably not what you're looking for.
@roganjosh Your windscreen frost question would be fine on Physics.SE, unless it's a dupe. ;) If it's not a dupe, it's almost guaranteed to go HNQ. My guess is that the glass can radiate away heat on both sides, so it gets colder than the ground. But that doesn't explain why the car body doesn't get the same amount of frost. OTOH, car bodies have a lot of thermal inertia, and take a long time to cool down.
 
user11867329
5:08 AM
I DID IT
 
5:18 AM
@OakDev Excellent.
Speaking of Unicode etc, you might find these links helpful:
Apr 16 at 15:48, by PM 2Ring
@WSLUser Here's a nice article about Unicode & encodings which you may find helpful http://kunststube.net/encoding/ Also see http://nedbatchelder.com/text/unipain/unipain.html
Ned's Unipain article is mainly aimed at Python 2, but it still has good general info.
 
user11867329
Script logic wasn't working proper.
 
user11867329
Fixed with @Sheepy 's time with regex
 
user11867329
I need to learn regex.
 
@OakDev Ok. That's why we make a big deal about min-reprex / MCVE. When isolating the problem to a minimal example you often notice the logic bug that is the real cause of the problem.
 
user11867329
5:28 AM
Hey, I provided a gist with both files necessary to create the exemple which was used to "understand" the goal.

@Sheepy reminded me how to ask what I wanted to ask
 
@OakDev Learning to write regex isn't that hard. Unfortunately, the same cannot be said of learning how to read them. ;) So the first lesson in regex is to ask: "can I possibly do this efficiently without regex?". ;)
 
user11867329
Yeah
 
user11867329
But the thing was
 
user11867329
1 I wasn't sure about how to escape the proper character (i'm still not certain of my process)
 
user11867329
2. Replace "" => "
 
user11867329
5:30 AM
etc...
 
user11867329
cause csv
 
@OakDev Yes, I noticed, although I didn't actually look at the gist.
 
user11867329
so, since I couldn't even identify all the actual actions needed
 
user11867329
I couldn't concoct a proper regex flow or wtv
 
user11867329
In my head, I always think "Man, someone must've actually made a business out of something with that function"
 
user11867329
5:32 AM
Like, wtf there's not a "CSV maker" that takes a bunch of text and formats "per X paragraphs"
 
user11867329
to make a
1,2,3,4,5
 
user11867329
but there's "password managers" that auto-fills your password fields
 
user11867329
I don't know, I am sleepy, have a good night.
 
Good night.
 
user11867329
I mean...
 
user11867329
5:35 AM
what's YOUR opinion on password managers that autofill your password fields
 
user11867329
you know
 
@wim I updated it, but it kind of sounds like you're supposed to call A.bar with the correct self (i.e. b) and the intended solution doesn't do that. The puzzle also worked without the inheritance btw
 
user10984358
9:02 AM
hey guys, of these 3, which should go for if i want to see if a list or tuple has the same integer elements
 
user10984358
>>> someTuple=(1,1,1)
>>> reduce(int.__eq__,someTuple)
True
>>> len(set(someTuple))==1
True
>>> someTuple.count(someTuple[0])==len(someTuple)
True
 
len(set(someTuple))==1 or all(x == someTuple[0] for x in someTuple)
 
or?
Ah, not as in python
@TheNamesAlc never the first
But the others don't check if it's an int
 
user10984358
i knew reduce was a bad idea, its for a code site, so it is always an int
 
s = set(some_tuple)  # snake_case!
len(s) == 1 and isinstance(s[0], int)
 
9:04 AM
>>> reduce(int.__eq__, (1, 0, 0))
True
>>> reduce(int.__eq__, (2, 2, 2))
False
 
@TheNamesAlc reduce is not bad. int.__eq__ is
 
reduce is also bad
nobody can read that
 
@Aran-Fey meh. I can't, but it has its use cases
 
user10984358
@Aran-Fey that would perhaps work if i wrote a 2 argument function that returns the actual number if they are same?
 
@AndrasDeak That's a pretty half-assed isinstance check. You're only checking if the first tuple element was an int (since set([1, 1.0, True]) == {1})
@TheNamesAlc it'd work, but why would you do that?
 
9:09 AM
@Aran-Fey fair, but I had ('potato', 'potato') etc. in mind
Your edge case is very edgy
 
user10984358
i guess i will stick with the generator exp. syntax then, adding an if for the instance check
 
@TheNamesAlc not an if. An and.
 
I just noticed how subtle the formatting of inline code is with the default theme. That's hardly distinguishable from normal text, wow
 
@PM2Ring I may well post, but I'm mildly entertained by trying to reason it out atm :) Radiating into the car might be part of the key actually because I'm finding it somewhat unpalatable that it can radiate heat to such an extent that it's 2 degrees below its immediate vicinity. From my engineering history, I can't make the energy balance, well, balance. But the phenomenon is real, so I guess any answer will be surprising to me :)
 
@Aran-Fey which theme do you use? because yeah, it's hard to notice sometimes
 
user10984358
9:14 AM
i just realized why an and was needed and not an if, the latter would only add if it was an int, so it would be true
 
user10984358
i keep seeing themes, how do you use that? i want a dark mode theme
 
@Arne I found a random dark theme for SO and customized it. Still haven't found a really good one, though. Some parts of the main site are still unstyled bright eye killers. I can upload it somewhere if you want to try it though
alternatively, darkreader.org automagically makes every website dark themed. It's honestly better than a lot of manually-written dark styles out there
 
user10984358
@AndrasDeak TypeError: 'set' object is not subscriptable
 
user10984358
i am going to set dark theme rn
 
user10984358
so i cant download the .crx file without having to link my gmail with the chrome in mywork laptop?
 
9:22 AM
you shouldn't have to download anything... both addons are available on the addon store
unless you're using a very exotic browser
 
user10984358
that was easy, so apparently the sign in button was just there, i thought once i clicked add, it would prompt me to sign in, guess not
 
darkreader's code highlighting is as bad as the default one =/
* for chat.stackoverflow
 
user10984358
this even works on leetcode :O
 
@-moz-document domain("chat.stackoverflow.com") {
    div.message pre, div.message code {
        background: #e0e0ee;
    }
}
for the light theme users
hrmm, I should probably start using @document instead
 
you expect too much of me, my frontend skills are on par with my dog's frontend skills =(
 
9:40 AM
hmm, I wonder if there's an easy way to install a style... let me try putting it in a gist
 
thanks, I appreciate it
 
hmm, nope, a gist is no good. Seems there's no way to easily install it unless it's uploaded on userstyles.org
 
9:58 AM
amazing, thanks!
 
10:27 AM
Morning guys, any ideas how to fix this issue : ModuleNotFoundError: No module named 'ctypes' ? Using : MacOS, Anaconda trying to build a standalone simple application using py2app :(
 
you can try message formats there without disturbing anyone
 
So I got the following issue with pytest:
from model.entities.LocationEntity import Location
from model.entities.RelationshipEntity import Relationship
from model.entities.InterestsEntity import Interests
from model.entities.SearchesForEntity import SearchesFor
from model.entities.ProfessionEntity import Profession
from model.entities.SexualOrientationEntity import SexualOrientation
class User(object):
    def __init__(self, name: str ,age: int,profession: Profession, interests: Interests,
                            relationship_status: Relationship, sexual_orientation: SexualOrientation,
Testfile:
from model.entities.UserEntity import User
from model.entities.ProfessionEntity import Profession
from model.entities.InterestsEntity import Interests
from model.entities.SearchesForEntity import SearchesFor
from model.entities.LocationEntity import Location
from model.entities.RelationshipEntity import Relationship
from model.entities.SexualOrientationEntity import SexualOrientation
def test_user_creation():
    """ Test creation of user """
    u = User(name="foo",age=12,profession= Profession(),interests= Interests(),relationship_status= Relationship(),
and the error:
def test_user_creation():
        """ Test creation of user """
>       u = User(name="foo",age=12,profession= Profession(),interests= Interests(),relationship_status= Relationship(),
                              sexual_orientation= SexualOrientation(),searches_for= SearchesFor(),location= Location())
E       TypeError: __init__() missing 1 required positional argument: 'name'

tests\model\entities\test_UserEntity.py:10: TypeError
im running pytest btw
`python -m pytest tests/` from root dir
 
consider putting all this stuff inside of gists, anything longer than ~10 lines is a bad fit for just posting it into chat
 
Seems pretty clear to me. One of the constructors you're calling (Profession(), Interests(), Relationship(), SexualOrientation(), SearchesFor(), Location()) is missing an argument
 
10:33 AM
judging from the error message I'd first try to create all the other objects like Profession, Interest etc. on separate lines, maybe one of them needs a name too.
 
@0x45 please check whether you are using the correct version of your code. I could not reproduce this when replacing your models with placeholders.
 
oh... youre right Arne
I misunderstood the error then, thought it was talking about User.name
Thanks!
 
np, Aran was faster though
 
Ah yeah
 
anyone ? any ideas :(
 
10:37 AM
@AnotherUser31 do you get the error when building or when executing your application?
 
yes, i try to run it and I get this error : File "/Users/adrian/dist/myapp.app/Contents/Resources/__boot__.py", line 60, in <module>
import ctypes
ModuleNotFoundError: No module named 'ctypes'
2019-10-31 11:34:39.878 myapp[4031:550808] myapp Error
using anaconda
 
If I didn't know any better I'd assume anaconda installed python incorrectly, and now it's broken. Can you tell it to re-install it?
But I'm not an ana/conda user (and I think neither are most people here). you might have more luck asking here gitter.im/conda/conda
 
11:16 AM
@TheNamesAlc whoopsie
make that s.pop(), sorry
@AnotherUser31 does ctypes work with your interpreter?
Or is that what isn't working?
 
user10984358
you must have let it slip thru when you typed if off the top of your head, np :)
 
If you built python yourself you need libffi in order to be able to build with ctypes
@TheNamesAlc still a shameful mistake to make :P
@TheNamesAlc there's also rlemon's dark theme for SO chat, ported to firefox by Madara Uchiha github.com/MadaraUchiha/se-chat-dark-theme-plus . It has additional features, like handling oneboxed images/gifs and emoji input
 
user10984358
i see someone from naruro i click, also surprised that name wasnt taken by some one less active
 
he's been Madara in SO chat alone since 2012
 
user10984358
11:31 AM
only know names here :/ , also for what i was about to ask before i got side tracked, if i am doing this for large files and i need the text in tags, what difference do these snippets make
 
user10984358
for event,elem in ET.iterparse(xml_file, events=('start','end')):
	# stuff
	# stuff
	elem.clear()


for event,elem in ET.iterparse(xml_file, events=('start','end')):
	# stuff
	# stuff
	if event=='end':
		elem.clear()
 
user10984358
ET=xml.etree.ElementTree
 
user10984358
the only difference i gathered at a cursory notice was the first one gave elem.text as None, where as the second doesnt (gives me the text) for the "end" events
 
cbg
 
12:25 PM
@TheNamesAlc I suspect the behavior of the first one is implementation-dependent, so you should avoid it. When the parser generates an element under the "start" event, the contents of the text and tail attributes are undefined; you can't be sure whether they exist yet, and whether they'll be created later. So if you call clear() and clear out the text and tail, then you might be clearing it out, or maybe you aren't and the parser will go on to populate those attributes later.
From your description it sounds like that it pretty consistently does clear out the text, since it's still empty when the "end" event occurs for that same element. But you can't be sure it will always behave this way, on all distributions and environments
 
user10984358
so Tl;DR is get values when event is end and then clear?
 
Are you sure you need to clear at all? If you're only trying to extract data from the document, I don't think you should be altering it at all.
 
user10984358
<?xml version="1.0" standalone="yes" ?>
<a>
	<b>b text
		<c>c text</c>
	</b>
</a>
 
user10984358
if that is my "huge" xml, then why does <a> have <b> as well?
 
Define "have"
 
user10984358
12:33 PM
What I mean is when I do for child in elem : inside the for event,elem in ET.iterparse(xml_file, events=('start','end')): i get b in it
 
Makes sense to me. The <a> node has one child, and that child is the <b> node.
 
user10984358
shouldnt it read lazily?
 
It sounds like you're surprised that the element has any children at all during the "start" event. I think this bit from the documentation is relevant: 'iterparse() only guarantees that it has seen the “>” character of a starting tag when it emits a “start” event'
In other words, the parser is allowed to emit the start event immediately after seeing the ">" in the "<a>" tag. But it's also allowed to read farther and emit the start event further down the line
 
user10984358
but <c> will not be "visible" right?
 
user10984358
root=ET.fromstring(xml_file.read()) gives me MemoryError , this is the only reason I went for iterparse
 
12:41 PM
I think it might depend on which parser you're using.
 
user10984358
i havent specified anything explicitly, though i came across lxml being used at various sources i looked
 
user10984358
elem.clear() clears the particular tag from memory, is that what it does, am I understanding that part correct?
 
You can't be sure that <c> won't be visible by the time <a>'s start event emits. There's no guarantee that the parser will only read some finite number of nodes ahead. For all we know, it creates a model for the entire document before emitting any events.
It probably doesn't do that, since that would make for a lousy incremental parser, but it's not forbidden by the specification
 
user10984358
anything other than pastebin that is possibly not blocked in orgs?
 
user10984358
if someone can explain the part i want to show I guess my mind model will be pretty set
 
12:48 PM
Regulars with restrictive firewalls tell me that Gist and dpaste work for them
 
user10984358
dpaste works, can i bother you to look at a small snippet and explain that, 10 lines of code?
 
Yeah.
 
10 lines of code to look at will be a great improvement compared to usual business :)
not meaning you, but the room in general
 
user10984358
lol, here it is dpaste.com/0EXGY0M , the xml_file is what i posted the ones with <a><b><c> tags
 
Here is CPython's current implementation of iterparse. The noteworthy line is data = source.read(16 * 1024); this implies that the parser parses the file in chunks of 16KB
 
12:52 PM
cabbage
 
user10984358
so when i visualize the elem tag after the first iteration i get the whole xml, and then its just sub sets, if i get the whole file at once, its no point in iterparsing isnt it?
 
Since your sample data is smaller than 16 KB, it's true that the first iteration will yield the entire document. When your data is larger than 16 KB, I would expect minidom.parseString(eTree.tostring(elem)) to fail on the first iteration, since eTree.tostring(elem) would fail to properly serialize the element, since it's not necessarily fully populated yet.
 
@TheNamesAlc try with ^ Kevin'd
 
If your file is 32 KB, for example, I'd expect tostring to either crash or return a string representation of the top-level element and only half of its children
 
user10984358
740 MB :)
 
12:55 PM
cbg all
 
@TheNamesAlc also for your example
 
But let's pretend that tostring always succeeds because the element is always fully loaded. In that case, you are correct that there's no point in iterparsing, since tostring will create a 740 MB string in the first iteration.
 
@TheNamesAlc I replicated the <b></b> block of your example 5000 or so times, and now I get multiple batches with your code
 
user10984358
my main goal with this is to take all the "text" <tag> text <tag> in all tags
 
I'm not entirely confident that iterparse is memory-efficient in any case. I suspect that by the last iteration, the entire element tree is fully loaded in memory.
 
user10984358
12:59 PM
that is why elem.clear() ?
 
user10984358
at each end event if i clear that reduces that overhead? that is what some SO answer suggested to a similar question
 
Hmm, possibly
 
user10984358
but what made me doubt that was seeing the first iteration in the outer loop, the one for <a> gave the entire tree i was thinking elem.clear() wouldnt be of help, but if it reads in chunk i guess it will work
 
If I understand your goal properly, I think you should only be iterating over "end" events
 
cbg. Is there a way to only allow certain string values with typing.Union? For example, something like this (this is incorrect syntax, because the values have to be types, not strings):
NUM_TYPES = ["float", "decimal"]
STR_TYPES = ["varchar", "char"]
DB_TYPES = Union[NUM_TYPES, STR_TYPES]
x: DB_TYPES = ...
 
user10984358
1:03 PM
to sum it up, I get "text" when the event is "end "then clear, that stands?
 
user10984358
yeah that
 
There's no point in iterating over start events, because there's no guarantee that the text is accessible at that point, and there's no guarantee that .clear() does anything at that point. So you may as well work entirely within "end"
 
user10984358
yeah right, thank you both of you!
 
no problem, though I'm not sure I did anything :D
 
DATA_DOT_XML_CONTENTS = """
<?xml version="1.0" standalone="yes" ?>
<a>
    a start text
	<b>b text
		<c>c text</c>
	</b>
    b trailing text
</a>
"""

import xml.etree.ElementTree as ET

results = []
for event, elem in ET.iterparse('data.xml'):
    for s in (elem.text, elem.tail):
        if s and s.strip(): results.append(s.strip())
    elem.clear()
print(results)

#result: `['c text', 'b text', 'b trailing text', 'a start text']`
 
user10984358
1:09 PM
well I was stuck at getting a mental model for this so I was pretty desperate for any insights, everyone already left home :/
 
user10984358
didnt know .tail was a thing
 
It's not strictly necessary if you only care about text that exists by itself in an element
 
user10984358
well I dont really know if there are such lines, but afaik there isnt any
 
user10984358
thanks again!
 
I wonder how hard it would be to make results have the same order as the original document. Right now "a start text" appears last.
 
user10984358
1:13 PM
after the first for append those results in a temporary list and then reverse and add to results?
 
I don't think a single reverse call will accomplish what we want.
Maybe something with a stack of lists...
 
user10984358
leave that part to me :) it is like a code site problem at that point
 
"Turn a postorder traversal of a tree into a preorder traversal using only O(height(tree)) additional memory" is such a code site problem
 
user10984358
I dont feel comfortable enough with my recursion skills to dive into that :/ , yet
 
It's extra hard because you can't use recursion here, you need an iterative solution
 
user10984358
1:20 PM
At this point in interviews they ask they such questions just because they can
 
Thinking about it some more, I don't think it's possible to use iterparse to iteratively extract all text in order unless you can store every piece of text in memory simultaneously. Which is fine if 99% of your 740MB file is tags and indentation and only 1% is text, but if the document is text-heavy then you may be in trouble
 
user10984358
at most the tags are 5 levels deep and the text is more of numbers or N/A
 
user10984358
only the deepest tags have text
 
Or maybe I'm thinking inflexibly. It's impossible assuming that it's never safe to inspect the text or tail of any element during a "start" event, but now that I think about it, it's only unsafe to inspect the current element. Inspecting the current element's parent's text should be safe...
 
user10984358
1:31 PM
how do you find the parent of elem, do I need to store it explicitly and then do? i dont think you can do elem.parent
 
user10984358
@gerrit I would love to tag with them, for that, adds value to my resume until they ask what exactly are you an expert in
 
Right, and even if elem.parent was a thing, there would still be corner cases where it doesn't give you exactly what you need
 
user10984358
will xmlToDict work here? or does that throw up a MemoryError?
 
MemoryError, probably
 
user10984358
what troubles me is there is a perl code that does what i want to do
 
1:36 PM
I changed my mind. It's possible with iterparse, but the algorithm is tricky.
 
user10984358
but the internal docs has all but this code
 
user10984358
how tricky is tricky?
 
"Not obvious at first unless you're Dutch" level
 
I'm wondering, would using beautifulsoup help anything here?
 
I have a plan.
 
1:48 PM
good thing it's halloween, because that sounds very spooky
 
user10984358
BS needs the whole dump to begin with I guess
 
oh, happy halloween and all that stuff
 
user10984358
I don’t have that here but I’m just going to watch a scary movie
 
2:10 PM
ooooh I've managed to build my python with numpy
I can barely contain myself :D
 
standing ovations
 
and I only had to build, uh, ssl, libffi, and the entirety of GNU binutils including assembler and linker from source
all I need is...scipy and numba. Should be easy :D
 
@isquared-KeepitReal If you make those enums instead, then it would work right out of the box
 
@isquared-KeepitReal use a typing.Literal
 
welp, seems like I have to build scipy as well
 
> New in version 3.8.
 
@TheNamesAlc Prototype inorder text iterator, which I have barely tested: dpaste.com/3SFP8NZ
Oops, "inorder" is the wrong word. "preorder" is what this does.
 
user11867329
i didit
 
user11867329
\o/
 
user10984358
@Kevin Welp, I’ll saw yields in it. Time to pen and paper trace this code :D
 
2:27 PM
The yields aren't strictly necessary. You could replace each one with a print call and the result would be mostly the same
Also notice that the function is not recursive, so there's not much that needs to be traced
 
user10984358
I’ll try it out. Thanks a bunch.
 
user10984358
I wish I were Dutch rn
 
I have a feeling that this could all be done much more easily by directly creating an XMLPullParser and feeding it data one byte at a time, but that's not as fun
 
ok guys, what are your opinions on this?

i'm using pytest fixtures to mock things like amazon SQS and to spin up databases for my testing. i have some long methods that enter in a couple things into a database, maybe perform some operation, and return some response
i can (and do) write a test to make sure all of those things would be done
but these tests all rely on the same fixture, which persists through out them
is this bad practice? that is, instead of:
    run_method()
    test_thing_1_is_put_into_database
    tear everything down (nothing persists) and move onto next test

    run_method()
    test_thing_2_is_put_into_database
we just have
run_method()
test_thing_1_is_put_into_database
test_thing_2_is_put_into_database
tear_down
 
I think the ideal is to create everything from scratch every time, but it's justifiable to bend the rules if it turns out that the right way makes your test suite take 80 hours to run
Perhaps it would be possible to do a partial teardown at the end of each test. Revert the single most recent commit, but leave the database itself alive
 
2:42 PM
that's definitely possible (to make the database fixture module-level, but anything put into the database is removed after every test—so the method has to run every test)
what would the 1st style prevent that could be overlooked by the 2nd?
 
The 2nd as in the approach you proposed following your "we just have" message? If the first test has unexpected side effects that you're not aware of, it may interfere with the results of future tests.
Suppose you have a database with tables WIDGETS and SPROCKETS. Your first test is supposed to insert a row into WIDGETS, and verifies that the WIDGETS table has one row. Your second test is supposed to insert a row into SPROCKETS, and verifies that the SPROCKETS table has one row.
But unbeknownst to you, the first test actually inserts one row into WIDGETS and one row into SPROCKETS. Your first test runs and succeeds, but your second test runs and fails, because it sees that SPROCKETS has two rows.
This is a problem, because the code executed by the second test is actually working perfectly. The problem is with the code in the first test. But you don't know that, since your test framework says that test 1 succeeds and test 2 fails.
 
good point yes. ok, i think i'll just tear everything down and spin everything up at the beginning of every test
and i'll worry about persistence if the time they take to run becomes prohibitive
thank you :)
 
Approach #1 (tearing down everything every time) and approach #3 (reverting the most recent commit but leaving the database alive) don't fully solve this problem -- test 1 will succeed, and you won't be aware that it incorrectly inserts a row into SPROCKETS. But at least both approaches correctly report that test 2 succeeds.
 
oh. the assumption i'm making is that "run_method()" in test1 and test2 does exactly the same thing--that is, the same method, same arguments, same everything is being run
it's just being run twice (so that the tests maintain independence)
so if we have something like...

def method():
    insert_something_into_WIDGETS
    insert_something_into_SPROCKETS
    return 'success'
    our tests could either be persistent:

    spin up
    run method()
    check WIDGETS
    check SPROCKETS
    check return value
    tear down

or

spin up
run method()
check widgets
tear down

spin up
run method()
check sprockets
tear down

spin up
run method()
check return value
tear down
does that change anything?
 
3:00 PM
If both tests run exactly the same code, then it's probably fine to execute that code only once before running the tests, and tear it down only once after all the tests are done.
 
oh cool. i think that is ok too. thanks for helping out: i have like... a gut reaction against having any persistence what so ever, even though it makes sense to have some. i needed to make sure it made sense to have some
 
3:39 PM
One reason you might teardown after every test anyway is if you're paranoid that the assertion itself has side effects. assert foo.bar == 23 followed by assert foo.troz == 42 with no intervening teardown might have a surprising outcome if it turns out that bar is a property whose getter mutates the attribute troz for some reason
keyword "paranoid" there as most properties don't mutate public attrs willy-nilly without thoroughly documenting this fact
Unrelated topic. Do we have a canonical post for "Q: My return statement, which executes unconditionally inside a for loop, only returns one value. How do I make it return one value for each iteration? A: try using yield instead"?
 
4:07 PM
morning cabbage
 
5:05 PM
cbg
 
cbg
 
Something has gone wrong with my brain's code styling engine because I keep subconsciously doing parity checks like if x %2 == 0 and I don't know why it's skipping the space between % and 2
 
maybe something's making you think of "2 percent" - so you're writing it as such, and then another bit is making you "that makes no sense for code... it's %2" or something?
 
Ascii pitchfork has had a good run... just sayin
 
The people love to see me get hoist by my own petard
 
wim
5:19 PM
🎃 great google doodle today! 🎃
 
Just highlighted "google" and selected "Search Google for 'google'" in order to find the Google frontpage
 
@Kevin are you back on those energy drinks again :p
 
No, since "again" implies that I ever stopped
 
and "drink" implies pouring the liquid into the mouth. We all know that intravenous is the way to go.
 
5:26 PM
btw, I'll be marketing a new energy IV
any suggestions for names
 
"IV Loko"
 
Someone at the office suggested
"Methed Up"
My contribution was "Direct Energy" but it lacks flare
 
@piRSquared fairly sure that'd have a huge connotation related with actual illegal drugs but...
 
/dripping_sarcasm Oh! I hadn't noticed that at all. I thought it implied that it was so potent it gave you a lisp. (-: /end_sarcasm
 
hey hey. i'm trying to do recursive downloads in python like wget, i'm using scrapy but it seems a little overkill for what i want and i'm not 100% sure how to use it
is there a simpler tool
 
5:39 PM
@Jarede is it though if you're trying to do the same thing?
what's simpler?
 
i'm not sure
 
seems you to should stick to wget (using it recursively) or learn how scrapy works, maybe?
 
wim
5:52 PM
Sep 20 '18 at 16:43, by Andras Deak
meth(): not even once
 
wim
6:11 PM
@Aran-Fey it doesn't with the "easy" solution, but it is also possible to solve it with passing the correct self in one-line.
 
6:27 PM
i miss the 3 close votes to close feature.
 
@AndrasDeak closed
 
7:19 PM
@ParitoshSingh I kinda miss the 1 vote close :p
 
7:35 PM
>>> zed.scare()
Python 3 isn't turing complete!
 
Well, I managed to make it back to the house without being egged. Hate Halloween round here :/
 
Todays' DenverCoder9 moment: There are polygons with only right angles which have an odd number of corners cites cs.rice.edu/~keith/DuncanHall/myths.html as proving that odd-numbered right-angle polygons are possible. The page merely says "Thanks to Ken Kennedy for the proof". There is no citation and Ken Kennedy has been dead for twelve years.
The maintainer of the page describes himself as being terrible at email correspondence. Someone needs to physically go to Rice University and confront this man.
 
wim
@Aran-Fey :D
 
Want me to update the riddle? The zombie version is a bit long
 
wim
7:59 PM
sure
or just delete it, I don't care
 
oh, the solution is actually different, isn't it
 
wim
yep
well, that my intended solution, I bet there are other ways to solve it too (probably better ways)
 
sopython fails to load pretty often lately
 
wim
oh, that works, but it still leaves poor zed with some kind of dissociative identity disorder. won't stop him trick or treating I guess!
 
Is there a Pulp Fiction reference in there?
 
8:42 PM
I thought it was a LPTHW reference
/me doing quality control sampling of our Halloween candy
 
I was doing some searches around Zed and he seems to just wanna paint these days (and make some yet-to-be-seen JS project)
 
primarily I think it's a "Z as in zombie" reference, but Zed's dead, baby
 
Is there some benefit of res = dict((v,k) for k,v in a.items()) vs. res = {v:k for k,v in a.items()} for swapping keys and values in a dict? A dupe search brought up this answer which credits erik for his suggestion for Python 3, yet changes it
 
dict comprehensions came in 2.7/3.0 python.org/dev/peps/pep-0274
 
So it's just trying to keep consistent with the 2009 answer/approach rather than any benefit over a dict comp?
 
8:55 PM
@roganjosh I guess they focussed on iteritems vs items
 
I was guessing that dict comps hadn't been around when the answer was first posted, but I see no reason why the P3 version shouldn't be the idiomatic dict comp since they came with 3.0
 
I'd say the dict comp is even superior because you can shadow dict
 
Is it worth editing it in to that top answer? Because you have to go a long way down the answers before you get to an answer that actually uses erik's suggestion
Actually, no, I missed this one
 
00:00 - 21:0021:00 - 00:00

« first day (3302 days earlier)      last day (1639 days later) »