« first day (1616 days earlier)      last day (3348 days later) » 

12:01 AM
May I ask a Django question here?
 
@Mark yes - see sopython.com/chatroom for the room "rules".
 
How can I generate a fully-qualified URL (including protocol and port) outside of a web request context (i.e. in a Model property getter)?
For example, I have a model class like this:
class Package(models.Model):
        name = models.CharField(max_length=200)
        description = models.CharField(max_length=500)
        version = models.CharField(max_length=30)
        pub_date = models.DateTimeField('date published')
        filename = models.CharField(max_length=200)
        is_published = models.BooleanField()
        release_notes_url = models.CharField(max_length=1000)
        platform = models.ForeignKey(Platform)
        groups = models.ManyToManyField(Group)

        @property
 
12:23 AM
SETTINGS.ROOT_URL i think
if its in django
where settings is imported
from the django stuff
 
thats just a string in a settings file? it can't get it dynamically?
 
sure
with the request
....
typically these types of functions just return the stub part ie "/foo/%s"%(self.filename)
and its a different things delegation to figure out the rest
 
right, but there is no request available in a model instance, is there?
 
 
2 hours later…
 
3 hours later…
5:26 AM
Cbg
 
cbg
 
6:25 AM
cbg
yesterday was a hectic one for sure
@Ffisegydd my wife tells me all the time I have the biggest head of all people she has ever met, so thanks
 
7:11 AM
@AnttiHaapala wow :) is she right?
 
how can I know
can't know every person she's ever met :D
 
:3
 
solar eclipse today
partial :(
nice
though seeing a solar eclipse in the UK -> forget it
 
7:26 AM
@AnttiHaapala do you think she's right? :)
 
Waaaaay to broad and a recommendation request and primarily opinion based.
 
@RobertGrant probably
 
and cbg :-P
 
@AnttiHaapala well, that's a good start :)
 
user image
7
 
7:34 AM
We need one more vote on that one..
 
@vaultah chat on my phone is doing the same weird photo thing btw
 
maybe we should have a q and answer:
"where to find information on Python standard library modules"
and then we'd hammer every one of these duplicate of that :d
ah scrap that
 
cbg!
I'm trying to move files from parent dir to child dir. This is how far I've reached.. Any help ?
 
You should probably write some code to do it.
Have you googled for, for example, "moving files with python"?
 
import os
import shutil
def move_folder(path):
    dir_src = path
    filenames=os.listdir(path)  # list all files
    for i in range(0, len(filenames),250): # for each 250 files in parent create a child dir
        path = path+str(i)                # path of child
        file1 = filenames[i:i + 250]
        if not os.path.exists(path):
            os.makedirs(path)             # create dir if not exists
        src_file = os.path.join(dir_src, file1)  ## error
        dst_file = os.path.join(dir_dst, file1)  ## not working
Yes. I've written above code to do it.
 
7:43 AM
Ah OK. It sounded like you hadn't written a thing at first and so I was going to say stern things, but now I shall not :p
 
That file1 = filenames[i:i + 250] thing looks weird
But I am on a call so maybe I'm not thinking straight
 
Ha Ha! I had my experience here before on SO. I know when to post a question now. :P
But sadly I'm still not allowed to ask a question. :(
 
The patent for toilet paper should settle the over vs under debate http://t.co/arZl6l6ALn
 
Because aren't you making a list of filenames, and then doing os.path.join with that list?
 
I'm listening
Oh!
 
7:48 AM
@Ffisegydd oh, which photos are affected?
 
Umm.. I don't know. But it gets the job done. I have tried moving single file from one folder to another
 
@d-coder you want to name file1 as fileslice or something
 
@d-coder see what I mean? :)
 
then you do for file1 in fileslice:
for file1 in fileslice:
    src_file = os.path.join(dir_src, file1)  ## error
    dst_file = os.path.join(dir_dst, file1)  ## not working
    shutil.move(src_file, dst_file)         ##
because the file1 is not a 1 file
it is a list of upto 250 consecutive file names from the os.listdir
 
Homework dump, no attempt at anything.
 
7:58 AM
@vaultah at the moment Antti Bob and maybe Martijn (not too sure on Martijns)
 
Pew pew
 
Yep, same
 
So gravatar-hosted images only?
 
I haven't found the bug tracker :(
 
Because d-coder's image is hosted on i.stack.imgur.com
 
8:02 AM
and vaultah's image is white, though that might not exactly be a bug
 
Joran's image is unaffected @MartijnPieters
 
@vaultah just trying to find a pattern.
It is enough for most gravatar images to be corrupted.
But as soon as you find a i.stack.imgur.com image corrupted, then it is more likely to be your browser or network.
 
and davidism's image is affected as well
 
My own is unaffected btw
 
@vaultah type three lines in a row and see what happens
 
8:07 AM
I'd be surprised at a network issue. I'm on the same wifi that I use for my PC and it's fine. Let me try an alternative phone browser.
 
Can't reproduce using Firefox
I used like 3 networks yesterday, it doesn't appear to be network- related
 
Can't reproduce in basic Android browser. Seems to be Android Chrome only.
Also when I open an image in a new tab it looks fine.
 
@RobertGrant you mean three messages?
 
Yes
He says, breaking the chain.
 
so how are they broken?
@Ffisegydd ca71042d9d6724f4cbc2598195662eb0?s=48&d=identicon&r=PG: JPEG image data, JFIF standard 1.01, comment: "CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), quality = 90"
@Ffisegydd open link gravatar.com/avatar/…
and reload
 
8:17 AM
Tada, everything is fine in Chrome Beta
 
the gravatars are jpegs
 
These days, everything's a Chrome beater
 
@vaultah is this on Android? No problems on my iPhone.
 
Ahahaaaa. Ah.
 
@RobertGrant :-P
 
8:24 AM
@MartijnPieters yes, Android
 
@AnttiHaapala : Thanks a ton!
@RobertGrant : Yes. I realized after you mentioned it.
Thank you all
 
Cool :)
 
8:49 AM
This code finally worked :)
import os
import shutil
def move_folder(path):
    dir_src = path
    filenames=os.listdir(path)  # list all files
    for i in range(0, len(filenames),250): # for each 250 files in parent create a child dir
        child_path = str(i) # path of child
        fileslice = filenames[i:i + 250]
        if not os.path.exists(child_path):
            os.makedirs(child_path)
            dir_dst = child_path
            for file1 in fileslice:
                src_file = os.path.join(dir_src, file1)
                dst_file = os.path.join(dir_dst, file1)
Now I have one more question. :P
 
Might want to get rid of that # error comment :)
 
Okay @Ffisegydd and @MartijnPieters, do you use the Data Saver option?
 
Is it possible to import all modules at t time ? If yes then how ?
a*
 
@d-coder also, don't call that method move_folder; isn't it more like archive_folder?
Or something else. But not move. It doesn't even move the folder :)
 
@RobertGrant : You are killing me!
 
8:55 AM
Yes, yes I am. This is what death feels like.
Welcome to my bony clutches
 
Settings > Data Saver > Off - Clear cache - Images are corrupted; Settings > Data Saver > On - Clear cache - Images are okay
Yay!
 
@vaultah that's an unexpected way round
 
Yes! You are right! But that code will not stay forever like an answer on SO.
So I'm gonna leave it like that :P
 
@d-coder that almost never turns out to be true, unless you delete the code :)
 
re-hey-up
@vaultah Data Saver?
 
8:58 AM
Settings > Data Saver
 
Don't have that option.
 
Moreover that code will never be used as reference by anyone here. I know people here can write better code than what I wrote. :P
 
@vaultah Not sure, I think so.
 
Wow. So much cloud. Such eclipse.
 
@RobertGrant : It wont be used as reference by anyone here. You all can do better than that.
 
9:00 AM
chat.stackoverflow.com/transcript/message/22201648#22201648 Now I need to do something with this information
 
@RobertGrant : I can't edit or even delete it now. So it'll be there forever :)
 
@vaultah: yeah, I have data saver on.
 
Mm, kind of obvious
 
9:26 AM
This Solar eclipse is amazing. It's spectacular how the blanket clouds over Bath are getting ever so slightly dimmer.
 
17k
 
I know...
 
Cabbage!
 
Cabbage @poke
 
9:41 AM
The damn sun is too bright ⊙_⊙
 
@vaultah Q_Q
There’s a partial solar eclipse here today, and all I can see is stupid fog.
 
I hope my phone will let me see it, with the appropriate camera settings...
 
It won’t.
Unless you have a really good ND filter.
I was talking to a friend last night, and we considered building one ourselves by adding smut to a piece of glass by holding it over a candle.
it won’t be a N D filter, but it should take out a significant amount of light.
(and you don’t really care about colors when photographing the sun…)
 
Did that a few years ago
 
9:57 AM
Did it work?
 
When I was an undergrad we used to have access to hydrogen-alpha filters which were perfect for the sun. Blocked out a serious amount of light and also only allowed specific wavelength through, meant you could use it with a telescope.
 
Interesting
 
@Ffisegydd why is asking for a python module off-topic and not a programming question ? — DhruvPathak 44 secs ago
17k rep...
 
lol.
 
The last partial solar eclipse that was visible here I watched with a pair of welding goggles. It was ok, but it's still not a great thing to do to your eyes. Indirect viewing methods are much safer.
FWIW, the cv-pls I posted earlier has been solved by the OP - it was (mostly) a simple Bash syntax error.
 
10:02 AM
I should have used my welding mask. Damn didn't think of that.
 
10:34 AM
Anyone up for a cute little geometry problem? See math.stackexchange.com/questions/1188845/…
 
10:50 AM
Community took down a question where I had a 4 upvoted answer :'(
 
Wow. I thought questions with up-voted answers couldn't be deleted.
 
Got both of those from this
@Ffisegydd I have asked questions related to python modules in the past, and they have been well received, and in my opinion, they related to programming . stackoverflow.com/questions/24634833/… stackoverflow.com/questions/17404348/…DhruvPathak 2 mins ago
 
@PM2Ring I think accepted questions cannot be deleted. I am not sure though...
 
user559633
11:15 AM
We need a salad word for people that aren't really time vampires, but want you to debug their stupid local environments
 
"The pycrunchbase module has on the six and requests modules. " - there appears to be a word (or two) missing from that sentence.
 
user559633
@PM2Ring thanks
 
No worries, tristan. Maybe that guy need to re-install / upgrade pycrunchbase now that he has its dependencies installed?
 
user559633
Nah, they're newer in terms of timestamps, so the import system will exec them
 
user559633
11:30 AM
i'd guess that he installed pip separately and it's looking to some non-system python
 
user559633
Which is to say, I'm nearly positive what's wrong, but explaining it over the internet just takes a long time and it's not interesting
 
user559633
this is the perfect "let me see your computer for a second" problem
 
11:47 AM
solar eclipse cbg
 
user559633
cbg
 
Re-cbg
 
Too late :)
 
@RobertGrant you had a whole 68 seconds for it! Slowpoke.
 
11:59 AM
I did go as soon as I saw it! cowers
 
user559633
Slowbert Grant..more like it
 
It started snowing ten minutes after I arrived at work. Maybe all my coworkers will stay home. That would be nice.
3
 
user559633
You're already at work?
 
Yeah, I usually arrive at 7:30-8:00 local time
 
user559633
My girlfriend got up for water, which in turn woke up my cat, who decided that 4 AM is totally close enough to normal hours and it's time to play with the ball ball ball
 
user559633
12:01 PM
@Kevin oof. are you just a morning person or are your hours 8-6?
 
7:30-4:30 usually
 
user559633
Is that a thing people do in commuting areas?
 
I'd prefer 9-5 but I made the fatal error of getting into an industry where 40 hour work weeks are laughable
 
user559633
I do 9-6:30, sometimes 9-7:30 if i'm drinking in the office
 
Hmm, not sure if "fatal" is the right word, since I'm still alive. Certainly I'm dead on the inside...
 
user559633
12:04 PM
We all are, Kevvy, we all are.
 
anyone here use services like Sendgrid? Seems like there are a lot of them. Which ones are best?
 
I like to eat dinner at 6:00 so that puts a hard limit on how late I'll stay
 
user559633
@corvid CV, opinion based (but really, are you looking for transactional mail?)
 
@tristan It's funny, from birth to college graduation, I preferred a "2:00 AM to 11:00 AM" sleep schedule, but nowadays I pretty much can't sleep past 8:00 even on the weekends.
 
yeah, just something to send emails in a production environment, right now for testing I'm just using my own email address
 
12:07 PM
I don't know if that's a biological change due to aging, or a pattern ingrained from months of getting up early for work, or what.
 
user559633
Yeah, I'm happiest with a 5->1 sleep schedule, but i've been forced to adjust to a 10-5a when i can get it
 
@Kevin I'm the same. I regularly wake up at 0630-0700 even on weekends.
 
My only regret is I can't stay up late enough on Saturday to watch the 1:00 AM shows on Cartoon Network. But I guess I've seen enough reruns of Ghost In The Shell for one lifetime.
 
user559633
Ghost in the Shell of a Man
 
user559633
baleeted
 
12:09 PM
If my parents get wind of me being awake before noon on a Saturday, they're all like "waking up for a special occasion? Are you ill?" and I'm like, "no... This is just who I am now"
 
user559633
Look what society has made me
 
Looking at the starred list, I wonder how many of the things I say in complete seriousness get interpreted by others as Steven-Wright-esque deadpan.
 
@tristan bah, too late to leave my comment... "You must bring the ashes of a vampire, the blood of a fallen champion, and the feathers of a raven to a sorcerer for him to transmute the invisibility potion of which you speak."
 
user559633
@corvid to your earlier question, i use mandrill for one of my applications and i'm happy with it
 
user559633
12:17 PM
disclaimer: i technically work for a company that has an email service, but AFAIK they don't do transactional email
 
@Kevin I was a bit disappointed with ghost in the shell (was it a movie first? If so, that)
The other thing being called git sac barely made up for it
 
I think it has a number of incarnations. Whichever one showed up on Cartoon Network seemed to follow the "5% amazing action scenes, 95% talking heads" model.
Which worked pretty well, really. Save up all your animation budget for one kickass cyborg Vs tank scene every three episodes or so. Fill the rest of the time with philosophical debates.
 
Yeah that sounds about right
It just wasn't as revolutionary or whatever as I was hoping; seemed like a fairly standard setting
"Maybe our souls can live on in machines" is not a jaw-dropping idea
Or whatever it was. Maybe I'm remembering it with whatever the bad version of rose-tinted spectacles is
Through a pair of rose-tinted spectacles darkly
 
"Maybe machines can have consciousness too" has never been a particularly astonishing idea to me. I guess I see it as a natural consequence of my own physicalist philosophy
 
Maybe is easy. Definitely, based on any AI advance I've ever heard of is harder to swallow
Yeah that was aimed at you, Hawking
 
12:27 PM
The simplest approach would seem to be: create a computer which can simulate real physics down to the quantum level. Then, scan a human and simulate them. Ta daa! Artificial consciousness.
Here "simple" means conceptually simple, rather than practical. You may or may not need a computer the size of Jupiter to simulate real physics at a macroscopic scale.
So the answer to "will humanity ever make a conscious machine?" is still "maybe", regardless of the answer to "is it possible given a ridiculous amount of resources?"
 
Yeah, assuming that works :)
If we can we will; of course
Unless it'd bankrupt the planet
In which case we'd only do it if someone else were also doing it, so we could end up spending twice the resources
 
This tangentially reminds me of a short story I read about a space shipping company that discovered the barely functional battle-torn body of an angel floating in the vacuum. It doesn't respond to any kind of stimuli, with one exception: when presented with a Go board, it makes the best possible move instantaneously. They regard this as a fun yet useless talent until they realize that you can encode NP-hard problems on a sufficiently large Go board.
They devise a mechanism to automatically send NP-hard queries to the angel and get a response back in constant time. This gives them a ridiculous competitive advantage against all other space shipping companies, and they go on to dominate the galaxy.
The end! No moral.
 
12:46 PM
Hey everyone, could someone tell me if it is possible to provide a list to the python in operator? So can I check list b is in list a?
 
You could use a list comprehension. if all(item in a for item in b):
Take note that this will inspect each element in an unordered way. So it will return True for a = [1,2,3,4,5], b = [5,3,1], even though those numbers aren't neighbors in list a.
 
yeah I don't care about order at all
problem is this is via robot framework
so using builtin libraries
 
And it doesn't care about duplicates, so it returns True for a = [1,2,3,4,5], b = [1,2,2,2,2,2,2,2,2,3]
Ok, well, list comprehensions are indeed a built-in feature, so no problem there.
 
asserts.fail_unless(item2 in item1, msg)
 
@Kevin Psst. That's a generator expression. :)
 
12:50 PM
could I provide a list to that? or would it need to be changed as per your example?
 
Well, you could paste my example in directly (changing out a and b for item1 and item2), or you could write a contains(a,b) function if you're going to be doing this a lot
You can do whatever you want :-)
 
Kevin's code checks each item in list b in turn to see if it's in list a. It bails out early if an item can't be found in a.
 
If you're about to say "I tried asserts.fail_unless(if all(item in item1 for item in item2):, msg) and it didn't work", you got me! I forgot to clarify that you shouldn't paste in the if and colon.
@PM2Ring Ok. I can never remember the difference so I just use "comprehension" as an umbrella term.
 
I see. That could get confusing. :) You definitely want to use a gen exp here rather than a list comp, so that you get the early bail-out behaviour.
 
I need a good term for "that category of things you can do where you use for in an expression"
 
12:58 PM
Do you not get the earlier bail out behaviour with a list comp?
 
I don't think you do, no
(not in 2.7 at least)
 
@Ffisegydd Not if you do if all([item in a for item in b]): - it has to build the whole list before all() can test it.
 
CBG! :D
 
cbg, BhargavRao! You're late. I hope you brought a note. :)
 
Nope, What should I have brought?
 
1:03 PM
Devil's advocate: "list comps are generally faster than generator expressions, so you might actually want to use them here, if bailout behavior is unlikely to occur very often"
Kevin's advocate: "but that requires typing an additional pair of square brackets, which is a lot of work. Just don't bother"
 
@PM2Ring And why late? Did I miss anything?
 
do list comprehensions on all fail on the first occurrence of a False value?
 
Just crashed my laptop trying to make a list of 1bil elements. Big numbers are not my forte
 
Not really. I'm just being silly. It's just after midnight in my timezone.
 
@PM2Ring Also congrats, the Aussies won!
 
1:06 PM
@Kevin Good point. It looks like this is being in some kind of assertion test, so I guess we can assumed it's not supposed to ever fail.
@BhargavRao Thanks, but I don't follow cricket. :)
 
Double devil's advocate: if you care enough about performance that you agonize over list comps vs gen exps, you're probably going to disable asserts anyway.
 
Gen seems like the future
 
If asserts aren't disabled in production code, you're doing it wrong.
 
hrmph. This is weird. I have an https:// site with nginx, and an alias in /etc/hosts, but it keeps thinking I'm using localhost
 
@corvid Let's see.
def frob():
    yield True
    yield False
    print "this will only appear if `all` doesn't fail on the first occurrence of a False value"

print all(frob())
#result:
#False
 
1:08 PM
@RobertGrant Gen exps usually have less memory overhead than a list comp (unless the list is fairly small), but as Kevin said, they're often slower than list comps.
 
@PM2Ring sure, but it seems like a good default unless you really need the speed and the whole list in memory
 
nevermind... I'm an idiot.
 
Be nice if the interpreter worked out that it needs the whole list in memory the next time it's referred to, and switched to a list comp automatically
 
@RobertGrant Sometimes it's not obvious when you need the whole list. A common example is when using str.join() - it's much more efficient to join a list comp than a gen exp - Raymond Hettinger explains why here
 
cbg
 
1:18 PM
> In general, genexps (as they are affectionately known) are more memory efficient and faster than list comprehensions.
Now I've heard exactly contradictory statements regarding the general time efficiency of gen exps :-(
I guess I'll have to... gulp... perform my own measurements instead of depending on the word of "experts"
 
Yeah gen is slower if you need the whole list at the end, and maybe slower regardless, unless you're using so much memory you slow things down
 
JavaScript patterns are a little weird... would it be overextending to include an API wrapper on top of an authentication wrapper?
 
@corvid, the answer, my friend, is blowin' in the wind
 
If str.join() didn't make two passes over the data then it'd have to the equivalent of final_string+=separator + substring which would be even worserer.
 
That's how it works in KevinScript :-( I really need a native array type.
Lists don't cut it! I need something with earlier-than-just-in-time memory allocation.
 
1:24 PM
@Kevin That's not good, since it has to allocate memory for the new string each time around the loop.
 
Agreed
 
Python lists can grow more efficiently time-wise because they over-allocate a little when they need to expand.
 
Hi, do you see where is the error in this code below?
mapper="s3n://myfolder/" +key_mapper,
reducer="s3n://myfolder/"+key_reducer,

Because Im having this error: TypeError: cannot concatenate 'str' and 'Key' objects
 
Have you read the error message?
You cannot add a Key object to a string.
 
yes..but I needed to concatenate
 
1:29 PM
Well, you can't. So look to see if Key objects have an attribute like Key.str or some other similar attribute that returns a string.
Or see if there's a way you can add the string to the Key, like Key.add_prefix.
 
hm ok thanks, I will try that
 
Here's a nice blog post on the CPython list implementation. And FWIW here's the C source of the List object.
 
Amortized O(1) append is pretty sweet
 
1:46 PM
Waiting for 1 more guy!
:D
 
cabbage everybody
 
Trying to decide whether to hammer this question...
 
Definitely closeworthy - I suppose there's an argument you should refrain from wielding the hammer since it's not actually a Python question ;-)
Moot now anyway; your vote will be the fifth.
 
@MartijnPieters what do you think of a regexp answer as the answer of this question
2
Q: Python: How to parse a "return" string

Andre DieballI'm writing a little tool which uses an existing framework via import. The part I'm using is: def exec_command(self, command, timeout=60, mode=cli.CLIMode.UNDEF, output_expected=None, error_expected=False, prompt=None): """Executes the given command. This m...

 

« first day (1616 days earlier)      last day (3348 days later) »