Skip to main content

Mert Nuhoglu's Library tagged python   View Popular

01 Nov 09

Python Encodings and Unicode | One More Blog

  • >>> import codecs
    >>> fh = codecs.open("/tmp/utf-8.txt", "w", "utf-8")
    >>> fh.write(u"\u2013")
    >>> fh.close()
    • Decode First, Encode Last
    • When in doubt, encode as utf-8
    • Use codecs with unicode objects to simplify things
  • 3 more annotations...

Unicode exception in 'paster shell' (repr versus __repr__) - pylons-discuss | Google Groups

  • >> Does anyone have an explanation why foo.__repr__() and repr(foo) makes such
    >> a difference here? Hints welcome.

    > Shouldn't repr return plain string, not unicode one? When calling .__repr__()
    > directly you just call a method directly. When called by repr() some ipython
    > magic happens, which expects __repr__ to return a string.

    Thanks - you saved my day. I'm now using .encode('utf-8') before I return
    the string and now everything works.

Computer Programming for Everybody

  • "What will happen if users can program
    their own computer?"
  • We compare mass ability to read and write software with mass literac
  • 7 more annotations...
07 Sep 09

Let's talk about WSGI

    • As an interface for Python applications to speak HTTP, WSGI leaves quite a lot to be desired.

    • As an interface for Python web developers to implement and work with, WSGI is antiquated and frustrating.

    • As an interface for composing useful functionality from the various Python web components, WSGI is far from sufficient.
  • 4 more annotations...
28 Aug 09

Introduction to Python/Django testing: Basic Doctests | Surfing in Kansas

  • You can go ahead and put that in a file in your tests/ directory, I named it doctst.py
  • run ./manage.py test APPNAME
  • 2 more annotations...

Introduction to Python/Django testing: Basic Unit Tests | Surfing in Kansas

  • you should have a basic tests directory, with an __init__.py and a doctst.py file inside of it.
  • import unittest

    class TestBasic(unittest.TestCase):
    "Basic tests"

    def test_basic(self):
    a = 1
    self.assertEqual(1, a)
  • 5 more annotations...

DynamicWare: Introduction to Python/Django testing: Doctests

  • You need to go into your init.py file and put some stuff in there.

    import doctst
    __test__ = {
    'Doctest': doctst
    }

    You are importing the doc test module and then adding it to the __test__ dictionary. You have to do this because of the way that python handles looking for doc tests. It looks for a __test__ dictionary inside of your module, and if that exists it looks through it, executing all docstrings as doctests.

26 Aug 09

The Python Property Builtin

  • something = property(something)
    • @property
    • def something(self):
  • 1 more annotations...
13 Aug 09

Django | 2. Adding __str__() or __unicode__() to models | Django Documentation

  • def __str__(self):
    # Caution: this is only safe if you are certain that headline will be
    # in ASCII.
    return self.headline
  • def __unicode__(self):
    return self.headline

Does __str__() call decode() method behind scenes? - Stack Overflow

  • Basically, __str__ can only output ascii strings. Since t2 contains unicode codepoints above ascii, it cannot be represented with just a string.
  • when dealing with django applications, you should use __unicode__ for everything, and never touch __str__.
12 Aug 09

Python Unicode Objects

  • Best article I have ever read about unicode in python. - mertnuhoglu on 2009-08-12
  • each distinct character has its own
    number, the code point.
  • Unicode characters don’t have an encoding; each character
    is represented by its code
  • 14 more annotations...
10 Aug 09

How to Use UTF-8 with Python

  • byte strings and Unicode strings
  • Python uses your computer's default locale to convert the bytes into characters.
  • 7 more annotations...
1 - 20 of 37 Next ›
Showing 20 items per page

Diigo is about better ways to research, share and collaborate on information. Learn more »

Join Diigo