« first day (2111 days earlier)      last day (3061 days later) » 

00:09
cbg
Question about classes/objects
Suppose my class has a function in it (for the sake of argument, foo() )
Elsewhere, I create an instance of that class, called blah
and I want to pass a number into function foo()
can I do that after instantiating the object blah?
as I understand it currently, no
how is foo defined
yeah, you can
if you define blah inside foo you can
blah.foo(number)?
foo.blah(number)
just make sure that you define def foo(self,number):
00:14
oops
I thought foo was the class
you were right
it's blah.foo(x)
class MyClass:
    def foo(self):
        pass

blah = MyClass()
is that what you have?
I've got a django question
sorry- internet interrupted
yes @idjaw
that's what I currently have
if you try doing blah.foo(4) that will not work then
you will have to change the definition to something like
def foo(self, some_number)
3 mins ago, by Andras Deak
just make sure that you define def foo(self,number):
00:18
^^ that
just sayin':P
sorry-
this is what I currently have
oh hey Andras!
does any of you know django?
class EratoSieve:

    def __init__(self, limit):
        self.limit = limit+1

    def SieveEratList(self):
        numbers = [False]*2+[True]*(self.limit-2)
        result = []
        for index, prime_candidate in enumerate(numbers):
            if prime_candidate:
                result.append(index)
                for x in xrange(index*index, self.limit, index):
                    numbers[x] = False
        return result
00:18
ask the question, and if someone knows they will answer.
I'm thinking of a new feature request for RABBIT.... something with django and a question mark
big_prime = EratoSieve(5)

for i in big_prime.SieveEratList():
    print i
Can I make a double relationship with django models?
now, my question is whether I have to pass in the number 5 when I instantiate big_prime, or if I can do it later (namely, in that for loop)
I have a Post class that can have one and only one Content
00:20
@daOnlyBG well, nothing can stop you from using 5 locally
and the Content can have many Posts
Does that variable get used any other time? Does it make sense to keep it as an instance attribute?
Honestly, I'm just trying to get comfortable with classes and objects, so I guess I have no preference
so it seems that I have a conflict with letting Post have one Content and Content have many Posts
however, I'm wondering why I'd have to make a new object every time I have to pass in a value
00:21
well you need to do what's straightforward for your problem:)
@daOnlyBG ?
sorry? yes?
exactly
because whenever I try to create a new Post I must be add a Content, but whenever I create a new content I must link to a Post
what do you mean by "creating a new object every time you have to pass in a value"?
so what is the correct way to do that double relationship correctly?
00:22
big_prime = EratoSieve(5)

for i in big_prime.SieveEratList():
    print i

#vs

big_prime = EratoSieve()

for i in big_prime.SieveEratList(5):
    print i
both created once ^
OK, I tried doing the latter- and got an error
let me try running it again
because you have to implement your class in a different way:)
the __init__ doesn't expect a second argument, but SieveEratList does
your current implementation has them the other way around
ah
yes, I got this
Traceback (most recent call last):

  File "EratoSieve.py", line 26, in <module>
    big_prime = EratoSieve()
TypeError: __init__() takes exactly 2 arguments (1 given)
and both can work; it's a matter of design
which I believe is what you're referring to
00:24
yes.
so let me try rewriting the class- thanks
no prob
I would probably set the limit as an instance attribute (in __init__) if it's really bound to the object, rather than the function call later
if it's related to the function call, and it can change between calls on the same object, I'd let it pass to the function directly
I apologize, but I'm not sure I follow
You need to determine how you want to use this
is it expected that every time you call your method it should be able to take a different value?
OK, I want to use the class over and over in the same setting to compute numbers
I believe so
00:28
Well, if your number is the color of your gorilla, then you'd say Joe = gorilla(brown), then later Joe.eat_bananas(), If your number is how hungry your gorilla is, then you'd say Joe = gorilla(), then later Joe.eat_bananas(5) because Joe is very hungry
but next time he might be less hungry, so Joe.eat_bananas(2) (without killing Joe in the mean time)
no offense to any possible Joes around
lol, sure
none taken
I don't mean Average Joes;)
Offended
Good.:P
now you can say you're sorry
00:32
sorry....... :(
no worries
ahahah
9 hours ago, by Morgan Thrapp
@BhargavRao Docs are bad. People are mad. Mods are deleting stuff and making us sad.
So, I did this...
Bhargav Tupac Rao
00:36
class EratoSieve:

    #def __init__(self, limit):
    #    self.limit = limit+1

    def SieveEratList(self, limit):
        self.limit = limit+1
        numbers = [False]*2+[True]*(self.limit-2)
        result = []
        for index, prime_candidate in enumerate(numbers):
            if prime_candidate:
                result.append(index)
                for x in xrange(index*index, self.limit, index):
                    numbers[x] = False
        return result


big_prime = EratoSieve()

for i in big_prime.SieveEratList(5):
and __init__ is missing an argument
no, it's not...that's commented code
so...why self.limit? Why not just limit?
Good question. I'm not quite sure why I need the "self" argument.
All the tutorials I've tried reading up online had it
My guess is that it has something to do with accessor methods
when you set self.limit, you set an attribute of the object itself, which you can see whenever you have a hold on self
To be honest, this made a little more sense in Java/C#, haha
in python "self" is just a convention, you could call the first argument of a bound method whatever you like
so consider this:
class foo:
    def set_bar(self,newbar):
        self.bar = newbar
    def print_bar(self):
        print(self.bar)
by setting self.bar you store this information linked to the object itself, as an instance attribute (I hope that's the right name)
00:41
I think it is the right name, yes
so later you can just say myfoo = foo(); myfoo.set_bar(2); myfoo.print_bar()
the printing function sees self because it's bound to the instance called myfoo, and it can access myfoo.bar to print it
okay, this is beginning to make sense
But in your case you have a single method to which you pass limit, which uses it, then throws it away
so you can probably skip the whole instance attribute thingy
right
which maybe it what I want
maybe what I really want is something called a "module"?
i.e., something to access a method from?
?
I don't know what you want, or what a module is in this context:P
and I think you should be careful when defining instance attributes outside __init__, there's this about using properties
00:44
don't over complicate your problem
You seem to want to call your SieveEratList with different values
but this is beyond me
But here is the other question I have now. Why do you have that in a class? Is this part of a bigger chunk of code?
@idjaw That is correct- I want to call SieveEratList with different values
are there other methods in there?
i.e. are you showing just a small piece of your class?
Eventually there will be more methods, yeah.
00:45
ok
But in all honesty, I just want a library of different methods
@idjaw daOnlyBG is learning python via all sorts of prime coding;)
I don't necessarily want to compute various stuff for one single number, so maybe a class isn't necessary in this context
so according to my understanding, some of it is a bit contrived in order to see how it could be done that way
@daOnlyBG you can just define functions. Unlike java, python is happy with free-standing functions
looking at your code as is without thinking of adding any methods you don't need a class at all
however, if this class is going to serve for other similar calculations
then you definitely want to make sure that each method can take a value
00:48
For sure
Also, one thing I noticed you mention...
You should read in to instance vs class attributes/methods
that will explain what "self" actually means
and why you need it
@AndrasDeak When you say "free standing functions," do you mean just a free standing function in a python file, and then just call on that function later from a different file?
@daOnlyBG either that, or just put it in your current file to refer to it directly. If it's in another file, you have to import the other file
@idjaw Thanks. I've been doing a bit of reading lately on this topic but my God everyone thinks so highly of their metaphors lol. I end up getting confused often. But I figure osmosis will eventually drive this into my head
Also, just for completion sake...get in to the habit of sticking with Python's style guide. Typically, classes will take camel case, and methods and variables will take snake case.
00:49
    def SieveEratList(limit):
        limit = limit+1
        numbers = [False]*2+[True]*(limit-2)
        result = []
        for index, prime_candidate in enumerate(numbers):
            if prime_candidate:
                result.append(index)
                for x in xrange(index*index, limit, index):
                    numbers[x] = False
        return result

    for i in big_prime.SieveEratList(5):
        print i
camel case?
CamelCase
ThisIsCamelCase and this_is_snake_case
actually, thisIsCamelCase, but python people don't make the distinction
00:50
actually, I hate to admit this, but I may have been using functions and methods interchangably
I'm sure there's a difference or some sort
not a huge one
I don't want to make definitive statements because I'm unaware of the subtleties
and here is a more python-centric answer that was actually flagged as a dupe of what I just posted, here
Wow, that makes sense
and here is the tutorial on classes that should help you out: docs.python.org/3/tutorial/classes.html
so you have some good reading material there. :)
should help you understand things better to help out with your design dilemma :)
and there's SO Documentation *runs away*
00:53
haha
I saw a link on SO to SOD today
SO documentation is best documentation
(almost-clear self-promotion, mind you)
GENERAL SOD
kneel before SOD
00:54
cbg!
@idjaw Thanks!
cbg
@AndrasDeak I tried running this code but still got an error
not sure about this whole SO documentation thing
did poke's team for documentation get removed?
I don't even see the post about it here anymore
namely,
Traceback (most recent call last):
  File "EratoSieve.py", line 29, in <module>
    for i in big_prime.SieveEratList(5):
TypeError: SieveEratList() takes exactly 1 argument (2 given)
00:59
@idjaw SO employees removed and then went through and removed traces of it too
wow. OK.
@AndrasDeak..?
@daOnlyBG The error is clear, you probably still have something like def SieveEratList(self) and you are calling it with SieveEratList(5)
sorry
should've been for i in SieveEratList(5)...
but it's enough if you ping me once per question
01:05
@AndrasDeak sorry
@JGreenwell rejected, good find
seriously, copy and google search is half of my review process for docs
and I keep finding stuff
LOL - I copied the entire chunk of code and got the relevant SO post
wow
oh and now I noticed your comment :P
yeah, I've learned that comments seem to help stop robo-accepts (or just bad accepts)
it seems like I can accept this though
at what point does the "approve" get blocked?
01:09
he had two (other just changed variable names)
oh I see..I can only improve draft
DSM
DSM
You know how we have some people here who like Salad and some who don't? Is there anyone around here who thinks that Docs is on the right track? As near as I can tell, room sentiment is at best disappointed.
You know, if they explained everything and provided that code and cited the link. It would have been OK. But just dumping it on there
jeez
I was excited, not due to Python but for other subjects which were lacking, has destroyed my hope of it being good (particularly as I did not want another cookbook in those subjects)
@idjaw as that was a college, and publicly posted part of a lecture, a cite might be enough but copyrights can get tricky so I'm not as sure
01:20
rbrb
I'm banging my head against this twisted problem that I just can't seem to make any sense of so far. Mind if I brain dump here see if anyone might have any obvious response? Maybe I was looking at this too long...
go ahead
DSM
DSM
At worst we'll just throw popcorn.
it better be salted
DSM
DSM
You could have "topping", or whatever they call it now.
01:23
haha I call it futter
I have white cheddar popcorn.....will be salty-ish
alright....let's see if I don't botch this explanation up.
see my comment on that one if you want the link to the place it is copied from
and never doubt my Google-Fu
So in my reactor I have hooked a ssh service, and through that service I connect to another thread via a socket (I'm simulating a device that allows remote connections to servers that are connected serially). Now, When I send data in to the socket there is an odd behaviour I'm noticing that whatever stream of data I send, the socket seems to always expect an extra byte to be sent before accepting the next stream of data I want to send
so my unit test looks like this:
def test_disconnecting_from_server_works(self):
    self.client.read('# ')
    self.client.child.send('some_command \n')
    self.client.read('some_command\n')
    self.client.child.send('a')
    self.client.child.send('~.')
    self.client.read('Connection to localhost closed.')
So, the problem is that it will never read "self.client.child.send('~.')"
unless I passed some arbitrary byte of data to it. hence the self.client.child.send('a')
01:30
question is....is there something obvious I'm missing when sending data over my socket where there is this extra byte of data always expected?
Do I need to be more explicit about the stream of data I'm sending with each chunk I'm sending?
I just can't seem to find something obvious in my tracing that just points me to the problem.
DSM
DSM
Can I ask some questions which will quickly reveal my ignorance about socket programming?
Please do. And you will quickly see we probably aren't far part in knowledge :D
DSM
DSM
You're using Python 2? And child is a socket?
cbg all
long time
how's everyone been?
DSM
DSM
Hey, iG! Has it been as hot up the river as down here?
01:40
indeed. Quite warm, and muggy too
today isn't as bad, though
@inspectorG4dget hey!! :)
heya @idjaw!
@DSM Python 2 yes. child is not a socket. It is simply an attribute in my SSH command processor
depending on the command, in the ssh command processor, it could invoke a connection via TCP socket
DSM
DSM
Now all we need are people from Vancouver, Calgary, Edmonton, and Winnipeg, and we've got ourselves a postseason.
sorry, I have not as much experience as some others here with your socket problem
01:42
:) It's all good
I think I'm getting to the point where I should leave this until tomorrow morning and I'll probably figure out what is going on.
oh?! In that case, I could use a hand understanding the roles of iter and __next__ in turning my class into a for elem in myClassInstance compliant iterator
DSM
DSM
See, when I think of sockets, I always think in terms of needing to explicitly handle message sizes myself. My first guess would be that's it's not actually that you need a dummy character, it's that the send forces a flush or something. But now I'm just guessing.
In the morning, all will be clear!
@DSM You're right both about the explicit size/flushing AND morning being clearer
Thanks anyway though :)
I think I'm going to let this one digest until tomorrow.
Twisted can be...twisted :P
DSM
DSM
Oh, you meant Twisted twisted, not just puzzling and loopy.
oh yeah....THE twisted
01:47
a friend of mine has a sister who loves Twisted. I always called her twisted sista
DSM
DSM
Oh, g4dget. How I've missed you. ;-)
I've missed you too, DSM!
Studying for comps is not nearly as fun
I think I'm going to go for a run and just not think about this for a little while. Get a fresh look at it tomorrow.

If you guys aren't around when I come back, rbrb! :)
DSM
DSM
Enjoy the air, idjaw!
run like the wind, idjaw!
DSM
DSM
01:51
My comps weren't so bad. They were scarier in theory than in practice.
everyone tells me that. I'm still sweating
DSM
DSM
Beats overconfidence, I guess, but you can go too far in that direction too. :-)
true enough
would you happen to have any thoughts on that iterator question?
DSM
DSM
Not sure what the question is. :-) You've got your dunder-iter and dunder-next methods working?
I wrote a class Foo and it works. But I don't quite know what roles __next__ and __iter__ do, or rather, how python uses them
DSM
DSM
01:56
Okay, well, __iter__ is just what all iterables have which returns something (possibly itself, possibly something else) which it's going to call __next__ on. Then it calls __next__ on that object until it gets a StopIteration.
oh?! that was way easier than I thought it would be
thank you
DSM
DSM
That's partly why it's so powerful, I think, the specification is really straightforward.
follow up question: is there a "best practices rule" that determines when I should return self within __iter__ and when I should return something else?
DSM
DSM
Hmm. I think it's the same rule as when you'd refactor out iteration logic into an iterator in general -- if the logic is going to be reused among a bunch of classes, but the classes aren't all going to inherit from some common parent who can provide it, then you can return SomeHandyIteratorOver(self) instead.
Jim
Jim
Also, if you need to re-iterate at some later point, it's better to return a custom iterator object instead of returning self from what I know. I asked about this when I saw lists returning <list_iterators> and got the reply from Martijn.
02:00
good point. Thanks
DSM
DSM
That is a good point, which is unsurprising, given the source. ;-)
@Jim I'm reading it now
such. an. on. point. answer
Jim
Jim
@inspectorG4dget Yup, made perfect sense when I read it. By the way, yield might come in handy in the __iter__ if you go with the custom iterator instead of self.
oh yeah! true. Thanks
does anyone know php here?
DSM
DSM
02:04
I remember the dark days before yield from. (shudder)
i know its wrong room but in php there are not that many people
I did some PHP back in the day. SO I'm no expert. I might be able to help with some basic question, though
hey @DSM! (since you missed me so much): What does a drunk almost-lawyer say, at exam time?
DSM
DSM
(gives up) I don't know, G4dget. What does he say?
"I love everybody in this bar... exam"
DSM
DSM
(note to self: find Salad for groan)
02:14
I don't see a squash in there... would that make for a good groan?
DSM
DSM
I can't tell if that's meant to be a grown/groan pun or not.
oh?! I hadn't thought of that. Happy accident!
DSM
DSM
:-P
Well, I've booted into Windows for the first time in a year and a half to upgrade to 10, and it tells me I should reboot. But I've got stuff to do before I go to bed and for that I need nix, so we'll see if I frotz the whole thing by making it wait..
Eastern daylight time rhubarb for all!
I just discovered that I can get the same results as __iter__ and __next__ with __len__ and __getitem__. I still think that refactoring out the iterator logic makes the former method win, though
rhubarb DSM!
 
2 hours later…
04:11
cbg!
Wow ThiefMaster, DSM and Inspectore is still here
Whoaaa Jon is a moderator and Sir Martijn is already at 477k
My God, I've been gone for almost two years.
I'm sure nobody remembers me by now lol
:) Martijn is a moderator too
Oh yeah?
OOH
And here I am feeling like a grain of sand
//disappears into the darkness
05:00
@aIKid -- I know. I spent about 2 years of relative inactivity as well.
Not that I'm really coming out of it now, but ...
I'm trying to not live under a rock quite so much.
05:19
@aIKid cbg
great first message
yes, have no idea why chat is so active and everybody talking bull**** and it's a programming site.
it's actually hilarious.
@MansoorAkram pls read the rules at sopython.com/pages/chatroom :D
sure will do. :)
05:31
@inspectorG4dget this is the conceptual problem with Python iterators.` __iter__` for iterators should return self, unmodified. __iter__ for something else should return the iterator
Do anyone have answer to this question?
-1
Q: Python logic is incorrect or regex is wrong, output unexpected

Mansoor AkramHere is my python code: import re, os from urllib.parse import urlparse, unquote url = "http://www.example.com/dynamic/search.aspx?searchtype=cat&class_id=4520&page=1" path = urlparse(url) lpath = os.path.dirname(path.path) html = u"<a data-fancybox-type=\"iframe\" href=\"../../dynamic/email...

I have also updated the "UPDATE" section.
@MansoorAkram yes,
1326
Q: RegEx match open tags except XHTML self-contained tags

JeffI need to match all of these opening tags: <p> <a href="foo"> But not these: <br /> <hr class="foo" /> I came up with this and wanted to make sure I've got it right. I am only capturing the a-z. <([a-z]+) *[^/]*?> I believe it says: Find a less-than, then Find (and capture) a-z one or ...

Please enlighten me :)
see the first answer
<- applying that to python, use beautifulsoup4
@MansoorAkram As people have mentioned in comment to your question, try using Beautifulsoup instead of regex to parse HTML.
05:41
this is what you're doing at the moment, you're doing it wrong.
Yes i understood that regex is wron way
good
what you're asking is to help people file the end of the hammer so that it'd "do the job"
but until linkList regex it only gets links and not tags.
Okay okay :D
but beautifulsoup is very slow
is it possible that I may do it with lxml?
try with lxml parser
beautifulsoup can use lxml internally
05:47
Actually I am using lxml for 1.5 years.
beginner level.
But beautifulsoup was dropped after 1-2 days for being slow.
Caaaaan I achieve my goal alone with lxml and not beautifulsoup?
did you try beautifulsoup 4 with lxml?
it doesn't use lxml if you do not tell it to use lxml
no, I am resisiting because, I will have to learn bs4 again. :|
and it's difficult as compared to lxml
then by all means use lxml
... beautifulsoup difficult?
it has css selectors ...
05:53
I never had a problem with bs4, wasn't slow at all.
it is very slow because it uses the html parser written in python by default
@AnttiHaapala IS xpath difficult?
@AnttiHaapala If you can confirm that lxml can do all what regex is doing then today I will change the code and post as answer.
?
@MansoorAkram that depends on how complicated your query is :)
There is a strange link in Documentation Conditional List Comprehensions (this is the topic). The link is found in "Live demo" inside that topic. I don't want to disable NoScript to see what that page is. Is the Live Demo link ok?
@MansoorAkram no, lxml cannot parse your html documents incorrectly
so it cannot do everything your code does :D
05:58
@aIKid It's certainly been a while :)
@AnttiHaapala So can you suggest the technique which can be both easy and help me with my end goal?
beautifulsoup4
with lxml html parser
and css selectors
@AnttiHaapala I will give it a try and if I fail, you will most certainly see me again here. :D
nice addition SO.:)
06:27
stackoverflow.com/q/4650818/2301450 old terribly off-topic question which still receives answers
06:38
The rhubarb pie I made yesterday is apparently classified as cake
user image
3
And yes, it is overcooked
I'd eat it.
But I do agree that it looks more like cake...
Yeah kinda looks like a sponge, looks good though.
Bonus for choosing rhubarb instead of cabbage though :)
I'd give you bonus points if you could make a decent tasting cabbage pie ...
@JonClements it was meant to be sweet, it's hard to make cabbage taste sweet, as far as I can tell :P
06:57
Heston Marc Blumenthal, OBE (/ˈbluːmənθɔːl/; born 27 May 1966) is a British celebrity chef. He is the proprietor of The Fat Duck in Bray, Berkshire, one of four restaurants in Great Britain to have three Michelin stars; it was voted No. 1 in The World’s 50 Best Restaurants in 2005. Blumenthal owns the restaurant Dinner in London, which has two Michelin stars, and two pubs in Bray, The Crown at Bray and The Hinds Head, which has one Michelin star. He invented recipes for triple-cooked chips and soft-centred Scotch eggs. He advocates scientific understanding in cooking, for which he has been awarded...
I'm sure ^^^ could magic something horrible up :)
07:43
lol...
the only example of mine that wasn't rejected or criticized in C was the one that didn't compile because that was full of errors.
cbg'all

« first day (2111 days earlier)      last day (3061 days later) »