« first day (2483 days earlier)      last day (2689 days later) » 

00:01
When you discover that chat exists after using stack overflow for years
welcome....we should tell the design team that they didn't hide it well enough
only 3 or 4 clicks in obscure places on main, and Bob's your uncle ;)
well, they did hide it more in the new design so that's a step in the right direction
00:18
but then they made it part of a new research plan...and they did make it the way to voice concerns about Docs.....so they might be confusing people
rhubarb
see ya @AndrasDeak
I got too creative with git
but because git allows you to be so creative....I was able to fix the creativity and fix things
yay git!
I love git, except when I hate it
haha it's exactly what happened
I did something and had a "ugh...why did you let me be stupid git..."
00:25
every developer has their own git terror story. Yes, I mean "terror". See a horror story is when something terrible happens to you. A terror story is when you do something horrible to someone or something else (and usually yourself too)
Mine starts with those horrible words: "Well, the lead said to just commit it to the live server..."
yaaaaaaaaaaay
01:11
cabbage
rn im create a django app in which a user enter's their full name rather than their first and last names separately
woo made it back home before the massive storm about to hit
@idjaw Are you in the northeast?
We're getting tons of flash floods in the Boston area
yeah. Montreal
that being said is there a way to subclass the default user class model to exclude those two fields and create a fullname char field in it's place
I'm not a Django person, sorry.
01:14
@idjaw Yup haha, we've discussed that. I'm just leaving it there for anyone
@MalikBrahimi If your subclass keeps the two original fields and make the new one optional you should theoretically have Liskov substitutability, but since there's an ORM, I'm not placing any bets. (I'm not a Django person either.)
I keep hearing rumours about this big boolean. Huge if true.
01:34
Wife hands me some melon. I say, "yay, melon!" The door to Moria opens.
I don't get it
Melon is the word for "friend" in Elvish.
01:51
any ideas why Pyspark is throwing a tuple object cannot be called error for [StructField('id', StringTypes(), True)] ? Every example I've seen says that the parens are a must, and I just get a different error if I take them out.
what is the different error when you take them out?
I'm running the code on a Databricks Jupyter notebook if it matters
AssertionError: dataType should be DataType
@idjaw
is this exactly how you have it [StructField('id', StringTypes(), True)]
that looks really weird
from the examples I'm seeing, it should be something like [field_name, type]
maybe that third argument is used too. But the way you have it seems off
[StructField('id'), StringTypes(), True]
would be my guess
but I've never used pypark
it seems to be that StringType() is valid and StringTypes() is not valid
well I guess I solved my own question, yay :P
thanks for the inspiration
np
02:00
um....rhubarb? lol
rhubarb == rbrb
yes
rbrb
02:22
I have a list of words, and a dict of words=>ints. I'm trying to find min(dict[word] for word in words if word in dict)
is this possible with numpy?
03:09
Cabbage
@zounds Why Numpy? Numpy is great for fast array operations. But that code is doing dictionary lookups, so you should use plain Python. Does that code do what you want, or do you actually want the word associated with the minimum number, rather than the number?
Hello I am facing a little beginner's issue
I have one script and am trying to run another python script from the first one
the code does what i want, my data set is just very large and so i'm trying to see how to improve performance
in order to do that I need to import it. But there seems to be something wrong when importing:
    import align-dlib
                ^
SyntaxError: invalid syntax
Is this '-' symbol not allowed?
80
Q: Is it ok to use dashes in Python files when trying to import them?

Joan VengeBasically when I have a python file like: python-code.py and use: import (python-code) the interpreter gives me syntax error. Any ideas on how to fix it? Are dashes illegal in python file names?

apparently not
@zounds thx
03:16
@trilolil No, a module name is just like any other identifier, so you can't stick a minus sign in the middle of it.
hmm OK ill just modify its name
thx :)
@zounds You may be able to speed it up a little. Are the int values in the dict all >= 0?
More importantly, is there an upper limit to the integer values in the dict?
 
1 hour later…
04:45
@IşıkKaplan All of that str -> int conversion stuff makes your code needlessly complicated and inefficient. Here's a simpler way:
num = 100
# Start with all doors closed
doors = [0] * num
for i in range(1, num + 1):
    # Toggle each door whose index is divisible by i
    for k, v in enumerate(doors, 1):
        if k % i == 0:
            doors[k - 1] = 1 - v
# Get the open doors
print([k for k, v in enumerate(doors, 1) if v])
04:55
cabbage
any ideas on why my Spark dataframe is calling NumberFormat.parse when I explicitly set the column's schema to StringFormat?
StructField("purpose", StringType(), True),
spark.read.format("csv").option("header", "true").schema(csvSchema).load(CSV_FILE_PATH)
`SparkException: Job aborted due to stage failure: Task 0 in stage 42.0 failed 1 times, most recent failure: Lost task 0.0 in stage 42.0 (TID 84, localhost, executor driver): java.text.ParseException: Unparseable number: "major_purchase"
at java.text.NumberFormat.parse(NumberFormat.java:385)`
(major_purchase is a value of column purpose which Java is choking on)
interestingly enough it is row 19, so either the columns aren't ordered or something weird is going on
05:11
Hi, @RobertGrant . It's good to see you back in the room. I see you made a contribution to the SO Meta Documentation Sunset thread. ;)
05:37
@PM2Ring it got deleted for being in "extremely poor taste" :-)
And thanks - been far too long
@RobertGrant Yes, that's because it is in poor taste. But I understand why you did it. ;)
It felt good, if only for a few seconds :)
05:57
s = "k k k"
r = [s.split(',') if len(s.split(','))>0 else s.split('')]
I was expecting result to be split by spaces. Is it correct way to write?
s.split(',') if s.count(',')>0 else s.split(' ')
@user123 Why are you doing s.split(',')? There are no commas in your input string.
@PM2Ring If , present then first priority should be given to it, that is why
actually s.count(',')>0 should just be ',' in s
@Rawing Thanks, but I didnt get your last point
06:06
s.split(',') if ',' in s else s.split(' ')
I suggest:
r = [u.strip() for u in s.split(',')] if ',' in s else s.split()
@user123 s.count(',')>0 has to scan the whole string to get the full comma count, but ',' in s stops scanning as soon as it finds the first comma.
not a lot of Spark users online tonight? :(
@PM2Ring oh got the point, thanks
And len(s.split(','))>0 won't work, because if s doesn't contain a comma s.split(',') will return a list containing the original string, so len(s.split(',')) will always be at least 1, even if s is the empty string. Besides, splitting a string is relatively slow, compared to calling ,count, or doing an in test.
@MacSigler `Fraid not, but it's still early, so give it a few hours. Many of the room regulars do a quick skim of the transcript when they come online.
melon, I've just been working on this all day and i'm just... yam, lol
06:19
cbg
06:36
Cabbage
198
Q: Sunsetting Documentation

Jon Ericson We will stop accepting contributions to Documentation on August 8 On behalf of everyone who worked on Documentation, I want to thank all 15,451 users who contributed. We particularly want to acknowledge the 294 people who tested the private beta and the 2,361 who pounded on the public beta in ...

> We’re certain to have failed projects in the future, but we’re working to fail a lot earlier in the process.
It’s not like nobody knew early…
They are learning to fail more quickly... then I'm their man... I fail hard and fast
See what I mean... that joke was a case in point...
stopping while I'm ahead, I'm chime in with something more useful next time
06:59
Is there any effective way to add celery to class methods
when using on class methods I am not able to acess instance of class
I am currently using a function to call class object and adding it to celery
@piRSquared lol… xD
Not sure that msgpack guy is getting it... sighs
Well, we tried.
hm?
lols…
@PaulMcG I thought so, but I saw it too late to write an answer.
why do i see None in
>>> [print(x) for x in (1, 2, 3)]
1
2
3
[None, None, None]
morning
07:29
@pythonRcpp Because print(...) returns None. List comprehensions are for building lists, not for printing.
If you want to print the elements, use a loop
@PM2Ring I wonder if we can do this in-place in linear time and one iteration…
that is, without modifying the list length to avoid possible reallocations.
@poke I don't think so. Certainly, it can be done in one pass, but I don't think you can do it in-place in one pass.
At least not without indexed access :/
At least, not if you want to preserve the order of the non-None items.
I was thinking about the sort option... with timsort - the complexity won't be near worst case I imagine for that size list... although... where's a "partition" function when you want one :)
07:35
@JonClements There's some discussion on the unexpected high speed of doing it with TimSort in the comments to user12357112's answer.
ahh... will have a look
lst = [None, None, 90, 10, None, 34, None, 108]
idx = 0
for x in lst:
    if x is not None:
        lst[idx] = x
        idx += 1
for k in range(idx, len(lst)):
    lst[k] = None

print(lst) # [90, 10, 34, 108, None, None, None, None]
Closest I can get
This would be a very efficient solution in languages with real array types I guess.
I'm not sure why an answer posted after this got more upvotes than this did though they both say the same thing, or the fact that 5 people attempted to answer this, but this question has no upvotes. — cᴏʟᴅsᴘᴇᴇᴅ 2 hours ago
Coldspeed seems a litty whiny about the question not getting upvotes…
@poke I think adding the Nones via slice assignment would be faster :
lst[idx:] = [None] * (len(lst) - idx)
hmm, not sure about that since it would first build up a list of Nones and then assign that to the slice. I’m also not sure how slice assignments actually work internally
In anyway, I opted for the constant space solution there, instead of having O(n) space for the None list
Also, my primary reason was to keep it “bare metal” as I was already going that route :P You can easily translate the solution into C or whatever
@poke Fair enough. The list multiplication is very fast. Slice assignments are a little faster than assigning in a Python loop, but slower than creating a new list with simple concatenation, and of course if we create a new list it's no longer an in-place solution.
07:49
You’re right though. ~23% faster.
In [14]: def f(iterable):
    ...:     count = 0
    ...:     for it in iterable:
    ...:         if it is not None:
    ...:             yield it
    ...:         else:
    ...:             count += 1
    ...:     yield from repeat(None, count)
Is that too boring? :(
@PM2Ring why is it so fast?
@khajvah Likely because it’s native code
07:50
Hey - I'm on a tablet device with a bluetooth keyboard at the moment... have to switch to desktop mode to get fixed font thingy... gimme a break :p
pfff!
I thought you are on a break now, considering you’re here instead of doing busy mod stuff :P
Having to ssh into a server to get a decently working Python interpreter...
You still write code with an interpreter around?
@khajvah It gets done at C speed, and it bypasses the usual progressive reallocation when you append stuff in a loop, since it knows ahead of time how much extra space it will need, so it can do a single reallocation.
07:52
I swear, half of my answers, if not more, are written without me ever running any code… >_<
Plus it can just create an array of N many pointers to the same object... a very fast memcpy operation
At least not running them on an actual compiler but just in my head…
@poke well - strangely - I have to think them up in my head first... then I generally like to try them out... bit difficult posting answers on SO saying "please refer to my brain's memory ingrams" :p
– I wonder if coldspeed would appreciate a solution that requires a native Python extension… (as in: writing that native extension in the answer)
If you can do it at a low level, I think it's a simple case of pointer swapping..
07:55
@joncle Trying out solutions? What a weird suggestion.
@poke I always like to test stuff before posting. It's just too easy to make a silly mistake.
Mar 9 at 8:43, by PM 2Ring
@AshishNitinPatil Old programmer saying: "Nothing is so smiple that you can't screw it up." :)
@PM2Ring let's not forget though... our poke is special... /me runs as fast as he can on his short legs...
lol @vaultah
@JonClements I'll pay that.
@JonClements I would think so too!
07:56
huh?
closing that question :P
I sometimes dream I'm coding, but the damn REPL never works properly. :)
3
How do I paste code to chat
You have 2 minutes to edit that. Or just post a new version & we'll kill the old one.
07:57
We believe in you
Hah! more than two minutes now
dumb!
Control-K will make your message fixed font - see sopython.com/wiki/… for more help
@piRSquared Impressive ^^"
lst = [None, None, 90, 10, None, 34, None, 108]

i = 0
k = len(lst)
while i < k:
    if lst[i] is None:
        lst.pop(i)
        lst.append(None)
        k -= 1
    else:
        i += 1
Life is hard!
He reopened the question I hammered again, and his reasoning is weird (again)
08:03
slow clap
wtf
reopening own question is a pretty bad thing to do
(I worded it badly, I've only seen him reopening his own question once)
@piRSquared Yeah, ok. Though, popping inside a list is a little inefficient, since it has to move all the subsequent items down to fill the gap. True, that happens at C speed, but it's still best to avoid it if you can.
What if you wrap that in jit
We don't have JIT in CPython...
@PM2Ring still at c speed but still better to avoid
08:10
rbrb in a bit
I meant numba
from numba import njit
I'll mess around a bit and show you what I mean
@piRSquared As a rule of thumb, yes, because doing pop in a loop over a list of size n is O(n²) for the whole loop instead of O(n). But it can be worthwhile to do timeit tests with real data, since the C speed can make a big difference.
How can I get time last seen: TI:ME from Area51 using BeautifulSoup?
I scored nicely here, even though my first solution uses the embarrassingly convoluted list(zip(*g))[1]) instead of [x for _, x in g].
08:22
Why not [x[1] for x in g]?
The tuple unpacking looks needlessly obscure
But groupby is definitely the way to go, esp. since the input is already sorted
@PaulMcG It's a Python idiom, and I'm pretty sure that it's faster than indexing.
Why would it be faster? You are building a tuple each time (the _,x) just to throw away the first item. Indexing is just indexing.
@PaulMcG strangely, unpacking is faster than indexing
(not in a blow your socks off way... but...)
08:26
@PaulMcG Magic! :D
n [18]: test = [(r, r) for r in range(100000)]

In [19]: %timeit [el[1] for el in test]
4.87 ms ± 296 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [20]: %timeit [i for _, i in test]
3.88 ms ± 124 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
My theory is that a real Python tuple doesn't actually get built, and it's all done with C shenanigans .
Umm... bigger difference than I remember
>>> dis.dis(el[1] for el in test)
  1           0 LOAD_FAST                0 (.0)
        >>    3 FOR_ITER                15 (to 21)
              6 STORE_FAST               1 (el)
              9 LOAD_FAST                1 (el)
             12 LOAD_CONST               0 (1)
             15 BINARY_SUBSCR
             16 YIELD_VALUE
             17 POP_TOP
             18 JUMP_ABSOLUTE            3
        >>   21 LOAD_CONST               1 (None)
             24 RETURN_VALUE
>>> dis.dis(x for _,x in test)
Yes, I know that is a big code paste, delete if you must...
It's relevant - why would it need to be deleted?
08:34
Code pastes > 10 lines or so are generally discouraged, but I thought it was relevant too
So I guess I was right: the _, x tuple doesn't really get created.
So everyone's learnt something today - hurrah!
It looks like UNPACK_SEQUENCE is just doing 'n' stack pushes, which get popped by the STORE_FASTs. I just checked and it is the same with 5-tuples as with 2-tuples
So I guess for something like in this question if you wanted a list comp to convert all those to floats, one could use: [float(f) for f, in x] instead of [float(f[0]) for f in x] - although that trailing comma always look awkward
Oh, that's a FIFO stack, not a LIFO stack
08:46
>>> abc = 'hello how are you?'
>>> ab = abc['how':'you']

I want to get text from 'how' to 'you'.
Is that possibe?

And I don't want to use something like [3:]
I'm quite sure it's possible
str.index will likely be involved somehow
str.index?
Is it just me, or has the OP failed to ask an actual question here? stackoverflow.com/questions/45479118/…
08:48
@JonClements - I just looked and I have something like that deep in pyparsing, could be a couple of % help
Cabbage
The rest of the code is already pretty opaque anyway, I won't quibble about a dangling comma
@PaulMcG here is the code I tried: abc.index('how','you') but it didn't worked
@MuhammadNouman - open a Python interpreter, type "help(str.index)"
@MuhammadNouman re.sub(r'\bhow\b(.*?)\byou\b', abc) ?
08:53
@JonClements I think you want to use re.search there :)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
re.sub(r'\bhow\b(.*?)\byou\b', abc)
TypeError: sub() missing 1 required positional argument: 'string'
I am using python 3
+1, as you should
>>> re.search(r'\bhow\b(.*?)\byou\b',abc)
But
Result: <_sre.SRE_Match object; span=(6, 17), match='how are you'>
It works
re.search(...).group(1)
But really? A regex solution?
re.search(...).group(0)
Thanks :)
08:57
No - group 0 gives you the whole match - group 1 gives you the contents of the capturing group
@PaulMcG Well, regex avoids stupid problems with strings like "you how are you"
Everything between 'how' and 'you', which was your original question
@Rawing I'm obviously not as good as @poke... that's what happens when I type off the top of my head :)
@PaulMcG Anything wrong with it in particular?
No - @Rawing shows me the light
I mean get text from how to you like it will be : how are you.
@PaulMcG I am really sorry that I didn't make it more understandable.
But Thanks :)
09:00
I'm used to it
@Rawing, the more difficult one to catch with just str.index would be "how how how are you" since you only want to match the last 'how'
maybe
or maybe not
Yeah, and there's stuff like "show you" too, which you have to take care not to match
@MuhammadNouman - if your text included "how how how are you", what would you want to match? Everything from the first 'how' to 'you', or from the last 'how'?
I love it, iphone, ipad shrinking
I have an other problem on the same code:


Hello

how
09:03
flash, flex, .net, linq...
When I use the code here , it gives me error
I want to to use bs4 ( I am not too pro at it ) to extract a line from a site.
def cut(src, start, stop):
    i = src.find(start)
    if i > -1:
        j = src.find(stop, i + 1)
        if j > -1:
            return src[i:j+len(stop)]
    return None

abc = 'hello how are you?'
print(cut(abc, 'how', 'you'))
print(cut(abc, 'lo', 'ar'))
print(cut(abc, 'cabbage', 'how'))
print(cut(abc, 'how', 'cabbage'))
#output
how are you
lo how ar
None
None
@MuhammadNouman ^and that for you
09:08
Actually, that assignment to j would be better as:
j = src.find(stop, i + len(start))
<yawning> - I'm out, rbrb all
@PaulMcG bye
In [37]: def cut(src, start, stop):
    ...:     b1, s1, p1 = src.partition(start)
    ...:     b2, s2, p2 = p1.partition(stop)
    ...:     if s1 and s2:
    ...:         return s1 + b2 + s2
@PM2Ring or something like ^^^?
Hello.

In windows, is there any way to open resource monitor from Task manager, and find for a particular service from that resource monitor box?
i tried WMI but it shows only process and doesn't list all of them
$1.4m in Ether lost partly because javascript has no integers https://mobile.twitter.com/a_ferron/status/892350579162439681
09:21
Hi Guys
i need help
@AnttiHaapala Good job world.
@JonClements Nice. I keep forgetting about .partition
Is there any one ?
Cabbage, all. I presume I'm late with the big news: meta.stackoverflow.com/questions/354217/…
@holdenweb Hi, indeed @PM2Ring brought the news
09:25
@holdenweb Yep, it's been posted a few times already. We can't get enough of it though!
@vinwin That doesn't sound like a Python question...
Most telling quote: "When we started Documentation, our discovery phase was largely done without interviewing typical users."
Who'd have guessed? :-)
@AndyK No, I think it was MooingRawr davidism
@WaqasAhmed There's noone who'll respond to a statement like "I need help", no. But if you tell us what you need help with, then you'll probably have more luck.
@holdenweb It's like you are designing a road for the sake of designing a road... -_-
09:28
ok thanks
Here's the post: chat.stackoverflow.com/transcript/6?m=38440053#38440053 ... unless there's an earlier one. :)
i have installed python on ubuntu 14.04
@PM2Ring fair enough
i want to run web page
@WaqasAhmed Ok. Are you using some Python framework for this?
09:31
no
i just need one page with form
So why are you asking about this in the Python room?
with DB connection
how to run server for python files
Are you asking how to run Python scripts on your server?
@WaqasAhmed please read this message. Also, your question can be answered by a quick Google search.
09:35
not working fine
waqas61@waqas:/var/www/devcode/PY$ python -m SimpleHTTPServer
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/lib/python2.7/SimpleHTTPServer.py", line 230, in <module>
test()
File "/usr/lib/python2.7/SimpleHTTPServer.py", line 226, in test
BaseHTTPServer.test(HandlerClass, ServerClass)
File "/usr/lib/python2.7/BaseHTTPServer.py", line 595, in test
@WaqasAhmed Have you tried pasting the error message into Google? This was the first result.
Anyone smell garlic?
let me do it
@WaqasAhmed Please be aware that SimpleHTTPServer is a simple server. It has virtually no security features, and you should only use it on your LAN. Don't try to use it on the actual internet!
ok
how to run py script with index.html containing form
09:45
stupid java stream
@WaqasAhmed The modern way would be to use a Web framework. But if it's a simple Web page, and a simple form, you could do it the old-fashioned way with CGI.
can't handle my exceptions
@WaqasAhmed Note that the cgi module just deals with the interaction between your Web page and your Python CGI script, it knows nothing about databases.
i also need db connection and fetch results in form
so how to create custom web app consist of one page?
@WaqasAhmed I suggest you to do more research.
09:52
i want like that
2
Q: How to run a http server which serve a specific path?

roipoussierethis is my Python3 project hiearchy: projet \ script.py web \ index.html From script.py, I would like to run a http server which serve the content of the web folder. Here is suggested this code to run a simple http server: import http.server import socketserver PORT = 8000 Han...

@WaqasAhmed That's for Python 3. And if you want it to be able to deal with a submitted form, then you need to tell it to use CGI. As khajvah said, you need to do more research. Then come back when you have a clear idea of what you're doing, and you have specific questions.
@WaqasAhmed The easiest way for a beginner is to do it with a web framework like flask.pocoo.org or docs.pylonsproject.org/projects/pyramid/en/latest
these will give you some idea of how stuff work. And then, if you want to, you can go low level.
ok thanks
10:26
Didn't realise that was quite such a good song... (bit depressing in its own way, but I like it)
> I'm just a beginner rigidly following Zed's ""Learn python the hard way". I got stuck with exercise 15. The example he gave wouldn't run.
And nobody in room 6 is surprised.
@poke I'm surprised. Only in the sense they've stuck with it to exercise 15 though :p
It should probably fail a lot earlier, right?
In an ideal world... yackety yackety yack...
In an ideal world, the book wouldn’t exist..
10:35
@JonClements That dancer though.
Madison Nicole "Maddie" Ziegler (born September 30, 2002) is an American dancer, actress and model. She first became known for appearing in Lifetime's reality show Dance Moms from 2011 (at age 8) until 2016. From 2014 to 2016, she gained wider fame for starring in five music videos by Sia, including "Chandelier" and "Elastic Heart", which cumulatively have attracted more than 3.4 billion views on YouTube. Ziegler has guest-starred on scripted shows, danced on various TV shows and at concerts, and has been seen on magazine covers and in feature articles. She has modeled for Capezio, Ralph Lauren...
Ooo... just seen an advert for "Stack Overlow Talent UK" on FB... that's handy - cos I'd never heard of that company before d0h!
I can "get the employer branding tools you need to attract developers" apparently...
@MartijnPieters yeah... I tend to not watch too closely as it's ouuuuuucccchhh.... that's gotta hurt...

« first day (2483 days earlier)      last day (2689 days later) »