Re: list of tuples with dynamic change in position

2010-09-07 Thread Gerard Flanagan
On 7 Sep, 07:42, sajuptpm wrote: > More details > I have a list of tuples l = [((cpu_util,mem_util),(disk_util)), > ((cpu_util,mem_util),(disk_util))] > ie, l = [((30,50),(70)), ((50,20),(20))] > > l.sort(key=lambda x:(-x[0][0], x[1][0])) # sorting cpu_util asc and > disk_util desc > > suppose i c

Re: list of tuples with dynamic change in position

2010-09-06 Thread Gerard Flanagan
sajuptpm wrote: I have a list of tuples l = [(('s','a'),(5,9)), (('u','w'),(9,2)), (('y','x'),(3,0))] and postion of values in the tuple change dynamicaly. I need a way to access correct value even if change in position. from itertools import starmap, izip, imap list(imap(dict, starmap(izip, d)

Re: first non-null element in a list, otherwise None

2010-09-02 Thread Gerard Flanagan
wheres pythonmonks wrote: This should be trivial: I am looking to extract the first non-None element in a list, and "None" otherwise. Here's one implementation: x = reduce(lambda x,y: x or y, [None,None,1,None,2,None], None) print x 1 I thought maybe a generator expression would be better,

Re: Dynamic Class Creation

2010-03-17 Thread Gerard Flanagan
Josh English wrote: Chris, Thanks. This worked for the attributes, but I think the tactic is still misleading. There are child elements I can't quite determine how to deal with: Analog Science Fiction and Fact Analog Science Fiction First Contact Hard Science Fiction

Re: Searching for most pythonic/least stupid way to do something simple

2010-03-16 Thread Gerard Flanagan
david jensen wrote: ... and of course i screwed up my outcomes... that should read outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] abstracting the given algorithm: def iterweights(N): d = 1.0/(N-1) for i in xrange(N): yield i*d, (N-1-i)*d def iterpart

Re: use strings to call functions

2010-02-08 Thread Gerard Flanagan
Klaus Neuner wrote: Hello, I am writing a program that analyzes files of different formats. I would like to use a function for each format. Obviously, functions can be mapped to file formats. E.g. like this: if file.endswith('xyz'): xyz(file) elif file.endswith('abc'): abc(file) ... Y

Re: Modifying Class Object

2010-02-08 Thread Gerard Flanagan
Arnaud Delobelle wrote: "Alf P. Steinbach" writes: * Chris Rebert: On Sun, Feb 7, 2010 at 5:05 PM, T wrote: Ok, just looking for a sanity check here, or maybe something I'm missing. I have a class Test, for example: class Test: def __init__(self, param1, param2, param3): self.pa

Re: Common area of circles

2010-02-04 Thread Gerard Flanagan
Gary Herron wrote: Gerard Flanagan wrote: A brute force approach - create a grid of small squares and calculate which squares are in all circles. I don't know whether it is any better than monte-carlo: That's just what the monte-carlo method is -- except the full family of m

Re: Common area of circles

2010-02-04 Thread Gerard Flanagan
On 2/4/2010 7:05 AM, Shashwat Anand wrote: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I g

Re: Inheriting methods but over-riding docstrings

2010-01-16 Thread Gerard Flanagan
Steven D'Aprano wrote: I have a series of subclasses that inherit methods from a base class, but I'd like them to have their own individual docstrings. The obvious solution (other than copy-and-paste) is this: class Base(object): colour = "Blue" def parrot(self): """docstring

Re: filename of calling function?

2009-11-28 Thread Gerard Flanagan
Phlip wrote: Consider these two python modules: aa.py def a(): print '?' bb.py import aa def bb(): aa.a() bb() How do I make the print line emit the filename of bb.py? (It could be anything.) Possibly not very reliable in every situation (doctests, other pythons, ...) but this i

Re: String prefix question

2009-11-09 Thread Gerard Flanagan
Alan Harris-Reid wrote: In the Python.org 3.1 documentation (section 20.4.6), there is a simple “Hello World” WSGI application which includes the following method... def hello_world_app(environ, start_response): status = b'200 OK' # HTTP Status headers = [(b'Content-type', b'text/plain; charset

Re: Accessing a method from within its own code

2009-11-02 Thread Gerard Flanagan
Paddy O'Loughlin wrote: Hi, I was wondering if there was a shorthand way to get a reference to a method object from within that method's code. Take this code snippet as an example: import re class MyClass(object): def find_line(self, lines): if not hasattr(MyClass.do_work, "matche

Re: Is there a command that returns the number of substrings in a string?

2009-10-27 Thread Gerard Flanagan
alex23 wrote: Gerard Flanagan wrote: def count(text, *args): Other than the ability to handle multiple substrings, you do realise you've effectively duplicated str.count()? I realise that calling this count function with a single argument would be functionally identical to ca

Re: Is there a command that returns the number of substrings in a string?

2009-10-26 Thread Gerard Flanagan
Peng Yu wrote: For example, the long string is 'abcabc' and the given string is 'abc', then 'abc' appears 2 times in 'abcabc'. Currently, I am calling 'find()' multiple times to figure out how many times a given string appears in a long string. I'm wondering if there is a function in python which

Re: find sublist inside list

2009-05-05 Thread Gerard Flanagan
Matthias Gallé wrote: Hi. My problem is to replace all occurrences of a sublist with a new element. Example: Given ['a','c','a','c','c','g','a','c'] I want to replace all occurrences of ['a','c'] by 6 (result [6,6,'c','g',6]). For novelty value: from itertools import izip def replace2(da

Re: Automatically generating arithmetic operations for a subclass

2009-04-14 Thread Gerard Flanagan
Steven D'Aprano wrote: I have a subclass of int where I want all the standard arithmetic operators to return my subclass, but with no other differences: class MyInt(int): def __add__(self, other): return self.__class__(super(MyInt, self).__add__(other)) # and so on for __mul__,

Re: objectoriented -?- functional

2009-03-18 Thread Gerard Flanagan
Walther Neuper wrote: >>> def reverse_(list): ... """list.reverse() returns None; reverse_ returns the reversed list""" ... list.reverse() ... return list ... >>> ll = [[11, 'a'], [33, 'b']] >>> l = ll[:] # make a copy ! >>> l = map(reverse_, l[:]) # make a copy ? >>> ll.exte

Re: Help cleaning up some code

2009-03-07 Thread Gerard Flanagan
odeits wrote: I am looking to clean up this code... any help is much appreciated. Note: It works just fine, I just think it could be done cleaner. The result is a stack of dictionaries. the query returns up to STACK_SIZE ads for a user. The check which i think is very ugly is putting another con

Re: Number of Packages in the "cheeseshop"

2009-03-05 Thread Gerard Flanagan
Michael Rudolf wrote: > Hi, I just wondered how many Packages are in the Python Package Index. fwiw http://bitbucket.org/djerdo/musette/src/tip/tools/download-pypi.py regards G. -- http://mail.python.org/mailman/listinfo/python-list

Re: looking for template package

2009-03-04 Thread Gerard Flanagan
Neal Becker wrote: I'm looking for something to do template processing. That is, transform text making various substitutions. I'd like to be able to do substitutions that include python expressions, to do arithmetic computations within substitutions. I know there are lots of template packag

Re: get most common number in a list with tolerance

2009-02-20 Thread Gerard Flanagan
Astan Chee wrote: Hi, I have a list that has a bunch of numbers in it and I want to get the most common number that appears in the list. This is trivial because i can do a max on each unique number. What I want to do is to have a tolerance to say that each number is not quite unique and if the

Re: flexible find and replace ?

2009-02-17 Thread Gerard Flanagan
Gerard Flanagan wrote: def replace(s, patt, repls): def onmatch(m): onmatch.idx += 1 return repls[onmatch.idx] onmatch.idx = -1 return patt.sub(onmatch, s) test = """ abcTAG TAG asdTAGxyz """ REPLS = [ 'REPL1', &#

Re: flexible find and replace ?

2009-02-17 Thread Gerard Flanagan
OdarR wrote: Hi guys, how would you do a clever find and replace, where the value replacing the tag is changing on each occurence ? "...TAGTAGTAG..TAG." is replaced by this : "...REPL01REPL02REPL03..REPL04..."

Re: Breaking Python list into set-length list of lists

2009-02-11 Thread Gerard Flanagan
Jason wrote: Hey everyone-- I'm pretty new to Python, & I need to do something that's incredibly simple, but combing my Python Cookbook & googling hasn't helped me out too much yet, and my brain is very, very tired & flaccid @ the moment I have a list of objects, simply called "list". I ne

Re: ElementTree and clone element toot

2009-02-02 Thread Gerard Flanagan
Gabriel Genellina wrote: En Mon, 02 Feb 2009 12:37:36 -0200, Gerard Flanagan escribió: e = ET.fromstring(s) def clone(elem): ret = elem.makeelement(elem.tag, elem.attrib) ret.text = elem.text for child in elem: ret.append(clone(child)) return ret f = clone(e

Re: ElementTree and clone element toot

2009-02-02 Thread Gerard Flanagan
m.banaouas wrote: Hi all, Working with the ElementTree module, I looked for clone element function but not found such tool: def CloneElment(fromElem, destRoot = None) fromElem is the element to clone destRoot is the parent element of the new element ; if None so the new element will be child of

Re: writing pickle function

2009-01-23 Thread Gerard Flanagan
On Jan 23, 2:48 pm, perfr...@gmail.com wrote: > hello, > > i am using nested defaultdict from collections and i would like to > write it as a pickle object to a file. when i try: > > from collections import defaultdict > x = defaultdict(lambda: defaultdict(list)) > > and then try to write to a pick

Re: Generator metadata/attributes

2009-01-08 Thread Gerard Flanagan
On Thu, 08 Jan 2009 08:42:55 -0600, Rob Williscroft wrote: > > def mydecorator( f ): > def decorated(self, *args): > logging.debug( "Created %s", self.__class__.__name__ ) > for i in f(self, *args): > yield i > return decorated > can optionally be written as: def mydecorator

Re: "return" in def

2008-12-28 Thread Gerard Flanagan
On Dec 28, 5:19 pm, Roger wrote: > Hi Everyone, [...] > When I define a method I always include a return statement out of > habit even if I don't return anything explicitly: > > def something(): >         # do something >         return > > Is this pythonic or excessive?  Is this an unnecessary af

Re: Mathematica 7 compares to other languages

2008-12-11 Thread Gerard flanagan
Xah Lee wrote: On Dec 10, 2:47 pm, John W Kennedy <[EMAIL PROTECTED]> wrote: Xah Lee wrote: In lisp, python, perl, etc, you'll have 10 or so lines. In C or Java, you'll have 50 or hundreds lines. [...] Thanks to various replies. I've now gather code solutions in ruby, python, C, Java, here:

Re: A more pythonic way of writting

2008-12-05 Thread Gerard flanagan
eric wrote: Hi, I've got this two pieces of code that works together, and fine def testit(): for vals in [[i&mask==mask for mask in [1<', flag(*vals) def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False, DOTALL=False, UNICODE=False, VERBOSE=False): vals = [IGNORECASE, LOCALE, MULT

Re: HELP!...Google SketchUp needs a Python API

2008-11-27 Thread Gerard flanagan
alex23 wrote: On Nov 28, 4:32 pm, Gerard flanagan <[EMAIL PROTECTED]> wrote: http://en.wikipedia.org/wiki/Zero-sum#Complexity You're a far more generous soul than I am, I would've been more inclined to link to the following: http://en.wikipedia.org/wiki/Persecution_complex

Re: HELP!...Google SketchUp needs a Python API

2008-11-27 Thread Gerard flanagan
r wrote: To think...that I would preach freedom to the slaves and be lynched for it...IS MADNESS! Not one vote for Python, not a care. I think everyone here should look deep within their self and realize the damage that has been done today! I hope Guido's eyes never see this thread, for he may l

Re: Enumerating k-segmentations of a sequence

2008-11-25 Thread Gerard flanagan
bullockbefriending bard wrote: I'm not sure if my terminology is precise enough, but what I want to do is: Given an ordered sequence of n items, enumerate all its possible k- segmentations. This is *not* the same as enumerating the k set partitions of the n items because I am only interested in

Re: Best strategy for finding a pattern in a sequence of integers

2008-11-21 Thread Gerard flanagan
Slaunger wrote: Hi Gerard, This definitely looks like a path to walk along, and I think your code does the trick, although I have to play a little around with the groupby method, of which I had no prior knowledge. I think I will write some unit test cases to stress test you concept (on Monday, wh

Re: Best strategy for finding a pattern in a sequence of integers

2008-11-21 Thread Gerard flanagan
Anton Vredegoor wrote: On Fri, 21 Nov 2008 18:10:02 +0100 Gerard flanagan <[EMAIL PROTECTED]> wrote: data = ''' 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6 1 6 6 1 6 6 1 6 6 1 6 6

Re: Best strategy for finding a pattern in a sequence of integers

2008-11-21 Thread Gerard flanagan
Slaunger wrote: Hi all, I am a Python novice, and I have run into a problem in a project I am working on, which boils down to identifying the patterns in a sequence of integers, for example 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6

Re: Clustering the keys of a dict according to its values

2008-11-16 Thread Gerard flanagan
Florian Brucker wrote: Florian Brucker wrote: Hi everybody! Given a dictionary, I want to create a clustered version of it, collecting keys that have the same value: >>> d = {'a':1, 'b':2, 'c':1, 'd':1, 'e':2, 'f':3} >>> cluster(d) {1:['a', 'c', 'd'], 2:['b', 'e'], 3:['f']} That is, gene

Re: Unyeilding a permutation generator

2008-11-04 Thread Gerard Flanagan
On Nov 3, 11:45 pm, [EMAIL PROTECTED] wrote: > > Thats interesting code but seems to give a different output, > suggesting thet the underlying algorithm is different. > Ignoring linebreaks and case, the original code gives: > abcd bacd bcad bcda acbd cabd cbad cbda acdb cadb cdab cdba abdc badc > b

Re: algorizm to merge nodes

2008-10-17 Thread Gerard flanagan
JD wrote: Hi, I need help for a task looks very simple: I got a python list like: [['a', 'b'], ['c', 'd'], ['e', 'f'], ['a', 'g'], ['e', 'k'], ['c', 'u'], ['b', 'p']] Each item in the list need to be merged. For example, 'a', 'b' will be merged, 'c', 'd' will be merged. Also if the node in

Re: Finding subsets for a robust regression

2008-09-29 Thread Gerard flanagan
Gerard flanagan wrote: [EMAIL PROTECTED] wrote: x1 = [] #unique instances of x and y y1 = [] #median(y) for each unique value of x for xx,yy in d.iteritems(): x1.append(xx) l = len(yy) if l == 1: y1.append(yy[0

Re: Finding subsets for a robust regression

2008-09-29 Thread Gerard flanagan
[EMAIL PROTECTED] wrote: x1 = [] #unique instances of x and y y1 = [] #median(y) for each unique value of x for xx,yy in d.iteritems(): x1.append(xx) l = len(yy) if l == 1: y1.append(yy[0]) else:

Re: Docstrings for class attributes

2008-09-23 Thread Gerard flanagan
George Sakkis wrote: On Sep 23, 1:23 am, "Tom Harris" <[EMAIL PROTECTED]> wrote: Greetings, I want to have a class as a container for a bunch of symbolic names for integers, eg: class Constants: FOO = 1 BAR = 2 Except that I would like to attach a docstring text to the constants, so

Re: dict generator question

2008-09-19 Thread Gerard flanagan
Boris Borcic wrote: Gerard flanagan wrote: George Sakkis wrote: .. Note that this works correctly only if the versions are already sorted by major version. Yes, I should have mentioned it. Here's a fuller example below. There's maybe better ways of sorting version numbers, b

Re: dict generator question

2008-09-18 Thread Gerard flanagan
George Sakkis wrote: On Sep 18, 11:43 am, Gerard flanagan <[EMAIL PROTECTED]> wrote: Simon Mullis wrote: Hi, Let's say I have an arbitrary list of minor software versions of an imaginary software product: l = [ "1.1.1.1", "1.2.2.2", "1.2.2.3", "

Re: dict generator question

2008-09-18 Thread Gerard flanagan
Simon Mullis wrote: Hi, Let's say I have an arbitrary list of minor software versions of an imaginary software product: l = [ "1.1.1.1", "1.2.2.2", "1.2.2.3", "1.3.1.2", "1.3.4.5"] I'd like to create a dict with major_version : count. (So, in this case: dict_of_counts = { "1.1" : "1",

Re: decorator and API

2008-09-18 Thread Gerard flanagan
Lee Harr wrote: I have a class with certain methods from which I want to select one at random, with weighting. The way I have done it is this import random def weight(value): def set_weight(method): method.weight = value return method return set_weight class A(o

Re: Counting Elements in an xml file

2008-08-31 Thread Gerard flanagan
Ouray Viney wrote: Hi All: I am looking at writing a python script that will let me parse a TestSuite xml file that contains n number of TestCases. My goal is to be able to count the elements base on a key value pair in the xml node. Example I would like to be able to count the number of T

Re: Identifying the start of good data in a list

2008-08-28 Thread Gerard flanagan
George Sakkis wrote: On Aug 27, 3:00 pm, Gerard flanagan <[EMAIL PROTECTED]> wrote: [EMAIL PROTECTED] wrote: I have a list that starts with zeros, has sporadic data, and then has good data. I define the point at which the data turns good to be the first index with a non-zero entry t

Re: Identifying the start of good data in a list

2008-08-27 Thread Gerard flanagan
[EMAIL PROTECTED] wrote: I have a list that starts with zeros, has sporadic data, and then has good data. I define the point at which the data turns good to be the first index with a non-zero entry that is followed by at least 4 consecutive non-zero data items (i.e. a week's worth of non-zero da

Re: Filling in Degrees in a Circle (Astronomy)

2008-08-25 Thread Gerard flanagan
W. eWatson wrote: The other night I surveyed a site for astronomical use by measuring the altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north clockwise around the site to 360 degrees, almost north again) of obstacles, trees. My purpose was to feed this profile of obstacle

Re: online tutorials?

2008-08-18 Thread Gerard Flanagan
On Aug 18, 12:53 am, Gits <[EMAIL PROTECTED]> wrote: > I want to learn how to program in python and would like to know if you > guys know of any free online tutorials.  Or is it too complicated to > learn from a site or books? Some texts and examples here: http://thehazeltree.org/ hth G. -- htt

Re: Formatting input text file

2008-08-14 Thread Gerard flanagan
[EMAIL PROTECTED] wrote: Hi, it's me again with tons of questions. I hava an input file structured like this: X XYData-1 1. 3.08333 2. 9.05526 3. 3.13581

Re: ANN: Google custom search engine for Python

2008-07-31 Thread Gerard flanagan
Gerard flanagan wrote: What is it? --- A Google custom search engine which targets only the following sites: + `The Hazel Tree <http://thehazeltree.org>`__ + `The Python standard library docs <http://docs.python.org/lib>`__ + `The Python wiki <http://wiki.python.or

ANN: Google custom search engine for Python

2008-07-30 Thread Gerard flanagan
What is it? --- A Google custom search engine which targets only the following sites: + `The Hazel Tree `__ + `The Python standard library docs `__ + `The Python wiki `__ + `Python Package Index

Re: Regular expression help

2008-07-18 Thread Gerard flanagan
[EMAIL PROTECTED] wrote: Hello, I am new to Python, with a background in scientific computing. I'm trying to write a script that will take a file with lines like c afrac=.7 mmom=0 sev=-9.56646 erep=0 etot=-11.020107 emad=-3.597647 3pv=0 extract the values of afrac and etot and plot them. I'm r

Re: read file into list of lists

2008-07-11 Thread Gerard flanagan
antar2 wrote: Hello, I can not find out how to read a file into a list of lists. I know how to split a text into a list sentences = line.split(\n) following text for example should be considered as a list of lists (3 columns and 3 rows), so that when I make the print statement list[0] [0], tha

Re: ANN: XML builder for Python

2008-07-03 Thread Gerard flanagan
Jonas Galvez wrote: Not sure if it's been done before, but still... from __future__ import with_statement from xmlbuilder import builder, element xml = builder(version="1.0", encoding="utf-8") with xml.feed(xmlns='http://www.w3.org/2005/Atom'): xml.title('Example Feed') xml.link

Re: Docutils rst2html.py gives Unknown Directive type "toctree"

2008-06-29 Thread Gerard Flanagan
On Jun 19, 11:19 pm, "Calvin Cheng" <[EMAIL PROTECTED]> wrote: > Hi, > > I am attempting to convert a bunch of .txt files into html using the > docutils package. > > It works for most of the txt files except for the index.txt file which > gives 2 errors: > (1) Unknown Directive type "toctree" > (2

Re: Removing inheritance (decorator pattern ?)

2008-06-17 Thread Gerard flanagan
Maric Michaud wrote: Le Monday 16 June 2008 20:35:22 George Sakkis, vous avez écrit : On Jun 16, 1:49 pm, Gerard flanagan <[EMAIL PROTECTED]> wrote: [...] variation of your toy code. I was thinking the Strategy pattern, different classes have different initialisation strategies? But th

Re: Removing inheritance (decorator pattern ?)

2008-06-16 Thread Gerard flanagan
George Sakkis wrote: I have a situation where one class can be customized with several orthogonal options. Currently this is implemented with (multiple) inheritance but this leads to combinatorial explosion of subclasses as more orthogonal features are added. Naturally, the decorator pattern [1]

Re: Simple Doc Test failing without any reason [Help Needed]

2008-05-28 Thread Gerard Flanagan
On May 28, 1:48 pm, afrobeard <[EMAIL PROTECTED]> wrote: > The following following code fails with the failiure:- > > File "test.py", line 27, in __main__.sanitize_number > Failed example: > sanitize_number('0321-4683113') > Expected: > '03214683113' > Got: > '03214683113' > > Expected

Re: Producing multiple items in a list comprehension

2008-05-22 Thread Gerard flanagan
Joel Koltner wrote: Is there an easy way to get a list comprehension to produce a flat list of, say, [x,2*x] for each input argument? E.g., I'd like to do something like: [ [x,2*x] for x in range(4) ] ...and receive [ 0,0,1,2,2,4,3,6] ...but of course you really get a list of lists: [[0, 0

Re: Issue with regular expressions

2008-04-30 Thread Gerard Flanagan
On Apr 29, 3:46 pm, Julien <[EMAIL PROTECTED]> wrote: > Hi, > > I'm fairly new in Python and I haven't used the regular expressions > enough to be able to achieve what I want. > I'd like to select terms in a string, so I can then do a search in my > database. > > query = ' " some words" with an

Re: Ideas for parsing this text?

2008-04-24 Thread Gerard Flanagan
On Apr 24, 4:05 am, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Apr 23, 8:00 pm, "Eric Wertman" <[EMAIL PROTECTED]> wrote: > > > I have a set of files with this kind of content (it's dumped from > > WebSphere): > > > [propertySet "[[resourceProperties "[[[description "This is a required > > prope

Re: Script to convert Tcl scripts to Python?

2008-04-23 Thread Gerard Flanagan
On Apr 23, 9:17 am, "Achillez" <[EMAIL PROTECTED]> wrote: > Hi, > > I have a 10k+ line Tcl program that I would like to auto convert over to > Python. Do any scripts exist that can convert ~90% of the standard Tcl > syntax over to Python? I know Python doesn't handle strings, but just for > general

Re: manipulating class attributes from a decorator while the class is being defined

2008-04-21 Thread Gerard Flanagan
On Apr 19, 11:19 pm, Wilbert Berendsen <[EMAIL PROTECTED]> wrote: > Hi, is it possible to manipulate class attributes from within a decorator > while the class is being defined? > > I want to register methods with some additional values in a class attribute. > But I can't get a decorator to change

Re: Rounding a number to nearest even

2008-04-11 Thread Gerard Flanagan
On Apr 11, 2:05 pm, Gerard Flanagan <[EMAIL PROTECTED]> wrote: > On Apr 11, 12:14 pm, bdsatish <[EMAIL PROTECTED]> wrote: > > > The built-in function round( ) will always "round up", that is 1.5 is > > rounded to 2.0 and 2.5 is rounded to 3.0. > > >

Re: Rounding a number to nearest even

2008-04-11 Thread Gerard Flanagan
On Apr 11, 12:14 pm, bdsatish <[EMAIL PROTECTED]> wrote: > The built-in function round( ) will always "round up", that is 1.5 is > rounded to 2.0 and 2.5 is rounded to 3.0. > > If I want to round to the nearest even, that is > > my_round(1.5) = 2# As expected > my_round(2.5) = 2# No

Re: subprocess.Popen() output to logging.StreamHandler()

2008-04-10 Thread Gerard Flanagan
On Apr 10, 5:34 pm, Gerard Flanagan <[EMAIL PROTECTED]> wrote: > On Apr 10, 2:11 pm, "sven _" <[EMAIL PROTECTED]> wrote: > > > > > Version: Python 2.5.1 (r251:54863, Mar 7 2008, 04:10:12) > > > My goal is to have stdout and stderr written

Re: subprocess.Popen() output to logging.StreamHandler()

2008-04-10 Thread Gerard Flanagan
On Apr 10, 2:11 pm, "sven _" <[EMAIL PROTECTED]> wrote: > Version: Python 2.5.1 (r251:54863, Mar 7 2008, 04:10:12) > > My goal is to have stdout and stderr written to a logging handler. > This code does not work: > > # START > import logging, subprocess > ch = logging.StreamHandler() > ch.setLevel

Re: Python-by-example - new online guide to Python Standard Library

2008-04-07 Thread Gerard Flanagan
On Apr 3, 8:33 pm, AK <[EMAIL PROTECTED]> wrote: > AK wrote: > > Hello, > > > I find that I learn easier when I go from specific examples to a more > > general explanation of function's utility and I made a reference guide > > that will eventually document all functions, classes and methods in > >

Re: Copy Stdout to string

2008-04-01 Thread Gerard Flanagan
On Apr 1, 4:03 pm, sophie_newbie <[EMAIL PROTECTED]> wrote: > Hi, I'm wondering if its possible to copy all of stdout's output to a > string, while still being able to print on screen. I know you can > capture stdout, but I still need the output to appear on the screen > also... > > Thanks! I don'

Re: finding euclidean distance,better code?

2008-03-29 Thread Gerard Flanagan
On Mar 29, 11:01 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sat, 29 Mar 2008 10:11:28 +0100, Roel Schroeven wrote: > > Steven D'Aprano schreef: > >> On Fri, 28 Mar 2008 16:59:59 +0100, Robert Bossy wrote: > > >>> Gabriel Genellina wrote: > That's what I said in anot

Re: Inheritance question

2008-03-25 Thread Gerard Flanagan
On Mar 25, 4:37 pm, Brian Lane <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > > > Gerard Flanagan wrote: > > Use the child class when calling super: > > > -- > > class Foo(object): &g

Re: Inheritance question

2008-03-25 Thread Gerard Flanagan
On Mar 25, 1:34 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote: > > Rather than use Foo.bar(), use this syntax to call methods of the > > super class: > > > super(ParentClass, self).method() > > Hi Jeff, > here is the nw version which cause an error > > class Foo(object): > def __init__(self):

Re: Script Request...

2008-03-20 Thread Gerard Flanagan
On Mar 19, 10:29 pm, some one <[EMAIL PROTECTED]> wrote: > Thanks Diez, I found some docs and examples on urllib2. Now how do i > search the string I get from urllib2, lets say I put it in "myURL", How > do I search for only Numbers and ".'s" in the "#.#.#.#" pattern. That > is all I am intereste

Re: parsing directory for certain filetypes

2008-03-11 Thread Gerard Flanagan
On Mar 11, 6:21 am, royG <[EMAIL PROTECTED]> wrote: > On Mar 10, 8:03 pm, Tim Chase wrote: > > > In Python2.5 (or 2.4 if you implement the any() function, ripped > > from the docs[1]), this could be rewritten to be a little more > > flexible...something like this (untested): > > that was quite a g

Re: defining a method that could be used as instance or static method

2008-03-10 Thread Gerard Flanagan
On Mar 10, 4:39 pm, Sam <[EMAIL PROTECTED]> wrote: > Hello > > I would like to implement some kind of comparator, that could be > called as instance method, or static method. Here is a trivial pseudo > code of what I would like to execute > > >> class MyClass: > > ...def __init__(self, value):

Re: Removing default logging handler (causes duplicate logging)

2008-03-04 Thread Gerard Flanagan
On Mar 4, 1:29 pm, Gal Aviel <[EMAIL PROTECTED]> wrote: > Hello All, > > I want to add a logger to my application, then addHandler to it to log to a > special destination. > > Unfortunately when I use logging.getLogger("my_logger") to create the new > logger, it apparently comes with a default hand

Re: metaclasses

2008-03-03 Thread Gerard Flanagan
On Mar 4, 6:31 am, [EMAIL PROTECTED] wrote: > On Mar 3, 10:01 pm, Benjamin <[EMAIL PROTECTED]> wrote: > > > > > On Mar 3, 7:12 pm, [EMAIL PROTECTED] wrote: > > > > What are metaclasses? > > > Depends on whether you want to be confused or not. If you do, look at > > this old but still head bursting

Re: joining strings question

2008-02-29 Thread Gerard Flanagan
On Feb 29, 7:56 pm, I V <[EMAIL PROTECTED]> wrote: > On Fri, 29 Feb 2008 08:18:54 -0800, baku wrote: > > return s == s.upper() > > A couple of people in this thread have used this to test for an upper > case string. Is there a reason to prefer it to s.isupper() ? Premature decreptiude, officer

Re: is there enough information?

2008-02-29 Thread Gerard Flanagan
On Feb 29, 7:55 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Thu, 28 Feb 2008 00:54:44 -0800 (PST), [EMAIL PROTECTED] declaimed > the following in comp.lang.python: > > > On Feb 28, 2:30 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > ### I smell Java burning... +1 QOTW "Mistah Kur

Re: Python and Combinatorics

2007-10-26 Thread Gerard Flanagan
On Oct 25, 12:20 am, none <""atavory\"@(none)"> wrote: > Hello, > > Is there some package to calculate combinatorical stuff like (n over > k), i.e., n!/(k!(n - k!) ? > > I know it can be written in about 3 lines of code, but still... > > Thanks, > > Ami http

Re: Best way to generate alternate toggling values in a loop?

2007-10-18 Thread Gerard Flanagan
On Oct 18, 1:55 am, Debajit Adhikary <[EMAIL PROTECTED]> wrote: > I'm writing this little Python program which will pull values from a > database and generate some XHTML. > > I'm generating a where I would like the alternate 's to be > > > and > > > What is the best way to do this? > from iter

Re: Can you determine the sign of the polar form of a complex number?

2007-10-17 Thread Gerard Flanagan
On Oct 17, 3:17 pm, [EMAIL PROTECTED] wrote: > To compute the absolute value of a negative base raised to a > fractional exponent such as: > > z = (-3)^4.5 > > you can compute the real and imaginary parts and then convert to the > polar form to get the correct value: > > real_part = ( 3^-4.5 ) * co

Re: Making a small change to a large XML document

2007-09-24 Thread Gerard Flanagan
On Sep 25, 12:38 am, Dan Stromberg <[EMAIL PROTECTED]> wrote: > Say I want to take an existing XML document, and change the value="9997" > and value="9998" to two different numbers, without changing any of the > rest of the document - not even changing comments or indentation, if > avoidable. > > W

Re: tempfile.mkstemp and os.fdopen

2007-08-29 Thread Gerard Flanagan
On Aug 28, 7:55 pm, billiejoex <[EMAIL PROTECTED]> wrote: > Hi there. > I'm trying to generate a brand new file with a unique name by using > tempfile.mkstemp(). > In conjunction I used os.fdopen() to get a wrapper around file > properties (write & read methods, and so on...) but 'name' attribute >

Re: C# and Python

2007-08-21 Thread Gerard Flanagan
On Aug 21, 12:01 pm, subeen <[EMAIL PROTECTED]> wrote: > Hi, > I am a newcomer in Python. I am going to write a small Python > application that will run in windows xp. This application needs to > have GUI. Is it possible to make a C# application using visual studio > 2005 that will call the python

Re: ploting issues in program

2007-08-16 Thread Gerard Flanagan
On Aug 16, 9:48 am, yadin <[EMAIL PROTECTED]> wrote: > hi every one! > > can you please help me to fix these polar plot in db's > so that the center is at the minimun negative number in voltagedb > about [-50] > and the maximun is at zero and how can i see values on the axis like > showing that the

Re: Awkward format string

2007-08-02 Thread Gerard Flanagan
On Aug 1, 11:52 pm, Ian Clark <[EMAIL PROTECTED]> wrote: > Gerard Flanagan wrote: > > (snip) > > > def tostring(data): > > return tuple(strftime(x) for x in data[:2]) + data[2:] > > Hrmm, not sure that having a function named tostring() that returns a >

Re: Awkward format string

2007-08-01 Thread Gerard Flanagan
On Aug 1, 6:11 pm, beginner <[EMAIL PROTECTED]> wrote: > Hi, > > In order to print out the contents of a list, sometimes I have to use > very awkward constructions. For example, I have to convert the > datetime.datetime type to string first, construct a new list, and then > send it to print. The fo

Re: Compiling python2.5 on IBM AIX

2007-07-16 Thread Gerard Flanagan
On Jul 16, 12:29 pm, [EMAIL PROTECTED] wrote: > hi, > > I'm trying to make a local install of python 2.5 on AIX and I'm > getting some trouble with _curses. > > Here is how I tried to compile it : > > export BASE=/usr/local/python251 > > cd Python.2.5.1 > ./configure --prefix=${BASE}/\ > LD

Re: Compiling python2.5 on IBM AIX

2007-07-16 Thread Gerard Flanagan
On Jul 16, 12:29 pm, [EMAIL PROTECTED] wrote: > hi, > > I'm trying to make a local install of python 2.5 on AIX and I'm > getting some trouble with _curses. > > Here is how I tried to compile it : > > export BASE=/usr/local/python251 > > cd Python.2.5.1 > ./configure --prefix=${BASE}/\ > LD

Re: Re-raising exceptions with modified message

2007-07-06 Thread Gerard Flanagan
On Jul 6, 12:18 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote: > Sorry for the soliloquy, but what I am really using is the following so > that the re-raised excpetion has the same type: > > def PoliteException(e): > class PoliteException(e.__class__): > def __init__(self, e): >

Re: Generator for k-permutations without repetition

2007-07-04 Thread Gerard Flanagan
On Jul 4, 1:22 pm, bullockbefriending bard <[EMAIL PROTECTED]> wrote: > I was able to google a recipe for a k_permutations generator, such > that i can write: > > x = range(1, 4) # (say) > [combi for combi in k_permutations(x, 3)] => > > [[1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 2, 1], [1, 2, 2], [1,

Re: How to format a string from an array?

2007-06-14 Thread Gerard Flanagan
On Jun 13, 11:11 am, Allen <[EMAIL PROTECTED]> wrote: > a = range(256) > I want to output the formated string to be: > 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f > 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f > > f

Re: How to format a string from an array?

2007-06-13 Thread Gerard Flanagan
On Jun 13, 11:11 am, Allen <[EMAIL PROTECTED]> wrote: > a = range(256) > I want to output the formated string to be: > 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f > 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f > > f

Re: howto obtain directory where current (running) py-file is placed?

2007-06-08 Thread Gerard Flanagan
On Jun 8, 1:01 am, Stef Mientki <[EMAIL PROTECTED]> wrote: > Gerard Flanagan wrote: > > On Jun 7, 8:39 am, dmitrey <[EMAIL PROTECTED]> wrote: > >> Hi all, > >> I guess this question was asked many times before, but I don't know > >> ke

  1   2   3   4   >