« first day (961 days earlier)      last day (4002 days later) » 

7:00 PM
@mgilson so most of the time, if you need a singleton instance, you use modules instead of class?
 
@PeterVaro -- I've never actually needed a singleton instance :-P
 
:):):)
 
And it really depends on how "safe" you want your singleton to be
There's a singleton class decorator floating around somewhere which could work.
If you wanted to guarantee that all subclasses of a class are also singletons, you might use a metaclass
But, if you don't want your code to be "hacked" into not being a singleton, and you don't care that it's not able to be subclassed ... Sure, go for a module
 
spooky metaclasses -> those are far-far beyond my knowledge at the moment
 
(I've recently just gotten interested in learning about them)
 
7:02 PM
I watched tons of youtube videoy (pycon, etc) about them
but I dont know why to use them
 
BUT, taking it back to your original question -- If you think you need the global statement, you're probably wrong.
 
@mgilson you're on the verge of taking the red pill, and finding out how deep the rabbit hole goes then? :)
 
@mgilson Yep, now that I understand what this global thingy do, I absolutely agree with you
 
@JonClements -- I'd happily take the red pill if I knew how (or why) I was taking it.
I'd like to know how deep the rabbit hole goes ...
 
@mgilson why is that?
 
7:04 PM
@Kneel-Before-ZOD -- why is what?
 
If you think you need the global statement, you're probably wrong.
 
Counterpoint: globals are awesome, use them all the time. Prove me wrong!!!
 
Because 9 times out of 10, there's a better way to do what you want.
A way which doesn't make your functions have surprising side-effects
 
how about settings that do not change, such as DB access information
 
(8.5 out of those 9 times, the better way is a class)
if it doesn't change, why do you need global at all?
 
7:06 PM
@Kneel-Before-ZOD your functions are going to be more deterministic if you don't use global -- as far as I understand @mgilson 's words
 
you only need the global statement to write to a name in the global namespace. you can read from that name without it.
 
And that means better debugging, optimising etc.
 
@PeterVaro -- Nice explanation.
 
@mgilson oh okay; I was reading it wrong then
I presumed you needed to use that keyword in order to read the content....my bad ;)
 
thanks for the explanation @mgilson , now I can go to watch Jack the giant slayer :):)
 
7:08 PM
@PeterVaro -- No problem
 
does python use a pattern called traits?
 
I suppose I ought to try to get a little more work done. (Writing papers is hard work!)
 
Hey, where did you get that photograph of me?
 
@JonClements does python support the traits pattern?
 
7:11 PM
@Kneel-Before-ZOD there's trait libraries if that's what you're after
@mgilson I'd wave at you, but I figure that'd just freak you out ;)
 
okay; that answers the question then
 
Freaksss us out when peoplesss wavesss -- it doesss
 
SO really needs a way to encourage users to post tracebacks with their questions.
 
does downvoting not count ;-)
 
so many questions get posted without then on the Python tag, and they make answering questions so much easier.
 
7:14 PM
They sure do
And It's really annoying when you ask for one and the user responds in comments:
'It says "IndexError: Value out of range" '
(which was already in the title of their post)
Maybe someone needs to ask a SO question "What is a traceback?"
And then we can give it a really good accepted answer that demonstrates what the traceback looks like and how it's super useful for debugging (and getting questions answered promptly on SO)
And we can point people to that question whenever they don't put a traceback in their question.
Kind of the same way that we point people to "How does accepting an answer work" when they clearly don't know but have expressed that a particular (good) answer solved their problem.
 
Someone can just whack an entry on sopython.com/WhyPostATraceback or something
 
Yeah, that's probably a better place for it. :)
 
(now that one's remembered to update card details cough)
 
7:37 PM
Okay - is anyone going to volunteer to do aforementioned page? :)
 
just done watching the game of thrones s3e9
dear god!
 
@JonClements -- I might get around to it at some point
(though I wouldn't hold my breath on that one either)
 
@mgilson fair enough - was thinking of having a go, but then not sure what I'm doing later - so might not have time either
 
7:53 PM
could anyone look at Emanuel's answer here and help me modify it so it does what it was supposed to do?
My edit shows a full solution, hope it's what you need... — Emmanuel 3 hours ago
 
wow - fantastic 5 minute brain burp
how embarassing
 
8:53 PM
@maxpower what was that question for btw ?
 
@Jon Clements a specific assignment I'm struggling with
 
ahh okies
 
I thought i could do this cool tool for my work but it turned out to be harder than i thought
 
what I meant by the filename order was if they're all continious in the file
ie, 123, 123, 123, 456, 456, 456
or if it's possible it's 123, 456, 123, 456, 456, 123
 
I'm not sure if i understand you correctly
the file names in that example should be 83 154 122
so 3 files in total
as the output
 
8:57 PM
yes, but will they always 83 83 83 83 83 83 83 83 83 154 154 154 154 154 154 122 122 (etc...), or could they be 83 83 83 83 154 154 122 154 154 154 83 83 83 83 122
 
oh right... sorry
yes they are continuos
always
 
howdy all
 
heya @ShotgunNinja
 
by the way the code you posted gives me "deque index out of range"
Hey there
Which i'm trying to figure out what that exactly means
 
oooooooooooooops
pasted wrong version
updated now
 
9:02 PM
@JonClements: you know what I was saying earlier about CheckiO and it being possible to win GitHub accounts but the terms not being very clear?
 
@Cairnarvon yup
 
I just got an email saying I won first prize.
So that answers that, then.
 
83 124 128
154 120 124
122 92 97
is the correct answer, right ?
 
@Jon Clements thank you sir
You've made my day
 
@Cairnarvon and first prize is.... ?
@MaxPower no problem
 
9:07 PM
A coupon for a paid account plan. I think it's the $50 one but details are missing now.
I'm not sure what I'd be doing with fifty private repositories for one month, though.
 
Is it possible to write into a different folder other than the folder where python is located? i.e would this work? fout.write('folder/{} {}')
 
@MaxPower no, that'd just writer folder/ as a literal into the file - change the open to include a filename with a path that exists
with open('my_sub_folder/{}.txt'.format(k), 'w') or similar
 
when ".format(k)" is?
 
k is the name of the file you wish to create
 
right right sorry ^^
though it does only get defined in the for loop
 
9:12 PM
np
 
or "assigned"
 
well - it does have to exist somehow with some name ;)
@Cairnarvon you're a linux wiz?
@Cairnarvon any experience with procmail ?
 
No, I don't.
Email is a tremendous mess and I haven't had cause to untangle it, sorry.
 
Well, I'll go with my gut instinct then... should just work using the | /path/to/script kind of syntax
got some system doing something with emails, and don't have access to the email server logs, so was just going to put a script in a way, that just makes a log to my servers, and passes it on untouched, and then I can compare later using some shite XML RPC thingy to see what happened
 
People keep trying to force XML into Linux and I wish they'd stop.
Freedesktop.org are the worst offenders.
 
9:22 PM
@JonClements should i pass "k" over from another function or possibly assign it as a global variable? or class-scope variable, not sure what it's called...
 
@MaxPower no k is coming from the reading of the file - what are you trying to do ?
@Cairnarvon one company I worked for, told me off for using JSON as it's "too verbose" and I should use "XML"
 
@JonClements with open('final/180x181Result.txt'.format(k), 'w') as fin:
 
@MaxPower err, there's nothing for it to format
what are you trying to do ?
 
i still did not get to the .format idea thing in my learning so i'm shooting in the dark here to be honest
i want to write into a folder called "final" the set of files...
with open('final/[].txt'.format(k), 'w') as fin:
this would format the file name and not the folder path that's what i dont understand
 
that looks better, but it's {} instead of []
 
9:27 PM
yes, sorry
 
print 'my name is {}'.format('max')
see what happens
 
alright
('{}/180x181Result.txt'.format('final'), 'w')
would write '180x181Result.txt' into a folder called 'final'... though it deletes the contents of '180x181Result.txt' and prints IOError: File not open for reading
and writes an empty text file called 'final'
in that folder though so that's a good thing i guess ;)
oh wait
...
i think i got it, sorry for being a pain in the ass...
@JonClements ('{}/'+ k + '.txt'.format('final'), 'w') <- what is the proper way to add "k" in the middle of a string? since it prints back "No such file or directory: '{}/2.txt'" i assume i'm not doing it right
 
9:42 PM
does your folder exist?
 
yes
 
I thought you wanted to create separate files with that folder ?
 
separate files inside that folder
does that make sense?
 
then use 'your_folder/{}.txt'.format(filename) - or as we've called it k ?
 
ohhh right
again, thanks a million
tomorrow i'll be working on putting all of the functions i have by now under one class
Have them call one another
 
9:49 PM
be interesting to see if that's an interesting design choice, but anyway ;)
 
well it's either that or i sit there manually calling each function at a time
at least, i dont know of a better way to do this ;)
 
class methods don't automagically call each other without you telling them how either
 
yes that i know
i did take a java class a year ago and it was mostly theoretic explanations about oop, heirarchy, inheritance, etc...
 
theory and practice are sadly massively difference... but on the plus side, gather some practical experience and it eventually comes together...
 
I sure hope so... but yeah i was going to say that my technical practice side is not that good yet, as you can probably see :P
But that's why i chose to practice on Python since it's somehow more appealing to me
Alright im off. Thanks a lot for all the Asparagus ;)
 
9:58 PM
take care - catch you later
 
Apparently the coupon is valid for a year. And it is indeed the largest plan.
I get $264/month off on a $50/month plan. I'm not sure what that's about.
 
Ahh, so you get paid to use it ?
 
I don't have any bank account details on file, so probably not.
Unless this is how it works.
Oh, that's the wrong GIF. Damn Redditors ruin everything.
 
LOL
mind you - I'm a scrooge - if a supermarket or similar offers "buy one get one free" - I want to try and get a single item half price...
 
11:01 PM
Hello guys ;)
 
howdy Tom
 
@TomCruise hi; is it ur real name?
 
http://stackoverflow.com/questions/16907109/python-list-comprehension-vs-for
I am looking for similar examples when one "Python structure" has better performance than other (even at the cost of illegibility). Do you think of sth ? (it don't have to be related with loops...)
@Tshepang: No, it doesn't :)
 
Using list.sort is faster than writing all of your data to a file, printing that, physically mailing it to a friend in Finland, having him sort it by hand and send it back by carrier pigeon, scanning the letter using OCR, and parsing it back into a list.
This is just one example.
 
11:16 PM
:D
I got question "What has better performance (in above example): for or list comprehensive and why" during job interview, so I suppose, I should know it ;)
but your example is very good... funny, thank you :-)
 
The list comprehension just assembles the list all in one go, without too much fuss or indirection. The alternative first creates a list and then calls a function (in addition to the comparison that the comprehension also does) for every item in the new list, and that function can end up resizing the whole list several times behind the scenes.
Look at the difference between the implementations using the dis module, and then look at what list.append does in detail.
 
In short the underlying implementation of list can have a better stab at optimisation
 
11:32 PM
rhubarb for everyone
~
 
I was going to write up a detailed answer to that part of your question when I saw it earlier, but I'm not feeling great. The second part of your question, though, asking for more examples, is not really very constructive.
Oh, I guess someone else already did now. That's good.
 
ok
thanks ;)
one question: does list comprehensive use a generator ?
 
it utilises an "expression syntax" that can yield either a generator a list - called gen-exps or list-comps
(i for i in blah) is a gen-exp, [i for i in blah] is a list-comp
one is lazy, one gets built
 
OK I am sleeping thanks ;]
good night
 
night
 
11:46 PM
I am from Poland so here is night ;) bye ;)
 
user1786283
Hiya fellas.
 
wb @enginefree
 

« first day (961 days earlier)      last day (4002 days later) »