SV: Conventions for dummy name

2008-01-10 Thread David.Reksten
Torsten Bronger wrote:
>Hallöchen!
>
>Ben Finney writes:
>
>> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
>>
>>> The underscore is used as "discarded" identifier. So maybe
>>> 
>>> for _ in xrange(10):
>>> ...
>>
>> The problem with the '_' name is that it is already well-known and
>> long-used existing convention for an entirely unrelated purpose:
>> in the 'gettext' i18n library, the '_' function to get the
>> locally-translated version of a text string.
>
>Right, that's because I've used "__" where not all returning values
>are interesing to me such as
>
>a, b, __ = function_that_returns_three_values(x, y)

Variable name "dummy" serves the same purpose, such as:

a, b, dummy = function_that_returns_three_values(x, y)

According to http://linux.die.net/man/1/pylint it is also possible to use the
option

--dummy-variables-rgx=

to further specify which variable not to report as unused. As far as I can
tell, it defaults to '_|dummy'.

.david
-- 
http://mail.python.org/mailman/listinfo/python-list


SV: Conventions for dummy name

2008-01-10 Thread David.Reksten
Torsten Bronger writes:
>[EMAIL PROTECTED] writes:
>
>> Torsten Bronger wrote:
>>
>>> [...]
>>>
>>> Right, that's because I've used "__" where not all returning
>>> values are interesing to me such as
>>>
>>> a, b, __ = function_that_returns_three_values(x, y)
>>
>> Variable name "dummy" serves the same purpose, such as:
>>
>> a, b, dummy = function_that_returns_three_values(x, y)
>
>Granted, but my rationale is that "__" is less visible in the source
>code, so there is more emphasis on the actually interesting
>variables.

I guess it's a matter of preference. Personally, I find "dummy" to be more
explicit, and hence more readable for those that that will read my code
later. YMMV.

Regards,
.david
-- 
http://mail.python.org/mailman/listinfo/python-list


Unicode literals to latin-1

2008-01-30 Thread David.Reksten
How can I convert a string read from a database containing unicode literals, 
such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?

I have tried variations around
  "Fr\u00f8ya".decode('latin-1')
but to no avail.

.david
-- 
http://mail.python.org/mailman/listinfo/python-list


SV: Unicode literals to latin-1

2008-01-30 Thread David.Reksten
On 30. januar 2008 10:21, Berteun Damman wrote:
>On Wed, 30 Jan 2008 09:57:55 +0100, <[EMAIL PROTECTED]>
><[EMAIL PROTECTED]> wrote:
>> How can I convert a string read from a database containing unicode
>> literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?
>>
>> I have tried variations around
>>   "Fr\u00f8ya".decode('latin-1')
>> but to no avail.
>
>Assuming you use Unicode-strings, the following should work:
>  u"Fr\u00f8ya".encode('latin-1')

I'm afraid that the string read from the database is a non-unicode string, thus 
me not using u"..." above. But it may contain unicode literals from the 
(Python-based) system that populated the table, and I'd like to get them back 
to proper unicode strings again, so that I can display them correctly to the 
user.

>That is, for some string s, s.decode('encoding') converts the
>non-unicode string s with encoding to a unicode string u. Whereas
>for some unicode string u, u.encode('encoding') converts the unicode
>string u into a non-unicode string with the specified encoding.
>
>You can use s.encode() on a non-unicode string, but it will first try to
>decode it (which might give an DecodeError if there are non-ASCII
>characters present) and it will then encode it.

Any suggestions on how that would look, given the example above?

.david
-- 
http://mail.python.org/mailman/listinfo/python-list

SV: Unicode literals to latin-1

2008-01-30 Thread David.Reksten
On 30. januar 2008 10:48, Marc 'BlackJack' Rintsch wrote:
>On Wed, 30 Jan 2008 09:57:55 +0100, David.Reksten wrote:
>
>> How can I convert a string read from a database containing unicode
>> literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?
>>
>> I have tried variations around
>>   "Fr\u00f8ya".decode('latin-1')
>> but to no avail.
>
>In [388]: 'Fr\u00f8ya'.decode('unicode-escape')
>Out[388]: u'Fr\xf8ya'
>
>In [389]: print 'Fr\u00f8ya'.decode('unicode-escape')
>Frøya

'unicode-escape' did the trick! Thank you!

.david
-- 
http://mail.python.org/mailman/listinfo/python-list


SV: Unicode literals to latin-1

2008-01-30 Thread David.Reksten
On 30. januar 2008 14:31, Gabriel Genellina wrote:
>On 30 ene, 07:54, <[EMAIL PROTECTED]> wrote:
>> On 30. januar 2008 10:48, Marc 'BlackJack' Rintsch wrote:
>>
>> >On Wed, 30 Jan 2008 09:57:55 +0100, David.Reksten wrote:
>>
>> >> How can I convert a string read from a database containing unicode
>> >> literals, such as "Fr\u00f8ya" to the latin-1 equivalent, "Frøya"?
>
>> >In [388]: 'Fr\u00f8ya'.decode('unicode-escape')
>> >Out[388]: u'Fr\xf8ya'
>>
>> 'unicode-escape' did the trick! Thank you!
>
>A unicode-escaped string looks very strange in a database... I'd
>revise the way things are stored and retrieved.

I agree. I'm currently using the trick above to fix it.

.david
-- 
http://mail.python.org/mailman/listinfo/python-list