« first day (3426 days earlier)      last day (1513 days later) » 

12:16 AM
Are there any guides on how to write a wrapper/interface/non-web API for Python? I'm writing a wrapper, like github.com/soundcloud/soundcloud-python, and would like to consume some instructional resources first.
*and digest
 
not quite sure what kind of guide you're looking for. Something about OAuth and interacting with web APIs?
 
I'd just be using requests. In the Soundcloud wrapper, they use OOP and __getattr__ a lot, I was just hoping for some guide/best practices etc. resource related to that.
 
That __getattr__ usage doesn't strike me as a good design choice tbh
Anyway, I'd be surprised if there were guides about this stuff
 
gotcha, what would you use instead, just declare the get/post etc. methods outright?
Better yet, where have you learnt that? So that I may consume and digest the same material.
 
I'd declare the few methods that I need manually, yeah. You rarely need more than GET and POST
that's all just from experience
 
12:29 AM
ok
 
also it's weird that they made all those methods public. Why would the user ever want to call those?
 
12:49 AM
to be clear, the __getattr__ I don't like is the one in Resource. Although there may be a reason for it that I'm missing. The __getattr__ for the HTTP methods isn't all that bad
 
gotcha, why would you want to use __getattr__ for the http methods anyway? Since the valid calls are listed anyway in client.py:137.
 
It's shorter than writing 5 near-identical functions. Not the worst use of __getattr__
 
ah ok gotcha, thanks
 
I feel like most of these wrapper modules are written rather poorly. One time I found one that printed exceptions instead of raising them. That was wild
The module was basically unusable because of that
 
yes, which is why I want to learn how to do it properly.
 
1:06 AM
well, the good news is that the stuff that's going on under the hood is pretty irrelevant. Wrappers are usually pretty small projects (unless you're wrapping something complex like git), so the software design doesn't matter that much. What matters most is that the interface is nice
 
yes, I agree. I'll be unit testing it so that should help quite a bit.
 
 
6 hours later…
7:29 AM
@AndrasDeak done
 
thanks
 
7:59 AM
I have TimeStamps in format like 1583207280076325928, and need to group them minutely
1583207280076325928/10**9 and change last 2 digits to 0 should make a group i think
 
If you want them grouped by a minute, floor divide by 60 (after converting from ns to s).
 
(1583207280076325928/10**9)//60
26386788
 
@pythonRcpp getting a strange feeling of deja vu :)
 
8:23 AM
ts[0:10])//60*60 works, thanks
 
are your time stamps strings?
 
That looks like truncating them to minute precision, not grouping :)
 
@pythonRcpp weren't you doing this before and knew how to do it using pandas but didn't want to use pandas?
(unless I'm imagining it - fairly sure you were asking something like this last year?)
 
8:51 AM
cbg guys o/
 
cbg \o
 
cbg \o/
 
cbg /o\
 
9:13 AM
     |\_/|
     | @ @   Woof!
     |   <>              _
     |  _/\------____ ((| |))
     |               `--' |
 ____|_       ___|   |___.'
/_/_____/____/_______|
 
train wrecked D:
 
 
1 hour later…
10:23 AM
Anyone know prediction future values with LSTM?
 
you have a specific question or are you asking in general?
if you're asking in general, this guy knows
 
I m stuck in a part of LSTM. i tried to follow a tutorial (i looking this guy code too) but i really don't understand how to capture future data
 
go through the machinelearningmastery tutorial, and see if that helps clear things up. There's a good amount of explanation of how you should be laying out your data in that blog post
 
10:43 AM
Hi I am trying to scrap https://www.olx.in/ using selenium but here when I try driver.find_element_by_xpath('//*[@id="container"]/main/div/section/div[2]/div[3]/div[1]/div[2]/div[2]/div[3]')
It is saying not found but the element is there in that website I am not understanding why it is showing like that
 
11:10 AM
In my current program, I'm using scapy to read in the packets as a stream from a .pcap file from wireshark. How could I replay these packets over TLS to a server running on localhost (same as TLS client sending the packets)?
 
aloha friends, any Pyspark experts in the house?
 
@Datanovice room rules "Ask your question directly. Avoid asking if it's okay to ask, or if anyone knows about a topic. Users may want to see your question before speaking up, and users who join later can see it."...
 
ah fair, has anyone had any fun with dynamic partition with Pyspark 3.0 ? if so what was your experience
 
11:53 AM
@Datanovice nope, been only using AWS Glue which has PySpark 2.4 and 2.2 and it wasn't fun at all :P
 
datalake curation is such a pain in the arse thanks @AnttiHaapala
 
@Datanovice news at 9.
but I guess this is not even PySpark specific, you could also ask Scala datascientists alike
 
datascalaists
 
there are PySpark specific idiocies like when if you write something in Python and it sifts all data from java from there and back again...
 
datascientsts and datalake curation don't usually go hand in hand
 
12:42 PM
I have a non-python but stackoverflow-y question
 
shoot
 
A few months ago I saw my "Impact" increase drastically, up to 305k but with no obvious explanation. For instance some people I follow (Ansev) with like 3x my reputation, 2x my amount of answers and so on, has not even 1/3 of my impact, is there any cause? Or has been a ddos or something kind of thing?
(He's also been for more time around than me)
 
@CeliusStingher "Impact" as in "people reached" in your profile?
 
@CeliusStingher It's not a very significant statistic, but anyway meta.stackexchange.com/questions/332317/…
 
1:17 PM
with ThreadPoolExecutor(max_workers=10) as executor:
    futures = {executor.submit(Second, link, name): link, name for link, name in First}
 
SyntaxError?
 
you need parentheses around link, name
 
Cbg
 
the first pair, directly after :. The second is fine.
 
1:19 PM
or do {executor.submit(Second, link, name): link_name for link_name in First}, since First is apparently a sequence of pairs (might not be tuples tho).
Looks like reverse memoizing
 
First is actually a Function which return 2 values
 
@PaulMcG Fogetting?
 
got TypeError: 'function' object is not iterable
 
@αԋɱҽԃαмєяιcαη yeah
Call it...
 
Should be First()
 
1:21 PM
Ops . my mistake
 
This ain't ruby
 
:D you got me
 
@PaulMcG I think it should be executor.submit(Second, *link_name) then
 
Ah, correct - I am in pre-coffee stage
 
@PaulMcG you need some java
 
1:24 PM
Wait, does First() return a sequence of pairs?
 
are typed languages like... less resource-intensive or something?
or is the only difference in potential bugs?
 
@MisterMiyagi using *args will not be good in my case since am calling the values separately in the function .
i got stuck into it now for "ValueError: too many values to unpack (expected 2)" going to share the code now.
 
@αԋɱҽԃαмєяιcαη the * is for unpacking the arguments, not for receiving them
 
@AmagicalFishy do you mean statically typed?
 
1:27 PM
yes, statically typed is what i meant
 
these are usually easier to compile, thus less resource-hungry at runtime
 
Ok, First returns two lists, and you want the list values matched up. Change First to return a single list of pairs - you can do this by changing your return statement to return zip(links, names)
 
whether the cost of compilation outweighs the runtime cost depends on the use-case
 
@PaulMcG got it. just for my own knowledge, i couldn't assign the zip inside the futures? correct?
 
@αԋɱҽԃαмєяιcαη You should reconsider your naming scheme. A function named First is at best obscure.
 
1:30 PM
@MisterMiyagi i understand that point.
 
ah, makes sense.
 
@αԋɱҽԃαмєяιcαη Not so much that you couldn't assign it, as it is clunky to pass around paired values in two separate lists. If you want to keep First as-is, then you could write, um,... {executor.submit(Second, link, name): link, name for link, name in zip(First())}. As you have written Second, it takes only a single link and name, so you need to zip the lists before this.
 
@αԋɱҽԃαмєяιcαη What is the point of the dictionary in the first place? Looks like a job for Executor.map
 
@MisterMiyagi i were having the same question for myself. but in many articles and even in the official document they pass it as dict. idk why. docs.python.org/3/library/…
 
@αԋɱҽԃαмєяιcαη The example actually does the reverse lookup to get the url from the future: url = future_to_url[future]. Your code doesn't do any such thing.
 
1:39 PM
@MisterMiyagi thanks for clarifying that.
 
Thanks for posting - I learned about concurrent.futures.Executor. Looks like a legit form of the previously undocumented multiprocessing.pool.ThreadPool.
 
you welcome :)
 
@AndrasDeak Alright, so regarding my question on impact/people reached I think I have an answer based on the comments of the meta question you sent me
"Seeing my total reached is about 700k and all my other posts are in <20k views posts, my guess is that it erroneously adds the views regardless of when I posted an answer in a question."
 
@PaulMcG if you don't mind, could you please show me how it's can be done using map ? i tried with >> futures = executor.map(Second, *First())
 
Though it still has the same flaw as the ThreadPool - the iterable passed in gets fully traversed as part of calling map, rather than pulling from it as workers need new work. At our office, we sometimes want to spin up workers to chew on many, many millions of things, and ThreadPool (and also ThreadPoolExecutor) begin by building a complete list of tasks before starting, and this makes for some pain.
Are you keeping First() as-is, returning two lists?
 
1:52 PM
return zip(links, names)
 
Ok, then First() is returning the iterable that you want to pass to map. Also, from my brief experiment, map does not return Futures, but returns the actual values from the returned by the given function.
You will need to write Second to accept a tuple, not two separate args.
 
I think Second can be left unchanged if First returns two separate lists. It must be unpacked in the map call then, though.
@PaulMcG You wouldn't just happen to know a library that does these things properly?
 
If you want to keep Second as-is, then you'll need something gross like: for result in executor.map(lambda link_name_pair: Second(*link_name_pair), First()): print(result)
 
i usually mixed up with map and lambda
i've to re-look into them once again as am rarely using lambda
 
@MisterMiyagi I've written my own class to do it, but it isn't publicly available
 
2:12 PM
My grumpiness is strong today. Is posting a question with an answer to make clear one doesn't look for that answer dubious?
 
The "I'm looking for alternatives" part doesn't belong in the answer, but otherwise it seems fine
 
@MisterMiyagi my mental parser is struggling with the issue as-worded :/
Ah ok, it's the last sentence. It probably should just be edited out. A link to the library would probably be helpful too
 
Looks like a double-dip: posting a question that is asking for recommendations (discouraged for fomenting arguments and debates), plus getting rep for both the question and the answer.
I'm close-voting as "opinion-based"
 
2:34 PM
@CeliusStingher that seems reasonable. No point in bending over backwards for a reliable number. Nobody cares.
 
We should host monthly / annual prizes on different categories of questions
"Funniest titles", "Most innovative topics", "Shortest/straight to the point question", etc... Sometimes I can't help but LoL when I read some titles
For instances, the one @roganjosh is actively participating in ^.^ stackoverflow.com/questions/60509480/…
 
@MisterMiyagi very unclear
 
I think the title does belie a bit of an issue with understanding. It comes across as "I've seen the light" but I'm erring on the side of them just not having stumbled over a straight "it's slow" answer
It's not outside the potential bounds of reason that you could find loads of answers with "don't iterate a dataframe" without any qualification for why
 
Yes. However my first interpretation was "Why no one iterates a dataframe like me" as in "Ain't nobody do it like I do"
 
cbg.... getting moo'd at bring back memory of when DSM was around :\
 
2:45 PM
I just happend to listen to a lot of stand-up comedy podcasts and my mind doesn't always work appropriately. "You guys might be pro coders and talk about efficiency and vectorized operations, but have you checked my code? Did you see how I iterate? You guys know nothing, no one iterates a dataframe like me ;) "
 
@CeliusStingher I've sadly got a bookmark folder for "amusing but deleted questions"... one of those titles was: "Answer me please i need to know everything before i start"
 
@JonClements don't suppose the answer to that is available somewhere? Asking for a friend
 
My favourite probably still remains:
HEY GUISE PLS HALP WITH CODEN
HEY GUISE MY NAME IS HARR.E WARD IM FROM SUDAN AND MY DREAM IS TO BE THE BEST CODDER EVAR.

THERE IS ONE PROBLEM WITH MY PLAN.

I CANT CODE.

PLS GUISE TEACH ME THE BASICs

sorry for my bad englando hello I am walk 2 years for russia to get internet pls dunt let me down guise

i esk my mother she sad i dunt ned a moose to codd well, is she rite? it teks me 5 months to earn mooney 4 moose pls dont sey ets needed.

sory 4 bad englando agin. I em using russian translater named kevin, he help me write dis 4 alcohol. dis is my dream.
That actually is quite an amusing bit of trolling :)
 
They need to do way instain mother
 
Sudanese moose are some of the finest in the world
 
2:53 PM
Noooo!! Dang it! They deleted my favorite. It was something like "Please help omg I have no idea what I'm doing"
 
@CeliusStingher sounds like my internal monologue every single day :)
 
@CeliusStingher doctoral students hate this one weird trick :)
 
3:09 PM
Okay... going through bookmarks is interesting... I wonder why I bookmarked: vat19.com/item/26-pound-party-gummy-bear :p
 
@JonClements quite the walk from Sudan to Russia
 
@Datanovice obviously quite determined :)
 
@JonClements he probably had to go via Libya to Europe then to Ukraine to Russia so yeah quite a determined chap he skirted two civil wars, a migrant trail, death at sea.
i'd hire him
 
3:23 PM
I'm going to start using "englando"
 
3:52 PM
Incompatible types in assignment (expression has type "function", variable has type "Callable[[T], Awaitable[R]]")
It's times like these when I doubt Python's type checking support...
Anyone has an idea what this is supposed to mean?
N.B.: Callable[[T], Awaitable[R]] is my annotation. Plain Callable doesn't work either.
 
@MisterMiyagi Python actually does anything with those type annotations? Or are you using an additional tool such as typeguard or mypy?
 
@MisterMiyagi What's the code?
 
@amcgregor that was mypy reminding me of the good old times with C++ compilers...
@Peilonrayz trying to cook up a ruprecht at the moment.
The original code is make_key: Callable[[T], Awaitable[R]] = _awaitify(key) if key is not None else identity, which probably isn't helpful...
 
"cooking up a ruprecht" makes you sound like a cannibal
 
4:08 PM
# mypy 0.761 reprex
from typing import Callable, TypeVar, Optional

T = TypeVar('T')
R = TypeVar('R')

def identity(x: T) -> T: return x

def funcify(function: Callable[..., R]) -> Callable[..., R]: return function

def test(a: Optional[Callable[[T], R]]):
    b: Callable = funcify(a) if a is not None else identity
 
"I'm afraid I can't stop. I'm having an old friend for dinner"
 
@Aran-Fey "No animals were harmed in the making of this MCVE."
 
@MisterMiyagi I think it's a bug with how mypy merges two Callables it ternary. I'm assuming the ternary has to convert them to a common type, where it throws a wobbly and types it as function.
 
I kinda understand falling back to function, what I don't get is why Callable is not satisfied by that.
 
4:25 PM
IDK, I've never seen function as a type before.
 
Am I just being pedantic or is this a data breach that should be deleted? It seems odd that they would be sample photos but it's a faff to try reverse Google from a phone
 
@roganjosh very much
ah, they say they found them in google :|
ugh
 
Nevermind. They clarified that they were found on google
 
still ugh
 
4:34 PM
just because it's on google doesn't mean it's not personal data.
 
wow those google (ddg) hits
@MisterMiyagi also true
 
Definitely, but I guess it's not an issue to be handled on SO. Had I the privilege, I would have nuked the question before getting clarification I think
 
Any way to set code to run when an object is garbage collected? I've got a reference to temp folder with some images in an object, and while I currently just delete it when I'm done, I anticipate a circumstance where another part of the code might want to reference it, so I figure the most sensible way to get rid of it is to delete the temp folder when there's no more references to the object.
 
I might have been tempted to outright delete it and do a bit of checking...
 
I can only speak about EU/German laws, but according to these I'd fry the question without second thought.
 
4:36 PM
if I still cared about SO this would be worth asking on meta
Odds are it's a meta dupe of course
as a middle ground one could ask in SOCVR
 
I've flagged the question for moderator intervention.
@toonarmycaptain __del__ is run at object finalisation.
 
@MisterMiyagi but not always, right?
 
Note that the standard library already has a module for safe, temporary directories and files.
@AndrasDeak Well, there is no guarantee that an object is finalised.
@toonarmycaptain Do you use CPython, and don't have any circular references that contain the object you want cleaned up? Then using __del__ is fine.
 
51
Q: An Update On Creative Commons Licensing

Tim PostWe’d like to provide you with an update to our transition to version 4.0 of the CC BY-SA license. We realize that this is something that you care deeply about, and that our response to your concerns is long overdue. We’d like to thank all of you for your patience while we worked on a plan forward...

 
@MisterMiyagi Ah. See I read this, but wasn't certain whether that was just called when you explicitly call it or del objas well as reading in a couple of other places that this might not run as you expect it.
No, no circular refs, just planning ahead, assuming I'll not only want to reference the objects temp folder in this one instance, and rather than passing references around or explicitly managing it, just have the object delete it when it is garbage collected itself.
 
4:50 PM
You might also want to check out tempfile and atexit
Note that strictly speaking, there is no safe way to guarantee any form of cleanup.
 
5:29 PM
whats the difference between a data engineer and a software enginner (backend)?
 
Tempfile is what I'm using, but AFAICR it says explicitly that you're responsible for cleanup.
So what I'm doing is having a tempfolder that these are created in, then clearing the contents on app startup and close, and trusting the object/s to cleanup after themselves such that there won't be much scope for egregious disk usage.
 
@toonarmycaptain If you use a tempfile.TemporaryFile or tempfile.TemporaryDirectory as context managers they delete themselves after you use them.
 
You mean within a with block? I don't know if that'll work with how I'm using it.
 
5:47 PM
I was wondering if I could get a recommendation on some resources to learning c++ if you're already are proficient in a lot of languages like Python, Java, Scala.
 
@SebastianNielsen try asking C++ people perhaps?
 
I figured someone in here know c++
I asked here as it's the most active chat room by far.
 
u-huh
 
@Permian probably isn't well-defined tbh
 
huh?
huh...
 
5:52 PM
From what I read in job descriptions they tend to be looking for similar people. A data engineer might focus more on the quality and cleaning of data as opposed to making stable software but there seems to be an overlap
A software engineer (backend) can dump things into a database but they might not think so much about how it could feed a model, for example
 
and then you've got data scientist to throw in the mix...
 
my spidey senses are tingling. Someone call for a data scientist?
 
Are you a data scientist @inspectorG4dget?
 
@SebastianNielsen according to my manager, yes
 
Lol, okay...
 
6:01 PM
@inspectorG4dget just to further mix things up - if something's weird and it don't look good... who you gonna call? :p
 
6:11 PM
I threw all my pun foo at "ghost busters" and came up short :/ Surely there's one to be had
 
I've written a project that has at least three classes with no body. I sure hope this is one of those "you almost never need to do this" scenarios, and not a "you never need to do this" scenario.
 
6:23 PM
@roganjosh entropy busters? 'most' busters?
 
"Busters" --> "clusters" is my starting point. It's the pesky "ghost"
 
I'm struggling to get past "localhost" for that one...
 
Boost Clusters. My final offering. But I've totally ruined the potential of the pun
@JonClements Ghost needs to be a library if it isn't already. It does something something with localhost just because it needs to for pun-related issues
 
Ghostscript was the royalty-free version of Postscript, so it's kind of taken
 
also isn't it a headless browser thingy? Or is that phantom?
 
6:35 PM
Does that work with Opera?
stackoverflow.com/q/60513516/4799172 speak of the devil/ghost. Needs more focus
 
Getting error related to libstdc++ and libc++ in Python : pdftotext installation
Mac OS
10.15 catalina
 
Ok. What is the error?
Also what is the context? Are you trying to install something like numpy/pandas that will compile locally? You really haven't given much info at all
 
6:57 PM
@JonClements I was gonna go with Ghostbusters
 
@inspectorG4dget that's just so last decade(s) :p
 
(Oxidized, though revitalized through coffee) Cabbage everyone
 
@JonClements Code Busters! 🎺🎺🎺
 
I have a question regarding np.select() when using it with pandas, how can we get the default value to be a value in the series?
Specifically in this answer of mine, the last part, the default value should be None instead of the default False. stackoverflow.com/questions/60513313/…
 
> default : scalar, optional
I suspect you can't
I bet you can shoehorn in a default array with compatible size as another choice
 
7:03 PM
Oh, definitely skipped the "scalar" part ;x>
Yeah, or I can nest np.where's
 
blech
the top comment seems good enough for OP's problem
 
Just rego'd for PyTexas :)
 
Was the cabbage too oxidized for you? I come from an excel background where nested ifs where the thing
 
I wouldn't advertise that :P
 
Yeah, my story is full of that kind of situations, I'm not proud of them, but it definitely was advantageous for me. Because I'm not a programmer, I'm a business major, with master in credit risk management
In my country, from my experience, managers from small companies (cfo, ceo, cro) usually don't understand programmers jobs, they only like the fancy words and the visualizations/tables. So when you nest a few ifs or have decent wpm, because they do understand that they are amazed and find the person as really talented with computers
 
7:15 PM
Anyone here?
 
What's up Zeta
 
There is this contest I'm practicing for...Usual flow is input is provided in stdin and I should print out result. How can I just copy the sample inputs and use "input()" function but instead of manually entering data, I use a txt file to automate my code-test precedure?
 
Are you on windows or linux?
 
win
But I kinda can have unix utilities
You mean pipe?
 
not even that, you can just send a file into the stdin of a process with <
 
7:18 PM
But what happens if I invoke input() two times?
Does < feed input line-wise?
 
< inputs complete with newlines. It's input() that decides to read a line at a time.
this is also something you can play with yourself to test
 
So does input() have a memory somewhere about which line it should read?
 
How/why would it?
 
Suppose file.txt contains 10 lines. < feeds everything to stdin. first input() reads first line? Then second input() reads second line?
 
Try and see?
you don't have to take my word for anything
 
7:20 PM
<computer explodes>
 
@Zeta.Investigator stdin is a stream, not a file. When input reads a line, that line is gone from stdin.
 
@AndrasDeak I actually forgot about this licensing thing.... huh...
 
@MooingRawr it was one of the sore points due to how it was (mis)handled
 
@MisterMiyagi Yeah good point. tested it. OK
Also I always mess up javascript stuff with python. like `` for template printing
What do you guys do
 
@JonClements given global warming and everything, that was just the cooler decade
 
7:25 PM
@Zeta.Investigator templates used where?
 
@roganjosh I mean python3.x has this f"" for formatting
javascript has similar feature with backtick
I confuse the synataxes
 
Oh. In that case, I found JS template formatting unusual and I don't think we're the correct pool of people to be asking.
 
they're asking how not to confuse JS and python syntax
to which I can only say "well, uh, don't"
 
They also asked "what do you guys do". My answer to that would be that I do all string operations I can on the backend and then feed the results to jinja2 for rendering
 
@roganjosh :D
Another problem. So this < method works but the contest page has a few test cases. What is the best approach? Using multiple text files for each case or utlizing some unittest framework?
 
user11867329
7:38 PM
Daily reminder that @AndrasDeak may be rough, but that makes him fair.
 
Yes it was massively mishandled. I recall the storm that came after the announcement. I think the first highest rated answer sums it up well.
 
@Zeta.Investigator Unless the input data is well-curated, piping each file to a separate process should be your first approach. The complexity of a proper test harness for such one-off tasks isn't worth it, unless the input data is very well selected.
@Zeta.Investigator Use a proper IDE for each language.
 
1 hour ago, by roganjosh
https://stackoverflow.com/q/60513516/4799172 speak of the devil/ghost. Needs more focus
still needs that vote ^
 
done
 
thanks
 
7:51 PM
@MisterMiyagi The cases are always a multi-line input and expecting a multi-line output. Can't I just get away with python's own unit-test with sth like assertEqual?
 
Python's builtin unittest is a beast. Since you basically want to a) read the file, b) execute the program, c) compare output by equality, there doesn't seem to be any advantage to using a unittest setup.
 
Hello guy. I will appreciate if anyone can give some advises for you question: stackoverflow.com/questions/60086675/… it looks like sentiment is looking at only 1 character at a time
 
@MisterMiyagi But If I have like 4 test cases, I should create 4 txt files and run the program with < for each of them? I mean I guess something could be done with bash scripting but doing all stuff in a single py file would be preferable
import unittest
a, b, c = [int(a) for a in input().split(' ')]
print("Yes" if a + b + c == 180 else "No")


class TestProvidedCases(unittest.TestCase):

    def test_c1(self):
        expected = "Yes"
        actual = "No" #???
        self.assertEqual(actual, expected)


if __name__ == '__main__':
    unittest.main()
 
@Zeta.Investigator Note that I have no idea about the current format of your data. Previous messages imply they are in separate files.
 
@MisterMiyagi The contest provides input in stdin
I wanted to mock the samples utlizing < and input.txt...But now I want to do everything in the script itself
In short, How to programmatically test for stdin data?
 
8:06 PM
@Verbamore isn't that the one you posted yesterday? Have you considered what people told you?
@Zeta.Investigator by writing to stdin
 
Point of note; I find "<" really distracting and keep assuming it's part of your code. But it has no appearances in your actual code sample and it isn't part of English grammar.
 
@roganjosh i think that's the pipe on shell/bash
 
@roganjosh I wanted to mock the sample case in a txt file . The do python mycode.py < case.txt
Now I want to do everything in a single file
 
@MisterMiyagi yes I was able to fix the error by using a try except block but I still have a problem with the loop. The sentiment is looking at only 1 character at a time. I need it to look for a tweet at a time
 
How to invoke "this" script inside that Test class?
 
8:10 PM
Aha, but I thought that was >. My bad, I'm a Window guy, please forgive me
 
@Verbamore I see that you edited the question. Did that change the scope? Please don't change the goal of a question, it makes it futile to attempt an answer.
 
@roganjosh both exist: foo < to_stdin > from_stdout
 
@roganjosh I'm on windows too. I'm using cmder
 
@Zeta.Investigator do the same you would be doing without the Test class boilerplate: use subprocess.run
 
@MisterMiyagi yes I changed it because I fixed the error part. Sorry for the confusion. what is the best practice here? Do I need to ask a new question?
 
8:13 PM
Yes. When previous answers would not be adequate anymore, ask a new question instead of editing the old one.
 
I was just being slow @Zeta.Investigator, sorry
 
@MisterMiyagi got it. thank you for your advice. I am asking a new question but it will be the same as the existing one
 
then you are doing something wrong
 
user11867329
8:34 PM
Any French users using Antidote?
 
@OakDev What is that?
 
import unittest
import sys
from io import StringIO
import subprocess

script_name = "p10230.py"


class TestProvidedCases(unittest.TestCase):

    def test_c1(self):
        expected = "Yes"
        input_case = """70 60 50"""
        stdin = sys.stdin
        sys.stdin = StringIO(input_case)
        proc = subprocess.Popen(
            ["python", "-m", script_name], stdout=subprocess.PIPE)
        actual = proc.communicate()[0]
        self.assertEqual(actual, expected)


if __name__ == '__main__':
This is my test harness script. How can I invoke my target script and catch its output?
 
monkeypatching sys.stdin has no effect on your subprocess
 
How can I invoke that external script with my desired stdin?
 
pass the stdin to communicate
 
8:57 PM
@Aran-Fey Why the following hangs?
        proc = subprocess.Popen(
            ["python", script_name], stdout=subprocess.PIPE)
        actual = proc.communicate(input=input_case)[0]
        self.assertEqual(actual, expected)
 
you also need to pass stdin=subprocess.PIPE
 
@Aran-Fey And how can I make input_case a "bytes-like object"? With StringIO?
 
Use os.fsencode
 
@Aran-Fey and where is Jimmy Hoffa? ;)
 
well, not in my room, that's for sure. Can't be more specific than that, sorry
 
9:03 PM
@Aran-Fey Can I use encoding instead?
    proc = subprocess.Popen(
        ["python", script_name], encoding='utf8',
        stdout=subprocess.PIPE, stdin=subprocess.PIPE)
 
sure, but utf8 might not be the same encoding that you would have to deal with in real-world conditions
 
import unittest
import sys
import subprocess

script_name = "p10230.py"
cases = [("70 60 50", "Yes"), ("180 0 0", "No")]


class TestProvidedCases(unittest.TestCase):

    def test_c1(self):
        for case in cases:
            expected = case[1]
            input_case = case[0]
            print("testing" + str(case))
            proc = subprocess.Popen(
                ["python", script_name], encoding='utf8',
                stdout=subprocess.PIPE, stdin=subprocess.PIPE)
            actual = proc.communicate(input=input_case)[0].strip()
1- Is this a good way of using unittest with cases array?
2- How can I make the unit-test to print the exact case at which error occured?
(manually printing?)
 
9:20 PM
Is there anyone there that can help me? It has to do with selenium
 
@EthanCulp Please don't ask to ask, just ask.
 
Ok, sorry, lol
So what I need help with is this code right here:
from selenium import webdriver
print('Starting webdriver') # This line is executed
driver = webdriver.Chrome(executable_path='C://bin//chromedriver.exe') # This line is executed
print('Webdriver started')# This line is not executed
Someone has told me that it might have something to do with my chrome binary version but idk what that means
None of the code below the driver is executed
 
9:38 PM
Watching The Chase (a quiz show in the UK with a US counterpart). "How many years between the first and last moon walks?".
 
@Zeta.Investigator As said before, use subprocess.run. It does all the Popen, stdin, encoding and communicate business for you.
 
@MisterMiyagi Thanks
What about first question?
Is it a good idea to cramp all test cases in a single method?
 
@roganjosh does that account for Michael Jackson?
 
I don't believe there was any provision for amazing dance moves :/
Still, I was well out at my suggestion shouted at the TV
 
I'd guess something like 20
or probably less
 
9:55 PM
Well off. My guess was 12 and it was too high. I'm not sure if anyone else wants a pop before I give the answer
 
I don't know when it started or ended (duh), but I know that the know-how to put people on the Moon was lost fast. So I'm not too surprised if it's a narrower window than one would think
 
Guess the output:
class Foo:
    __eq__ = None

print('__hash__' in vars(Foo))
 
12 people total on the moon. That's not a lot.
 
3 years according to them. I can't even see how NASA orchestrated the launches in that timeframe
 
@roganjosh weird
I wonder how much it gets confused with decades of space shuttle missions
 
10:03 PM
I certainly fell into that trap. With all the probes being launched with a crazy real-time, I would never have guessed 3 years
Lead-time*
 
Quick question, with __new__ do you need to call __init__? Does Python basically just do obj = Cls.__new__(...) obj.__init__(...) return obj?
 
If __new__ returns an instance of that class, then python automatically calls __init__ for you (with the same arguments)
 
Nice, thanks Aran
 
@Aran-Fey Is it cheating, if I went and checked the data model docs?
 
Formally yes, but ultimately the goal is to learn something new, so...
we won't award you any quatloos for the correct answer ;P
 
10:18 PM
Sniffle.
 

« first day (3426 days earlier)      last day (1513 days later) »