[ANN] Release 0.59 of Task Coach

2006-08-23 Thread Frank Niessink
Hi all,

I'm pleased to announce release 0.59 of Task Coach. New in this release:

Bugs fixed:
* Improved efficiency while tracking effort for tasks.
* The column width of the list with filenames in the attachment page of 
the task editor is now adaptable, so that long filenames can be made 
visible entirely.
* Translation errors in tips.
* When having multiple tasks with the same subject, new effort records 
would always be created for the first of these tasks instead of the 
selected task.
* Opening a file with a non-ascii filename specified on the command line 
did not work.

Features added:
* Japanese translation thanks to Yutaka Usui.
* Filter sidebar.
* Printing. Selecting 'File' - 'Print' will print the currently active 
view. This means only the visible columns will be printed and only the 
filtered tasks will be printed, in the current sort order.
* Export to HTML. Selecting 'File' - 'Export' - 'Export to HTML' will 
export the currently active view to HTML. This means only the visible 
columns will be exported and only the filtered tasks will be printed, in 
the current sort order.
* Columns with numbers or dates are right-aligned.


What is Task Coach?

Task Coach is a simple task manager that allows for hierarchical
tasks, i.e. tasks in tasks. Task Coach is open source (GPL) and is
developed using Python and wxPython. You can download Task Coach from:

http://taskcoach.niessink.com
https://sourceforge.net/projects/taskcoach/

A binary installer is available for Windows XP and a disk image is
available for Mac OSX, in addition to the source distribution.

Note that Task Coach is alpha software, meaning that it is wise to back
up your task file regularly, and especially when upgrading to a new release.

Cheers, Frank

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


[ANN]UliPad 3.3 is released

2006-08-23 Thread limodou
What's it?


It's an Editor based on wxPython. NewEdit is the old name, and UliPad
is the new name. UliPad uses Mixin and Plugin technique as its
architecture. Most of its classes can be extended via mixin and plugin
components, and finally become an integrity class at
creating the instance. So UliPad is very dynamic. You can write the
new features in new files, and hardly need to modify the existing
code. And if you want to extend the existing classes, you could write
mixins and plugins, and this will be bound to the target class that I
call Slot Class. This technique will make the changes centralized
and easily managed.

What are its features?


  *  Cross platform
o   based on wxPython, so it can run anywhere that wxPython
works, such as: Windows, Linux.
o   Unicode support.

  *  Most features of wxStyledTextCtrl(Scintilla)
o   Syntax highlighting, support Python, c/c++, html, plain
text, perl, ruby, css, javascript
o   Folding
o   Brace Matching
o   ...

  *  Extended selection
o   Extended word selection -- You can press
Ctrl+MouseDoubleClick to select a word including '.'
o   Matched selection -- Select text in quoted chars like:
(), [], {}, '', .
  *  Other editing extension
o   Duplicating text -- Just like Vim Ctrl+V, Ctrl+P, and
more. You can duplicate above or below char, word, line
o   Quoting text -- Add some quoted chars before and after
selected text, just as: , '', (), [], {}, and
o   Text convertion and view -- python - html, reStructured
Text - html, textile - html, and you can output or view
o   Utf-8 encoding auto detect
o   Changing document encoding
oAuto backup
oLast session support -- It'll save all the filenames as
closed, and reopen the files as next started.
oSmart judge the indent char -- It'll auto guess the
indent char, and sets it.
oFinding in files
oBookmark support

  *  Python support
obuilt-in python interactive window based on ?PyShell,
support Unicode
o   Auto completion
o   Function syntax calltips
o   Run, run with argument, stop python source
o   Auto change current path
o   Python class browser
o   Indent pasting support(New)

  *  Code snippets
o  You can manage your code snippets with categories, and
each category can have many items. Every item will represent a code
snippet. You can insert an item just by double-clicking on it. It even
supports importing and exporting.

  *  Simple project support
o  Can create a special file _project, so every file and
folder under the folder which has the _project can be considered as a
whole project.

  *  Extension mechanism
o  Script -- You can write easy script to manipulate the all
resource of UliPad, just like: text conversion, etc.
o  Plugin -- Customized function. More complex but more
powerful. Can easily merge with UliPad, and can be managed via menu.
o  Shell command -- Add often used shell commands, and execute them.

  *  Ftp support
o  You can edit remote files through ftp. You can add,
rename, delete, upload, download file/directory.

  *  Multilanguage support
o  Currently supports two languages: English and Chinese,
which can be auto-detected.

  *  Shipped plugins(must be configed as used them before)
o  Document links -- Python documentation and wxPython documentation.
o  Many plugins can be found at UliPad wiki page.

  *  Shipped scripts
o  Many scripts can be found at UliPad wiki page.

  *  Wizard (New)
o  You can make your own wizard template. The wizard can
input user data, combine with template, and output the result. And
wizard also support code framework created. This feature will help you
improving coding efficiency.

  *  Direcotry Browser(New)
o  Browse multiple directories, and you can really add,
delete, rename directories and files. Double click will open the file
in Editor window.
o  Support Copy, Cut, and Paste.
o  Search in Directory

  *  AutoComPlete(acp)(New)
o  Suport user autocomplete file, it can help to input code
very helpful and functional. Just like EditPlus, but may be more
powerful.
o  Manually apply some acp files to current document

  *  Column Edit Mode(New)

Where to download it?


download lastest version 3.3:
http://wiki.woodpecker.org.cn/moin/UliPad?action=AttachFiledo=gettarget=UliPad_3.3.zip
also have windows installer:
http://wiki.woodpecker.org.cn/moin/UliPad?action=AttachFiledo=gettarget=UliPad3.3.exe
wiki: http://wiki.woodpecker.org.cn/moin/UliPad
svn: http://cvs.woodpecker.org.cn/svn/woodpecker/ulipad/trunk
maillist: http://groups.google.com/group/ulipad

If you have any problem as using UliPad, welcome to join the UliPad
maillist to discuss.

Hope fun!



-- 
I like python!
My 

ANNOUNCE: kiwi 1.9.9

2006-08-23 Thread Johan Dahlin
Kiwi is a PyGTK framework for building graphical applications loosely
based on MVC Model-View-Controller (MVC) and Allen Holub's Visual proxy
[1]. Think of Kiwi as a high-level, object-oriented layer built on
PyGTK.

Its design is based on real-world experience using PyGTK to develop
large desktop applications, which use many concepts common to most
graphical applications: multiple windows and dialogs, forms, data
persistence, lists and high-level classes that support domain objects
directly.


Download


Grab the latest sources from:

  http://download.gnome.org/sources/kiwi/1.9/kiwi-1.9.9.tar.gz


What's new since 1.9.8?
===

- KiwiEntry improvements (Johan, Patrick, Ronaldo)
- Win32 installation fixes for Gazpacho  Kiwi (Johan)
- DateEntry fixes (Ronaldo, Johan)
- DateEntry win32 support (Aaron Spike)
- Logging improvements (Johan)
- Datatypes refactoring and improved Gazpacho integration (Ronaldo)
- Add UI tests (Johan)
- Bugs fixes:
  #2535: entry needs exceptions that don't fail (Patrick O'Brien)
  #2545: DateEntry calendar popup doesn't hide correctly (Ronaldo)
  #2562: Falha na exibição de valores do tipo currency
(Lincoln, Ronaldo)
  #2610: [Patch] Remove unnecessary on_column__clicked handler
(Dave Cook)
  #2611: Adding a sortable keyword to objectlist (Dave Cook)
  #2612: [Patch] objectlist.refresh() fix and optimization (Dave Cook)
  #2632: Problems with datatype currency when the language ...
 (Lincoln, Johan)
  #2654: Decimal precision is removed when pickling (Ronaldo)
  #2656: ComboEntry's clear() is missing (Ronaldo)
  #2681: Kiwi doesn't respect system colors after widget ...
 (Johan, Gustavo Barberi)
  #2682: Mandatory fields fails to validade if they state ...
 (Gustavo, Ronaldo)
  #2685: Make it able to turn fading of invalid stateness to ...
 (Ali, Johan)
  #2697: Add a pixbuf data type (Johan, Ronaldo)
  #2698: Add a ProxyButton (Johan, Henrique)
  #2720: DateEntry breaks when set invalid. (Ali)
  #2721: Missing locale specific date formatting information ...
(Aaron Spike, Johan)
  #2758: Datatype converters should provide a get_mask method. (Ronaldo)

Features


* An MVC-derived framework of classes:
  * Views, which represent the graphical display
  * Controllers, which handles user interaction with the widgets
in a View.
  * Delegates, combines a View and a Controller.
  * Models, which are special mixins for your domain objects
  * Proxies, special types of Delegate designed to implement forms

* Validation: Kiwi supports validation on different levels:
  data type validation and verification on the Model/Proxy level,
  View validation and hooks for visually displaying validation state.

* ObjectList widget, which provides a higher level abstraction of
  GtkTreeView and all its classes (GtkTreeModel, GtkTreeViewColumn,
  GtkCellRenderer) with hooks to easily integrate into the
  Kiwi Framework.

* Mask suport: You can set a mask on entries to force the input to
  follow a certain standard, such as zip code, social security, ip address

* Gazpacho integration for most (non-deprecated) interactive
  widgets with attributes for handling validation and proxy
  attributes.

* UI Testing framework
  Features a recorder and a player. The recorder allows you to record
  different tasks, a script will be saved which will reproduce the
  actions you made in the interface.

* Kiwi Tasklets
  Tasklet is a small coroutines framework written by Gustavo Carneiro,
  it was previously known as gtasklets.

* PyGTK utilities, to make it easier to add signals and properties to
  your objects.

* i18n translation utilities, to help you translate PyGTK applications,
  currently depends on gettext and intltool.

* and many other things!


Requirements


Python 2.3 or higher (2.4 recommended)  http://www.python.org/
PyGTK 2.6.0 or higher (2.8 recommended) http://www.pygtk.org/
gazpacho 0.6.5 (svn recommenced)http://gazpacho.sicem.biz/


Documentation
=
Kiwi provides API documentation generated by epydoc, it can be found at

 http://www.async.com.br/projects/kiwi/api/

Included in the tarball are also a number of examples, which serves as a
good starting point. Keep in mind that most of them require gazpacho to
be installed.


Thanks
==
Christian Robottom Reis: Original author and design
Lorenzo Gil Sanchez: PyGTK 2.x port

Also thanks to the following people which has contributed features
or bug reports:
Ali Afshar, Gustavo Barbieri, Gustavo Carneiro, David M Cook,
Daniel Saran R. da Cunha, Patrick O'Brien, Ronaldo Maia, Evandro Vale
Miquelito, Henrique Romano, Sidnei da Silva, Aaron Spike

Resources
=

Homepage http://www.async.com.br/projects/kiwi/
Download http://www.async.com.br/projects/kiwi/download/
Repository   

ANN: Urwid 0.9.6 - Console UI Library

2006-08-23 Thread Ian Ward
Announcing Urwid 0.9.6
--

Urwid home page:
   http://excess.org/urwid/

Tarball:
   http://excess.org/urwid/urwid-0.9.6.tar.gz


About this release:
===

This release improves Unicode support with Python  2.4 and new features 
were added to the tutorial and reference generation scripts.

The graph.py example program introduced in 0.9.5 should now work 
properly for everyone.  Please let me know if you have any trouble with it.


New in this release:


   - Fixed Unicode conversion and locale issues when using Urwid with
 Python  2.4.  The graph.py example program should now work
 properly with older versions of Python.

   - The docgen_tutorial.py script can now write out the tutorial
 example programs as individual files.

   - Updated reference documentation table of contents to show which
 widgets are flow and/or box widgets.

   - Columns.set_focus(..) will now accept an integer or a widget as
 its parameter.

   - Added detection for rxvt's HOME and END escape sequences.

   - Added support for setuptools (improved distutils).


About Urwid
===

Urwid is a console UI library for Python. It features fluid interface
resizing, UTF-8 support, multiple text layouts, simple attribute markup,
powerful scrolling list boxes and flexible interface design.

Urwid is released under the GNU LGPL.






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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: how do you get the name of a dictionary?

2006-08-23 Thread Fredrik Lundh
jojoba wrote:

 no, you're just wasting a lot of bandwidth making it clear that you just
 cannot be bothered to learn how things actually work.
 
 By the way, what exactly led you to this conclusion?

the fact that despite all attempts to explain how things work, you're 
still haven't realized that if you want the names of things, you should 
pass *namespaces* to your object viewer, not individual objects.

/F

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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Georg Brandl
Steven D'Aprano wrote:
 On Tue, 22 Aug 2006 10:12:00 -0700, BartlebyScrivener wrote:
 
 how difficult would it be to assign a string name(s)
 to an object upon creation (and upon referencing)?
 
 Exactly the point that's being made. It's so easy just do it yourself:
 
 banana={name:banana}
 
 Hey what is the name of my dictionary?
 
 banana[name]
 
 But why build it into Python and force everyone else to do it, when
 most of the time nobody cares what the name is, or they already know?
 
 It's like forcing everybody everywhere always and forever to wear
 Hello My Name Is tags.
 
 On reflection, I'm wondering if we've been too harsh on Jojoba and not
 thought this through, simply because that's the way it's always been.
 
 Functions have a __name__ attribute. So do classes and modules. Why are
 these three objects special that they know the name they were created
 with, when other objects don't? Python doesn't attempt to track what name
 they are known at *now*, just the name they were born with.

Because they're not created by simple assignment, because they are
usually created once, because new names are bound to them rarely,
and because it's crucial to know their name in debugging, introspection etc.

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


Re: Python and STL efficiency

2006-08-23 Thread Mc Osten
Ray [EMAIL PROTECTED] wrote:

 I'm using VC++ Express, I didn't care to tweak the optimizations, I
 merely chose the Release configuration for the executable. It's
 blazing fast, taking only 30+ ms each run.

Of course it is faster. We are looping 100 times, you just 1.

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and STL efficiency

2006-08-23 Thread Mc Osten
Ray [EMAIL PROTECTED] wrote:

 Not really, see my test, in my other post in the same thread. I'm using
 VC++ Express 2005. If we're comparing with Python 2.5 I think it's just
 fair that for C++ we're using the latest as well.

In your test, you are looping 1 times, we looped 100.
In Python tests with 1 elements, it was about 10 ms.

Moreover, we tried various Python and C++ configurations. Most of the
tests are done with Python 2.4, not 2.5.
And I used gcc4, that is to say the latest on my platform.
 
 Same here, although that said Python's implementation of those data
 structure must already be as optimal as mortals can do it. 

I think this is the rationale behind it.

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and STL efficiency

2006-08-23 Thread Mc Osten
[EMAIL PROTECTED] wrote:

 That's to say,
 python is still much faster?

Yes it is. But of course you can't sat that Python is faster than C++.
We found that the code to do this, written in the most natural way, is a
lot faster in Python. However, if you optimze the code, C++ gets almost
as fast.

In other benchmarks C++ outperforms Python and is 10 or 100 times
faster.


 Maybe someone can post this to the c++ maillist and they will tell how
 to accelerate it.

There are enough C++ experts here to do it. The point is another.

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you get the name of a dictionary?

2006-08-23 Thread Fredrik Lundh
Steven D'Aprano wrote:

 But an upside is that it would enable more useful error messages, at least
 sometimes. Here's some trivial pseudo-code:
 
 def foo(a):
 assert len(a)  10, %s is too short % a.__name__
 
 y = hello
 foo(y)
 
 would display AssertionError: y is too short.

why not a is too short ?

or for that matter, x is to short ?

/F

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


Re: Modules... paths... newbie confusion

2006-08-23 Thread MrBlueSky
Well thank you all... that's all very helpful (apart from the brief
diversion into MySQL, but even that was instructive!).

Your comments about setup.py prompted me to read the pytz README.txt
a bit more carefully and there it says to run python setup.py
install.  And this copies stuff into site-packages.  So it's all
starting to come together and make a bit more sense to me, hurrah!

There's no README.txt with MSSQL, and python setup.py install gave me
a compilation error:
c:\Python24\MSSQL-0.09\mssqldb.h(16) : fatal error C1083: Cannot open
include file: 'sqlfront.h'.  I suspect I'm missing some MS SQL Server
developer stuff.

Copying the files myself to site-packages didn't work either: there's
only a mssqldb.pyd file, no .py or .pyc file.  And as you pointed out,
there's no 2.4 folder so I'm a bit worried about compatibility.

So I abandoned this library and decided to try another SQL Server
library instead.   I tried pymssql and it came with a Windows installer
so I didn't need to run setup.py, which meant I didn't need the MS SQL
Server developer stuff.  Worked First Time!

To conclude: I've got all the answers I needed and have acquired some
useful understanding... thank you very much indeed!

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


Re: Python and STL efficiency

2006-08-23 Thread Ray

Mc Osten wrote:
 Ray [EMAIL PROTECTED] wrote:

  I'm using VC++ Express, I didn't care to tweak the optimizations, I
  merely chose the Release configuration for the executable. It's
  blazing fast, taking only 30+ ms each run.

 Of course it is faster. We are looping 100 times, you just 1.

Certainly--I was not comparing 100 against 1. Referring to the
OP's statement: However, while the python code gave the result almost
instantly, the C++ code took several seconds to run! 30ms sounds like
a definite improvement over several seconds!

I'll try to tweak it later at home and report here. I'll try out the
100 too.

Cheers
Ray


 --
 blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
 site:  http://www.akropolix.net/rik0/  | tenetevi riso e
 forum: http://www.akropolix.net/forum/ | bacchette per voi.

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


Re: Python and STL efficiency

2006-08-23 Thread Ray

Mc Osten wrote:
 In your test, you are looping 1 times, we looped 100.
 In Python tests with 1 elements, it was about 10 ms.

 Moreover, we tried various Python and C++ configurations. Most of the
 tests are done with Python 2.4, not 2.5.
 And I used gcc4, that is to say the latest on my platform.

Mine's VC 2005 Express--let me put the optimization parameters later
and measure again when I get home.  

snip

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


Re: What do you want in a new web framework?

2006-08-23 Thread Hendrik van Rooyen
Fredrik Lundh [EMAIL PROTECTED] wrote:

| Alex Martelli wrote:
| 
|  Indeed, it has been truthfully observed that Python's the only language
|  with more web frameworks than keywords.
| 
| recent research indicates that it has more web frameworks than comments
| in the source code.
| 
| /F 

Argh!


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


Re: What do you want in a new web framework?

2006-08-23 Thread Hendrik van Rooyen
 Alex Martelli [EMAIL PROTECTED]


| Tim Roberts [EMAIL PROTECTED] wrote:
|...
|  themselves.  However, in the case of web frameworks, I believe Marc is
|  fundamentally correct: the web framework proliferation in Python is
|  actually doing the language a huge disservice.
| 
| Indeed, it has been truthfully observed that Python's the only language
| with more web frameworks than keywords.
| 
| I have already suggested to the BDFL that he can remedy this situation
| in Py3k: all he has to do, of course, is to add a LOT more keywords.
| 
| 
| Alex

*groan*


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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Hendrik van Rooyen
 jojoba [EMAIL PROTECTED] Wrote:

|  At the risk of stating the obvious, why don't you simply add a parameter
|  for the title in the invocation of the tree editor? I.e. instead of
|  invoke_tree_editor(somedict)
|  do
|  invoke_tree_editor(somedict, somedict)
|  HTH,
|  Carsten.
|
|
| Thanks Carsten.
| This would indeed allow me to assign a title for my dicitonaries, but i
| am looking for something more general..
| specfically:
| given any dictionary, get a name for it.
|
| But yeah, your way would totally work!
| Thanks,
| jojoba
|

At the risk of asking the even more obvious - given any dictionary - How is it
given - just print whatever it is that causes you to believe that you are
dealing with a dictionary..

- Hendrik

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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Steven D'Aprano
On Wed, 23 Aug 2006 08:56:54 +0200, Fredrik Lundh wrote:

 Steven D'Aprano wrote:
 
 But an upside is that it would enable more useful error messages, at least
 sometimes. Here's some trivial pseudo-code:
 
 def foo(a):
 assert len(a)  10, %s is too short % a.__name__
 
 y = hello
 foo(y)
 
 would display AssertionError: y is too short.
 
 why not a is too short ?
 
 or for that matter, x is to short ?

These are all valid responses too. But consider that when you get an
exception that says a is too short, you often have to mentally change
gears and think about where a came from and what it is called in the
enclosing scope. After all, if the value of a is invalid, and the value of
a is set in the enclosing scope, it makes sense to refer to the object
known locally as a by the name it was known as when it was set.

Of course, this leads to greater complexity, it still doesn't deal well
with objects known by multiple names, or no name at all, and it would
require a lot of overhead for something which is only of value
occasionally. In other words, the downside outweighs the upside
significantly.



-- 
Steven D'Aprano 

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


Re: Translating Javascript programs to python.

2006-08-23 Thread supercoder

Vyz wrote:
 Hi,
 I have a script with hundreds of lines of javascript spread accross 7
 files. Is there any tool out there to automatically or
 semi-automatically translate the code into python.

 Thanks
 Vyz

Not a tool, but assuming the javascript is not too complex you could
interpret some of it using python and the CGI module.

But really, what would be the use?

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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Robert Kern
Steven D'Aprano wrote:
 On Wed, 23 Aug 2006 08:56:54 +0200, Fredrik Lundh wrote:
 
 Steven D'Aprano wrote:

 But an upside is that it would enable more useful error messages, at least
 sometimes. Here's some trivial pseudo-code:

 def foo(a):
 assert len(a)  10, %s is too short % a.__name__

 y = hello
 foo(y)

 would display AssertionError: y is too short.
 why not a is too short ?

 or for that matter, x is to short ?
 
 These are all valid responses too. But consider that when you get an
 exception that says a is too short, you often have to mentally change
 gears and think about where a came from and what it is called in the
 enclosing scope. After all, if the value of a is invalid, and the value of
 a is set in the enclosing scope, it makes sense to refer to the object
 known locally as a by the name it was known as when it was set.

That's what tracebacks are for. You don't have to mentally change gears; you 
just look.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth.
   -- Umberto Eco

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


Re: Python and STL efficiency

2006-08-23 Thread GHUM
Mc Osten schrieb:

 Yes it is. But of course you can't sat that Python is faster than C++.

Of course not. Python is faster then assembler. Proofed @ EuroPython
2006 in CERN, near the LHC Beta, in the same room many Nobel laurates
gave their presentations before.

Harald

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


Python bindings for picasaweb ...

2006-08-23 Thread manatlan
Just a post to announce some python bindings for picasaweb (photo's
service of google).
--- PycasaWeb (GPL), http://manatlan.infogami.com/pycasaweb
I think it may be usefull for linux users, because it's one of the only
way to post pictures on picasaweb. And can be usefull to script batch
with it ... and our wonderful python box ;-)

It's inspired from the recent google-sharp module :
http://svn.myrealbox.com/viewcvs/trunk/google-sharp/?rev=63077

I will try to implement others api, but contributions are accepted ;-)

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


Re: Python and STL efficiency

2006-08-23 Thread Mc Osten
Ray [EMAIL PROTECTED] wrote:

 Certainly--I was not comparing 100 against 1. Referring to the
 OP's statement: However, while the python code gave the result almost
 instantly, the C++ code took several seconds to run! 30ms sounds like
 a definite improvement over several seconds!

Of course. I suppose there's something broken in OP's C++ setup (in fact
the version I compiled with VCPP 2005 also takes a lot of seconds...
something like 20-30 seconds, but of course this makes me think I
haven't understood how it is supposed to work, since my gcc gives
results comparable to yours).

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and STL efficiency

2006-08-23 Thread Mc Osten
GHUM [EMAIL PROTECTED] wrote:

 Proofed @ EuroPython
 2006 in CERN, near the LHC Beta, in the same room many Nobel laurates
 gave their presentations before.

Have you some link? I suppose it's kind of a joke they did or something
like that...

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN]UliPad 3.3 is released

2006-08-23 Thread limodou
What's it?


It's an Editor based on wxPython. NewEdit is the old name, and UliPad
is the new name. UliPad uses Mixin and Plugin technique as its
architecture. Most of its classes can be extended via mixin and plugin
components, and finally become an integrity class at
creating the instance. So UliPad is very dynamic. You can write the
new features in new files, and hardly need to modify the existing
code. And if you want to extend the existing classes, you could write
mixins and plugins, and this will be bound to the target class that I
call Slot Class. This technique will make the changes centralized
and easily managed.

What are its features?


  *  Cross platform
o   based on wxPython, so it can run anywhere that wxPython
works, such as: Windows, Linux.
o   Unicode support.

  *  Most features of wxStyledTextCtrl(Scintilla)
o   Syntax highlighting, support Python, c/c++, html, plain
text, perl, ruby, css, javascript
o   Folding
o   Brace Matching
o   ...

  *  Extended selection
o   Extended word selection -- You can press
Ctrl+MouseDoubleClick to select a word including '.'
o   Matched selection -- Select text in quoted chars like:
(), [], {}, '', .
  *  Other editing extension
o   Duplicating text -- Just like Vim Ctrl+V, Ctrl+P, and
more. You can duplicate above or below char, word, line
o   Quoting text -- Add some quoted chars before and after
selected text, just as: , '', (), [], {}, and
o   Text convertion and view -- python - html, reStructured
Text - html, textile - html, and you can output or view
o   Utf-8 encoding auto detect
o   Changing document encoding
oAuto backup
oLast session support -- It'll save all the filenames as
closed, and reopen the files as next started.
oSmart judge the indent char -- It'll auto guess the
indent char, and sets it.
oFinding in files
oBookmark support

  *  Python support
obuilt-in python interactive window based on ?PyShell,
support Unicode
o   Auto completion
o   Function syntax calltips
o   Run, run with argument, stop python source
o   Auto change current path
o   Python class browser
o   Indent pasting support(New)

  *  Code snippets
o  You can manage your code snippets with categories, and
each category can have many items. Every item will represent a code
snippet. You can insert an item just by double-clicking on it. It even
supports importing and exporting.

  *  Simple project support
o  Can create a special file _project, so every file and
folder under the folder which has the _project can be considered as a
whole project.

  *  Extension mechanism
o  Script -- You can write easy script to manipulate the all
resource of UliPad, just like: text conversion, etc.
o  Plugin -- Customized function. More complex but more
powerful. Can easily merge with UliPad, and can be managed via menu.
o  Shell command -- Add often used shell commands, and execute them.

  *  Ftp support
o  You can edit remote files through ftp. You can add,
rename, delete, upload, download file/directory.

  *  Multilanguage support
o  Currently supports two languages: English and Chinese,
which can be auto-detected.

  *  Shipped plugins(must be configed as used them before)
o  Document links -- Python documentation and wxPython documentation.
o  Many plugins can be found at UliPad wiki page.

  *  Shipped scripts
o  Many scripts can be found at UliPad wiki page.

  *  Wizard (New)
o  You can make your own wizard template. The wizard can
input user data, combine with template, and output the result. And
wizard also support code framework created. This feature will help you
improving coding efficiency.

  *  Direcotry Browser(New)
o  Browse multiple directories, and you can really add,
delete, rename directories and files. Double click will open the file
in Editor window.
o  Support Copy, Cut, and Paste.
o  Search in Directory

  *  AutoComPlete(acp)(New)
o  Suport user autocomplete file, it can help to input code
very helpful and functional. Just like EditPlus, but may be more
powerful.
o  Manually apply some acp files to current document

  *  Column Edit Mode(New)

Where to download it?


download lastest version 3.3:
http://wiki.woodpecker.org.cn/moin/UliPad?action=AttachFiledo=gettarget=UliPad_3.3.zip
also have windows installer:
http://wiki.woodpecker.org.cn/moin/UliPad?action=AttachFiledo=gettarget=UliPad3.3.exe
wiki: http://wiki.woodpecker.org.cn/moin/UliPad
svn: http://cvs.woodpecker.org.cn/svn/woodpecker/ulipad/trunk
maillist: http://groups.google.com/group/ulipad

If you have any problem as using UliPad, welcome to join the UliPad
maillist to discuss.

Hope fun!



-- 
I like python!
My 

Re: Python and STL efficiency

2006-08-23 Thread Ray

Mc Osten wrote:
 Of course. I suppose there's something broken in OP's C++ setup (in fact
 the version I compiled with VCPP 2005 also takes a lot of seconds...
 something like 20-30 seconds, but of course this makes me think I
 haven't understood how it is supposed to work, since my gcc gives
 results comparable to yours).

Yeah, my guess would be either he used the Debug configuration or he
actually created a Managed executable instead of a pure Win32
application. Sigh, now I can't wait to get home and try it out :)


 --
 blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
 site:  http://www.akropolix.net/rik0/  | tenetevi riso e
 forum: http://www.akropolix.net/forum/ | bacchette per voi.

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


Re: Python and STL efficiency

2006-08-23 Thread Maric Michaud
Le mardi 22 août 2006 23:15, Fredrik Lundh a écrit :
 Maric Michaud wrote:
  The problem here, is that the strings in the set are compared by value,
  which is not optimal, and I guess python compare them by adress (s*n is
  s*n has the same complexity than s*n == s*n in CPython, right ?).

 wrong.


Ah ! wrong, thanks, but not in our case :

In [80]: for i in (10**e for e in range(5)) :
   : res1 = timeit.Timer('s == t', 's, t = e*%i, e*%i'%(i, 
i)).timeit()
   : res2 = timeit.Timer('s is t', 's, t = e*%i, e*%i'%(i, 
i)).timeit()
   : print res1/res2
   :
   :
1.10532866525
1.27507328965
1.90244004672
8.33974283485
89.5215441627

Indeed, it's wrong for two instances of str, but not if we compare an instance 
to itself :

In [79]: for i in (10**e for e in range(9)) :
   : r1=timeit.Timer('s is p', s, p = ('s'*%s,)*2 % i).timeit()
   : r2=timeit.Timer('s == p', s, p = ('s'*%s,)*2 % i).timeit()
   : print r1/r2
   :
   :
0.854690643008
0.872682262181
0.851785060822
0.871193603744
0.890304121256
0.86925960859
0.846364097331
0.91614070798
0.825424114324


So my lastest c++ algorithm is the good one still, as the python code is 
like :

In [29]: timeit.Timer('set(t)', 't=(e*10,)*10').timeit()
Out[29]: 1.883868932723999

In [30]: timeit.Timer('set(t)', 't=(e*100,)*10').timeit()
Out[30]: 1.8789899349212646

and not :

In [27]: timeit.Timer('set(t)', 't=[e*10 for i in range(10)]').timeit()
Out[27]: 2.6000990867614746

In [28]: timeit.Timer('set(t)', 't=[e*100 for i in range(10)]').timeit()
Out[28]: 4.1173238754272461



   timeit -ss='x'; n=1000 s*n is n*s

 100 loops, best of 3: 1.9 usec per loop

   timeit -ss='x'; n=1000 s*n == n*s

 10 loops, best of 3: 4.5 usec per loop

 /F

-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Unicode Error

2006-08-23 Thread Tim Golden
[Gallagher, Tim (NE)]

| Hey all I am learning Python and having a fun time doing so.  
| I have a question for y'all, it has to do with active directory.

| I want to get the last login for a computer from Active 
| Directory.  I am using the active_directory module and here 
| is my code.

[START]
import active_directory
computer = active_directory.root()
for cpu in computer.search (cn='Computer_Name'): 
print cpu.samAccountName#←--- Works find
print cpu.operatingSystem   #←--- Works find
print cpu.lastLogon #←--- Getting Error
[END]

| I get an error that I am not sure what to do with, the error 
| is TypeError: coercing to Unicode: need string or buffer, 
| instance found in my line Do I have to change the output to 
| meet Unicode formation?

I started to write an explanation of Unicode and what an
encoding was and why you needed it, but then I realised
that it wouldn't help - at least not here - because the
problem seems to involve converting the value in cpu.lastLogon
to Unicode. And I'm not sure why it's even trying to do that.

The lastLogon value (according to the MS docs) is actually
a structure in its own right with a HighPart and a LowPart,
and you perform various maths on these numbers to give
you a real date. In my case (cf code below) if I simply print the 
lastLogon, I get the anonymous COMObject string.

code
import active_directory
me = active_directory.find_computer ()
print me.samAccountName

print me.lastLogon 
# gives COMObject unknown

print me.lastLogon.HighPart, me.lastLogon.LowPart
# gives two long numbers

/code

Short answer, try lastLogon.HighPart  lastLogon.LowPart

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Steven D'Aprano
On Wed, 23 Aug 2006 02:44:28 -0500, Robert Kern wrote:

 But consider that when you get an
 exception that says a is too short, you often have to mentally change
 gears and think about where a came from and what it is called in the
 enclosing scope. After all, if the value of a is invalid, and the value of
 a is set in the enclosing scope, it makes sense to refer to the object
 known locally as a by the name it was known as when it was set.
 
 That's what tracebacks are for. You don't have to mentally change gears; you 
 just look.

Here's a traceback. One of the arguments to spam() is too small. Can you
tell which one just by looking at the traceback?

 a, b, c, d = range(4)
 spam(a, b, c, d)
Traceback (most recent call last):
  File stdin, line 1, in ?
  File stdin, line 6, in spam
  File stdin, line 5, in eggs
  File stdin, line 4, in beans
ValueError: x is too small

Of course you can't. x could be any one of a, b, c or d, and the traceback
doesn't give you enough information to tell which.

 def spam(foo, bar, baz, qux):
... def eggs(alpha, beta, gamma, delta):
... def beans(w, x, y, z):
... raise ValueError(x is too small)
... beans(alpha, beta, gamma, delta)
... eggs(foo, bar, baz, qux)
...

Nesting the functions was an arbitrary choice -- the same issue occurs
regardless of whether they are nested or not. That's a relatively simple
example, with only three layers of nested scopes (four if you count the
global scope). I've seen tracebacks with twenty or thirty levels. Ouch.

I could have come up with a devilishly convoluted example if I wished,
reusing the same names for different purposes in different scopes, or
re-binding the names multiple times, or even simply moving the order of
arguments around from one function to another. But that would be overkill.

This is NOT a complaint against Python's object module, merely a call to
recognise that, in some instances, if objects knew their own name, it
would be useful. As I've already said, the benefit gained is probably less
than the cost required, so I'm not suggesting that Python work this way.
But the idea isn't totally pointless.


-- 
Steven D'Aprano 

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


Re: Python and STL efficiency

2006-08-23 Thread Maric Michaud
Tim, sorry for I send it to you personally, I was abused by thunderbird.

Tim N. van der Leeuw a écrit :

 
 Your C++ version got me the following timings (using gcc 3.4.5 as the
 compiler, MinGW version, with -O6):
 
 ...
 
 
 Hmmm... Can we conclude now that carefully crafted C++ code is about
 twice as fast as casually and intuitively written Python code? ;) (Just
 kidding here of course)

Every C++ code must be carefully crafted :).

But your benchmark surprise me, here is what I get on my windows box :

Python2.4 :
===

[EMAIL PROTECTED] /cygdrive/c/Documents and Settings/maric/Bureau
$ which python2.4
/usr/bin/python2.4

[EMAIL PROTECTED] /cygdrive/c/Documents and Settings/maric/Bureau
$ which python
/cygdrive/c/Python24/python

[EMAIL PROTECTED] /cygdrive/c/Documents and Settings/maric/Bureau
$ python2.4 testpython.py
so long...
What do you know
fool
chicken crosses road
Elapsed: 3.655000 seconds

[EMAIL PROTECTED] /cygdrive/c/Documents and Settings/maric/Bureau
$ python testpython.py
so long...
What do you know
fool
chicken crosses road
Elapsed: 3.077764 seconds

Cygwin version is slower, but not too much.

C++, compiled with VS2005, release, no other configuration :


print_occurence_of_strings
What do you know?
chicken crosses road
fool
so long...
print_occurence_of_unique_strings
What do you know?
chicken crosses road
fool
so long...
print_occurence_of_unique_strings_compared_by_address
What do you know?
chicken crosses road
fool
so long...
strings : 16.718 # memory allocation is quite bad
unique strings : 1.188
compared by address : 0.453

C++, with gcc 3.3/Cygwin


[EMAIL PROTECTED] /cygdrive/c/Documents and Settings/maric/Bureau
$ g++ -O3 -o testcpp testcpp.cpp

[EMAIL PROTECTED] /cygdrive/c/Documents and Settings/maric/Bureau
$ ./testcpp
print_occurence_of_strings
What do you know?
chicken crosses road
fool
so long...
print_occurence_of_unique_strings
What do you know?
chicken crosses road
fool
so long...
print_occurence_of_unique_strings_compared_by_address
What do you know?
chicken crosses road
fool
so long...
strings : 17.266 # still bad
unique strings : 1.547
compared by address : 0.375

Hum, with my old gcc I get equal or better performances than with VS2005.

Finally, the equivalent code is still about 10x faster in c++ than in 
Python, as it was on my Linux box.



Mc Osten a écrit :
...
  However, I would have written the code using a proper compare function
  rather than using two sets. In this particular case the number of
  elements of the first set is negligible in respect of the initial vector
  size, thus copying it again does not take a lot of time.
  But such code is optimized for the problem itself: in the real world I

Of course, it's a quick hack to get the same behavior.

  suppose we would have passed set a proper comparison function that
  checks address and then string equality.
 

Yes, furthermore, that is *exactly* what the python code is doing (see 
my other post to Fredrik).


-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create a Multilanguage PDF in Python

2006-08-23 Thread Rob Wolfe

Perseo wrote:
 Nothing to do!
 I enable test2.py and the folder with 777 permission and I write at the
 top of the file the PYTHONPATH #!/usr/bin/python as you told me but
 it doesn't works as well.

#!/usr/bin/python is not PYTHONPATH. I think you should
read this:
http://docs.python.org/tut/node4.html#SECTION00422

 The verdana font doesn't exist in the reportlab fonts folder. I try to
 delete the rows where it is called like (registerFont, setFont) but
 nothing to do.

Fonts are not part of reportlab package. You should find it
in your OS or in the net. You need to know what font do you want to
use.

 any suggestion?!

Install reportlab package in your home directory, for example
/home/perseo/python/lib

and then in the shell write this:

export PYTHONPATH=/home/perseo/python/lib

and look here:
http://docs.python.org/tut/node8.html#SECTION00811

HTH,
Rob

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


Re: What do you want in a new web framework?

2006-08-23 Thread Paul Boddie
Cliff Wells wrote:

 I disagree.  Even if most of the frameworks end up being nothing more
 than research artifacts, the fact is they embody research.  Without
 research the Python web framework space will be forever relegated to
 runner-up (and probably has-been at some point).

It's perhaps surprising that even in the areas of the software industry
that are focused on selling expertise by providing services, as opposed
to selling licences for some code, that the research aspect of
developing some software, along with the knowledge gained in the
exercise, is frequently ignored in favour of some mass of code that is
gradually approaching legacy status. Familiarity with the problem
domain is extremely useful, even if it produces no long-lasting product
such as a popular Web framework, and the mere knowledge gained in
producing something that perhaps no-one else wants to use can be
important in informing future decisions about adopting (rather than
developing) suitable frameworks, if nothing else.

[...]

 Ruby on Rails doesn't come preinstalled either.  I don't think it's
 appropriate (and apparently most Linux distros currently agree) to
 install web programming frameworks by default.

I think the comment about pre-installed frameworks either confused the
issue of availability with the default package selection in some
distros, or mistook some announcement/hype about Rails on Mac OS X as
being an indication of a wider trend.

[...]

 No, the reason Rails is successful is due to being a decent, focused
 product with *great* marketing (screencasts, anyone?).

Screencasts? Perhaps, like a great showman, they draw in the punters
effectively enough, but I'd rather developers concentrate on writing
decent documentation than stuffing the pipes of the Internet up with
multi-megabyte proprietary blobs showing some individual developing
hello world (and still having to practise slight-of-hand in order to
make it slick enough).

[...]

 Also the fact that Ruby doesn't suck isn't hurting Rails any either.  If
 GvR wants to improve Python's status against Ruby, I suggest looking at
 what people are *really* raving about in the Ruby world (despite how
 they got there) and address those issues rather than getting sidetracked
 with this nonsense.

First of all, I'd take the raving from the Ruby scene with a pinch of
salt, given the tendency of the blog personalities doing the raving to
breathlessly declare some kind of victory at every turn - as Steve
Holden once said, these people are good at the don't mention the
weaknesses style of marketing, and that's probably something various
Python Web framework developers have picked up quite effectively. I'd
rather the Python core developers stopped chasing shadows and looked at
the Python distribution in its entirety. Hopefully, the Python 3000
exercise will see its focus shift into really removing the artifacts of
legacy decisions in both the language and the library rather than
shoehorning more wishlist items into the language.

Paul

P.S. Wishlist shoehorning example: decorators plus annotations (not
really for static typing, honest!) equals...

http://mail.python.org/pipermail/python-3000/2006-August/003034.html

It's possible that the example decorator in the above message
unintentionally communicates the cynical view of decorators, but the
spectre of multi-page annotations is still worth worrying about even
if you're a decorator fan. See other messages in that thread for some
of the ideas (and to bring forth that longing for simpler times).

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


Finding the type of indexing supported by an object?

2006-08-23 Thread Derek Peschel
Here are two functions.

def invert_dict_to_lists(dict):
lists = {}
for key in dict:
value = dict[key]
if not value in lists:
lists[value] = [key]
else:
lists[value].append(key)
return lists

def invert_list_to_lists(list):
lists = {}
for key in range(len(list)):
value = list[key]
if not value in lists:
 lists[value] = [key]
else:
lists[value].append(key)
return lists

They are the same except for the expression in for key in   Can they
be combined into one function?  How can I determine if the argument is
like a list (with numeric indices that are not stored in the list) or a dict
(with arbitrary keys that are stored)?  I said object in the subject,
but I want to support Python primitive types, class instances, extension
module types (array, dictproxy, dbm, gdbm, etc.), and any future types.

I've thought about looking for keys(), looking for the special method names
that allow you to override indexing behavior, and looking at the class or
type of the object.  I could be wrong, but I don't think any of those
strategies will work with all arguments.

Thanks,

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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Michael Janssen
jojoba wrote:

 given any dictionary, get a name for it.

You do not want to open your text editor and hardcode the name (neither
as a variable name nor a name-attribute), do you? Your script is
hopefully capable to determine the dict-to-be-displayed from
user-input? Perhaps name of a file to be parsed?

 anydict = getTheDamnDict(userinput)
 displayTheDamnDict(anydict)

Even when you can display the name of the variable the dictionary is
assigned to you yield 'anydict'. That's not that compelling. When you
really intend to hardcode the variable's name to something meaningful,
how is your script supposed to do sensible work after your work is done
with it?

When you want to have a programm that can display arbitrary
dictionaries you end up with a variable name that is (hopefully ;-)
meaningful in the context of the programm but not meaningful in respect
of the content of the dictionary: at programming-time you can't know
what dictionaries are to be displayed so you don't have meaningful
names. You might want to take the name of the file to be parsed or
something else from userinput as the name of the dict - but the
variables name is the wrong place to store this information. Did I miss
anything?

regards
Michael

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


Creating a subpackage of a built-in module?

2006-08-23 Thread Derek Peschel
Can I add my own subpackages to modules that are written in C?

I've put /Users/dpeschel/lib/python into my PYTHONPATH variable.
Inside there, I've created a termios directory, and inside termios
I've created __init__.py and signals.py.  Now import termios.signals
works, but import termios only appears to work (it has no effect).
Do I have to do something sneaky in __init__.py to find the original
module, or is there a better way?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the type of indexing supported by an object?

2006-08-23 Thread Fredrik Lundh
Derek Peschel wrote:

 I've thought about looking for keys(), looking for the special method names
 that allow you to override indexing behavior, and looking at the class or
 type of the object.  I could be wrong, but I don't think any of those
 strategies will work with all arguments.

the behaviour of obj[arg] is determined by the __getitem__ method, and
that method can do whatever it wants.

/F 



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


Re: Finding the type of indexing supported by an object?

2006-08-23 Thread Peter Otten
Derek Peschel wrote:

 Here are two functions.
 
 def invert_dict_to_lists(dict):
 lists = {}
 for key in dict:
 value = dict[key]
 if not value in lists:
 lists[value] = [key]
 else:
 lists[value].append(key)
 return lists
 
 def invert_list_to_lists(list):
 lists = {}
 for key in range(len(list)):
 value = list[key]
 if not value in lists:
  lists[value] = [key]
 else:
 lists[value].append(key)
 return lists
 
 They are the same except for the expression in for key in   Can they
 be combined into one function?  How can I determine if the argument is
 like a list (with numeric indices that are not stored in the list) or a
 dict
 (with arbitrary keys that are stored)?  I said object in the subject,
 but I want to support Python primitive types, class instances, extension
 module types (array, dictproxy, dbm, gdbm, etc.), and any future types.
 
 I've thought about looking for keys(), looking for the special method
 names that allow you to override indexing behavior, and looking at the
 class or
 type of the object.  I could be wrong, but I don't think any of those
 strategies will work with all arguments.

Instead of the (unreliable) introspection approach you could let the client
code decide:

 def invert(pairs):
... result = {}
... for k, v in pairs:
... if v in result:
... result[v].append(k)
... else:
... result[v] = [k]
... return result
...
 invert(dict(a=1, b=2, c=1).iteritems())
{1: ['a', 'c'], 2: ['b']}
 invert(enumerate([1,1,2,3]))
{1: [0, 1], 2: [2], 3: [3]}

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


Re: swapping numeric items in a list

2006-08-23 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Jiang Nutao
wrote:

 To convert list
 aa = [0x12, 0x34, 0x56, 0x78]
 into
 [0x34, 0x12, 0x78, 0x56]
 
 How to do it fast? My real list is huge.

Use the `array` module and the `array.byteswap()` method.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you get the name of a dictionary?

2006-08-23 Thread Fredrik Lundh
Steven D'Aprano wrote:

 Here's a traceback. One of the arguments to spam() is too small. Can you
 tell which one just by looking at the traceback?

 a, b, c, d = range(4)
 spam(a, b, c, d)
 Traceback (most recent call last):
  File stdin, line 1, in ?
  File stdin, line 6, in spam
  File stdin, line 5, in eggs
  File stdin, line 4, in beans
 ValueError: x is too small

 Of course you can't. x could be any one of a, b, c or d, and the traceback
 doesn't give you enough information to tell which.

for some reason, your example gives a different error on my machine:

StrawManError: Attempt to construct Reductio ad absurdum argument failed

/F 



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


Re: key not found in dictionary

2006-08-23 Thread Sion Arrowsmith
Chaz Ginger  [EMAIL PROTECTED] wrote:
KraftDiner wrote:
 desc = self.numericDict[k][2]
 KeyError: 589824    This is the error that is being produced,
As stated you can wrap the access in the try - except - else statement, 
as in

try:
  foo['bar']
except :
  # Handle the error.

Bare except is generally a bad idea. Here, it could be letting
through whole truckloads of other errors. Suppose the OP typos:

try:
desc = self.numericDict[j][2]
except:
# handle missing key

but the except isn't handling a KeyError, it's got a NameError
(assuming j doesn't exist). Or what if self.numericDict[k] exists
but self.numericDict[k][2] gives a TypeError or IndexError? It
really needs to be:

except KeyError:

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: idutils and Python

2006-08-23 Thread Fabio Zadrozny
 What exactly are you trying to accomplish?If you want to index function/class names, variables, etc then you should take a look at
 exuberant ctags http://ctags.sourceforge.net53 --although it started off as a C indexer, it has excellent Python support, it's free, and as a bonus its indices are well supported from inside major editors (vim,
 emacs, etc) so you can easily follow code flow, find function/class definitions, etc.Sorry for not being clear enough. I want the following:a) have my editor go to the point where a function/whatever is defined

Pydev Extensions (http://www.fabioz.com/pydev) should do that without
any problems with F3 (it first tries a 'context-sensitive' match,
trying to find it in locals, globals, current class, etc and if not
found like that, it goes and looks for the signature in a
context-insensitive way, as if it was a simple text-search)
b) see all places where a function/whatever is used.
This can be handed pretty well with the search that is builtin into Eclipse (ctrl+h). 

Cheers,

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

Re: Can I do this with list comprehension?

2006-08-23 Thread barberomarcelo
Thanks a lot to everybody.

Marcelo

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


Re: Python and STL efficiency

2006-08-23 Thread bearophileHUGS
This thread can be useful for ShedSkin (the Python = C++ translator),
because often it manages strings slower than CPython still, some
suggestions from a C++ expert can surely improve things a lot. C++ is
fast, but you have to use and know it well, otherwise you don't obtain
much speed.

Maybe this can be useful to speed up C++ hashing (now used in ShedSkin
too):
http://www.azillionmonkeys.com/qed/hash.html

I suggest to test this code with the D language too, it has built-in
dicts too (associative arrays, impleented with trees and not hashes),
so the source code needed is pretty short.

Bye,
bearophile

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


Re: Python and STL efficiency

2006-08-23 Thread Mc Osten
Ray [EMAIL PROTECTED] wrote:

 Yeah, my guess would be either he used the Debug configuration or he
 actually created a Managed executable instead of a pure Win32
 application. Sigh, now I can't wait to get home and try it out :)

Can be. But I suppose a Managed should not get *that* slow. 
IronPython on Tim's machine is still faster than C++ (even though not as
fast as CPython).

-- 
blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
site:  http://www.akropolix.net/rik0/  | tenetevi riso e
forum: http://www.akropolix.net/forum/ | bacchette per voi.
-- 
http://mail.python.org/mailman/listinfo/python-list


find, replace and save string in ascii file

2006-08-23 Thread peter
Hello all,

I'm looking for an advice.

Example (one block in ascii file):
$
NAME='ALFA'
CODE='x'
$

There are many similar blocks in the file with different NAMEs and
different CODEs. What I'm looking for is a script that searchs through
whole file and finds all strings with name ALFA and based on what CODE
is after each ALFA (can be x, y or z) the ALFA name is replaced by
BETAx,BETAy or BETAz and so changed file saves.

What I did is that I can find all strings which I need, next I change
these strings based on CODE, but what I can't is to replace old string
with new one, on the same position in the file. It always writes new
string at the end of the file. Here is my code

Thanks in advance for any kind of help. Regards, Boris


import shutil

NamFile=test2.nam
BackupNamFile = 1
if BackupNamFile == 1:
shutil.copyfile(NamFile,NamFile.replace(.nam,.nam.bak))
LineNum=1
LineNumQuantity=0
ArrayCount=0
LineNumArray=[]
ReqArray=[]
ReqName=
NamFileOpen=file(NamFile,r+)
for line in NamFileOpen:
LineTextFound1 = line.find(bk)
LineTextFound2 = line.find(_results)
if LineTextFound1 != -1 and LineTextFound2 != -1:
ReqName=line.split(')[1]
print Line: \t\t\t+ str(LineNum)
print Request Name: \t\t+ ReqName
LineNumQuantity = LineNum + 2
ReqArray=[LineNum-2,ReqName]
if LineNum == LineNumQuantity:
QuantityName=line.split(')[1]
print Quantity Type: \t\t+QuantityName
if QuantityName == dx:
Suffix = _disp
elif QuantityName == vx:
Suffix = _velo
elif QuantityName == fx:
Suffix = _force
else:
Suffix = _results
print Suffix: \t\t+Suffix
NewReqName=ReqName.replace(_results,Suffix,1)
ReqArray.append(NewReqName)
LineNumArray.insert(ArrayCount,ReqArray)
ArrayCount+=1
print New Request Name: \t+NewReqName
print ---
LineNum = LineNum+1
print LineNumArray
print len(LineNumArray)
NamFileOpen.close()

NamFileOpen2=file(NamFile,r+)
LineNum=1
for i in LineNumArray:
print i
for line in NamFileOpen2:
print line
print LineNum
print i[1]
if i[0]== LineNum:
print i[0]
print LineNum
print line
Temp=line.replace(line.split(')[1],i[2],1)
print Temp
NamFileOpen2.write(Temp) 
LineNum=LineNum+1 
NamFileOpen2.close()

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


Re: swapping numeric items in a list

2006-08-23 Thread Boris Borcic
Jiang Nutao wrote:
 Hi,
 
 I simplify my problem like below
 
 To convert list
 aa = [0x12, 0x34, 0x56, 0x78]
 into
 [0x34, 0x12, 0x78, 0x56]
 
 How to do it fast? My real list is huge.

Mark Rintsch's suggestion appears best if applicable, but just to cite yet 
other 
ways to do it :

list(aa[j+(-1)**j] for j in range(len(aa)))

or

sum(reversed(zip(*[reversed(aa)]*2)),())

or (py 2.5)

from itertools import izip
ab = iter(aa)
list((yield y) or x for x,y in izip(ab,ab))

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


Re: find, replace and save string in ascii file

2006-08-23 Thread Amit Khemka
On 23 Aug 2006 05:48:37 -0700, peter [EMAIL PROTECTED] wrote:
 Hello all,

 I'm looking for an advice.

 Example (one block in ascii file):
 $
 NAME='ALFA'
 CODE='x'
 $

 There are many similar blocks in the file with different NAMEs and
 different CODEs. What I'm looking for is a script that searchs through
 whole file and finds all strings with name ALFA and based on what CODE
 is after each ALFA (can be x, y or z) the ALFA name is replaced by
 BETAx,BETAy or BETAz and so changed file saves.

 What I did is that I can find all strings which I need, next I change
 these strings based on CODE, but what I can't is to replace old string
 with new one, on the same position in the file. It always writes new
 string at the end of the file. Here is my code

A simpler way can be:

1. Read a 'block' from the input file, ( you can simply read a line
starting with 'NAME' and keep on reading till you find a line with
starting 'CODE')
2. Once you have read a 'block', make whatever you want changes to the
NAME and then write the 'block' to a temperory file.

If you want the output to be written to same file just 'move' this
temperory file to the input file once you are done.

Note: if there is other stuff in the input file, apart from such
'blocks' that you want to preserve, a small modification in step 1
would take care of it.

hth,
amit.

-- 

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


Re: Python and STL efficiency

2006-08-23 Thread Tim N. van der Leeuw

Mc Osten wrote:
 Ray [EMAIL PROTECTED] wrote:

  Yeah, my guess would be either he used the Debug configuration or he
  actually created a Managed executable instead of a pure Win32
  application. Sigh, now I can't wait to get home and try it out :)

 Can be. But I suppose a Managed should not get *that* slow.
 IronPython on Tim's machine is still faster than C++ (even though not as
 fast as CPython).

 --
 blog:  http://www.akropolix.net/rik0/blogs | Uccidete i filosofi,
 site:  http://www.akropolix.net/rik0/  | tenetevi riso e
 forum: http://www.akropolix.net/forum/ | bacchette per voi.

I have to admit to a stupid mistake, for which I feel quite ashamed - I
got the loop-size wrong in the Python code. So all Python results
posted by me were off by a factor of 10 :-(
I feel quite bad about that!

With the nr of loops corrected, Python on my laptop performs worse than
C++ under all circumstances, by a factor of about 2:

 Python 2.4 =
[EMAIL PROTECTED] ~/My Documents/Python
$ /cygdrive/c/Python24/python.exe SpeedTest.py
Begin Test
Number of unique string objects: 4
so long...
What do you know
fool
chicken crosses road
Number of unique string objects: 400
so long...
What do you know
fool
chicken crosses road
Fast - Elapsed: 4.239721 seconds
Slow - Elapsed: 11.883234 seconds

 Python 2.5 =
[EMAIL PROTECTED] ~/My Documents/Python
$ /cygdrive/c/Python25/python.exe SpeedTest.py
Begin Test
Number of unique string objects: 4
so long...
What do you know
fool
chicken crosses road
Number of unique string objects: 400
so long...
What do you know
fool
chicken crosses road
Fast - Elapsed: 4.031873 seconds
Slow - Elapsed: 11.314742 seconds


 GCC 3.4.5, MinGW, -O6 =
[EMAIL PROTECTED] ~/My Documents/Python
$ ./SpeedTest.exe
Begin Test
What do you know?
chicken crosses road
fool
so long...
What do you know?
chicken crosses road
fool
so long...
Fast - Elapsed: 2.088 seconds
Slow - Elapsed: 7.033 seconds

 VC++ 6, 'release' build =
[EMAIL PROTECTED] ~/My Documents/Python
$ ./SpeedTest_VC.exe
Begin Test
What do you know?
chicken crosses road
fool
so long...
What do you know?
chicken crosses road
fool
so long...
Fast - Elapsed: 4.585 seconds
Slow - Elapsed: 5.024 seconds

== GCC 3.4.5, MinGW, -O6, with most optimized C++ code
==
[EMAIL PROTECTED] ~/My Documents/Python
$ ./testcpp.exe
print_occurence_of_strings
What do you know?
chicken crosses road
fool
so long...
print_occurence_of_unique_strings
What do you know?
chicken crosses road
fool
so long...
print_occurence_of_unique_strings_compared_by_address
What do you know?
chicken crosses road
fool
so long...
strings : 2.338
unique strings : 1.109
compared by address : 0.23

[EMAIL PROTECTED] ~/My Documents/Python

 IronPython 1.0rc2 =

IronPython had a hard time coping with it; creating 4 million string
objects is a bit too much and the CLR was eating nearly a gigabyte of
memory near the end.
Here are the numbers:

IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
 import sys
 sys.path.append('C:/Documents and Settings/LeeuwT/My Documents/Python')
 import SpeedTest
 SpeedTest.run_test()
Begin Test
Number of unique string objects: 4
What do you know
so long...
chicken crosses road
fool
Number of unique string objects: 400
What do you know
so long...
chicken crosses road
fool
Fast - Elapsed: 10.501273 seconds
Slow - Elapsed: 371.047343 seconds


 Java 1.6.0 b2 =
Set size: 4
chicken crosses road
What do you know
fool
so long...
Set size: 4
chicken crosses road
What do you know
fool
so long...
Fast - Elapsed 1.003 seconds
Slow - Elapsed 3.96 seconds

 Java 1.5.0  =
Set size: 4
fool
What do you know
so long...
chicken crosses road
Set size: 4
fool
What do you know
so long...
chicken crosses road
Fast - Elapsed 1.754 seconds
Slow - Elapsed 5.044 seconds
=

Note that the Python code creates a set of all unique id's of all
objects in list a, and prints the length of this set, to verify that
all strings are really unique instances or duplicate instances. The C++
versions don't do that (at least not for 4 million strings); so Python
is at a slight disadvantage here. Printing the number of strings still
didn't help me catch the off-by-ten errors though.

I included a Java version of the program, and it looks like it performs
quite well compared to C++ both with jdk1.5 and jdk1.6.


I humbly apologize for my misinformation yesterday.

Regards,

--Tim

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


Re: find, replace and save string in ascii file

2006-08-23 Thread peter
Thank you for your advice.

I'm not so good in python yet, so could you be so kind and write me a
piece of code for the part

 If you want the output to be written to same file just 'move' this
 temperory file to the input file once you are done.

Because that's what I don't know how to do it. How to replace a string
in the middle of the file and than save this file.

Thanks a lot.


Amit Khemka wrote:
 On 23 Aug 2006 05:48:37 -0700, peter [EMAIL PROTECTED] wrote:
  Hello all,
 
  I'm looking for an advice.
 
  Example (one block in ascii file):
  $
  NAME='ALFA'
  CODE='x'
  $
 
  There are many similar blocks in the file with different NAMEs and
  different CODEs. What I'm looking for is a script that searchs through
  whole file and finds all strings with name ALFA and based on what CODE
  is after each ALFA (can be x, y or z) the ALFA name is replaced by
  BETAx,BETAy or BETAz and so changed file saves.
 
  What I did is that I can find all strings which I need, next I change
  these strings based on CODE, but what I can't is to replace old string
  with new one, on the same position in the file. It always writes new
  string at the end of the file. Here is my code

 A simpler way can be:

 1. Read a 'block' from the input file, ( you can simply read a line
 starting with 'NAME' and keep on reading till you find a line with
 starting 'CODE')
 2. Once you have read a 'block', make whatever you want changes to the
 NAME and then write the 'block' to a temperory file.

 If you want the output to be written to same file just 'move' this
 temperory file to the input file once you are done.

 Note: if there is other stuff in the input file, apart from such
 'blocks' that you want to preserve, a small modification in step 1
 would take care of it.

 hth,
 amit.

 --
 
 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


Re: find, replace and save string in ascii file

2006-08-23 Thread Andy Terrel
Take your code, pretend it is in file:

 $
NAME='ALFA'
CODE='x'
$


a python functions could be:

def change(filename):
fp = open(filename, 'r')
lines = fp.readlines()
fp.close()
for i in range(len(lines)):
if lines[i].find('NAME') = 0:
  if lines[i+1].find('CODE') = 0:
  code = lines[i+1].split('=')[1]
  lines[i] = 'NAME='+something based off code
 fp2 = open(filename,'w')
 fp2.write(.join(lines))



So this is pretty crude and not very robust.  But should give you about
some idea of how to write something.  I'm not sure if there is a way
around opening two file pointers but  I think python has no problems
with this.  Also if you files can't fit into memory you probably want
to do something a lot more, that is read only a block at a time and
then mess with stuff, probably writing out to a temp file and then
overwriting your original file.


peter wrote:
 Thank you for your advice.

 I'm not so good in python yet, so could you be so kind and write me a
 piece of code for the part

  If you want the output to be written to same file just 'move' this
  temperory file to the input file once you are done.

 Because that's what I don't know how to do it. How to replace a string
 in the middle of the file and than save this file.

 Thanks a lot.


 Amit Khemka wrote:
  On 23 Aug 2006 05:48:37 -0700, peter [EMAIL PROTECTED] wrote:
   Hello all,
  
   I'm looking for an advice.
  
   Example (one block in ascii file):
   $
   NAME='ALFA'
   CODE='x'
   $
  
   There are many similar blocks in the file with different NAMEs and
   different CODEs. What I'm looking for is a script that searchs through
   whole file and finds all strings with name ALFA and based on what CODE
   is after each ALFA (can be x, y or z) the ALFA name is replaced by
   BETAx,BETAy or BETAz and so changed file saves.
  
   What I did is that I can find all strings which I need, next I change
   these strings based on CODE, but what I can't is to replace old string
   with new one, on the same position in the file. It always writes new
   string at the end of the file. Here is my code
 
  A simpler way can be:
 
  1. Read a 'block' from the input file, ( you can simply read a line
  starting with 'NAME' and keep on reading till you find a line with
  starting 'CODE')
  2. Once you have read a 'block', make whatever you want changes to the
  NAME and then write the 'block' to a temperory file.
 
  If you want the output to be written to same file just 'move' this
  temperory file to the input file once you are done.
 
  Note: if there is other stuff in the input file, apart from such
  'blocks' that you want to preserve, a small modification in step 1
  would take care of it.
 
  hth,
  amit.
 
  --
  
  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


Re: idutils and Python

2006-08-23 Thread Ramon Diaz-Uriarte
On 22 Aug 2006 10:04:12 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 That's usually cscope  http://cscope.sourceforge.net/ but I've not
 tried to use it with Python before; from the web page it looks like it
 may be worth a spin:
 The fuzzy parser supports C, but is flexible enough to be useful for
 C++ and Java, and for use as a generalized 'grep database' (use it to
 browse large text documents!


Thanks for your answer. I'll take a new look at cscope (I think I
looked at it, but discarded because it seemed to focus on C/C++; never
noticed it is possible use as a general browser for large text
collections).

 I am usually happy with grep, but we only have a medium-large size
 project (320,000 lines of Python code); I can imagine on very large
 codebases that would be too slow to be practical.

I am generally happy with grep (and your code is much larger than
ours) but idutils' output offers both that and, by showing all
together, a kind of poor-man's static call graph, and can be of use
when refactoring.

Thanks again,

R.

On 22 Aug 2006 10:04:12 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Ramon Diaz-Uriarte wrote:
  On 21 Aug 2006 22:56:13 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 
   What exactly are you trying to accomplish?  If you want to index
   function/class names, variables, etc then you should take a look at
   exuberant ctags http://ctags.sourceforge.net53 --although it started
   off as a C indexer, it has excellent Python support, it's free, and as
   a bonus its indices are well supported from inside major editors (vim,
   emacs, etc) so you can easily follow code flow, find function/class
   definitions, etc.
 
 
  Sorry for not being clear enough. I want the following:
 
  a) have my editor go to the point where a function/whatever is defined

 That's usually ctags/etags

  b) see all places where a function/whatever is used.

 That's usually cscope  http://cscope.sourceforge.net/ but I've not
 tried to use it with Python before; from the web page it looks like it
 may be worth a spin:
 The fuzzy parser supports C, but is flexible enough to be useful for
 C++ and Java, and for use as a generalized 'grep database' (use it to
 browse large text documents!

 The vim integration is very nice.  It has emacs integration too, but I
 haven't used it and can't comment on how good it is.

  I think the wish do not use grep, just look at the index file, and
  immediately display all matches  is reasonable and probably other
  Python coders had thought about it before. But I am wondering if I am
  missing something obvious, as most people seem to be very happy with
  exuberant ctags.

 I am usually happy with grep, but we only have a medium-large size
 project (320,000 lines of Python code); I can imagine on very large
 codebases that would be too slow to be practical.

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



-- 
Ramon Diaz-Uriarte
Bioinformatics Unit
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: idutils and Python

2006-08-23 Thread Ramon Diaz-Uriarte
Thanks for the answer. I had read about PyDev and its extenssions but,
if at all possible, I'd like to keep working with Emacs (or Vim)
instead of Eclipse, and I'd rather use free/open source software.

Best,

R.

On 8/23/06, Fabio Zadrozny [EMAIL PROTECTED] wrote:


 
   What exactly are you trying to accomplish?  If you want to index
   function/class names, variables, etc then you should take a look at
   exuberant ctags http://ctags.sourceforge.net53 --although it started
   off as a C indexer, it has excellent Python support, it's free, and as
   a bonus its indices are well supported from inside major editors (vim,
   emacs, etc) so you can easily follow code flow, find function/class
   definitions, etc.
 
 
  Sorry for not being clear enough. I want the following:
 
  a) have my editor go to the point where a function/whatever is defined


  Pydev Extensions (http://www.fabioz.com/pydev) should do that without any
 problems with F3 (it first tries a 'context-sensitive' match, trying to find
 it in locals, globals, current class, etc and if not found like that, it
 goes and looks for the signature in a context-insensitive way, as if it was
 a simple text-search)


  b) see all places where a function/whatever is used.


  This can be handed pretty well with the search that is builtin into Eclipse
 (ctrl+h).

  Cheers,

  Fabio



-- 
Ramon Diaz-Uriarte
Bioinformatics Unit
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python bindings for picasaweb ...

2006-08-23 Thread Andy Terrel
sweet.  I'll definitely be trying to use this.


[EMAIL PROTECTED] wrote:
 Just a post to announce some python bindings for picasaweb (photo's
 service of google).
 --- PycasaWeb (GPL), http://manatlan.infogami.com/pycasaweb
 I think it may be usefull for linux users, because it's one of the only
 way to post pictures on picasaweb. And can be usefull to script batch
 with it ... and our wonderful python box ;-)

 It's inspired from the recent google-sharp module :
 http://svn.myrealbox.com/viewcvs/trunk/google-sharp/?rev=63077

 I will try to implement others api, but contributions are accepted ;-)

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


Python-like C++ library

2006-08-23 Thread Will McGugan
Hi folks,

I'm forced to use C++ and STL at work, and consequently miss the ease
of use of Python. I was wondering if there was a C++ library that
implemented the fundamental objects of Python as close as possible,
perhaps using STL underneath the hood.

Too clarify, Im not looking to interface C++ with Python in any way,
just to emulate the strings / containers / slicing etc. I did google
for it but my search terms were too vague...

Thanks in advance,

Will McGugan
--
http://www.willmcgugan.com

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


Re: Python and STL efficiency

2006-08-23 Thread Ray

Tim N. van der Leeuw wrote:
 With the nr of loops corrected, Python on my laptop performs worse than
 C++ under all circumstances, by a factor of about 2:

*Phew*

Great to know that my model of how the world works is still correct!
(at least in relation to Python and C++!) :)

Thanks,
Ray


  Python 2.4 =
 [EMAIL PROTECTED] ~/My Documents/Python
 $ /cygdrive/c/Python24/python.exe SpeedTest.py
 Begin Test
 Number of unique string objects: 4
 so long...
 What do you know
 fool
 chicken crosses road
 Number of unique string objects: 400
 so long...
 What do you know
 fool
 chicken crosses road
 Fast - Elapsed: 4.239721 seconds
 Slow - Elapsed: 11.883234 seconds

  Python 2.5 =
 [EMAIL PROTECTED] ~/My Documents/Python
 $ /cygdrive/c/Python25/python.exe SpeedTest.py
 Begin Test
 Number of unique string objects: 4
 so long...
 What do you know
 fool
 chicken crosses road
 Number of unique string objects: 400
 so long...
 What do you know
 fool
 chicken crosses road
 Fast - Elapsed: 4.031873 seconds
 Slow - Elapsed: 11.314742 seconds


  GCC 3.4.5, MinGW, -O6 =
 [EMAIL PROTECTED] ~/My Documents/Python
 $ ./SpeedTest.exe
 Begin Test
 What do you know?
 chicken crosses road
 fool
 so long...
 What do you know?
 chicken crosses road
 fool
 so long...
 Fast - Elapsed: 2.088 seconds
 Slow - Elapsed: 7.033 seconds

  VC++ 6, 'release' build =
 [EMAIL PROTECTED] ~/My Documents/Python
 $ ./SpeedTest_VC.exe
 Begin Test
 What do you know?
 chicken crosses road
 fool
 so long...
 What do you know?
 chicken crosses road
 fool
 so long...
 Fast - Elapsed: 4.585 seconds
 Slow - Elapsed: 5.024 seconds

 == GCC 3.4.5, MinGW, -O6, with most optimized C++ code
 ==
 [EMAIL PROTECTED] ~/My Documents/Python
 $ ./testcpp.exe
 print_occurence_of_strings
 What do you know?
 chicken crosses road
 fool
 so long...
 print_occurence_of_unique_strings
 What do you know?
 chicken crosses road
 fool
 so long...
 print_occurence_of_unique_strings_compared_by_address
 What do you know?
 chicken crosses road
 fool
 so long...
 strings : 2.338
 unique strings : 1.109
 compared by address : 0.23

 [EMAIL PROTECTED] ~/My Documents/Python

  IronPython 1.0rc2 =

 IronPython had a hard time coping with it; creating 4 million string
 objects is a bit too much and the CLR was eating nearly a gigabyte of
 memory near the end.
 Here are the numbers:

 IronPython 1.0.60816 on .NET 2.0.50727.42
 Copyright (c) Microsoft Corporation. All rights reserved.
  import sys
  sys.path.append('C:/Documents and Settings/LeeuwT/My Documents/Python')
  import SpeedTest
  SpeedTest.run_test()
 Begin Test
 Number of unique string objects: 4
 What do you know
 so long...
 chicken crosses road
 fool
 Number of unique string objects: 400
 What do you know
 so long...
 chicken crosses road
 fool
 Fast - Elapsed: 10.501273 seconds
 Slow - Elapsed: 371.047343 seconds
 

  Java 1.6.0 b2 =
 Set size: 4
 chicken crosses road
 What do you know
 fool
 so long...
 Set size: 4
 chicken crosses road
 What do you know
 fool
 so long...
 Fast - Elapsed 1.003 seconds
 Slow - Elapsed 3.96 seconds

  Java 1.5.0  =
 Set size: 4
 fool
 What do you know
 so long...
 chicken crosses road
 Set size: 4
 fool
 What do you know
 so long...
 chicken crosses road
 Fast - Elapsed 1.754 seconds
 Slow - Elapsed 5.044 seconds
 =

 Note that the Python code creates a set of all unique id's of all
 objects in list a, and prints the length of this set, to verify that
 all strings are really unique instances or duplicate instances. The C++
 versions don't do that (at least not for 4 million strings); so Python
 is at a slight disadvantage here. Printing the number of strings still
 didn't help me catch the off-by-ten errors though.

 I included a Java version of the program, and it looks like it performs
 quite well compared to C++ both with jdk1.5 and jdk1.6.


 I humbly apologize for my misinformation yesterday.
 
 Regards,
 
 --Tim

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


Re: find, replace and save string in ascii file

2006-08-23 Thread Gabriel Genellina

At Wednesday 23/8/2006 09:48, peter wrote:


What I did is that I can find all strings which I need, next I change
these strings based on CODE, but what I can't is to replace old string
with new one, on the same position in the file. It always writes new
string at the end of the file. Here is my code


Better create a new file with the new contents, and then rename it.



Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

How to download a web page just like a web browser do ?

2006-08-23 Thread Bo Yang
Hi ,
 It is about one month passed since I post to this list
last time . Yes , I use python , I used it in every day normal
work , whenever I need to do some scripts or other little-scale
works , python is the first one I took consideration in . I must
say it is a powerful tool for me , and what is more important
is there is a friendly and flourish community here .
 Oh , I must stop appriciation and go to my question now .

Everyday , I receive a newsletter from NYTimes , but I
didn't want to read the news in evening the time the letter
came in . So , I am about to download the web page
contains the news and read them next morning ! I decide to
use python to write a tool , which should be feeded with a
URL , and then download the page to my disk . This
function just like the Browser's save as... function . I
know what shoud I do to accomplish that , I need to parse
the web page , and download all pages in the page , and
modify all the links to conrespond local disk links and ...

   So , is there any similar function any one have impelment?
Does anyone can share some code with me ? I really don't
want to some confusing code to process such as text findings
and substitutions .

 Thanks in advance !


Bo

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


callable to disappear?

2006-08-23 Thread Antoon Pardon
I have been reading http://www.python.org/dev/peps/pep-3100/
en there is written:

  To be removed:
 ...

 callable(): just call the object and catch the exception

 ...

But that doesn't seem to be a generally available option.
The place where you want to check if something is callable
doens't need to be the place where you actually want to call
it. Removing callable will mean that you can't check whether
or not something is callable without incurring the side-effects
of calling it.

I also think code will become more ugly

How do you suggest I would code the following:

if callable(func):
for i, el in lst:
lst[i] = func(el)
othercode()


I can code as follows:

try:
for i, el in lst:
lst[i] = func(el)
othercode()
except TypeError:
pass


But this has the problem that othercode could throw a TypeError:

So it seems I would need at least two try statements

try:
for i, el in lst:
try:
lst[i] = func(el)
except TypeError
raise LoopBreak
othercode()
except LoopBreak:
pass

And this still has problems because the TypeError could be
raised because lst is an unsubscriptable object.


Is there a chance this will be reconsidered?

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


Re: Finding the type of indexing supported by an object?

2006-08-23 Thread Alex Martelli
Derek Peschel [EMAIL PROTECTED] wrote:

 Here are two functions.
 
 def invert_dict_to_lists(dict):
 lists = {}
 for key in dict:
 value = dict[key]
 if not value in lists:
 lists[value] = [key]
 else:
 lists[value].append(key)
 return lists
 
 def invert_list_to_lists(list):
 lists = {}
 for key in range(len(list)):
 value = list[key]
 if not value in lists:
  lists[value] = [key]
 else:
 lists[value].append(key)
 return lists
 
 They are the same except for the expression in for key in   Can they
 be combined into one function?  How can I determine if the argument is

They can easily be refactored, if that's what you mean:

def _invert_internal(container, keys):
lists = {}
for key in keys:
value = container[key]
if not value in lists:
 lists[value] = [key]
else:
lists[value].append(key)
return lists

def invert_dict_to_lists(adict):
return _invert_internals(adict, adict)

def invert_list_to_lists(alist):
return _invert_internals(alist, xrange(len(alist)))

I've also performed a few other minor enhancements (never name things
dict or list because that hides the builtin types, use xrange vs range).
I have not changed the 4 lines in the if/else though I don't like them
(if not.../else is a very confusing construct -- at a minimum I'd
rephrase it as if/else swapping the bodies of the two clauses).

If you want to add a generic form accepting either lists or dicts you
need a try/except statement inside it, e.g.:

def invert_generic(container):
try:
container['zap']
except TypeError:
keys = xrange(len(container))
except KeyError:
keys = container
else:
keys = container
return _invert_internal(container, keys)

Of course there are all sort of fragilities here -- e.g., something like
invert_dict_to_lists({23:[45]}) will crash and burn.  But that's quite
separate from the issue of distinguishing a dict from a list, which is
what the generic function is doing, showing how to handle exceptions for
the purpose.  Of course, there's no way to use a totally generic
container, because there are no real limits to the keys it may accept
(including infinite sets thereof, computing values in __getitem__).


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


Re: How to download a web page just like a web browser do ?

2006-08-23 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Bo Yang wrote:

 Everyday , I receive a newsletter from NYTimes , but I
 didn't want to read the news in evening the time the letter
 came in . So , I am about to download the web page
 contains the news and read them next morning ! I decide to
 use python to write a tool , which should be feeded with a
 URL , and then download the page to my disk . This
 function just like the Browser's save as... function . I
 know what shoud I do to accomplish that , I need to parse
 the web page , and download all pages in the page , and
 modify all the links to conrespond local disk links and ...

Why don't you just use the `wget` program.  Not written in Python but much
easier to use instead of writing the functionality yourself.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I enumerate all windows services and disable some of them?

2006-08-23 Thread Tim Golden

Tim Golden wrote:
 [Tim Golden]

 | [EMAIL PROTECTED]
 |
 | | I know that Module win32service has some functions on manipulating
 | | win32 services.
 | | But I still have 2 questions:
 | | 1. how to enumerate all services?
 | | 2. how to disable a certain one?
 |
 | You can use WMI to do this if you want.


(continues talking to self...)

In fact you *can* do this with WMI.
eg, to disable the Alerter service:

code
import wmi
c = wmi.WMI ()
for service in c.Win32_Service (Caption=Alerter):
  service.Change (StartMode=Disabled)

/code

TJG

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


Re: How to download a web page just like a web browser do ?

2006-08-23 Thread Cyril Bazin
look at the modules urllib and urllib2, they both are provided with python : http://docs.python.org/lib/module-urllib.html
http://docs.python.org/lib/module-urllib2.htmlAnd look at the examples :http://docs.python.org/lib/node483.html
http://docs.python.org/lib/urllib2-examples.htmlOn 23 Aug 2006 07:34:45 -0700, Bo Yang [EMAIL PROTECTED]
 wrote:Hi , It is about one month passed since I post to this list
last time . Yes , I use python , I used it in every day normalwork , whenever I need to do some scripts or other little-scaleworks , python is the first one I took consideration in . I mustsay it is a powerful tool for me , and what is more important
is there is a friendly and flourish community here . Oh , I must stop appriciation and go to my question now .Everyday , I receive a newsletter from NYTimes , but Ididn't want to read the news in evening the time the letter
came in . So , I am about to download the web pagecontains the news and read them next morning ! I decide touse python to write a tool , which should be feeded with aURL , and then download the page to my disk . This
function just like the Browser's save as... function . Iknow what shoud I do to accomplish that , I need to parsethe web page , and download all pages in the page , andmodify all the links to conrespond local disk links and ...
 So , is there any similar function any one have impelment?Does anyone can share some code with me ? I really don'twant to some confusing code to process such as text findingsand substitutions .
 Thanks in advance !Bo--http://mail.python.org/mailman/listinfo/python-list

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

Re: Python-like C++ library

2006-08-23 Thread Cyril Bazin
Look at boost and boost.python . In your case, bosst.python seems more interesting, but you take a look at boost it may help you at work... http://www.boost.org/
http://www.boost.org/libs/python/doc/CyrilOn 23 Aug 2006 07:19:42 -0700, Will McGugan [EMAIL PROTECTED]
 wrote:Hi folks,I'm forced to use C++ and STL at work, and consequently miss the ease
of use of Python. I was wondering if there was a C++ library thatimplemented the fundamental objects of Python as close as possible,perhaps using STL underneath the hood.Too clarify, Im not looking to interface C++ with Python in any way,
just to emulate the strings / containers / slicing etc. I did googlefor it but my search terms were too vague...Thanks in advance,Will McGugan--http://www.willmcgugan.com
--http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to download a web page just like a web browser do ?

2006-08-23 Thread Gabriel Genellina

At Wednesday 23/8/2006 11:34, Bo Yang wrote:


Everyday , I receive a newsletter from NYTimes , but I
didn't want to read the news in evening the time the letter
came in . So , I am about to download the web page
contains the news and read them next morning ! I decide to
use python to write a tool , which should be feeded with a
URL , and then download the page to my disk . This
function just like the Browser's save as... function . I
know what shoud I do to accomplish that , I need to parse
the web page , and download all pages in the page , and
modify all the links to conrespond local disk links and ...


This tool already exists: wget



Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: Permission Denied

2006-08-23 Thread Magnus Lycka
Jorge Godoy wrote:
 ;-)  And think about security as well.

I.e. put '.' in the end of your PATH, never in the beginning!

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


Re: Create a Multilanguage PDF in Python

2006-08-23 Thread Perseo
PERFECT! Done! Thanks
Now I create a little file in pdf format but the data are in the MySql
database! :(
How can I connect to it?

Thanks for all suggestions
Perseo


Rob Wolfe wrote:
 Perseo wrote:
  Nothing to do!
  I enable test2.py and the folder with 777 permission and I write at the
  top of the file the PYTHONPATH #!/usr/bin/python as you told me but
  it doesn't works as well.

 #!/usr/bin/python is not PYTHONPATH. I think you should
 read this:
 http://docs.python.org/tut/node4.html#SECTION00422

  The verdana font doesn't exist in the reportlab fonts folder. I try to
  delete the rows where it is called like (registerFont, setFont) but
  nothing to do.

 Fonts are not part of reportlab package. You should find it
 in your OS or in the net. You need to know what font do you want to
 use.

  any suggestion?!

 Install reportlab package in your home directory, for example
 /home/perseo/python/lib

 and then in the shell write this:

 export PYTHONPATH=/home/perseo/python/lib

 and look here:
 http://docs.python.org/tut/node8.html#SECTION00811
 
 HTH,
 Rob

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


Python + Java Integration

2006-08-23 Thread Chas Emerick
This may seem like it's coming out of left field for a minute, but  
bear with me.

There is no doubt that Ruby's success is a concern for anyone who  
sees it as diminishing Python's status.  One of the reasons for  
Ruby's success is certainly the notion (originally advocated by Bruce  
Tate, if I'm not mistaken) that it is the next Java -- the language  
and environment that mainstream Java developers are, or will, look to  
as a natural next step.

One thing that would help Python in this debate (or, perhaps simply  
put it in the running, at least as a next Java candidate) would be  
if Python had an easier migration path for Java developers that  
currently rely upon various third-party libraries.  The wealth of  
third-party libraries available for Java has always been one of its  
great strengths.  Ergo, if Python had an easy-to-use, recommended way  
to use those libraries within the Python environment, that would be a  
significant advantage to present to Java developers and those who  
would choose Ruby over Java.  Platform compatibility is always a huge  
motivator for those looking to migrate or upgrade.

In that vein, I would point to JPype (http://jpype.sourceforge.net).   
JPype is a module that gives python programs full access to java  
class libraries.  My suggestion would be to either:

(a) include JPype in the standard library, or barring that,
(b) make a very strong push to support JPype

(a) might be difficult or cumbersome technically, as JPype does need  
to build against Java headers, which may or may not be possible given  
the way that Python is distributed, etc.

However, (b) is very feasible.  I can't really say what supporting  
JPype means exactly -- maybe GvR and/or other heavyweights in the  
Python community make public statements regarding its existence and  
functionality, maybe JPype gets a strong mention or placement on  
python.orgall those details are obviously not up to me, and I  
don't know the workings of the official Python organizations enough  
to make serious suggestions.

Regardless of the form of support, I think raising people's awareness  
of JPype and what it adds to the Python environment would be a Good  
Thing (tm).

For our part, we've used JPype to make PDFTextStream (our previously  
Java-only PDF text extraction library) available and supported for  
Python.  You can read some about it here:

http://snowtide.com/PDFTextStream.Python

And I've blogged about how PDFTextStream.Python came about, and how  
we worked with Steve Ménard, the maintainer of JPype, to make it all  
happen (watch out for this URL wrapping):

http://blog.snowtide.com/2006/08/21/working-together-pythonjava-open- 
sourcecommercial

Cheers,

Chas Emerick
Founder, Snowtide Informatics Systems
Enterprise-class PDF content extraction

[EMAIL PROTECTED]
http://snowtide.com | +1 413.519.6365


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


Re: How to download a web page just like a web browser do ?

2006-08-23 Thread Max Penet
You can also try HarvestMan:

http://harvestman.freezope.org/



Bo Yang wrote:
 Hi ,
  It is about one month passed since I post to this list
 last time . Yes , I use python , I used it in every day normal
 work , whenever I need to do some scripts or other little-scale
 works , python is the first one I took consideration in . I must
 say it is a powerful tool for me , and what is more important
 is there is a friendly and flourish community here .
  Oh , I must stop appriciation and go to my question now .

 Everyday , I receive a newsletter from NYTimes , but I
 didn't want to read the news in evening the time the letter
 came in . So , I am about to download the web page
 contains the news and read them next morning ! I decide to
 use python to write a tool , which should be feeded with a
 URL , and then download the page to my disk . This
 function just like the Browser's save as... function . I
 know what shoud I do to accomplish that , I need to parse
 the web page , and download all pages in the page , and
 modify all the links to conrespond local disk links and ...

So , is there any similar function any one have impelment?
 Does anyone can share some code with me ? I really don't
 want to some confusing code to process such as text findings
 and substitutions .

  Thanks in advance !
 
 
 Bo

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


ANN: Urwid 0.9.6 - Console UI Library

2006-08-23 Thread Ian Ward
Announcing Urwid 0.9.6
--

Urwid home page:
   http://excess.org/urwid/

Tarball:
   http://excess.org/urwid/urwid-0.9.6.tar.gz


About this release:
===

This release improves Unicode support with Python  2.4 and new features 
were added to the tutorial and reference generation scripts.

The graph.py example program introduced in 0.9.5 should now work 
properly for everyone.  Please let me know if you have any trouble with it.


New in this release:


   - Fixed Unicode conversion and locale issues when using Urwid with
 Python  2.4.  The graph.py example program should now work
 properly with older versions of Python.

   - The docgen_tutorial.py script can now write out the tutorial
 example programs as individual files.

   - Updated reference documentation table of contents to show which
 widgets are flow and/or box widgets.

   - Columns.set_focus(..) will now accept an integer or a widget as
 its parameter.

   - Added detection for rxvt's HOME and END escape sequences.

   - Added support for setuptools (improved distutils).


About Urwid
===

Urwid is a console UI library for Python. It features fluid interface
resizing, UTF-8 support, multiple text layouts, simple attribute markup,
powerful scrolling list boxes and flexible interface design.

Urwid is released under the GNU LGPL.






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


Re: Python + Java Integration

2006-08-23 Thread Ben Sizer
Chas Emerick wrote:
 There is no doubt that Ruby's success is a concern for anyone who
 sees it as diminishing Python's status.  One of the reasons for
 Ruby's success is certainly the notion (originally advocated by Bruce
 Tate, if I'm not mistaken) that it is the next Java -- the language
 and environment that mainstream Java developers are, or will, look to
 as a natural next step.

Is it? I thought it was more along the lines of you've been struggling
with Java to build web-apps all this time - here, have Ruby on Rails
which is much easier. Python provides just as much simplicity in the
web frameworks, but no consensus on what is 'best' (recent BDFL
pronouncement aside), and thus only a small community for each
framework. I bet that if Django or TurboGears had been fully ready for
prime-time before Ruby on Rails, we wouldn't be having this discussion.

As a language, Python is much closer to Java than Ruby is anyway.
People already migrate over to Python from Java in their multitudes,
bringing some odd assumptions with them. (eg. The whole thing about
'why isn't a Python static method equivalent to a Java class method?'
because they've been wrongly told that 'static' in Java signifies a
'class method', and because they never read the Python docs where it
clearly shows that classmethod != staticmethod. A bit of C++ knowledge
might have sorted them out here too, as it would have for many problems
encountered by people who were raised on Java, but I digress...)

 One thing that would help Python in this debate (or, perhaps simply
 put it in the running, at least as a next Java candidate)

Java itself never deserved to be the 'next' anything anyway. It was
sold on hype and has never lived up to it. I can see your point from a
business perspective but I like to think Python is sold on its merits
and not on being the new panacea for middle managers to deploy.

-- 
Ben Sizer

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


Re: MS SQL Server: NT Authentication. Possible?

2006-08-23 Thread Dirk Hagemann
I already mentioned, that it the following works when it's NOT executed
by the webserver:
 code
 import adodbapi

 db = adodbapi.connect (Provider=sqloledb;Data Source=VODEV1;Initial
 Catalog=EVOBACK;Integrated Security=SSPI;)
 q = db.cursor ()
 q.execute (SELECT SYSTEM_USER)
 print q.fetchone ()
 q.close ()
 /code

Now I found this work-around: I have on a fileserver some directories
with restricted rights. In every directory is a file which has always
the same name. Now I let the script (executed by the IIS-Webserver) try
to open this file (directory is chosen by the user):
data =
open(server\\directory\\+variable+\\index.py,r).readlines()
If the NT-Account of the user has the right to open this file, the
script will proceed with the addicted Database-View. If the user has
not the right he gets an error-message.

And this works! In this case the webserver is working on the fileserver
with the NT-account of the user who has used the webinterface. So on
the one hand the IIS works fine with the fileserver, but the IIS does
not work with the SQL-Server. And it seems not to be the fault of the
code, because it works when it's executed directly.
It's so confusing...

Dirk

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


Re: idutils and Python

2006-08-23 Thread Fabio Zadrozny
On 8/23/06, Ramon Diaz-Uriarte [EMAIL PROTECTED] wrote:
Thanks for the answer. I had read about PyDev and its extenssions but,if at all possible, I'd like to keep working with Emacs (or Vim)instead of Eclipse, and I'd rather use free/open source software.

Well, you can use only Pydev without the extensions (its implementation
of go to definition is powered by Bycicle Repair Man, which should be
on par with other open-source implementations).

Cheers,

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

Re: Python + Java Integration

2006-08-23 Thread Diez B. Roggisch
Chas Emerick wrote:

 This may seem like it's coming out of left field for a minute, but
 bear with me.
 
 There is no doubt that Ruby's success is a concern for anyone who
 sees it as diminishing Python's status.  One of the reasons for
 Ruby's success is certainly the notion (originally advocated by Bruce
 Tate, if I'm not mistaken) that it is the next Java -- the language
 and environment that mainstream Java developers are, or will, look to
 as a natural next step.
 
 One thing that would help Python in this debate (or, perhaps simply
 put it in the running, at least as a next Java candidate) would be
 if Python had an easier migration path for Java developers that
 currently rely upon various third-party libraries.  The wealth of
 third-party libraries available for Java has always been one of its
 great strengths.  Ergo, if Python had an easy-to-use, recommended way
 to use those libraries within the Python environment, that would be a
 significant advantage to present to Java developers and those who
 would choose Ruby over Java.  Platform compatibility is always a huge
 motivator for those looking to migrate or upgrade.

While you might have a point with easing the transition for java developers
might favor them python over ruby, you seem to mix a few things here, and
forget about others:


 - ruby has no notion of java-library support. So if anything lures java
developers from J2EE-land to rails, its the framework itself. Which, by my
standards, is at least met if not excelled by TurboGears and Django. So
it's marketing, but of a different kind, we need.


 - jython, after a period of seemingly inactivity, makes huge progress
towards python2.2 and python2.3. Which will open up new possibilities just
the other way round: use existing, powerful python libraries written in
post-2.1 from jython, neatly integrating java and python. Now there is
jRuby trying to do the same for ruby - but I never heard of it before
(googled it for this post), so it seems not to be as important as jython
certainly is


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


Re: Python + Java Integration

2006-08-23 Thread hiaips


 Java itself never deserved to be the 'next' anything anyway. It was
 sold on hype and has never lived up to it. I can see your point from a
 business perspective but I like to think Python is sold on its merits
 and not on being the new panacea for middle managers to deploy.

Bravo. I could not have said it any better.

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


Re: Python + Java Integration

2006-08-23 Thread Chas Emerick
On Aug 23, 2006, at 11:50 AM, Ben Sizer wrote:Chas Emerick wrote: There is no doubt that Ruby's success is a concern for anyone who sees it as diminishing Python's status.  One of the reasons for Ruby's success is certainly the notion (originally advocated by Bruce Tate, if I'm not mistaken) that it is the "next Java" -- the language and environment that mainstream Java developers are, or will, look to as a natural next step.  Is it? I thought it was more along the lines of "you've been struggling with Java to build web-apps all this time - here, have Ruby on Rails which is much easier". Python provides just as much simplicity in the web frameworks, but no consensus on what is 'best' (recent BDFL pronouncement aside), and thus only a small community for each framework. I bet that if Django or TurboGears had been fully ready for prime-time before Ruby on Rails, we wouldn't be having this discussion.There's a lot of truth in that, but there's no doubt that there is a meme out there that Ruby is the "next Java", regardless of any technical facts.  This is all marketing and perception, which is why I was positing JPype as being a wildcard that could help Python significantly by providing an easy migration path for Java folk who are tied to specific libraries. One thing that would help Python in this "debate" (or, perhaps simply put it in the running, at least as a "next Java" candidate)  Java itself never deserved to be the 'next' anything anyway. It was sold on hype and has never lived up to it. I can see your point from a business perspective but I like to think Python is sold on its merits and not on being the new panacea for middle managers to deploy. I was having a discussion with a friend of mine recently, where I told him how depressed I became for a period after I realized that sales, marketing, and perception are all that really matter in this kooky technical world we spend so much time in.  For years I thought that "most people" make technical decisions based on the facts on the ground and the merits of each alternative.  While that's a great ideal to aspire to, it's not realistic as long as technical laypersons make very technical decisions -- in such an environment, heuristics, guidelines, and rules-of-thumb rule.  Ergo, it's good to have marketing firepower, because that can move the needle on rules-of-thumb *really* easily.So, back on topic, I think regardless of how we got here, or who's better (Ruby or Python -- and really, it's better for the larger universe of 'agile' languages to grow anyway), if we want to improve Python's attractiveness to mainstream Java developers and their managers, providing (and promoting!) an easy migration route like JPype is a no-brainer.Cheers,Chas EmerickFounder, Snowtide Informatics SystemsEnterprise-class PDF content extraction[EMAIL PROTECTED]http://snowtide.com-- 
http://mail.python.org/mailman/listinfo/python-list

Accessing application data portably

2006-08-23 Thread Tom E H
My Python application includes some data files that need to be accessed by
modules I distribute with it.

Where can I put them, and how should I arrange my code, so that it works
across platforms?

On Linux, I could install the data to /usr/lib/myprogram/datafile, and
on Windows to datafile relative to where the executable (made by
py2exe) is installed.  Then I could detect the operating system, and choose
appropriately.

To be that explicit seems undesirable.  Any cleverer ideas?

Tom

(Please CC me on replies: I'm not subscribed.  The From address is munged)

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


Re: Python and STL efficiency

2006-08-23 Thread skip

Ray Same here, although that said Python's implementation of those data
Ray structure must already be as optimal as mortals can do it.

Perhaps more optimal.  We've had (tim)bots working on the problem for years.

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


Re: Create a Multilanguage PDF in Python

2006-08-23 Thread Perseo
It's too difficult for me, anyone can help me contact me thru chat or
something else, please. It drives me crazy!

Perseo wrote:
 PERFECT! Done! Thanks
 Now I create a little file in pdf format but the data are in the MySql
 database! :(
 How can I connect to it?

 Thanks for all suggestions
 Perseo


 Rob Wolfe wrote:
  Perseo wrote:
   Nothing to do!
   I enable test2.py and the folder with 777 permission and I write at the
   top of the file the PYTHONPATH #!/usr/bin/python as you told me but
   it doesn't works as well.
 
  #!/usr/bin/python is not PYTHONPATH. I think you should
  read this:
  http://docs.python.org/tut/node4.html#SECTION00422
 
   The verdana font doesn't exist in the reportlab fonts folder. I try to
   delete the rows where it is called like (registerFont, setFont) but
   nothing to do.
 
  Fonts are not part of reportlab package. You should find it
  in your OS or in the net. You need to know what font do you want to
  use.
 
   any suggestion?!
 
  Install reportlab package in your home directory, for example
  /home/perseo/python/lib
 
  and then in the shell write this:
 
  export PYTHONPATH=/home/perseo/python/lib
 
  and look here:
  http://docs.python.org/tut/node8.html#SECTION00811
  
  HTH,
  Rob

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


Re: how do you get the name of a dictionary?

2006-08-23 Thread jojoba



Fredrik Lundh wrote:
 the fact that despite all attempts to explain how things work, you're
 still haven't realized that if you want the names of things, you should
 pass *namespaces* to your object viewer, not individual objects.


And what im saying is that isnt it silly that we need pass an entire
namespace, when a much simpler notion would be to have each object know
its own name(s) (even if that name doesnt exist).
Now, here's where everyone tells me this isnt possible, and how my
statement implies that i have no idea whatsoever of how python
works

jojoba

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


RE: MS SQL Server: NT Authentication. Possible?

2006-08-23 Thread Tim Golden
[Dirk Hagemann]

| Now I found this work-around: [... snip opening restricted file ...]

| And this works! [...] So on the one hand the IIS works fine with the 
| fileserver, but the IIS does not work with the SQL-Server. And it
seems 
| not to be the fault of the code, because it works when it's executed 
| directly. It's so confusing...

(Vague handwavy answer in the hope that someone truly knowledgeable will
come across with clarifications and/or corrections). 

It's almost certainly to do with Delegation or Impersonation, 
which are fairly important aspects of the Windows security model
when it comes to distributed security but also fairly difficult to
understand (especially by me, who has never had to try...).

Try looking
at articles like:

http://msdn.microsoft.com/msdnmag/issues/05/09/SecurityBriefs/
http://msdn2.microsoft.com/en-us/library/bsz5788z.aspx

or Google around for iis sqlserver impersonation and so on.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Python-like C++ library

2006-08-23 Thread bearophileHUGS
Will McGugan:
 I was wondering if there was a C++ library that
 implemented the fundamental objects of Python as close as possible,
 perhaps using STL underneath the hood.
 Too clarify, Im not looking to interface C++ with Python in any way,
 just to emulate the strings / containers / slicing etc.

Maybe you can use the ShedSkin libraries, it maps Python to C++:
http://shedskin.sourceforge.net/

EasySTL is unrelated to Python, but you may find it useful:
http://userpages.umbc.edu/~bcorfm1/software.html

Bye,
bearophile

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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Simon Brunning
On 23 Aug 2006 09:29:40 -0700, jojoba [EMAIL PROTECTED] wrote:
 And what im saying is that isnt it silly that we need pass an entire
 namespace, when a much simpler notion would be to have each object know
 its own name(s) (even if that name doesnt exist).
 Now, here's where everyone tells me this isnt possible, and how my
 statement implies that i have no idea whatsoever of how python
 works

It's not inconcevable that Python could behave that way, it's just
that it would impose an overhead on the 99.999% of Python users who
would have no use for the feature. It's a price not worth paying.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do you get the name of a dictionary?

2006-08-23 Thread jojoba

 And what im saying is that isnt it silly that we need pass an entire
 namespace, when a much simpler notion would be to have each object know
 its own name(s) (even if that name doesnt exist).


please note:  in my above comment, i was completely disregarding any
notions of added costs that would be incurred to have such a feature,
and that in fact, such costs might actually nullify any other benefits
from having such a feature. Purely a what-if idea from a nascent python
programmer.

jojoba

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


Re: Python and STL efficiency

2006-08-23 Thread skip

 Yes it is. But of course you can't sat that Python is faster than
 C++.

Harald Of course not. Python is faster then assembler. Proofed @
Harald EuroPython 2006 in CERN, near the LHC Beta, in the same room
Harald many Nobel laurates gave their presentations before.

Harald, do you have a reference to a talk abstract or a paper?

Thx,

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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Georg Brandl
jojoba wrote:
 And what im saying is that isnt it silly that we need pass an entire
 namespace, when a much simpler notion would be to have each object know
 its own name(s) (even if that name doesnt exist).
 
 
 please note:  in my above comment, i was completely disregarding any
 notions of added costs that would be incurred to have such a feature,
 and that in fact, such costs might actually nullify any other benefits
 from having such a feature. Purely a what-if idea from a nascent python
 programmer.

Even from such a point of view, the concept isn't clearly enough defined.
What name would be assigned to the dict below?

l = [1,2,3]
a = some_str
l[0] = {'foo': 'bar'}

Some immutable objects, such as small integers, exist only once. Would you
assign names to them? They're likely to be completely meaningless.

When a name goes out of scope, but the object continues to live (e.g.
because it's returned by some function), the name is void.

Etc.


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


Re: find, replace and save string in ascii file

2006-08-23 Thread Roberto Bonvallet
peter wrote:
 Example (one block in ascii file):
 $
 NAME='ALFA'
 CODE='x'
 $
 
 There are many similar blocks in the file with different NAMEs and
 different CODEs. What I'm looking for is a script that searchs through
 whole file and finds all strings with name ALFA and based on what CODE
 is after each ALFA (can be x, y or z) the ALFA name is replaced by
 BETAx,BETAy or BETAz and so changed file saves.

name = myfile
lines = file(name).readlines()

for i, line in enumerate(lines):
if ALFA in line:
code = lines[i + 1].split(=)[1].strip(' \n)
lines[i] = line.replace(ALFA, BETA%s % code)

file(name).writelines(lines)

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


Re: Python + Java Integration

2006-08-23 Thread Chas Emerick
On Aug 23, 2006, at 12:30 PM, Diez wrote: - ruby has no notion of java-library support. So if anything lures java developers from J2EE-land to rails, its the framework itself. Which, by my standards, is at least met if not excelled by TurboGears and Django. So it's marketing, but of a different kind, we need.People move in crowds, and although the initial draw to Ruby was Rails, that translated into "Ruby is the next Java", which is a force to be reckoned with in and of itself.I think the fact that Ruby doesn't have a Java library migration path is exactly why JPype is a great opportunity for Python.  Django and TG will not (regardless of their technical merits) catch up to Rails in terms of broader mindshare for years, if ever.  Having them (and pylons! :-) is obviously fantastic, but opening up a new front of comparison where Python is the obvious choice is where Python can score points, rather than try to catch up.  - jython, after a period of seemingly inactivity, makes huge progress towards python2.2 and python2.3. Which will open up new possibilities just the other way round: use existing, powerful python libraries written in post-2.1 from jython, neatly integrating java and python. Now there is jRuby trying to do the same for ruby - but I never heard of it before (googled it for this post), so it seems not to be as important as jython certainly is You bet, Jython is a great concept, and it's another arrow in Python quiver.  I don't think it comes close to nullifying JPype's potential to help Python's stature with Java developers, though -- it's orthogonal to JPype, and therefore complimentary.Chas EmerickFounder, Snowtide Informatics SystemsEnterprise-class PDF content extraction[EMAIL PROTECTED]http://snowtide.com-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Text to MP3 using pyTTS - Non-programmer question

2006-08-23 Thread seyeRMReyes
Thanks for much for all the help, but it doesn't seem as if the wav
file is being created, but I really don't get an error message.

Initially, I got error messages about TCL and TK lidbrary and I added
them to the PATH.

Do the encoder need to be in the source folder along with the code?

Again, I don't know anything about programming, but was able to make
sense of most of it.

Any help would be helpful.

Thanks

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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Robert Kern
jojoba wrote:
 
 Fredrik Lundh wrote:
 the fact that despite all attempts to explain how things work, you're
 still haven't realized that if you want the names of things, you should
 pass *namespaces* to your object viewer, not individual objects.
 
 And what im saying is that isnt it silly that we need pass an entire
 namespace, when a much simpler notion would be to have each object know
 its own name(s) (even if that name doesnt exist).

No, it's silly to avoid a very well-defined, heavily optimized strategy used 
everywhere in the language in favor of a new, vague strategy that is usually 
uninformative and frequently undefined.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth.
   -- Umberto Eco

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


Re: Python and STL efficiency

2006-08-23 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
  Yes it is. But of course you can't sat that Python is faster than
  C++.

 Harald Of course not. Python is faster then assembler. Proofed @
 Harald EuroPython 2006 in CERN, near the LHC Beta, in the same room
 Harald many Nobel laurates gave their presentations before.

 Harald, do you have a reference to a talk abstract or a paper?

Via the lightning talks page:

http://wiki.python.org/moin/EuroPy2006LightningTalks

Here's a direct link:

http://wiki.python.org/moin/EuroPy2006LightningTalks?action=AttachFiledo=gettarget=%3AFasterThenAssemblerLightning.odp

Of course, Harald's interpretation of the faster than qualification
is broader than a pure assessment of raw performance, so I wouldn't
expect too many technical revelations. And while footage exists of at
least one talk in the CERN Auditorium which led to a Nobel prize, I
don't think that any footage of the EuroPython lightning talks (or of
any of the other talks) has been released just yet.

Paul

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


running windows 'start' cmd using spawnl

2006-08-23 Thread Tor Erik
Hi,

I need to start a program in a new cmd-window. To do this I need to 
execute: start [command]
With os.system this is straight-forward.
But I need to do it with spawnl and P_NOWAIT. I.e, asynchronously.
The problem is that I need to know the path where start resides,
which I'm unable to find.

Does anyone know where this command is located, or an alternative way of 
doing what I want?

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


Re: Create a Multilanguage PDF in Python

2006-08-23 Thread Perseo
Hi Rob this is my code:

code
#!/usr/bin/python

import time, os, sys
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch, cm
from reportlab.lib.pagesizes import A4

#precalculate some basics
top_margin = A4[1] - inch
bottom_margin = inch
left_margin = inch
right_margin = A4[0] - inch
frame_width = right_margin - left_margin

pdfmetrics.registerFont(TTFont('Verdana', 'verdana.ttf'))
canv = canvas.Canvas(test.pdf)

def drawPageFrame(mycanv):
  mycanv.line(left_margin, top_margin, right_margin, top_margin)
  mycanv.setFont('Verdana',12)
  mycanv.drawString(left_margin, top_margin + 2, Pdf Test)
  mycanv.line(left_margin, top_margin, right_margin, top_margin)

  mycanv.line(left_margin, bottom_margin, right_margin, bottom_margin)
  mycanv.drawCentredString(0.5*A4[0], 0.5 * inch,
  Page %d % mycanv.getPageNumber())

canv.setPageCompression(1)
drawPageFrame(canv)

#do some title page stuff
canv.setFont(Verdana, 36)
canv.drawCentredString(0.5 * A4[0], 7 * inch, Pdf Test)

canv.setFont(Verdana, 18)
canv.drawCentredString(0.5 * A4[0], 5 * inch, Test Staff)

canv.setFont(Verdana, 12)
tx = canv.beginText(left_margin, 3 * inch)
tx.textLine(This is a test to a PDF Exporting Tool)
canv.drawText(tx)
canv.showPage()

canv.save()

print Content-Type: text/html\n\n
print a href=\test.pdf\PDF Test/a

/code


I would like to create a simple pdf splitted in two column with a
vertical row.

   |
Όνομα, Επώνυμο | John, Malkovic
 Διεύθυνση (1) | 11 Main Street, Athens 54640
   | Thessaloniki Greece
 Διεύθυνση (2) |
  Τηλέφωνο | 00302310886995
 Διεύθυνση | [EMAIL PROTECTED]
  ηλεκτρονικού |
 ταχυδρομείου  |
   Κινητό τηλέφωνο | 00345353453453
Τόπος γέννησης | Thessaloniki
  Χώρα | Greece
Υπηκοότητα | Greek
Ημερομηνία |
  γέννησης |
Μητρική γλώσσα | Greek
Rob Wolfe wrote:
 Perseo [EMAIL PROTECTED] writes:

  Hi guys,
 
  I'm disprate with the Pdf Unicode. I try to create a class using ufpdf
  but some chars are not correct and now I would like try Python because
  a friend tolds me that it's very powerful.
  I need a simple script in Python that grab all Records from a MySql
  table and print in the pdf file.
 
  The languages stored in my db are about 25 and they are:
  Greek English French Hungarian Italian Lithuanian Dutch Portuguese
  Albanian
  Czech Danish German Spanish Estonian Finnish Irish Latvian Maltese
  Polish Romanian
  Russian Slovene Slovak Swedish

 You can give reportlab [1] a try. It has support for TrueType fonts
 and unicode translation using UTF-8. I used to use it for pdf files
 with polish chars.

 Some example code:

 code
 from reportlab.pdfbase import pdfmetrics
 from reportlab.pdfbase.ttfonts import TTFont
 from reportlab.pdfgen import canvas

 pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
 c = canvas.Canvas(pl.pdf)
 c.setFont(Verdana, 12)
 c.drawString(100, 600, Witaj, ¶wiecie!.decode(iso-8859-2).encode(utf-8))
 c.showPage()
 c.save()
 /code
 
 
 [1] http://www.reportlab.org/
 
 -- 
 HTH,
 Rob

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

Re: swapping numeric items in a list

2006-08-23 Thread Jiang Nutao
Thank you all guys for the help. Guess I'm gonna pick bearophile's way. It's 
fast, neat, and easy to read.

array.byteswap() won't work for me easily. I tried this before my 1st post. 
I defined

aa = array('H', [0x12, 0x34, 0x56, 0x78])

Then did byteswap aa.byteswap(). The result was

array('H', [0x1200, 0x3400, 0x5600, 0x7800])

You can see it byteswapped within each item.

Jason

Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 In [EMAIL PROTECTED], Jiang Nutao
 wrote:

 To convert list
 aa = [0x12, 0x34, 0x56, 0x78]
 into
 [0x34, 0x12, 0x78, 0x56]

 How to do it fast? My real list is huge.

 Use the `array` module and the `array.byteswap()` method.

 Ciao,
 Marc 'BlackJack' Rintsch
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 



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


Re: callable to disappear?

2006-08-23 Thread faulkner
what's wrong with hasattr(obj, '__call__')?

Antoon Pardon wrote:
 I have been reading http://www.python.org/dev/peps/pep-3100/
 en there is written:

   To be removed:
  ...

  callable(): just call the object and catch the exception

  ...

 But that doesn't seem to be a generally available option.
 The place where you want to check if something is callable
 doens't need to be the place where you actually want to call
 it. Removing callable will mean that you can't check whether
 or not something is callable without incurring the side-effects
 of calling it.

 I also think code will become more ugly

 How do you suggest I would code the following:

 if callable(func):
 for i, el in lst:
 lst[i] = func(el)
   othercode()


 I can code as follows:

 try:
 for i, el in lst:
   lst[i] = func(el)
   othercode()
 except TypeError:
 pass


 But this has the problem that othercode could throw a TypeError:

 So it seems I would need at least two try statements

 try:
 for i, el in lst:
   try:
   lst[i] = func(el)
   except TypeError
   raise LoopBreak
   othercode()
 except LoopBreak:
 pass

 And this still has problems because the TypeError could be
 raised because lst is an unsubscriptable object.


 Is there a chance this will be reconsidered?
 
 -- 
 Antoon Pardon

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


Re: running windows 'start' cmd using spawnl

2006-08-23 Thread Gabriel Genellina

At Wednesday 23/8/2006 14:22, Tor Erik wrote:


I need to start a program in a new cmd-window. To do this I need to
execute: start [command]
With os.system this is straight-forward.
But I need to do it with spawnl and P_NOWAIT. I.e, asynchronously.
The problem is that I need to know the path where start resides,
which I'm unable to find.


On Windows NT, XP, 2003 and others, there is no start.exe 
executable; it's an internal command. It only exists on 95, 98, maybe ME.

Try the subprocess module.


Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: swapping numeric items in a list

2006-08-23 Thread Gabriel Genellina

At Wednesday 23/8/2006 14:44, Jiang Nutao wrote:


array.byteswap() won't work for me easily. I tried this before my 1st post.
I defined

aa = array('H', [0x12, 0x34, 0x56, 0x78])

Then did byteswap aa.byteswap(). The result was

array('H', [0x1200, 0x3400, 0x5600, 0x7800])

You can see it byteswapped within each item.


Use array('b') or 'B'. 'H' are two-byes integers.



Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: swapping numeric items in a list

2006-08-23 Thread Jiang Nutao
This is what I got in the debugger:

(Pdb) aa=array('b', [126, 55, 71, 112])
(Pdb) aa
array('b', [126, 55, 71, 112])
(Pdb) aa.byteswap()
(Pdb) aa
array('b', [126, 55, 71, 112])

- Original Message - 
From: Gabriel Genellina [EMAIL PROTECTED]
To: Jiang Nutao [EMAIL PROTECTED]
Cc: python-list@python.org
Sent: Wednesday, August 23, 2006 11:28 AM
Subject: Re: swapping numeric items in a list


 At Wednesday 23/8/2006 14:44, Jiang Nutao wrote:

array.byteswap() won't work for me easily. I tried this before my 1st 
post.
I defined

 aa = array('H', [0x12, 0x34, 0x56, 0x78])

Then did byteswap aa.byteswap(). The result was

 array('H', [0x1200, 0x3400, 0x5600, 0x7800])

You can see it byteswapped within each item.

 Use array('b') or 'B'. 'H' are two-byes integers.



 Gabriel Genellina
 Softlab SRL




 __
 Preguntá. Respondé. Descubrí.
 Todo lo que querías saber, y lo que ni imaginabas,
 está en Yahoo! Respuestas (Beta).
 ¡Probalo ya! http://www.yahoo.com.ar/respuestas

 

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


Regex help...pretty please?

2006-08-23 Thread MooMaster
I'm trying to develop a little script that does some string
manipulation. I have some few hundred strings that currently look like
this:

cond(a,b,c)

and I want them to look like this:

cond(c,a,b)

but it gets a little more complicated because the conds themselves may
have conds within, like the following:

cond(0,cond(c,cond(e,cond(g,h,(af)),(ad)),(ab)),(a1))

What I want to do in this case is move the last parameter to the front
and then work backwards all the way out (if you're thinking recursion
too, I'm vindicated) so that it ends up looking like this:

cond((a1), 0, cond((ab),c,cond((ad), e, cond((af), g, h

futhermore, the conds may be multiplied by an expression, such as the
following:

cond(-1,1,f)*((float(e)*(2**4))+(float(d)*8)+(float(c)*4)+(float(b)*2)+float(a))

Here, all I want to do is switch the parameters of the conds without
touching the expression, like so:

cond(f,-1,1)*((float(e)*(2**4))+(float(d)*8)+(float(c)*4)+(float(b)*2)+float(a))

So that's the gist of my problem statement. I immediately thought that
regular expressions would provide an elegant solution. I would go
through the string by conds, stripping them  the () off, until I got
to the lowest level, then move the parameters and work backwards. That
thought process became this:
-CODE
import re

def swap(left, middle, right):
left = left.replace((, )
right = right.replace(), )
temp = left
left = right
right = temp
temp = middle
middle = right
right = temp
whole = 'cond(' + left + ',' + middle + ',' + right + ')'
return whole

def condReplacer(string):
 #regex = re.compile(r'cond\(.*,.*,.+\)')
 regex = re.compile(r'cond\(.*,.*,.+?\)')
 if not regex.search(string):
  print whole string is:  + string
  [left, middle, right] = string.split(',')
  right = right.replace('\'', ' ')
  string = swap(left.strip(), middle.strip(), right.strip())
  print the new string is: + string
  return string
 else:
  more_conds = regex.search(string)
  temp_string = more_conds.group()
  firstParen = temp_string.find('(')
  temp_string = temp_string[firstParen:]
  print there are more conditionals! + temp_string
  condReplacer(temp_string)
def lineReader(file):
 for line in file:
 regex = r'cond\(.*,.*,.+\)?'
 if re.search(regex,line,re.DOTALL):
condReplacer(line)

if __name__ == __main__:
   input_file = open(only_conds2.txt, 'r')
   lineReader(input_file)
-CODE

I think my problem lies in my regular expression... If I use the one
commented out I do a greedy search and in my test case where I have a
conditional * an expression, I grab the expression too, like so:

INPUT:

cond(-1,1,f)*((float(e)*(2**4))+(float(d)*8)+(float(c)*4)+(float(b)*2)+float(a))
OUTPUT:
whole string is:
(-1,1,f)*((float(e)*(2**4))+(float(d)*8)+(float(c)*4)+(float(b)*2)+float
(a))
the new string
is:cond(f*((float(e*(2**4+(float(d*8+(float(c*4+(float(b*2+float
(a,-1,1)

when all I really want to do is grab the part associated with the cond.
But if I do a non-greedy search I avoid that problem but stop too early
when I have an expression like this:

INPUT:
cond(a,b,(abs(c) = d))
OUTPUT:
whole string is: (a,b,(abs(c)
the new string is:cond((abs(c,a,b)

Can anyone help me with the regular expression? Is this even the best
approach to take? Anyone have any thoughts? 

Thanks for your time!

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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Fredrik Lundh
jojoba wrote:

 the fact that despite all attempts to explain how things work, you're
 still haven't realized that if you want the names of things, you should
 pass *namespaces* to your object viewer, not individual objects.
 
 And what im saying is that isnt it silly that we need pass an entire
 namespace

namespaces are objects too, you know.  passing an entire namespace is 
no harder than passing any other object.

/F

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


Re: running windows 'start' cmd using spawnl

2006-08-23 Thread Fredrik Lundh
Tor Erik wrote:

 I need to start a program in a new cmd-window. To do this I need to 
 execute: start [command]
 With os.system this is straight-forward.
 But I need to do it with spawnl and P_NOWAIT. I.e, asynchronously.
 The problem is that I need to know the path where start resides,
 which I'm unable to find.

os.startfile(command) could work.

/F


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


Re: how do you get the name of a dictionary?

2006-08-23 Thread Fredrik Lundh
Steve Holden wrote:

 Right. Plus it's fun to imagine the effbot hitting itself as hard as 
 some people would obviously have liked to hit it in the past :-)

you mean the guy who's spent the last six months downrating every single 
post I've made on this list over at googlegroups ?  I'd say it's safe to 
ignore him; he's a certified nutcase.

/F

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


  1   2   3   >