Re: Override a method but inherit the docstring

2009-07-17 Thread Peter Otten
Ben Finney wrote: > Howdy all, > > The following is a common idiom:: > > class FooGonk(object): > def frobnicate(self): > """ Frobnicate this gonk. """ > basic_implementation(self.wobble) > > class BarGonk(FooGonk): > def frobnicate(self): >

Re: UnicodeEncodeError: 'ascii' codec can't encode character u'\xb7' in position 13: ordinal not in range(128)

2009-07-17 Thread Nobody
On Thu, 16 Jul 2009 20:26:39 -0700, akhil1988 wrote: > Well, you were write: unintentionally I removed strip(). But the problem does > not ends here: > > I get this error now: > > File "./temp.py", line 488, in > main() > File "./temp.py", line 475, in main > for line in sys.stdin: >

Re: urllib with x509 certs

2009-07-17 Thread Lacrima
Hello! I've solved this problem, using pyCurl. Here is sample code. import pycurl import StringIO b = StringIO.StringIO() c = pycurl.Curl() url = 'https://example.com/' c.setopt(pycurl.URL, url) c.setopt(pycurl.WRITEFUNCTION, b.write) c.setopt(pycurl.CAINFO, 'cert.crt') c.setopt(pycurl.SSLKEY, 'm

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Steven D'Aprano
On Thu, 16 Jul 2009 23:13:51 -0700, koranthala wrote: >> That test was designed to treat None as a boolean False, without >> noticing that numeric 0 is also treated as False and could make the >> test do the wrong thing. This is an extremely common type of error. > > Actually, I felt that 0 not

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Paul Rubin
Steven D'Aprano writes: > It is very useful to be able to write e.g.: > if header or body or footer: > print assemble_page(header, body, footer) > and have empty strings to be equivalent to False. Why doesn't assemble_page properly handle the case where header, body, and footer are all empty?

Re: invoke method on many instances

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 05:19:50 +, Alan G Isaac wrote: > As a recurrent situation, I need to invoke the same method on many > instances. Speed matters, but the solution should be pure Python. Is > the following convenience function a reasonable approach? > > def apply2(itr, methodname, *args, *

Re: Override a method but inherit the docstring

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 12:58:48 +1000, Ben Finney wrote: >> Using a decorator in this manner requires repeating the super class >> name. Perhaps there is a way to get the bases of BarGonk, but I don't >> think so, because at the time that the decorator is called, BarGonk is >> not yet fully defined.

Re: TypeError: unbound method

2009-07-17 Thread Steven D'Aprano
On Thu, 16 Jul 2009 18:08:45 -0700, Chris Rebert wrote: > You're trying to call an instance method on the class itself, which > doesn't make sense. Oh I don't know, people do it all the time -- just not the way the OP did :) > You need to first create an instance of the class to invoke the meth

Re: How to check if any item from a list of strings is in a big string?

2009-07-17 Thread Steven D'Aprano
On Thu, 16 Jul 2009 11:02:57 -0500, Pablo Torres N. wrote: > On Thu, Jul 9, 2009 at 22:07, Steven > D'Aprano wrote: >> On Thu, 09 Jul 2009 18:36:05 -0700, inkhorn wrote: >> >>> def list_items_in_string(list_items, string): >>>     for item in list_items: >>>         if item in string: >>>        

ann: servicestation - run your linux/mac services on windows without needing pywin...

2009-07-17 Thread Oisin Mulvihill
Hi There, I gave a lightning talk about my ServiceStation project at Europython 2009. While it isn't written in Python (C++/Windows), I did write it with python in mind. Its released under the CDDL license. I'm hoping it will be of use to other Python users who will need to run their serv

Re: question of style

2009-07-17 Thread Piet van Oostrum
> koranthala (k) wrote: >>> That test was designed to treat None as a boolean False, without >>> noticing that numeric 0 is also treated as False and could make the >>> test do the wrong thing. This is an extremely common type of error. >k> Actually, I felt that 0 not being considered False

Re: Persistent variable in subprocess using multiprocessing?

2009-07-17 Thread Piet van Oostrum
There is stil something not clear in your description. >m> I'm using multiprocessing to spawn several subprocesses, each of which >m> uses a very large data structure (making it impractical to pass it via >m> pipes / pickling). I need to allocate this structure once when the >m> process is created

Re: ann: servicestation - run your linux/mac services on windows without needing pywin...

2009-07-17 Thread Tim Golden
Oisin Mulvihill wrote: Hi There, I gave a lightning talk about my ServiceStation project at Europython 2009. While it isn't written in Python (C++/Windows), I did write it with python in mind. Its released under the CDDL license. I'm hoping it will be of use to other Python users who will ne

Re: ctype performance benchmark

2009-07-17 Thread Stefan Behnel
auror...@gmail.com wrote: > My overall observation is that ctypes function has an overhead that is > 2 to 3 times to a similar C extension function. This may become a > limiting factor if the function calls are fine grained. Using ctypes > for performance enhancement is a lot more productive if the

Re: no return value for threading.Condition.wait(timeout)?

2009-07-17 Thread Piet van Oostrum
> Gabriel Rossetti (GR) wrote: >GR> I have a 1-1 relation, I have a thread reading msgs from a network socket >GR> and a method waiting for an answer to arrive (see my thread >GR> "Threading.Condition problem"). I would like to be able to have a timeout >GR> as to not block forever, so the id

ANN: psyco V2

2009-07-17 Thread Christian Tismer
Announcing Psyco V2 source release -- This is the long awaited announcement of Psyco V2. Psyco V2 is a continuation of the well-known psyco project, which was called finished and was dis-continued by its author Armin Rigo in 2005, in favor of the PyPy project. Th

Re: Why not enforce four space indentations in version 3.x?

2009-07-17 Thread Nobody
On Thu, 16 Jul 2009 09:18:47 -0500, Tim Chase wrote: > Yes, the dictatorial "a tab always equals 8 spaces" Saying "always" is incorrect; it is more accurate to say that tab stops are every 8 columns unless proven otherwise, with the burden of proof falling on whoever wants to use something differ

Re: Clarity vs. code reuse/generality

2009-07-17 Thread Albert van der Horst
In article , Dennis Lee Bieber wrote: >On 07 Jul 2009 05:05:12 GMT, Steven D'Aprano > declaimed the following in >gmane.comp.python.general: > >> Paraphrasing the Collins Dictionary of Mathematics: >> >> opposite sense. Sense is also used to distinguish clockwise and anti- >> clockwise. >> >

Re: UnicodeEncodeError: 'ascii' codec can't encode character u'\xb7' in position 13: ordinal not in range(128)

2009-07-17 Thread Piet van Oostrum
> akhil1988 (a) wrote: >a> Well, you were write: unintentionally I removed strip(). But the problem >does >a> not ends here: >a> I get this error now: >a> File "./temp.py", line 488, in >a> main() >a> File "./temp.py", line 475, in main >a> for line in sys.stdin: >a> File "/u

Re: ann: servicestation - run your linux/mac services on windows without needing pywin...

2009-07-17 Thread Oisin Mulvihill
On Jul 17, 9:34 am, Tim Golden wrote: > Oisin Mulvihill wrote: > > Hi There, > > > I gave a lightning talk about my ServiceStation project at Europython > > 2009. While it > > isn't written in Python (C++/Windows), I did write it with python in > > mind. Its > > released under the CDDL license. >

Re: error when compiling source on linux

2009-07-17 Thread Peter Fodrek
On Friday 17 July 2009 06:44:26 aj wrote: > when I try to compile Python 2.6 from source code on ubuntu, I get the > message > /usr/bin/ld: cannot open output file python: Is a directory This says that there is directory in the sources with same name as will be named output It can only occur whe

Re: ann: servicestation - run your linux/mac services on windows without needing pywin...

2009-07-17 Thread Tim Golden
Oisin Mulvihill wrote: I have to admit I didn't come across srvany before. It's been part of the Windows Resource Kit since way back, but like many such things is probably known more by word-of-mouth than by Internet Searchability * Properly tracking all child processes launched by the comma

Re: Passing python list from C to python

2009-07-17 Thread hartley
On Jul 16, 9:26 pm, a...@pythoncraft.com (Aahz) wrote: > In article > <0afc5c4d-1af5-4d0e-9442-26b51b12e...@m11g2000yqh.googlegroups.com>, > > hartley   wrote: > > >If you had loosened up on the sarcasm I would probably have read what > >you wrote more thoroughly instead of just skimming through i

Re: Override a method but inherit the docstring

2009-07-17 Thread Ben Finney
Peter Otten <__pete...@web.de> writes: > Just thinking aloud: Write a patch for pydoc that looks up the > base-class documentation. That doesn't scale; I want the docstring to be discovered by the normal interface (the ‘__doc__’ attribute) by *every* tool that gathers docstrings from methods. Al

Re: Why aren't OrderedDicts comparable with < etc?

2009-07-17 Thread Sion Arrowsmith
Jack Diederich wrote: >It isn't an OrderedDict thing, it is a comparison thing. Two regular >dicts also raise an error if you try to LT them. Since when? Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information

Re: missing 'xor' Boolean operator

2009-07-17 Thread Jean-Michel Pichavant
Luis Alberto Zarrabeitia Gomez wrote: Quoting Jean-Michel Pichavant : Emile van Sebille wrote: On 7/16/2009 7:04 AM Unknown said... On 2009-07-16, Emile van Sebille wrote: daysInAdvance = int(inputVar) or 25 I don't get it. That doesn't work right when i

Re: ANN: psyco V2

2009-07-17 Thread Bearophile
Very good, thank you. I'll try it when I can. Is Psyco3 going to borrow/steal some ideas/code from Unladen Swallow? The problem I have with Psyco1.6 is that you can't use the normal profilers to know how much seconds of running time is taken by each function/method of your code. Psyco1.6 has a pr

Re: Try... except....Try again?

2009-07-17 Thread Andre Engels
On Fri, Jul 17, 2009 at 7:31 AM, Xavier Ho wrote: > I have a simple class that generates prime numbers, using memorisation and > iteration to generate the next prime number. > > In the class, I have defined a function that gives, say, the 5th prime > number. Or the 1000th, it's still very fast. But

Re: Try... except....Try again?

2009-07-17 Thread Xavier Ho
On Fri, Jul 17, 2009 at 7:33 PM, Andre Engels wrote: > > Where do you get these "Don't do it!"s? As far as I know, "while true" > loops are a very acceptable idiom for programming in Python (and > several other languages). > Hey Andre, Friends, internet, common sense. Also... "while True" has a

Re: Override a method but inherit the docstring

2009-07-17 Thread David Stanek
On Fri, Jul 17, 2009 at 2:58 AM, Peter Otten<__pete...@web.de> wrote: > Ben Finney wrote: > >> Howdy all, >> >> The following is a common idiom:: >> >>     class FooGonk(object): >>         def frobnicate(self): >>             """ Frobnicate this gonk. """ >>             basic_implementation(self.w

setup.py not found

2009-07-17 Thread larry.mart...@gmail.com
I'm trying to install a package (cx_Oracle) on a mac running 10.5.7. I've done this on other platforms, but never on a mac. I followed the instructions given, but when I try and run setup I get: Apollo:instantclient_10_2 user$ python setup.py build /System/Library/Frameworks/Python.framework/Versi

guessing file type

2009-07-17 Thread Seldon
Hello, I need to determine programmatically a file type from its content/extension (much like the "file" UNIX command line utility) I searched for a suitable Python library module, with little luck. Do you know something useful ? Thanks in advance. -- Seldon -- http://mail.python.org/mailman

Re: Override a method but inherit the docstring

2009-07-17 Thread David Stanek
On Fri, Jul 17, 2009 at 3:52 AM, Steven D'Aprano wrote: > On Fri, 17 Jul 2009 12:58:48 +1000, Ben Finney wrote: > >>> Using a decorator in this manner requires repeating the super class >>> name.  Perhaps there is a way to get the bases of BarGonk, but I don't >>> think so, because at the time that

Re: guessing file type

2009-07-17 Thread Ben Finney
Seldon writes: > Hello, I need to determine programmatically a file type from its > content/extension (much like the "file" UNIX command line utility) The Unix ‘file(1)’ program does its magic with a library called “magic” and a corresponding database. > I searched for a suitable Python librar

Re: guessing file type

2009-07-17 Thread Tim Chase
Hello, I need to determine programmatically a file type from its content/extension (much like the "file" UNIX command line utility) I searched for a suitable Python library module, with little luck. Do you know something useful ? Are you looking for something comprehensive? Or are you just

Re: guessing file type

2009-07-17 Thread VanL
Seldon wrote: Hello, I need to determine programmatically a file type from its content/extension (much like the "file" UNIX command line utility) I searched for a suitable Python library module, with little luck. Do you know something useful ? Python-magic (http://pypi.python.org/pypi/pytho

Re: Try... except....Try again?

2009-07-17 Thread MRAB
Xavier Ho wrote: I have a simple class that generates prime numbers, using memorisation and iteration to generate the next prime number. In the class, I have defined a function that gives, say, the 5th prime number. Or the 1000th, it's still very fast. But the code isn't what I really like.

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 00:34:00 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> It is very useful to be able to write e.g.: >> >> if header or body or footer: >> print assemble_page(header, body, footer) >> >> and have empty strings to be equivalent to False. > > Why doesn't assemble_pag

ANN: Leo 4.6 final released

2009-07-17 Thread Edward K Ream
Leo 4.6 final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.6: -- - Cached

Re: missing 'xor' Boolean operator

2009-07-17 Thread Steven D'Aprano
On Thu, 16 Jul 2009 15:53:45 +0200, Jean-Michel Pichavant wrote: > Python has extended the algebra definition of "or" and "and" top any > type, but it is so unintuitive (I'm no LISP programmer). I disagree. The Something/Nothing dichotomy is so intuitive to me that I would hate to go back to a l

Re: guessing file type

2009-07-17 Thread Justin Ezequiel
On Jul 17, 8:39 pm, VanL wrote: > Seldon wrote: > > Hello,  I need to determine programmatically a file type from its > > content/extension (much like the "file" UNIX command line utility) > > > I searched for a suitable Python library module, with little luck. Do > > you know something useful ? >

Re: Try... except....Try again?

2009-07-17 Thread Steven D'Aprano
Apologies for breaking threading, but the original post hasn't showed up on my ISP's news server. Xavier Ho wrote: > I have a simple class that generates prime numbers, using memorisation > and iteration to generate the next prime number. [...] > The next() function generates the next prime, and

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Paul Rubin
Steven D'Aprano writes: > def assemble_page(header, body, footer): > if header or body or footer: > do_lots_of_expensive_processing() > else: > do_nothing_gracefully() Why should the processing be expensive if all three fields are empty? > if header or body or footer:

Re: missing 'xor' Boolean operator

2009-07-17 Thread Luis Zarrabeitia
On Friday 17 July 2009 07:06:26 am Jean-Michel Pichavant wrote: > > I was saying that using boolean operators with object instead of boolean > values is error prone, cause no language behaves he same way, I don't know of many languages that actively promote the duck typing concept, are as highly

Re: missing 'xor' Boolean operator

2009-07-17 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Thu, 16 Jul 2009 15:53:45 +0200, Jean-Michel Pichavant wrote: Given three result codes, where 0 means "no error" and an arbitrary non- zero integer means some error, it is simple and easy to write: failed = result_1 or result_2 or result_3 The equivalent: failed = (

Try... except....Try again?

2009-07-17 Thread Xavier Ho
oops, wrong address. When will reply-to tag appear on the Python mailing list? =/ Good idea, Steven and MRAB. I changed my code to the following: def nPrime(self, n): "Returns nth prime number, the first one being 2, where n = 0. When n = 1, it returns 3." for x in range(n+2

Re: missing 'xor' Boolean operator

2009-07-17 Thread Ethan Furman
Jean-Michel Pichavant wrote: Steven D'Aprano wrote: On Thu, 16 Jul 2009 15:53:45 +0200, Jean-Michel Pichavant wrote: Given three result codes, where 0 means "no error" and an arbitrary non- zero integer means some error, it is simple and easy to write: failed = result_1 or result_2 or result

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 07:12:51 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> def assemble_page(header, body, footer): >> if header or body or footer: >> do_lots_of_expensive_processing() >> else: >> do_nothing_gracefully() > > Why should the processing be expensive

Re: Try... except....Try again?

2009-07-17 Thread Jack Diederich
On Fri, Jul 17, 2009 at 10:35 AM, Xavier Ho wrote: > I changed my code to the following: > >     def nPrime(self, n): >     "Returns nth prime number, the first one being 2, where n = 0. When > n = 1, it returns 3." >     for x in range(n+2): >     try: >     return sel

Re: Einstein summation notation

2009-07-17 Thread MRAB
koranthala wrote: That test was designed to treat None as a boolean False, without noticing that numeric 0 is also treated as False and could make the test do the wrong thing. This is an extremely common type of error. Actually, I felt that 0 not being considered False would be a better option

Re: no return value for threading.Condition.wait(timeout)?

2009-07-17 Thread Gabriel Rossetti
Piet van Oostrum wrote: Gabriel Rossetti (GR) wrote: GR> I have a 1-1 relation, I have a thread reading msgs from a network socket GR> and a method waiting for an answer to arrive (see my thread GR> "Threading.Condition problem"). I would like to be able to have a timeout GR>

Re: Einstein summation notation

2009-07-17 Thread Jerry Hill
On Fri, Jul 17, 2009 at 11:09 AM, MRAB wrote: > Python did always have True and False. Only if "always" means "since python 2.2.1". See: http://www.python.org/doc/2.3/whatsnew/section-bool.html and http://www.python.org/dev/peps/pep-0285/ for details. -- Jerry -- http://mail.python.org/mailma

Re: missing 'xor' Boolean operator

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 16:34:57 +0200, Jean-Michel Pichavant wrote: > Steven D'Aprano wrote: >> On Thu, 16 Jul 2009 15:53:45 +0200, Jean-Michel Pichavant wrote: >> >> >> Given three result codes, where 0 means "no error" and an arbitrary >> non- zero integer means some error, it is simple and easy to

Re: Einstein summation notation

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 16:09:03 +0100, MRAB wrote: > Python did always have True and False. $ python1.5 Python 1.5.2 (#1, Apr 1 2009, 22:55:54) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> True, False Traceback (innermost last

'del' function for Dictionary

2009-07-17 Thread mayank gupta
Hi all, I wanted to know whether there is a more efficient way to delete an entry from a dictionary (instead of using the 'del' function), because after analyzing the time taken by the code, it seems to me that the 'del' function takes most of the time. I might be incorrect as well. Kindly help me

Re: Try... except....Try again?

2009-07-17 Thread Xavier Ho
On Fri, Jul 17, 2009 at 11:02 PM, Jack Diederich wrote: > > If you use an off-the-shelf prime number generator fucntion[1] that > returns consecutive primes the method collapses into a simple > function. > > def nPrime(n, primes=[], next_prime=eratosthenes().next): >while len(primes) < n: >

Re: 'del' function for Dictionary

2009-07-17 Thread Michiel Overtoom
mayank gupta wrote: after analyzing the time taken by the code, What code? -- http://mail.python.org/mailman/listinfo/python-list

Find first matching substring

2009-07-17 Thread Eloff
Almost every time I've had to do parsing of text over the last 5 years I've needed this function: def find_first(s, subs, start=None, end=None): results = [s.find(sub, start, end) for sub in subs] results = [r for r in results if r != -1] if results: return min(results) re

Re: Einstein summation notation

2009-07-17 Thread Ethan Furman
Paul Rubin wrote: Steven D'Aprano writes: def assemble_page(header, body, footer): if header or body or footer: do_lots_of_expensive_processing() else: do_nothing_gracefully() Why should the processing be expensive if all three fields are empty? if header or body o

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Paul Rubin
Steven D'Aprano writes: > Since I haven't specified an implementation for assemble_page, it could > be doing *anything*. Perhaps it has to talk to a remote database over a > slow link, perhaps it generates 300 lines of really inefficient HTML code > with no content, perhaps it sends a print job

Question regarding style/design..

2009-07-17 Thread Wells Oliver
Sometimes I see relatively small application, generally task scripts, written as essentially a list of statements. Other times, I see them neatly divided into functions and then the "if __name__ == '__main__':" convention. Is there a preference? Is there an... application scope such that the prefer

A multi-threaded file searcher for processing large text files

2009-07-17 Thread Mahmoud Abdelkader
I'm building a threaded file searcher that uses some of Fredrik Lundh's ( http://effbot.org/zone/wide-finder.htm) suggestions for parsing text very quickly in pure python, as I have about a 10GB log file to parse every day. A naiive approach would be to just parse the 1MB chunks, add the results in

Re: missing 'xor' Boolean operator

2009-07-17 Thread Emile van Sebille
On 7/17/2009 7:34 AM Jean-Michel Pichavant said... Steven D'Aprano wrote: On Thu, 16 Jul 2009 15:53:45 +0200, Jean-Michel Pichavant wrote: Given three result codes, where 0 means "no error" and an arbitrary non- zero integer means some error, it is simple and easy to write: failed = result_1

Regular exprssion for IRC messages

2009-07-17 Thread nohics nohics
Hello, When an IRC client receive a messages, this message in in a special format defined here: Message format in pseudo BNF( http://www.irchelp.org/irchelp/rfc/chapter2.html#c2_3_1 ). For example we can have: :mynickname!n=myusern...@41.2

Re: Question regarding style/design..

2009-07-17 Thread Tim Chase
Sometimes I see relatively small application, generally task scripts, written as essentially a list of statements. Other times, I see them neatly divided into functions and then the "if __name__ == '__main__':" convention. Is there a preference? Is there an... application scope such that the prefe

Re: ctype performance benchmark

2009-07-17 Thread Wai Yip
I started with ctypes because it is the battery included with the Python standard library. My code is very fluid and I'm looking for easy opportunity to optimize it. One example is to find the longest common prefix among two strings. Right now I am comparing it character by character with pure Pyth

Installing python-gnutls on Windows

2009-07-17 Thread IronyOfLife
Hi, I'm new to python and would like to request your help installing python-gnutls on windows. Are there binaries available which can be installed ? Looks like the setup.py file which came with the package is for Debian. I tried modifying it for windows but am still getting errors. get_options()

getopt code NameError exception on logTail.py

2009-07-17 Thread LoD MoD
I am having trouble extending my option parsing. Any help is appreciated: import sys import getopt import time def tail(file): while 1: where = file.tell() line = file.readline() if not line: time.sleep(1) file.seek(where) el

Propagate import for all modules in a package.

2009-07-17 Thread Phil
I'm really new to Python and I am absolutely stumped trying to figure this out. I have searched plenty, but I am either searching for the wrong keywords or this isn't possible. What I want to do is have one import be global for the entire package. Here is an example... __init__.py module1.py

Re: UnicodeEncodeError: 'ascii' codec can't encode character u'\xb7' in position 13: ordinal not in range(128)

2009-07-17 Thread Scott David Daniels
akhil1988 wrote: > Nobody-38 wrote: On Thu, 16 Jul 2009 15:43:37 -0700, akhil1988 wrote: ... In Python 3 you can't decode strings because they are Unicode strings and it doesn't make sense to decode a Unicode string. You can only decode encoded things which are byte strings. So you are mixing

Re: Einstein summation notation

2009-07-17 Thread Matthew Barnett
Steven D'Aprano wrote: On Fri, 17 Jul 2009 16:09:03 +0100, MRAB wrote: Python did always have True and False. Oops! I meant "didn't", of course. $ python1.5 Python 1.5.2 (#1, Apr 1 2009, 22:55:54) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Copyright 1991-1995 Stichting Mathematis

Re: Question regarding style/design..

2009-07-17 Thread Robert Kern
On 2009-07-17 12:11, Tim Chase wrote: Sometimes I see relatively small application, generally task scripts, written as essentially a list of statements. Other times, I see them neatly divided into functions and then the "if __name__ == '__main__':" convention. Is there a preference? Is there an..

Re: Propagate import for all modules in a package.

2009-07-17 Thread Diez B. Roggisch
Phil schrieb: I'm really new to Python and I am absolutely stumped trying to figure this out. I have searched plenty, but I am either searching for the wrong keywords or this isn't possible. What I want to do is have one import be global for the entire package. Here is an example... __init__

Re: Find first matching substring

2009-07-17 Thread MRAB
Eloff wrote: > Almost every time I've had to do parsing of text over the last 5 years > I've needed this function: > > def find_first(s, subs, start=None, end=None): > results = [s.find(sub, start, end) for sub in subs] > results = [r for r in results if r != -1] > if results: >

Generator Expressions and CSV

2009-07-17 Thread Zaki
Hey all, I'm really new to Python and this may seem like a really dumb question, but basically, I wrote a script to do the following, however the processing time/memory usage is not what I'd like it to be. Any suggestions? Outline: 1. Read tab delim files from a directory, files are of 3 types:

Re: Propagate import for all modules in a package.

2009-07-17 Thread Albert Hopkins
On Fri, 2009-07-17 at 10:28 -0700, Phil wrote: > I'm really new to Python and I am absolutely stumped trying to figure > this out. I have searched plenty, but I am either searching for the > wrong keywords or this isn't possible. > > What I want to do is have one import be global for the entire pa

Re: Question regarding style/design..

2009-07-17 Thread Tim Chase
Robert Kern wrote: [sage advice snipped] Don't waste half a day trying to figure out why your script mysteriously doesn't work. Learn from my mistakes. :-) I find that's the best type of mistake to learn from: other people's ;-) -tkc -- http://mail.python.org/mailman/listinfo/python-list

Writing a single list of numbers to a .m (matlab) file

2009-07-17 Thread Hanna Michelsen
Hi, I was wondering if I could get some suggestions on how to write a single list of numbers to a .m file (for matlab) so that I can create a matlab vector out of the list of numbers from my python program. I have been using a csv writer to create .m files from lists of lists, but I'm not sure how

Re: getopt code NameError exception on logTail.py

2009-07-17 Thread MRAB
LoD MoD wrote: I am having trouble extending my option parsing. Any help is appreciated: import sys import getopt import time def tail(file): while 1: where = file.tell() line = file.readline() if not line: time.sleep(1) file.seek(where)

Re: Generator Expressions and CSV

2009-07-17 Thread Emile van Sebille
On 7/17/2009 10:58 AM Zaki said... Now, I've tried running this and it takes much longer than I'd like. I was wondering if there might be a better way to do things Suppose, for the sake of argument, that you've written highly efficient code. Then the processing time would already be entirel

Re: getopt code NameError exception on logTail.py

2009-07-17 Thread LoD MoD
In this instance the trackback was somewhat unhelpful.There problem was here: file = open(filename, 'r') should be file = open(a, 'r') args should be passed within the getopt riff On Fri, Jul 17, 2009 at 11:08 AM, MRAB wrote: > LoD MoD wrote: > >> I am having trouble ex

Re: ctype performance benchmark

2009-07-17 Thread Nick Craig-Wood
Wai Yip wrote: > I started with ctypes because it is the battery included with the > Python standard library. My code is very fluid and I'm looking for > easy opportunity to optimize it. One example is to find the longest > common prefix among two strings. Right now I am comparing it character

Re: Propagate import for all modules in a package.

2009-07-17 Thread Phil
Thanks to both of you for the fast and detailed responses. I will just treat the package for what it is, a namespace. -- http://mail.python.org/mailman/listinfo/python-list

Re: Propagate import for all modules in a package.

2009-07-17 Thread Phil
Thanks to both of you for the fast and detailed responses. I will just use the package for what it is, a namespace. -- http://mail.python.org/mailman/listinfo/python-list

Re: Propagate import for all modules in a package.

2009-07-17 Thread Phil
Thanks to both of you for the fast and detailed responses. I will just use the package for what it is, a namespace. -- http://mail.python.org/mailman/listinfo/python-list

Re: Generator Expressions and CSV

2009-07-17 Thread MRAB
Zaki wrote: Hey all, I'm really new to Python and this may seem like a really dumb question, but basically, I wrote a script to do the following, however the processing time/memory usage is not what I'd like it to be. Any suggestions? Outline: 1. Read tab delim files from a directory, files ar

Mechanize not recognized by py2exe

2009-07-17 Thread Stephen M. Olds
I have a Python script getData.py that uses Mechanize, and runs fine under the interpreter. It was installed using easy_install - and the install seemed to indicate it was completed. The problem is, when I try to compile it using py2exe while in the folder of the script, and using the run line

Re: ctype performance benchmark

2009-07-17 Thread Duncan Booth
Wai Yip wrote: > I started with ctypes because it is the battery included with the > Python standard library. My code is very fluid and I'm looking for > easy opportunity to optimize it. One example is to find the longest > common prefix among two strings. Right now I am comparing it character >

Re: A Bug By Any Other Name ...

2009-07-17 Thread Albert van der Horst
In article , Gabriel Genellina wrote: >En Mon, 06 Jul 2009 00:28:43 -0300, Steven D'Aprano > escribi?: >> On Mon, 06 Jul 2009 14:32:46 +1200, Lawrence D'Oliveiro wrote: >> >>> I wonder how many people have been tripped up by the fact that >>> >>> ++n >>> >>> and >>> >>> --n >>> >>> fail si

proposal: add setresuid() system call to python

2009-07-17 Thread travis+ml-python
Hello, Historically, I have used scripting languages like python for typical uses, but they tend to not fare very well at system programming; for close interfacing with the operating system, I'm often forced to use a language like C. This is undesirable to me. I do not think this has to be the c

Re: A Bug By Any Other Name ...

2009-07-17 Thread J. Cliff Dyer
On Fri, 2009-07-17 at 20:53 +, Albert van der Horst wrote: > Because unlike in algol 68 in python whitespace is relevant, > we could get by with requiring whitespace: > x= -q # okay > a 8 ** -2 # okay This is actually quite thor

Re: Generator Expressions and CSV

2009-07-17 Thread Zaki
On Jul 17, 2:49 pm, MRAB wrote: > Zaki wrote: > > Hey all, > > > I'm really new to Python and this may seem like a really dumb > > question, but basically, I wrote a script to do the following, however > > the processing time/memory usage is not what I'd like it to be. Any > > suggestions? > > > O

Re: proposal: add setresuid() system call to python

2009-07-17 Thread Mahmoud Abdelkader
Why don't you write a python extension module? This is a perfect opportunity for that. -- mahmoud mack abdelkader http://blog.mahmoudimus.com/ On Fri, Jul 17, 2009 at 4:01 PM, > wrote: > Hello, > > Historically, I have used scripting languages like python for typical > uses, but they tend to

Re: proposal: add setresuid() system call to python

2009-07-17 Thread Robert Kern
On 2009-07-17 15:01, travis+ml-pyt...@subspacefield.org wrote: Hello, Historically, I have used scripting languages like python for typical uses, but they tend to not fare very well at system programming; for close interfacing with the operating system, I'm often forced to use a language like C.

Re: turtle dump

2009-07-17 Thread Terry Reedy
Peter Otten wrote: Terry Reedy wrote: I tried it. Unfortunately, OOo does not open it correctly. It just displays the first three lines of metadate - Title, Creator, Date -- as image text. Photoshop does read the image, and does an ok job of conversion once anti-aliasing is turned off. I snat

Re: turtle dump

2009-07-17 Thread Terry Reedy
alex23 wrote: The help in iPython says the same, but also mentions that it's a dynamically generated function, so it may not be picking up the docstring that way. turtle.ScrolledCanvas.postscript is similarly terse, but you can find more info in turtle.Canvas.postscript: Print the contents of

Re: no return value for threading.Condition.wait(timeout)?

2009-07-17 Thread Piet van Oostrum
> Gabriel Rossetti (GR) wrote: >GR> Piet van Oostrum wrote: Gabriel Rossetti (GR) wrote: >>> >>> >GR> I have a 1-1 relation, I have a thread reading msgs from a network socket >GR> and a method waiting for an answer to arrive (see my thread >GR> "Threading.Condition prob

Re: Writing a single list of numbers to a .m (matlab) file

2009-07-17 Thread Chris Rebert
On Fri, Jul 17, 2009 at 11:06 AM, Hanna Michelsen wrote: > Hi, > > I was wondering if I could get some suggestions on how to write a single > list of numbers to a .m file (for matlab) so that I can create a matlab > vector out of the list of numbers from my python program. I have been using > a csv

Re: A Bug By Any Other Name ...

2009-07-17 Thread MRAB
J. Cliff Dyer wrote: On Fri, 2009-07-17 at 20:53 +, Albert van der Horst wrote: Because unlike in algol 68 in python whitespace is relevant, we could get by with requiring whitespace: x= -q # okay a This is actually quite thoroughly untrue. In python,

Re: proposal: add setresuid() system call to python

2009-07-17 Thread Jean-Paul Calderone
On Fri, 17 Jul 2009 15:01:41 -0500, travis+ml-pyt...@subspacefield.org wrote: Hello, [snip] I am suggesting that the setresuid function be added to python, perhaps in the OS module, because it has the clearest semantics for manipulating user ids. The reason why is best described in the followi

  1   2   >