Re: how to remove multiple occurrences of a string within a list?

2007-04-04 Thread Maël Benjamin Mettler
How about:

list(frozenset(['0024', 'haha', '0024']))

[EMAIL PROTECTED] schrieb:
 On Apr 4, 2:20 am, bahoo [EMAIL PROTECTED] wrote:
 Hi,

 I have a list like ['0024', 'haha', '0024']
 and as output I want ['haha']

 If I
 myList.remove('0024')

 then only the first instance of '0024' is removed.

 It seems like regular expressions is the rescue, but I couldn't find
 the right tool.

 Thanks!
 bahoo
 
 how about this:
 target = 0024
 l = [0024, haha, 0024, 0024, sfs]
 result = [ item for item in l if item != target]
 result
 ['haha', 'sfs']
 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 3000 PEP: Postfix type declarations

2007-04-01 Thread Maël Benjamin Mettler

   Is this supposed to be a joke? 

First of April? Likely.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to delete PyGTK ComboBox entries?

2007-02-26 Thread Maël Benjamin Mettler
Hello list!

I need to repopulate PyGTK ComboBox on a regular basis. In order to do
so I have to remove all the entries and then add the new ones. I tried
to remove all entries like that:

def clear_comboboxes(boxreference):
try:
while True:
boxreference.remove_text(0)
except:
pass

And then repopulate by iterating through the list of desired entries and
calling ComboBox.append_text(text). It works, but is painfully
slw! Is there a faster way to completely change the entries in a
ComboBox, by using an all erase method or overwriting the container
object? I haven't found anything with google, as the searches are too
ambiguous to yield usable results.

Thanks,

Maël
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to delete PyGTK ComboBox entries?

2007-02-26 Thread Maël Benjamin Mettler
Hej!
 
  model = combo_box.get_model()
  combo_box.set_model(None)
  model.clear()
  for entry in desired_entries:
  model.append([entry])
  combo_box.set_model(model)
 
  model.append is essentially the same as combo_box.append_text. Setting
  the model to None before making changes to it speeds things at least in
  the case of tree views. I'm not sure if it does much with combo boxes.
  If you experince speed issues with combo boxes you're either doing
  something very wrong or you have so many entries that you ought to be
  using a tree view instead.
 

Works like a charm. Thanks a lot!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: c++ for python programmers

2007-02-12 Thread Maël Benjamin Mettler
SAMS Teach yourself C in 21 days by Bradley L. Jones and Peter Aitken

Learning C++ is not worth is in my opinion, since you can get the OOP
power from Python and use C if you need speed...

Thomas Nelson schrieb:
 I realize I'm approaching this backwards from the direction most
 people go, but does anyone know of a good c/c++ introduction for
 python programmers?
 
 Thanks,
 
 Thomas
 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to access an absolute address through Python?

2007-02-11 Thread Maël Benjamin Mettler
volcano schrieb:
 Can it be done, and if yes - how?
 

Define address. Are you talking about URLs? File paths? Postal
addresses? Memory addresses? Whatever addresses?
I'm afraid the people on this list can't read your thoughts...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to find all the same words in a text?

2007-02-11 Thread Maël Benjamin Mettler
In order to find all the words in a text, you need to tokenize it first.
The rest is a matter of calling the count method on the list of
tokenized words. For tokenization look here:
http://nltk.sourceforge.net/lite/doc/en/words.html
A little bit of warning: depending on what exactly you need to do, the
seemingly trivial taks of tokenizing a text can become quite complex.

Enjoy,

Maël

Neil Cerutti schrieb:
 On 2007-02-10, Johny [EMAIL PROTECTED] wrote:
 I need to find all the same words in a text .
 What would be the best idea  to do that?
 I used string.find but it does not work properly for the words.
 Let suppose I want to find a number 324 in the  text

 '45  324 45324'

 there is only one occurrence  of 324 word but string.find()   finds 2
 occurrences  ( in 45324 too)

 Must I use regex?
 Thanks for help
 
 The first thing to do is to answer the question: What is a word?
 
 The second thing to do is to design some code that can find
 words in strings.
 
 The last thing to do is to search those actual words for the word
 you're looking for.
 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Free and Open Source Python IDE

2007-02-08 Thread Maël Benjamin Mettler
Srikanth schrieb:
 Yes,
 
 All I need is a good IDE, I can't find something like Eclipse (JDT).
 Eclipse has a Python IDE plug-in but it's not that great. Please
 recommend.
 
 Thanks,
 Srikanth
 

http://www.serpia.org/spe
http://www.die-offenbachs.de/detlev/eric.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: postgres backup script and popen2

2007-02-08 Thread Maël Benjamin Mettler
Use pexpect: http://pexpect.sourceforge.net/

flupke schrieb:
 Hi,
 
 i made a backup script to backup my postgres database.
 Problem is that it prompts for a password. It thought i
 could solve this by using popen2.
 I tested popen2 with dir (i'm on windows 2000, python 2.4.3)
 and it works.
 However when i try popen2 and my pg_dump command, it prompts
 for a password and I was under the impression that i was
 going to be able to dynamically communicate with the process.
 
 sin, sout = popen2(backup_command)
 sin.readline() # the password prompt
 sout.write(password)
 sin.readlines()
 
 How can i catch the password prompt and feed the password
 from my code?
 
 Thanks,
 Benedict

-- 
http://mail.python.org/mailman/listinfo/python-list


Built-in datatypes speed

2007-02-07 Thread Maël Benjamin Mettler
Hello Python-List

I hope somebody can help me with this. I spent some time googling for an
answer, but due to the nature of the problem lots of unrelevant stuff
shows up.

Anyway, I reimplemented parts of TigerSearch (
http://www.ims.uni-stuttgart.de/projekte/TIGER/TIGERSearch/ ) in Python.
I am currently writing the paper that goes along with this
reimplementation. Part of the paper deals with the
differences/similarities in the original Java implementation and my
reimplementation. In order to superficially evaluate differences in
speed, I used this paper (
http://www.ubka.uni-karlsruhe.de/cgi-bin/psview?document=ira/2000/5format=1
) as a reference. Now, this is not about speed differences between Java
and Python, mind you, but about the speed built-in datatypes
(dictionaries, lists etc.) run at. As far as I understood it from the
articles and books I read, any method call from these objects run nearly
at C-speed (I use this due to lack of a better term), since these parts
are implemented in C. Now the question is:

a) Is this true?
b) Is there a correct term for C-speed and what is it?

I would greatly appreciate an answer to that, since this has some impact
on the argumentation in the paper.

Thanks,

Maël

PS: For people interested in this reimplementation project: my code will
be published here (
http://www.ling.su.se/dali/downloads/treealigner/index.htm ) as soon as
it is integrated with the GUI and properly tested. The whole thing is
GPLed...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (n)curses or tcl/tk?

2007-02-07 Thread Maël Benjamin Mettler
As far as I know Windows does not support ncurses natively (using CygWin
probably changes that). So go with Tkinter. Looks crappy but at least it
should run on all major platforms...
 Hi All,

 Just learning Python - my first new language for about 18 years (I'm
 not a programmer ...). I'm writing a small utility to manipulate some
 text files (for the game VGA Planets, if you're interested: http://
 www.phost.de). It's currently working, but it looks a bit ugly with
 raw_input and just basic text output.

 I have plans to expand the functions of the utility, and I want a
 simple GUI frontend. I assumed I'd end up with something that looks a
 bit like the Debian installer: a curses-driven thing with simple ascii
 boxes and buttons. But reading a bit more about Python makes me think
 that support for tcl/tk is much more developed than support for
 curses.

 So my question is, should I go to the trouble of learning how to make
 boxes and stuff using tcl/tk, or just go with ncurses as I imagined?

 Which is more portable? The basic idea is that this just runs on the
 largest possible variety of systems (er, assuming they have Python
 installed, of course). I use Debian mostly, but of course it needs to
 run on bog-standard Windows boxes. Does that tilt the balance in
 favour of curses or tcl/tk? Or should I just stick with ugly text?

 Thanks for all your help,

 CC (noob)

   

-- 
http://mail.python.org/mailman/listinfo/python-list