Re: (Very Newbie) Problems defining a variable

2008-12-12 Thread Marc 'BlackJack' Rintsch
you use to look at the text how many spaces will be displayed. Better use four real spaces to indent one level so it looks the same everywhere. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: var or inout parm?

2008-12-12 Thread Marc 'BlackJack' Rintsch
def f(a, x): .: a += x .: In [253]: dis.dis(f) 2 0 LOAD_FAST0 (a) 3 LOAD_FAST 1 (x) 6 INPLACE_ADD 7 STORE_FAST 0 (a) 10 LOAD_CONST 0 (None) 13 RETURN_VALUE Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Removing None objects from a sequence

2008-12-12 Thread Marc 'BlackJack' Rintsch
uch an error in a post, I suggest to practice some time > writing correct code before having one-liner contests with your > perl-loving friends :) If you call something an error, make sure it really is one. :-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: var or inout parm?

2008-12-12 Thread Marc 'BlackJack' Rintsch
e that may or may not raise that exception, depending on implementation details: t = (1, 2) t[0] = 1 # Maybe okay -- maybe not. t[1] += 0 # Same here. I'd find that quite odd. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: var or inout parm?

2008-12-13 Thread Marc 'BlackJack' Rintsch
cts? I use it very often with number types and sometimes with tuples, and there rebinding is necessary. If I couldn't use it in this way: ``x = 0; x += z``, I'd call that a bad design decision. It would be a quite useless operator then. Ciao, Marc 'BlackJack' Rintsc

Re: Umlauts in idle

2008-12-13 Thread Marc 'BlackJack' Rintsch
but let the interpreter show the result you get the `repr()` form of that character displayed, which always uses escapes for bytes that are non-printable or not within the ASCII range for strings. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Optimizing methods away or not?

2008-12-14 Thread Marc 'BlackJack' Rintsch
t do others think? > Which do you consider better design? None of it. Why not simply: class Parrot: def __init__(self, *args): print "Initialising instance..." assert self.verify() def _verify(self): print "Verifying..." return None If you compile with -O the ``assert`` is optimized away. But you still can call `_verify()` at specific points even in optimized code if you want or need. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Optimizing methods away or not?

2008-12-14 Thread Marc 'BlackJack' Rintsch
On Sun, 14 Dec 2008 09:19:45 +, Marc 'BlackJack' Rintsch wrote: > class Parrot: > def __init__(self, *args): > print "Initialising instance..." > assert self.verify() Here I meant ``assert self._verify()`` of course. > def _verif

Re: the official way of printing unicode strings

2008-12-14 Thread Marc 'BlackJack' Rintsch
t is the official, recommended Python way? I'd make that first line: sys.stdout = codecs.getwriter('utf-8')(sys.stdout) Why is it even more cumbersome to execute that line *once* instead encoding at every ``print`` statement? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I return a non-zero status result from a python script?

2008-12-15 Thread Marc 'BlackJack' Rintsch
On Mon, 15 Dec 2008 13:12:08 -0800, silverburgh.me...@gmail.com wrote: > How can I return a non-zero status result from the script? Just do a > return 1? at the end? ``sys.exit(42)`` Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Structure using whitespace vs logical whitespace

2008-12-15 Thread Marc 'BlackJack' Rintsch
ent. No the program flow there is just some linear calls to methods. It's the XML structure that is not reflected by the indentation, the program flow is represented just fine here. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: How to parsing a sequence of integers

2008-12-19 Thread Marc 'BlackJack' Rintsch
max/min, is there something like average()? No, but it's easy to implement with `sum()`, `len()` and ``/``. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: encoding problem

2008-12-19 Thread Marc 'BlackJack' Rintsch
g- ASCII to decode the > utf8 encoded string literal, and thus generates the error. > > The question is why the Python interpreter use the default encoding > instead of "utf-8", which I explicitly declared in the source. Because the declaration is only for decoding unic

Re: List comprehension in if clause of another list comprehension

2008-12-19 Thread Marc 'BlackJack' Rintsch
On Fri, 19 Dec 2008 04:26:16 -0800, bearophileHUGS wrote: > Peter Otten: >> The problem is that list comprehensions do not introduce a new >> namespace. > > I think Python3 fixes this bug. Or removes that feature. ;-) -- http://mail.python.org/mailman/listinfo/python-list

Re: New Python 3.0 string formatting - really necessary?

2008-12-19 Thread Marc 'BlackJack' Rintsch
ogramming for this > student. Lets not forget how important C is! To a Python "n00b"? Not important at all. Beside the point that '%s' is still possible -- someone who knows C but struggles with replacing '%s' by '{0}' has far greater problems. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: encoding problem

2008-12-19 Thread Marc 'BlackJack' Rintsch
On Fri, 19 Dec 2008 08:20:07 -0700, Joe Strout wrote: > Marc 'BlackJack' Rintsch wrote: > >>> The question is why the Python interpreter use the default encoding >>> instead of "utf-8", which I explicitly declared in the source. >> >&

Re: encoding problem

2008-12-19 Thread Marc 'BlackJack' Rintsch
On Fri, 19 Dec 2008 15:20:08 -0700, Joe Strout wrote: > Marc 'BlackJack' Rintsch wrote: > >>> And because strings in Python, unlike in (say) REALbasic, do not know >>> their encoding -- they're just a string of bytes. If they were a >>> string of

Re: New Python 3.0 string formatting - really necessary?

2008-12-20 Thread Marc 'BlackJack' Rintsch
On Fri, 19 Dec 2008 17:12:00 -0800, r wrote: > Marc, > Why move away from a concise and widely accepted way of sting > formatting, just to supposedly make it a little easier for n00bs? (which > i disagree this is easier) In turn, creating more syntactical clutter. > (%s %f %d) is

Re: encoding problem

2008-12-20 Thread Marc 'BlackJack' Rintsch
On Fri, 19 Dec 2008 16:50:39 -0700, Joe Strout wrote: > Marc 'BlackJack' Rintsch wrote: > >>>> And does REALbasic really use byte strings plus an encoding!? >>> You betcha! Works like a dream. >> >> IMHO a strange design decision. > > I

Re: New Python 3.0 string formatting - really necessary?

2008-12-21 Thread Marc 'BlackJack' Rintsch
the language whereas my ideas for "fixes" of the quirks wouldn't. "joe-python" most often doesn't see the whole picture and demands changes that look easy at first sight, but are hard to implement right and efficient or just shifts the problem somewhere else where

Re: New Python 3.0 string formatting - really necessary?

2008-12-21 Thread Marc 'BlackJack' Rintsch
lems. And even if nobody has problems with the limitations of ``%`` string formatting why shouldn't they add a more flexible and powerful way!? Python 3.0 is not a bug fix release. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Python is slow

2008-12-21 Thread Marc 'BlackJack' Rintsch
ou are not fast enough to elaborate on Python's slowness!? :-) cm_gui is slow! Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: New Python 3.0 string formatting - really necessary?

2008-12-21 Thread Marc 'BlackJack' Rintsch
mpile time and ``a % b`` returns an object of ``type(a)``. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: New Python 3.0 string formatting - really necessary?

2008-12-21 Thread Marc 'BlackJack' Rintsch
On Sun, 21 Dec 2008 15:30:34 +, Duncan Booth wrote: > Marc 'BlackJack' Rintsch wrote: > >>> a+b+c+d might execute a.__add__(b,c,d) allowing more efficient string >>> concatenations or matrix operations, and a%b%c%d might execute as >>> a.__mod__(b

Re: Strategy for determing difference between 2 very large dictionaries

2008-12-24 Thread Marc 'BlackJack' Rintsch
btle point here :) `keys()` creates a list in memory, `iterkeys()` does not. With ``set(dict.keys())`` there is a point in time where the dictionary, the list, and the set co-exist in memory. With ``set(dict.iterkeys())`` only the set and the dictionary exist in memory. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Memory leak problem (while using tkinter)

2008-12-31 Thread Marc 'BlackJack' Rintsch
lest possible program that still has the problem. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Videocapture in python

2009-01-01 Thread Marc 'BlackJack' Rintsch
On Thu, 01 Jan 2009 04:28:21 -0800, koranthala wrote: > Please let me know if you need any more information. Where does `videocapture.py` coming from? It's not part of the standard library. And which operating system are we talking about? Ciao, Marc 'BlackJack

Re: Why not Ruby?

2009-01-03 Thread Marc 'BlackJack' Rintsch
cff5937?hl=en&q=recycle+bin#97254d877903bbd No you didn't "got" Steven, as unnecessary cross posting is something different than answering a question that should have been a new thread start. Oh, and: *plonk* for your childish annoying behaviour… Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: why cannot assign to function call

2009-01-03 Thread Marc 'BlackJack' Rintsch
are likely to have been exposed to is simple > and sensible. I think the "bin model" is more complex because you don't just have a name and an object but always that indirection of the "bin". Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Returning a string

2009-01-03 Thread Marc 'BlackJack' Rintsch
004 >> > Out[19]: u'004' >> >> What? > > That's the output got from ipython. As you can see, it prints > 'Afghanistan' but it can not returns it. In change, the another strings > are returned. Maybe you should show the *input* too… Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Take the first n items of an iterator

2009-01-04 Thread Marc 'BlackJack' Rintsch
On Sun, 04 Jan 2009 10:55:17 +, Steven D'Aprano wrote: > I thought there was an iterator in itertools for taking the first n > items of an iterator, then halting, but I can't find it. Did I imagine > such a tool, or am I missing something? `itertools.islice()` Ciao,

Re: why cannot assign to function call

2009-01-05 Thread Marc 'BlackJack' Rintsch
On Sun, 04 Jan 2009 20:03:11 -0600, Derek Martin wrote: > On Sat, Jan 03, 2009 at 10:15:51AM +0000, Marc 'BlackJack' Rintsch > wrote: >> On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote: >> >> What's the difference between Python and Java or

Re: why cannot assign to function call

2009-01-05 Thread Marc 'BlackJack' Rintsch
let`` is optional in Commodore BASIC. But where is the difference to x = 10 print x ? Wouldn't you have guessed what this Python program will do just the same? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter - problem closing window

2009-01-06 Thread Marc 'BlackJack' Rintsch
6raiz = Tk() The problem is here… > 27F = Frame(raiz) > 28F.pack() > 29hello = Label(F, text=resultado) 30hello.pack() > 31F.mainloop() …and here. There is only one `Tk` instance and mainloop allowed per `Tkinter` application. Otherwise really strange thi

Re: why cannot assign to function call

2009-01-07 Thread Marc 'BlackJack' Rintsch
Using reference counting for memory management is an implementation detail. It's possible to use other garbage collectors without the need of reference counting. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: del behavior 2

2009-01-07 Thread Marc 'BlackJack' Rintsch
which I have had happen. So if python does not get a chance to take > care of those, what is a good way to do so? Does a try/finally or a > with statement address that? Thanks! If you clean up the mess in the ``finally`` branch: yes. + raises a `KeyboardInterrupt`. Ciao, Marc

Re: An idea of how to identify Israeli owned software companies

2009-01-07 Thread Marc 'BlackJack' Rintsch
o those who >> want to support Israeli companies. > > Something like that web-service that publishes the names and addresses > of doctors who perform abortions so that they can be assassinated? Hey, it's about boycott, not killing them. Applied to the doctors example:

Re: "python -3" not working as expected

2009-01-08 Thread Marc 'BlackJack' Rintsch
t;. > > Unfortunately I saw no warnings about print becoming a function in > Python 3 ("print()"). Where is the problem? There is no problem. ``print``\s are handled fine by the 2to3.py script. The option warns about stuff that is not easily automatically converted. C

Re: Implementing file reading in C/Python

2009-01-09 Thread Marc 'BlackJack' Rintsch
pixels += 1 > if (havepixels % 1024) == 0: > print("Progresss %s: %.1f%%" % (sys.argv[1], 100.0 * havepixels / > pixels)) > > picture[(posx, posy)] = most Why are you using a dictionary as "2d array"? In the C code you simply write the values sequentially, why can't you just use a flat list and append here? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Implementing file reading in C/Python

2009-01-09 Thread Marc 'BlackJack' Rintsch
On Fri, 09 Jan 2009 19:33:53 +1000, James Mills wrote: > On Fri, Jan 9, 2009 at 7:15 PM, Marc 'BlackJack' Rintsch > wrote: >> Why parentheses around ``print``\s "argument"? In Python <3 ``print`` >> is a statement and not a function. > > N

Re: Implementing file reading in C/Python

2009-01-09 Thread Marc 'BlackJack' Rintsch
ictionary are mapped to ones after the loop which gives a pretty boring PGM. :-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Implementing file reading in C/Python

2009-01-09 Thread Marc 'BlackJack' Rintsch
dx%d' % (width, height) print 'Bytes per Pixel: %d' % blocksize with open(filename, 'rb') as data_file: blocks = iter(partial(data_file.read, blocksize), '') pixel_values = imap(ord, iter_max_values(blocks, pixels)) write_pgm(

Re: string split

2009-01-09 Thread Marc 'BlackJack' Rintsch
On Fri, 09 Jan 2009 12:39:22 -0800, Leland wrote: > It seems work this way, but is there more elegant way to do this? Yes, the `csv` module in the standard library. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Where's Psyco now?

2009-01-09 Thread Marc 'BlackJack' Rintsch
d directly to machine code. And for some very generic functions that are called with lots of different types, the memory consumption is high because of all the specialized code that will be compiled. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Implementing file reading in C/Python

2009-01-09 Thread Marc 'BlackJack' Rintsch
On Fri, 09 Jan 2009 15:34:17 +, MRAB wrote: > Marc 'BlackJack' Rintsch wrote: > >> def iter_max_values(blocks, block_count): >> for i, block in enumerate(blocks): >> histogram = defaultdict(int) >> for byte in bl

Re: python noob help

2008-10-06 Thread Marc 'BlackJack' Rintsch
re crying for help. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: distributing apps without the Python source?

2008-10-08 Thread Marc 'BlackJack' Rintsch
c files. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: PIL problem

2008-10-08 Thread Marc 'BlackJack' Rintsch
ht = size_tuple[1] > > square_length = 75 > > x1 = (width / 2) - (square_length / 2) x2 = x1 + square_length > y1 = (height / 2) - (square_length / 2) y2 = y1 + square_length > > image.crop((x1,y1,x2,y2)) This doesn't change `image` but creates and returns a new

Re: distributing apps without the Python source?

2008-10-08 Thread Marc 'BlackJack' Rintsch
On Wed, 08 Oct 2008 10:59:44 -0500, skip wrote: > Marc> On Wed, 08 Oct 2008 09:18:47 -0600, Joe Strout wrote: > >> We have a client who's paranoid about distributing the Python > >> source to his commercial app. Is there some way I can distribute > &g

Re: Python syntax question

2008-10-08 Thread Marc 'BlackJack' Rintsch
gt; > The little carrot points to the equal sign ('=') in 'file=stderr' > > What's the syntax problem? That's Python 3.0 syntax where ``print`` is not a keyword anymore but a function. Won't work with Python 2.5. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Clever way of sorting strings containing integers?

2008-10-09 Thread Marc 'BlackJack' Rintsch
in(): lines = ['foo1bar2', 'foo10bar10', 'foo2bar3', 'foo10bar2', 'fo', 'bar1000', '777'] lines.sort(key=key_func) print '\n'.join(lines) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Python HTML parser chokes on UTF-8 input

2008-10-10 Thread Marc 'BlackJack' Rintsch
objects. > However I am sure you will agree that explicit encoding conversions are > cumbersome and error-prone. But implicit conversions are impossible because the interpreter doesn't know which encoding to use and refuses to guess. Implicit and guessed conversions are error prone too. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Append a new value to dict

2008-10-13 Thread Marc 'BlackJack' Rintsch
only *once* to ``counter['B']`` in every case. `dict.setdefault()` is for situations where you really want to actually put the initial value into the dictionary, like with the list example by the OP. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: messages from pylint - need some reasoning

2008-10-17 Thread Marc 'BlackJack' Rintsch
ey accidentally share objects. And this refactoring takes an indentation level from the old inline code, making it easier to keep the lines in the 80 characters limit. > Who can give me some hints to improve my code or arguments to switch of > that warnings? Try to write the code with less names and statements. Write functions that do just "one thing" and split big functions into smaller ones. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing a file with iterators

2008-10-17 Thread Marc 'BlackJack' Rintsch
On Fri, 17 Oct 2008 11:42:05 -0400, Luis Zarrabeitia wrote: > I need to parse a file, text file. The format is something like that: > > TYPE1 metadata > data line 1 > data line 2 > ... > data line N > TYPE2 metadata > data line 1 > ... > TYPE3 metadata > ... > […] > because when the parser iterat

Re: inserting Unicode character in dictionary - Python

2008-10-17 Thread Marc 'BlackJack' Rintsch
t do you mean by "does not work"? And you are aware that the above snipped doesn't involve any unicode characters!? You have a byte string there -- type `str` not `unicode`. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: inserting Unicode character in dictionary - Python

2008-10-17 Thread Marc 'BlackJack' Rintsch
On Fri, 17 Oct 2008 11:32:36 -0600, Joe Strout wrote: > On Oct 17, 2008, at 11:24 AM, Marc 'BlackJack' Rintsch wrote: > >>> kw = 'генских' >>> >> What do you mean by "does not work"? And you are aware that the above >> snipped d

Re: heapreplace, methodcaller

2008-10-18 Thread Marc 'BlackJack' Rintsch
start > performing a little more optimizations, like turning that tiny lambda > into inlined code. How? The functions in `operator` are meant to be passed directly or to to create other functions that are passed as HOFs into other functions. So the compiler doesn't know in which funct

Re: keyword in package name.

2008-10-19 Thread Marc 'BlackJack' Rintsch
irectory? The `__init__.py` of which vendor should live at the `com/` directory level? If you install them into two different directories but want to import modules from both vendors -- how? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: pyparsing 1.5.1 released

2008-10-20 Thread Marc 'BlackJack' Rintsch
On Mon, 20 Oct 2008 13:54:56 +0800, oyster wrote: > but the pyparsing.py in pyparsing-1.5.1.tar.gz is marked as 2008-10-02 I > think it is good too touch all the files' time up-to-date. Why? This throws away information, such as "when was package/module xy changed"

Re: dumping in destructor

2008-10-20 Thread Marc 'BlackJack' Rintsch
e call to `__del__()` is not guaranteed. > can I somehow save my data from destructor? Reliably? No! Change your design, it won't work this way. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: indentation

2008-10-21 Thread Marc 'BlackJack' Rintsch
gt; column 1, pressing tab will move the equivalent of 8 spaces, which takes > you column 9, not 8. Ever noticed that computer freaks often start counting at 0? ;-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Append a new value to dict

2008-10-22 Thread Marc 'BlackJack' Rintsch
gt; >> if counter.has_key('B'): >>     counter['B'] += 1 >> else: >>     counter['B'] = 1 > > Both those are slow. Better to use: > > if 'B' in counter: > counter['B'] += 1 > else: > counter['B'] = 1 > > Or with a defaultdict: > > counter = defauldict(int) > counter['B'] += 1 Or: counter['B'] = counter.get('B', 0) + 1 Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: why does math.pow yields OverflowError (while python itself can calculate that large number)

2008-10-23 Thread Marc 'BlackJack' Rintsch
000 > 000 > 000 > L >>>> This can be written more straigth forward as ``100**155`` or ``pow(100, 155)``. No need for `eval()`\ing a stri

Re: More efficient array processing

2008-10-23 Thread Marc 'BlackJack' Rintsch
* 73 * 20 * 8 bytes You want: GiB * 2.1146536 / 0.47289069 Do you have a 32 bit system? Then 2 GiB is too much for a process. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: why would 'import win32com' fail?

2008-10-23 Thread Marc 'BlackJack' Rintsch
2com` module? It is not part of the standard library. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: More efficient array processing

2008-10-23 Thread Marc 'BlackJack' Rintsch
s? Any chance they are just 4 byte floats in your Fortran code i.e. C floats instead of C doubles like the default in `numpy`? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: More efficient array processing

2008-10-23 Thread Marc 'BlackJack' Rintsch
On Thu, 23 Oct 2008 13:56:22 -0700, John [H2O] wrote: > I'm using zeros with type np.float, is there a way to define the data > type to be 4 byte floats? Yes: In [13]: numpy.zeros(5, numpy.float32) Out[13]: array([ 0., 0., 0., 0., 0.], dtype=float32) Ciao, Marc 'Bl

Re: URL as input -> "IOError: [Errno 2] The system cannot find the path specified"

2008-10-24 Thread Marc 'BlackJack' Rintsch
t;URL" lacks the protocol! Correct would be http://amazon.fr… (I guess). > [...] > > IOError: [Errno 2] The system cannot find the path specified: > 'amazon.fr\\search\\index.php?url=search' Without protocol it seems that the 'file://' protocol is used a

Re: portable python

2008-10-24 Thread Marc 'BlackJack' Rintsch
" + scan(ip,port,timeout) …one of which is `None` and that will blow up here, regardless of platform. In [18]: " : " + None --- Traceback (most recent call last) /home/bj/ in () : cannot con

Re: doctest redundant mock class instantiations

2008-10-24 Thread Marc 'BlackJack' Rintsch
hat functions or methods and use the doctest module to check if my examples agree with the actual implementation. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Limit between 0 and 100

2008-10-25 Thread Marc 'BlackJack' Rintsch
The ``try``/``except`` structure can have an ``else`` branch. Maybe that can be of use here. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Ordering python sets

2008-10-26 Thread Marc 'BlackJack' Rintsch
are not 100% interchangeably. Dictionaries as implemented need keys to be hashable objects and sorted dictionaries need the keys to have an order defined. So switching mapping types may fail unless the key objects already have the needed magic methods implemented to do the right thing. Ciao, Mar

Re: Need advice/suggestion for small project

2008-10-28 Thread Marc 'BlackJack' Rintsch
ople with programming experience in other languages `Dive into Python` is a recommended free Python text. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Unicode Problem

2008-10-30 Thread Marc 'BlackJack' Rintsch
= > so my question is > 1)why >>> abebe prints '\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0 > \xe1\x89\xa0\xe1\x88\xb6 \xe1\x89\xa0\xe1\x88\x8b' instead of አበበ በሶ በላ > 2) why >>> print abeba don't print the expected አበበ በሶ በላ string thanks > a lot. Because lists represent their content in the `repr()` form. So you, the programmer, can see what's really in there. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Need some help speeding up this loop

2008-10-30 Thread Marc 'BlackJack' Rintsch
templates = [k.replace('{{ state }}', > state.state).replace('{{ state_abbr }}', state.abbreviation) for k in > templates] It seems you are iterating over *all* accumulated templates so far, over and over again, even those which don't have those place h

Re: Ascii codec can't encode

2008-10-30 Thread Marc 'BlackJack' Rintsch
of those line raised the exception? Full traceback please. I guess it is one of the ``print``\s because `BeatifulSoup` returns `unicode` objects which may lead to that exception when printed and the output encoding can not be determined. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Python-list Digest, Vol 61, Issue 443

2008-10-30 Thread Marc 'BlackJack' Rintsch
s encoded in three bytes. If you really want to operate on characters instead of bytes, use `unicode` objects: In [129]: u = abebe.decode('utf-8') In [130]: len(u) Out[130]: 9 In [131]: print u[0] አ Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: modifying locals

2008-10-31 Thread Marc 'BlackJack' Rintsch
nd surprising side effects. So I ask for the use case too. What problem are you trying to solve? There might be a better way than executing strings as code and trying to inject names into the callers namespace. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Printing with interspersed element

2008-10-31 Thread Marc 'BlackJack' Rintsch
e without shadowing the built in `iter()` and without calling the "magic method" directly: iterator = iter([1, 2, 3, 4, 5]) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: split() and string.whitespace

2008-10-31 Thread Marc 'BlackJack' Rintsch
ts at the string '\t\n\x0b\x0c\r ' which doesn't occur in `mytext`. The argument is a string not a set of characters. > print string.split(mytext, sep=whitespace) Same here. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: convert string literal to object attribute

2008-10-31 Thread Marc 'BlackJack' Rintsch
.attribute > return > print "\n" > return > > i want i.attribute to be treated as i._ward Look at the `getattr()` function. > I get a compile error "instance has no attribute 'attribute' " which i > underst

Re: Why does numpy.array(a[0],b[0]) have this meaning?

2008-11-03 Thread Marc 'BlackJack' Rintsch
ay, or any (nested) sequence. And `numpy.int32` instances have an `__array__()` method: In [225]: ten = numpy.int32(10) In [226]: ten.__array__() Out[226]: array(10) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Unyeilding a permutation generator

2008-11-03 Thread Marc 'BlackJack' Rintsch
here the generator code is allowed to run when `next()` is called and stops itself when it ``yield``\s an object. Sort of cooperative multitasking. The name "yield" is often used in concurrent code like Java's or Io's `yield()` methods. Ciao, Marc 'BlackJack&

Re: problem with quote and single-quote when using "subprocess"

2008-11-03 Thread Marc 'BlackJack' Rintsch
oest" was a typo!?) has no option `'-f '"%s %s" name addr' `. And you should decide if you want to split the arguments yourself or if you want to use the shell. Mixing both doesn't make much sense. If *you* split the arguments, the call should look like this: p = subprocess.Popen(['goset', '-f', ' "%s %s" name addr ', 'file_name']) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Structures

2008-11-03 Thread Marc 'BlackJack' Rintsch
On Mon, 03 Nov 2008 23:32:25 +, Paulo J. Matos wrote: > What's then the reason for adding named tuples if they are not > mutable...??? Names are more descriptive than "magic numbers" as indices. See for example the "named tuple" returned by `os.stat()`.

Re: Finding the instance reference of an object

2008-11-03 Thread Marc 'BlackJack' Rintsch
27;t discussed this in much detail in this group lately, but it applies to Python which does call-by-object or call-by-sharing. ;-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the instance reference of an object

2008-11-04 Thread Marc 'BlackJack' Rintsch
ject or call-by-sharing. Call-by-name "injects" the expression used to call into the called function and evaluates it every time the argument is accessed within the function. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: problem with single-quote and double-quote when using subprocess.

2008-11-04 Thread Marc 'BlackJack' Rintsch
p = subprocess.Popen(["goest", "-f", "' \"%s %s\" name addr '", > "file_name"], shell=True) The argument after '-f' doesn't have the single quotes at both ends. They tell the shell that it is just one argument and the shell removes them before calling ``goset`` (or ``goest``). Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the instance reference of an object

2008-11-04 Thread Marc 'BlackJack' Rintsch
an to explain the underlying machinery two levels below (because the CPython-VM doesn't know pointers either). Maybe not for people who know that low levels from older languages and insist on explaining everything in the terms of those. Maybe that's the reason for the Java folks to call their strategy call-by-value, because they were afraid to confuse C++ programmers with "new" concepts. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: What's your choice when handle complicated C structures.

2008-11-04 Thread Marc 'BlackJack' Rintsch
On Tue, 04 Nov 2008 16:52:17 -0800, 一首诗 wrote: > Now I'm using the upack function of 'struct' module, but it's really > annoying to write fmt strings for complicated structures. > > What will be your choice when handling binary structures? http://construct.wik

Re: Is there a better/simpler way to filter blank lines?

2008-11-04 Thread Marc 'BlackJack' Rintsch
in xrange(10) ^ : invalid syntax In [271]: a = (x for x in xrange(10)) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a better/simpler way to filter blank lines?

2008-11-04 Thread Marc 'BlackJack' Rintsch
On Wed, 05 Nov 2008 13:18:27 +1100, Ben Finney wrote: > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes: > > Your example shows only that they're important for grouping the > expression from surrounding syntax. As I said. > > They are *not* important f

Re: Is there a better/simpler way to filter blank lines?

2008-11-05 Thread Marc 'BlackJack' Rintsch
On Wed, 05 Nov 2008 14:39:36 +1100, Ben Finney wrote: > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes: > >> On Wed, 05 Nov 2008 13:18:27 +1100, Ben Finney wrote: >> >> > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes: &g

Re: False and 0 in the same dictionary

2008-11-05 Thread Marc 'BlackJack' Rintsch
`bool`\s to `int`\s then. Sometimes I write it as sum(int(el == val) for el in iterable) just for clarity what the intent is. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Rewriting a bash script in python

2008-11-05 Thread Marc 'BlackJack' Rintsch
ork. It just pretends until you really *need* the backed up data. ;-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: More __init__ methods

2008-11-06 Thread Marc 'BlackJack' Rintsch
# ... return cls(a, b, c) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Fastest way to tint an image with PIL

2008-11-07 Thread Marc 'BlackJack' Rintsch
tiply(image, Image.new('RGB', image.size, tint_color)) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: is it a bug in Module copy or i am wrong??

2008-11-07 Thread Marc 'BlackJack' Rintsch
e immutable so the CPython implementation caches small integers as an optimization. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: declaration problem

2008-11-07 Thread Marc 'BlackJack' Rintsch
t.socket` because then you would use the `recv()` method of that object. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

<    10   11   12   13   14   15   16   17   18   19   >