« first day (3098 days earlier)      last day (1842 days later) » 
00:00 - 17:0017:00 - 00:00

12:05 AM
@wim Yeah. Py 3.6 is coming - the newest branch (2019.2) should support it. IIRC our biggest hurdle is tornado...
apparently when we first added Tornado we did some... unfortunate things. Now we have to fix that :P
The biggest challenge for us is that Ops folks are not exactly known for staying on the cutting edge. More like the clotting edge ;)
Not everyone lives like Arch :D
 
12:41 AM
cbg
 
12:57 AM
cbg @U9-Forward
 
@WayneWerner Lol, haha :-)
 
1:09 AM
Holy crap! Hahahah this is amazing!

If you are one of todays lucky 10k: https://knowyourmeme.com/memes/press-f-to-pay-respects
but it gets better
^F == ACK (see asciitable.com)
wahahahah that's hilarious!
 
lol
 
rbrb
 
 
2 hours later…
Wis
3:30 AM
is there a python package that's for python what github.com/shelljs/shelljs is for node?
 
3:45 AM
Soliciting votes for the enumerate-list-comprehension solutions and against the Java-like multiple-nested-for-loops-and-explicitly-walking-indices on this. We should teach new users good Python idiom, not how to write flabby (and non-scaleable) Java-like syntax.
 
Wis
why does pypi have all there search categories and no option for ascending descending order for number of stars?
looks like sh and plumbum are the top 2, are there other good popular libraries that I missed?
 
4:20 AM
if I recall, there should be a shorter way to write {(i, j) for i in range(N) for j in range(N)} but I can't seem to figure out what it is
 
@Wis not familiar with shelljs but looks like amoffat.github.io/sh
dunno about popular but one of the popular subprocess questions has an answer which promotes sultan.readthedocs.io/en/latest
 
 
3 hours later…
7:27 AM
 
8:05 AM
^ closed
 
8:30 AM
@coldspeed set(itertools.product(range(N), repeat=2)) ? Or use your setcomp but create a single range object outside the setcomp, so you don't build N of them in the inner loop.
@WayneWerner I rarely play games these days, (apart from Freecell, & sometimes puzzles like Kenken), so the full implications may be lost on me, but that does seem extremely tacky.
@smci The title says "each occurrence of a item", which suggests they want all indices of a single specific item. Although of course a solution that allows you to ask for indices of multiple items can be useful, & more efficient than getting them one at a time.
 
8:55 AM
Also, while using enumerate is certainly cleaner & less clunky than for i in range(len(list)), the looping speed is virtually identical; you're still using a Python for loop.
 
@PM2Ring See my comments from several hours ago. The title and first line imply "look through a python list (iterate?) and print out each occurrence's index number" but the code example only mentions occurrences of the item 't'. The OP should be clearer. But given a choice between interpreting it such as not to give a very reusable resource (e.g. just for item 't'), we should choose the more general way ("each occurrence of all items").
 
@PM2Ring Thanks... I ended up going for speed in the end (timed assignment)
 
@smci Nowhere does it imply that the OP wants each occurence of every item, just each occurence of an item. But I've upvoted your request for clarification, just to be on the safe side. I agreed earlier that a more general solution has benefits. OTOH, a solution that works for single items is simpler to use. Why use a Swiss army knife when a plain knife does the job?
 
@PM2Ring Look at the Java-like code some people posted. A single for-loop is not that less efficient, although explicitly looking up a[i] is bad practice. But I said multiple-nested-for-loops are not scaleable (it's O(N^2)). Once new users start writing for-loops for everything even where not needed, they end up writing nested for-loops. Really we should be steering new users away from that. List comprehensions, iterators, enumerate...
 
@smci I've read that page thoroughly, and posted multiple comments.
 
9:09 AM
...if-clauses or predicate functions inside list comprehensions to keep things legible.
At minimum, always develop an awareness that for i in range(len(something)) is always a code smell for enumerate(something), even if user chooses not to write it that way.
 
Yes, I've upvoted your comments about that stuff.
OTOH, I also criticize & downvote code that uses enumerate just to get the index: for i, _ in enumerate(lst): # do stuff with i
 
I want to do web scrapping on linux server. But linux servers don't have GUI. They have only black screen i.e terminal. Recently I prepared a selenium script which messages your friends on whatsapp. I want to run it on linux. It won't run there, right? So, how do I do it in linux server
made selenium script on windows
 
@smci See:
If the author feels that the enumerate is simpler to understand than list(range(len(a))) I have no intention of reading anything he writes about Python! Sure, list(range(len(a))) is slightly inefficient in Python 2, but both those calls run at C speed so it's still pretty fast, and for large len(a) it will be much faster than the Python speed loop in a list comp using enumerate (or range or xrange). — PM 2Ring Apr 15 '16 at 12:57
But also see my comments on the author's answer.
 
9:35 AM
@PM2Ring I disagree with you if you're suggesting list(range(len(a))) is clear code. As to the speed argument (on Python 3.7) and suggesting enumerate is less scaleable, how could we measure the two? What's the crossover value of list length? Also remember with [... for i,x in enumerate(a)] you're also getting a free iterator into a, so no need for the extra O(1) lookup a[i]. If enumerate has a scaleability problem (in 3.7), I wasn't aware and love to see that posted as a question.
 
@smci My objection is to using enumerate only for the index and throwing away the item.
 
I'm a bit unhappy with our how to test multiple variables against a value canonical. My main issues are that 1) most people try to do something like x == 0 or 1, but the canon does x or y or z == 0, which can be confusing for newbies. And 2) Martijn's answer is the only one that actually explains the problem, all the other answers are just like "you can copy/paste this code I wrote for you that you don't understand". Any thoughts about this?
5
 
@user9181286 You mean "How do I run a Selenium script on Linux?". a) that's not a Python question, this is the Python chatroom b) it's been asked on SO before c) you posted a duplicate question anyway. Unless you meant "What are web-scraping alternatives to selenium which run on Linux?"
 
If I take this to Meta, is there any chance of something productive happening?
 
@Aran-Fey usually no, I guess?
@Aran-Fey I'm pretty sure a better canonical could be written up and then we can mark that one as a duplicate of the new canonical
 
9:49 AM
I foresee some community backlash... Pretty sure a lot of people would think we're doing that for the rep
If we go that route, I think it should be after we get Meta approval
 
@PM2Ring Oh ok that wasn't clear. I would object to that too (it's like how LISP programmers compute the length of something). But hey if enumerate() is not scaleable on 3.x I want to know so I stop recommending it. Has anyone measured its crossover point?
 
@Aran-Fey Regarding 1), we also have Kevin's Q&A: stackoverflow.com/questions/20002503/…
 
@Aran-Fey not much, what do you expect from meta?
 
Is there a way to use `threading.Timer` with `yield` instead of creating a class with
__enter__ and __exit__?

 @contextlib.contextmanager
 def my_func():
     threading.Timer(10, unyield)
     yield
     # Do something after 10 seconds
 
plus people thinking you're doing it for the rep probably won't be swayed by the existence of a meta post
 
9:51 AM
@AndrasDeak Well, basically I want approval before I do anything that a lot of people are likely to disagree with
@PM2Ring Neat. I think I'll just use that, then.
 
@smci I'm confident that enumerate scales perfectly well, since it runs at C speed. The problem I mentioned earlier was the wasted time iterating over the list & throwing away the items.
 
Dang, now I need to earn 300 rep for a bounty...
 
@Aran-Fey ah, actually, I think I was only familiar with Kevin's. Is that not what we have in the canon?
 
@PM2Ring Ok fine. Your comment was impossible to understand, I read it as saying the opposite.
 
Python 2 range(N) creates a list at C speed, so it looks faster than Python 3's list(range(N)), but IIRC the relevant speed improvements in Py 3 are significant, so it may even be faster.
 
9:57 AM
@AndrasDeak Yeah, it's there. I don't check there as often as I should... And anyway, I'd ideally have liked to do something about the subpar canonical. Leaving it alone is not my preferred outcome for this situation
I guess I'll leave a comment linking to Kevin's question
better than nothing, hopefully
 
How about switching the orientation of the dupe?
(after due discussion)
 
discussion with who? Meta?
 
I think for that this room would be enough
 
+1
 
it was duped by animuson who doesn't seem like a python person
if we think reversing the dupe is fine we can ask a python mod (:P) especially one who is a stakeholder in one of the posts to chime in
 
10:00 AM
alright then. I vote for a reversal
 
@Aran-Fey I fully agree with you that both the question and answer should show lots more "wrong" ways of doing multiple comparison. Other pitfalls are Boolean operations and 'falsey' values like 0, 0.0, False, [], (). With x,y = 3,0 then x == 3 or y evaluates to True, but x == 2 or y to 0.
 
hmm, with only 1 more year of life the worse dupe has 10x more views
 
'cause it's the canonical one
 
But, how to edit the existing question or answer? And asking "What are some wrong examples of pitfalls in trying to compare multiple values in Python?" [EDIT:... pressed return early meant to say this is not good SO fodder]
 
760 linked questions vs 150 linked questions
 
10:02 AM
An answer that has a green check mark also looks more attractive
 
@Aran-Fey ah
@smci that's not a good question for SO
and people with this problem won't find the question anyway, it has to be a good dupe target primarily
@Aran-Fey what about the answers? Do you think Martijn's answer is confusing? Or do you only have an issue with the questions?
 
@AndrasDeak Yes I pressed return early meant to say this is not good SO fodder. Yes people with that problem won't find the answer from search box or Google, but they will from following highly upvoted questions.
 
The problem is that Martijn's post has a lot of links and explanations as usual, and it would be nice to keep that too.
@smci you can edit messages for 2 minutes :P
 
@AndrasDeak (yes I had already edited it)
 
@Aran-Fey I seriously think we should unhammer Kevin's Q&A, since it's the logical complement of the dupe target. I suppose we could get zero323 in on the discussion, since he now has Python gold. animuson is a SO employee, but not a Python coder, so his opinion isn't that relevant, IMHO. ;)
 
10:07 AM
@AndrasDeak Martijn's answer is great, it's the other answers that I have problems with. In fact I'm planning to ask Martijn to repost his answer on Kevin's question (with minor modifications, of course).
 
@smci ah
@Aran-Fey that or a merger is what I've been thinking
 
@PM2Ring That person's been last seen in October '17... I don't think we have to worry about them too much (:
I'll ask Martijn to weigh in, I suppose
 
Yup
 
@Aran-Fey Rightio. FWIW, here's the relevant sopython page, which links to 3 questions. sopython.com/canon/22/…
The 1st link's ok, but a bit sparse.
 
@MartijnPieters Sorry for pinging out of the blue, but we're discussing what to do about the canonical "how to test multiple variables against a value" question and Kevin's related question. (Discussion starts here.) Since you're a mod and have an answer on the former question, I'd like to know what you think should be done.
Yeah, the first question there isn't as good as Kevin's IMO. Not a perfect fit for most new questions either, since it has parentheses around the or.
 
10:15 AM
I had a bit of a giggle on the xkcd forum a couple of hours ago, reading a thread about favourite programming languages. Someone mentioned Python as a new language. I had to reply that it's almost 30 years old. :)
 
Yess
 
Yes?
 
@AndrasDeak I know that people who aren't logged in automatically get sent to the dupe target if they click on a dupe from a search engine. I assume that means the closed question doesn't score a view hit, only the dupe target does, but I'm not certain. That'd make sense, assuming search engines take view counts into consideration.
 
@Aran-Fey While we're at it, I left Martijn some comments on how that question and answer assume integers, and non-zero integers at that. I don't think we want separate canonicals for floats, Booleans, short (interned) strings, long strings, pointer aliasing with if a is b...
 
@PM2Ring if I were SO I'd consider it viewed
 
10:28 AM
@Aran-Fey I think neither of those questions should be closed as dupes. But if we unhammer Kevin's we can protect it to prevent answers from clueless newbies.
 
@smci Hmm, well, I can see how 1 in (True, False) could be a problem, but that behavior is caused by the fact that bools are a subclass of ints. It doesn't really have anything to do with falsey values.
But yeah, it would probably be a good idea to show the correct way to write that if statement without using in Nvm, Martijn did that anyway
 
got any tools for analysis of python code? For example taking in a directory, and spitting out a graph of how the modules are linked, and which files are mentioned where
or listing all class names with all methods/properties
 
like doxygen?
no idea
 
 
"potential security risk" :P
 
10:34 AM
yup
don't want to take a random tool off of the internet
 
yup
 
well, this room is the internet
but you get the point
 
yeah, we're the good mob
 
I'd trust you with at least 5 dollars :P
so, nothing in mind?
 
No, but I wouldn't know. The actual devs might.
 
10:35 AM
python's very simple syntax seems to make it one of the best languages to do static analysis with (well, I guess it doesn't get simpler than java's reverse dns imports at the top)
some context: my task for part of today is looking at a relatively large python project and getting a feel for what does what
I could wing it and manually look into files and dig into holes, which is what I think I'll do
but maybe there's nicer ways
 
@towc problem is that everything is dynamic, so you'll never know whether a given import gets executed, for instance
(well, you can if they are on top where they belong usually :P)
 
@towc One handy feature of the CPYthon interpreter is its verbose mode, invoked with the -v or -vv option code. From docs.python.org/3/using/…
Print a message each time a module is initialized, showing the place (filename or built-in module) from which it is loaded. When given twice (-vv), print a message for each file that is checked for when searching for a module. Also provides information on module cleanup at exit. See also PYTHONVERBOSE.
 
ok, interesting
this is a side-effect heavy project though
 
Wow. Python 3.7 now has -X importtime to show how long each import takes. It shows module name, cumulative time (including nested imports) and self time
 
10:57 AM
it is normal than after like 200 epochs, the loss of my neural network went from 1.7 to 4.4 in 2 epochs?
it took 200 epochs to go from 4 to 1.7... xD
and then it went down again to 2.5 in 10 epochs
 
11:11 AM
so, this is already pretty neat: ag "(def )|(class)" --no-numbers --color-match="0;2"
lists all classes and functions/methods in a pretty way, with the file at the top
I guess the reason people don't write python analysis tool is that it's trivial to script most of their functionality
 
@Ajit Sorry, your question got buried under the discussion. Perhaps it would help if you explain what you're trying to achieve. I've written a few threading Timer answers you might find helpful, eg stackoverflow.com/a/45164619/4014959 & stackoverflow.com/a/37501797/4014959
 
@towc I recently read an article from pycoders weekly...
Ah here we are: pynsource.com
Might do what you want
 
11:40 AM
oh, neat!
thanks
 
11:52 AM
it's so frustrating to use
doesn't seem to link modules
best I got so far is still grep/ag, funnily enough
 
Raj
Hi Guys
 
hi guy
 
Raj
Need some help.
 
@towc did you move to python?
 
Raj
Kind of ..I am new to python
 
12:01 PM
proceed with the question
 
Raj
Thanks man..
I have a ttl file and i have to process (replace some text with another text)
before replacing the text i am converting that file to json
there is data such as
like this 100 os of nodes are there
 
@Neoares this is far from the first time you've seen me here
 
really?
 
yup
 
I remember you from the C# room I think
or maybe it was this one.. who knows
 
12:07 PM
I don't remember almost ever being in the C# room
 
What is a good data type for a unit collection in an rts? Im contributing to an api that lets you write bots for the strategy game starcraft2 in Python. And right now there is a class 'units' that inherits from list. every frame, a New units object gets created and then selections of these units are made, for example with a Filter for All enemy units or for All flying units to create a New units objects. This means we do a lot of filtering by attributes every frame which takes a lot of time.
Is there a better datataype for this?
 
@Neoares yup
I know both of you from the JS room so I don't understand the source of the confusion :P
 
I don't remember seing him in this room
 
you're here intermittently; I have
 
I know, that's why I asked if he moved to python or something
 
12:15 PM
we allow dual citizenship
 
only dual? :c
 
two citizenships should be enough for anybody
 
@AndrasDeak I'm offended
 
that's not new
 
good.
 
12:18 PM
@AndrasDeak damn
 
Hello o/
I have to do some grunt work on many files, I am thinking of writing a script to do it.

Is there some library which can help me with this?
 
I think it's called python
what task do you have to do, more precisely?
 
Pretty unclear what you expect that library to do. It sounds like you need pathlib and a loop.
 
(actually, depending on size and task, doing some bash stuff might be better)
 
I have to add some lines to files and in those lines, I have to have name of parameters which I have to regex to find it
I'm not very good at sed :(
 
12:27 PM
if you're not worried about scary stuff, it sounds like you want find and grep and echo
 
^
 
echo can't be used to insert at middle of a file? Not easily I guess
 
Can anything be used to insert at middle of a file, rather than creating a new file?
 
@codeconscious well, you can append to a file
if it's in the middle, I guess sed's your friend
if you feel comfortable with python, you could loop over all files and perform your ops
but you need to have a strong-ish grasp of string manipulation
 
I guess, I have to make my way through sed :(
 
12:32 PM
that's the sed state of affairs (sorry)
 
:'''''(
 
he's a sedist
 
at least I tried not to be
 
Hey has anybody had the problem, that when restoring a tf session with the tf.train.saver the network needed like a small warmup phase? I save the weights of my model using numpy and tf saver and then when loading them in again I compare the loaded ones against the numpy ones and this sanity check passes and tells me that the weights are the same as the one that were saved.
Yet when I do let some examples go trough the model the first ones are always bad(big loss) and only after a few training steps it reaches the old loss niveau that is lower, see image. And I have no clue how this can be
any ideas?
 
rubber duck: any chance that the algorithm has some memory?
we use a kind of mixing procedure in a very different application which means that restarting might break the convergence a bit, delaying by a few iterations
 
12:44 PM
@AndrasDeak what do you mean by this? It is a neural net build with tensorflow, using the adam optimizer
I thought saving all tensorflow variables should capture everything, but yeah what you say seems to be on track
 
@Hakaishin Yes, I know nothing about neural networks
if the state is more than "this" state (because there's a tail of a few previous iterations that affects further iterations) then saving "this" state is missing some of the state, and transients are a given when continuing.
 
Ah, forgot the Python tag. @AndrasDeak isn't there a userscript for that?
 
there's poke's hammer warning but you have flask gold...
10
Q: Close hammer warning

pokePower users may have experienced this situation before: They see a question that’s clearly a duplicate, so they hunt down the duplicate target and close the question. It’s only then that they realize that the question was improperly tagged, so they cannot hammer it, although they expected it to w...

ugh, typing is hard
 
@AndrasDeak I see that would make sense
 
I guess it gets less useful if I have multiple related golds. Need one that just says "heads up, tag this as python if you're going to cv-pls it". :-)
 
12:58 PM
yeah, that would be a bit localized in target audience ;)
#MultipleBadgerProblems
 
closed it
 
thanks
 
Raj
1:23 PM
@Neoares yes bro ,, I am new to the python
Also new to this room.
 
cbg all
 
hello
what does cbg stand for? I can see that's a local greeting :>
 
Is there a way to save hover plots to file, to use in ppts etc.? I've explored matplotlib and bokeh but nothing that solves my problem
 
if that's what it takes to be a part of a cool kids club, I'm in ;)
 
@PawelFlajszer, that's the salad language in the chat room. cbg means Hello!
 
1:31 PM
haha looking into it now
so...
@amanb Melon ;-)
 
@PawelFlajszer, Watermelon! :)
 
hehe
any rules I should follow on creating helper functions? say I have the following
 
Is it even possible to embed interactive plots in ppt's? I have plots ready but they export to html(with bokeh)
 
1:50 PM
Damn I just realized Github has issues off by default. I think that is an awesome idea
 
Raj
cbg
 
 
1 hour later…
It's looking right at us! D=
 
Does this mean we know black holes exist now? Until recently the notion was "we are pretty pretty pretty sure". Wonder if this can be anything other than an accretion disk of a black hole
(but too lazy to google)
 
@AndrasDeak Not quite.
in The h Bar on The Stack Exchange Network Chat, 4 hours ago, by PM 2Ring
@Akash.B Bear in mind that we have located many potential black hole candidates, but it's difficult to prove that they really are black holes. OTOH, with the best candidates, if they aren't actually black holes, they'd have to be something even weirder.
in The h Bar on The Stack Exchange Network Chat, 4 hours ago, by PM 2Ring
Also, we need a quantum gravity theory before we can fully model black holes correctly, although almost all the experts expect that current physics is sufficient to explain almost all of the external features of a BH, and we only need quantum gravity to model the core of BHs.
 
thanks
so we don't know more but we've known enough anyway
still cool to have a photo
 
We're starting to get questions on both Physics & Astronomy about M87, and some answers have appeared, but as yet there's not a lot of juicy info.
@AndrasDeak Yep. This answer has some interesting stuff astronomy.stackexchange.com/a/30322/16685
"This long-sought image provides the strongest evidence to date for the existence of supermassive black holes and opens a new window onto the study of black holes, their event horizons, and gravity".
 
3:17 PM
I just found and answer about how to get the last n items in a Django db query and I have a question about slicing a list that is simultaneously being instantiated.
obsn_set = Obsset.objects.filter(site_name=location)[:100]
 
@davidism - I'm working through the flask tutorial, cropped up on what seems to be a common issue - when people get to flask init-db it doesn't recognise the init-db command. My issue was I had spaces around the equals when running set FLASK_APP = myapp. I don't know if that's worth emphasising in the tutorial or not (since that distinction in Python assignment syntax isn't often important), but...my two cents.
 
If I do something like what I've shown will the the list be instantiated and then sliced. Like if there are 15000 items in the database will a 15000 item list be created and then sliced?
Seems like that could be inneficient
 
Do I need to close this Thread?
Thread(target=open_website, args=["http://google.com"]).start()
 
@Dodge You could just write it to an n-item deque - then no more than n items in memory at a time. But you would still create and throw away 15000-n items along the way
 
The idea is to post something to a slow website, but dont wait for the response
 
3:21 PM
Why not ORDER BY your db query in reverse, and then take the first 'n' items?
 
@PaulMcG Cool, I'll figure out how to do that. So you're saying that, as it stands, 15000 items would be instantly created, sliced and then discarded?
 
Or even ORDER BY in reverse with LIMIT n
No slicing involved. Think of a deque as a list that can grow to no more than 'n' items in size. You just keep appending to the end, and when you exceed 'n', the 0'th item gets discarded.
 
Oooh that's smart, yup okay that's what needs to happen. I'll implement something along those lines
 
@Dodge collections.deque is one of my favourite objects in the standard library.
 
@PaulMcG I'm going to be attending the PyTexas conference by the way. The lineup looks pretty interesting. Thanks for the advice here. ORDER BY in reverse and taking the first items seems to be the way to go
 
3:25 PM
@MarcosAguayo threads can't be closed/stopped/killed/whatever
 
@PM2Ring welp, then that is definitely something I'll spend some time getting familiar with
 
deque is even faster than a plain list for a simple stack, and much better if you need a queue. In a multithreading program, there's the threadsafe queue.Queue, which uses a deque.
But when you do actually need to slice various flavours of iterable, check out itertools.islice
 
@Aran-Fey So, I don't have to do anything else? Just that?
@Aran-Fey I am afraid that since this will happend so many times it will consume a lot of CPU power if the Threads keep open
 
@PaulMcG wait, that is not too different than what I am already doing, hmmm. I get all the observations for a location and take only the first 100 but at some point there is a list containing the entire observation history, if I reverse the query and take the first one hundred that same thing happens because of the nature of the query. Maybe the deque will be better
 
threads stop automatically when they're done executing whichever function you made them execute
 
3:31 PM
@MarcosAguayo What Aran-Fey said. If you need a thread to stop, you can't tell it to stop, but you can ask it to stop. So you need to set it up so that you can send it some kind of signal, and it needs to check that signal at appropriate times.
@Dodge If you only want the first 100, use islice. If you only want the last 100, use a deque.
 
Okay, sounds good, thanks
 
morning cabbage\
 
@Dodge Can you .filter differently to return fewer objects? If so you'll eliminate the problem. If you still want all of them, eventually, maybe making several smaller calls?
cbg
 
@toonarmycaptain Yes and you are right. I get a unix timestamp from Open Weather Map for each observation set (I'm collecting every 30 minutes) I harvest. What I should probably do is to set the query to return the two week history based on the timestamps rather than grabbing the entire obs history and attempting to manage that.
I just started wondering what happens if you simultaneously instantiate and slice a list, how much of the list actually ever exists in memory
 
@Dodge Maybe. I suspect that that history is only going to increase in size, so manageable now might not be so going forward.
 
3:41 PM
There is kind of an exception to that rule about threads. When you create a thread you have the option of making it a daemon thread. When all the non-daemon threads in a program terminate, the whole program terminates. The daemons get forcibly shut down, so they need to be designed in such a way that getting shut down won't create a mess. See stackoverflow.com/questions/190010/daemon-threads-explanation for some info.
 
The unix timestamps are in the db for each observation set, so probably just need to query for observations where the date is greater than datetime.now() - timdelta(days=14)
 
@Dodge If it's an actual list, then the whole list exists in RAM, and the sliced list does too. But the objects in the lists are shared. The lists themselves are basically arrays of pointers to their items, with a few other OOP bits & pieces. So the slice is a fresh array of pointers to the same objects in the parent list.
 
@PM2Ring Okay that's sort of what I would expect, although I'd not considered that the slice would exist as a separate set of pointers as well as the parent list
 
Hi guys; I'm using subprocess.Popen to run a (closed source) program and I need to pass the private key's password... problem is that the program somehow does not seem to take the stdin itself, I think it's calling openssl or something similar so p.stdin.write() is not working
how could I send stdin to the child of the child process (this is what I guess the problem here is, right?)
 
'Fraid so. Numpy arrays can do that sort of thing, but not plain lists. We do have memoryview docs.python.org/3/library/stdtypes.html#memory-views which can be handy, if you aren't using Numpy.
@LFLFM Python 3? Note that Python 3's stdin / stdout / stderr are Text streams, not byte streams. You can access an underlying byte stream, which is still a Python object, and if that's not good enough, you can get access to the real C level stdio file streams.
 
4:00 PM
Unless the sub-subprocess is doing something very funky, writing to the subprocess's stdin should work. If that doesn't work, well, I don't know how you could find out how it's actually getting its input
 
via gravitational waves
 
@PM2Ring unforunately I'm restricted to python 2
I'm getting the stdout without problems, but the prompt for the key's password gets printed into the console directly and it's waiting for user input
 
@PM2Ring subprocess stdout and stderr are bytes unless you explicitly say text=True (née universal_newlines=True), I guess it's different for stdin but I'm not in a place where I can test
 
@LFLFM Windows, Linux, or Mac?
 
4:09 PM
Linux
 
@Dodge Great, I'll look for you there
 
cmd = ['proprietary_information', '-par', 'value']
p = subprocess.Popen(cmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
can you strace the process and see where it's reading from? I'm guessing it probably opens /dev/tty or something like that
 
Mm... looks like it:
open("/dev/tty", O_RDONLY)              = 5
open("/dev/tty", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 6
 
@tripleee :oops: Ah, of course. But not really relevant in Py 2.
 
4:13 PM
@Dodge Can confirm [n*n for n in range(10**3)][:100] returns almost instantly. [n*n for n in range(10**6)][:100] will (per Task Manager) increase ram by multiple GB before dumping to disk, and takes awhile to return. Making that **8 ends up freezing machine, necessitating a hard restart, whereupon windows wants to install updates...hi.
 
@LFLFM Excellent.
 
(sorry about my strace ignorance) the opening of /dev/tty comes somewhat before the program actually stops for my input, the very last stuff that comes out of strace before it freezes for user input is:
ioctl(5, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon -echo ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3fcfec5000
read(5, 0x7f3fcfec5000, 4096)           = ? ERESTARTSYS (To be restarted)
--- SIGWINCH (Window changed) @ 0 (0) ---
read(5,
any way for me to capture this and feed it via python?
maybe I write to /dev/tty ?
 
@toonarmycaptain Oh that's cool, welp TIL. I really shouldn't say "TIL" because it happens every single day I read this chat room transcript. Probably would be more relevant to say TIDL but that would never happen, lol
 
how about "This Minute I Learned" Or just IL
But TIL is still accurate even if you use 20 times in a day
 
@Dodge I was like you could benchmark that properly, but let me try a very low fidelity ballpark... Needless to say don't do [n*n for n in range(10**99)] unless you want to hard reset your machine. NB I managed to end the process to escape that in task manager the first time...but not when I did 10**10...
...although (back on my original machine now)...chrome restoring tabs and keeping half typed message in the box after reset, windows update, and restoring tabs is pretty cool.
 
4:26 PM
(shame we can't reply to our own messages in this thing)...
ok, a quick search hints that I'll probably solve this by interacting directly with /dev/tty so I'll try that later (gotta leave for a bit)... thanks a lot @tripleee + @PM2Ring :)
 
@LFLFM jfs has written several answers on this topic. Eg stackoverflow.com/a/22253472/4014959 is kinda relevant.
 
Hi, I am new to programming and have wrote a program which is taking lots of time :(

The problem is to Find the number of ways a string can be split in a non-overlapping way such that p+q is a palindrome string. Two pairs (p,q) and (p',q') are treated as different iff p is chosen from different position from p' or q is chosen from diff position of q' .
Can someone help me to count this in will take less time?
 
@LFLFM I haven't messed with it in over a year, so I'm a bit rusty. jfs is probably the SO expert on this stuff, but I think Antti Haapala could also give good suggestions.
 
So p and q can be arbitrary (non-overlapping) sub-strings? Because when you say "split", that sounds like p always starts at the start and q always ends at the end
 
Yeah arbritrary substrings
 
4:34 PM
@taritgoswami Please show us a couple of examples, so we know exactly what you mean.
 
wim
@Aran-Fey my 2c, unhammer Kevin's (clearer question, and better answer than Martijn's one). then start using that one going forward. don't merge or move any existing content, that just makes a mess.
 
noted
 
@PM2Ring For example, take the string abba. The possible substrings which are palindrome can be formed from the pairs (p,q) resp. : ("a", "a"), ("a", "ba"), ("a", "bba"), ("ab", "a"), ("ab", "ba"), ("abb", "a"), ("b", "b") and we get: aa, aba, abba, aba, abba, abba, bb resp.
so the answer is 7
 
no problem, thanks a lot man; you guys already helped a lot by helping me identify that it's using tty; at least I know a bit more of what's going on and even learned a little something extra :)
unfortunately I got called into something else so I'll only be able to look into it tomorrow, but I've noted down all of this and I'll be looking into the answers from those guys too
 
@wim When anyone suggests merging questions, it reminds me of The Cone of Silence from Get Smart. Nice idea in theory, confusing in practice.
 
4:36 PM
cya tomorrow ;)
 
wim
yes it's almost always losing context
 
@LFLFM No worries. Good luck. And if Antti drops by I'll point him at your question.
@taritgoswami Thanks. Let me think about it. At worst, we can just produce solutions & count them, but it's often the case in combinatorial problems that there's a faster clever algorithm that can count solutions without producing them.
 
@PM2Ring Ok. Thanks
 
@taritgoswami Will the input string always be a palindrome?
 
@PM2Ring not neceassaryly
 
4:52 PM
@taritgoswami I'd do it like this
 
@Aran-Fey But the answer is 7
 
oh wait, that's not right. Should've paid closer attention to all the outputs you listed...
 
00:00 - 17:0017:00 - 00:00

« first day (3098 days earlier)      last day (1842 days later) »