Re: How to show percentage

2005-09-22 Thread George Sakkis
"Sen-Lung Chen" <[EMAIL PROTECTED]> wrote: > Dear All: > I have a question of show percentage. > For example ,I want to show the percentage of 1/3 = 33.33% > > I use the 1*100/3 = 33 > it is 33 not 33.33 , how to show the 33.33 % > Thanks "%.2f%%" % (100./3.) Not quite the most readable expres

Re: Newbie regular expression and whitespace question

2005-09-22 Thread George Sakkis
"googleboy" <[EMAIL PROTECTED]> wrote: > Hi. > > I am trying to collapse an html table into a single line. Basically, > anytime I see ">" & "<" with nothing but whitespace between them, I'd > like to remove all the whitespace, including newlines. I've read the > how-to and I have tried a bunch of

Re: Using distutils 2.4 for python 2.3

2005-09-23 Thread George Sakkis
"Noam Raphael" <[EMAIL PROTECTED]> wrote: > Hello, > > I want to distribute a package. It's compatible with Python 2.3. > Is there a way to use distutils 2.4 feature package_data, while > maintaining the distribution compatible with python 2.3 ? > > Thanks, > Noam Raphael You could distribute the

Re: Most direct way to strip unoprintable characters out of a string?

2005-09-24 Thread George Sakkis
"Steve Bergman" <[EMAIL PROTECTED]> wrote: > When sanitizing data coming in from HTML forms, I'm doing this (lifted > from the Python Cookbook): > > from string import maketrans, translate, printable > allchars = maketrans('','') > delchars = translate(allchars, allchars, printable) > input_string

Re: Parsing an HTML a tag

2005-09-24 Thread George Sakkis
"Stephen Prinster" <[EMAIL PROTECTED]> wrote: > George wrote: > > How can I parse an HTML file and collect only that the A tags. I have a > > start for the code but an unable to figure out how to finish the code. > > HTML_parse gets the data from the URL document. Thanks for the help > > Have you t

Re: Parsing an HTML a tag

2005-09-24 Thread George Sakkis
"George" <[EMAIL PROTECTED]> wrote: > I'm very new to python and I have tried to read the tutorials but I am > unable to understand exactly how I must do this problem. > > Specifically, the showIPnums function takes a URL as input, calls the > read_page(url) function to obtain the entire page for

Re: Most direct way to strip unoprintable characters out of a string?

2005-09-25 Thread George Sakkis
"Steve Bergman" <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > > > > > >If by straightforward you mean one-liner, there is: > >''.join(c for c in input_string if c not in string.printable) > > > >If you care about perform

Re: unittest setup

2005-09-25 Thread George Sakkis
"paul kölle" <[EMAIL PROTECTED]> wrote: > > [snipped] > > It seems to me my case is not that exotic, I thought it would be quite > natural to write the boilerplate stuff in setUp() and build on that to > step through the applications state with test* methods each building on > top of each other. Is

Re: Struggling with basics

2005-09-25 Thread George Sakkis
"Jason" <[EMAIL PROTECTED]> wrote: > What I'd like to know is do you think it would be better to sort the > list in memory, or print it out sorted? If the latter, then naturally > I'd need to change the showScores section to show the list in a reverse > order. But, would sorting the list in memo

Re: Struggling with this concept please help

2005-09-25 Thread George Sakkis
"George" <[EMAIL PROTECTED]> wrote: > Hello everyone I know many have helped but I cannot get this to work > out correctly. I cannot use BeautifulSoup at all. I need to: > [snipped] What do you mean you cannot use BeautifulSoup ? You cannot download it, install it, import it, or you are not allo

Re: PEP 350: Codetags

2005-09-26 Thread George Sakkis
"Paul Rubin" wrote: > I'm opposed to pretty much every proposal of this sort. If you want > to propose adding a feature to the language, add it in a way that the > compiler can know about it and notice when it's not used correctly. > Mere conventions that are not checke

Sparse matrices

2005-09-26 Thread George Sakkis
Is there any sparse matrix package compatible with Numeric/Numarray ? Ideally, the implementation of a matrix (dense/sparse) should be transparent to the application. However the APIs of the only packages I'm aware of -- the Sparse module in Scipy and PySparse --are both pretty incomplete compar

Re: backreferences

2005-09-28 Thread George Sakkis
"Amy Dillavou" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Can someone help me with understanding how python uses backreferences? > I need to remember the item that was last matched by the re engine but i > cant seem to understand anything that I find on backreferences. if I > w

Re: grouping array

2005-09-29 Thread George Sakkis
<[EMAIL PROTECTED]> wrote: > hi if I have an array > > say x = [[2,2,0,0,1,1], > [1,1,0,0,1,1], > [1,1,0,0,1,1]] > I basically want to group regions that are non zero like I want to get > the coordinates of non zero regions..as (x1,y1,x2,y2) > [(0,0,2,1),(0,4,2,5)] which show the

Re: Opinion on Pyrex

2005-09-30 Thread George Sakkis
"Carl" <[EMAIL PROTECTED]> wrote: > I have recently started to use Pyrex and am amazed by it's useability. > > Are there any alternatives to Pyrex? > > One thing that I haven't figured out is how to embed pure C/C++ source code > into Pyrex. For example, if you have a bunch of C files that you wan

Re: "no variable or argument declarations are necessary."

2005-10-02 Thread George Sakkis
"Michael" <[EMAIL PROTECTED]> wrote: > James A. Donald wrote: > > On Sun, 02 Oct 2005 17:11:13 -0400, Jean-Francois Doyon > > James A. Donald: > >> > Surely that means that if I misspell a variable name, my program will > >> > mysteriously fail to work with no error message. > >> No, the error m

Re: "no variable or argument declarations are necessary."

2005-10-03 Thread George Sakkis
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote > [snipped] > No compiler will catch this error: > > x = 12.0 # feet > # three pages of code > y = 15.0 # metres > # three more pages of code > distance = x + y > if distance < 27: > fire_retro_rockets() Actually modern compilers can (http://www.bo

Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-07 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote: > Ok, that one looks more sleak than what I came up with. For the most efficient and elegant solution, check out Raymond Hettinger's reply to: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/141934 George -- http://mail.python.org

Re: Python recipes: list mixin, improved timeit, etc

2005-10-07 Thread George Sakkis
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > I've just found this: > > [quote] > A mixin class is a parent class that is inherited from - but not as > a means of specialization. Typically, the mixin will export services to a > child class, but no semantics will be implied about the child "being

Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-07 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote: > Thanks, that looks like Mike's solution except that it uses the > built-in heapq module. This make a big difference for the algorithmic complexity; replacing an item in a heap is much more efficient than sorting the whole list. > While this

Re: Objects with different data views

2005-10-07 Thread George Sakkis
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > I'm not sure how to do this, or where to start looking for the right > information, so any advice would be appreciated. > > I want to implement a class with two (or more) different ways of looking > at its attributes. > > One example of this might be

Re: Best way to share a python list of objects

2005-10-07 Thread George Sakkis
"kyle.tk" <[EMAIL PROTECTED]> wrote: > So I have a central list of python objects that I want to be able to > share between different process that are possibly on different > computers on the network. Some of the processes will add objects to > list and another process will be a GUI that will view

Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-08 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > George Sakkis <[EMAIL PROTECTED]> wrote: > > >>Yes, it's a little inconvenient that the builtin heap doesn't take a > >>comparison operation but you ca

Re: Function decorator that caches function results

2005-10-08 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote: > [snip] > > Ok, so I thought, how about creating a decorator that caches the > function results and retrieves them from cache if possible, otherwise it > calls the function and store the value in the cache for the next invokation. > > [snip] C

Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-08 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > > Just added a recipe at > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440673. You can try > > both and see if there's any significant performance diffe

Re: how do you pronounce wxpython

2005-10-08 Thread George Sakkis
"Alex" <[EMAIL PROTECTED]> wrote: > My native language is not English so I just wonder how you pronounce > wxPython. > > vi-ex python > double-you-ex python > wax-python > > or something else > > Thanks I am sure it is pronounced the same way as wxWidgets . George -- http://mail.python.org/ma

Re: Python reliability

2005-10-09 Thread George Sakkis
Steven D'Aprano wrote: > On Sun, 09 Oct 2005 23:00:04 +0300, Ville Voipio wrote: > > > I would need to make some high-reliability software > > running on Linux in an embedded system. Performance > > (or lack of it) is not an issue, reliability is. > > [snip] > > > The software should be running co

Re: Newbie Count Question

2005-10-09 Thread George Sakkis
"ProvoWallis" wrote: > I've managed to get this far thanks to looking at other > posts on the board but no matter waht I try all of the > sections end up being numbered for the total number of > sections in the document. e.g., if there are 100 sections > in the document the "no" attribute is "1.10

Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-10 Thread George Sakkis
"Alex Martelli" <[EMAIL PROTECTED]> wrote: > George Sakkis <[EMAIL PROTECTED]> wrote: >... > > > manipulation of a heap to place an item in the right spot, but with 4-5 > > > or a few more sources might not make an impact at all. > > &

Re: best Pythonic way to do this sort: Python newb

2005-10-10 Thread George Sakkis
"Satchidanand Haridas" <[EMAIL PROTECTED]> wrote: > >So, I want to sort myList by the return of myFunction( value3 ) > > > >I tried doing the following... with no luck so far > >myList.sort(lambda x, y: cmp(myFunction(x[2]), myFunction(y[2])) > > > > > > > I think the above statement should be as

Re: Comparing lists

2005-10-10 Thread George Sakkis
"Christian Stapfer" <[EMAIL PROTECTED]> wrote: > <[EMAIL PROTECTED]> wrote: > > try to use set. > > Sorting the two lists and then extracting > A-B, B-A, A|B, A & B and A ^ B in one single > pass seems to me very likely to be much faster > for large lists. Why don't you implement it, test it

set.__getstate__ not overriden

2005-10-10 Thread George Sakkis
>>> import pickle >>> class Foo(set): ... def __getstate__(self): assert False >>> pickle.dumps(Foo()) # doesn't raise AssertionError The same happens with frozenset. Before I submit it to the bugs tracker, is there a chance this is a 'feature' ? George -- http://mail.python.org/mailman/li

Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-10 Thread George Sakkis
"Dave Hansen" <[EMAIL PROTECTED]> wrote: > On Mon, 10 Oct 2005 16:42:34 -0500, Terry Hancock > <[EMAIL PROTECTED]> wrote: > > >On Sunday 09 October 2005 07:50 am, phil hunt wrote: > >> On Fri, 7 Oct 2005 01:05:12 -0500, Terry Hancock <[EMAIL PROTECTED]> wrote: > >> >GvR's syntax has the advantage

Re: How to do *args, **kwargs properly

2005-10-11 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote: > So what you're saying is that instead of: > > def fn(*values, **options): > > I should use: > > def fn(values, cmp=cmp): > > in this specific case? > > and then instead of: > > fn(1, 2, 3, cmp=...) > > this: > > fn([1, 2, 3], cmp=...) > > > >

Re: Merging sorted lists/iterators/generators into one stream of values...

2005-10-11 Thread George Sakkis
> Function name is perhaps not the best one. It occurs to me that this > is the GROUP BY in SQL so perhaps a different name is better, but > then again this might be moot if such a already exists somewhere :) Amazing, you keep reinventing things, even with the exact same name :) from itertools im

Re: A Tree class, my $0.02 contribution to the python community.

2005-10-12 Thread George Sakkis
"Antoon Pardon" <[EMAIL PROTECTED]> wrote: > Comments are welcome: > > http://www.pardon-sleeuwaegen.be/antoon/avltree.html How about adding two shortcut methods, nextkey(k) and prevkey(k), to return the next and previous key respectively ? For instance nextkey would be equivalent to (untested)

Re: Multiple assignments simplification

2005-10-12 Thread George Sakkis
<[EMAIL PROTECTED]> wrote: > [snipped] > > Do you know some algorithm (or you can give some suggestions) to > minimize the number of simple assignments needed for a "regular" > situation like that? You can formulate the task as a graph-theoretic problem by representing the set of assignments as

Re: how to make this code faster

2005-10-13 Thread George Sakkis
<[EMAIL PROTECTED]> wrote: > hello, > > I found that scipy only works with python 2.3 or? You can use Numeric instead of scipy if you need/want to: from Numeric import arange,reshape,sin def computeMatrix(n): xcoor = arange(0,1,1/float(n)) ycoor = reshape(xcoor, (n,1)) return sin(xc

Re: NYLUG meeting: The Python Object Model with Alex Martelli & Google(open bar and food!)

2005-10-14 Thread George Sakkis
"Ron Guerin" <[EMAIL PROTECTED]> wrote: > The New York Linux User's Group invites you to a special presentation > by Alex Martelli of Google, on the Python Object Model. This > presentation will be held at P.J. Clarke's Sidecar, rather than our > usual location, and Google is picking up the tab f

Re: Searching files in directories

2005-10-14 Thread George Sakkis
"Larry Bates" wrote: > Not tested but should be close: > > import os > import shutil > > files = ['file1.txt'] > source_directory = '/tmp/source/' > destination_directory = '/tmp/destination/' > > for file in files: > src=os.path.join(source_directory, file > dst=os.path.join(destinat

Re: object inheritance and default values

2005-10-14 Thread George Sakkis
"Ron Adam" <[EMAIL PROTECTED]> wrote: > I'm trying to implement simple svg style colored complex objects in > tkinter and want to be able to inherit default values from other > previously defined objects. > > I want to something roughly similar to ... > > class shape(object): > def __

Re: Function to execute only once

2005-10-14 Thread George Sakkis
"snoe" <[EMAIL PROTECTED]> wrote: > I've been seeing alot about decorators and closures lately and my > initial thought was that this would be a good place to use them instead > of wrapping it around a class. That was my initial thought :) What I > came up with was this: Apparently you're not the

Re: XML dom question

2005-10-14 Thread George Sakkis
"George" <[EMAIL PROTECTED]> wrote: > How can I do the following in python: > > [snipped] In exactly the same way you could do it if you actually read the replies to the thread with the same topic you posted yesterday. Duh! George -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with creating a dict from list and range

2005-10-14 Thread George Sakkis
"James Stroud" <[EMAIL PROTECTED]> wrote: > Could be even simpler since enumerate creates tuples anyway: > > dct = dict(x for x in enumerate(description)) > > James > > On Friday 14 October 2005 08:37, Steve Holden wrote: > > >>> dct = dict((x[1], x[0]) for x in enumerate(description)) > > >>> d

Re: Microsoft Hatred FAQ

2005-10-15 Thread George Sakkis
Keith Thompson wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > > Hm... What does this have to do with Perl? > > > > Why did you post this in comp.lang.perl.misc? > > He posted this in comp.lang.python, comp.lang.perl.misc, > comp.unix.programmer, comp.lang.java.programmer, *and* > comp.

Re: Dynamic generation of doc-strings of dynamically generated classes

2005-10-17 Thread George Sakkis
"Mikael Olofsson" <[EMAIL PROTECTED]> wrote: > Hi! > > I've asked Google, but have not found any useful information there. > > Situation: I have a base class, say > > >>> class base(object): > ImportantClassAttribute = None > > Now, I want to dynamically generate subclasses of base. That

Re: Mutual module imports

2005-10-17 Thread George Sakkis
"Tony Nelson" <[EMAIL PROTECTED]> wrote: > [snipped] > > I have written a Python module that uses some C functions. I wrote the > module in two parts, one Python, one Pyrex (C). They need to share some > globals. > > [snipped] > > Now the Python module imports the Pyrex module and just shoves >

Re: Intersection of lists/sets -- with a catch

2005-10-18 Thread George Sakkis
"Carl Banks" <[EMAIL PROTECTED]> wrote: > Howabout something like this (untested): > > class CmpProxy(object): > def __init__(self,obj): > self.obj = obj > def __eq__(self,other): > return (self.obj.att_a == other.obj.att_b > and self.obj.att_b == other.obj.

Re: how best to split into singleton and sequence

2005-10-18 Thread George Sakkis
"Randy Bush" <[EMAIL PROTECTED]> wrote: > >>> l = [] > >>> s = 'a|b' > >>> t, l = s.split('|') > >>> t > 'a' > >>> l > 'b' > >>> s = 'a|b|c|d' > >>> t, l = s.split('|') > Traceback (most recent call last): > File "", line 1, in ? > ValueError: too many values to unpack > >>> > > so, i imagine wh

Re: Upper/lowercase regex matching in unicode

2005-10-19 Thread George Sakkis
"Jason Stitt" <[EMAIL PROTECTED]> wrote: > What's the best way to match uppercase or lowercase characters with a > regular expression in a unicode-aware way? Obviously [A-Z] and [a-z] > aren't going to cut it. I thought there were character classes of the > form ::upper:: or similar syntax, but ca

DBM scalability

2005-10-20 Thread George Sakkis
I'm trying to create a dbm database with around 4.5 million entries but the existing dbm modules (dbhash, gdbm) don't seem to cut it. What happens is that the more entries are added, the more time per new entry is required, so the complexity seems to be much worse than linear. Is this to be expe

Re: DBM scalability

2005-10-21 Thread George Sakkis
"Paul Rubin" <http://[EMAIL PROTECTED]> wrote: > "George Sakkis" <[EMAIL PROTECTED]> writes: > > I'm trying to create a dbm database with around 4.5 million entries > > but the existing dbm modules (dbhash, gdbm) don't seem to cut > >

Re: How to separate directory list and file list?

2005-10-23 Thread George Sakkis
"Gonnasi" <[EMAIL PROTECTED]> wrote: > With > >glob.glob("*") > > or > >os.listdir(cwd) > > I can get a combined file list with directory list, but I just wanna a > bare file list, no directory list. How to get it? > > Tons of thanks in advance! > > Gonnasi Using the path module (http://www.joren

Re: XML Tree Discovery (script, tool, __?)

2005-10-28 Thread George Sakkis
"[EMAIL PROTECTED]" wrote: > Hi all, > > Finally diving into XML programmatically. Does anyone have a best > practice recommendation for programmatically discovering the structure > of an arbitrary XML document via Python? > > It seems like it is a common wheel I'd be re-inventing. > > Thanks and

Re: XML Tree Discovery (script, tool, __?)

2005-10-29 Thread George Sakkis
<[EMAIL PROTECTED]> wrote: > """ > I was looking for something similar (XML to DTD inference) but I didn't > find anything related in python. Trang > (http://www.thaiopensource.com/relaxng/trang-manual.html#introduction), > on the other hand seems impressive after a few non-trivial tests. It > wou

Re: Recursive generators and backtracking search

2005-10-29 Thread George Sakkis
"Talin" <[EMAIL PROTECTED]> wrote: > I've been using generators to implement backtracking search for a while > now. Unfortunately, my code is large and complex enough (doing > unification on math expressions) that its hard to post a simple > example. So I decided to look for a simpler problem that

Attributes of builtin/extension objects

2005-11-02 Thread George Sakkis
Hi all, I have a few questions on object introspection of builtins and extension modules. Here's an example: >>> from datetime import date >>> d=date(2003,1,23) >>> d.__dict__ Traceback (most recent call last): File "", line 1, in ? AttributeError: 'datetime.date' object has no attribute '__dic

Re: Perl XML::Simple and Data::Dumper - exists in Python?

2005-11-06 Thread George Sakkis
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > Miguel Manso wrote: > > > Can you point me out to Python solutions for: > > > > 1) Perl's Data::Dumper > > > > It dumps any perl variable to the stdout in a "readable" way. > > >>> import pprint > >>> help(pprint) > > > 2) Perl's XML::Simple > > > > It

Re: A Tcl/Tk programmer learns Python--any advice?

2005-11-07 Thread George Sakkis
"Kevin Walzer" <[EMAIL PROTECTED]> wrote: > I've gotten all the approropriate resources for learning Python (docs, > books, tutorials), so my question is this: are there any "gotchas" that > Tcl programmers often encounter in learning Python? I'm thinking > specifically about habits that may requi

Re: Map of email origins to Python list

2005-11-07 Thread George Sakkis
"Jorge Godoy" <[EMAIL PROTECTED]>: > H... I don't see mine listed there: I'm in South America, Brasil. More > specifically in Curitiba, Paraná, Brasil. :-) That's funny; I was looking for mine and I stumbled across yours at Piscataway, NJ, US. :-) George -- http://mail.python.org/mailman

Re: which feature of python do you like most?

2005-11-08 Thread George Sakkis
<[EMAIL PROTECTED]> wrote: > [snipped] > > i've read a few chapters of a python tutorial book. The things are much like > the perl one. > > I have no idea why people are so facinating with python. Because they can write a program or module longer than 100 lines and be actually able to read, debu

Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread George Sakkis
"Alex Martelli" wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > FP functions like dropwhile/takewhile etc. > > No way -- the itertools module is and remains a PRECIOUS resource. > If you want an iterator rather than a list, itertools.ifilter is quite > appropriate here. What about th

Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread George Sakkis
"[EMAIL PROTECTED]" wrote: > Alex Martelli wrote: > > This becomes a valid list comprehension by writing 'if' instead of > > 'when'. > > valid, yes. efficient, I am not sure. > > [ x for x in xrange(1000) if p(x) ] > > means I need to go through the whole range even if p = lambda x: x < 2 Ite

Re: [ x for x in xrange(10) when p(x) ]

2005-11-09 Thread George Sakkis
"Steve Holden" <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > Itertools is your friend in this case: > > > >>>>from itertools import takewhile > >>>>list(takewhile(p, xrange(1000))) > > > > [0, 1] > > Maybe,

Re: What do you use as symbols for Python ?

2005-11-10 Thread George Sakkis
"Erik Max Francis" <[EMAIL PROTECTED]> wrote: > Pierre Barbier de Reuille wrote: > > > When you need some symbols in your program, what do you use in Python ? > > > > For example, an object get a state. This state is more readable if > > expressed as a symbols, for example "opened", "closed", "err

Re: XML Tree Discovery (script, tool, __?)

2005-11-14 Thread George Sakkis
I somehow missed this reply posted two weeks ago. <[EMAIL PROTECTED]> wrote: > "Neat, though non-trivial XSLT makes my head spin." > > Well, you don't have to know XSLT at all to use the Examplotron > transform, although I can understand wanting to understand and hack > what you're using. > > "Ju

Re: Inheritance in nested classes

2005-11-15 Thread George Sakkis
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > But I hope you are aware that nested classes aren't quite the same as > they are in java, are you? Actually they are more like java's static inner classes. If you want to simulate non-static inner classes in python, you may check the recipe here: ht

Re: Immutable instances, constant values

2005-11-21 Thread George Sakkis
Steven D'Aprano wrote: > Yes, that would be how I interpret constants: You want a name which can't > be re-bound to something else. > > One work-around is to use the convention of writing the name in all caps: > > CONSTANT = some_value > > and then trust that your module user doesn't rebind CONSTA

Re: about sort and dictionary

2005-11-21 Thread George Sakkis
"Shi Mu" wrote: > Got confused by the following code: > >>> a [6, 3, 1] > >>> b [4, 3, 1] > >>> c > {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]} > >>> c[2].append(b.sort()) > >>> c > {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]} > #why c can not append the sorted b?? In python 2.4, you can

Re: about sort and dictionary

2005-11-21 Thread George Sakkis
"Shi Mu" wrote: > Got confused by the following code: > >>> a [6, 3, 1] > >>> b [4, 3, 1] > >>> c > {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]} > >>> c[2].append(b.sort()) > >>> c > {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]} > #why c can not append the sorted b?? In python 2.4, you can

Re: Converting a flat list to a list of tuples

2005-11-22 Thread George Sakkis
"Laurent Rahuel" wrote: > Hi, > > newList = zip(aList[::2], aList[1::2]) > newList > [('a', 1), ('b', 2), ('c', 3)] > > Regards, > > Laurent Or if aList can get very large and/or the conversion has to be performed many times: from itertools import islice newList = zip(islice(aList,0,None,2), isl

Re: How about "pure virtual methods"?

2005-01-06 Thread George Sakkis
"Noam Raphael" <[EMAIL PROTECTED]> wrote: > Thanks for your suggestion, but it has several problems which the added > class solves: > > * This is a very long code just to write "you must implement this > method". Having a standard way to say that is better. > * You can instantiate the base class,

Re: Pre/Postconditions with decorators

2005-01-07 Thread George Sakkis
"Robert Brewer" <[EMAIL PROTECTED]> wrote: > Ian Bicking was just talking about @require decorators: > http://blog.ianbicking.org/already-under-our-noses.html > > @require(int, int) > def gcd(a, b): > ... > > If we made a "checker" module for such things in the stdlib, we could > write most of

Re: Pre/Postconditions with decorators

2005-01-07 Thread George Sakkis
> Hi George, > it would be nice to see how you have tackled > the task. > Maybe we will have a checker > module in Python one day... ;-) I posted my module on http://rafb.net/paste/results/voZYTG78.html and its unit test on http://rafb.net/paste/results/MYxMQW95.html. Any feedback will be appreci

Re: Pre/Postconditions with decorators

2005-01-09 Thread George Sakkis
"Stephen Thorne" <[EMAIL PROTECTED]> wrote: > Unresolved Problems: > 1) How do you handle duck types, i.e. a method that accepts StringIO, > cStringIO or any other object that has a .readlines(), .seek() and > .read() method? I think the 'proper' way of checking duck types (among other things) is

Tuple slices

2005-01-24 Thread George Sakkis
Why does slicing a tuple returns a new tuple instead of a view of the existing one, given that tuples are immutable ? I ended up writing a custom ImmutableSequence class that does this, but I wonder why it is not implemented for tuples. George -- http://mail.python.org/mailman/listinfo/python

Re: Tuple slices

2005-01-24 Thread George Sakkis
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Steven Bethard wrote: > > >a = 1, 2, 3 > >b = a[:] > >a is b > >> True > > > > My impression was that full tuple copies didn't actually copy, but that > > slicing a subset of a > > tuple might. Not exactly

Re: Tuple slices

2005-01-24 Thread George Sakkis
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > George Sakkis wrote: > > Fair enough. So perhaps the question is whether such cases are more regular > > than something like: > > a = give_me_a_huge_tuple() > > slices = [a[i:j

Re: Tuple slices

2005-01-24 Thread George Sakkis
"Terry Reedy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Aside from the problem of not being able to delete the underlying object, > the view object for a tuple would have to be a new type of object with a > new set of methods. It *could*, but it doesn't have to. One can repre

Re: Tuple slices

2005-01-24 Thread George Sakkis
"Jeff Shannon" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > [My newsreader crapped out on sending this; apologies if it appears > twice.] > > George Sakkis wrote: > > > "Terry Reedy" <[EMAIL PROTECTED]> wrote in message > &g

Re: Tuple slices

2005-01-25 Thread George Sakkis
An iterator is perfectly ok if all you want is to iterate over the elements of a view, but as you noted, iterators are less flexible than the underlying sequence. The view should be (or at least appear) identical in functionality (i.e. public methods) with its underlying sequence. George -- http

Re: Tuple slices

2005-01-25 Thread George Sakkis
I got one (and only so far) good reason for the current implementation from Fredrik Lundh, namely the reference to the original object. > As George Sakkis the OP noted, the essential data constituting a contiguous > section view are the underlying sequence and two position markers. Whether &g

Re: Tuple slices

2005-01-25 Thread George Sakkis
"Jeff Shannon" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > George Sakkis wrote: > > > An iterator is perfectly ok if all you want is to iterate over the > > elements of a view, but as you noted, iterators are less flexible than > > the und

Re: Tuple slices

2005-01-26 Thread George Sakkis
"Bengt Richter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Wed, 26 Jan 2005 11:55:59 -0800, jfj <[EMAIL PROTECTED]> wrote: > > >Jeff Shannon wrote: > > > >> > >> > >> So, what problem is it, exactly, that you think you'd solve by making > >> tuple slices a view rather than a c

Swig-friendly distutils.command.build_ext

2005-02-05 Thread George Sakkis
I'm using a custom extension of the build_ext distutils 'command' that integrates better with SWIG. Specifically, it: 1. Adds '-I' (include) swig option for each directory containing a source file in the given Extension. 2. Determines whether to add the '-c++" option by checking the source file

Re: Why is there no instancemethod builtin?

2005-06-18 Thread George Sakkis
"Steven Bethard" wrote: > John Reese wrote: > > I now do: > > > > if isinstance(x, list): > > > > It is my understanding that this is what people do nowadays. > > I wouldn't go that far. I don't have an isinstance check for lists > anywhere in my entire codebase. Why do you think you need to c

Re: Is there something similar to ?: operator (C/C++) in Python?

2005-06-19 Thread George Sakkis
"Bo Peng" wrote: > Roy Smith wrote: > > > Can you give us some idea of what it is that you're trying to do? It > > pretty unusual to see > > a requirement like that. > > def func(type_of_obj1, type_of_obj2, .): >callfunc( [ > type_of_obj1 and obj1a() or obj1b(), > type_of_obj2

Re: Why is there no instancemethod builtin?

2005-06-19 Thread George Sakkis
"Michele Simionato" wrote: > In this case I have used hasattr(obj, "__iter__") instead of > isinstance(obj, list) > (strings are iterable but do not have __iter__ method). I think hasattr > is much better > since it works for tuples and custom iterables too. The fact that strings don't have __ite

Re: Why is there no instancemethod builtin?

2005-06-19 Thread George Sakkis
Michele Simionato wrote: > I think strings do not have __iter__ on purpose, exactly to distinguish > them from other iterables, since sometimes it is nice to consider them > atomic, but I am not sure of this. You should ask the developers. Anyway, the > right definition of iterable is (as I was tol

Re: Why is there no instancemethod builtin?

2005-06-19 Thread George Sakkis
"John Roth" wrote: > Unfortunately it doesn't work: getitem can be defined for > a class that acts like a dictionary: that is, the items are > not integers, let alone integers that extend in a strict > sequence from 0. This is true, but that's the current behaviour of iterators for classes that d

Re: Couple functions I need, assuming they exist?

2005-06-20 Thread George Sakkis
> I assume you mean translating something like '100' to '1,000,000'? > I don't know of an existing function that does this, but here's a > relatively simple implementation: > > py> import itertools as it > py> def add_commas(s): > ... rev_chars = it.chain(s[::-1], it.repeat('', 2)) > ...

Re: Back to the future - python to C++ advice wanted

2005-06-20 Thread George Sakkis
"Kay Schluehr" wrote: > I recommend studying C++ idioms carefully. > > http://www1.bell-labs.com/user/cope/Patterns/C++Idioms/EuroPLoP98.html Thanks for the link; very useful indeed. > If Georges starts on greenfields he may have a look at Qt and it's > object library which is not only concerned

Compiling C++ extensions with distutils on Cygwin

2005-06-21 Thread George Sakkis
I'm trying to build a C++ extension on Cygwin, but it fails because distutils invokes gcc instead of g++. Looking into distutils internals, it turns out that compilation is assumed to be independent of the target language, while linking is not (CCompiler.compile() doesn't take a target_lang argumen

Re: Compiling C++ extensions with distutils on Cygwin

2005-06-22 Thread George Sakkis
"George Sakkis" wrote: > I'm trying to build a C++ extension on Cygwin, but it fails because > distutils invokes gcc instead of g++. Looking into distutils internals, > it turns out that compilation is assumed to be independent of the > target language, while linkin

Re: Does a function like isset() exist in Python?

2005-06-22 Thread George Sakkis
"Patrick Fitzsimmons" wrote: > Hi, > > I'm sure I should know this, but I can't find it in the manual. > > Is there a function in Python like the function in PHP isset()? It > should take a variable name and return True or False depending on > whether the variable is initialized. > > Thanks for a

Profiling extension modules

2005-06-22 Thread George Sakkis
Is there a (relatively) simple way to profile an extension module, preferably without static linking ? It compiles with 'gcc -pg' but there are a bunch of undefined references at linking (_mcount, _monstartup, __mcleanup); googling for them didn't bring back anything particularly useful. Any ideas

Re: Favorite non-python language trick?

2005-06-24 Thread George Sakkis
"Joseph Garvin" wrote: > I'm curious -- what is everyone's favorite trick from a non-python > language? And -- why isn't it in Python? Although it's an optimization rather than language trick, I like the inline functions/methods in C++. There has been a thread on that in the past (http://tinyurl.

Re: a dictionary from a list

2005-06-24 Thread George Sakkis
"Rocco Moretti" wrote: > Are you sure you need a dictionary? You may want to look at the Set > module instead, if the values aren't important. Set is the name of the type in the module sets, introduced in 2.3. Since 2.4 you can use the builtin set type. Here's the import snippet that works for 2.

Re: How does one write a function that increments a number?

2005-06-24 Thread George Sakkis
<[EMAIL PROTECTED]> wrote: > Wait... so this means it is impossible to write a function that > increments an integer without turning the integer into a list? The short answer is no you can't, because integers are immutable (as well as floats and strings among others). The longer answer is you can

Re: a dictionary from a list

2005-06-25 Thread George Sakkis
"Roy Smith" <[EMAIL PROTECTED]> wrote: > I just re-read the documentation on the dict() constructor. Why does it > support keyword arguments? > >dict(foo="bar", baz="blah") ==> {"foo":"bar", "baz"="blah"} > > This smacks of creeping featurism. Is this actually useful in real code? > It took

  1   2   3   4   5   6   7   8   9   10   >