Re: Guessing the encoding from a BOM

2014-01-16 Thread Björn Lindqvist
t; which exception?) I like this option the most because it is the most "fail fast". If you return 'undefined' the error might happen hours later or not at all in some cases. -- mvh/best regards Björn Lindqvist -- https://mail.python.org/mailman/listinfo/python-list

Re: Python ++ Operator?

2011-07-15 Thread Björn Lindqvist
ates to i. Pre and post-increments are almost always confusing unless they are used as the counter-variable inside for-loops. -- mvh/best regards Björn Lindqvist http://www.footballexperts.net/ -- http://mail.python.org/mailman/listinfo/python-list

KeyboardInterrupt and DiskIO

2010-04-27 Thread Björn Lindqvist
DiskIO appears to not be interruptable. For example: >>> open('bighugefile.sql').read() Pressing Ctrl-C (on Linux with python 2.6.4) will not interrupt the command. I believe that it used to in previous versions of python but I may be mistaken. Is it supposed to be that way? The behavior is annoy

Re: The rap against "while True:" loops

2009-10-10 Thread Björn Lindqvist
I have many times screwed up "while True"-loops. When I thought I had a safe exit condition which turned out to be never reached in some rare corner cases. Leading to weird bugs with hanging threads. I have seen colleges screw up in the same way too. Often it is possible to reformulate "while True"

Re: Split string but ignore quotes

2009-09-29 Thread Björn Lindqvist
2009/9/29 Scooter : > I'm attempting to reformat an apache log file that was written with a > custom output format. I'm attempting to get it to w3c format using a > python script. The problem I'm having is the field-to-field matching. > In my python code I'm using split with spaces as my delimiter.

Re: Python word to text

2009-09-01 Thread BJörn Lindqvist
2009/9/1 Tino Wildenhain : > Am 01.09.2009 13:42, schrieb Nitebirdz: >> >> On Tue, Sep 01, 2009 at 11:38:30AM +0200, BJörn Lindqvist wrote: >>> >>> Hello everybody, >>> >>> I'm looking for a pure Python solution for converting word documents

Re: Python word to text

2009-09-01 Thread BJörn Lindqvist
2009/9/1 Nitebirdz : > On Tue, Sep 01, 2009 at 11:38:30AM +0200, BJörn Lindqvist wrote: >> Hello everybody, >> >> I'm looking for a pure Python solution for converting word documents >> to text. App Engine doesn't allow external programs, which means that

Python word to text

2009-09-01 Thread BJörn Lindqvist
Hello everybody, I'm looking for a pure Python solution for converting word documents to text. App Engine doesn't allow external programs, which means that external programs like catdoc and antiword can't be used. Anyone know of any? Thanks in advance. -- mvh Björn -- http://mail.python.org/m

Re: Graphical library - charts

2009-06-22 Thread BJörn Lindqvist
2009/6/22 : > Hello, > > I have thousends of files with logs from monitoring system. Each file > has some important data (numbers). I'd like to create charts using those > numbers. Could you please suggest library which will allow creating > such charts ? The preferred chart is line chart. > > Bes

Re: Self function

2009-05-04 Thread BJörn Lindqvist
2009/5/4 : > An idea-syntax: > > def fact(n): >    return 1 if n <= 1 else n * inspect.self(n - 1) > > Or even a lambda, because you don't need the name anymore to call the > function: > > fact = lambda n: 1 if n <= 1 else n * self(n - 1) How would it work with methods? class Foo: def fac(se

Re: Is there a programming language that is combination of Python and Basic?

2009-04-18 Thread BJörn Lindqvist
I first started programming basic and i don't think it has hurt me much. I can somewhat sympathise with the op, neither python nor any other mainstream language can still do this: SCREEN 13 PSET 160,100,255 2009/4/17, Leguia, Tony : > Though I don't know why you would want to reference lines nu

Heuristically processing documents

2009-03-19 Thread BJörn Lindqvist
I have a large set of documents in various text formats. I know that each document contains its authors name, email and phone number. Sometimes it also contains the authors home address. The task is to find out the name, email and phone of as many documents as possible. Since the documents are not

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-11 Thread BJörn Lindqvist
2009/1/11 Madhusudan.C.S : > Django's code for some reason. I have now strongly started feeling if > Python really follows its > "Readability Counts" philosophy. For example, > >class A: >a = 10 >b = "Madhu" > >def somemethod(self, arg1): >self.c = 20.22 >d = "some l

Re: "as" keyword woes

2008-12-09 Thread BJörn Lindqvist
2008/12/4 Chris Mellon <[EMAIL PROTECTED]>: > Aside from the cultural indoctrination, though (and that may be a real > and strong force when dealing with math software, and I don't want to > discount it in general, just for purposes of this discussion) why is > it more sensible to use "x" here inst

Re: Workflow engine?

2008-11-10 Thread BJörn Lindqvist
2008/11/10 Grzegorz Staniak <[EMAIL PROTECTED]>: > On 09.11.2008, Tino Wildenhain <[EMAIL PROTECTED]> wroted: > >> The common denonimator of a workflow (state engine) is so simple, the >> only complexity comes from the environment it needs to drive. >> >> So in short: I doubt there is a general sol

Re: Improving interpreter startup speed

2008-10-29 Thread BJörn Lindqvist
2008/10/27 James Mills <[EMAIL PROTECTED]>: > On Mon, Oct 27, 2008 at 5:40 PM, David Cournapeau <[EMAIL PROTECTED]> wrote: >> Depends on the tool: build tool and source control tools are example >> it matters (specially when you start interfaciing them with IDE or >> editors). Having fast command l

Re: Improving interpreter startup speed

2008-10-26 Thread BJörn Lindqvist
2008/10/26 James Mills <[EMAIL PROTECTED]>: > On Sun, Oct 26, 2008 at 11:23 AM, BJörn Lindqvist <[EMAIL PROTECTED]> wrote: >> How are you getting those numbers? 330 μs is still pretty fast, isn't >> it? :) Most disks have a seek time of 10-20 ms so it seem implaus

Re: Improving interpreter startup speed

2008-10-25 Thread BJörn Lindqvist
2008/10/25 Pedro Borges <[EMAIL PROTECTED]>: > Is there a way to improve the interpreter startup speed? > > In my machine (cold startup) python takes 0.330 ms and ruby takes > 0.047 ms, after cold boot python takes 0.019 ms and ruby 0.005 ms to > start. How are you getting those numbers? 330 μs is

Re: arange randomly words in a list

2008-10-25 Thread BJörn Lindqvist
2008/10/20 william paul <[EMAIL PROTECTED]>: > I have a list that looks like: > > name = name1 name2 name3 name4 > > and I would like to be able to arrange randomly this list, like: > > name = name 2 name 1 name3 name4 > name = name4 name2 name1 name3 > > > I have tried with random.shuffle, bu

Re: How to write verbose scripts

2008-09-03 Thread BJörn Lindqvist
2008/9/3 Hendrik van Rooyen <[EMAIL PROTECTED]>: > > Steven D'Aprano wrote: > >>Is there a better way of doing this than the way I am going about it? > > Not sure if its "better", but I would keep the messages in a table or dict and > have different tables or dicts for different levels of verbosit

Re: How to search the Python manuals

2008-08-24 Thread BJörn Lindqvist
2008/8/22 Terry Reedy <[EMAIL PROTECTED]>: [snip] > On the left, click [+] for Language Reference > (3.0: The Python language reference). "Language Reference (for language lawyers)" Language Lawyer? That's almost as worser than Grammar Nazi, no wonder no one is finding anything there. -- mvh

Re: Should Python raise a warning for mutable default arguments?

2008-08-23 Thread BJörn Lindqvist
2008/8/22 Peter Otten <[EMAIL PROTECTED]>: > [EMAIL PROTECTED] wrote: > >> DrScheme is an implementation of Scheme that is very newbie-friendly. >> It has several limited sub-languages, etc. >> >> So maybe a command line option can be added to Python3 ( - >> newbie ? :-) ) that just switches on sim

Re: learning unit testing in python

2008-06-23 Thread BJörn Lindqvist
On Mon, Jun 23, 2008 at 2:55 PM, Alex <[EMAIL PROTECTED]> wrote: > Hi all. > > I'd like learn some basic unit testing with python. > I red some articles about different testing framework like unittest or > nose, but I'm a bit confused: what is the best choice? I'm not a > professional developer (I'

Re: Summing a 2D list

2008-06-13 Thread BJörn Lindqvist
On Thu, Jun 12, 2008 at 3:48 PM, Mark <[EMAIL PROTECTED]> wrote: > Hi all, > > I have a scenario where I have a list like this: > > UserScore > 1 0 > 1 1 > 1 5 > 2 3 > 2 1 > 3 2 > 4

Re: Summing a 2D list

2008-06-13 Thread BJörn Lindqvist
On Fri, Jun 13, 2008 at 2:12 PM, Karsten Heymann <[EMAIL PROTECTED]> wrote: > Although your problem has already been solved, I'd like to present a > different approach which can be quite a bit faster. The most common > approach seems to be using a dictionary: > > summed_up={} > for user,vote in pai

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

2008-06-07 Thread BJörn Lindqvist
On Wed, Jun 4, 2008 at 2:02 PM, Antoon Pardon <[EMAIL PROTECTED]> wrote: > Now of course noone would defend such a limitation on the grounds > that one doesn't need the general case and that the general case > will only save you some vertical space. > > But when it came to the ternary operator that

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

2008-06-03 Thread BJörn Lindqvist
On Mon, Jun 2, 2008 at 10:50 PM, Russ P. <[EMAIL PROTECTED]> wrote: > On Jun 2, 6:41 am, Carl Banks <[EMAIL PROTECTED]> wrote: > >> You are not realizing that only useful(**) thing about data hiding is >> that some code has access to the data, other code does not. If you >> "hide" data equally fro

Re: Compare 2 files and discard common lines

2008-05-29 Thread BJörn Lindqvist
Open('3rd', 'w').writelines(set(open('2nd').readlines())-set(open('1st'))) 2008/5/29, loial <[EMAIL PROTECTED]>: > I have a requirement to compare 2 text files and write to a 3rd file > only those lines that appear in the 2nd file but not in the 1st file. > > Rather than re-invent the wheel I am w

Re: design choice: multi-threaded / asynchronous wxpython client?

2008-04-27 Thread BJörn Lindqvist
I think twisted is overkill for this problem. Threading, elementtree and urllib should more than suffice. One thread polling the server for each race with the desired polling interval. Each time some data is treated, that thread sends a signal containing information about what changed. The gui list

Re: ANN: pry unit testing framework

2008-04-05 Thread BJörn Lindqvist
On Sat, Apr 5, 2008 at 12:54 PM, Aldo Cortesi <[EMAIL PROTECTED]> wrote: > Thus spake Matthieu Brucher ([EMAIL PROTECTED]): > > > > How does it compare to the nose framework ? > > As far as the base unit testing functionality is concerned, I think > they try to address similar problems. Both hav

Re: removing all instances of a certain value from a list

2008-03-19 Thread BJörn Lindqvist
On Wed, Mar 19, 2008 at 10:28 PM, Lee Sander <[EMAIL PROTECTED]> wrote: > Hi, > I have a float array ( eg [-1.3, 1.22, 9.2, None, 2.3] ) but there are > many missing vlaues which are represented as None. I would like to > remove all such instances in one go. > There is a remove function but it

Re: Interesting math problem

2008-03-19 Thread BJörn Lindqvist
On Mon, Mar 17, 2008 at 11:57 PM, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > > def make_slope(distance, parts): > > step = distance / float(parts) > > intstep = int(step) > > floatstep = step - intstep > > > > steps = [] > > acc = 0.0 > > for i in range(parts): >

Interesting math problem

2008-03-17 Thread BJörn Lindqvist
Here is an interesting math problem: You have a number X > 0 and another number Y > 0. The goal is to divide X into a list with length Y. Each item in the list is an integer. The sum of all integers is X. Each integer is either A or A + 1, those should be "evenly distributed." Example: 17 // 5 =

Re: PyCon Feedback and Volunteers (Re: Pycon disappointment)

2008-03-16 Thread BJörn Lindqvist
On Mon, Mar 17, 2008 at 12:32 AM, Paul Boddie <[EMAIL PROTECTED]> wrote: > On 17 Mar, 01:09, [EMAIL PROTECTED] (Aahz) wrote: > > > > PyCon is what YOU make of it. If you want to change PyCon, propose a > > presentation or join the conference committee (concom) -- the latter only > > requires s

Re: List mutation method gotcha - How well known?

2008-03-13 Thread BJörn Lindqvist
On Thu, Mar 13, 2008 at 8:36 AM, Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > foo = [1,2,3,4] > x = foo.append(5) > print x > > What will be the output (choose one): > > 1) [1,2,3,4] > 2) [1,2,3,4,5] > 3) That famous picture of Albert Einstein sticking out his tongue > 4) Nothing - n

Re: for-else

2008-03-04 Thread BJörn Lindqvist
On Tue, Mar 4, 2008 at 4:17 PM, Carl Banks <[EMAIL PROTECTED]> wrote: > > for ...: > > ... > > exhausted: > > ... > > broken: > > ... > > > > The meaning is explicit. While "else" seems to mean little there. > > So I may like something similar for Python 3.x (or the removal of

Re: Does anyone else use this little idiom?

2008-02-04 Thread BJörn Lindqvist
> In Python, the direct translation of this is a for loop. When the > index doesn't matter to me, I tend to write it as: > > for _ in xrange (1,n): >some code > > An alternative way of indicating that you don't care about the loop > index would be > > for dummy in xrange (1,n): >some code

Re: Can someone explain this unexpected raw_input behavior?

2008-01-24 Thread BJörn Lindqvist
On Jan 24, 2008 8:08 AM, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Thu, 24 Jan 2008 01:00:53 -0200, Mike Kent <[EMAIL PROTECTED]> escribió: > > > Gabriel, thank you for clarifying the source of this behavior. Still, > > I'm surprised it would be hard-coded into Python. Consider an > > int

Re: "do" as a keyword

2007-12-13 Thread BJörn Lindqvist
On Dec 11, 2007 4:06 PM, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > However, did you have an specific need for a do-while construct? > Perhaps we could show you the alternatives. I have wanted do-while loops in exactly one kind of algorithms, when you generate something and you have to keep tryin

Re: the annoying, verbose self

2007-11-26 Thread BJörn Lindqvist
On Nov 24, 2007 11:55 AM, jakub silar <[EMAIL PROTECTED]> wrote: > Below is my coding standard - I'm lazy, even lazy to persuade > comutinties into strange (imho) language syntax extensions. > > > class Vector: > def __init__(s, x, y, z): > s.x = x > s.y = y

Re: the annoying, verbose self

2007-11-23 Thread BJörn Lindqvist
On Nov 23, 2007 11:54 PM, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Fri, 23 Nov 2007 23:38:24 +, BJörn Lindqvist > wrote: > > > I like that a lot. This saves 12 characters for the original example and > > removes the need to wrap it. > > > >

Re: the annoying, verbose self

2007-11-23 Thread BJörn Lindqvist
On Nov 22, 2007 2:08 PM, Colin J. Williams <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Alexy: > >> Sometimes I > >> avoid OO just not to deal with its verbosity. In fact, I try to use > >> Ruby anywhere speed is not crucial especially for @ prefix is better- > >> looking than self. >

Re: Iterator for circulating a list

2007-11-13 Thread BJörn Lindqvist
On Nov 13, 2007 3:43 PM, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Tue, 2007-11-13 at 15:12 +0100, BJörn Lindqvist wrote: > > L = somelist > > > > idx = 0 > > while True: > > item = L[idx] > > # Do something with item > >

Iterator for circulating a list

2007-11-13 Thread BJörn Lindqvist
L = somelist idx = 0 while True: item = L[idx] # Do something with item idx = (idx + 1) % len(L) wouldn't it be cool if there was an itertool like this: def circulate(L, begin = 0, step = 1): idx = begin while True: yield L[idx] idx = (idx + step) % len(L) f

Re: pytz has so many timezones!

2007-10-08 Thread BJörn Lindqvist
On 10/8/07, Sanjay <[EMAIL PROTECTED]> wrote: > Hi All, > > I am using pytz.common_timezones to populate the timezone combo box of > some user registration form. But as it has so many timezones (around > 400), it is a bit confusing to the users. Is there a smaller and more > practical set? If not,

Re: using inspect on pygtk

2007-10-01 Thread BJörn Lindqvist
On 9/29/07, Chris Pax <[EMAIL PROTECTED]> wrote: > Hello, > > I recently been trying to use the inspect module to inspect the > arguments of gtk objects, such as gtk.Button. I tried like this: > > inspect.getargspec(gtk.Button.__init__) > > and get the fallowing error: > > File "", line 1, in >

Re: SVG to raster conversion.

2007-09-17 Thread BJörn Lindqvist
On 9/16/07, J. Cliff Dyer <[EMAIL PROTECTED]> wrote: > Does anybody know a good solution (preferably in python) for rasterizing > SVG or other vector graphics. > > I'm thinking something like > > vector_image = SVGFile(path_to_image) > raster_image = vector_image.rasterize(format, (width, height),

Re: Try this

2007-09-17 Thread BJörn Lindqvist
On 9/16/07, GeorgeRXZ <[EMAIL PROTECTED]> wrote: > Well you are speed That's an awesome party trick! But before I mail this to everyone at the office, must have a better sentence. Well you are speed is to gibberish. Something microsoft+evil... hm.. -- mvh Björn -- http://mail.python.org/mailman

Re: Needless copying in iterations?

2007-09-16 Thread BJörn Lindqvist
On 9/16/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > Maybe I'm being unfair, but it seems to me that the attitude is similar: > 'there's no point optimizing the common case of printing (say) ints > stored in a list, Just In Case the programmer wants the incredibly rare > case of setting sys.std

Re: newbie: self.member syntax seems /really/ annoying

2007-09-13 Thread BJörn Lindqvist
On 9/12/07, Dave Hansen <[EMAIL PROTECTED]> wrote: > The name "self" is just a convention. You can give it any name you > wish. Using "s" is common. Not it's not common. And the name "self" is a convention codified in PEP8 which you shouldn't violate. And I agree with the OP that the convention

[ANN] GtkImageView 1.5.0 and PyGtkImageView 1.0.0 -- Image viewer widget for GTK

2007-09-10 Thread BJörn Lindqvist
I'm pleased to finally announce GtkImageView 1.5.0. I'm even more pleased to ALSO announce PyGtkImageView 1.0.0: Description --- GtkImageView is a simple image viewer widget for GTK+. Similar to the image viewer panes in gThumb or Eye of Gnome. It makes writing image viewing and editing ap

Re: list index()

2007-08-31 Thread BJörn Lindqvist
On 8/30/07, Carsten Haese <[EMAIL PROTECTED]> wrote: > Is the Pythonic way > > try: > i = somelist.index(thing) > # Do something with i > except IndexError: > # Do something if thing not found That is not the Pythonic way. "# Do something with i" might also raise an IndexError and they

Re: advice about `correct' use of decorator

2007-08-29 Thread BJörn Lindqvist
On 8/24/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Thu, 23 Aug 2007 09:20:21 -0300, BJörn Lindqvist <[EMAIL PROTECTED]> > escribi�: > > > def check_user_logged_in(func): > > def f(*args, **kwargs): > > if global_state.the_user.is_logge

Re: advice about `correct' use of decorator

2007-08-23 Thread BJörn Lindqvist
On 8/22/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > On 22 ago, 10:00, "BJörn Lindqvist" <[EMAIL PROTECTED]> wrote: > > As I said, you can accomplish the exact same thing by calling a > > function from within the function that requires the user to be l

Re: advice about `correct' use of decorator

2007-08-22 Thread BJörn Lindqvist
On 8/17/07, Gerardo Herzig <[EMAIL PROTECTED]> wrote: > BJörn Lindqvist wrote: > >def is_logued_in(): > >if not user.is_logged_in(): > >raise NotLoggedInError > > > >It costs you one more line, but reduces complexity. And if you are > >worr

Re: advice about `correct' use of decorator

2007-08-17 Thread BJörn Lindqvist
On 8/16/07, Gerardo Herzig <[EMAIL PROTECTED]> wrote: > @is_logued_in > def change_pass(): > bla > bla > > And so on for all the other functions who needs that the user is still > loged in. > > where obviosly the is_logued_in() function will determine if the dude is > still loged in, and TH

Re: decorators - more than just syntactic sugar

2007-08-14 Thread BJörn Lindqvist
On 8/13/07, Bjoern Schliessmann <[EMAIL PROTECTED]> wrote: > BJörn Lindqvist wrote: > > > unpedagogically not separated from ordinary functions. > > Decorators _are_ ordinary functions. Remember the "syntactic sugar" > in this thread? Remember also "t

Re: decorators - more than just syntactic sugar

2007-08-13 Thread BJörn Lindqvist
On 8/11/07, Helmut Jarausch <[EMAIL PROTECTED]> wrote: > How can I find out the predefined decorators? There are two in the standard library, @classmethod for declaring class methods and @staticmethod for declaring static methods. They are listed at the built ins page http://docs.python.org/dev/li

Re: Can a low-level programmer learn OOP?

2007-07-13 Thread BJörn Lindqvist
On 7/13/07, John Nagle <[EMAIL PROTECTED]> wrote: > You can sometimes get better performance in C++ than in C, because C++ > has "inline". Inline expansion happens before optimization, so you > can have abstractions that cost nothing. C99 has that too. > Python is a relatively easy lan

Re: What is the preferred doc extraction tool?

2007-07-09 Thread BJörn Lindqvist
On 7/9/07, Emin.shopper Martinian.shopper <[EMAIL PROTECTED]> wrote: > Dear Experts, > > What is the preferred doc extraction tool for python? It seems that there > are many very nice options (e.g., pydoc, epydoc, HappyDoc, and lots of > others), but what is the "standard" tool or at least what is

Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-04 Thread BJörn Lindqvist
On 6/22/07, Eduardo EdCrypt O. Padoan <[EMAIL PROTECTED]> wrote: > Remember that pure CPython has no different "compile time" and > runtiime. But Psyco and ShedSkin could use the annotations the way > they want. . > def compile(source: "something compilable", >filename: "where the c

Re: Q: listsort and dictsort - official equivalents?

2007-06-20 Thread BJörn Lindqvist
On 6/20/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > > It's not true that the sort must complete (or that the whole file must > > be read for that matter), Python has cool generators which makes the > > above possible. > > That's not possible, the input must be read completely before sorted()

Re: Q: listsort and dictsort - official equivalents?

2007-06-19 Thread BJörn Lindqvist
> In python I must kick off a sort on the line before I start the > iteration. (This does make sense because at the end of the day the sort > has complete BEFORE the for loop can proceed - that is... until the day > when python lists have a secondary index ;-). > > group_list=group_dict.keys() > g

Re: A patch to support L.count(value, cmp=None, key=None)

2007-06-18 Thread BJörn Lindqvist
> I patched Objects/listobject.c to support > L.count(value, cmp=None, key=None). > I tested it with the same script above by replacing slist > with built-in list. It worked correctly with this small > test. The patch is below (126 lines, I hope that's not Great! If you want this change includ

Re: a_list.count(a_callable) ?

2007-06-15 Thread BJörn Lindqvist
On 6/15/07, Ping <[EMAIL PROTECTED]> wrote: > > > > sum(1 for i in a_list if a_callable(i)) > > > > -- > > Carsten Haesehttp://informixdb.sourceforge.net > > This works nicely but not very intuitive or readable to me. > > First of all, the generator expression makes sense only to > trained eyes. S

Re: Select one of 2 functions with the same name ?

2007-06-10 Thread BJörn Lindqvist
On 6/10/07, Stef Mientki <[EMAIL PROTECTED]> wrote: > I can realize it with a simple switch within each function, > but that makes the code much less readable: > > def Some_Function(): >if simulation_level == 1: > ... do things in a way >elif simulation_level == 2: > ... do things

Re: itertools.groupby

2007-06-05 Thread BJörn Lindqvist
On 27 May 2007 10:49:06 -0700, 7stud <[EMAIL PROTECTED]> wrote: > On May 27, 11:28 am, Steve Howell <[EMAIL PROTECTED]> wrote: > > The groupby method has its uses, but it's behavior is > > going to be very surprising to anybody that has used > > the "group by" syntax of SQL, because Python's groupb

Re: Creating a distro of python... What would you include in it?

2007-05-30 Thread BJörn Lindqvist
On 30 May 2007 08:25:48 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I am creating a distro of Python to be licensed as GPL am > wondering, what would anyone suggest as to 3rd party modules being put > into it (non-commercial of course!)? I know I'd put MySQLdb into it at > the very le

Re: Is PEP-8 a Code or More of a Guideline?

2007-05-29 Thread BJörn Lindqvist
On 5/29/07, Eric S. Johansson <[EMAIL PROTECTED]> wrote: > A huge reason why this is important because the vast majority of software > developers who are injured fall off the economic ladder. They leave the > profession and had very few options for work that doesn't involve significant > handy is.

Re: Quote aware split

2007-05-16 Thread BJörn Lindqvist
How is the code different from shlex.split? -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list

Re: Is it possible to merge xrange and slice?

2007-04-30 Thread BJörn Lindqvist
On 30 Apr 2007 11:02:19 -0700, Bas <[EMAIL PROTECTED]> wrote: > stupid question, but would it be possible to somehow merge xrange > (which is supposed to replace range in py3k) and slice? Both have very > similar start, stop and step arguments and both are lightweight > objects to indicate a range.

Re: While we're talking about annoyances

2007-04-29 Thread BJörn Lindqvist
On 4/29/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > To do that, I needed to generate an index table first. In the book > "Numerical Recipes in Pascal" by William Press et al there is a procedure > to generate an index table (46 lines of code) and one for a rank table > (five lines). 51 lines

Re: is laziness a programer's virtue?

2007-04-17 Thread BJörn Lindqvist
On 4/17/07, Mirco Wahab <[EMAIL PROTECTED]> wrote: > The reason why I answered your posting at all (besides > seeing your x-post going into 5 ng's) is your mentioning > of 'God'. According to christian tradition (which is > somehow on topic in a Perl group) it is exactly the > case of Jesus (imho),

Re: function with list argument defaulting to [] - what's going on here???

2007-04-14 Thread BJörn Lindqvist
> This comes up so often that I wonder whether Python should issue a warning > when it sees [] or {} as a default argument. > > > What do people think? A misuse or good use of warnings? I think Python should reevaluate the default values. -- mvh Björn -- http://mail.python.org/mailman/listinfo/

Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread BJörn Lindqvist
On 4/14/07, BJörn Lindqvist <[EMAIL PROTECTED]> wrote: > On 14 Apr 2007 07:24:32 -0700, jamadagni <[EMAIL PROTECTED]> wrote: > > > You already can emulate the using statement like this: > > > > You can emulate only assignments like this. How would you emulate

Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread BJörn Lindqvist
On 14 Apr 2007 07:24:32 -0700, jamadagni <[EMAIL PROTECTED]> wrote: > > You already can emulate the using statement like this: > > You can emulate only assignments like this. How would you emulate > function calls, like the ones in my example? You can't, of course. But using the with statement: u

Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread BJörn Lindqvist
Your idea isn't new and has already been discussed lots of time before. It was once planned to be implemented in py3k, but no longer is. One of the problems is that with a "using" statement, you always have to decide whether your code repeats some prefix enough times to use a "using" statement. Sh

Re: tuples, index method, Python's design

2007-04-10 Thread BJörn Lindqvist
> > while not game_has_ended: > > for current_player in p: > > player_does_something(current_player) > > > > I'm curious why someone would even consider using a tuple in this case > regardless. I think that much of the desire for tuple.index is because > people use a tuple where they could ha

Re: tuples, index method, Python's design

2007-04-10 Thread BJörn Lindqvist
On 4/10/07, Carsten Haese <[EMAIL PROTECTED]> wrote: > > > opponents = tuple(x for x in p if x is not current_player) > > > > > Your alternative is wrong because it wont raise ValueError if > > current_player is not present in the tuple. Please revise your > > "solution." > > You have a point. Here

Re: tuples, index method, Python's design

2007-04-10 Thread BJörn Lindqvist
On 4/10/07, Steve Holden <[EMAIL PROTECTED]> wrote: > Paul Boddie wrote: > > On 10 Apr, 11:48, Antoon Pardon <[EMAIL PROTECTED]> wrote: > >> On 2007-04-10, Duncan Booth <[EMAIL PROTECTED]> wrote: > >> > >>> There is a cost to every new language feature: it has to be implemented, > >>> documented, m

Re: tuples, index method, Python's design

2007-04-10 Thread BJörn Lindqvist
On 4/10/07, Carsten Haese <[EMAIL PROTECTED]> wrote: > i = p.index(current_player) > opponents = p[:i-1] + p[i+1:] > > An alternative is this: > > opponents = tuple(x for x in p if x is not current_player) > > You may disagree, but in my opinion, the alternative is better because > it is a more nat

Re: Easy question: More items in a For loop?

2007-04-05 Thread BJörn Lindqvist
> Here is some sample tuna: > ['[7:55pm] My teachings goes back to the last iceage.\r\n', > '[7:55pm] <%Zack> ahh now it does\r\n', '[7:55pm] <%Zack> ok\r\n', > '[7:55pm] Or it is down just for you.\r\n', '[7:55pm] <@FC3> > which one? that -12000 ice age or the one before\r\n', '[7:55pm] > the e

Re: An error of matrix inversion using NumPy

2007-04-04 Thread BJörn Lindqvist
On 4 Apr 2007 06:15:18 -0700, lancered <[EMAIL PROTECTED]> wrote: > During the calculation, I noticed an apparent error of > inverion of a 19x19 matrix. Denote this matrix as KK, U=KK^ -1, I > found the product of U and KK is not equivalent to unit matrix! This > apparently violate the defi

Re: When is List Comprehension inappropriate?

2007-03-19 Thread BJörn Lindqvist
On 19 Mar 2007 07:41:59 -0700, Ben <[EMAIL PROTECTED]> wrote: > I have recently learned how list comprehension works and am finding it > extremely cool. I am worried, however, that I may be stuffing it into > places that it does not belong. > > What's the most "pythony" way to do this: > > even =

Re: Grep Equivalent for Python

2007-03-14 Thread BJörn Lindqvist
> I come from a shell/perl background and have just to learn python. To > start with, I'm trying to obtain system information from a Linux > server using the /proc FS. For example, in order to obtain the amount > of physical memory on the server, I would do the following in shell: > > grep ^MemTo

Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread BJörn Lindqvist
On 9 Mar 2007 02:31:14 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Thanks for the thoughts. > > > This could be implemented without new syntax: just make your editor > > recognize some special comments, and apply the highlighting to the > > following block. By example, > > > >

Re: Interface Implementation in Python

2007-03-06 Thread BJörn Lindqvist
On 5 Mar 2007 16:25:03 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, > > I would like to know the interface concept in Python.How the > Interface is defined and implemented in Python?. > > How to access the interface fromn Client? You have a class with methods and data. You write many

Re: class declaration shortcut

2007-03-01 Thread BJörn Lindqvist
On 28 Feb 2007 13:53:37 -0800, Luis M. González <[EMAIL PROTECTED]> wrote: > Hmmm... not really. > The code above is supposed to be a shorter way of writing this: > > class Person: > def __init__(self, name, birthday, children): > self.name = name > self.birthday = birthday >

Re: Python 3.0 unfit for serious work?

2007-02-20 Thread BJörn Lindqvist
On 2/20/07, Jeff Templon <[EMAIL PROTECTED]> wrote: > Bjorn, I am not sure I see why my post is bull crap. I think all you > are doing is agreeing with me. My post was entitled "Python 3.0 unfit > for serious work", you just indicated that the Linux distros will > agree with me, in order to be ta

Re: Python 3.0 unfit for serious work?

2007-02-20 Thread BJörn Lindqvist
What a load of bull crap. Python is one of the simplest packages to have multiple version of installed. When Python 3.0 is released, all Linux distros will acquire a symlink at /usr/bin/python2 pointing to the latest Python 2.x version installed. Or something equivalent. Rest assured that Linux dis

Re: Pep 3105: the end of print?

2007-02-16 Thread BJörn Lindqvist
On 2/16/07, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > I was just pointing out that some people might be confused. I didn't make > any judgement about that fact. You seem to be suggesting that because there > are other confusing things, it's okay for Python to be confusing too. I'm > not m

Re: f---ing typechecking

2007-02-15 Thread BJörn Lindqvist
On 2/15/07, James Stroud <[EMAIL PROTECTED]> wrote: > I guess we differ on what is obvious. This seems obvious to me: > > [1] + (1,) => [1, 1] > (1,) + [1] => (1, 1) I agreed with you up to this point. But this seems more obvious to me: [1] + (1,) => [1, 1] (1,) + [1] => [1, 1] In other language

Re: compound statement from C "?:"

2007-02-11 Thread BJörn Lindqvist
On 11 Feb 2007 16:57:07 -0800, Carl Banks <[EMAIL PROTECTED]> wrote: > You don't need any ternary operator to avoid repetition, anyways. You > could factor the common parts out like this: > > if n == 1: > what = "a car" > else: > what = "%d cars" % n > print "I saw %s" % what Or even bett

Re: Why doesn't my heapify work?

2007-02-07 Thread BJörn Lindqvist
You do know about the heapq module? http://docs.python.org/dev/lib/module-heapq.html -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list

Re: in place-ness of list.append

2007-02-05 Thread BJörn Lindqvist
On 2/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Bart> #-- > Bart> def addnumber(alist, num): > Bart> """ work around the inplace-ness of .append """ > Bart> mylist = alist[:] > Bart> mylist.append(num) >

Re: Inheriting str object

2007-02-05 Thread BJörn Lindqvist
On 5 Feb 2007 02:48:08 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I want to have a str with custom methods, but I have this problem: > > class myStr(str): > def hello(self): > return 'hello '+self > > s=myStr('world') > print s.hello() # prints 'hello world' > s=s.upper() > p

Re: division by 7 efficiently ???

2007-02-01 Thread BJörn Lindqvist
This is maybe not so efficient :) but it implements integer division by 7 for positive integers without - and /. def div2(num): return num >> 1 def div4(num): return num >> 2 def div8(num): return num >> 3 def mul2(num): return num << 1 def mul4(num): return num << 2 def m

Re: data design

2007-01-31 Thread BJörn Lindqvist
On 1/31/07, James Stroud <[EMAIL PROTECTED]> wrote: > [copy_files] > files_dir1 = this.file that.file > path_dir1 = /some/path > > files_dir2 = the_other.file yet_another.file > path_dir2 = /some/other/path > > In yaml, it might look thus. > > copy_files : > - files : [this.file, that.file] >

Re: How can I know both the Key c and Ctrl on the keyboard are pressed?

2007-01-30 Thread BJörn Lindqvist
On 30 Jan 2007 05:44:40 -0800, Szabolcs Nagy <[EMAIL PROTECTED]> wrote: > however Ctrl+C is a special key combination: running python in a unix > terminal it raises KeyboardInterrupt exception, imho in a windows cmd > promt it raises SystemExit No it is KeyboardInterrupt in Windows too. -- mvh B

Re: Getting to an SSH account over a HTTP proxy

2007-01-25 Thread BJörn Lindqvist
On 1/22/07, Yu-Xi Lim <[EMAIL PROTECTED]> wrote: > He's referring to the HTTP CONNECT method, which can tunnel arbitrary > TCP connections, not just HTTP. The IETF draft for this is titled > "Tunneling TCP based protocols through Web proxy servers". > > AFAIK, there are no Python modules which supp

  1   2   >