F

Fredrik Lundh

effbot.org · Personal blog · on HN since 2007

Fredrik Lundh, a Python developer, wrote tutorials and reference notes on Python internals, parsing, regular expressions and language semantics.

What HN saysHN commenters cite it as a Python reference, for example in explaining why Python requires an explicit self in methods.
64HN people shared it
40linked it in comments
26stories submitted
96story points
4 years agolast shared
2007people per year2026

Most-shared posts

  1. 1
    Simple Top-Down Parsing in Python
    9 people · 35 points · first shared 2008 · 1 comments on HN
  2. 2
    Understanding Python's "with" statement
    8 people · 6 points · first shared 2010 · discussion on HN
  3. 3
    Default Parameter Values in Python
    7 people · 2 points · first shared 2012 · discussion on HN
  4. 4
    Effbot.org on Hiatus
    4 people · 4 points · first shared 2015 · 1 comments on HN
  5. 5
    Call by object
    3 people · first shared 2009
  6. 6
    Compiling Python Code
    2 people · 27 points · first shared 2010 · 7 comments on HN
  7. 7
    Understanding how Python's "for" statement works
    2 people · 5 points · first shared 2010 · discussion on HN
  8. 8
    Using Regular Expressions for Lexical Analysis
    2 people · 3 points · first shared 2008 · discussion on HN
  9. 9
    Simple Iterator-based Parsing in Python
    2 people · 1 points · first shared 2013 · discussion on HN
  10. 10
    Python's free lists
    2 people · 1 points · first shared 2010 · discussion on HN
  11. 11
    Stringlib
    2 people · first shared 2010
  12. 12
    Thread synchronization
    2 people · first shared 2016
  13. 13
  14. 14
    Some Notes on Tim Bray's Wide Finder Benchmark in Python
    1 people · 3 points · first shared 2007 · discussion on HN
  15. 15
    What kinds of global value mutation are thread-safe?
    1 people · 2 points · first shared 2015 · discussion on HN

What HN people wrote when they linked it

zephyrfalcon · 2018-04-22
OK, but in Python this isn't actually true... numbers are not passed any differently than other kinds of objects. As such, it does not have the same semantics as Java, which does distinguish between primitives and non-primitives. Of course, this kind of discussion isn't new to the Python community either. The actual calling convention is somewhere between call by value and call by reference, sometimes called "call by object". This is well worth reading: http://effbot.org/zone/call-by-object.htm
dalke · 2014-07-05
This depends completely on your needle and your haystack. If it's the string "ABC" in "QABC" then certainly the naive algorithm will be the fastest. "Mechanical sympathy" unfortunately is easily misinterpreted to mean to only listen to the machine. Remember though that Martin Thompson is alluding to Jackie Stewart and Formula One racing. All of the cars competed on the same track. But you wouldn't enter a Formula One car for the Baja 1000. In fact, I don't think you should use term unless you have a specific goal in mind. KMP is only best for certain classes of searches. Boyer-Moore is used for others. And there are plenty of other algorithms with there own pros and cons. See http://www-igm.univ-mlv.fr/~lecroq/string/index.html for descriptions. Python, for example, uses (or used?) the algorithm described at http://effbot.org/zone/stringlib.htm , for the reasons listed therein.
inklesspen · 2008-04-08
a) There are excellent reasons why Python requires passing 'self' to each method. The article linked to three of them; I'll just link to one: http://effbot.org/pyfaq/why-must-self-be-used-explicitly-in-method-def… b) form_for(Model.new) is great. That's why I've successfully gotten it added in the next version of Pylons. SQLAlchemy is a zillion times more powerful than ActiveRecord, but if you need hand-holding, you can use an AR-ish layer on top of it, such as Elixir: http://elixir.ematia.de/trac/wiki I've been using Rails for a year and a half, and every time I get a chance to work in Pylons, it's like a breath of fresh air.
kernel_sanders · 2013-03-08
This isn't uncommon in the python community for long running processes - especially those that frequently that create large amounts of small objects. An application server sitting in front of mongodb does exactly this. It forwards queries to mongo, then pymongo json loads the result for you, the application server does what it wants with the objects, then json dumps them to serve to clients. The json loads/dumps calls create tons of objects and memory bloat. The GC cleans them all up, yet memory isn't returned to the OS. See here: http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-de… In my tests of python 2.6.6, 2.7.3, and 3.3, python 2.7.3 was by far the worst in hanging on to memory. Yet the performance increase (due to integration of simplejson) is worth the memory penalty. We use gunicorn with sync workers to serve our WSGI app and a memory watchdog to signal the worker to gracefully retire after it handles a query large enough to leave it with a large memory footprint. Performance has been awesome and we're very happy with the result.
jerf · 2012-08-21
There's always a serialization step. The type of the resulting data is a consequence of the serialization technique, not the data format. I demonstrated the part you seemed to most strongly claim didn't exist, JSON <-> strong typing, but I can show you "weakly-typed" XML too. In addition to the DOM, which is a standardized "weak type" XML representation, you also have things like ElementTree http://effbot.org/zone/element-index.htm . It is the case that JSON has a simple default weak serialization in many popular languages, and that it is a great deal of the reason for its popularity, but it is worth pointing out this is a local effect in the Javascript/Python/Perl/Ruby space, and that it hasn't got anything to do with strongly or weakly typed but rather what the target languages shipped with. There is no natural mapping for JSON in C++, C#, Erlang, Haskell, Prolog, SQL, or a wide variety of other languages (and Erlang and SQL are both fairly "weakly typed"), and even in JS/Python/Perl/Ruby there are some edge cases that can bite you if you aren't careful about exactly what the "just_decode_some_json_man()" is really doing with Unicode and numbers that may not fit into 32 bits. (Also, I scarequote all my "weakly typed" because the term is basically ill-defined. I'm coming around to prefer "sloppy type", which is a language where all values are perfectly well strongly typed but the language and/or library is shot through with automatic coercions and/or extensive duck…
sireat · 2020-11-12
Solve "How to deploy my sweet Python script on grandma's computer" problem. That is some reasonable way to deploy to someone who is not a programmer nor tech person. Not sure how much has changed since this was written: http://effbot.org/pyfaq/can-python-be-compiled-to-machine-code-c-or-so… PyInstaller.. well.. it works okay with std.. sometimes it does not. It is the Electron solution.. add pandas to a project and you get a 600MB install. As developers we can manage to deal with package managers.
kubav · 2020-10-01
To implement scope guard you can use with statement and implement __enter__, __exit__ methods. It is not real RAII as object is not destroyed on exit but it is still quite useful. http://effbot.org/zone/python-with-statement.htm
carapace · 2020-07-03
I once made a simple little GUI generator based on effbot's "Generating Tkinter User Interfaces from XML"[1][2]. I added a tiny parser (written with SPARK[3]) that converted a simple DSL to XML (technically an ElementTree object, the actual XML isn't serialized/emitted at any point) which is then "realized" as a tree of Tkinter widgets with event callbacks. [1] https://www.effbot.org/zone/element-tkinter.htm [2] https://github.com/calroc/pygoo [3] http://pages.cpsc.ucalgary.ca/~aycock/spark/ "Scanning, Parsing, and Rewriting Kit"
fooblitzky · 2019-10-14
It seems if you use '=' it leads to dangerous programming bugs[1], whereas ':=' somehow prevents those bugs? [1] https://effbot.org/pyfaq/why-can-t-i-use-an-assignment-in-an-expressio…
mci · 2019-01-10
Fredrik Lundh describes a DIY patch on top of unicodedata here: http://effbot.org/zone/unicode-convert.htm It solves the ä->ae problem and its ilk for Western European languages. Time has devoured my comment on that post, which extended the transliteration table to Eastern European languages and proposed to use mnemonic names like int(u'\N{Latin capital letter AE}') instead of 0xc6.
mirko22 · 2018-12-18
> 7 (pass by reference) is another totally-wrong one. Yes, specially cos it is not "pass by reference", but "call by sharing" http://www.effbot.org/zone/call-by-object.htm https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing
AdamM12 · 2018-07-06
Isn't Python to C using CPython missing? Edit: Or I guess technically python byte code. [1] [1] http://effbot.org/zone/python-compile.htm
jonbarker · 2017-07-26
Does this not help with handling this issue in python or is this considered a hack? http://effbot.org/zone/thread-synchronization.htm
paulddraper · 2016-10-30
Only one thread runs at a time because of the GIL, but the threads can preempt each other wherever between opcodes (http://effbot.org/zone/thread-synchronization.htm#atomic-operations) Imagine two threads running a += 1 That's four opcodes. Only one operation will run at a time, but one thread might preempt the other midway through the four operations, and `a` will have been incremented by 1, not two. In some sense, mulithreading with Python's GIL is the worst of both worlds: you can use only one CPU, but you still need to account for concurrent state mutation. (Of course, it doesn't have the function color problem of asyncio http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-functi…
enrmarc · 2016-08-24
Why does Python use methods for some functionality (e.g. list.index()) but functions for other (e.g. len(list))? http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functiona… I guess is that.
arnoldschw · 2015-07-06
Blogs/websites in no particular order: * http://blog.codinghorror.com/ (Jeff Atwood) * http://www.catonmat.net/ (Pete Krumins) * http://blog.fogus.me/ (Mike Fogus) * http://research.swtch.com/ (Russ Cox) * http://effbot.org/ (Fred Lundh) * http://adam.herokuapp.com/ (Adam Wiggins) Podcasts in no particular order: * http://www.dotnetrocks.com/ (NET Rocks) * http://herdingcode.com/ (NET focused podcast with Scott Allen, Kevin Dente, Scoot Koon and Jon Galloway) * http://www.coreint.org/ (A podcast about indie software development) * http://www.talkpythontome.com/ (Python podcast) * http://www.binpress.com/blog/category/podcast/ (Binpress podcast about digital products) Magazines in no particular order: * http://www.hackernewsletter.com/ (HN in PDF) * http://www.codemag.com/magazine (Tech/coding news) * http://www.drdobbs.com/ (Dr. Dobbs) and many more.
acjohnson55 · 2013-12-11
Really, using a context manager and the `with` statement is usually the better way to go: http://effbot.org/zone/python-with-statement.htm
brownbat · 2013-07-13
You can use a sentinel if you want to allow None as an argument. More on that, along with a way to use mutable defaults productively: http://effbot.org/zone/default-values.htm
727374 · 2013-07-12
When I learned python I was surprised by the absence of a length() member on collections. But, apparently this was far from an accident. http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functiona…
js2 · 2013-04-12
A nice complement to this article is http://effbot.org/zone/simple-top-down-parsing.htm and its earlier piece http://effbot.org/zone/simple-iterator-parser.htm Also, this page maintains links to many python parsing options - http://nedbatchelder.com/text/python-parsers.html
erikb · 2012-08-31
I think you are looking for the "with" statement! The feature you describe is already there. And it works with objects, so it's reusable, extendable and exchangeable if needed. http://effbot.org/zone/python-with-statement.htm
graue · 2012-07-24
You're missing that if an exception gets thrown, the files are still guaranteed to be closed as soon as you exit that 'with' block. Imagine you open 'infile', but then opening 'outfile' fails. To prevent a resource leak, now you need to close 'infile'. The linked code guarantees this. Likewise if there is any error which aborts the copying, both files will get closed and you don't have to worry so much about corner cases. See this for more: http://effbot.org/zone/python-with-statement.htm
wololo · 2012-06-30
I wish python 3 would make default parameters immutable. It seems to go against the "simple", "explicit" python philosophy, not to mention that (it seems) most people tend to learn about the feature through debugging. description: http://effbot.org/zone/default-values.htm
anthonyb · 2012-05-20
There are a few use cases for default variables on effbot's site: http://effbot.org/zone/default-values.htm Basically, sometimes you do want to reuse the mutable between function calls, and in those cases it can save a fair bit of code passing it in repeatedly.
exim · 2012-05-06
In python, stay away from default arguments for methods/functions. EDIT: yes, mutable default values: http://effbot.org/zone/default-values.htm
shawnps · 2012-04-19
Regarding this one: http://google-styleguide.googlecode.com/svn/trunk/pyguide.html?showone… I commented about this on another post. There's a nice explanation here as to why using mutable objects as default values in function/method definitions is bad: http://effbot.org/zone/default-values.htm In short, it can be bad to set default arguments to mutable objects because the function keeps using the same object in each call.
orangecat · 2011-05-06
Python's "with" statement handles this scenario: http://effbot.org/zone/python-with-statement.htm
jaen · 2010-12-20
You can use ElementTree's iterparse() function (also available for lxml) to do incremental parsing while still having XPath-like functionality available for the elements you like (manually calling the .clear() method to release memory). http://effbot.org/zone/element-iterparse.htm
amccollum · 2010-12-06
Actually, Python does use a Boyer-Moore-Horspool variant internally for substring matching (I'm not sure about Ruby, though). See: http://effbot.org/zone/stringlib.htm Here's a link to the file in the Python SVN repo: http://svn.python.org/view/python/trunk/Objects/stringlib/fastsearch.h…

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close