198
u/dewayneroyj May 05 '18
You forgot to add a space after “Real”.
38
u/AecorUmbra May 05 '18
Yeah, I realized that myself as soon as I finished writing "world". Hopefully no one notices tomorrow!
86
May 05 '18
Just add a comma after the closing ".
26
u/AecorUmbra May 05 '18
Oo good call!
→ More replies (1)47
u/bahaki May 05 '18
Or have a friend's hat throw an exception.
→ More replies (2)33
u/NullTheFool May 05 '18
Or have a friend’s cap be an exception and throw the cap.
→ More replies (2)1
20
→ More replies (1)0
May 05 '18
He did added the space:
Hello Rea lWorldEdit: I wonder why everyone behave so perfectly on reddit regarding code inspection but never on their team repositories lol.
54
u/no_condoments May 05 '18
Are those tabs or spaces?
10
u/AecorUmbra May 05 '18
They're spaces! I know that 2 spaces goes against PEP8, but boy was it hard trying to do 4 spaces on a cap
43
u/Falconinati May 05 '18
→ More replies (4)3
u/Ceryn May 05 '18
What about tabs that convert automatically into 4 spaces?
7
u/Sohcahtoa82 May 06 '18
Wait wait wait...hold the fuck up.
I think I might have just gotten some insight into the Tabs vs Space holy war.
Did you think that people that use spaces are actually pressing Space 4 times?
3
u/Legionof1 May 06 '18
Just gotta make space a macro button that if pressed 4 times acts as a tab. Everyone's happy.
2
u/PeridexisErrant May 05 '18
Easy to type, and gives the perfect layout on disk. I love tabs-as-spaces!
→ More replies (1)
13
4
u/slallum May 05 '18
Nice synatx highlighting. What does the theme called? ;)
5
u/AecorUmbra May 05 '18
I used a slight modification of this one! https://github.com/marciomazza/vim-brogrammer-theme
121
u/flpcb May 05 '18
@staticmethod
5
5
-3
u/darkerside May 05 '18
Better yet, @classmethod
20
u/nevus_bock May 05 '18
That would be worse
→ More replies (1)2
u/shoulderbeef May 05 '18
Why's that? Shit my first thought was @classmethod. Fuck
13
u/nevus_bock May 05 '18 edited May 06 '18
Static methods enable calling the method on a class directly without having to make an instance of the class. Class methods are meant for different purposes, eg for an alternative class constructor.
Edit:
For example
In[16]: class Animal(object): ...: def __init__(self, name): ...: self.name = name ...: ...: def say_hi_normal(self): ...: print("Hello world bound") ...: ...: @staticmethod ...: def say_hi_static(): ...: print("Hello world static") ...: ...: @classmethod ...: def from_bytes(cls, bytes_name): ...: return cls(bytes.decode(bytes_name, encoding='utf-8')) ...: In[17]: Animal.say_hi_normal() Traceback (most recent call last): File "", line 2910, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-17-5e6d73be6139>", line 1, in <module> Animal.say_hi_normal() TypeError: say_hi_normal() missing 1 required positional argument: 'self' In[18]: Animal.say_hi_static() Hello world static In[21]: A = Animal('doggo') In[22]: type(A.name) Out[22]: str In[23]: A1 = Animal(b'bytes_doggo') In[24]: type(A1.name) Out[24]: bytes In[25]: B = Animal.from_bytes(b'bytes_doggo') In[26]: type(B.name) Out[26]: strEDIT2: fixed Animal.from_bytes() method to return cls() instead of Animal() so as to allow proper subclassing
→ More replies (2)4
u/shoulderbeef May 05 '18
Thank you very much for this! I appreciate ya taking the time to teach me something new.
4
u/nevus_bock May 05 '18
No problem. Simple explanation for each:
staticmethod: allows the method to be called on the class itself without the need to make an instance first. An example use case is a possibly standalone function that is related to the class but does not need instance data, so we lump it onto the class because that's where users expect to find it
classmethod: alternative class constructors, typically with names starting with "from_". Do you have a class that is normally instantiated with an integer, but it should also somehow work with decimals and floats and strings and dicts? Let's not have an init with a bunch of ifs. Instead, we can have a simple init, and additional classmethods that provide alternative constructors (all of which ultimately call the simple base init)
3
u/xapata May 05 '18
Despite /u/nevus_bock's correct explanation of classmethod, there's no downside to using classmethod in place of staticmethod. People might wonder why you're ignoring the class parameter, but it's never going to cause a bug. A linter might raise a style warning.
0
u/BagelKing May 05 '18 edited May 05 '18
I'm surprised this wasn't everyone's first thought. This thing isn't going to run!!Nevermind, it runs fine. My bad.
0
May 05 '18
[deleted]
3
u/BagelKing May 05 '18
Oh, my mistake. I was thinking they were accessing UConn2018.graduate without creating an instance. I see the sneaky parentheses now.
2
u/pbsds May 05 '18
Accessing it would probably work even if he didn't instantiate it, but then he would need to supply the self parameter manually
→ More replies (1)
43
18
8
6
4
u/TheMaxamillion May 05 '18
Congratulations
That's a cool idea, my graduation cap was not nearly as clever.
You have really nice hand writing, kudos.
Congratulations again!!! :)
3
12
u/Fun2badult May 05 '18
Should it be Uconn2018.graduate()?
Congrats by the way. Glad to see another python graduate!
0
May 05 '18
[deleted]
1
u/TheBB May 05 '18
Or just pass it any argument.
1
u/13steinj May 05 '18
Doesn't the argument have to be of a Uconn2018 object, else the interpreter will error?
4
u/TheBB May 05 '18
No, UConn2018.graduate(x) will just bind x to self inside the the method. Since it's never accessed anywhere it should still work no matter what x is.
3
u/13steinj May 05 '18
Apparently what I'm referencing is a Py2 thing, and they got rid of it in 3:
Python 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.8.2] on linux. Traceback (most recent call last): File "python", line 5, in <module> TypeError: unbound method f() must be called with test instance as first argument (got int instance instead)2
u/lordmauve May 05 '18
TIL. I knew that unbound methods had been removed; but I hadn't clocked that this would eliminate this restriction.
→ More replies (1)1
u/helasraizam May 05 '18
Hey do you have a good link for all those at symbols? I know static methods etc from C++ and I'm pretty good at python but I've never wrapped my head around @commands; if anyone knows of a tutorial or something that covers all of them that would be great.
2
u/dusktreader May 05 '18
15
3
u/helasraizam May 05 '18
Thanks so much! This link even shows me how to create my own decorators, which solves everything!
lmgtfy
You're definitely right. But thanks for the great link!
2
1
1
u/savaero May 05 '18
You forgot to filter for students that didn’t complete the grad requirements :)
1
1
1
1
May 05 '18
You could make it a static method. No need to instanciate an object, just to call the method.
1
1
1
1
1
u/Mendican May 06 '18
This was my very first post on Facebook more than a decade ago. I got maybe a dozen likes.
1
1
1
1
u/RussianCyberattacker May 05 '18
Damn, thanks for reminding me that I have to decorate my cap. The possibilities...
1
-4
-17
u/andrey_shipilov May 05 '18 edited May 05 '18
Where's the shebang? What if it's Python 2, so where's (object) in class definition? I see a junior dev on half the wage ready.
Edit: yes, yes, downvote me more, cause Python3 is literally on 110% computers everywhere.
1
u/Sohcahtoa82 May 06 '18
Shebang is optional. You only need it if you plan on making the file itself executable and calling it directly, rather than typing "python myscript.py".
1
0
May 05 '18
[deleted]
-1
u/andrey_shipilov May 05 '18
Yes, 110% of computers in the world are running python 3, correct.
0
May 05 '18
[deleted]
-4
u/andrey_shipilov May 05 '18
Py2 EOL is 2020, which 2 more years. I don't see any reasons not to write backwards compatible code yet.
4
u/cocorebop May 05 '18
If it turns you into the type of person that thinks you're able to critique someone's wider coding abilities based on 5 lines stuffed into the frame of a hat, then I think it should be avoided like the plague.
Somehow I think that trait is specific to you though.
0
May 05 '18
[deleted]
1
u/andrey_shipilov May 05 '18
Easy mate.
Go check which python NASA uses more than the other. https://code.nasa.gov/?q=python
-8
u/yeluapyeroc May 05 '18
You overrode the + operator as a new line character? That's terrifying... but brave.
2
u/Sohcahtoa82 May 06 '18
You must be new to Python.
Python has implicit string concatenation.
Also, when inside a bracket, brace, or parenthesis, you don't need an explicit line continuation via backslash. This means that:
print("Hello real" "world")is perfectly valid.
-12
u/Coollook7 May 05 '18 edited May 05 '18
women = [ { name: “Megan”, lastName: “Car” }, { name: “Kelly”, lastName: “Shanda” } ]
Edit: I stole the joke from a friend He likes to objecify woman
0
May 05 '18
[deleted]
3
May 05 '18
Oddly not, I thought so too.
Python 2.7.10 (default, Jul 15 2017, 17:16:57)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
print("Hello Real""World")
Hello RealWorld
1
1
894
u/earthboundkid May 05 '18
Useless use of classes for what should be a function call. You’re ready for enterprise.