Re: % sign in python?

2008-07-17 Thread Robert Bossy
korean_dave wrote: What does this operator do? Specifically in this context test.log( "[[Log level %d: %s]]" % ( level, msg ), description ) (Tried googling and searching, but the "%" gets interpreted as an operation and distorts the search results) It's the string formatting operator: h

Re: decorator to prevent adding attributes to class?

2008-07-11 Thread Robert Bossy
Michele Simionato wrote: This article could give you same idea (it is doing the opposite, warning you if an attribute is overridden): http://stacktrace.it/articoli/2008/06/i-pericoli-della-programmazione-con-i-mixin1/ There is also a recipe that does exactly what you want by means of a metaclass

Re: Looking for lots of words in lots of files

2008-06-18 Thread Robert Bossy
I forgot to mention another way: put one thousand monkeys to work on it. ;) RB Robert Bossy wrote: brad wrote: Just wondering if anyone has ever solved this efficiently... not looking for specific solutions tho... just ideas. I have one thousand words and one thousand files. I need to read

Re: Looking for lots of words in lots of files

2008-06-18 Thread Robert Bossy
brad wrote: Just wondering if anyone has ever solved this efficiently... not looking for specific solutions tho... just ideas. I have one thousand words and one thousand files. I need to read the files to see if some of the words are in the files. I can stop reading a file once I find 10 of t

Re: dict order

2008-06-18 Thread Robert Bossy
Peter Otten wrote: Robert Bossy wrote: I wish to know how two dict objects are compared. By browsing the archives I gathered that the number of items are first compared, but if the two dict objects have the same number of items, then the comparison algorithm was not mentioned. If I

Re: dict order

2008-06-18 Thread Robert Bossy
Lie wrote: Whoops, I think I misunderstood the question. If what you're asking whether two dictionary is equal (equality comparison, rather than sorting comparison). You could do something like this: Testing for equality and finding differences are trivial tasks indeed. It is the sort order

dict order

2008-06-18 Thread Robert Bossy
Hi, I wish to know how two dict objects are compared. By browsing the archives I gathered that the number of items are first compared, but if the two dict objects have the same number of items, then the comparison algorithm was not mentioned. Note that I'm not trying to rely on this order. I

Re: sed to python: replace Q

2008-04-30 Thread Robert Bossy
Raymond wrote: For some reason I'm unable to grok Python's string.replace() function. Just trying to parse a simple IP address, wrapped in square brackets, from Postfix logs. In sed this is straightforward given: line = "date process text [ip] more text" sed -e 's/^.*\[//' -e 's/].*$//' a

Re: Issue with regular expressions

2008-04-29 Thread Robert Bossy
Julien 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 and "withoutquotes " ' p = re.compile(magic_reg

bisect intersection

2008-04-28 Thread Robert Bossy
Hi, I stumbled into a sorted list intersection algorithm by Baeza-Yates which I found quite elegant. For the lucky enough to have a springerlink access, here's the citation: http://dblp.uni-trier.de/rec/bibtex/conf/cpm/Baeza-Yates04 I implemented this algorithm in python and I thought I could

Re: Given a string - execute a function by the same name

2008-04-28 Thread Robert Bossy
[EMAIL PROTECTED] wrote: I'm parsing a simple file and given a line's keyword, would like to call the equivalently named function. There are 3 ways I can think to do this (other than a long if/elif construct): 1. eval() 2. Convert my functions to methods and use getattr( myClass, "method" )

Re: Little novice program written in Python

2008-04-25 Thread Robert Bossy
Marc 'BlackJack' Rintsch wrote: Indeed. Would it be a sensible proposal that sequence slices should return an iterator instead of a list? I don't think so as that would break tons of code that relies on the current behavior. Take a look at `itertools.islice()` if you want/need an iterator

Re: multiple pattern regular expression

2008-04-25 Thread Robert Bossy
Arnaud Delobelle wrote: micron_make <[EMAIL PROTECTED]> writes: I am trying to parse a file whose contents are : parameter=current max=5A min=2A for a single line I used for line in file: print re.search("parameter\s*=\s*(.*)",line).groups() is there a way to match multiple patt

Re: Little novice program written in Python

2008-04-25 Thread Robert Bossy
John Machin wrote: On Apr 25, 5:44 pm, Robert Bossy <[EMAIL PROTECTED]> wrote: Peter Otten wrote: Rogério Brito wrote: i = 2 while i <= n: if a[i] != 0: print a[i] i += 1 You can spell this as a for-loop: for p in a: if p:

Re: Little novice program written in Python

2008-04-25 Thread Robert Bossy
Peter Otten wrote: Rogério Brito wrote: i = 2 while i <= n: if a[i] != 0: print a[i] i += 1 You can spell this as a for-loop: for p in a: if p: print p It isn't exactly equivalent, but gives the same output as we know that a[0] and a[1] are also 0. I

Re: annoying dictionary problem, non-existing keys

2008-04-24 Thread Robert Bossy
bvidinli wrote: i use dictionaries to hold some config data, such as: conf={'key1':'value1','key2':'value2'} and so on... when i try to process conf, i have to code every time like: if conf.has_key('key1'): if conf['key1']<>'': other commands this is very annoying. in php, i

Re: Profiling, recursive func slower than imperative, normal?

2008-04-17 Thread Robert Bossy
Gabriel Genellina wrote: > En Wed, 16 Apr 2008 17:53:16 -0300, <[EMAIL PROTECTED]> escribió: > > >> On Apr 16, 3:27 pm, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: >> >> >>> Any function can be implemented without recursion, although it isn't >>> always easy or fun. >>> >>> >> Rea

Re: use object method without initializing object

2008-04-15 Thread Robert Bossy
Reckoner wrote: > would it be possible to use one of an object's methods without > initializing the object? > > In other words, if I have: > > class Test: > def __init__(self): > print 'init' > def foo(self): > print 'foo' > > and I want to use the foo function without hitting the >

Re: Process multiple files

2008-04-14 Thread Robert Bossy
Doran, Harold wrote: > Say I have multiple text files in a single directory, for illustration > they are called "spam.txt" and "eggs.txt". All of these text files are > organized in exactly the same way. I have written a program that parses > each file one at a time. In other words, I need to run m

Re: 答复: Java or C++?

2008-04-14 Thread Robert Bossy
Penny Y. wrote: > Perl is a functional language I guess you mean functional in the sense it works. RB -- http://mail.python.org/mailman/listinfo/python-list

Re: Java or C++?

2008-04-14 Thread Robert Bossy
[EMAIL PROTECTED] wrote: > Hello, I was hoping to get some opinions on a subject. I've been > programming Python for almost two years now. Recently I learned Perl, > but frankly I'm not very comfortable with it. Now I want to move on > two either Java or C++, but I'm not sure which. Which one do yo

Re: PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.

2008-04-08 Thread Robert Bossy
Hi, First thing, I appreciate (and I'm positive we all do) if you DID'N YELL AT ME. [EMAIL PROTECTED] wrote: > I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v. > 1310 32 bit (Intel)] on win32 with IDLE 1.2.1 > My O/S is Windows XP SP2 I use 512 MB RAM. > I am encountering the

Re: reading dictionary's (key,value) from file

2008-04-07 Thread Robert Bossy
[EMAIL PROTECTED] wrote: > Folks, > Is it possible to read hash values from txt file. > I have script which sets options. Hash table has key set to option, > and values are option values. > > Way we have it, we set options in a different file (*.txt), and we > read from that file. > Is there easy w

Re: finding euclidean distance,better code?

2008-03-28 Thread Robert Bossy
Gabriel Genellina wrote: > That's what I said in another paragraph. "sum of coordinates" is using a > different distance definition; it's the way you measure distance in a city > with square blocks. I don't know if the distance itself has a name, but I think it is called Manhattan distance in

Re: Inheritance question

2008-03-25 Thread Robert Bossy
Hi, I'm not sure what you're trying to actually achieve, but it seems that you want an identificator for classes, not for instances. In this case, setting the id should be kept out of __init__ since it is an instance initializer: make id static and thus getid() a classmethod. Furthermore, if yo

Re: Creating dynamic objects with dynamic constructor args

2008-03-25 Thread Robert Bossy
[EMAIL PROTECTED] wrote: > I'd like to create objects on the fly from a pointer to the class > using: instance = klass() But I need to be able to pass in variables > to the __init__ method. I can recover the arguments using the > inspect.argspec, but how do I call __init__ with a list of argu

Re: dynamically created names / simple problem

2008-03-25 Thread Robert Bossy
Robert Bossy wrote: > Jules Stevenson wrote: > >> Hello all, >> >> I'm fairly green to python and programming, so please go gently. The >> following code >> >> for display in secondary: >> >> self.("so_active_"+display) =

Re: dynamically created names / simple problem

2008-03-25 Thread Robert Bossy
Jules Stevenson wrote: > > Hello all, > > I'm fairly green to python and programming, so please go gently. The > following code > > for display in secondary: > > self.("so_active_"+display) = wx.CheckBox(self.so_panel, -1, "checkbox_2") > > Errors, because of the apparent nastyness at the beginnin

Re: script won't run using cron.d or crontab

2008-03-21 Thread Robert Bossy
Bjorn Meyer wrote: > I appologize if this been discussed previously. If so, just point me > to that information. > > I have done a fair bit of digging, but I haven't found a description > of what to actually do. > > I have a fairly lengthy script that I am able to run without any > problems from

Re: xml sax

2008-03-19 Thread Robert Bossy
Timothy Wu wrote: > Hi, > > I am using xml.sax.handler.ContentHandler to parse some simple xml. > > I want to detect be able to parse the content of this tag embedded in > the XML. > 174 > > > Is the proper way of doing so involving finding the "Id" tag > from startElement(), setting flag when s

Re: lists v. tuples

2008-03-17 Thread Robert Bossy
[EMAIL PROTECTED] wrote: > On Mar 17, 6:49 am, [EMAIL PROTECTED] wrote: > >> What are the considerations in choosing between: >> >>return [a, b, c] >> >> and >> >> return (a, b, c) # or return a, b, c >> >> Why is the immutable form the default? >> > > Using a house definition from

Re: merging intervals repeatedly

2008-03-14 Thread Robert Bossy
Magdoll wrote: >> One question you should ask yourself is: do you want all solutions? or >> just one? >> If you want just one, there's another question: which one? the one with >> the most intervals? any one? >> > > I actually don't know which solution I want, and that's why I keep > trying di

Re: Creating a file with $SIZE

2008-03-14 Thread Robert Bossy
Bryan Olson wrote: > Robert Bossy wrote: > >> [EMAIL PROTECTED] wrote: >> >>> Robert Bossy wrote: >>> >>>> Indeed! Maybe the best choice for chunksize would be the file's buffer >>>> size... >>>>

Re: "Attribute Doesnt Exist" ... but.... it does :-s

2008-03-13 Thread Robert Bossy
Robert Rawlins wrote: > Hi Guys, > > Well thanks for the response, I followed your advice and chopped out all the > crap from my class, right down to the bare __init__ and the setter method, > however, the problem continued to persist. > > However, Robert mentioned something about unindented lines

Re: "Attribute Doesnt Exist" ... but.... it does :-s

2008-03-13 Thread Robert Bossy
Robert Rawlins wrote: > > Hello Guys, > > I’ve got an awfully aggravating problem which is causing some > substantial hair loss this afternoon J I want to get your ideas on > this. I am trying to invoke a particular method in one of my classes, > and I’m getting a runtime error which is telling

Re: Creating a file with $SIZE

2008-03-13 Thread Robert Bossy
[EMAIL PROTECTED] wrote: > On Mar 12, 2:44 pm, Robert Bossy <[EMAIL PROTECTED]> wrote: > >> Matt Nordhoff wrote: >> >>> Robert Bossy wrote: >>> >>>> k.i.n.g. wrote: >>>> >>>>> I think I

Re: Creating a file with $SIZE

2008-03-12 Thread Robert Bossy
Matt Nordhoff wrote: > Robert Bossy wrote: > >> k.i.n.g. wrote: >> >>> I think I am not clear with my question, I am sorry. Here goes the >>> exact requirement. >>> >>> We use dd command in Linux to create a file with of required si

Re: Creating a file with $SIZE

2008-03-12 Thread Robert Bossy
k.i.n.g. wrote: > I think I am not clear with my question, I am sorry. Here goes the > exact requirement. > > We use dd command in Linux to create a file with of required size. In > similar way, on windows I would like to use python to take the size of > the file( 50MB, 1GB ) as input from user and

Re: merging intervals repeatedly

2008-03-12 Thread Robert Bossy
Magdoll wrote: > Hi, > > I have to read through a file that will give me a bunch of intervals. > My ultimate goal is to produce a final set of intervals such that not > two intervals overlap by more than N, where N is a predetermined > length. > > For example, I could read through this input: > (1,

Re: difference b/t dictionary{} and anydbm - they seem the same

2008-03-11 Thread Robert Bossy
davidj411 wrote: > anydbm and dictionary{} seem like they both have a single key and key > value. > Can't you put more information into a DBM file or link tables? I just > don't see the benefit except for the persistent storage. Except for the persistent storage, that insignificant feature... ;) We

Re: parsing directory for certain filetypes

2008-03-10 Thread Robert Bossy
jay graves wrote: > On Mar 10, 9:28 am, Robert Bossy <[EMAIL PROTECTED]> wrote: > >> Personally, I'd use glob.glob: >> >> import os.path >> import glob >> >> def parsefolder(folder): >> path = os.path.normpath(os.path.join(

Re: parsing directory for certain filetypes

2008-03-10 Thread Robert Bossy
royG wrote: > hi > i wrote a function to parse a given directory and make a sorted list > of files with .txt,.doc extensions .it works,but i want to know if it > is too bloated..can this be rewritten in more efficient manner? > > here it is... > > from string import split > from os.path import isd

Re: problem with join

2008-03-07 Thread Robert Bossy
nodrogbrown wrote: > hi > i am using python on WinXP..i have a string 'folder ' that i want to > join to a set of imagefile names to create complete qualified names so > that i can create objects out of them > > folder='F:/brown/code/python/fgrp1' > filenms=['amber1.jpg', 'amber3.jpg', 'amy1.jpg',

Re: why not bisect options?

2008-03-04 Thread Robert Bossy
Aaron Watters wrote: > On Feb 29, 9:31 am, Robert Bossy <[EMAIL PROTECTED]> wrote: > >> Hi all, >> >> I thought it would be useful if insort and consorts* could accept the >> same options than list.sort, especially key and cmp. >> > &g

Re: Eurosymbol in xml document

2008-03-04 Thread Robert Bossy
Diez B. Roggisch wrote: > Hellmut Weber wrote: > > >> Hi, >> i'm new here in this list. >> >> i'm developing a little program using an xml document. So far it's easy >> going, but when parsing an xml document which contains the EURO symbol >> ('€') then I get an error: >> >> UnicodeEncodeError:

Re: Problem round-tripping with xml.dom.minidom pretty-printer

2008-02-29 Thread Robert Bossy
Ben Butler-Cole wrote: >> An additional thing to keep in mind is that toprettyxml does not print >> an XML identical to the original DOM tree: it adds newlines and tabs. >> When parsed again these blank characters are inserted in the DOM tree as >> character nodes. If you toprettyxml an XML documen

Re: Problem round-tripping with xml.dom.minidom pretty-printer

2008-02-29 Thread Robert Bossy
Ben Butler-Cole wrote: > Hello > > I have run into a problem using minidom. I have an HTML file that I > want to make occasional, automated changes to (adding new links). My > strategy is to parse it with minidom, add a node, pretty print it and > write it back to disk. > > However I find that ever

Re: joining strings question

2008-02-29 Thread Robert Bossy
[EMAIL PROTECTED] wrote: > Hi all, > > I have some data with some categories, titles, subtitles, and a link > to their pdf and I need to join the title and the subtitle for every > file and divide them into their separate groups. > > So the data comes in like this: > > data = ['RULES', 'title','sub

why not bisect options?

2008-02-29 Thread Robert Bossy
Hi all, I thought it would be useful if insort and consorts* could accept the same options than list.sort, especially key and cmp. The only catch I can think of is that nothing prevents a crazy developer to insort elements using different options to the same list. I foresee two courses of acti

Re: executing a python program by specifying only its name in terminal or command line

2008-02-26 Thread Robert Bossy
Steve Holden wrote: > bharath venkatesh wrote: > >> hi, >>i wanna run a python program by specifying only its name ex prog >> with the arguments in the terminal or command line instead of specifying >> python prog in the terminal to run the program not even specifying the >> it with .

Re: Parent instance attribute access

2008-02-25 Thread Robert Bossy
Gabriel Rossetti wrote: > Hello, > > I have something weird going on, I have the following (simplified) : > > class MyFactory(..., ...): > > def __init__(self, *args, **kwargs): > self.args = args > self.kwargs = kwargs > ... > > class MyXmlFactory(MyFactory): > > de

Re: check a directory

2008-02-25 Thread Robert Bossy
Raj kumar wrote: > Hi all, > I'm using following code... > > for x in listdir(path) > some code. > > but how i can check whether x is a directory or not? > Because listdir() is giving all the files present in that path Take a look at the module os.path, especially the functions named is

Re: integrating python with owl

2008-02-25 Thread Robert Bossy
Noorhan Abbas wrote: > Hello, > I have developed an ontology using protege owl and I wonder if you > can help me get any documentation on how to integrate it with python. > Hi, It depends on what you mean by integrating. If you mean reading OWL files generated by Protégé, there are some Pyth

Re: is this data structure build-in or I'll have to write my own class?

2008-02-21 Thread Robert Bossy
mkPyVS wrote: > This isn't so optimal but I think accomplishes what you desire to some > extent... I *think* there is some hidden gem in inheriting from dict > or an mapping type that is cleaner than what I've shown below though. > > class dum_struct: >def __init__(self,keyList,valList): >

Re: distutils and data files

2008-02-20 Thread Robert Bossy
Sam Peterson wrote: > I've been googling for a while now and cannot find a good way to deal > with this. > > I have a slightly messy python program I wrote that I've historically > just run from the extracted source folder. I have pictures and sound > files in this folder that this program uses.

Re: dictionary of operators

2008-02-15 Thread Robert Bossy
A.T.Hofkamp wrote: > On 2008-02-14, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >> Hi, >> >> In the standard library module "operator", it would be nice to have a >> dictionary >> mapping operators strings with their respective functions. Something like: >> >> { >> '+': add, >> '-'

Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-12 Thread Robert Bossy
Jeff Schwab wrote: > Erik Max Francis wrote: > >> Jeff Schwab wrote: >> >> >>> Erik Max Francis wrote: >>> >>>> Robert Bossy wrote: >>>> >>>>> I'm pretty sure we can still hear educa

Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Robert Bossy
Grant Edwards wrote: > On 2008-02-11, Steve Holden <[EMAIL PROTECTED]> wrote: > > >> Well the history of physics for at least two hundred years has >> been a migration away from the intuitive. >> > > Starting at least as far back as Newtonian mechanics. I once > read a very interesting art