« first day (2473 days earlier)      last day (2475 days later) » 

12:28 AM
long-day-finally-get-to-sitdown cbg
\o/
 
 
2 hours later…
2:43 AM
Maybe this could be a stupid question but I don't understand this:
Why the ternary operator can't be without the else?
A person say me that if you do:
 var = True if A = 5
If A is 5 then var would be True, but, if A is 6 what would be var? Then var would be something undefined and that is an error.
But he also said that the problem could be solved doing that if the condition is false it automatly do: else None.
 var = True if A = 5 else None
Why it doesn't do that?
Also I have an idea:
If you do:
 if A = 5: var = True
If A is 6 it doesn't give an error, simply var is "skipped" and it isn't assigned.
Why don't do the same with the ternary operator?
Also, anyone knows what is sopython.com/spoiler? I found that link in sopython.com/chatroom
 
that's just how it's defined. python.org/dev/peps/pep-0308
 
But your example is invalid Python syntax.
I don't understand this at all
 
i think that middle one was a typo
 
and the sopython.com/spoiler is if you want to talk about something like a TV show or movie that has a spoiler, you write it in that box, and generate a spoiler link, and paste the link here...and indicate it is a spoiler so people don't click on it if they don't want the spoiler
 
What line is wrong? Maybe I commit a mistake
 
2:52 AM
var = True if A = 5 else None
 
>>> A = 5
>>> var = True if A = 5 else None
  File "<stdin>", line 1
    var = True if A = 5 else None
                    ^
SyntaxError: invalid syntax
>>>
 
I think he's just asking why you can't do var = True if A == 5
 
and the answer is "because GVR said so"
 
oh...so he's asking why that is invalid?
 
ups, in your mind change: A = 5 for A == 5
 
2:53 AM
like, you can do if A == 5: var = True or you could do var = True if A == 5 else False or something, or even var = (A == 5)
 
@Marcus But the last one only work for True or False.
 
yes
 
you should also think about the logic of it all as well
 
depending on what A is
 
so let us say you want to do this: var = True if A == 5
great
but, what should var be if A != 5?
 
2:55 AM
A.__eq__
 
you can't do var = True if A == 5 by itself because Python syntax for this example requires you to have an else condition built into it
 
exactly
 
@idjaw nothing? It could don't be defined.
 
But, that in itself also seems a bit wrong. If I know that my variable is going to hold a bool
 
@Marcus I am asking Why it must have an else condition. It can simply don't be defined, no?
 
2:56 AM
or are you asking "why can't they make it so var = True if A == 5 is functionally equivalent to var = True if A == 5 else None?"
 
then I want it to be one or the other right?
 
@EnderLook Yes, the language could have been written a different way than it was written. But it was not.
 
@Hatshepsut I don't know the meaning of that....
 
And yes...the final answer here is because Guido said so
and imho I think it makes it clearer and more intuitive
 
Python does not permit you to write var = 5 if A == 3 without an else part
 
2:57 AM
@idjaw really? This answer... is... quite... dissapointing.
Ok, thanks. It only was curiosity.
 
here read this
 
@EnderLook It's just the way the language is defined, and in this case it makes sense to require an else, since var = True if A == 5 looks a little ambiguous. If A isn't equal to 5, what happens to var? Does it still get assigned something like None, or False, or is the line skipped over?
 
why is it disappointing?
what were you expecting? 😛
 
@idjaw I was thinking in skip the line...
Sprouts.
@idjaw What a coincidence! I make my question after reading that.
 
man headaches are the worst
really puts a kink in any programming or learning you wanted to do
 
3:06 AM
Start popping those advils
 
yeppp
damn it I did it again
yeeeeep
there
 
lol
 
3:59 AM
@Hatshepsut What means typo? ==?
 
 
1 hour later…
5:00 AM
cbg
 
5:42 AM
I see that a lot of people has titles like: "Senior Numerics Developer", "Senior Software Developer at Software Consulting Associates" or "Senior Staff Automation Engineer at infinite.io", can I put me something like "Lord of Time, Senior of Seniors, Supreme Leader of the High Council of Time and Space"? ;). Or that must be something true?
 
6:20 AM
Why do you think it isn't true?!
cbg \o
@EnderLook It's your space, it's about you. You get to decide (unless it's against SO policy, e.g. obscene? etc.)
 
6:48 AM
I am grouping a df by some attributes using df.groupby(['A','B','C','D','E','F']).nth(-1) Now i need it back as csv (with all attributes as were in df). I tried pd.DataFrame(df.groupby(['A','B','C','D','E','F']).nth(-1)).to_csv("myfile") but it removes ABCDEF attributes and gives grouped output
This site is currently in read-only mode; we'll return with full functionality soon. Follow @StackStatus or visit our status blog for more info. SO also has downtime !
 
SO is read only. Guess that means it's time for bed.
 
I got my problem fixed using reset_index() thanks
 
 
1 hour later…
8:03 AM
hi everyone :)
 
user6845426
cbg
 
While working in c# I am now consider making a fine grained -"deepish"- list of namespace. Yet when I was creating those I remembers pep20: "flat is better than nested". So now I'm wondering, what was the rationale for that?
 
Readability / easy understanding? (guessing here)
 
8:19 AM
Thanks for the link, though it's still hard for me to decide; I can't expect others to make the decision on code organization for me.
 
8:53 AM
2017 is so much easier than the previous years... (in terms of plugging in open sourced stuff to make your life easy by not having to implement it on your own)
It's your code, if you think something doesn't look right because of a convention, rethink, if you still think the same, then break the rule?
 
9:47 AM
cbg
 
 
1 hour later…
11:15 AM
cbg
 
11:28 AM
cbg
 
cabbage
 
user6845426
 
Anyone knows how to get specific elements in xml using elementree
As you can see from the pastebin code
I am parsing through sub elements of an xml file
It has 4 tags with the same nam
I just want to select the last one, any idea on how to select?
 
@Anarach perhaps use beautifulsoup?
 
what is that?
 
Looks similar to html parser
 
otherwise, just take the last tag from the for loop :D
i.e. if you move your print outside the for-loop body, it will only print the last tag ;)
 
@AnttiHaapala Lol, nice one I am definately doing that
no time to learn soup and sauce
:-D
weird name though
why would someone name a lib something like that
what does it even mean lol "Beautiful Soup"
 
@Anarach a quick google search might help with that
 
@AndrasDeak Ohhh Alice in Wonderland... not english speaker , didnt know it was an actual thing.. ha ha
 
11:41 AM
me neither, so I googled
 
I just assumed developer was high while naming it :-)
 
these two aren't mutually exclusive possibilities
 
12:27 PM
cbg
 
Challenge: name 3 well-known creative works that are confirmed to have been created under the influence of drugs. Hard mode: nothing from the 70s.
 
just name 3 songs from the 60s?
 
If you like, but I personally don't know any.
 
you might
 
I'm sure I know many songs that were created in the 60s. But I don't know any song that I am completely sure is from the 60s.
 
12:36 PM
beatles?
that's around that time
> The Beatles were an English rock band formed in Liverpool in 1960.
 
@Kevin SELECT * FROM JIMI HENDRIX
 
Ok, that's two. Who wants the final nail?
OK, I'll just go ahead and declare myself the victor if nobody can name a third example in the next minute :-)
... He said, knowing full well that everybody had another eight examples from the 60s lined up, and were merely uninterested in the conversation
 
@Kevin Rolling stones
 
CABBAGGGHH
 
12:50 PM
Anyway I guess my point is: is drug use among creative types common enough that "must've been on drugs" should be the first explanation when we see something unusual? The evidence appears to be: for musicians from forty years ago, yes; for everything else, indeterminate.
 
Damn, I was going to go with baba O'Reilly, but 1971 apparently.
 
(In retrospect case rather than "the 70s" I should have said what I meant: the period of open drug use* that largely overlapped with the hippie cultural movement. Which, now that I look it up, did not fall squarely within the 70s)
 
@Kevin le Tour
 
((*If such a period truly existed: Wikipedia says "The stereotypical belief that in the 1960s, the hippies' heyday, drugs were running rampant and little was done to enforce drug laws, is not supported by the facts; by 1969 only 4% of Americans had tried marijuana."))
 
Also, pretty much everything by the Doors off the first two albums, non?
 
12:53 PM
@Withnail Good One
 
@paul23 ... The bike race?
 
@Kevin yes
 
Ditto Chocolate Watch Band
 
*bicycle a bike is a thing with a motor.
Btw even nowadays nearly each big band the front man used drugs during hteir heyday: nirvana, guns 'n roses, linkin park...
 
Ok, Nirvana. I award you a kewpie doll for giving an example from a time period I was alive for.
 
12:57 PM
Motterley Cruuhhh
 
Drugs for musicians = coffee for programmers
makes sense
one is a casual drink other is crime
 
COFFEE IS NOT A CRIME
 
You drink drugs?
 
Suppin' the dragon. It's all the rage.
 
If you're saying drugs are as common among musicians as coffee is among programmers, I feel like my argument has had the opposite of the intended effect.
 
12:58 PM
Kick back, sup some hand made, artisinal opium.
 
Considering we've only come up with two examples from this century
 
@Kevin Come on , I know a lot of bands in my country which assume that one has to be high inorder to make music
its sort of a social stigma
my personal friends in bands do marijuana
 
oh 90% of the bands I visit that come from the US blatantly state "I love amsterdam, we just smoked some weed during the day"
 
You can't use "I assume these artists are high" as evidence of the correctness of your assumption that most artists are high
 
*from america
 
1:00 PM
@Kevin I get what your are trying to say but that just might be true.. we will never know
 
morning everyone
 
So at least in the alternative rock scene it's common to smoke weed. - But that's nothing special I think.. Didn't count those when you asked for drug usage.
 
Hmm, I think I misread your message. I thought you were saying "One must assume that the bands in my country have to be high in order to make music" but you were saying "the members of bands in my country assume that they must be high in order to make music", which is entirely different.
 
@Kevin did I say anything like that?
 
Clarification: I think I misread Anarach's message.
 
1:03 PM
I think the only person not to have been infulenced by drugs when making music was Kelly Dodson of the 'Bed Intruder' song fame..
@Kevin Yup.. They just watch western musicians and assume one has to do drugs to be creative..
 
I could dig myself a deeper grave and say "I think it's telling that everybody named only musicians and not authors or directors" but I can already come up with examples from those categories without asking (Fear and Loathing in Las Vegas, every stoner comedy ever) so I think I'll just go sulk
 
Shallow graves and deeper graves only matter if you're the undead. For everyone else, the dirt is infinitely thick. Nods sagely
 
It's also pretty logical if you think about it; to be a musical performer one has to have a certain personality.
 
There is a genre in music dedicated to cannabis consumption "https://en.wikipedia.org/wiki/Stoner_rock"
"Black sabbath"
 
1:16 PM
\o cbg
 
oh great, I have to study a 600 page paper "as soon as possible"
goodbye spare time for programming :(
 
I wonder how my playstation is doing right now. On Saturday I dug it out on a whim and started playing Spyro The Dragon. I don't have a working memory card so it's been running continuously for the last 66 hours.
This is the first time I left it alone... Here's hoping it doesn't melt
 
the real roguelike experience
 
Incidentally, how flammable is hardwood?
 
1:26 PM
you needn't worry, I'm sure it's inflammable
 
Whew ;-)
 
@Kevin Original Platstation? woah..
 
@AndrasDeak ok "reader"
 
Thats a relic
 
Late model PS2, but still.
 
1:28 PM
I remember playing a game called pepsi man and Tomb Raider on it
 
I've been meticulously collecting all the gems in every level but I don't think I'm going to 100% the game because a lot of the macguffins can only be acquired by completing aggravating minigames that deviate from the more enjoyable core gameplay
 
@Kevin PS2 was by far the best console ever released just because the sheer number of greatest games ever
 
I've already postponed it by like 2 weeks because it's so condensed and not easily to start with.
 
@paul23 I thought it was an actual paper and my remark was more directed at the authors. Who knows how large review papers can get :P
 
Has anyone played shadow of colosus
 
1:30 PM
I played through half of it, and lost all steam to continue after spending a full hour failing to kill the bull boss
Ironically the smallest of the bosses was the largest obstacle for me
 
I'm told the smaller they are, the realer faeces gets
 
Bull faeces is the realest of all faeces.
 
and we live in the most faeces of all worlds imaginable, yes
 
I'm not totally convinced we aren't in the darkest timeline right now
 
just wait for the retcon
 
1:32 PM
It's why my study focusses so much on "limiting the amount you may write". I'm always jealous when I hear someone make a remark: "I have to write a report with at least 20 pages." That's many times more easy that what we get: "hey write everything you did the last half year in at most 15 pages".
 
perhaps you work too much
 
or he expands too much in his writing
 
Or his font size is too large
 
depending on the specific work you might have to write a lot just to record everything in a scientifically accurate manner
 
1:34 PM
Meh they want us to learn that much of what we do is not important for anyone... And should only be provided as an appendix that can be found somewhere. (Things like measure data and the like).
 
yeah, data is the worst
 
I have hit a point where I am starting to look for a python package for literally everything "The Python Effect"
Too much expectation on python
 
We mostly write reports with the idea that it's either for a scientific journal - or a report that would be send to the one you work for/the company you make your part for.
 
@Kevin I did that once in our analysis class. We were allowed to bring one A4 page's worth of hand-written notes to the mid-terms. I managed to squeeze in every major relevant theorem and definition and had a little space to spare. Then again I'm not sure I used any of it; I was good at math and writing those notes further reinforced my knowledge
 
@FlorianMargaine oh that's so true: even after spending many hours with an english language teacher just condensing everything constantly it's something we (Dutch people) often do, together with making long sentences where a lot is combined in subsentences.
 
1:39 PM
I remember a good number of my math classes having a policy of "If you need a formula for the test, it's going to be printed on the first page of the test itself". I guess the reasoning was, they were testing our ability to apply the knowledge, not our ability to memorize or write really small.
 
that's a really good system
as a physicist what I find important is using the right abstractions and relationships between quantities
 
OTOH every time I have to google the quadratic formula again, I feel a twinge of regret that they didn't force me to memorize it
 
you should be able to derive B from A but if A is a two-line triple integral perhaps your brain capacity is more needed elsewhere
@Kevin just rederive it
that takes longer but it's more fulfilling
 
And sometimes I do, but I don't always have the requisite scratch paper on-hand. For example, while skydiving.
 
@Kevin Well being able to memerize formulas is important in that it provided direct knowledge so you can actually tlak about things without having to google everything.
Like how in aerospace the lift/drag equations are so central the first years just have to memorise it by heart within the first weeks.
 
1:43 PM
Then again I learned the quadratic formula in early elementary school, only as a kid's rhyme because my brother was learning it proper in late elementary school (give or take a few years global shift). So I knew the formula before I knew what it meant, then waited for it to be taught to me later.
 
Mm hmm, some concepts can't be truly grokked until you're well past the point where you can recite them by rote
 
meh
if you're familiar enough, the formulae have meaning and it takes less/a different kind of mental effort to recall it
 
But is that really grokking, then? </noTrueScotsman>
 
for instance, each term of the Navier--Stokes equation has pretty solid meaning behind it, so even though I have no idea about the terms it wouldn't be too hard to know it by heart if I were into hydrodynamics
 
L = 0.5 * rho * cL * V^2 * S (rho = air density, cL = 3d lift constant of wing, V = actual air speed, S = wing surface area)
There now you can work at NASA
 
1:45 PM
@paul23 apart from the 0.5 cL part of that can be filled in based on dimension analysis
 
Oh and for drag: D = 0.5 * rho * cD * V^2 * S
 
stackoverflow.com/q/45268187 typo, import app -> from app import app
 
@AndrasDeak Well yes, but there are many ways to "fill dimensions" so that you get newtons out of it (given above is close to the SI definition of Newtons)
But also for programming you need to have some "basic knowledge" that you don't have to look up to be proficient in a field: if you wish to use python things like the "print" and "zip" function you really should be remember, there's just too little time if you have to look up everything
 
that's just a matter of optimizing your cache
what you use a lot, you'll remember anyway
I haven't been able to get the electron charge and mass out of my head for more than a decade
but the charge I sometimes use to convert between joules and electronvolts
 
@AndrasDeak I have a drink for you... It's called alcohol..
 
1:54 PM
something tells me that isn't very good at precision memory erasure
 
"You can derive that formula from dimension analysis" presupposes that I remember the dimension of things like newtons, which I do not :-)
 
yup, that is necessary
but then comes physics: F=m*a gives you the dimension of Newtons
...assuming you know the SI units of mass and acceleration
perhaps in some "fluid square feet over nautical ounces" unit
the physical relationships still hold so starting from non-SI units you'll end up with consistent non-SI units
 
Unfortunately in America both mass and distance are measured in Statues of Liberty so there is some ambiguity
 
that's just a liberty of units
it checks out
 
There have been attempts to switch to football fields for length, but a yard is too much like a meter, which is too European.
 
1:59 PM
football fields are great because they carry another level of obfuscation
"Football field? You mean 90-120 meters long?"
 
Even ignoring the handegg-soccer binary, it's not clear whether the measurement counts the goalposts and the area where the men with clipboards stand
It's rather like how the length of a foot changes depending on the shoe size of the current monarch
( ;-) )
 
and how gloves all around the country are ritually revoked when a polydactyl heir comes to power
 
Hi there! I'm trying to learn OOP in python and got stuck at a problem with inherited classes... Is it possible to pass a variable from a child-class to the parent-class so that it can be accessed from within the parent class and also from other child classes?
 
Yes, for certain interpretations of all the things you just said.
class Parent:
    def frob(self):
        print(self.foo)

class Child(Parent):
    def troz(self, x):
        self.foo = x

c = Child()
c.foo = 23
c.frob()

#result: 23
Or, hmm, "from other child classes"... One moment.
 
yeah thanks! but that would mean to access a method from the parent class in the child class using a variable saved in a child class. can I also save the variable in the parent class?
like
class Parent():
ehm, guess I need to think through what i wanted to type. I got confused...
 
2:11 PM
There is only one instance, belonging to the child class. Are you talking about class attributes or instance attributes?
 
class Parent:
    static_list_shared_by_everybody = []

class ChildA(Parent):
    def troz(self, x):
        self.static_list_shared_by_everybody.append(23)

class ChildB(Parent):
    def frob(self):
        print(self.static_list_shared_by_everybody)

x = ChildA()
y = ChildB()

x.troz(23)
y.frob()
#result: [23]
 
Suggestion: avoid that.
 
ahhh cool. that s exactly what I was looking for! thanks
ok, why should I avoid that?
 
it's called a class attribute ^
>>> x.static_list_shared_by_everybody is Parent.static_list_shared_by_everybody
True
it's the class that owns the variable, and every instance has access to/can modify it; it's like a global variable attached to the parent class itself (as opposed to an instance)
 
I should probably mention that this doesn't work for immutable objects
class Parent:
    static_list_shared_by_everybody = 42

class ChildA(Parent):
    def troz(self, x):
        self.static_list_shared_by_everybody = x

class ChildB(Parent):
    def frob(self):
        print(self.static_list_shared_by_everybody)

x = ChildA()
y = ChildB()

x.troz(23)
y.frob()
#result: 42
 
2:13 PM
@Kevin well "it works", but it's not what one might expect :P
 
Static fields (or class attributes) easily obfuscate what is happening, making it very hard to track why a some part has values as the way they are. Often causing problems where when making a mvce it suddenly works - but in the grand total it doesn't.
 
Yeah, mutable class attributes should be employed only in rare circumstances. And if you're not sure if your circumstance applies, it probably doesn't.
 
if you're starting with OOP and you feel like the circumstance applies, you just probably have to find the proper pattern for doing what you want, which might or might not involve finding the X to your potential XY problem
 
2:31 PM
hey sorry, my boss just came in. now i m back
 
Cabbage
 
cbg
 
what my work-around was until now: defining a "parent"-class and defining mathods that create "child"-classes within that "parent"-class
 
so that i don't use heritages
and instead use nested classes.
is that a better approach than using class attributes?
 
2:34 PM
Q: What's the favourite fruit of Unix / Linux users? A: Greps.
 
When you say "methods that create child classes", do you mean "methods that create instances of child classes", or "methods that create child classes"? Because that's a very big difference
 
Two goldfish are in a tank. One says to the other: "Are you sure you know how to drive this thing?"
 
class Foo:
    def __init__(self):
        pass
x = Foo()
In this code, x is an instance of the Foo class. x is not a class.
 
eh... ehm... well i guess i mean methods that create instances of child classes
 
2:36 PM
cbg. I'm very confused between the tag count on mobile app and desktop
 
1001 on mobile app
985 on desktop
no notification yet, so I assume the desktop is correct? But then why is the tag count always higher on mobile
(I'm just being a big baby about the gold hammer)
 
@Scotty1- The Python philosophy is that composition is generally better than inheritance, but inheritance is almost always better than nested classes.
 
@davidism <3
 
oh, so just thinking that through... can i create a class outside another class without a heritage and create an instance of that class by using a method inside another class? well, i guess yes, but i can't use methods from both classes inside the created instance, right?
 
2:38 PM
cbg idjaw \o
 
cbg Moo Moo
 
@PM2Ring: Ok thanks. And composition means that i create two classes and create an instance of one of these classes inside another class?
 
class Fred:
    def speak(self):
        print("Yabba dabba doo")

class Barney:
    def __init__(self, friend):
        self.friend = friend
    def troz(self):
        self.friend.speak()

f = Fred()
b = Barney(f)
b.troz()
In this code, each Barney instance can execute both Barney methods and Fred methods (by invoking methods on the self and self.friend objects respectively)
 
oh, boss is back again, brb. and thanks Kevin and all others so far!
 
@Scotty1- That's correct. Eg, you can create an instance of class B inside class A, so the B instance is an attribute of an A instance. Just like you might have an attribute of A that's a built-in type like a string or list. Or you bcan pass an existing intance of B into A, as in Kevin's example.
 
2:42 PM
so self.friend becomes an implied "property" when used in that instance?
 
dammit Kevin, stop sneaking up like that
you need to ease in to it.
 
@Kevin No, it's just a regular attribute.
 
in C# it would be:
public class Barney
{
    private Fred friend;
    public Barney(Fred friend) { this.friend = friend; }
    ...
}
 
Many languages will use "attribute" and "property" to mean the same thing, but in Python they are different
 
Ah, good point, RO Kevin.
 
2:44 PM
Actually I think C# uses the same distinction
 
you can't just do public Barney(Fred friend) { this.friend = friend; } unless you declare a class member, or a property.
 
When I see "property" in a Python context, I assume the person is talking about an @property
It's simpler in Python because we don't have declarations.
 
okok, i guess i m getting the hang of it! thanks!
 
simpler, as in, less readable. lol
 
In Python, we don't declare our variables, because we don't actually have variables. ;)
 
2:46 PM
cbg... thank God for coffee
 
but i still don't get the difference between attributes and properties
 
The name is different.
 
would that be... dynamic typing?
if you don't declare self.friend to be a certain type, then that would be self.friend could be anything, and setting something to self.friend that doesn't have a speak() method would throw a runtime exception, eh?
 
The @property decorator is used to create things that behave like attributes, but which can execute arbitrary code when you read or modify the value. Properties did not occur in this conversation until they were brought up by name in the current tangent.
@Kevin Yep.
 
yeah, Scotty, ignore this property talk I'm speaking of... completely different tangent, I come from .NET world.
 
2:49 PM
okok :)
 
To return to the C# tangent,
public class Foo
{
    public int bar;
    public int qux { get; set;}
}
bar is a field, qux is a property.
 
yep
class member field
or a class field member, haha
 
The Python equivalent* would look like:
class Foo:
    def __init__(self):
        self.bar = 23
        self._qux = None
    @property
    def qux(self):
        return self._qux
    @qux.setter
    def qux(self, value):
        self._qux = qux
(*... But not all concepts translate neatly from one language to the other, of course)
 
but typically, you create public properties with backing fields... public fields are usually bad design I'd say
 
In Python, the opposite is true.
 
2:53 PM
nice
 
Public attributes should be attributes and not properties with a private* backing attribute unless you need the property decorator's special abilities
 
good example
 
(*insofar as Python has a concept of "private" at all, which it pretty much doesn't)
 
in python there is an agreement that private variables (ones that should not be used by external code) start with underscore
if they start with double underscore they get mangled name as well
 
@Kevin why?
 
2:55 PM
Conciseness, primarily. bar was created in one line. qux was created in seven. They both do the same thing.
 
yeah, the same is debated with C#... public props are capitalized, fields are usually start with _, arguments are lowercase
 
@Kevin ah. I guess I've liked to do that purely because it provides me more flexibility in the future (though, often, I don't do the full setter/property thing and just have a function instead)
 
but many don't like the underscore... I do because then you can differentiate fields from arguments, because doing this.friend = friend is just more text to read. and friend = friend is obfuscated.
 
@Kevin, for example
class Test(object):
    def __init__(self):
        self.__t = 2


t = Test()
print t.__t
 
@enderland But if you start with a regular attribute and need to change to a property in the future, you can do it seamlessly without changing the class' public interface, so there's really no point in starting with a property for the purposes of future proofing
 
2:57 PM
this is gonna end up with error
but one could access __t with t._Test__t
 
Yeah. This is why I said Python "pretty much" doesn't have privacy: the safeguards that are in place can be circumvented without too much effort.
 

« first day (2473 days earlier)      last day (2475 days later) »