« first day (1552 days earlier)      last day (3382 days later) » 
00:00 - 16:0016:00 - 00:00

12:02 AM
basically my problem is that select waits for data but I cant add it because select is blocking the run loop. How do I go about this?
 
12:13 AM
@r00m rabbitmq is not thread safe, so you have to make sure only one thread does the connection stuff while another thread does the rest. It's not trivial. I had problems with it recently as well.
You can run a producer on a different process / thread
but don't use the same connection
 
Hmm.. Ok. So for lack of better words I need to implement some kind of messaging mechanism on top of messaging protocol? My objective is to fetch some data from the internet, then publisher sends the data for consumers to process. Now Im thinking that I will run the producer on different thread and share a queue with it, so that my main loop can add items to it and producer thread can pop them and publish for n consumers to consume. Or is perhaps is there a better way to achieve this?
Actually, now that I think about it - do I even need rabbitmq? I could just do this by using processes/threads and notify them about jobs using that queue?
 
12:28 AM
@r00m You don't need to make your own mechanism on top of it, he's saying you need to make sure you have a unique connection per thread
have you looked at celery? It uses rabbitmq as the backend
 
No. This is my first day with python :) I'll have a look at it
 
yeah, use that instead of doing it yourself
 
@ReutSharabani Pycharm is complaining that I'm shadowing names from outer scope when I write a class that uses self in every method definition. How do I get it to calm down?
 
do you have something named self in an outer scope?
 
Well, you're doing something wrong cause it shouldn't happen.
 
12:32 AM
I don't get that warning with the normal inspection profile
 
Or you found a bug in pycharm's static analysis (not likey)...
 
I don't have ANY code in an outer scope. Literally wrote up a dummy class to test the IDE
 
Can you share the dummy class?
 
class Hangman(object):
    def __init__(self, secret_word):
        self.__secret = secret_word
        self.letters_guessed = set()
        self.wrong_guesses_made = 0
 
what line is it complaining on?
 
12:35 AM
oh excuse me, it doesn't complain until I get to a method so...
class Hangman(object):
    def __init__(self, secret_word):
        self.__secret = secret_word
        self.letters_guessed = set()
        self.wrong_guesses_made = 0

        @property
        def masked_word(self):
            return ''.join([L if L in self.letters_guessed else "_" for L in
                            self.__secret])
 
__init__ is a method...
 
complains on def masked_word(self) line
 
Your indentation looks screwy
 
De-dent the prop
 
12:36 AM
is it?
 
LOL
 
Erase erase erase
I never asked this
 
no repro :P
 
12:37 AM
print screen + share on stackoverflow careers.
 
12:49 AM
@davidism Thanks, looks like I'll use celery! :)
 
Well, it's been real, and it's been fun, but I dunno if it's been real fun. #stuffmydadsays #gratuitoushashtags #noteventryingatthispoint #rhubarb
 
rhubarb :P
 
hi, someone there uses netbeans in linux environment?
 
1:24 AM
@Marby this is the Python room, not the right place to ask that question
 
 
1 hour later…
2:44 AM
cbg
 
3:07 AM
1 message moved to recycle bin
brief cbg
 
howdy Jon
 
3:46 AM
When I do: b'abc'[1:] does Python copy bc into another location in memory? Or does Python intelligently point to the corresponding existing memory?
 
3:56 AM
5
Q: Does Python do slice-by-reference on strings?

GuidoMBI want to know if when I do something like a = "This could be a very large string..." b = a[:10] a new string is created or a view/iterator is returned

 
@ZeroPiraeus Thanks!
 
4:15 AM
Well, this doesn't happen very often (to me). Casually reading an answer, and hey look, a link to one of my own :-)
 
While you were looking at it, you could have fixed the improper formatting when the user copied the dunder method name from the docs :) But it's always nice to get attention on old answers
 
I could have, if I weren't dazzled by the fleeting sense of being very, very slightly internet famous ;-) Good catch, though :-)
 
4:44 AM
guys, a design question. how would you test if file is empty or it has just /n or whitespace..first can be solved by os.stat(file).st_size but what would you recommend as efficient way for 2nd part?
 
53
Q: python how to check file empty or not

lakshmipathiI have a text file. How may I check whether the file is empty or not empty?

whoops, missed your edit
 
Thanks Adam. Sorry, i pressed alt+enter for just a /n and it entered everything
 
I mean I GUESS if you're that concerned about that, you could do:
with open('path/to/file.txt') as f:
    data = f.read()
    if not data: # file has whitespace only
 
would that also cover \n? or combination of \n and whitespace?
 
but you'll definitely have to check that your filesize is small first, because file.read pulls the whole file's contents into memory
with an arbitrary file, that could be bad
yes, both " " and "\n" test falsey in Python
 
4:48 AM
awesome
 
You could probably do better than that actually
 
yes.. honestly which is why i pinged here
 
with open('path/to/file.txt') as f:
    isempty = all(not line for line in f)
all will shortcircuit early if any lines have data
 
what is that gonna do?
ahhhh... awesome.
 
the same thing, just linewise instead of filewise
makes sure every line tests falsey
 
4:50 AM
where will you check isempty?
 
wherever you need to know if the file's empty or not
it's a boolean
 
now i understand way it works.. got it
actually still not but i will find out
 
be aware that this requires that you have permission to open the file
 
yes, thanks
 
If you don't, I think it throws an OSError
 
4:51 AM
gotcha
 
but it might be a PermissionError I don't really remember
 
Problems with sign in using openid cannot reproduce according to latest comment from op
 
thats okay. thanks Adam. i will try to figure it out
 
good luck
 
read it in documentation, makes sense... also saw any() there
 
4:53 AM
cbg
 
yeah they're useful functions. I THINK that not any(f) might work there too but I'm not really sure
cbg @AnttiHaapala
 
You need to use strip, because iterating over lines includes the newline:
with open("empty") as f:
    isempty = not any(line.strip() for line in f)
 
Whoa did I totally just fail at Python there? I thought whitespace was falsey
so the trailing newline wouldn't matter
 
>>> bool("\n")
True
 
yeah I just did that. Also bool(" ") == True
@AjGauravdeep I'm awful. Do what Zero says.
:)
 
4:59 AM
So tempted to star that ;-)
 
Adam, its allright
looking at what Zero said
def isFileEmpty(file):
        if os.stat(file).st_size == 0:
                return True
        else:
                with open(file) as f:
                        isempty = all(not line for line in f)
        return isempty
didn't work
 
right, instead do isempty = not any(line.strip() for line in f) or isempty = all(not line.strip() for line in f) whatever reads more clearly to you
they're equivalent
I thought a string of pure whitespace tested as False in Python but apparently I need to go back to Python 101 :)
str.strip in this case will remove all the whitespace from the beginning and the end. If the whole string in whitespace, it will leave an empty string "" which WILL for sure test as False
 
succumbs to temptation
 
this works
Thanks Zero and Adam
understood..
 
@ZeroPiraeus I knew you had it in you
 
5:07 AM
I think the rationale re: falsiness is that it's consistent with other sequence types - only the empty one is falsey.
 
It makes sense. If you're testing for user input, "" means the user entered nothing, but " " means the user entered something. If you were asking the user for something like "What's the delimiter between tokens" that would be very meaningful.
 
i am trying to create a library to parse a file which could be empty at times.
so that something for it
 
Nothing makes me miss python regex like vim regex.
 
5:23 AM
It's backslashariffic ;-)
 
re.sub(r'"([^"]+?)"', r"\1") becomes s/"\([^"]\{-1,\}\)"/\1/
I mean...WHAT?
 
I rather like \_[ CTRL-V, CTRL-M ] for an embedded newline myself.
 
I'm overengineering a Hangman game because I don't have anything better to do at 11:30 at night. I think I've made some poor decisions somewhere.
3
That said, I'd never used Enums until right now!
 
5:43 AM
I like the enum module. You can do some quite elegant stuff with it.
 
That's gorgeous
 
6:01 AM
HI
In python script, if i am want to click enter key from android keypad. Hows its possible?
 
question is not clear @Harry .
 
I am automating android app and in an Editbox, i entered the values using send_keys. Now it doesn't have any button to send the text. The only option is android native keypad's 'enter/send' key. So how to click on it?
 
6:18 AM
?
 
Hooray it's three classes across two files and almost broke 100LOC, but it's done lol
Now the question is: how badly do I need to unit test my overengineered Hangman? :)
 
You mean you didn't write the tests first? I'm shocked – shocked, I say.
 
Well I would have
but I didn't think I'd be as bored as I am.
that was my mistake.
 
6:40 AM
Cabbage
 
Cbg all
 
7:18 AM
Anyone work with django and ubuntu up in dis here chat?
 
Hi, i want to increment the value of 'i' at everytime, following is the code:
i=1
for i in range (5):
element = self.driver.find_element_by_name("Comments...")
element.send_keys(str(i) \n)
but i am getting an error
anyone tell me how to do it?
 
you should give more details!
and make a post about it!
 
"up in dis here chat"?
 
8:02 AM
Cbg
 
@Ffisegydd cabbaggio
 
8:23 AM
Cbg :)
 
8:46 AM
Cabbage!
 
9:00 AM
I must be getting really old. I haven't got a clue as to what "cbg" means.
 
Just got a call from a recruiter. Interesting sounding job but too advanced for me I think :/
 
What about?
As it happens, it will be my first official work day today.
 
@Ffisegydd don't say that :) why too advanced?
You can always say, "I don't think I'm ready for that, but would love the opportunity, so would you consider paying me 75% salary and training me?"
 
Data science position
 
late for work :(
 
9:10 AM
I dunno, just based on the listing, there's only 1 or 2 things I can do, some of the stuff I know of but can't do, and some of it I've never heard the terms before.
 
I think if you want it, then get ready to be uncomfortable and learn fast :) if you're not sure then apply anyway and just chat openly in the interview about your current abilities, as it's all good practice
 
9:25 AM
It's also based in North London, which is quite far away so I'd obviously have to re-locate.
 
But not for the interview :)
 
I'm starting to lose weight, so I'm just prototyping an app out that'll let me enter my weight everyday and then keep track of it. Gonna prototype it in Python then maybe write it up properly in JS so I can use it in the browser.
 
10:05 AM
cbg
 
@Ffisegydd what units will you use? :)
 
@Robert mate I support multiple units :P
class Weight(object):

    def __init__(self, kg, date=None):
        self.kg = Kilogram(kg)

        if date is None:
            self.date = dt.date.today()
        elif isinstance(date, dt.datetime):
            self.date = date.date()
        elif isinstance(date, dt.date):
            self.date = date
        elif isinstance(date, str):
            parse(date)
        else:
            raise TypeError('date argument is invalid.')

    @staticmethod
    def lb_to_kg(lb):
        return lb * 0.453592
 
And now we come to the key component of the system: the ML heuristic that determines based on historic data the likelihood of whether someone accidentally selected the wrong units
Nailed it
 
10:52 AM
I updated my N-in-a-row game yesterday if anyone wants to test it. I tested on windows mac and Ubuntu, but not with the new pre-game configuration frame and features. Is there a way to sudo-apt-get install from pip when installing on ubuntu? (Tkinter si not bundled by default with ubuntu python for some reason).
 
11:03 AM
cbg
@Ffisegydd google docs spreadsheets FTW for that already ;)
 
Pah that's boring though :P
Plus I need some project to work with D3.js on
 
11:40 AM
That sounds like overkill.
 
So? :P
 
d3 does look awesome; I think that's definitely one to invest time in if you understand the domain
 
12:21 PM
If I implement __hash__ in an object and the use it as a key fora dictionary (the object). It's automatically called, right? Also, when two objects end up with the same hash, they override eachother's values in dict[hash(object)]?
 
>>> class Foo:
        def __hash__ (self):
            print('hashed!')
            return 4 # chosen by a fair dice roll

>>> { Foo(): 'bar', Foo(): 'baz' }
hashed!
hashed!
{<__main__.Foo object at 0x000000000378CFD0>: 'baz', <__main__.Foo object at 0x000000000378CEF0>: 'bar'}
TL;DR: No.
 
dict doesn't call hash???
so I have to manually state d[hash(obj1)] = obj1 ?
or am I missing a dunder method to do it for me?
 
It does, but it doesn't call it based on where you want it to be, I think
 
@ReutSharabani See the updated code above :)
 
Or that's my guess, anyway
 
12:24 PM
oh, it probably does a second hash or something after using eq
 
Yeah isn't the hash a bucket, and it'll be inside a list in that bucket?
 
I wonder if it calls eq, i'll test
this means I have to make sure eq works as well
 
The type having a __hash__ implementation is necessary for objects of that type to be hashable. But a hash alone is not enough to decide over object identity. And when you are using an object as a key in a dictionary, object identity still matters.
So they have the same hash—that’s unfortunate for performance reasons but won’t prevent you from using different keys.
 
thanks poke, I understand now. Good implementation :)
so I need __eq__ and __hash__?
 
If you want to specify the same key with multiple objects, yes.
 
12:30 PM
Cool, and one more question: What's a fast way to compare frozensets? I tested == and it seems to work, but Is it working the way I expect? (both frozen sets are identical memberwise)
 
1:03 PM
I don’t think you can compare them other than by content.
 
I seriously thought that it should be marked spam
 
1:15 PM
@Ffisegydd is marching on LinkedIn. :)
 
Hi
all
 
1:17 PM
cbg @ρss
 
cbg @davidism
I have a question if you don't mind regarding python
 
Just ask dude, if someone can answer they will do.
 
only t1 is executing. ?
 
2 messages moved to Trash
please use dpaste.com
 
sorry
 
1:22 PM
No problem :) we just prefer to keep long bits of code (say > 6 lines) in a dpaste.com link or such as it doesn't crowd the chatroom too much.
 
ok I'll try again this code works fine. http://dpaste.com/2KR64GG

But this one doesn't. http://dpaste.com/3EVS5VQ In this one t1 is executing? What am I missing?
I mean only t1 is executing
 
press up to edit posts, rather than posting corrections
 
t1 = Thread(target=myClassA.runA)
t2 = Thread(target=myClassA.runB)
It should be this ^ (no parens)
 
ok please wait
 
yeah, you need to pass a callable, right now you're executing them synchronously as you set up the threads
 
1:28 PM
Is this correct: dpaste.com/07W1SRX ?
 
No, runA and runB are instance methods
 
Yeah.
So how can I execute them in two different threads?
Is it possible`?
 
You could create an actual instance of MyClass, and do Thread(target=myClassInstance.runA), or make runA and runB into static methods. Depends on what the functions actually do.
Ex. staticmethod is preferable if they don't actually use self at any point
 
Thanks. I just found the solution by playing around. :)
yes I need an instance of the class to do so.
 
Btw, consider using thread.join instead of while True: pass if you want to keep the script alive until the threads finish. Or just make them not daemons.
 
1:35 PM
Does anyone else think that LinkedIn's use of SO smacks of desperation?
 
nah, more lazy than desperate
 
@Kevin Thanks. In my actual application. One thread is going to update a list every second. and another thread will read this list and do some other job.
So I guess I keep them running for ever until someone closes the app ? Is it ok
 
I guess so
 
It just seems as though rather than write some howtos for different languages and platforms, they'd rather...not
 
1:56 PM
Thanks :)
 
2:11 PM
should I use @property for getters / functions instancemethods that only use self?
 
I usually don't bother
 
2:36 PM
Quiet today. Almost...too quiet...
 
That's a great time for self advertisement... :)
 
You kids get off my lawn!
@Ffisegydd Loud enough? :)
 
@Roman this is my house and you'll follow my rules! We use = not <- young man!
(I'm actually thinking of applying for a job with a company that uses primarily R, need to step up the learning process)
 
Point of R is that it uses data.frames, which are analogous to tables in excel/calc. Most things regarding statistics and data manipulation revolves around those data.frames. I think pandas tries to implement a similar paradigm in Python.
 
It does yeah.
I know a fair bit about pandas so hoping I won't need to learn as much with R.
 
If you have any questions about R, you can always drop me a line over skype, where my handle is "romunov".
 
@Roman thanks for the offer, I may do. For the moment I'm just learning the basics.
Doing some online courses and such.
 
Aye, that's pretty optimal. The R community has grown since I started (only a few years ago) and it's a bit easier to get some good help thanks to numerous books and tutorials.
 
3:02 PM
Problems with sign in using openid op's comment indicates there's no problem any more
 
I'm gonna have to give up on this user:
That I posted let the idle give us the IndexError, while at the last codeblock we are excepting this happen. — py.codan 55 secs ago
I have no idea anymore where to begin explaining things to him now.
Not when there is such a language barrier.
@davidism I already voted on that one. One more to go, people!
 
yeah, I posted it earlier but it was a little quiet
 
Anyone usin SublimeText ?
 
Yep
 
"How to stop input when programm is running? Ctrl+C, Ctlr+D, Ctrl+Z don't help.."
 
3:06 PM
Sometimes.
 
I have no experience with SublimeRepl though
 
why was your question in quotes?
 
It's quoting the question
1
Q: How to stop input in SublimeREPL python

vvv vvvwhile(True): a = raw_input() print a How to stop input when programm is running? Ctrl+C, Ctlr+D, Ctrl+Z don't help..

 
No clue, I use pycharm if I want to run/debug code
Sublime's just for quick snippets
 
I use Sublime, but not SublimeREPL.
 
3:12 PM
Marty How can you answer to something I've not posted?
I was typin that you had mentioned that you use Sublime (in your interview)
 
If I get accepts on those two Flask questions I just answered, I'll be over 9000! Catching up, @Ffisegydd.
 
D: I took a day or two off and this is what happens!
 
If I get 150 upvotes, I'll be over 9000! xD
D:
 
And 600 upv for me
 
3:27 PM
Phew. FGITW'd 50 rep there. Just need to keep ahead for a little while longer...
 
@BhargavRao you asked who was using Sublime..
24 mins ago, by Bhargav Rao
Anyone usin SublimeText ?
I won't get any more points from upvotes until after 00:00 UTC..
 
Yeah, I had typed half way stating that you had mentioned that you use ST in your interview and you can answer it ... And then I see that your comment props up
@MartijnPieters Anyday in SO, have you got a rep less than 400?
 
@BhargavRao plenty, most days in fact.
I usually do not hit 400.
I'm tempted to make snide comments about WOREST SPELLING here: meta.stackexchange.com/questions/247129/…
 
DSM
Morning cabbage to all!
 
Yay, I can downvote on meta SE
 
3:42 PM
I need to get some meta.se rep so I can downvote. ... That sounds mean.
 
@Ffisegydd Thanks for that comment :) But I would prefer neil's answer, that is cleaner than mine. I think I am the only one who upvoted it :(
 
@MartijnPieters Guess you'll have got legendary some 10 times
 
@MartijnPieters But "I am blowing away now" is a magnificent turn of phrase :-)
 
eval('cbg')
 
DSM
NameError to you too. :-)
 
3:49 PM
 
@BhargavRao the /review audit trail states I earned mortarboard 900 times. That number can be lower than the actual count due to post deletions.
 
Hey what kind of an answer is this stackoverflow.com/a/27966947/4099593
 
Flag it as offensive. It'll soon disappear.
 
whats the opposite of ord?
ahhh tried char
 
chr
 
3:52 PM
chr
 
hehe
 
@Ffisegydd Flag it for mod attention ... And then comment ... It is a d ;)
 
Afternoon guys
 
Because 1334 is not the same as 1344. Look closely. — Martijn Pieters 35 secs ago
That famous robotic wit :P
Sup Intrepid.
 
3:55 PM
Jumping on to steal some advice and then (probably) dashing off again
 
@MartijnPieters Voting to delete also.
 
DSM
Everyone, lock up your advice!
 
I've got a client that keeps making the same mistakes (right hand not knowing what the left hand is doing). Looking for a non-techie way of managing a number of projects
I was thinking Asana, but does anyone know of anything else of giving a general overview of where projects are at?
 
@IntrepidBrit the obvious solution would be to manage less projects and get them completed faster :D
 
closely sounds like an app that close-votes these kind of posts automatically.
 
3:57 PM
For stackoverflow.com/questions/27967476/… I think the OP already has the best way :/
 
... that is the obvious solution to anyone not managing in the company
 
@AnttiHaapala If only! The client is involved in manufacturing. So there's a lot of projects sitting around waiting for folks elsewhere to do things
 
00:00 - 16:0016:00 - 00:00

« first day (1552 days earlier)      last day (3382 days later) »