wxPython, Syntax highlighting

2007-03-28 Thread Eric von Horst
Hi,

I am looking for wx widget that has the ability to show text, edit the
text (like a TextCtrl) but also does syntax highlighting (if the text
is e.g. XML or HTML).
I have been looking in the latest wxPython version but I could not
really find anything.

Any suggestions?

(I need this because my collegue who is very Java-minded can
apparently do that without any problems)

Kd

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


Re: Fortran vs Python - Newbie Question

2007-03-28 Thread Tim Roberts
Steven D'Aprano [EMAIL PROTECTED] wrote:

On Mon, 26 Mar 2007 06:40:49 -0700, kyosohma wrote:

 Fortran also appears to be a compiled language, whereas Python is an
 interpreted language.

Sheesh. Do Java developers go around telling everybody that Java is an
interpreted language? I don't think so.

What do you think the c in .pyc files stands for? Cheese?

Well, I'm being a bit argumentative here, but it's hard to deny that the
use of compiled in the context of .pyc (or .javac) is very different from
the use of compiled in the context of running gcc.  Once upon a time,
Basic enthusiasts would have used the word tokenized to describe .pyc
files.

A .pyc file is, in fact, interpreted by an intermediate language
interpreter.  I don't understand why anyone would be embarrassed by that.
Is it fast enough?  It certainly is for MY needs.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyDoc -g call to Alt-Installed Python

2007-03-28 Thread Peter Otten
D.Hering wrote:

 I have both python2.4 and 2.5 installed on a (k)ubuntu linux box. I'm
 trying to get the call to pydoc -g (pydoc server called from the
 system console) to recognize python2.5 rather than the system's
 default 2.4 release.
 
 I've tried several different things so far, to no avail. My console
 scripting knowledge, so far, is minimal. Any help here is appreciated.

Copy Tools/scripts/pydoc from the Python2.5 source distribution into ~/bin.
Then change its first line from 

#!/usr/bin/env python 

to

#!/usr/bin/env python2.5

Peter

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


Re: wxPython, Syntax highlighting

2007-03-28 Thread Justin Ezequiel
On Mar 28, 2:56 pm, Eric von Horst [EMAIL PROTECTED] wrote:

 I am looking for wx widget that has the ability to show text, edit the
 text (like a TextCtrl) but also does syntax highlighting (if the text
 is e.g. XML or HTML).
 I have been looking in the latest wxPython version but I could not
 really find anything.

see
.\wxPython2.6 Docs and Demos\samples\ide\ActiveGridIDE.py

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


Re: Fortran vs Python - Newbie Question

2007-03-28 Thread Alex Gibson

Beliavsky [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 On Mar 26, 10:16 am, [EMAIL PROTECTED] (Cameron Laird) wrote:
 In article 
 [EMAIL PROTECTED],[EMAIL PROTECTED] 
 [EMAIL PROTECTED] wrote:

 Is there a mac version??
 Thanks
 Chris

 Yes.

 Several, in fact--all available at no charge.  The Python
 world is different from what experience with Fortran might
 lead you to expect.

 Your experience with Fortran is dated -- see below.


 I'll be more clear:  Fortran itself is a distinguished
 language with many meritorious implementations.  It can be
 costly, though, finding the implementation you want/need
 for any specific environment.

 Gfortran, which supports Fortran 95 and a little of Fortran 2003, is
 part of GCC and is thus widely available. Binaries for g95, also based
 on GCC, are available for more than a dozen platforms, including
 Windows, Mac OS X, and Linux. I use both and consider only g95 mature,
 but gfortran does produce faster programs. Intel's Fortran compilers
 cost about $500 on Windows and Mac OS and $700 on Linux. It's not
 free, but I would not call it costly for professional developers.

 Speaking of money, gfortran and g95 have free manuals, the latter
 available in six languages
 http://ftp.g95.org/ . Final drafts of Fortran standards, identical to
 the official ISO standards, are freely available. The manual for Numpy
 costs $40 per copy.

Sun also provides its sun studio ide and compilers(c , c++ and fortran) free 
of charge on x86 linux
just have to register for free.
http://developers.sun.com/sunstudio/downloads/

Alex 


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


Re: Python automatic testing: mocking an imported module?

2007-03-28 Thread Peter Otten
Silfheed wrote:

 So we have the following situation: we have a testee.py that we want
 to automatically test out and verifiy that it is worthy of being
 deployed.  We want our tester.py to test the code for testee.py
 without changing the code for testee.py.  testee.py has a module in it
 that we want to mock in some tests and in others use the real module.
 
 /foo.py:  (real module)
 class bar:
def __init__(self):
 I am real
 
 /foo_fake/foo.py: (fake module)
 class bar:
def ___init__(self):
 I am a banana
 
 /testee.py:
 import foo
 foo.bar()
 
 /tester.py:
 from foo_fake import foo
foo.bar()# prints I am a banana
testee.py  # also prints I am a banana
 import foo
foo.bar()   # prints I am real
testee.py # also prints I am real
 
 
 This isnt working as we would like, does anyone have any tips  on how
 to get something like this working?

You can put foo_fake.foo into sys.modules as foo:

import sys
from foo_fake import foo

assert foo not in sys.modules
sys.modules[foo] = foo

foo.bar()# prints I am a banana
import foo
foo.bar()# prints I am a banana

Peter

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


XML Parsing

2007-03-28 Thread [EMAIL PROTECTED]
I want to parse this XML file:

?xml version=1.0 ?

text

text:one
filefilename/file
contents
Hello
/contents
/text:one

text:two
filefilename2/file
contents
Hello2
/contents
/text:two

/text

This XML will be in a file called filecreate.xml

As you might have guessed, I want to create files from this XML file
contents, so how can I do this?
What modules should I use? What options do I have? Where can I find
tutorials? Will I be able to put
this on the internet (on a googlepages server)?

Thanks in advance to everyone who helps me.
And yes I have used Google but I am unsure what to use.

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


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Bruno Desthuilliers
Carl Friedrich Bolz a écrit :
 ==
 PyPy 1.0: JIT compilers for free and more
 ==
 
 Welcome to the PyPy 1.0 release - a milestone integrating the results
 of four years of research, engineering, management and sprinting
 efforts 

You guys rock !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML Parsing

2007-03-28 Thread Amit Khemka
On 28 Mar 2007 00:38:38 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 I want to parse this XML file:

 ?xml version=1.0 ?

 text

 text:one
 filefilename/file
 contents
 Hello
 /contents
 /text:one

 text:two
 filefilename2/file
 contents
 Hello2
 /contents
 /text:two

 /text

 This XML will be in a file called filecreate.xml

 As you might have guessed, I want to create files from this XML file
 contents, so how can I do this?
 What modules should I use? What options do I have? Where can I find
 tutorials? Will I be able to put
 this on the internet (on a googlepages server)?

http://effbot.org/zone/celementtree.htm


HTH,
-- 

Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Freeze problem(second time do not imported)

2007-03-28 Thread dyp
Hi,

I am using DLLs from freez.py  and these dll are running inside a
program(Not OS level). If I have 2 dlls such as A.dll, B.dll,
I can import and run a(A.run()) function in  A.dl,
next I can import and run a function(B.run()) in B.dll
Next if I try to run A.run(), it doesn't work at all.

Anyone knows what is the reason and tips?

Thanks in advance!

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


Re: socket read timeout

2007-03-28 Thread Steve Holden
hg wrote:
 Facundo Batista wrote:
 
 hg wrote:

 Do you mean use select ?
 No, socket's timeout:

 import socket
 s = socket.socket()
 s.settimeout(5)
 ...
 Regards,

 --
 .   Facundo
 .
 Blog: http://www.taniquetil.com.ar/plog/
 PyAr: http://www.python.org/ar/
 
 
 My issue with that is the effect on write: I only want a timeout on read ...
 but anyway ...
 
If you want selective timeout behaviour then yes, you should use select.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings   http://holdenweb.blogspot.com

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


Re: PyDoc -g call to Alt-Installed Python

2007-03-28 Thread D.Hering
On Mar 28, 3:09 am, Peter Otten [EMAIL PROTECTED] wrote:
 D.Hering wrote:
  I have both python2.4 and 2.5 installed on a (k)ubuntu linux box. I'm
  trying to get the call to pydoc -g (pydoc server called from the
  system console) to recognize python2.5 rather than the system's
  default 2.4 release.

  I've tried several different things so far, to no avail. My console
  scripting knowledge, so far, is minimal. Any help here is appreciated.

 Copy Tools/scripts/pydoc from the Python2.5 source distribution into ~/bin.
 Then change its first line from

 #!/usr/bin/env python

 to

 #!/usr/bin/env python2.5

 Peter

Thanks Pete

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


Re: with timeout(...):

2007-03-28 Thread Nick Craig-Wood
Hendrik van Rooyen [EMAIL PROTECTED] wrote:
   Nick Craig-Wood [EMAIL PROTECTED] wrote:
  Hendrik van Rooyen [EMAIL PROTECTED] wrote:
But would be useful to be able to do without messing with
threads and GUI and imports. 
Could be hard to implement as the interpreter would have 
to be assured of getting control back periodically, so a 
ticker interrupt routine is called for - begins to sound more 
like a kernel function to me.  
Isn't there something available that could be got at via ctypes?
  
  I think if we aren't executing python bytecodes (ie are blocked in the
  kernel or running in some C extension) then we shouldn't try to
  interrupt.  It may be possible - under unix you'd send a signal -
  which python would act upon next time it got control back to the
  interpreter, but I don't think it would buy us anything except a whole
  host of problems!
 
  Don't the bytecodes call underlying OS functions? - so is there not a case
  where a particular bytecode could block, or all they all protected by
  time outs?

I beleive the convention is when calling an OS function which might
block the global interpreter lock is dropped, thus allowing other
python bytecode to run.

  Embedded code would handle this sort of thing by interrupting
  anyway and trying to clear the mess up afterward - if the limit
  switch does not appear after some elapsed time, while you are
  moving the 100 ton mass, you should abort and alarm, regardless of
  anything else...  And if the limit switch sits on a LAN device, the
  OS timeouts could be wholly inappropriate...

Well, yes there are different levels of potential reliability with
different implementation strategies for each!


-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Carl Friedrich Bolz
Hi Luis!

Luis M. González wrote:
  Carl Friedrich Bolz wrote:
  ==
  PyPy 1.0: JIT compilers for free and more
  ==
[snip]
 
 
  Congratulations!

Thanks :-)

  I just have a couple of questions:
 
  Attempting to execute pypy-c.exe (precompiled binary for Windows),
  raise an error message indicating that it cannot find gc_pypy.dll.
  Have you missed something or I'm doing something wrong?

Brain error on our side: the gc_pypy.dll is the dll of the Boehm garbage
collector, which you would need to compile yourself (which makes
precompiled binaries a bit useless :-) ). We updated the zip file, would
you mind checking whether it works better now?

  Regarding the jit integration, do you have any rough idea of when will
  it speed up arbitrary code, other than integer aritmethic?

Relatively soon. The hard bits of that are done, the JIT compiler
generator is in a pretty good shape, we need to apply it to more parts
of the PyPy Python interpreter. There are some non-coding related
reasons why we are not doing it _right_ now: we still need to write some
EU-reports (about the JIT for example) then we will need a while to
recover from the EU project.

Cheers,

Carl Friedrich Bolz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML Parsing

2007-03-28 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 I want to parse this XML file:
 
 ?xml version=1.0 ?
 
 text
 
 text:one
 filefilename/file
 contents
 Hello
 /contents
 /text:one
 
 text:two
 filefilename2/file
 contents
 Hello2
 /contents
 /text:two
 
 /text
 
 This XML will be in a file called filecreate.xml
 
 As you might have guessed, I want to create files from this XML file
 contents, so how can I do this?
 What modules should I use? What options do I have? Where can I find
 tutorials? Will I be able to put
 this on the internet (on a googlepages server)?
 
 Thanks in advance to everyone who helps me.
 And yes I have used Google but I am unsure what to use.

The above file is not valid XML. It misses a xmlns:text namespace
declaration. So you won't be able to parse it regardless of what parser you
use.

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


Re: Beginner GTK question

2007-03-28 Thread dashawn888
On Mar 25, 5:00 pm, Dave Cook [EMAIL PROTECTED] wrote:
 On 2007-03-25, dashawn888 [EMAIL PROTECTED] wrote:

  gui.py:79: GtkWarning: Quit: missing action
menubar = uimanager.get_widget('/MenuBar')
 menuitem name=Quit/

 This should probably be action=Quit.

 Dave Cook


Fixed it.  :)  Thanks

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


Re: XML Parsing

2007-03-28 Thread harvey . thomas
On Mar 28, 10:51 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  I want to parse this XML file:

  ?xml version=1.0 ?

  text

  text:one
  filefilename/file
  contents
  Hello
  /contents
  /text:one

  text:two
  filefilename2/file
  contents
  Hello2
  /contents
  /text:two

  /text

  This XML will be in a file called filecreate.xml

  As you might have guessed, I want to create files from this XML file
  contents, so how can I do this?
  What modules should I use? What options do I have? Where can I find
  tutorials? Will I be able to put
  this on the internet (on a googlepages server)?

  Thanks in advance to everyone who helps me.
  And yes I have used Google but I am unsure what to use.

 The above file is not valid XML. It misses a xmlns:text namespace
 declaration. So you won't be able to parse it regardless of what parser you
 use.

 Diez- Hide quoted text -

 - Show quoted text -

The example is valid well-formed XML. It is permitted to use the :
character in element names. Whether one should in a non namespace
context is a different matter.

Harvey

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


Re: wxPython, Syntax highlighting

2007-03-28 Thread Christian
Eric von Horst wrote:
 Hi,
 
 I am looking for wx widget that has the ability to show text, edit the
 text (like a TextCtrl) but also does syntax highlighting (if the text
 is e.g. XML or HTML).
 I have been looking in the latest wxPython version but I could not
 really find anything.

Have a look at StyledTextControl (wx.stc) in the demo.

Christian

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


Re: XML Parsing

2007-03-28 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
 I want to parse this XML file:
zip
 As you might have guessed, I want to create files from this XML file
 contents, so how can I do this?
 What modules should I use? What options do I have? Where can I find
 tutorials? Will I be able to put
 this on the internet (on a googlepages server)?

See urllib2 module and its missing guide.

 Thanks in advance to everyone who helps me.
 And yes I have used Google but I am unsure what to use.
 

About XML, to complete Amit link to ElementsTree, you may take a look at:

http://www.diveintopython.org/xml_processing/index.html
(learn by example)

And look at:
http://pyxml.sourceforge.net/
http://www.rexx.com/~dkuhlman/pyxmlfaq.html
http://shellsage.com/?q=node/12
http://www.python.org/community/sigs/current/xml-sig/
http://docs.python.org/lib/markup.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML Parsing

2007-03-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 I want to parse this XML file:
 
 ?xml version=1.0 ?
 
 text
 
 text:one
 filefilename/file
 contents
 Hello
 /contents
 /text:one
 
 text:two
 filefilename2/file
 contents
 Hello2
 /contents
 /text:two
 
 /text
 
 This XML will be in a file called filecreate.xml
 
 As you might have guessed, I want to create files from this XML file
 contents, so how can I do this?

Using a sax parser might be the best solution here.

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


pygtk: how to make a screenlocking window?

2007-03-28 Thread André Wyrwa
Hi,

can anyone please point me to the relevant pygtk window properties i
need to set to make a window
- fullscreen
- stay in front
- grab all input focus
so that i can use it as a screen lock the likes that gksu or
gnome-power-manager do?

Thanks.
André.



signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: XML Parsing

2007-03-28 Thread Diez B. Roggisch
 
 The example is valid well-formed XML. It is permitted to use the :
 character in element names. Whether one should in a non namespace
 context is a different matter.

It is? I was always under the impression one has to declare a namespace. But
this might be shaped from the usage of XSLT and W3C schema that require
these.

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


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Kay Schluehr
On Mar 27, 11:48 pm, Carl Friedrich Bolz [EMAIL PROTECTED] wrote:
 ==
 PyPy 1.0: JIT compilers for free and more
 ==

 Welcome to the PyPy 1.0 release - a milestone integrating the results
 of four years of research, engineering, management and sprinting
 efforts, concluding the 28 months phase of EU co-funding!

 Although still not mature enough for general use, PyPy 1.0 materializes
 for the first time the full extent of our original vision:

 - A flexible Python interpreter, written in RPython:

- Mostly unaware of threading, memory and lower-level target platform
  aspects.
- Showcasing advanced interpreter features and prototypes.
- Passing core CPython regression tests, translatable to C, LLVM and
 .NET.

 - An advanced framework to translate such interpreters and programs:

- That performs whole type-inference on RPython programs.
- Can weave in threading, memory and target platform aspects.
- Has low level (C, LLVM) and high level (CLI, Java, JavaScript)
 backends.

 - A **Just-In-Time Compiler generator** able to **automatically**
enhance the low level versions of our Python interpreter, leading to
run-time machine code that runs algorithmic examples at speeds typical
of JITs!

 Previous releases, particularly the 0.99.0 release from February,
 already highlighted features of our Python implementation and the
 abilities of our translation approach but the **new JIT generator**
 clearly marks a major research result and gives weight to our vision
 that one can generate efficient interpreter implementations, starting
 from a description in a high level language.

 We have prepared several entry points to help you get started:

 * The main entry point for JIT documentation and status:

http://codespeak.net/pypy/dist/pypy/doc/jit.html

 * The main documentation and getting-started PyPy entry point:

http://codespeak.net/pypy/dist/pypy/doc/index.html

 * Our online play1 demos showcasing various Python interpreters,
features (and a new way to program AJAX applications):

http://play1.codespeak.net/

 * Our detailed and in-depth Reports about various aspects of the
project:

http://codespeak.net/pypy/dist/pypy/doc/index-report.html

 In the next few months we are going to discuss the goals and form of
 the next stage of development - now more than ever depending on your
 feedback and contributions - and we hope you appreciate PyPy 1.0 as an
 interesting basis for greater things to come, as much as we do
 ourselves!

 have fun,

  the PyPy release team,
  Samuele Pedroni, Armin Rigo, Holger Krekel, Michael Hudson,
  Carl Friedrich Bolz, Antonio Cuni, Anders Chrigstroem, Guido Wesdorp
  Maciej Fijalkowski, Alexandre Fayolle

  and many others:
  http://codespeak.net/pypy/dist/pypy/doc/contributor.html

 What is PyPy?
 

 Technically, PyPy is both a Python interpreter implementation and an
 advanced compiler, or more precisely a framework for implementing dynamic
 languages and generating virtual machines for them.

 The framework allows for alternative frontends and for alternative
 backends, currently C, LLVM and .NET.  For our main target C, we can
 can mix in different garbage collectors and threading models,
 including micro-threads aka Stackless.  The inherent complexity that
 arises from this ambitious approach is mostly kept away from the Python
 interpreter implementation, our main frontend.

 PyPy is now also a Just-In-Time compiler generator.  The translation
 framework contains the now-integrated JIT generation technology.  This
 depends only on a few hints added to the interpreter source and should
 be able to cope with the changes to the interpreter and be generally
 applicable to other interpreters written using the framework.

 Socially, PyPy is a collaborative effort of many individuals working
 together in a distributed and sprint-driven way since 2003.  PyPy would
 not have gotten as far as it has without the coding, feedback and
 general support from numerous people.

 Formally, many of the current developers were involved in executing an
 EU contract with the goal of exploring and researching new approaches
 to language and compiler development and software engineering.  This
 contract's duration is about to end this month (March 2007) and we are
 working and preparing the according final review which is scheduled
 for May 2007.

 For the future, we are in the process of setting up structures to help
 maintain conceptual integrity of the project and to discuss and deal
 with funding opportunities related to further PyPy sprinting and
 developments. See here for results of the discussion so far:

  http://codespeak.net/pipermail/pypy-dev/2007q1/003577.html

 1.0.0 Feature highlights
 ==

 Here is a summary list of key features included in PyPy 1.0:

 - The 

Re: XML Parsing

2007-03-28 Thread Christian
[EMAIL PROTECTED] wrote:
 I want to parse this XML file:
 
 ?xml version=1.0 ?
 
 text
 
 text:one
 filefilename/file
 contents
 Hello
 /contents
 /text:one
 
 text:two
 filefilename2/file
 contents
 Hello2
 /contents
 /text:two
 
 /text
 
 This XML will be in a file called filecreate.xml
 
 As you might have guessed, I want to create files from this XML file
 contents, so how can I do this?
 What modules should I use? What options do I have? Where can I find
 tutorials? Will I be able to put
 this on the internet (on a googlepages server)?
 
 Thanks in advance to everyone who helps me.
 And yes I have used Google but I am unsure what to use.
 

Try this:

http://www.python.org/doc/2.4.1/lib/expat-example.html


Christian

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


Re: Auto execute python in USB flash disk

2007-03-28 Thread Graeme Glass
Or take a look at http://www.truecrypt.org/ (Unless like Brain said,
you are doing this to learn)

On Mar 27, 11:17 pm, Larry Bates [EMAIL PROTECTED] wrote:
 Brian Erhard wrote:
  I am still fairly new to python and wanted to attempt a home made
  password protection program.  There are files that I carry on a USB
  flash drive that I would like to password protect.  Essentially, I
  would like to password protect an entire directory of files.  Is there
  a way to auto execute a python script after a user double clicks to
  open a folder on the USB drive? How can you capture that double click
  event on a specific folder?

  Thanks.

 Unless you are just doing this to learn, I would suggest you purchase
 USB key with encryption included.  They are REALLY cheap.

 http://www.kingston.com/flash/DataTravelers_enterprise.asp

 -Larry


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


Re: socket read timeout

2007-03-28 Thread skip

hg My issue with that is the effect on write: I only want a timeout on
hg read ...  but anyway ...

So set a long timeout when you want to write and short timeout when you want
to read.

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


how to check whether a drive is a network drive or drive from attached hard-disk

2007-03-28 Thread shailesh
Hi,

Few very simple questions.

Is there a way to detect whether a drive is a mapped network drive or
not in Windows?

Also, how can I get a list of drive letters currently in use in the
system?

Your help is highly appreciated. Thanks in advance.

With regards,
-Shailesh

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


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Paul Boddie
On 28 Mar, 14:12, Kay Schluehr [EMAIL PROTECTED] wrote:

 A somewhat unrelated question. With Py3K Python gets optional type
 annotations.

No, I believe the consensus is that Python 3000 gets optional
annotations which aren't specifically for type information... nudge
nudge, wink wink! That last part is important, because that's also how
many other people have interpreted this particular feature. I seem to
recall that some of the PyPy people weren't interested in static
analysis [1], so I'm skeptical about whether type annotations are
their kind of thing, either. That said, I imagine that the handling of
metadata (including type details) is an element in the way RPython
works, but I also imagine that things get more complicated as such
metadata diverges from plain type information and into arbitrary
observations about other aspects of program behaviour.

Still, I'd like to see the PyPy people stick their necks out and
answer your questions. ;-)

Paul

[1] http://codespeak.net/pipermail/pypy-dev/2007q1/003607.html

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


Re: how to check whether a drive is a network drive or drive from attached hard-disk

2007-03-28 Thread Tim Golden
shailesh wrote:
 Hi,
 
 Few very simple questions.
 
 Is there a way to detect whether a drive is a mapped network drive or
 not in Windows?
 
 Also, how can I get a list of drive letters currently in use in the
 system?

http://tgolden.sc.sabren.com/python/wmi_cookbook.html#find-drive-types

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


Re: looking for RSS generator

2007-03-28 Thread kyosohma
On Mar 27, 9:42 pm, alex23 [EMAIL PROTECTED] wrote:
  I'm looking for sample code to generate an RSS feed.

 For this, I highly recommend 
 PyRSS2Gen:http://www.dalkescientific.com/Python/PyRSS2Gen.html

 Very straightforward.

  I can annotate
  my html code with comments/tags to mark the articles, all I need is an
  engine to process the pages and generate the rss file.

 If you're wanting to convert HTML to RSS, I'd recommend using
 BeautifulSoup for parsing the 
 HTML:http://www.crummy.com/software/BeautifulSoup/

 Hope this helps.

 -alex23

Looks like there's an RSS module too:

http://www.mnot.net/python/RSS.py
http://www-128.ibm.com/developerworks/webservices/library/ws-pyth11.html

Fredrik Lundh also has some info on his site: 
http://effbot.org/zone/effnews-1.htm

Have fun with the snake!

Mike

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


Re: XML Parsing

2007-03-28 Thread Urban, Gabor
HI,
 
I could suggest you to use the minidom xml parser from xml module. Your
XML schema does not seem to complocated. You will find detailed
descriptions, and working code in the book: Dive ino Python. Google for
it :-))
 

Gabor Urban
NMC - ART 

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

Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Paul Boddie
On 28 Mar, 14:12, Kay Schluehr [EMAIL PROTECTED] wrote:

 A somewhat unrelated question. With Py3K Python gets optional type
 annotations.

No, I believe the consensus is that Python 3000 gets optional
annotations which aren't specifically for type information... nudge
nudge, wink wink! That last part is important, because that's also how
many other people have interpreted this particular feature. I seem to
recall that some of the PyPy people weren't interested in static
analysis [1], so I'm skeptical about whether type annotations are
their kind of thing, either. That said, I imagine that the handling of
metadata (including type details) is an element in the way RPython
works, but I also imagine that things get more complicated as such
metadata diverges from plain type information and into arbitrary
observations about other aspects of program behaviour.

Still, I'd like to see the PyPy people stick their necks out and
answer your questions. ;-)

Paul

[1] http://codespeak.net/pipermail/pypy-dev/2007q1/003607.html

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


Re: shutil.copy Problem

2007-03-28 Thread David Nicolson
Hi John,

That was an excellent idea and it was the cause problem. Whether this  
is a bug in shutil I'm not sure.

Here is the traceback, Python 2.4.3 on Windows XP:

 C:\Documents and Settings\GüstavC:\python243\python Z:\sh.py
 Copying  u'C:\\Documents and Settings\\G\xfcstav\\My Documents\\My  
 Music\\iTunes
 \\iTunes Music Library.xml' ...
 Traceback (most recent call last):
   File Z:\sh.py, line 12, in ?
 shutil.copy(xmlfile,C:iTunes Music Library.xml)
   File C:\python243\lib\shutil.py, line 81, in copy
 copyfile(src, dst)
   File C:\python243\lib\shutil.py, line 41, in copyfile
 if _samefile(src, dst):
   File C:\python243\lib\shutil.py, line 36, in _samefile
 return (os.path.normcase(os.path.abspath(src)) ==
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in  
 position 27: ordinal
 not in range(128)

Here is the code:

 import _winreg
 import os
 import shutil

 reg = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
 key = _winreg.OpenKey(reg, rSoftware\Microsoft\Windows 
 \CurrentVersion\Explorer\Shell Folders, 0, _winreg.KEY_READ)
 mymusic = _winreg.QueryValueEx(key, My Music)[0]

 xmlfile = os.path.join(os.path.join(mymusic,iTunes),iTunes Music  
 Library.xml)
 print Copying ,repr(xmlfile),...

 shutil.copy(xmlfile,C:\iTunes Music Library.xml)

The shutil line needed to be changed to this to be successful:

 shutil.copy(xmlfile.encode(windows-1252),C:\iTunes Music  
 Library.xml


Regards,
David


On 27/03/2007, at 4:47 PM, John Nagle wrote:

 Facundo Batista wrote:
 David Nicolson wrote:


 Thanks, but it's definitely not the print. In original the code the
 print statements are replaced by a call to a log method.

 Besides, the exception would be different if it was thrown  
 outside of
 the try block.


 The best you can do is take the piece of code that has the  
 problem, show
 it to us, and then copy the traceback.

 Regards,

There may be some problem here with a file being recognized as  
 Unicode
 in binary mode.  That shouldn't happen, but looking at the Windows
 UNICODE support, it might not be impossible.

Information needed:

   - Platform (Windows, Linux, ...)
   - Python version
   - A hex dump of the first few bytes of the input file.

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



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


Why doesnt __getattr__ with decorator dont call __get_method in decorator

2007-03-28 Thread glomde
Hi,

I tried to write a decorator for that should be for methods but for
some reasons
it doens seem to work when you try to do it on the __getattr__ method
in a class.
Could anybody give some hints why this is?

Example:
class decoratorTest(object):
def __init__(self, func):
self.func = func

def __get__(self, instance, cls=None):
print __get__, instance
self.instance = instance
return self

def __call__(self, *args, **kwds):
return self.func(self.instance, *args, **kwds)

class MyClass1(object):

@decoratorTest
def decoratorTestFunc(self):
print hello1

@decoratorTest
def __getattr__(self,name):
print hello2


a = MyClass1()
a.decoratorTestFunc() # This works since the __get__ method is called
and the instance is retreived
a.test # This doesnt call the __get__ !!!

Output
__get__ __main__.MyClass1 object at 0x4012baac
hello1
Traceback (most recent call last):
  File /home/tonib/test.py, line 27, in ?
a.test
  File /home/tonib/test.py, line 12, in __call__
return self.func(self.instance, *args, **kwds)
AttributeError: 'decoratorTest' object has no attribute 'instance'

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


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Paul Rubin
Kay Schluehr [EMAIL PROTECTED] writes:
 A somewhat unrelated question. With Py3K Python gets optional type
 annotations. Are you already architecting an annotation handler that
 can process these annotations? This feature is somewhat competitive to
 all the complicated type inference and jitting you have been worked
 out so I don't know how it fits well into the current PyPy
 architecture?

What's the nature of the conflict between annotations and inference?
Haskell for example has both.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why doesnt __getattr__ with decorator dont call __get_method in decorator

2007-03-28 Thread Alex Martelli
glomde [EMAIL PROTECTED] wrote:

 Hi,
 
 I tried to write a decorator for that should be for methods but for
 some reasons
 it doens seem to work when you try to do it on the __getattr__ method
 in a class.
 Could anybody give some hints why this is?
...
 a.test # This doesnt call the __get__ !!!
 
 Output
 __get__ __main__.MyClass1 object at 0x4012baac
 hello1
 Traceback (most recent call last):
   File /home/tonib/test.py, line 27, in ?
 a.test
   File /home/tonib/test.py, line 12, in __call__
 return self.func(self.instance, *args, **kwds)
 AttributeError: 'decoratorTest' object has no attribute 'instance'

What Python release are you using?  With Python 2.5, your code gives me
instead:

 a.test
Traceback (most recent call last):
  File stdin, line 1, in module
  File a.py, line 11, in __call__
return self.func(self.instance, *args, **kwds)
TypeError: __getattr__() takes exactly 2 arguments (3 given)
 

so there would seem to be some mis-alignment wrt the problems you
observe...


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


using PyUnit to test with multiple threads

2007-03-28 Thread winston . yang
Is it possible to use PyUnit to test with multiple threads?

I want to send many commands to a database at the same time. The order
of execution of the commands is indeterminate, and therefore, so is
the status message returned.

For example, say that I send the commands get and delete for a
given record to the database at the same time. If the get executes
before the delete, I expect a success message (assuming that the
record exists in the database). If the delete executes before the get,
I expect a failure message.

Is there a way to write tests in PyUnit for this type of situation?

Thank you in advance.

Winston

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


Re: socket read timeout

2007-03-28 Thread hg
[EMAIL PROTECTED] wrote:

 
 hg My issue with that is the effect on write: I only want a timeout
 on
 hg read ...  but anyway ...
 
 So set a long timeout when you want to write and short timeout when you
 want to read.
 
 Skip


Not bad  .. thanks

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


Re: Why doesnt __getattr__ with decorator dont call __get_method in decorator

2007-03-28 Thread glomde
On Mar 28, 4:47 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
 glomde [EMAIL PROTECTED] wrote:
  Hi,

  I tried to write a decorator for that should be for methods but for
  some reasons
  it doens seem to work when you try to do it on the __getattr__ method
  in a class.
  Could anybody give some hints why this is?
 ...
  a.test # This doesnt call the __get__ !!!

  Output
  __get__ __main__.MyClass1 object at 0x4012baac
  hello1
  Traceback (most recent call last):
File /home/tonib/test.py, line 27, in ?
  a.test
File /home/tonib/test.py, line 12, in __call__
  return self.func(self.instance, *args, **kwds)
  AttributeError: 'decoratorTest' object has no attribute 'instance'

 What Python release are you using?  With Python 2.5, your code gives me
 instead:

  a.test

 Traceback (most recent call last):
   File stdin, line 1, in module
   File a.py, line 11, in __call__
 return self.func(self.instance, *args, **kwds)
 TypeError: __getattr__() takes exactly 2 arguments (3 given)



 so there would seem to be some mis-alignment wrt the problems you
 observe...

 Alex

I was using 2.4 but I downloaded and installed ActivePython2.5.0.0 and
for I get the same message as in my original email.
What python version do you use more exactly?

/T




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


Re: Python automatic testing: mocking an imported module?

2007-03-28 Thread Mark T

Silfheed [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Heyas

 So we have the following situation: we have a testee.py that we want
 to automatically test out and verifiy that it is worthy of being
 deployed.  We want our tester.py to test the code for testee.py
 without changing the code for testee.py.  testee.py has a module in it
 that we want to mock in some tests and in others use the real module.

 /foo.py:  (real module)
 class bar:
   def __init__(self):
I am real

 /foo_fake/foo.py: (fake module)
 class bar:
   def ___init__(self):
I am a banana

 /testee.py:
 import foo
 foo.bar()

 /tester.py:
 from foo_fake import foo
   foo.bar()# prints I am a banana
   testee.py  # also prints I am a banana
 import foo
   foo.bar()   # prints I am real
   testee.py # also prints I am real


 This isnt working as we would like, does anyone have any tips  on how
 to get something like this working?


If you add the foo_fake directory to the front of sys.path, import foo 
will import the foo.py in foo_fake directory before the one in the local 
directory.

# unverified code
import sys
sys.path.append(0,'foo_fake') # add foo_fake to front of path
import foo
foo.bar()
execfile('testee.py')
sys.path.pop(0) # remove foo_fake
reload(foo)
foo.bar()
execfile('testee.py')

-Mark 

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


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Christian Tismer

On 28.03.2007, at 10:38, Carl Friedrich Bolz wrote:

 Brain error on our side: the gc_pypy.dll is the dll of the Boehm  
 garbage
 collector, which you would need to compile yourself (which makes
 precompiled binaries a bit useless :-) ). We updated the zip file,  
 would
 you mind checking whether it works better now?

Why can't we provide a pre-compiled binary?
Is this a license issue?

cheers - chris

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


Re: Numeric Soup

2007-03-28 Thread Harry George
Erik Johnson [EMAIL PROTECTED] writes:

 Robert Kern [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 
  http://www.scipy.org/History_of_SciPy
 
  numpy is the current array package and supercedes Numeric and numarray.
 scipy
  provides a bunch of computational routines (linear algebra, optimization,
  statistics, signal processing, etc.) built on top of numpy.
 
 Thank you.
 
 

Also see gsl and its python binding.
http://www.gnu.org/software/gsl/
http://sourceforge.net/projects/pygsl

-- 
Harry George
PLM Engineering Architecture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Kay Schluehr
On Mar 28, 2:54 pm, Paul Boddie [EMAIL PROTECTED] wrote:
 On 28 Mar, 14:12, Kay Schluehr [EMAIL PROTECTED] wrote:



  A somewhat unrelated question. With Py3K Python gets optional type
  annotations.

 No, I believe the consensus is that Python 3000 gets optional
 annotations which aren't specifically for type information... nudge
 nudge, wink wink! That last part is important, because that's also how
 many other people have interpreted this particular feature.

You are right. The feature is more situated on a syntactical /
interface level. The semantical level has to be specified by
annotation handlers. Among them there will also be those that deal
with type annotations. I have little doubts that one of them will make
it into the stdlib sooner or later and might also influence
compilation.

 I seem to
 recall that some of the PyPy people weren't interested in static
 analysis [1], so I'm skeptical about whether type annotations are
 their kind of thing, either.

That's why I asked the question with regard to Py3K style annotations
and not static analysis in Py2X which I consider intractible. The JIT
measures types at runtime and optimizes code using this information
but doing things in this style global optimizations are hardly
tractible as well. My main interest is in an intermediate level, given
type measurements as a byproduct of UTs and code coverage. This
methodology is process-oriented and non interferent.

 That said, I imagine that the handling of
 metadata (including type details) is an element in the way RPython
 works, but I also imagine that things get more complicated as such
 metadata diverges from plain type information and into arbitrary
 observations about other aspects of program behaviour.

RPython is heuristically defined as a subset of Python static enough
to be translatable to C. So it is actually static analysis that is
done here, not on a local scale but on a simpler sublanguage. It is
not clear to me whether for a sufficiently annotated Py3K program the
inequation RPython != Python still holds?

 Still, I'd like to see the PyPy people stick their necks out and
 answer your questions. ;-)

 Paul

 [1]http://codespeak.net/pipermail/pypy-dev/2007q1/003607.html


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


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Carl Friedrich Bolz
Hi Christian!

Christian Tismer wrote:
 On 28.03.2007, at 10:38, Carl Friedrich Bolz wrote:
 
 Brain error on our side: the gc_pypy.dll is the dll of the Boehm  
 garbage
 collector, which you would need to compile yourself (which makes
 precompiled binaries a bit useless :-) ). We updated the zip file,  
 would
 you mind checking whether it works better now?
 
 Why can't we provide a pre-compiled binary?
 Is this a license issue?

We can. That's exactly what we did.

Cheers,

Carl Friedrich Bolz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why doesnt __getattr__ with decorator dont call __get_method in decorator

2007-03-28 Thread 7stud
On Mar 28, 8:28 am, glomde [EMAIL PROTECTED] wrote:
 Hi,

 I tried to write a decorator for that should be for methods but for
 some reasons
 it doens seem to work when you try to do it on the __getattr__ method
 in a class.
 Could anybody give some hints why this is?


All you have to do is decorator should methods write be for reason it
works with class __getattr__ in!

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


Re: Fortran vs Python - Newbie Question

2007-03-28 Thread Michael Tobis
I feel obligated to fan the flames a bit by pointing to
http://www.fortranstatement.com/ a site which advocates discontinuing
development of Fortran and does a good job of summarizing the problems
with the contemporary development of that language.

I am not convinced that a new high performance language (Chapel,
Fortress, etc.) is necessary. Rather, I feel that FORTRAN 77 is a
mature tool, and that it, in combination with a powerful dynamic
language (Python being my choice) is entirely sufficient for any
foreseeable scientific computing.

Fortran 90 and successors (F9* in the following) provide a baroque and
elaborate effort to bolt modern computing methods over a finely honed
special purpose tool (F77) that manages large numerical arrays
spectacularly well. It is as if you decided to add a web search engine
(an elaborate, developing set of requirements) to grep (a finely honed
special purpose tool). It makes much more sense to add greplike
features to your websearch tool than to try to foist
Grep95 (competing with the Google search engine) on everyone who
ever needs to find a misplaced text file.

F77 interfaces smoothly and neatly with Python. F9* continues to be
the single most difficult case for interoperability with any other
contemporary algorithmic language. Fortunately there is hope within
the new standard, where an interoperability flag will force F2003 to
deliver arrays that are exportable. In exchange for this balkiness,
F9* offers crude and verbose implementations of encapsulation and
inheritance.

I am sure Dr Beliavsky and some others are productive with F9*, but I
would strongly advocate against it for anyone in a position to make a
choice in the matter. Some people are competent with hand-powered
drills, but I wouldn't set up a furniture production line with them on
that basis.

The performance and library advantages of Fortran are all available in
F77. Higher level abstractions can easily be wrapped around the low
level structures using Python and f2py. Making the combination
performance-efficient requires some skill, but making a pure Fortran
implementation efficient does no less so.

I don't think we should or can abandon the excellent infrastructure
provided by the Fortran of a generation ago. However, I am totally
unconvinced that there is a point to a backward compatible extension
to F77 that tries to support OOP and other abstractions unimaginable
in the early days of Fortran.

F77 and its numerical libraries are mature and complete. I think we
should treat it as a remarkable set of packages, and move on.

For any purposes I know of not involving an existing F9* legacy, I
believe that Python plus F77 is as good as or superior to F9* alone.
This includes the total time needed to learn the tools, (I think it is
easier to learn Python, F77 and f2py than to learn F9* alone to any
comparable skill level.) total time needed to develop the code, whole
system performance, testability and maintainability. Once Python gets
a first-class array type things will be even smoother as I understand
it.

mt

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


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Kay Schluehr
On Mar 28, 4:34 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
 Kay Schluehr [EMAIL PROTECTED] writes:
  A somewhat unrelated question. With Py3K Python gets optional type
  annotations. Are you already architecting an annotation handler that
  can process these annotations? This feature is somewhat competitive to
  all the complicated type inference and jitting you have been worked
  out so I don't know how it fits well into the current PyPy
  architecture?

 What's the nature of the conflict between annotations and inference?
 Haskell for example has both.

There is no conflict in Haskell because Haskell has a type system by
default. But Python has none and so one had to define RPython, a
subset of Python *viewed* as static enough to be translatable to C
( RPython is of course as polymorphic as any other Python code and can
be fed with arbitrary types. Only the context makes it special ).
RPython is an approximation to Python on which static type inference
is feasible. RPython is yet defined heuristically and this heuristics
might be changed when RPython can be defined by the power of a type
system defined *formally*. So it might be just a matter of reason to
define a typesystem for interpreter/jit level Python code.

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


very strange syntax errors

2007-03-28 Thread hg
Hi,

I'v been facing some very strange errors lately:

one example:

def __init__(self):

import my_info
some_text = my_info.T_SOME_TEXT
  ^ syntax error


I manage to get rid of that one by moving the import on top of my file.

Note: Python 2.4.1 under Windows


Any clue ?

Thanks,

hg


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


Re: Fortran vs Python - Newbie Question

2007-03-28 Thread Terry Reedy

Tim Roberts [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| Well, I'm being a bit argumentative here, but it's hard to deny that the
| use of compiled in the context of .pyc (or .javac) is very different 
from
| the use of compiled in the context of running gcc.

Besides the fact that the object code does not corresponded to the public 
interface of any *current* processor, the compilation process is quite 
similar.  Linear source code is parsed using standard techniques to produce 
a syntax tree.  The tree is walked to produce object code in a different 
language.  A certain amount of optimization is done.

For instance, CPython compiles a 'while ' statement to a conditional jump 
past the end before the body and an absolute jump to the begining at the 
end.  I am quite sure that gcc does essentially the same thing.  If CPython 
(by 2.4, at least) recognizes the condition as a constant whose Bool value 
is True, it removes (optimizes away) the loading of the constant and the 
conditional jump that would never happen.  Again, this is the same as gcc 
will do, I am sure, with at least some flag settings.

| Once upon a time,
| Basic enthusiasts would have used the word tokenized to describe .pyc 
files.

Perhaps, but they would, I think, have been wrong.  Tokenized Basic to the 
best of my knowledge, is a reversibly compressed version of the source 
file.  The 'while' keyword, is there is one, is replaced by a number, but 
no parsing is done.

Terry Jan Reedy



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


Hpw make lists that are easy to sort.

2007-03-28 Thread Anton Vredegoor
Python's sorting algorithm takes advantage of preexisting order in a 
sequence:

#sort_test.py
import random
import time

def test():
 n = 1000
 k = 2**28

 L = random.sample(xrange(-k,k),n)
 R = random.sample(xrange(-k,k),n)

 t = time.time()
 LR = [(i+j) for i in L for j in R]
 print time.time()-t
 LR.sort()
 print time.time()-t

 print

 t = time.time()
 #L.sort()
 R.sort()
 presorted_LR = [(i+j) for i in L for j in R]
 print time.time()-t
 presorted_LR.sort()
 print time.time()-t

if __name__=='__main__':
 test()

On this -very slow- computer this prints:

 d:\python25\pythonw -u sort_test.py
1.1014305
8.9603815

1.1014305
5.4900954
 Exit code: 0

Presorting the second sequence gains us more than three seconds. I 
wonder if there is a way to generate the combined items in such a way 
that sorting them is even faster? Is there some other sorting algorithm 
that can specifically take advantage of this way -or another way- of 
generating this list?

The final sequence is len(L)*len(R) long but it is produced from only 
len(L)+len(R) different items, is it possible to exploit this fact? I'd 
also be interested in a more general solution that would work for 
summing the items of more than two lists in this way.

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


Re: very strange syntax errors

2007-03-28 Thread hg
hg wrote:

 Hi,
 
 I'v been facing some very strange errors lately:
 
 one example:
 
 def __init__(self):
 
 import my_info
 some_text = my_info.T_SOME_TEXT
   ^ syntax error
 
 
 I manage to get rid of that one by moving the import on top of my file.
 
 Note: Python 2.4.1 under Windows
 
 
 Any clue ?
 
 Thanks,
 
 hg


PS:

and I also get some even weirder studd such as an error on line 374 when I
add a print on line 65

I'm using pydev + pydev ext

hg

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


Re: Why doesnt __getattr__ with decorator dont call __get_method in decorator

2007-03-28 Thread Arnaud Delobelle
On Mar 28, 3:47 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
 glomde [EMAIL PROTECTED] wrote:
  Hi,

  I tried to write a decorator for that should be for methods but for
  some reasons
  it doens seem to work when you try to do it on the __getattr__ method
  in a class.
  Could anybody give some hints why this is?
 ...
  a.test # This doesnt call the __get__ !!!

  Output
  __get__ __main__.MyClass1 object at 0x4012baac
  hello1
  Traceback (most recent call last):
File /home/tonib/test.py, line 27, in ?
  a.test
File /home/tonib/test.py, line 12, in __call__
  return self.func(self.instance, *args, **kwds)
  AttributeError: 'decoratorTest' object has no attribute 'instance'

 What Python release are you using?  With Python 2.5, your code gives me
 instead:

  a.test

 Traceback (most recent call last):
   File stdin, line 1, in module
   File a.py, line 11, in __call__
 return self.func(self.instance, *args, **kwds)
 TypeError: __getattr__() takes exactly 2 arguments (3 given)



 so there would seem to be some mis-alignment wrt the problems you
 observe...

I get this error with python 2.4 when I do

a.__getattr__('test') # This sets the 'instance' attribute as __get__
is called
a.test # __get__ is not called but 'instance' is set

To get python to run the __get__ method I think you have to call
__getattr__ explicitly:
a.__getattr__('test')

If you do:
a.test
python follows a different routine: it checks for the existence of the
attribute, then check if there is a __getattr__ attribute. Now the
speculative bit: then I conjecture that python assumes that
__getattr__ is a function with two arguments and directly passes them
on to it.  Indeed

type(a).__dict__['__getattr__'](a, 'test')

seems to produce the same errors as a.test, whether the instance
attribute is set or not.
And this explain why there are too many arguments (error message
above).

--
Arnaud

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


Re: very strange syntax errors

2007-03-28 Thread Terry Reedy

hg [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| I'v been facing some very strange errors lately:
| one example:
|
| def __init__(self):
| 
|import my_info
|some_text = my_info.T_SOME_TEXT
|  ^ syntax error
|
| I manage to get rid of that one by moving the import on top of my file.
| Note: Python 2.4.1 under Windows
| Any clue ?

Mixing tabs and spaces and not matching (s and 's are typical causes.





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


Re: very strange syntax errors

2007-03-28 Thread David Nicolson
This might be stating the obvious, but have you detabbed your text,  
if you are using spaces?


On 28/03/2007, at 8:18 PM, hg wrote:

 hg wrote:

 Hi,

 I'v been facing some very strange errors lately:

 one example:

 def __init__(self):
 
 import my_info
 some_text = my_info.T_SOME_TEXT
   ^ syntax error


 I manage to get rid of that one by moving the import on top of my  
 file.

 Note: Python 2.4.1 under Windows


 Any clue ?

 Thanks,

 hg


 PS:

 and I also get some even weirder studd such as an error on line 374  
 when I
 add a print on line 65

 I'm using pydev + pydev ext

 hg

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



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


Re: very strange syntax errors

2007-03-28 Thread Peter Otten
hg wrote:

 I'v been facing some very strange errors lately:
 
 one example:
 
 def __init__(self):
 
 import my_info
 some_text = my_info.T_SOME_TEXT
   ^ syntax error
 
 
 I manage to get rid of that one by moving the import on top of my file.
 
 Note: Python 2.4.1 under Windows
 
 
 Any clue ?

A guess: you may have mixed Unix (\n) and Windows (\r\n) newlines. Try
to ensure that every line ends with \r\n.

Peter

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


Re: very strange syntax errors

2007-03-28 Thread skip
 I'v been facing some very strange errors lately:
 
 one example:
 
 def __init__(self):
 
 import my_info
 some_text = my_info.T_SOME_TEXT
^ syntax error
 
 I manage to get rid of that one by moving the import on top of my file.
...
hg PS:

hg and I also get some even weirder studd such as an error on line 374
hg when I add a print on line 65

I think you're going to have to post a bit more of your code and some actual
tracebacks if people are to understand what the problem is.  For example, we
can't tell what the relationship is in your code between lines 65 and 374
without actually seeing the code.  I could look at those lines in an
arbitrary bit of my own code, but i doubt it would help.  Maybe not all of
your code, but a few lines of code around the suspect points.

Skip

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


XML/encoding/prolog/python hell...

2007-03-28 Thread fscked
I am a beginning pythoner and I am having a terrible time trying to
figure out how to do something that (it would seeme to me) should be
fairly simple.

I have a CSV file of unknown encoding and I need to parse that file to
get the fields --- DONE
I need to create an xml document that has the proper prolog and
namespace information in it. --- NOT DONE
I need it to be encoded properly--- Looks right in IE, not right in
any other app.

I should say that I have googled my butt off, tried ElementTree,
CSV2XML, and various other things and cannot get any of them to work.

A sample of the output I am looking for is as follows:

?xml version=1.0 encoding=UTF-8 standalone=yes?
ns2:boxes xmlns:ns2=Boxes
ns2:box id=9 mac=33 d_a=2006 hw_ver=v1.1 sw_ver=3
pl_h=No Data name=Lounge address=here phone=555-
country=US city=LA/
ns2:box id=7 mac=44 d_a=2005 hw_ver=v1.0 sw_ver=3
pl_h=No Data name=MyHouse address=there phone=555-5556
country=US city=New York/
/ns2:boxes

Is there some fundamental thing I am not getting? I cannot get
'tostrings' to work in ElementTree and I cannot figure the prolog out.

I posted a similar message back in January, but haven't had much luck.

PS
No I haven't been trying to do this since January, more important
things came up at work and I have just revived this. :)

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


Re: pattern search

2007-03-28 Thread Fabian Braennstroem
Hi,

Gabriel Genellina schrieb am 03/27/2007 10:09 PM:
 En Tue, 27 Mar 2007 18:42:15 -0300, Diez B. Roggisch [EMAIL PROTECTED]  
 escribió:
 
 Paul McGuire schrieb:
 On Mar 27, 10:18 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Fabian Braennstroem wrote:
 while iter:
 value = model.get_value(iter, 1)
 if value.endswith(.+ pattern): [...]

 Now, I would like to improve it by searching for different 'real'
 patterns just like using 'ls' in bash. E.g. the entry
 'car*.pdf' should select all pdf files with a beginning 'car'.
 Does anyone have an idea, how to do it?
 
 Use regular expressions. They are part of the module re. And if you  
 use them, ditch your code above, and make it just search for a pattern  
 all the time. Because the above is just the case of
 *.ext
 
 The glob module is a more direct tool based on the OP's example.  The
 example he gives works directly with glob.  To use re, you'd have to
 convert to something like car.*\.pdf, yes?
 
 I'm aware of the glob-module. But it only works on files. I was under
 the impression that he already has a list of files he wants to filter
 instead of getting it fresh from the filesystem.
 
 In that case the best way would be to use the fnmatch module - it already  
 knows how to translate from car*.pdf into the right regexp. (The glob  
 module is like a combo os.listdir+fnmatch.filter)

I have a already a list, but I 'glob' looked so easy ... maybe it is
 faster to use fnmatch. When I have time I try it out...

Thanks!
Fabian

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


Re: very strange syntax errors

2007-03-28 Thread Facundo Batista
hg wrote:


 I'v been facing some very strange errors lately:

 one example:

You'll need to paste here the exact code and the traceback.

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


Re: very strange syntax errors

2007-03-28 Thread Georg Brandl
Peter Otten schrieb:
 hg wrote:
 
 I'v been facing some very strange errors lately:
 
 one example:
 
 def __init__(self):
 
 import my_info
 some_text = my_info.T_SOME_TEXT
   ^ syntax error
 
 
 I manage to get rid of that one by moving the import on top of my file.
 
 Note: Python 2.4.1 under Windows
 
 
 Any clue ?
 
 A guess: you may have mixed Unix (\n) and Windows (\r\n) newlines. Try
 to ensure that every line ends with \r\n.

That shouldn't be a problem since Python reads source files in universal
newline mode.

Georg

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


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread bearophileHUGS
Kay Schluehr:
 RPython is heuristically defined as a subset of Python static enough
 to be translatable to C. So it is actually static analysis that is
 done here, not on a local scale but on a simpler sublanguage. It is
 not clear to me whether for a sufficiently annotated Py3K program the
 inequation RPython != Python still holds?

You may also take a very good look at ShedSkin, it's already able to
compile a decent part of Python, and that part is slowly growing
still.
I'd like to see a comparison of SSPython and RPython (width-wise and
running speed wise too) :-)

Bye,
bearophile

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


Re: Hpw make lists that are easy to sort.

2007-03-28 Thread kyosohma
On Mar 28, 12:12 pm, Anton Vredegoor [EMAIL PROTECTED]
wrote:
 Python's sorting algorithm takes advantage of preexisting order in a
 sequence:

 #sort_test.py
 import random
 import time

 def test():
  n = 1000
  k = 2**28

  L = random.sample(xrange(-k,k),n)
  R = random.sample(xrange(-k,k),n)

  t = time.time()
  LR = [(i+j) for i in L for j in R]
  print time.time()-t
  LR.sort()
  print time.time()-t

  print

  t = time.time()
  #L.sort()
  R.sort()
  presorted_LR = [(i+j) for i in L for j in R]
  print time.time()-t
  presorted_LR.sort()
  print time.time()-t

 if __name__=='__main__':
  test()

 On this -very slow- computer this prints:

  d:\python25\pythonw -u sort_test.py
 1.1014305
 8.9603815

 1.1014305
 5.4900954
  Exit code: 0

 Presorting the second sequence gains us more than three seconds. I
 wonder if there is a way to generate the combined items in such a way
 that sorting them is even faster? Is there some other sorting algorithm
 that can specifically take advantage of this way -or another way- of
 generating this list?

 The final sequence is len(L)*len(R) long but it is produced from only
 len(L)+len(R) different items, is it possible to exploit this fact? I'd
 also be interested in a more general solution that would work for
 summing the items of more than two lists in this way.

 A.

I found a website that hopefully will point you in the right
direction:

http://wiki.python.org/moin/HowTo/Sorting

And this one has an interesting profile of various sort methods with
Python:

http://www.biais.org/blog/index.php/2007/01/28/23-python-sorting-efficiency

Enjoy,

Mike

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


Re: XML/encoding/prolog/python hell...

2007-03-28 Thread kyosohma
On Mar 28, 12:40 pm, fscked [EMAIL PROTECTED] wrote:
 I am a beginning pythoner and I am having a terrible time trying to
 figure out how to do something that (it would seeme to me) should be
 fairly simple.

 I have a CSV file of unknown encoding and I need to parse that file to
 get the fields --- DONE
 I need to create an xml document that has the proper prolog and
 namespace information in it. --- NOT DONE
 I need it to be encoded properly--- Looks right in IE, not right in
 any other app.

 I should say that I have googled my butt off, tried ElementTree,
 CSV2XML, and various other things and cannot get any of them to work.

 A sample of the output I am looking for is as follows:

 ?xml version=1.0 encoding=UTF-8 standalone=yes?
 ns2:boxes xmlns:ns2=Boxes
 ns2:box id=9 mac=33 d_a=2006 hw_ver=v1.1 sw_ver=3
 pl_h=No Data name=Lounge address=here phone=555-
 country=US city=LA/
 ns2:box id=7 mac=44 d_a=2005 hw_ver=v1.0 sw_ver=3
 pl_h=No Data name=MyHouse address=there phone=555-5556
 country=US city=New York/
 /ns2:boxes

 Is there some fundamental thing I am not getting? I cannot get
 'tostrings' to work in ElementTree and I cannot figure the prolog out.

 I posted a similar message back in January, but haven't had much luck.

 PS
 No I haven't been trying to do this since January, more important
 things came up at work and I have just revived this. :)

I've never done this, but I found a recipe on the ActiveState website
that looks like it would be helpful:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/159100

I think you could modify it to make it work.

You could probably also use a combination of the csv module and the
pyxml module (links below).

http://pyxml.sourceforge.net/topics/
http://www.rexx.com/~dkuhlman/pyxmlfaq.html

I also found a Python XML book: 
http://www.oreilly.com/catalog/pythonxml/chapter/ch01.html

I hope that helps. I've started my own adventure into XML with XRC and
wxPython.

Mike

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


Re: very strange syntax errors

2007-03-28 Thread hg
Facundo Batista wrote:

 hg wrote:
 
 
 I'v been facing some very strange errors lately:

 one example:
 
 You'll need to paste here the exact code and the traceback.
 
 Regards,
 
 --
 .   Facundo
 .
 Blog: http://www.taniquetil.com.ar/plog/
 PyAr: http://www.python.org/ar/

Hi,

the code is _very_ long and has many dependencies (the longest file has a
few thousand lines (GUI callbacks) ... I know, need to refactor / but my
client is in a hurry right now so that'll wait )

So I'm not sure how I can provide any source that'll help .

I'll try the untab function of pydev on all files and see whether that fixes
the problems

hg



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


Re: Hpw make lists that are easy to sort.

2007-03-28 Thread Paul Rubin
Anton Vredegoor [EMAIL PROTECTED] writes:
 Presorting the second sequence gains us more than three seconds. I
 wonder if there is a way to generate the combined items in such a way
 that sorting them is even faster? Is there some other sorting
 algorithm that can specifically take advantage of this way -or another
 way- of generating this list?

Well there are various hacks one can think of, but is there an actual
application you have in mind?

 The final sequence is len(L)*len(R) long but it is produced from only
 len(L)+len(R) different items, is it possible to exploit this fact?
 I'd also be interested in a more general solution that would work for
 summing the items of more than two lists in this way.

If you really want the sum of several probability distriutions (in
this case it's the sum of several copies of the uniform distribution),
it's the convolution of the distributions being summed.  You can do
that with the fast fourier transform much more efficiently than
grinding out that cartesian product.  But I don't know if that's
anything like what you're trying to do.
-- 
http://mail.python.org/mailman/listinfo/python-list


newbi question on python rpc server, how it works?

2007-03-28 Thread krishnakant Mane
hello,
searched a lot of places including google search but can't find
answers to python-rpc.  I am also very new to rpc.  I am very clear
about its meaning and where it is to be used, but not about how it is
done.
I have a need where I need to create a layer of business logic that
will connect to mysql database at one end and a wxpython based thin
client at the other end.
can some one give me basic idea as to how I can use simple xml rpc
server class of python and build an xml rpc server and then a client
which I can embed in my wxpython based thin client?
as I said I am not aware of how xml rpc works in details.
I want to creat the wxpython client app in such a way that it only
does the work of validation and display and only sending the data as
is to the xml rpc server for logic and then xml rpc server will
inturn talk to mysql.
my business logic consists of many classes which I want to put in a
package directory with __init__.py and all the other modules.
do I need to create all of them as xml rpc server instances or can I
use them into one single xml rpc server class?
at the other end I am not really understanding how the xml rpc client
can be used to get data in to my wx based gui?
for example I want to fill up a list box with data that came from the
rpc server to the client and then some how looping through the
elements sent over and putting into a list.

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


Re: very strange syntax errors

2007-03-28 Thread Peter Otten
Georg Brandl wrote:

 Peter Otten schrieb:

 A guess: you may have mixed Unix (\n) and Windows (\r\n) newlines.
 Try to ensure that every line ends with \r\n.
 
 That shouldn't be a problem since Python reads source files in universal
 newline mode.

Oops, I should have guessed /that/.

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


Re: newbi question on python rpc server, how it works?

2007-03-28 Thread Larry Bates
krishnakant Mane wrote:
 hello,
 searched a lot of places including google search but can't find
 answers to python-rpc.  I am also very new to rpc.  I am very clear
 about its meaning and where it is to be used, but not about how it is
 done.
 I have a need where I need to create a layer of business logic that
 will connect to mysql database at one end and a wxpython based thin
 client at the other end.
 can some one give me basic idea as to how I can use simple xml rpc
 server class of python and build an xml rpc server and then a client
 which I can embed in my wxpython based thin client?
 as I said I am not aware of how xml rpc works in details.
 I want to creat the wxpython client app in such a way that it only
 does the work of validation and display and only sending the data as
 is to the xml rpc server for logic and then xml rpc server will
 inturn talk to mysql.
 my business logic consists of many classes which I want to put in a
 package directory with __init__.py and all the other modules.
 do I need to create all of them as xml rpc server instances or can I
 use them into one single xml rpc server class?
 at the other end I am not really understanding how the xml rpc client
 can be used to get data in to my wx based gui?
 for example I want to fill up a list box with data that came from the
 rpc server to the client and then some how looping through the
 elements sent over and putting into a list.
 
 regards.
 Krishnakant

I'm no expert, but maybe I can get you started.

If you understand how a SQL database works you can extend that knowledge
to RPC.  You make queries to the RPC server and it returns responses.
The format of the queries/responses is normally XML, but I'm pretty
sure you could invent your own if you wanted to (probably a bad idea).
Basically you define an API (like SQL queries define their API) that is
used by the clients to make requests, update information, retrieve
information, etc.

You probably should take a look at Twisted module.  It does XMLRPC with
just a few lines of code and also would scale well as you have many
users talking to the server.  Download Twisted and take a look.  You
might also want to pick up a copy of Twisted Network Programming
Essentials:

http://www.oreilly.com/catalog/twistedadn/

I'll bet it will be worth the purchase price if you choose to go this
direction.

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


Question about extending tuple

2007-03-28 Thread abcd
I wanted to extend tuple but ran into a problem.  Here is what I
thought would work

class MyTuple(tuple):
def __init__(self, *args):
tuple.__init__(self, args)

x = MyTuple(1,2,3,4)

That gives me...

TypeError: tuple() takes at most 1 argument (4 given).

However, this call works:

x = MyTuple((1,2,3,4))

I am perplexed only because args is a tuple by the definition of
*args.  Anyone?

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


Re: Question about extending tuple

2007-03-28 Thread Georg Brandl
abcd schrieb:
 I wanted to extend tuple but ran into a problem.  Here is what I
 thought would work
 
 class MyTuple(tuple):
 def __init__(self, *args):
 tuple.__init__(self, args)
 
 x = MyTuple(1,2,3,4)
 
 That gives me...
 
 TypeError: tuple() takes at most 1 argument (4 given).
 
 However, this call works:
 
 x = MyTuple((1,2,3,4))
 
 I am perplexed only because args is a tuple by the definition of
 *args.  Anyone?

As an immutable type, tuple makes use of __new__.

class MyTuple(tuple):
 def __new__(cls, *args):
 return tuple.__new__(cls, args)

should work.

Georg

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


Finding a module's sub modules at runtime

2007-03-28 Thread Joshua J. Kugler
[If this is documented somewhere, please just point me there.  I googled on
the terms that made sense to me, and didn't find anything.]

So, I have:

ModTest
__init__.py
AModule.py
BModule.py
CModule.py

All works fine.  However, when I import ModTest, I would like it to discover
and store the names of the modules beneath it, and construct a list, say
mod_list, that I can access later to find the names of the sub-modules in
this module.  Kind of setting __all__ at run time, I guess (yes, I'm aware
of the case caveats).

I figured __init__.py coudl take its own __path__ and walk the directory to
find all .py files other than __init__.py, but that seemed hackish.  Is
there an official way to do this?  Or a better way?

To give context: all the modules will have classes that have the same
name, same methods etc.  One of the modules will be picked depending on
which implementation is needed.

Thanks!

j

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com

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

Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread dmitrey
Hi!
Suppose I have a py-written module.
Is it possible somehow run PyPy on the whole module?
I didn't find it in documentation.
And if yes (or if just run in every module func) what will be after
computer restart?
Should I restart  PyPy on the module once again?
And are there any chances/intends for  PyPy to be included into Python
core?
Thx, D.


On Mar 28, 12:48 am, Carl Friedrich Bolz [EMAIL PROTECTED] wrote:
 ==PyPy1.0: JIT compilers for free and 
 more
 ==

 Welcome to thePyPy1.0 release - a milestone integrating the results
 of four years of research, engineering, management and sprinting
 efforts, concluding the 28 months phase of EU co-funding!

 Although still not mature enough for general use,PyPy1.0 materializes
 for the first time the full extent of our original vision:

 - A flexible Python interpreter, written in RPython:

- Mostly unaware of threading, memory and lower-level target platform
  aspects.
- Showcasing advanced interpreter features and prototypes.
- Passing core CPython regression tests, translatable to C, LLVM and
 .NET.

 - An advanced framework to translate such interpreters and programs:

- That performs whole type-inference on RPython programs.
- Can weave in threading, memory and target platform aspects.
- Has low level (C, LLVM) and high level (CLI, Java, JavaScript)
 backends.

 - A **Just-In-Time Compiler generator** able to **automatically**
enhance the low level versions of our Python interpreter, leading to
run-time machine code that runs algorithmic examples at speeds typical
of JITs!

 Previous releases, particularly the 0.99.0 release from February,
 already highlighted features of our Python implementation and the
 abilities of our translation approach but the **new JIT generator**
 clearly marks a major research result and gives weight to our vision
 that one can generate efficient interpreter implementations, starting
 from a description in a high level language.

 We have prepared several entry points to help you get started:

 * The main entry point for JIT documentation and status:

http://codespeak.net/pypy/dist/pypy/doc/jit.html

 * The main documentation and getting-startedPyPyentry point:

http://codespeak.net/pypy/dist/pypy/doc/index.html

 * Our online play1 demos showcasing various Python interpreters,
features (and a new way to program AJAX applications):

http://play1.codespeak.net/

 * Our detailed and in-depth Reports about various aspects of the
project:

http://codespeak.net/pypy/dist/pypy/doc/index-report.html

 In the next few months we are going to discuss the goals and form of
 the next stage of development - now more than ever depending on your
 feedback and contributions - and we hope you appreciatePyPy1.0 as an
 interesting basis for greater things to come, as much as we do
 ourselves!

 have fun,

  thePyPyrelease team,
  Samuele Pedroni, Armin Rigo, Holger Krekel, Michael Hudson,
  Carl Friedrich Bolz, Antonio Cuni, Anders Chrigstroem, Guido Wesdorp
  Maciej Fijalkowski, Alexandre Fayolle

  and many others:
  http://codespeak.net/pypy/dist/pypy/doc/contributor.html

 What isPyPy?
 

 Technically,PyPyis both a Python interpreter implementation and an
 advanced compiler, or more precisely a framework for implementing dynamic
 languages and generating virtual machines for them.

 The framework allows for alternative frontends and for alternative
 backends, currently C, LLVM and .NET.  For our main target C, we can
 can mix in different garbage collectors and threading models,
 including micro-threads aka Stackless.  The inherent complexity that
 arises from this ambitious approach is mostly kept away from the Python
 interpreter implementation, our main frontend.

 PyPyis now also a Just-In-Time compiler generator.  The translation
 framework contains the now-integrated JIT generation technology.  This
 depends only on a few hints added to the interpreter source and should
 be able to cope with the changes to the interpreter and be generally
 applicable to other interpreters written using the framework.

 Socially,PyPyis a collaborative effort of many individuals working
 together in a distributed and sprint-driven way since 2003.  PyPywould
 not have gotten as far as it has without the coding, feedback and
 general support from numerous people.

 Formally, many of the current developers were involved in executing an
 EU contract with the goal of exploring and researching new approaches
 to language and compiler development and software engineering.  This
 contract's duration is about to end this month (March 2007) and we are
 working and preparing the according final review which is scheduled
 for May 2007.

 For the future, we are in the process of setting up structures to help
 maintain conceptual integrity of the project and to discuss 

Re: newbi question on python rpc server, how it works?

2007-03-28 Thread Jeff McNeil

I've built a bit of an account provisioning/support framework here based on
SimpleXMLRPCServer (which is the one bundled w/ Python).  Take a look at
http://docs.python.org/lib/module-SimpleXMLRPCServer.html as it also
includes a bit of a code example.  It seems to work fine for my needs in
that I only server between 5 - 6 requests a minute.  All XML-RPC calls
translate into one or more LDAP calls. I've about ten clients connecting at
random times.

I've set it up to run on localhost:8080 and then I use
Apache+mod_ssl+htaccess+mod_proxy to provide some security.  Direct requests
are sent to https://user:[EMAIL PROTECTED]/RPC2 and proxied internally
back to the XMLRPC server.

Twisted might be an easier option though as you'll not have to deal with all
of the daemonization details.

Also, check out http://www.xmlrpc.com for protocol details.

Jeff

On 3/28/07, Larry Bates [EMAIL PROTECTED] wrote:


krishnakant Mane wrote:
 hello,
 searched a lot of places including google search but can't find
 answers to python-rpc.  I am also very new to rpc.  I am very clear
 about its meaning and where it is to be used, but not about how it is
 done.
 I have a need where I need to create a layer of business logic that
 will connect to mysql database at one end and a wxpython based thin
 client at the other end.
 can some one give me basic idea as to how I can use simple xml rpc
 server class of python and build an xml rpc server and then a client
 which I can embed in my wxpython based thin client?
 as I said I am not aware of how xml rpc works in details.
 I want to creat the wxpython client app in such a way that it only
 does the work of validation and display and only sending the data as
 is to the xml rpc server for logic and then xml rpc server will
 inturn talk to mysql.
 my business logic consists of many classes which I want to put in a
 package directory with __init__.py and all the other modules.
 do I need to create all of them as xml rpc server instances or can I
 use them into one single xml rpc server class?
 at the other end I am not really understanding how the xml rpc client
 can be used to get data in to my wx based gui?
 for example I want to fill up a list box with data that came from the
 rpc server to the client and then some how looping through the
 elements sent over and putting into a list.

 regards.
 Krishnakant

I'm no expert, but maybe I can get you started.

If you understand how a SQL database works you can extend that knowledge
to RPC.  You make queries to the RPC server and it returns responses.
The format of the queries/responses is normally XML, but I'm pretty
sure you could invent your own if you wanted to (probably a bad idea).
Basically you define an API (like SQL queries define their API) that is
used by the clients to make requests, update information, retrieve
information, etc.

You probably should take a look at Twisted module.  It does XMLRPC with
just a few lines of code and also would scale well as you have many
users talking to the server.  Download Twisted and take a look.  You
might also want to pick up a copy of Twisted Network Programming
Essentials:

http://www.oreilly.com/catalog/twistedadn/

I'll bet it will be worth the purchase price if you choose to go this
direction.

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

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

Re: Question about extending tuple

2007-03-28 Thread Lawrence Oluyede
abcd [EMAIL PROTECTED] wrote:
 I wanted to extend tuple but ran into a problem.  Here is what I
 thought would work

I think you should take a look at this to do it properly from the Python
devs:
http://svn.python.org/view/python/trunk/Lib/collections.py

Look for NamedTuple

-- 
Lawrence, oluyede.org - neropercaso.it
It is difficult to get a man to understand 
something when his salary depends on not
understanding it - Upton Sinclair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about extending tuple

2007-03-28 Thread abcd
 As an immutable type, tuple makes use of __new__.

 class MyTuple(tuple):
  def __new__(cls, *args):
  return tuple.__new__(cls, args)

 should work.

 Georg

strange.  not very consistent.

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


Re: Finding a module's sub modules at runtime

2007-03-28 Thread kyosohma
On Mar 28, 2:44 pm, Joshua J. Kugler [EMAIL PROTECTED] wrote:
 [If this is documented somewhere, please just point me there.  I googled on
 the terms that made sense to me, and didn't find anything.]

 So, I have:

 ModTest
 __init__.py
 AModule.py
 BModule.py
 CModule.py

 All works fine.  However, when I import ModTest, I would like it to discover
 and store the names of the modules beneath it, and construct a list, say
 mod_list, that I can access later to find the names of the sub-modules in
 this module.  Kind of setting __all__ at run time, I guess (yes, I'm aware
 of the case caveats).

 I figured __init__.py coudl take its own __path__ and walk the directory to
 find all .py files other than __init__.py, but that seemed hackish.  Is
 there an official way to do this?  Or a better way?

 To give context: all the modules will have classes that have the same
 name, same methods etc.  One of the modules will be picked depending on
 which implementation is needed.

 Thanks!

 j

 --
 Joshua Kugler
 Lead System Admin -- Senior Programmerhttp://www.eeinternet.com
 PGP Key:http://pgp.mit.edu/ ID 0xDB26D7CE

 --
 Posted via a free Usenet account fromhttp://www.teranews.com

I think you need to research how to create documentation. When I
import a module/package, I can then type help(moduleName) and it'll
give me the module or package's contents.

http://mail.python.org/pipermail/python-list/2003-February/192069.html

You may be able to figure out how to do this just be studying the
help module itself.

Mike

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


SimpleXMLRPCServer and Threading

2007-03-28 Thread Achim Domma
Hi,

is SimpleXMLRPCServer multithreaded or how does it handle multiple 
clients? I want to implement a simple server which will be queried by 
multiple processes for work to be done. The server will simply hold a 
queue with files to process. The clients will ask for the next file.

Do I have to sync access to the queue or is the server not threaded at all?

regards,
Achim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hpw make lists that are easy to sort.

2007-03-28 Thread Anton Vredegoor
Paul Rubin wrote:

 Well there are various hacks one can think of, but is there an actual
 application you have in mind?

Suppose both input lists are sorted. Then the product list is still not 
  sorted but it's also not completely unsorted. How can I sort the 
product? I want to know if it is necessary to compute the complete 
product list first in order to sort it. Is it possible to generate the 
items in sorted order using only a small stack?

Also, I have a sumfour script that is slow because of sorting. It would 
become competitive to the hashing solution if the sorting would be about 
ten times faster. If the items could be generated directly in order the 
script would also have only a very small memory footprint.

 If you really want the sum of several probability distriutions (in
 this case it's the sum of several copies of the uniform distribution),
 it's the convolution of the distributions being summed.  You can do
 that with the fast fourier transform much more efficiently than
 grinding out that cartesian product.  But I don't know if that's
 anything like what you're trying to do.

I want the product, but sorted in less time. If Fourier transforms can 
help, I want them :-)

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


Re: newbi question on python rpc server, how it works?

2007-03-28 Thread Goldfish
  I have a need where I need to create a layer of business logic that
  will connect to mysql database at one end and a wxpython based thin
  client at the other end.

Spring Python offers something similar (http://springpython.python-
hosting.com/wiki/DistributedRemoting) to link up clients withs
servers. You can code locally, and then when it is time to split
things up between different workstations, you can reconfigure the
networking.

There is a demo application, PetClinic (http://springpython.python-
hosting.com/wiki/PetClinic) that shows a database component, remoting
pieces, and finally a front end. The current version of PetClinic is a
web app. In the near future, we are planning to build a wxPython front
end to show more reusability of components.

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


Re: Question about extending tuple

2007-03-28 Thread Georg Brandl
abcd schrieb:
 As an immutable type, tuple makes use of __new__.

 class MyTuple(tuple):
  def __new__(cls, *args):
  return tuple.__new__(cls, args)

 should work.

 Georg
 
 strange.  not very consistent.

On the contrary -- __new__ *and* __init__ exist for all types.
The only difference is where a specific object is initialized, and
therefore which method you have to override.

__new__ is a static method (it doesn't need to be declared as one,
this is done automatically as it predates the introduction of
staticmethod()) which is called to *construct* an instance.
This can only be done once for a specific object since each call to
__new__ will result in a *new* object. In other words, this is
perfect for immutable objects -- once created, never changed.

__init__, OTOH, is called on the *instance* to initialize it. Of
course, this process can be repeated, and is therefore apt for
mutable objects like lists.

I hope you see now why it is consistent.

Georg

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


Re: Finding a module's sub modules at runtime

2007-03-28 Thread Joshua J. Kugler
On Wednesday 28 March 2007 12:04, [EMAIL PROTECTED] wrote:
 All works fine.  However, when I import ModTest, I would like it to
 discover and store the names of the modules beneath it, and construct a
 list, say mod_list, that I can access later to find the names of the
 sub-modules in
 this module.  Kind of setting __all__ at run time, I guess (yes, I'm
 aware of the case caveats).

 I figured __init__.py coudl take its own __path__ and walk the directory
 to
 find all .py files other than __init__.py, but that seemed hackish.  Is
 there an official way to do this?  Or a better way?

 To give context: all the modules will have classes that have the same
 name, same methods etc.  One of the modules will be picked depending on
 which implementation is needed.
 
 I think you need to research how to create documentation. When I
 import a module/package, I can then type help(moduleName) and it'll
 give me the module or package's contents.
 
 http://mail.python.org/pipermail/python-list/2003-February/192069.html
 
 You may be able to figure out how to do this just be studying the
 help module itself.
 
 Mike

Well, it seems the help module is a built in, and has no .py file
anywhere.  The epydoc package uses the imports.file_modules(dirname)
function, which just walks the directory tree.  Thanks for the
pointer...just confirmed that I have to do something I wanted to avoid. 
But I guess if I use Python's os module and the __path__ string, it should
still be nicely portable.  It just seems that since Python is gathering
that information anyway, it should make it available without me having to
walk the directory tree.

j

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com

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

Re: SimpleXMLRPCServer and Threading

2007-03-28 Thread Jeff McNeil

I do it this way and it's always worked great for me.

SimpleXMLRPCServer is based on SocketServer, so you can use the ForkingMixIn
or ThreadingMixIn classe to create something to handle requests in
parallel.

from SocketServer import ThreadingMixIn
import SimpleXMLRPCServer

class ThreadedXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
   My Threaded XMLRPC Server

You'll then use ThreadedXMLRPCServer when you instance your server object.

-Jeff



On 3/28/07, Achim Domma [EMAIL PROTECTED] wrote:


Hi,

is SimpleXMLRPCServer multithreaded or how does it handle multiple
clients? I want to implement a simple server which will be queried by
multiple processes for work to be done. The server will simply hold a
queue with files to process. The clients will ask for the next file.

Do I have to sync access to the queue or is the server not threaded at
all?

regards,
Achim
--
http://mail.python.org/mailman/listinfo/python-list

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

manually implementing staticmethod()?

2007-03-28 Thread 7stud
Hi,

Can someone show me how to manually implement staticmethod()?  Here is
my latest attempt:

def smethod(func):

def newFunc():
pass

def newGet():
print new get

newFunc.__get__ = newGet

return newFunc

class Test(object):

def show(msg):
print msg
show = smethod(show)


Test.show(hello)
--
...but I keep getting the error:

TypeError: unbound method newFunc() must be called with Test instance
as first argument (got str instance instead)

I think I need to intercept the function's __get__() method in order
to block creation of the method object, which requires that the
unbound method call provide an instance.

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


Finding User Profile path

2007-03-28 Thread kyosohma
Hi,

I am trying to query our domain to get a list of our users profile
locations. I thought I might be able to use WMI, but I can't get it to
work. I am using a Windows XP Pro workstation and Python 2.4 on a
mixed environment of Debian Linux (with Samba) and Windows servers. We
are in the process of moving the user profiles from an NT box to a
Debian box, but due to the many different servers in the organization,
it is a pain to keep track of which have been moved and which haven't.

Thank you for any help.

Mike

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


Re: XML/encoding/prolog/python hell...

2007-03-28 Thread fscked

[EMAIL PROTECTED] wrote:
---SNIP---
 I've never done this, but I found a recipe on the ActiveState website
 that looks like it would be helpful:

 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/159100


I tried looking at that but couldn't figure out how to get the
property file working.


 I think you could modify it to make it work.

 You could probably also use a combination of the csv module and the
 pyxml module (links below).

 http://pyxml.sourceforge.net/topics/
 http://www.rexx.com/~dkuhlman/pyxmlfaq.html

These are a little too confusing for me. :)

 I also found a Python XML book: 
 http://www.oreilly.com/catalog/pythonxml/chapter/ch01.html

 I hope that helps. I've started my own adventure into XML with XRC and
 wxPython.

 Mike

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


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Carl Friedrich Bolz
Hi!

dmitrey wrote:
 Hi!
 Suppose I have a py-written module.
 Is it possible somehow run PyPy on the whole module?
 I didn't find it in documentation.
 And if yes (or if just run in every module func) what will be after
 computer restart?
 Should I restart  PyPy on the module once again?
 And are there any chances/intends for  PyPy to be included into Python
 core?

PyPy contains a full Python interpreter (which can include a JIT 
compiler) and thus replaces the Python core. PyPy can never really be 
integrated into CPython.

Cheers,

Carl Friedrich Bolz
-- 
http://mail.python.org/mailman/listinfo/python-list


Creating a new data structure while filtering its data origin.

2007-03-28 Thread mmara
Hi everyone.

I'm trying to work with very simple data structures but I'm stuck in the very 
first steps. If someone has the luxury of a few minutes and can give an advice 
how to resolve this, I'll really appreciate it.

1- I have a list of tuples like this:
lista= [(162, 141, 3), (162, 141, 3), (162, 141, 3), (168, 141, 2), (168, 141, 
2), (168, 141, 2), (201,  141, 1), (213, 141, 1), (203, 141, 1), (562, 142, 4), 
(562, 142, 4), (562, 142, 4), (568, 142, 2), (568, 142, 2), (568, 142, 2), 
(501,  142, 1), (513, 142, 1), (503, 142, 1)]
and I want to end with a dict like this:
{141: {1: [203, 213, 201], 2: [168, ], 3: [162, ]}, 142: {1: [503, 513, 501], 
2: [568, ], 4: [562, ]}}
 the logic of the final output:
 a) the outer dict's key is a set() of the 2rd value of the input.
 b) the inner dict's key is a set() of the 3th value for tuples which 3rd value 
equals a). 
 c) the inner list will be fill up with the 1st value of every tuple which 3rd 
value equals b) and its 2rd value equals a).

So far, the only thing it seems I can achieve is the first part:
outer_dict = dict([(x,dict()) for x in set(row[1] for row in lista)])

From then on, I'm starting to get tired after several successful failures (I 
tried with itertools, with straight loops ...) and I don't know which can be 
the easier way to get that final output.

Thanks in advance.


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


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Jarek Zgoda
Carl Friedrich Bolz napisał(a):

 Welcome to the PyPy 1.0 release - a milestone integrating the results
 of four years of research, engineering, management and sprinting
 efforts, concluding the 28 months phase of EU co-funding!

So it took 4 yars of work and over 2 yaers of consumption of EU funds,
yeah, great.

Could anybody explain, what this gives to Python and its users? Would
we, eventually, get GIL-free VM, that is capable to consume all
available power of multicore processors? Or, maybe, we'll get something
special, I am unable to dream of? Or is it purely academic project to
create Python VM in Python?

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Carl Friedrich Bolz
Kay Schluehr wrote:
  Nice to read that things are going on. I've still a PyPy 0.7 version
  on my notebook. I guess I will upgrade :)
 
  A somewhat unrelated question. With Py3K Python gets optional type
  annotations. Are you already architecting an annotation handler that
  can process these annotations? This feature is somewhat competitive to
  all the complicated type inference and jitting you have been worked
  out so I don't know how it fits well into the current PyPy
  architecture?

I don't see at all why type annotations are competitive to the type
inference that PyPy's translation toolchain is doing. The type inference
of PyPy is an artefact of the way we are implementing our interpreter
(namely in RPython). You also wouldn't say that the static typing of C
is competitive to type annotations because CPython is written in C,
right?

The JIT (which is completely independent from our type inference engine)
will hopefully deal well with the eventual addition of type annotations
(it's not clear to me how soon we will start supporting Py3k features,
we are not even fully supporting Python 2.5 yet). Since the JIT is
automatically generated out of the Python interpreter it should deal
with any sort of language changes rather well. Whether that is true in
practice remains to be seen, but this is one of the reason why PyPy was
started in the first place.

Also, I fail to see how type annotations can have a huge speed-advantage
versus what our JIT and Psyco are doing. Imagine you have a function
that is nicely algorithmic, takes only integers as arguments and only
does some calculations with them. If you have a Psyco-like scheme, the
JIT will note that you are using it mostly with ints, generate
relatively efficient assembly for the whole function (at least after it
has been called several times). If you call that functions, the
arguments are checked whether they are integers and then the fast
assembly code is used without any further type checks. How can you
improve on this with type annotations? If the type annotations say that
your arguments have to be ints, you _still_ have to check whether this
is true. So it is not faster than what Psyco is doing and has the
disadvantage that it only works with ints -- good bye, duck typing.
Psyco on the other hand will be perfectly happy with you using a custom
class that looks mostly like an int and generate assembly optimized for
this situation.

Cheers,

Carl Friedrich Bolz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyPy 1.0: JIT compilers for free and more

2007-03-28 Thread Christian Tismer

On 28.03.2007, at 23:36, Jarek Zgoda wrote:

 Carl Friedrich Bolz napisał(a):

 Welcome to the PyPy 1.0 release - a milestone integrating the results
 of four years of research, engineering, management and sprinting
 efforts, concluding the 28 months phase of EU co-funding!

 So it took 4 yars of work and over 2 yaers of consumption of EU funds,
 yeah, great.

 Could anybody explain, what this gives to Python and its users? Would
 we, eventually, get GIL-free VM, that is capable to consume all
 available power of multicore processors? Or, maybe, we'll get  
 something
 special, I am unable to dream of? Or is it purely academic project to
 create Python VM in Python?

It will eventually give you a GIL-free VM, and it already gives you
a lot more than you have dreamt of.

There is one feature missing that is probably hard to add.
Handling the 'posters who are not willing to read before they post'  
syndrome.

cheers - chris

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

Re: manually implementing staticmethod()?

2007-03-28 Thread Michael Spencer

7stud [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hi,

 Can someone show me how to manually implement staticmethod()?  Here is
 my latest attempt:
 
Raymond Hettinger can:

http://users.rcn.com/python/download/Descriptor.htm#static-methods-and-class-methods




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


Re: PDB does not allow jumping to first statement?

2007-03-28 Thread Chris Lasher
I have submitted this as a bug via SourceForge:
https://sourceforge.net/tracker/?
func=detailatid=105470aid=1689458group_id=5470
or if munged
http://tinyurl.com/2nwxsf

The Python folks would like a test case and/or a patch. This is well
beyond my ken as a humble Python user. Could anybody more
knowledgeable please contribute one or both? Duncan or Rocky, would
you be able to spare time and effort?

Chris

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


How can I find out the size of a file

2007-03-28 Thread Marko . Cain . 23
Hi,

How can I find out the size of a file in a disk in python?

i try this, but it does not work:
 size = open(inputFileNameDir + / + file, 'r').size()

Thank for any help.

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


Re: How can I find out the size of a file

2007-03-28 Thread Irmen de Jong
[EMAIL PROTECTED] wrote:
 How can I find out the size of a file in a disk in python?

os.path.getsize(filename)


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


Re: Hpw make lists that are easy to sort.

2007-03-28 Thread Terry Reedy

Anton Vredegoor [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| Paul Rubin wrote:
|
|  Well there are various hacks one can think of, but is there an actual
|  application you have in mind?
|
| Suppose both input lists are sorted. Then the product list is still not
|  sorted but it's also not completely unsorted. How can I sort the
| product? I want to know if it is necessary to compute the complete
| product list first in order to sort it. Is it possible to generate the
| items in sorted order using only a small stack?

If you have lists A and B of lengths m and n, m  n, and catenate the m 
product lists A[0]*B, A[1]*B, ..., A[m-1]*B, then list.sort will definitely 
take advantage of the initial order in each of the m sublists and will be 
faster than sorting m*n scrambled items (which latter is O(m*n*log(m*n))).

One could generate the items in order in less space by doing, for instance, 
an m-way merge, in which only the lowest member of each of the m sublists 
is present at any one time.  But I don't know if this (which is 
O(m*n*log(m))) would be any faster (in some Python implementation) for any 
particular values of m and m.

Terry Jan Reedy



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


how can I clear a dictionary in python

2007-03-28 Thread Marko . Cain . 23
Hi,

I create a dictionary like this
myDict = {}

and I add entry like this:
myDict['a'] = 1
but how can I empty the whole dictionary?

Thank you.

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


Re: Creating a new data structure while filtering its data origin.

2007-03-28 Thread Larry Bates
[EMAIL PROTECTED] wrote:
 Hi everyone.
 
 I'm trying to work with very simple data structures but I'm stuck in the very 
 first steps. If someone has the luxury of a few minutes and can give an 
 advice how to resolve this, I'll really appreciate it.
 
 1- I have a list of tuples like this:
 lista= [(162, 141, 3), (162, 141, 3), (162, 141, 3), (168, 141, 2), (168, 
 141, 2), (168, 141, 2), (201,  141, 1), (213, 141, 1), (203, 141, 1), (562, 
 142, 4), (562, 142, 4), (562, 142, 4), (568, 142, 2), (568, 142, 2), (568, 
 142, 2), (501,  142, 1), (513, 142, 1), (503, 142, 1)]
 and I want to end with a dict like this:
 {141: {1: [203, 213, 201], 2: [168, ], 3: [162, ]}, 142: {1: [503, 513, 501], 
 2: [568, ], 4: [562, ]}}
  the logic of the final output:
  a) the outer dict's key is a set() of the 2rd value of the input.
  b) the inner dict's key is a set() of the 3th value for tuples which 3rd 
 value equals a). 
  c) the inner list will be fill up with the 1st value of every tuple which 
 3rd value equals b) and its 2rd value equals a).
 
 So far, the only thing it seems I can achieve is the first part:
 outer_dict = dict([(x,dict()) for x in set(row[1] for row in lista)])
 
From then on, I'm starting to get tired after several successful failures (I 
tried with itertools, with straight loops ...) and I don't know which can be 
the easier way to get that final output.
 
 Thanks in advance.
 
 

d={}
for a, b, c in lista:
if d.has_key(b):
if d[b].has_key(c):
if a not in d[b][c]: d[b][c].append(a)

else:
d[b][c]=[a]
else:
d[b]={c:[a]}


print d

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


Re: how can I clear a dictionary in python

2007-03-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 Hi,
 
 I create a dictionary like this
 myDict = {}
 
 and I add entry like this:
 myDict['a'] = 1
 but how can I empty the whole dictionary?

  help(dict)
Help on class dict in module __builtin__:

class dict(object)
(...)
  |  Methods defined here:
(...)
  |
  |  clear(...)
  |  D.clear() - None.  Remove all items from D.
(...)
 
  d = dict(a=1, b=2)
  d
{'a': 1, 'b': 2}
  d.clear()
  d
{}
 

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


Re: how can I clear a dictionary in python

2007-03-28 Thread Aahz
In article [EMAIL PROTECTED],
Larry Bates  [EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] wrote:
 
 I create a dictionary like this
 myDict = {}
 
 and I add entry like this:
 myDict['a'] = 1
 but how can I empty the whole dictionary?

just point myDict to an empty dictionary again

myDict={}

Go back and read Christian's post, then post a followup explaning why his
solution is better than yours.  Your explanation should use id().
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

Need a book?  Use your library!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how can I clear a dictionary in python

2007-03-28 Thread Christian Tismer

On 29.03.2007, at 00:48, Larry Bates wrote:

 [EMAIL PROTECTED] wrote:
 Hi,

 I create a dictionary like this
 myDict = {}

 and I add entry like this:
 myDict['a'] = 1
 but how can I empty the whole dictionary?

 Thank you.


 just point myDict to an empty dictionary again

 myDict={}

This is wrong and not answering the question.
Creating a new dict does not change the dict.
He wants to clear *this* dict, and maybe he
cannot know how many other objects are
referring to this dict.

cheers -- chris


--
pointless questions or useless answers - what do you like more
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >