Re: how to write a unicode string to a file ?

2009-10-16 Thread Niklas Norrthon
st are valuable insights. I have made a > gnote of it! > > \d Here is a link to a page that explains unicode and encodings in a way that made me think I understand some of it: http://www.joelonsoftware.com/articles/Unicode.html /Niklas Norrthon -- http://mail.python.org/mailman/listinfo/python-list

Re: Are min() and max() thread-safe?

2009-09-16 Thread Niklas Norrthon
ndamentally silly by having them walk over the same list > simultaneously? > For one time sequences like files and generators your code is broken for obvious reasons. /Niklas Norrthon -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I format unicode strings?

2009-09-09 Thread Niklas Norrthon
atting style newer then python 2.5? Yes. The new string formatting appeared in python 2.6. Perhaps there is some __future__ stuff you can import to get it to work, don't know. If not you are stuck with the old string formatting until you upgrade to 2.6 or newer: >>> print u'H

Re: simple string question

2009-09-07 Thread Niklas Norrthon
On 8 Sep, 05:39, Steven D'Aprano wrote: > On Mon, 07 Sep 2009 01:54:09 -0700, Niklas Norrthon wrote: > > Others have answered how to replace '\\n' with '\n'. For a more general > > approach which will handle all string escape sequences allowed in

Re: beginner's python help

2009-09-07 Thread Niklas Norrthon
On 6 Sep, 09:00, Maggie wrote: > code practice: > > test = open ("test.txt", "r") > readData = test.readlines() > #set up a sum > sum = 0; > for item in readData: >         sum += int(item) > print sum > > test file looks something like this: > > 34 > 23 > 124 > 432 > 12 > >>> sum(map(int, open('

Re: simple string question

2009-09-07 Thread Niklas Norrthon
ed it in quotes first: >>> unquoted_string = 'hello\\nworld\\x21\\tand\\tgood\\040\\x47ood bye!' >>> print unquoted_string hello\nworld\x21\tAnd\tgood\040\x47ood bye! >>> print eval('str("%s")' % unquoted_string) hello world! And good Good bye! /Niklas Norrthon -- http://mail.python.org/mailman/listinfo/python-list

Re: Can I get a technical explanation on the following error

2009-05-25 Thread Niklas Norrthon
kslash as > its last character. Tried it: >>> r'test \' SyntaxError: EOL while scanning string literal >>> r'test \\' 'test ' Second one is accepted. See the language reference section 2.4.1 as of why; http://www.python.org/doc/current/refere

Re: Why does Python show the whole array?

2009-04-09 Thread Niklas Norrthon
test.find(item) == True: ... > > > would have been better? > > Clearly, any comparison with a boolean literal should be illegal.  ;) > So you think truth_value = True if test.find(item) == truth_value: ... would have been better? :-) (couldn't resist...) /Niklas Norrthon -- http://mail.python.org/mailman/listinfo/python-list

Re: Unix programmers and Idle

2009-03-30 Thread Niklas Norrthon
gging: # debug_whatever.py: import sys sys.argv[1:] = ['arg1', 'arg2', 'arg3'] import whatever whatever.main() /Niklas Norrthon -- http://mail.python.org/mailman/listinfo/python-list

Re: What way is the best to check an empty list?

2009-03-26 Thread Niklas Norrthon
On 26 Mar, 08:18, Niklas Norrthon wrote: > But that can easily be achieved with the "or" operator as Michiel > Overton notes elsewhere in this thread: Michiel Overtoom was what I meant to write. My apologies! > def some_function(arg, coll=None): >     do_stuff(arg) >

Re: What way is the best to check an empty list?

2009-03-26 Thread Niklas Norrthon
for item in coll: do_more(arg, item) But that can easily be achieved with the "or" operator as Michiel Overton notes elsewhere in this thread: def some_function(arg, coll=None): do_stuff(arg) for item in coll or []: # <= Here or is used to make None behave

Re: PythonWin -vs- Idle

2009-02-26 Thread Niklas Norrthon
ocessing.GpDispatch.1') With this little code snippet in a utility module, I can use python 2.6 with ArcGIS, and I can test my scritps with python 2.4, to ensure that they run in ArcGIS 9.2 environments. /Niklas Norrthon -- http://mail.python.org/mailman/listinfo/python-list

Re: can multi-core improve single funciton?

2009-02-10 Thread Niklas Norrthon
n_section ** n / sqrt5 + 0.5) >>> fib(501) 225591516161940121919323945317755919750165306733355143970858461525064153963081278412888159063487104942080L >>> timeit.Timer('fib(501)', 'from __main__ import fib').timeit(1) 1.958083084179e-05 > > Less than a millisecond, versus millions of years for the OP's algorithm. > I know which I would choose. Faster hardware can only go so far in hiding > the effect of poor algorithms. > I agree 100% /Niklas Norrthon -- http://mail.python.org/mailman/listinfo/python-list

Re: urllib.urlopen fails in Emacs

2008-09-26 Thread Niklas Norrthon
help", "copyright", "credits" or "license" for more information. >>> import urllib >>> urllib.urlopen('http://www.google.com/') > >>> /Niklas Norrthon -- http://mail.python.org/mailman/listinfo/python-list

Re: Request Help Debugging Program

2008-07-23 Thread Niklas Norrthon
On 24 Juli, 00:30, Samir <[EMAIL PROTECTED]> wrote: > from math import sqrt > > def findSumOfDivisor(n): [...] >     return sum(divisor)                # return the sum of the > divisors > for i in range(2,10):                  # loop through integers 2 > through 9 [...] >         sum = findSumOfD

Re: concatenate the elements in each list of a list of lists

2008-07-23 Thread Niklas Norrthon
On 23 Juli, 17:33, antar2 <[EMAIL PROTECTED]> wrote: > I already asked a similar question, but encounter problems with > python... > How can I concatenate the elements in each list of a list of lists > > list_of_listsA = > > [['klas*', '*', '*'], > ['mooi*', '*', '*', '*'], > ['arm*', '*', '*(haar)

Re: formatting list -> comma separated (slightly different)

2008-07-21 Thread Niklas Norrthon
On 9 Juli, 22:25, Michiel Overtoom <[EMAIL PROTECTED]> wrote: > Paul & Robert wrote... > > d = ["soep", "reeds", "ook"] > >print ', '.join(d) > > soep, reeds, ook > > I occasionally have a need for printing lists of items too, but in the form: > "Butter, Cheese, Nuts and Bolts".  The last separator

Re: Why does python not have a mechanism for data hiding?

2008-06-10 Thread Niklas Norrthon
On 6 Juni, 03:09, "Russ P." <[EMAIL PROTECTED]> wrote: > On Jun 5, 2:57 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > > > "Russ P." <[EMAIL PROTECTED]> writes: > > > By the way, my recollection is that in C++ access defaults to private > > > if nothing is declared explicity. So normally the "priva

Re: Pythonwin

2008-05-09 Thread Niklas Norrthon
't bother. IDLE is pretty good. Emacs even better (unless you hate emacs). -- Niklas Norrthon ESRI S-GROUP -- http://mail.python.org/mailman/listinfo/python-list

Re: a Haskell a Day

2005-10-27 Thread Niklas Norrthon
rogramming. There is a reason why this is called cross posting. /Niklas Norrthon -- http://mail.python.org/mailman/listinfo/python-list