[issue7212] Retrieve an arbitrary element from a set without removing it

2009-10-28 Thread Willi Richert

Willi Richert w.rich...@gmx.net added the comment:

No particular reason, besides that it is ripped off of pop().

Your solution (omitting register) gives the same performance. Looks
cleaner, of course.

The patch tries to provide a clean way of for x in some_set: break, as
explained above. See the recent python-dev mailing list musings.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7212
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7212] Retrieve an arbitrary element from a set without removing it

2009-10-27 Thread Willi Richert

Changes by Willi Richert w.rich...@gmx.net:


Removed file: http://bugs.python.org/file15207/setobject_get.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7212
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7212] Retrieve an arbitrary element from a set without removing it

2009-10-27 Thread Willi Richert

Changes by Willi Richert w.rich...@gmx.net:


Added file: http://bugs.python.org/file15211/setobject_get.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7212
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7212] Retrieve an arbitrary element from a set without removing it

2009-10-27 Thread Willi Richert

Willi Richert w.rich...@gmx.net added the comment:

added tests for get() to test_set.py

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7212
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7212] Retrieve an arbitrary element from a set without removing it

2009-10-26 Thread Willi Richert

New submission from Willi Richert w.rich...@gmx.net:

Sometimes, a non-removing pop() is needed. In current Python versions,
it can achieved by one of the following ways:

1. 
x = some_set.pop()
some_set.add(x)

2. 
for x in some_set: 
break

3.
x = iter(some_set).next()

More native and clean would, however, be 
some_set.get()

The attached patch does this for set(). If this is accepted by the
community, frozenset should be extended as well.

--
components: Library (Lib)
files: setobject_get.patch
keywords: patch
messages: 94508
nosy: wrichert
severity: normal
status: open
title: Retrieve an arbitrary element from a set without removing it
type: feature request
versions: Python 3.1, Python 3.2
Added file: http://bugs.python.org/file15207/setobject_get.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7212
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: what IDE is the best to write python?

2009-02-02 Thread Willi Richert
Hi,

I used eclipse/pydev quite some time. What pulled me back into the arms of 
emacs was:

 - ability to save bookmarks (meaning a point in  a file) at all the 
keystrokes. Never found out how to do that in eclipse. In emacs I have now all 
the times j save at the current working position, f at the last failure I 
have to work on, and so on.

- just faster then pydev. Once pydev tries to understand your python code 
(refactoring) you can go and get a coffee

- ecb, tabbar, psvn provide the same functionality of eclipse you use in 
everyday.

Of course, it takes some time to use emacs. But it pays back with a nice 
Python integration and the advantage to customize everything you want.

wr

On Montag, 2. Februar 2009 11:18:48 Jeroen Ruigrok van der Werven wrote:
 -On [20090201 15:18], Craig (fasteliteprogram...@yahoo.com) wrote:
 eclipse

 With the pydev plugin of course.

 Personally I prefer to just use vim and (i)python. But at work I am using
 Eclipse with pydev as well.


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


Re: Integrating awk in Python

2009-01-16 Thread Willi Richert
Hi,

take a look at the 5th link at http://tinyurl.com/7s8kfq
It's called pyawk.

Regards,
wr

Am Freitag, 16. Januar 2009 13:02:59 schrieb Alfons Nonell-Canals:
 Hello,
 I'm developing a software package using python. I've programmed all
 necessary tools but I have to use other stuff from other people. Most of
 these external scripts are developed using awk.

 At the beggining I thought to translate them and program them in
 python but I prefer to avoid it because it means a lot of work and I
 should do it after each new version of this external stuff. I would like
 to integrate them into my python code.

 I know I can call them using the system environment but it is slower
 than if I call them inside the package. I know it is possible with C, do
 you have experience on integrate awk into python calling these awk
 scripts from python?

 Thanks in advance!

 Regards,
 Alfons.



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


Re: initialising a class by name

2009-01-14 Thread Willi Richert
Hi,

try the following exemplarily for the os module

import os, types
[(c, klass) for (c,klass) in os.__dict__.items() if 
type(klass)==types.ClassType]

will print: [('_Environ', class os._Environ at 0xb7d8114c)]

Regards,
wr

Am Mittwoch, 14. Januar 2009 10:55:27 schrieb Krishnakant:
 On Wed, 2009-01-14 at 00:39 -0800, Chris Rebert wrote:
  On Wed, Jan 14, 2009 at 12:36 AM, Krishnakant krm...@gmail.com wrote:
   On Wed, 2009-01-14 at 00:20 -0800, Chris Rebert wrote:
   Aside from Steven's excellent idea, to use the getattr() technique
   with your module scheme you'd probably also need to use __import__()
   to dynamically import the right module.
  
   I would generally import all the modules I would need at the top of the
   main module.
   then would use getattr(module,class_name) will that work?
 
  Yes, that is how you'd do it in that case.

 By the way, is there a kind of global list of modules/classes which are
 maintained in a package once the program is loaded into memory?
 happy hacking.
 Krishnakant.

  Cheers,
  Chris
  --
  Follow the path of the Iguana...
  http://rebertia.com

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

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


Re: Multiple values for one key

2008-08-29 Thread Willi Richert
Hi,

try defaultdict:

In [1]: from collections import defaultdict

In [2]: d=defaultdict(list)

In [3]: d[1].append(7)

In [4]: d[1].append(8)

In [5]: d
Out[5]: defaultdict(type 'list', {1: [7, 8]})

In [6]: d[1]
Out[6]: [7, 8]

Regards,
wr

Am Donnerstag 28 August 2008 19:02:55 schrieb Ron Brennan:
 I have another question.

 How would like to be able to add the contents on the values for one key.

 key['20001']:[978, 345]

 How can I do this?

 Thanks,
 Ron

 On Thu, Aug 28, 2008 at 11:56 AM, Bruno Desthuilliers

 [EMAIL PROTECTED] wrote:
  norseman a écrit :
   Terry Reedy wrote:
  Ron Brennan wrote:
  Hello,
How would I create a dictionary that contains multiple values for
  one key.
 
  Make the value a collection object (set or list if you plan to add and
  delete).
 
   I'd also like the key to be able to have duplicate entries.
 
 
  Dict keys must be hashable and unique.
 
  tjr
 
  --
  http://mail.python.org/mailman/listinfo/python-list
 
  
 
  First part I understand, second is still giving me a problem.
 
  For some reason I still want keys to be dbf column headers.
  like:
 
  name:address:zip so forth
   --- --- --
  guy: unknown:0
  girl: 123 tiny street:12345
  boy:321 here:3
  gal:999 over there: 5
  so forth
 
  Thus one key has many values. And you can then index on whatever key(s)
  you wish - name,zip...
 
  You can either use 1/ a list of dicts, or 2/ a dict mapping keys to
  lists.
 
  1/
  records = [
{name:guy, address:unknown,zip:0},
{name:girl, address:123 tiny street,zip:12345},
{name:boy, address:321 here,zip:3},
{name:gal, address:999 over there,zip:5},
  ]
 
  keys = (name, address, zip)
 
  print :.join(keys)
  print - * len(:.join(keys))
  for record in records:
 data = [record[key] for key in keys]
 print :.join(data)
 
 
  2/
  records = dict(
 name=[guy, girl, boy, gal],
 address=[unknown,123 tiny street,321 there,999 over there],
 zip=[0, 12345, 3, 5]
 )
 
  keys = (name, address, zip)
  nb_records = len(records[keys[0]])
 
  print :.join(keys)
  print - * len(:.join(keys))
  for i in xrange(nb_records):
 data = [data[key][i] for key in keys]
 print :.join(data)
 
 
  You are of course entitled the right to prefer the second solution, but
  then I hope I'll never have to maintain your code, since it's obviously
  not an appropriate data structure.
 
  With billions plus records,
 
 
  With billions plus records, it may be time to move to a serious RDBMS.
  Which btw will provide solution 1, or a lighter version of it using a
  list of tuples, ie:
 
  cursor = connection.cursor()
  cursor.execute(select name, address, zip from peoples)
  records = cursor.fetchall()
 
  # at this time, you have :
  #records = [
  #   (guy, unknown,0,),
  #   (girl, 123 tiny street,12345,),
  #   (boy, 321 here,3,),
  #   (gal, 999 over there, 5,),
  #]
 
 
  (snip)
 
  OK - I know I missed the whole concept of a Python Dictionary.
 
 
  Bad thing for you, since it's the central datastructure in Python.
 
  I haven't read anything as yet that gives a clear picture of what it is
  and
 
  what it is for.
 
  Then you failed to read the FineManual's tutorial, which is where you
  should have started:
 
  http://docs.python.org/tut/node7.html#SECTION00750
 
  Do yourself a favour : read the above first, then if you still have
  questions about dicts, we'll gladly try to help.
 
  And do yourself another favour : learn about SQL, relational model and
  RDBMS.
 
  (snip description of why the OP *really* wants a RDBMS)
 
  --
  http://mail.python.org/mailman/listinfo/python-list


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

Re: Getting pid of a remote process

2008-08-19 Thread Willi Richert
Hallo,

if the remote machines allow ssh login, you might try my SSHRemoteController 
(a combination of ssh and pexpect). Basically, it simulates a user typing 
something at the console. Then you can conveniently issue commands at the 
remote machine like ps ax | grep cmd.

http://www.richert.de/free/sshrc/SSHRemoteController-0.1.tar.bz2

Regards,
wr

  srinivasan srinivas2008-08-1906:47:44 
 HI,
 I am using Solaris and subprocess.Popen to spawn a process on a remote
 machine. Thanks,
 Srini



 - Original Message 
 From: Diez B. Roggisch [EMAIL PROTECTED]
 To: python-list@python.org
 Sent: Monday, 18 August, 2008 9:23:20 PM
 Subject: Re: Getting pid of a remote process

 srinivasan srinivas schrieb:
  Hi,
  Could you please suggest me a way to find pid of a process started on a
  remote machine by the current process?? I should get pid in the current
  process environment. The approach should be somewhat generic. It
  shouldn't expect the remote process to print its pid.

 Without information about

   - the OS you use

   - the technique you use for spawning processes remote

 there is no answer to this.

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



   Unlimited freedom, unlimited storage. Get it now, on
 http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/ --
 http://mail.python.org/mailman/listinfo/python-list

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

Re: Development for dual core machine

2007-08-20 Thread Willi Richert
Andy wrote:

 Thanks guys for the suggestions.
 
 Andy

It might be that you have to set the CPU affinity for your python process so
that it works at all. I had that problem on a dual core machine with
hyperthread enabled. Using taskset
(http://www.linuxcommand.org/man_pages/taskset1.html) helped solving the
problem:

taskset -c CPU# python ...

Best regards,
wr


-- 
pinkrose.dhis.org,
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting to an SSH account over a HTTP proxy

2007-01-23 Thread Willi Richert
Am Dienstag, 23. Januar 2007 02:16 schrieb Nanjundi:
 BJörn Lindqvist wrote:
  I want to use Python to connect to a SSH account over a HTTP proxy to
  automate some operations. I thought paramiko would be able to do that,
  but it can not (it seems).
 
  Is there some other Python module that can do what I want?
 
  --
  mvh Björn

 Did you take a look at twisted library?
 twistedmatrix.com
 http://twistedmatrix.com/projects/core/documentation/howto/clients.html


 I haven't tried to connect over port 80, but its worth a try.

 -N

If you need it for automation you might want to use pexpect: 
http://pexpect.sourceforge.net/

It listens to the tty-stream and simulates a user typing in commands. It is 
very useful, e.g. if you want to start processes on many machines over ssh. 
If there are gateways/firewalls between - no problem just use a 
second sendline('ssh [EMAIL PROTECTED]')

The only problem is the regular expression: If e.g. you use a custom $PS1 
variable for your prompt you have to account for that.

Regards,
wr
-- 
http://mail.python.org/mailman/listinfo/python-list


Pythonic A*-Algorithm

2007-01-11 Thread Willi Richert
Hi,

I'm looking for an A* implementation in Python (at least some wrapper around a 
C lib). So far I've only found http://arainyday.se/projects/python/AStar/ 
which looks not so promising.

http://wiki.python.org/moin/PythonGraphApi lists all major available graph 
libraries in Python, hoping to find a path to some standard Python graph 
library (as DBAPI). But none of them seems to have a decent A*-implementation 
(at least with Fibonacci-heap, as pqueue is supposed to be).

I know I could implement it myself as it is not that complicated, but I would 
rather like to align my project to some already existing and well established 
graph library containing A*.

Thanks,
wr
-- 
http://mail.python.org/mailman/listinfo/python-list


Priority based concurrent execution

2006-09-21 Thread Willi Richert
Hi,

I have a simulation application (PlayerStage) in which the robot is asked 
every ~200ms for an action. In the meantime the robot has to do some 
calculation with the perception. As the calculation gets more and more time 
consuming I am thinking about outsourcing it into a concurrently running 
method. If the calculation takes too long it would be ok for the result to be 
incorporated in some future cycle of the main loop, resulting in the 
calculation being done less and less often and the main loop executing some 
stop behavior.
My question: Is there a possibility in Python (either with the threading 
module or with Twisted's non-threading style) to prioritize the two 
(pseudo-)concurrent methods so that the main tread is further on executed 
every ~200ms and the calculation thread being executed only in idle time 
slots?

Thanks,
wr
-- 
http://mail.python.org/mailman/listinfo/python-list