Tweetovi
- Tweetovi, trenutna stranica.
- Tweetovi i odgovori
- Medijski sadržaj
Blokirali ste korisnika/cu @treyhunner
Jeste li sigurni da želite vidjeti te tweetove? Time nećete deblokirati korisnika/cu @treyhunner
-
Prikvačeni tweet
I run a service called
@PythonMorsels to help professional Python developers get practice with interesting Python features. Short on time but want to level-up your#Python skills every week? Try it out!
The first 4 weeks are completely free. 
https://www.pythonmorsels.com Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
The sorted, min, and max functions all follow this convention of accepting a key function https://trey.io/GAf51c
#PythonHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
Trey Hunner proslijedio/la je Tweet
If you're at all interested in
#Python, thinking about coming to#pycon#pycon2020 ? Today's the last day to request financial assistance. https://us.pycon.org/2020/financial-assistance/ … See art displays & performances, meet people at all programming skill levels, dip your toe into a new project...Prikaži ovu nitHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
An demo
#Python context manager
class Connection:
def __init__(self, yay):
self.yay = yay
def __enter__(self):
print("Opened")
return self
def __exit__(self, *args):
print("Closed")
with Connection("Python!") as c:
print(c.yay)Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
Finally watched
@anthonypjshaw's@pycon talk, "Writing simpler and more maintainable Python" today. Some great visuals and analogies in this talk!
I love the complexity mountain range, the functionality/users table, and the gravity of complexity. 
https://www.youtube.com/watch?v=dqdsNoApJ80 …Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
"We use the same syntax for constructing objects from classes and for calling functions: this fact is the main reason the word "callable" is such an important part of our Python vocabulary." http://trey.io/KByErT
#PythonHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
Two surprises for new Pythonistas: 1. Variables in
#Python don't have types. Objects have types. 2. Variables don't contain objects; variables point to objects. Assignment changes where a variable points. Mutation changes an object. More from@nedbat: https://nedbatchelder.com/text/names.htmlHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
Trey Hunner proslijedio/la je Tweet
Day 35<2020-01-23>
#100DaysOfCode Learnt more about List comprehensions - here's some advice from@treyhunner. List comprehensions are great, but sometimes less readable. Solution: break up a list comprehension over several lines.pic.twitter.com/NGJZapqmfv
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
"You'll also find functions-that-accept-functions in third-party libraries, like in Django, and in numpy." https://trey.io/GAf51c
#PythonHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
Trey Hunner proslijedio/la je Tweet
It does! No variable points to the file object after this line, so the file object is destroyed: text = open("file.txt").read() When a file object is destroyed in
#Python, the file auto-closes. This doesn't close the file: f = open("file.txt") text = http://f.read ()Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
Trey Hunner proslijedio/la je Tweet
An example of carriage returns being stripped (and the last newline being stripped) when using splitlines on a
#Python string: >>> text = "Python\r\nis\r\nlovely!" >>> text.split('\n') ['Python\r', 'is\r', 'lovely!'] >>> text.splitlines() # better ['Python', 'is', 'lovely!']Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
Trey Hunner proslijedio/la je Tweet
I am gonna blog about this but DID YOU KNOW that you can use "&" (and), "|" (or) and "~" (not) for
#DRF permissions? (h/t@webology) permission_classes = [IsSuperUser | IsAdmin]#django https://www.django-rest-framework.org/api-guide/permissions/#setting-the-permission-policy …Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
Need to split up text into lines in
#Python? Use the string splitlines method instead of the split method >>> text = open("file.txt").read() >>> text 'Python\nis\nlovely\n' >>> text.split("\n") ['Python', 'is', 'lovely', ''] >>> text.splitlines() ['Python', 'is', 'lovely']Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
You can do a case insensitive comparison in
#Python by normalizing the case of your strings first: >>> x = "Python" >>> y = "Python" >>> x.lower() == y.lower() True The casefold method normalizes more than lower/upper because it's more unicode-aware: https://docs.python.org/3/library/stdtypes.html#str.casefold …Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
When making a dictionary the last value for a key "wins": >>> items = [('a', 1), ('b', 2), ('a', 3)] >>> dict(items) {'a': 3, 'b': 2} You could make the first values "win", by reversing the iterable before passing it to dict: >>> dict(reversed(items)) {'a': 1, 'b': 2}
#PythonHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
By the way if you want to go the other way and confuse everyone, you could put trailing commas to pack and unpack in all your assignments. >>> x, = 1, >>> (x, y), = (1, 2),
#PythonPrikaži ovu nitHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
Yes you *can* make a single-item tuple without parentheses. It's valid syntax. I say "don't" because it's a readability misunderstanding waiting to happen. These are too similar for my liking: >>> x = 1, >>> x = 1
Prikaži ovu nitHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
"You can pass functions around because in Python, functions are objects." https://trey.io/GAf51c
#PythonHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
It's the comma that makes the tuple in
#Python, not the parentheses. Feel free to leave those off (readability permitting). loc = (3, 4, 5) loc = 3, 4, 5 Except empty tuples are all about parens: stuff = () Also don't make single-item tuples without parens...
nums = 3,Prikaži ovu nitHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
Did you know that you can include __dict__ in __slots__ on
#Python classes? class A: __slots__ = ('x', 'y', '__dict__') This won't make class instances save any memory, but lookups to x and y should be faster >>> a = A() >>> a.x = 2 >>> a.z = 4 >>> a.__dict__ {'z': 4}Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi -
When working with iterators, remember that you can only loop over them one time before they're exhausted. Iterators are single-use iterables.
#Python >>> nums = (n**2 for n in range(100)) >>> max(nums) 9801 >>> min(nums) ValueError: min() arg is an empty sequenceHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.
Curator of
Thought follower