The Artima Developer Community
Sponsored Link

Python Buzz Forum
py.std

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ian Bicking

Posts: 900
Nickname: ianb
Registered: Apr, 2003

Ian Bicking is a freelance programmer
py.std Posted: Dec 30, 2005 12:33 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Ian Bicking.
Original Post: py.std
Feed Title: Ian Bicking
Feed URL: http://www.ianbicking.org/feeds/atom.xml
Feed Description: Thoughts on Python and Programming.
Latest Python Buzz Posts
Latest Python Buzz Posts by Ian Bicking
Latest Posts From Ian Bicking

Advertisement

So, I was chatting about "helpers" with Ben Bangert on #webware, and thinking about adding stuff to __builtins__, like html_quote and the like. Hey, don't you judge me! Anyway, I think I like string.encode('html') more.

But anyway, I was thinking about how to make this stuff somewhat easier. And I was thinking about a discussion on Py-Dev about adding a dedent method to strings. The rationale was that inline strings that match up with surrounding whitespace need dedenting (ala textwrap.dedent). Why not just use textwrap.dedent? My opinion is that the value is too small for the overhead. And this kind of overhead happens often.

I also think the overhead shouldn't exist. Managing import statements is obnoxious. When they represent real dependencies or namespace operations that's fine -- I'd even say it is good. I like namespaces, really. But managing the imports is annoying.

In this case, I might be 100 lines into a module, and I'm writing a string. If I really want to use textwrap.dedent, I have to go up to the top of the file, add import textwrap and return to my previous location. And, since I know the standard library pretty well now and tend to use it, it is not uncommon for modules to start with 15 lines of imports. That just sucks!

Then I remember about the py-lib which has py.std. Using it I wouldn't have to import textwrap, I'd just use py.std.textwrap.dedent immediately. Does that string seem too long? I don't think so; it's not the length that is bothersome to me (it helps backtracking, and that's good), it's the disturbance of my workflow to add import statements, when I feel like I'm just feeding the compiler. There's good reasons to be explicit, but this is just as explicit as an import (maybe moreso). Unlike an import it is fully localized to the code fragment that uses the module.

Now putting std in __builtins__ is something I could stand behind.

Read: py.std

Topic: Guido to work on PyPy? Previous Topic   Next Topic Topic: simple_json 1.0

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use