« first day (1475 days earlier)      last day (3467 days later) » 

1:57 AM
@Basj The quick 'n' dirty way I'd do it:
i = 0
for line in file:
    if i > 2:
        do_something()
    i += 1
There are more elegant ways to do it, but I'm totally on the wrong timezone and don't trust myself not to mess up
Of course there's always docs.python.org/3/library/linecache.html - depending on the size of what you're wanting to process
I think linecache shoves the entire file into memory. Might be an issue if you've got giant files
 
@IntrepidBrit if you choose that solution, at least do it with enumerate()
for i, line in enumerate(file):
    if i > 2:
        do_something()
however, I would probably go with .readlines()
 
Bah and/or humbug
 
for line in file.readlines()[2:]:
    do_something()
 
I should have kept my mouth quiet and went to bed ;)
 
that's a bed bad strategy ;)
 
2:09 AM
But yes - enumerating over the file is a decent idea
Does readlines() read in the entire file at a time?
 
hmm.. good question.
my second suggestion however will definitely make another list -- so I guess enumeration is the way to go.
@IntrepidBrit it returns a list
so it read the whole file
therefore definitely go with the enumeration
 
Well, depends on what he wants to do
S/he could have wanted to perform operations as they went
 
ofc it depends, but right now we don't know the file size, so the best thing is to recommend the safest solution, which is the enumeration
 
We're getting to the point of splitting hairs
We won't know unless Basj comes back :)
 
for line in itertools.islice(file, 2, None):
    # etc.
 
2:17 AM
@IntrepidBrit I want to split hairs!
@ZeroPiraeus that's also cool -- what islice do under the hood?
 
Way of specifying start, stop and the step
Don't worry, I didn't know that until a second ago haha
 
What is it for, or how does it do it?
 
That is a very tasty piece of python functionality I didn't know about until tonight. Cheers @ZeroPiraeus
 
I mean you pass the file as an TextIOWrapper
which could be used as an iterator
how will it go to the third "stage"
 
It's intended to have the same functionality as slicing, but for any iterable.
 
2:20 AM
but how?
 
Just consumes items and throws them away.
 
so basically doing the same but in a more elegant form than what we did with enumerate() and if i > n?
 
I guess ... obviously there's more to it since it has stop and step parameters.
 
obviously.. but is it implemented in python or doing something at the C level?
 
Hell if I know ...
 
2:23 AM
:)
 
Ah, it's in C.
 
nice, so it is way faster than enumerate in python and start an if-conditional in python
in that case -- your solution is the best
;)
(that's why I was asking)
 
One question before I had to rhubarbing bed
Is a newbie comes on and asks the best method of doing something like the above, where there's varying levels of complexity and further understanding
 
@PeterVaro Well, yes, but on the other hand we're doing I/O, so ...
 
2:27 AM
Do we/should we just recommend the "best" method to them so at least they're aware of it? Or should we give them something like enumerate to be getting on with?
 
I think recommending the best is the best
because they are getting used to a better solution
which is even better than getting used to something which you have to replace in the future
when you have greater knowledge
(IMHO)
@ZeroPiraeus .. umm.. so? that's the job of the TextIOWrapper not the itertools.islice()
 
If someone asks for the best, that's what you give them. If they don't understand, they'll either ask (learning opportunity) or not (they're a gimme teh codez type so who cares)
@PeterVaro I meant that's the limiting factor on speed, not whether we're using Python or C.
 
ahh.. I see.. but actually my question was more general
 
Good points. It's not like Python is a language like C where you can quickly get balls deep in pointers and macros. That's quite likely to freak out the natives when your witchcraft causes an lunar eclipse
 
not restricted to IO but to islice in general
because I keep forgetting that itertools has islice function
even if I use almost all of the other function all the time
so I was curious.
@IntrepidBrit although in python:
> There should be one-- and preferably only one --obvious way to do it.
so I guess recommending the best. as the only way is a nice and pythonic behaviour
 
2:34 AM
I like that. Probably not worth canonising though
 
it has already been canonised ;)
type in: import this
 
I meant the discussion of "what should we suggest to people" :)
 
ahh.. good point :D
 
Okay guys
G'night and until later!
 
rhubarb(@IntrepidBrit)
@ZeroPiraeus I finally read and understood the whole block of C code of islice_new
it is just as fast as it can be -- sweet!
 
2:40 AM
I think Raymond Hettinger's responsible for itertools, isn't he? I know he's highly regarded.
 
I think he is, once he even mentions it in his presentation
but he has a terrible indentation style in C -- if this source is just looks like how he had done it ;)
 
3:27 AM
cbg
 
3:38 AM
@corvid resizing and performing operations is better..i have seen performance boost on my raspi when i downsized the image from (640.480) to (320,240)..
 
 
2 hours later…
5:20 AM
Cbg
 
cbg
 
5:32 AM
@AnttiHaapala Hey!
Got a minute?
 
6:17 AM
cbg
 
there you go your brandy..
 
at 6:20am!? :p Where'd you run off to get it from!!?
 
I have been awake for 4 hours now...i had a lot of time to run off..
 
Well - very kind of you to remember it... I'll put it aside for later :)
 
melons
 
6:29 AM
So what time is it there?
 
12:14 pm
 
Ahh... not too bad
 
what would have been "bad"?
 
6am like here? :(
 
why you up so early? and with that sad face?
 
6:35 AM
Oh, just getting a server deployed...
And to narrow down an intermittent bug
 
is it cold?
it is 21 degrees here
goodluck
 
I'm wearing a jumper indoors :) So it's not warm...
 
me a jacket...indoors too..
 
@tilaprimera what timezone is that?
 
GMT 5:45
 
6:37 AM
which country?
 
Nepal
 
Ohh , and indian states to the east of nepal follow +5:30
 
yea there is a time difference of 15 minutes between nepal and india
 
india is quite broad , it should have 2 timezones .
 
Then there'd be a cool bit in the middle where you could "time travel"? :)
 
6:39 AM
yea surely..i should have been precise...delhi time and here is 15 mins i guess
 
the best place is somewhere around new zealand.. cover a small distance and u travel 24 hours in time..
where +12hours GMt and -12 meet
 
Hah, I read about it somewhere
 
6:55 AM
Err... where is mysqldump on a Darwin machine?
Ahhh /usr/local/mysql/bin of course
 
@vaultah sorry wrong link :ÖP
this is the newer
they said someone used a robot to exploit, within 7 hours from disclosure
 
Oh boy. Didn't know about the newer one
 
*i mean the expoit is not new
the information
that automated exploits in 7 hours... so :P
haha
bc they do not say "we will be releasing a critical update at x"
they just disclose it at that time
 
Ah, yes
 
so say you are in vn, that announcement would have come at 11pm :D
then you wake up at 6 am, drink vietnamese coffee
and read some news...
and you are like "wtf" :D
and it is sqli. and everyone says "you can have sqli in every language, php is not an exception" :D
 
7:17 AM
> Authorities have identified the woman they believe is behind graffiti at eight national parks
CNN Breaking News..
 
how could i possibly insert an attribute val with value yellow in this expression:
for r in p.findall('.//{%(ns)s}highlight/../..//{%(ns)s}t' % {'ns': w}):

I did :
for r in p.findall('.//{%(ns)s}highlight[@val="yellow"]/../..//{%(ns)s}t' % {'ns': w}):
but doesn't work
 
@GamesBrainiac minute now :P
@vaultah is it now a crime to stand behind a graffiti in a national park?
 
:D
 
So, I have this sa field, updated_at inside a mixin. whats the best way to update this, override the __setattr__ function, or add an event?
with the event, its session specific, and not class specific.
With overriding __setattr__, it does not record the time of actual commit.
 
hmm if you used postgres maybe I'd do that in db instead
maybe with event
though with anything
it does not record the time of commit
but time of flush, hopefully
 
7:25 AM
Hmm.
 
otherwise you have a sh*tstorm at the time of commit
 
Okay, so __setattr__ it is.
Don't want a sh*tstorm
 
Cbg
 
@Ffisegydd STEWIE!!!!!!!!!!!!!!!!!!!!!!!1
 
7:35 AM
now that was a greeting :D
 
@Games yeah... but it's not being returned meep meep
 
@JonClements rubs jon's back its okay puppy. I appreciate you :)
 
/me goes grabs @Games his favourite toy
 
@Jon Briiiiiiiiiiiiiiian
I was replying to pokes answer
 
@JonClements So, did you get your wallet back?
 
7:48 AM
Will this morning... Dave and I have kept missing each other... he's bringing my nephew around later as well for lunch, so that'll be cool :)
Probably the longest I've gone without spending much money... so it's kinda been good in a way? :p
 
cbg @Robert
 
cbg @RobertGrant @Ffisegydd @GamesBrainiac @JonClements
 
@tila you geek :)
 
wondering when it hits the market
@JonClements same pinch!
 
8:07 AM
@JonClements Yea. Good thing you got a $20 supply.
 
Lucky I had a freezer full of food more like it
 
Somehow I don't see my meta question being implemented, never mind, twas only an idea and I'm sure we will survive as we always have.
 
We will prevail!
 
now someone is grumpy this morning
We will prevail!!
 
Is Sublime Text 3 development dead or something?
 
8:20 AM
I know it does seem very slow
I think Peter once mentioned that if you want the new features you need to use their dev builds as they rarely release stable milestones
 
Hmm, I think they're working on something brand new.
Either way, I just use ST for quick edits.
Holy sh*t. SA just reached 1.0
Oops false alarm.
The latest version of the docs are 1.0 :P
 
8:40 AM
...?
 
any SO co-creaters..lurking in here?
 
Check the tavern.
 
@IntrepidBrit @PeterVaro thanks for your solution about reading lines!
 
i want to update my database if a certain unique field data exists else create the unique field----------(django)
 
bbias - need to do some invoicing...
 
8:45 AM
another one @IntrepidBrit @PeterVaro : what's the nicest way in your opinion to do something each day at 0:15 am (the python script would run 24/24 7/7 but does nothing except at 0:15 am) . Of course I could use cron on Linux, planified tasks on Windows, etc. but I would like to do it with Python only.... I have found some SO questions on that, but not 100% sure if it's nice...
 
Use cron.
You can get python libraries that set your cron up for you if you want.
But use cron anyway.
 
@Ffisegydd : I'm on Windows, and I do the script for someone who doesn't know about command-line at all.... So I need to do all-with-one-tool, so that it's easier for him
 
@basj Task Scheduler in Windows
 
9:01 AM
Yeah use the Windows version. These things were built to handle what you want.
They'll have a low footprint and can call your script when you want.
 
9:15 AM
BBC Radio 1 - Live Lounge 2014 album is so awesome, I'll probably pay for it
 
I haven't listened to Radio 1 since they got rid of Chris Moyles.
Uninstalling Python ;_;
 
@Ffisegydd he was in the news the other day about "how tragic" it was his youtube thingy isn't working
 
Anyone watch "Peaky Blinders"?
 
I didn't even know he was doing something new. I always liked Moyles' breakfast show. Especially in comparison to the absolute crap they have now.
Then again I'm not exactly their peak demographic anymore.
 
When did they get rid of CM?
 
9:27 AM
I'm not quite Radio 4 material yet :)
 
Radio 4 is amazing
 
I don't listen to radio, but if I did it'd be Radio 2.
@Robert 2 years ago maybe?
 
For a second there I thought @RobertGrant said "Rails 4 is amazing" :P
 
Oh, wow okay
@GamesBrainiac pfft. CodeIgniter til I die by being crushed to death by a pile of verbose code
 
lol
I mean, this is not an exaggeration or an opinion, but CodeIgniter has a horrible API.
I don't think its even maintained properly anymore.
I think I understand why people stick with Django, SQLAlchemy's ORM isn't the greatest out there.
I learned more about a session object from reading its source code, than I did reading the docs.
 
9:33 AM
I've heard that SA is much better.
 
Me too. I used core till now, but now I'm starting to use the ORM layer.
So far, its been frustrating.
But at least I can use mixins, so yay :)
 
what is SA?
 
SQLAlchemy
 
oookay!
:D
 
I keep reading that as SQLAcademy
3
 
9:44 AM
hehe
Honestly, I'm pretty sure its good, I just wish the docs were a little more friendly.
Sometimes, I'm like "so what do you want, the table name or the class name?"
 
Yeah I hear very good things, but I don't yet do anything outside of what Django's ORM gives me
 
Well, since no one's offered to make me a cup of tea... I'll go make it myself shall I!? :P
 
I got a hot flask, and some tea bags, but damn the courier feeds @JonClements :P
 
well - damn coming to collect it in person @Games!
 
@JonClements btw, its green tea :)
 
9:53 AM
Blarghghgghgh!
Are you trying to poison puppy! :*(
 
Green tea is lovely.
 
Actually, I'm drinking the stuff right now
 
In fact I prefer green tea to normal British tea.
 
Lost a lot of weight because of it.
@Ffisegydd Dude, we are awesome :D
@Ffisegydd Do you add lemons?
 
WTF!? Have I entered the twilight zone this morning!?
 
9:54 AM
Sometimes yes. I also like peppermint tea.
 
@Ffisegydd ahhh peppermint tea I don't mind
 
We have very similar tastes.
 
Because we're part of the same hive mind.
 
@JonClements JOIN US; JOIN US;
 
I occasionally suffer from IBS, so peppermint tea helps that
 
9:55 AM
How do you guys like Elachi tea?
 
never heard of it myself...
 
Might have to try that at some point :)
 
Although I gotta say, I never buy from Twinings, those guys are expensive.
I ground the cardamom myself, and add some honey to black tea :)
 
That sounds like work though :p
 
9:59 AM
Hehe, but 25 bags is just too few. I drink something like 5 bags a day.
 
I like green tea
 
I typically drink coffee at work because COFFEE.
 
Honestly, drinking green tea for the weight loss. Coffee gives me a bit too much caffeine. Only drink it first thing in the morning, then I just cost with tea :P
 
@Games 5 seriously? I have 2 straight after getting up, then probably another 9/10 during the day
 
Don't have a kettle atm, need to buy one. Then I'll give you run for your money :P
 
10:03 AM
When it comes to tea, let's be honest. It's Whittard's English Breakfast Tea or it's just expensive urine.
 
Eww. If I'm going to have "normal" tea then it's Yorkshire Tea.
 
@Ffisegydd that's what's in my cupboard :)
 
@JonClements Got time for a small SA question?
@JonClements actually nvm. Fixed it :)
 
Wow... I'm so good I didn't need to even know the question and still solved it... :)
 
Eeek: "how to handle the different pythons inside my computer. I have at least four different python's" stackoverflow.com/questions/26650172/…
 
10:14 AM
cbg
(always forget that part)
 
@Paul worrying
I can't believe that Rightmove don't let you cheaply advertise a place to rent
 
Use pyenv. I think I wrote a post on it too. @Paul
But yea, use it.
 
I'm not the OP. Just lurking. Someone just mentioned virtualenv in the comments.
 
In that case would it be possible to have my account merged with one that already has the analytical badge please :) we have a competition in the office at work to see if anyone can actually achieve it. — DAVEWASLIN 1 min ago
Uhm, no.
 
10:35 AM
CBG
 
I was learning about decorators and I have a question
def cal(myfun):
        def add():
                return myfun()+1
        return add
@cal
def sim():
        return 6

x = sim()
print x
 
fire away
 
@d-coder yes, decorators do steal your stuff
 
if I say return add()
then it gives error
What is the difference between return add() and return add ?
 
10:39 AM
One returns the result of calling the function; the other returns the function object
waits to be corrected
 
@Rob No, that's correct. It's a matter of why add() gives an error.
@dcoder and for that matter, what specifically is your error?
 
Woohoo
 
@AlexThornton print sim()
TypeError: 'int' object is not callable
 
@dcoder it works fine for me
 
@AlexThornton Change the return addto return add()
 
10:43 AM
Yeah because then you're doing 7()
No you aren't, shut up Rob
 
wheeeee, serial upvote in progress.
It'll all be gone tomorrow.
 
It gives you that error. So I want to know the difference between return add() and return add
@MartijnPieters Could you help me out ?
 
@d-coder I think inner functions have some sort of special identity within a decorator, such that they don't need to be 'called' as such.
 
Now I look at it again and think you are doing 7()
 
@d-coder Your sample code works.
I don't get an error.
@AlexThornton The inner function is returned; it replaces the decorated function.
The @cal syntax is a decorator.
 
10:49 AM
Please try the following code
 
@MartijnPieters change return add to return add()
 
def cal(myfun):
        print myfun
        def add():
                return myfun()+1
        return add()
@cal
def sim():
        return 6

print sim()
 
@MartijnPieters He's asking why he doesn't have to call add with the () syntax within the decorator.
 
@RobertGrant right, I see.
 
the above snippet throws an error
 
10:50 AM
@d-coder welll yes it will... because you're returning 7 - not a callable object
 
WOOHOO
 
@d-coder You are calling the nested function, returning the result.
 
I was right twice in a row. This has never happened before.
 
So you indirectly called sim() in the decorator.
 
@robert ah oh... does that mean the universe has just reset itself?
 
10:51 AM
That returned 7, so now sim = 7 is executed.
 
@JonClements I don't want to answer in case I end my streak
 
Not getting enough close votes on this question: stackoverflow.com/questions/26650830/… possibly the worst I've ever seen.
 
@d-coder: remember that @decorator_expression is just syntactic sugar
Python calls the decorator, passing in the decorated function object
whatever is returned replaces the original function.
 
Wow... that's getting a delete vote when it's closed
 
so you get sim = cal(sim).
 
If you do return add() you return myfunc() + 1, which is sim() + 1 is 7.
 
Okay.
@JonClements I see
 
@Jon closed. Nuke it.
 
Thanks all!
 
Well... I single handedly can't.. but I've put my vote in
 
10:54 AM
grumble if only someone had won the bloody mod elections grumble
 
BTW I should mention that this room is very much lively and inspiring compared to others :)
 
@d-coder Python is a happy language. :)
3
 
If more people had of voted grumble
grumble democracy grumble
 
@Jon I did what I could, it's not easy getting all those sock puppets together to help with election fraud.
 
10:59 AM
next time we go more heavy with the bribery and black mailing, okay!?
 
I'm pretty sure I voted for him at the time purely because he was a Python specialist.
 

« first day (1475 days earlier)      last day (3467 days later) »