stdeb - Python to Debian source package conversion utility

2006-06-19 Thread Andrew Straw
I would like to announce the initial public release of stdeb, which may
be found at http://stdeb.python-hosting.com/ . The rest of this post is
copied directly from that web-page.

stdeb - Python to Debian source package conversion utility
==

stdeb_ (setuptools debian) produces Debian source packages from
Python packages via a new distutils command, ``sdist_dsc``, which
produces a Debian source package of a Python package.  Automatic
defaults are provided for the Debian package, but many aspects of the
resulting package can be customized via a configuration file.

.. _stdeb: http://stdeb.python-hosting.com/

News


2006-06-19: Version 0.1 Released. See the `download page`_.

Invocation
--

All methods eventually result in a call to the ``sdist_dsc`` distutils
command. You may prefer to do so directly::

  python -c import stdeb; execfile('setup.py') sdist_dsc

Alternatively, two scripts are provided::

  stdeb_run_setup [options] # calls python setup.py sdist_dsc [options]

  py2dsc [options] mypackage-0.1.tar.gz # uses pre-built Python source
package

In all cases, a Debian source package is produced from unmodified
Python packages. The following files are produced:

 * ``packagename_versionname.orig.tar.gz``
 * ``packagename_versionname-debianversion.dsc``
 * ``packagename_versionname-debianversion.diff.gz``

These can then be compiled into binary packages using the standard
Debian machinery (e.g. dpkg-buildpackage).

Download


Files are available at the `download page`_.

.. _download page: http://stdeb.python-hosting.com/wiki/Download

The subversion repository is available at
https://svn.stdeb.python-hosting.com/trunk

Background
--

For the average Python package, its source distribution
(python_package.tar.gz created with ``python setup.py sdist``)
contains nearly everything necessary to make a Debian source
package. This near-equivalence encouraged me to write this little
distutils extension, which executes the setup.py file to extract
relevant information. This process is made significantly easier
through the use of setuptools_.

.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools

setuptools is used because of the opportunities it provides, although
many of these features are currently un(der)-utilized. For example,
setuptools could make the job of Debianizing python console and gui
scripts much easier.

I wrote this initially to Debianize several Python packages of my own,
but I have the feeling it could be generally useful. It appears
similar, at least in theory, to easydeb_ and `Logilab's Devtools`_.

.. _easydeb: http://easy-deb.sourceforge.net/
.. _Logilab's DevTools: http://www.logilab.org/projects/devtools

Prerequisites
-

 * Python_ 2.3 or greater
 * setuptools_
 * subprocess.py_ (included with Python 2.4, backwards compatible with
Python 2.3)

.. _Python: http://www.python.org/
.. _subprocess.py:
http://svn.python.org/view/python/trunk/Lib/subprocess.py?rev=46651view=log

Customizing the produced Debian source package
--

stdeb will attempt to provide reasonable defaults, but these are only
guesses.

To customize the Debian source package produced, you may write config
files of the format understood by ConfigParser_. When building each
package, stdeb looks for the existance of a ``stdeb.cfg`` file in the
``.egg-info`` directory. You may specify an additional config file
with the command-line option --extra-cfg-file.

.. _ConfigParser: http://docs.python.org/lib/module-ConfigParser.html

Here's an example .cfg file which builds several packages::

 [DEFAULT]
 Debian-Version: 0ads1

 [setuptools]
 Source: python-setuptools

 [numpy]
 Source: python-numpy
 Upstream-Version-Prefix: 0.9.8+
 Build-Depends: python-dev, refblas3-dev, lapack3-dev
 Build-Conflicts: atlas3-base, atlas3-base-dev

 [matplotlib]
 # matplotlib doesn't incorporate its SVN version number into
sdist-built tarballs.
 # Therefore, if building the SVN version, substitute the version into the
 # Upstream-Version-Suffix variable and use py2dsc.
 # (For some reason, debuild -sa won't build matplotlib because tk.h
isn't found.)
 Source: python-matplotlib
 Upstream-Version-Suffix: .dev2500
 Build-Depends: python-dev, python-numpy, python-numarray,
python-numeric, python-gtk2-dev, tk8.4-dev, libwxgtk2.4-dev
 Depends: python-gtk2, python-numpy, python-numeric, python-numarray
 Suggests: gs-gpl

 [scipy]
 Source: python-scipy
 Upstream-Version-Prefix: 0.4.9+
 Build-Depends: python-numpy
 Depends: python-numpy

.. _numpy: http://scipy.org/NumPy

Using stdeb on stdeb


There is a chicken-and-egg problem when trying to make a Debian
package of stdeb with stdeb. Here's a recipe to avoid it::

 # in the stdeb distribution directory (with setup.py)
 python setup.py sdist
 python setup.py build
 PYTHONPATH=build/lib python stdeb/py2dsc.py dist/stdeb-VERSION.tar.gz

Pydev 1.2.0 Released

2006-06-19 Thread Fabio Zadrozny
Hi All,  Pydev and Pydev Extensions 1.2.0 have been released  Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: 
http://pydev.sf.net  Details on its development: http://pydev.blogspot.com  Release Highlights in Pydev Extensions: -
 - This is the first version supporting Eclipse 3.2.
- Interactive console: content is now changed so that blocks are closed
with the interactive interpreter 'rules' (so that you don't have
invalid syntax errors when passing code-blocks to the interactive
console).
- An action was added to the menu so that you can use the Open
Declaration Quick-outline without needing focus on the pydev editor.
 Release Highlights in Pydev: -- - Eclipse 3.2 supported (and 3.1 support is now discontinued)
- Lot's of optimizations to make pydev faster
- Ctrl+Click now works with the find definition engine
- Comments that start with #--- are shown in the outline
- Attributes are shown in the outline
- Parse errors are now shown (again) in the editor
- Many other bugs fixed   What is PyDev? --- 
PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.   Cheers,  --  Fabio Zadrozny -- Software Developer  ESSS - Engineering Simulation and Scientific Software
 http://www.esss.com.br  Pydev Extensions http://www.fabioz.com/pydev  Pydev - Python Development Enviroment for Eclipse
 http://pydev.sf.net http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


The First Pune Python meet is scheduled on 24th June.

2006-06-19 Thread Sandy
The First Pune Python meet organized by PythonThreads.com is scheduled
on 24th June. The main purpose of the meet is to introduce Python to
the developers and encourage them to use it in their daily tasks also
to raise the acceptance level of the non-Python developers by
introducing them to the Python world.

Python is used everywhere in almost all the sectors, however its not
yet popular in this part of the world (India) . Considering the growing
importance of scripting languages like Python, awareness of Python is
today a must for even non-Python developers. There are very few
groups in India (like Bangpypers) who are working with great efficiency
and contributing in the growth of Python. We are planning to conduct
the Python meets on every last Saturday of each month, it will help in
spreading the Python language in Pune and across the country.

We are targeting the Pune based software developers, freshers in the IT
sector for this meet. In this meet we will introduce Python, its
strengths, scope, in which sectors it can be implemented also an open
discussion on Python. IndicThreads.com Java meets are held on the last
Saturday of each month. The Python meets are also expected to follow
the same schedule.

Sandeep Gohad will speak on the basics of the Python language, sectors
in which Python is being used and about using and promoting Python. His
session will be followed by an open discussion on Python.

Date and Time:
Saturday, 24th June 2006

4.30 pm - 6.00 pm:
Java Server Faces session - By Swarraj Kulkarni

6.00 pm - 7.00 pm:
PythonThreads.com Pune Python Meet - Introduction To Python - By
Sandeep Gohad.

Venue:
Symbiosis Institute of Computer Studies and Research (SICSR),
7th floor, Atur Center, Model Colony, Pune
(Event supported by SICSR)

* Entry is free of cost. Entry on first come first served basis.

*Please share the meet details or this file on your college / company
mailing lists or notice boards so that others could also benefit.*

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

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


[ANN] PyYAML-3.03: YAML parser and emitter for Python

2006-06-19 Thread Kirill Simonov

 Announcing PyYAML-3.03


A new bug-fix release of PyYAML is now available:

http://pyyaml.org/wiki/PyYAML


Changes
===

* Fix Python 2.5 compatibility issues.
* Fix numerous bugs in the float handling.
* Fix scanning some ill-formed documents.
* Other minor fixes.


Resources
=

PyYAML homepage: http://pyyaml.org/wiki/PyYAML
PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation

TAR.GZ package: http://pyyaml.org/download/pyyaml/PyYAML-3.03.tar.gz
ZIP package: http://pyyaml.org/download/pyyaml/PyYAML-3.03.zip
Windows installer: http://pyyaml.org/download/pyyaml/PyYAML-3.03.win32.exe

PyYAML SVN repository: http://svn.pyyaml.org/pyyaml
Submit a bug report: http://pyyaml.org/newticket?component=pyyaml

YAML homepage: http://yaml.org/
YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core


About PyYAML


YAML is a data serialization format designed for human readability and
interaction with scripting languages.  PyYAML is a YAML parser and
emitter for Python.

PyYAML features a complete YAML 1.1 parser, Unicode support, pickle
support, capable extension API, and sensible error messages.  PyYAML
supports standard YAML tags and provides Python-specific tags that allow
to represent an arbitrary Python object.

PyYAML is applicable for a broad range of tasks from complex
configuration files to object serialization and persistance.


Example
===

 import yaml

 yaml.load(
... name: PyYAML
... description: YAML parser and emitter for Python
... homepage: http://pyyaml.org/wiki/PyYAML
... keywords: [YAML, serialization, configuration, persistance, pickle]
... )
{'keywords': ['YAML', 'serialization', 'configuration', 'persistance',
'pickle'], 'homepage': 'http://pyyaml.org/wiki/PyYAML', 'description':
'YAML parser and emitter for Python', 'name': 'PyYAML'}

 print yaml.dump(_)
name: PyYAML
homepage: http://pyyaml.org/wiki/PyYAML
description: YAML parser and emitter for Python
keywords: [YAML, serialization, configuration, persistance, pickle]


Copyright
=

The PyYAML module is written by Kirill Simonov [EMAIL PROTECTED].

PyYAML is released under the MIT license.

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

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


Re: Change value of element in list

2006-06-19 Thread Rony Steelandt
 Hi,

 I'm doing python tutorial,
 http://docs.python.org/tut/node5.html

 and I have these,

 lists = ['spam', 'eggs', 100, 1234]
 lists[2] = lists[2] + 23

 I expected this,
 lists = ['spam', 'eggs', 123, 1234]

 but got this,
 lists = ['spam', 'eggs', 100, 1234]

 What's my problem here ?

 I have Fedora C5 with python2.4.

 Thanks.

 O Plameras

Don't think so
Microsoft Windows XP [version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrateurpython
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] 
on win32
Type help, copyright, credits or license for more information.
 list=['spam','egg',100,1234]
 list
['spam', 'egg', 100, 1234]
 list[2]=list[2]+23
 list[2]
123
 list
['spam', 'egg', 123, 1234]


Rony

-- 
---
Rony Steelandt
BuCodi
rony dot steelandt (at) bucodi dot com

Visit the python blog at http://360.yahoo.com/bucodi


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


Re: aligning SGML to text

2006-06-19 Thread Gerard Flanagan

Steven Bethard wrote:
 Gerard Flanagan wrote:
  Steven Bethard wrote:
  I have some plain text data and some SGML markup for that text that I
  need to align.  (The SGML doesn't maintain the original whitespace, so I
  have to do some alignment; I can't just calculate the indices directly.)
For example, some of my text looks like:
[...]
 
  Steve
 
  This is probably an abuse of itertools...
 
[snip hammering]

 Thanks for taking a look.  Yeah, the alignment's a big part of the
 problem.  It'd be really nice if the thing that gives me SGML didn't add
 whitespace haphazardly. ;-)

 STeVe

I see, the problem was different than I thought. When all you have is a
hammer... :-)

Gerard

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


Re: wxPython GUI designer

2006-06-19 Thread jean-michel bain-cornu
[EMAIL PROTECTED] a écrit :
 I am newbie learning wxPython. I tried using GUI designer called
 wxGlade. When it generated code I couldnt get the same level of
 flexibility as writing the code by oneself.
 
 Any view on what you think about using GUI designer tools.
 
 Every help is appreciated.
 
Boa is excellent if you stay at a primary level. It's a visual design 
tool, and it can help you to learn how to manage wx classes. It works on 
windows and linux as well.
My understanding of wxglade is that you need skills about sizers to be 
confident with it. So if you know how to use sizers, you don't really 
need a tool.
Regards,
jm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython GUI designer

2006-06-19 Thread Rony Steelandt

 I am newbie learning wxPython. I tried using GUI designer called
 wxGlade. When it generated code I couldnt get the same level of
 flexibility as writing the code by oneself.
 
 Any view on what you think about using GUI designer tools.
 
 Every help is appreciated.
 
 Boa is excellent if you stay at a primary level. It's a visual design tool, 
 and it can help you to learn how to manage wx classes. It works on windows 
 and linux as well.
 My understanding of wxglade is that you need skills about sizers to be 
 confident with it. So if you know how to use sizers, you don't really need a 
 tool.
 Regards,
 jm

I use wxDesigner

-- 
---
Rony Steelandt
BuCodi
rony dot steelandt (at) bucodi dot com

Visit the python blog at http://360.yahoo.com/bucodi


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


Re: any subway web dev experiences

2006-06-19 Thread bruno at modulix
a wrote:
 subway is pythons ruby on rails competitor

Nope - it's a Python MVC web framework. Like Django, Pylons and
Turborgears. And FWIW, there have been recently some discussions about
merging Subway and Turbogears.

 pls tell me if u hav any expereinces

Please take time to learn and write readable english sentences.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Torben Ægidius Mogensen
Raffael Cavallaro [EMAIL PROTECTED]'espam-s'il-vous-plait-mac.com writes:

 This is purely a matter of programming style. For explorative
 programming it is easier to start with dynamic typing and add static
 guarantees later rather than having to make decisions about
 representation and have stubs for everything right from the start.

I think you are confusing static typing with having to write types
everywhere.  With type inference, you only have to write a minimum of
type information (such as datatype declarations), so you can easily do
explorative progrmming in such languages -- I don't see any advantage
of dynamic typing in this respect.

 The
 lisp programming style is arguably all about using heterogenous lists
 and forward references in the repl for everything until you know what
 it is that you are doing, then choosing a more appropriate
 representation and filling in forward references once the program
 gels. Having to choose representation right from the start and needing
 working versions (even if only stubs) of *every* function you call may
 ensure type correctness, but many programmers find that it also
 ensures that you never find the right program to code in the first
 place.

If you don't have definitions (stubs or complete) of the functions you
use in your code, you can only run it up to the point where you call
an undefined function.  So you can't really do much exploration until
you have some definitions.

I expect a lot of the exploration you do with incomplete programs
amount to the feedback you get from type inference.

 This is because you don't have the freedom to explore possible
 solutions without having to break your concentration to satisfy the
 nagging of a static type checker.

I tend to disagree.  I have programmed a great deal in Lisp, Scheme,
Prolog (all dynamically typed) and SML and Haskell (both statically
typed).  And I don't find that I need more stubs etc. in the latter.
In fact, I do a lot of explorative programming when writing programs
in ML and Haskell.  And I find type inference very helpful in this, as
it guides the direction of the exploration, so it is more like a
safari with a local guide than a blindfolded walk in the jungle.

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


Re: Python is fun (useless social thread) ;-)

2006-06-19 Thread Max M
bruno at modulix wrote:

 Or did you just like what you saw and decided to learn it for fun?
 
 Well, I haven't be really impressed the first time - note that it was at
 the very end of the last century, with v1.5.2. 


1.5.2 was an excellent version. Not really that different in use than 
current version.


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] code is data

2006-06-19 Thread bruno at modulix
Anton Vredegoor wrote:
 With the inclusion of ElementTree (an XML-parser) in Python25 and recent
 developments concerning JSON (a very Pythonesque but somewhat limited
 XML notation scheme, let's call it statically typed XML)

JSON stands for JavaScript Object Notation, and has *nothing* to do with
XML - except for the fact that it's more and more used instead of XML
for AJAX stuff.

 Python seems to
 have reached a stage where it now seems to be possible to completely
 swallow lesser languages code, modify it, and spit out new source code
 targeting the original language the code was written in, or even make a
 translation to other languages.

If you mean parsing source in a given format and outputting another -
modified or not - representation, in the same or another format, Python
as always been able to do so.

 The idea is that we now have a fast parser (ElementTree) with a
 reasonable 'API' and a data type (XML or JSON) that can be used as an
 intermediate form to store parsing trees. Especially statically typed
 little languages seem to be very swallow-able. Maybe I will be able to
 reimplement GFABasic (my first love computer language, although not my
 first relationship) someday, just for fun.
 
 Then there are things like cTypes (calling functions from native DLL's)
 and PyPy (implementing Python in Python).
 
 All this taken together, to me it starts looking like we're now entering
 a territory that traditionally was exclusively in the Lisp domain.

Sorry, but I just don't get the point. Parsing, working with trees and
calling native code are in no way exclusively in the Lisp domain.

 Yes, Python had eval and exec for a long time already, and metatypes and
 generators are having some strange unexplored possibilities too, but the
 day will come soon (and at last when PyPy is reaching execution speeds
 close to cPython) where Python will be able to swallow smaller
 languages, and finally it will be able to swallow its own tail, like
 Lisp but then more powerful

I'm afraid Python is still very far from Lisp - and will never get there
(FWIW, this seems not to be the goal anyway).

 (because of the widely used standard data
 types and the code exchange between languages that that makes possible).

I still don't get the point.

 Your thoughts please.
 
 Anton


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code is data

2006-06-19 Thread bruno at modulix
BJörn Lindqvist wrote:
 Personally, I would like to see macros in Python (actually Logix
 succeeding is good enough). But I am no language designer and the
 community has no interest in it. When I absolutely need macros, I will
 go elsewhere.
 
 
 One must wonder, when is that? When do you absolutely need macros?
 
One must wonder, when do you absolutely need HOFs, closures, OO,
functions, or even structured programming. All we 'absolutely' need is
tests and gotos... (and love, of course !-).

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: code is data

2006-06-19 Thread bruno at modulix
Ravi Teja wrote:
 BJörn Lindqvist wrote:
 
Personally, I would like to see macros in Python (actually Logix
succeeding is good enough). But I am no language designer and the
community has no interest in it. When I absolutely need macros, I will
go elsewhere.

One must wonder, when is that? When do you absolutely need macros?
 
 
 Whenever there is significant boiler plate code that functions and
 classes cannot eliminate alone.
 Whenever there is a more elegant way to express your code.
 
 Python 2.5 introduced conditional expressions and with statement. With
 macros, one would not have to wait for the language team to implement
 them. More so for features which only a small part of the community has
 an interest in.
 
 I *like* 1..5 (ada, ruby) instead of range(5). If I had macros, I would
 have done it myself for *my* code.

And that's the downside with macros - and with anything that's not
officially part of the language or it's standard lib : everybody
implements it it's own way, and you end up with dozens non-standard ways
of doing the same thing.

Not to say this is absolutely bad, but there's a balance to be found
here. One could do function decorators long before we had official
syntactic sugar for it, but it only started to be a common idiom with
the @decorator syntax. Python 2.5 introduces a 'partial' type, that is
quite easy to implement with 2.4 (and probably with older versions too),
but having it in the builtins or standard lib means it will become the
standard way to do it - no need to deal with half a dozen half-backed
implementations of it no more.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any subway web dev experiences

2006-06-19 Thread Fredrik Lundh
bruno at modulix wrote:

 Nope - it's a Python MVC web framework. Like Django, Pylons and
 Turborgears. And FWIW, there have been recently some discussions about
 merging Subway and Turbogears.

recently?  was that before or after the developer picked up his marbles 
and went home to complain to his mother?

(according to the subway wiki, only porn sites use the framework these 
days.  hint to developers: if you're shutting down a project, make sure 
you lock down the project site).

/F

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


Check if a file is closed

2006-06-19 Thread camillo
How to check if a file is closed?

On Win32 you can call CreateFile with write and share write and if it
raises an error, the file is closed.

How to do it in Python???

Thanks,
Camillo

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


Re: code is data

2006-06-19 Thread bruno at modulix
Ravi Teja wrote:

(snip)
 Annoted variables, symbols and code
 layout visually cue more efficiently to the object nature than do
 explicit text definitions. Of course, this is only sensible when there
 aren't too many of any of those. In that case, the cognitive cost of
 notation outweighs the representational cost of text.
 
 Representational minimalism is troublesome in general code (ala Perl),
 but not so in a DSL where the context is constrained.

This still impose the need to learn a new language.

 I would also like to symbolize field types since they occur so commonly
 in a definition file and only a few of them are commonly used. I admit
 though that I find the code below a bit visually jarring and I might
 use something else. But it serves to illustrate the point. I chose the
 respective symbols based on their colloquial use and association with
 the field types.
 
 @Poll:
 $question: length 200
 %pub_date('date published')
 
 @Choice:
 poll - Poll
 $choice: length 200
 #votes

IMHOYuck/IMHO.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tetris

2006-06-19 Thread [EMAIL PROTECTED]
pygame.org is what you need
it has tutorials
it's cool

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


Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Rob Thorpe
Torben Ægidius Mogensen wrote:
 Rob Thorpe [EMAIL PROTECTED] writes:

  Torben Ægidius Mogensen wrote:

   That's the point: Bugs that in dynamically typed languages would
   require testing to find are found by the compiler in a statically
   typed language.  So whil eit may take onger to get a program thatgets
   past the compiler, it takes less time to get a program that works.
 
  In my experience the opposite is true for many programs.
  Having to actually know the precise type of every variable while
  writing the program is not necessary, it's a detail often not relevant
  to the core problem. The language should be able to take care of
  itself.
 
  In complex routines it can be useful for the programmer to give types
  and for the compiler to issue errors when they are contradicted.  But
  for most routines it's just an unnecessary chore that the compiler
  forces on the programmer.

 Indeed.  So use a language with type inference.

Well, for most purposes that's the same as dynamic typing since the
compiler doesn't require you to label the type of your variables.  I
occasionally use CMUCL and SBCL which do type inference, which is
useful at improving generated code quality.  It also can warn the
programmer if they if they reuse a variable in a context implying that
it's a different type which is useful.

I see type inference as an optimization of dynamic typing rather than a
generalization of static typing.  But I suppose you can see it that way
around.

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


Re: Seeking regex optimizer

2006-06-19 Thread Kay Schluehr
Mirco,

with special characters I mentioned control characters of regular
expressions i.e. one of .^$()?[]{}\|+* but not non ascii-127
characters.

For a workaround you simply have to mangle those using an escape
control character:

REGEXCHAR = .^$()?[]{}\\|+*
def mangle(s):
pattern = []
for c in s:
if c in REGEXCHAR:
pattern.append(\\)
pattern.append(c)
   return .join(pattern)
 
Regards,
Kay

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


Re: Check if a file is closed

2006-06-19 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
 How to check if a file is closed?

 f = open('trashme.txt', 'w')
 f
open file 'trashme.txt', mode 'w' at 0x2ab66e40
 dir(f)
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
'__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__str__', 'close', 'closed', 'encoding',
'fileno', 'flush', 'isatty', 'mode', 'name', 'newlines', 'next', 'read',
'readinto', 'readline', 'readlines', 'seek', 'softspace', 'tell',
'truncate', 'write', 'writelines', 'xreadlines']
 f.closed
False
 f.close()
 f.closed
True


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Does anyone find what is fun in programming...?

2006-06-19 Thread Mohamad Nazzal








You all suck.



Am a programmer, and I must confess that I am dumb since am
a programmer. Stop being silly and talk about programming as if youre
writing a beautiful story. Youre not more than coding generators. Its
the most boring work that anybody can imagine. Am a computer sciences graduate,
and I am now a programmer, but I hope that soon I can escape from this shit. Am
studying Business management right now, and I want to change the whole previous
orientation of my career, you know why, because programming sucks the same as
the programmers suck. Were a bunch of freaks, we dont have social
life, actually I have a social life and that is why I cant go on with
programming, and sure I wont let programming corrupt my head. You all,
start the change and escape from programming. That is for your own benefit. And
unfortunately now after clicking on the send button, I have to go back to my
program and start this shit again. Go all to hell






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

RE: Check if a file is closed

2006-06-19 Thread Tim Golden
[EMAIL PROTECTED]

| How to check if a file is closed?
| 
| On Win32 you can call CreateFile with write and share write and if it
| raises an error, the file is closed.
| 
| How to do it in Python???

It's not clear whether you want a cross-platform Python-only
solution. But if all you want is a way to use the Win32
CreateFile API in Python, then:

http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/win32file
__CreateFile_meth.html

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


Just out of curiosity: Which languages are they using at Google and what for?

2006-06-19 Thread alainpoint
I know Google are using Python for testing purposes.
But for the rest ?
is it PHP or Java or .NET?
Which technology is rendering the google main page?

And of course th obvious question, why not Python?

Alain

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


Re: Noob script needs some input: CVS PatchMaker

2006-06-19 Thread Holger

John Machin wrote:
  Any feedback on what would be the pythonic way to do this would be
  much appreciated!
--snip--

 IMHO that flight of geese heading equatorwards for winter is not Xic for
 any language X. Compare with:

He he, good point.

 2nd comment: Make a habit of NOT using the names of built-ins like
 file for your own names. Pretend they are reserved words. Doesn't
 matter in this case, but will save you grief some day soon.


Agree.

 3rd comment: Read the section in the re manual that explains the
 difference between search and match. Searching for ^foo will give the
 same results as using match() with foo or the redundantly anchored
 ^foo. However some regex engines when presented with

Good point.

 4th comment: what you have called regx is a match object. mobj might
 be a better choice. The term regex is applied to a pattern, or
 sometimes to the compiled re object.
]

 HTH,
 John

Thank you for taking the time :-)
All points are noted.

Holger,

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


memory-leak in pysqlite 2.3.0 ?

2006-06-19 Thread Michael Husmann
After upgrading from pysqlite 2.0.5 to pysqlite 2.3.0 writing into a
sqlite database increases memory consumption heavily. A similar program
with Ruby and sqlite-ruby 1.1.0 does not affect memory consumption at
all.

Here a short example:
---
#!/usr/bin/env python

import os
from pysqlite2 import dbapi2
print dbapi2.version

db = dbapi2.connect(bla.db)
c = db.cursor()

c.execute(create table b (c integer))

for i in xrange(1000):
c.execute(insert into b values (%d) % i)
  
--

System in use:
Python 2.4.1, Sqlite3 3.3.6, Pysqlite 2.3.0

Regards,
Michael

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


Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Torben Ægidius Mogensen
Rob Thorpe [EMAIL PROTECTED] writes:

 Torben Ægidius Mogensen wrote:
  Rob Thorpe [EMAIL PROTECTED] writes:
 
   Torben Ægidius Mogensen wrote:
 
  Indeed.  So use a language with type inference.
 
 Well, for most purposes that's the same as dynamic typing since the
 compiler doesn't require you to label the type of your variables.

That's not really the difference between static and dynamic typing.
Static typing means that there exist a typing at compile-time that
guarantess against run-time type violations.  Dynamic typing means
that such violations are detected at run-time.  This is orthogonal to
strong versus weak typing, which is about whether such violations are
detected at all.  The archetypal weakly typed language is machine code
-- you can happily load a floating point value from memory, add it to
a string pointer and jump to the resulting value.  ML and Scheme are
both strongly typed, but one is statically typed and the other
dynamically typed.

Anyway, type inference for statically typed langauges don't make them
any more dynamically typed.  It just moves the burden of assigning the
types from the programmer to the compiler.  And (for HM type systems)
the compiler doesn't guess at a type -- it finds the unique most
general type from which all other legal types (within the type system)
can be found by instantiation.

  I
 occasionally use CMUCL and SBCL which do type inference, which is
 useful at improving generated code quality.  It also can warn the
 programmer if they if they reuse a variable in a context implying that
 it's a different type which is useful.
 
 I see type inference as an optimization of dynamic typing rather than a
 generalization of static typing.  But I suppose you can see it that way
 around.

Some compilers for dynamically typed languages will do a type analysis
similar to type inference, but they will happily compile a program
even if they can't guarantee static type safety.

Such type inference can be seen as an optimisation of dynamic
typing, as it allows the compiler to omit _some_ of the runtime type
checks.  I prefer the term soft typing for this, though, so as not
to confuse with static type inference.

Soft typing can give feedback similar to that of type inference in
terms of identifying potential problem spots, so in that respect it is
similar to static type inference, and you might get similar fast code
development.  You miss some of the other benefits of static typing,
though, such as a richer type system -- soft typing often lacks
features like polymorphism (it will find a set of monomorphic
instances rather than the most general type) and type classes.

Torben

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


Re: What is Expressiveness in a Computer Language

2006-06-19 Thread George Neuner
On 19 Jun 2006 10:19:05 +0200, [EMAIL PROTECTED] (Torben Ægidius
Mogensen) wrote:


If you don't have definitions (stubs or complete) of the functions you
use in your code, you can only run it up to the point where you call
an undefined function.  So you can't really do much exploration until
you have some definitions.

Well in Lisp that just drops you into the debugger where you can
supply the needed return data and continue.  I agree that it is not
something often needed.


I expect a lot of the exploration you do with incomplete programs
amount to the feedback you get from type inference.

The ability to write functions and test them immediately without
writing a lot of supporting code is _far_ more useful to me than type
inference.  

I'm not going to weigh in on the static v dynamic argument ... I think
both approaches have their place.  I am, however, going to ask what
information you think type inference can provide that substitutes for
algorithm or data structure exploration.

George
--
for email reply remove / from address
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python with Eclipse

2006-06-19 Thread Dennis Benzinger
Stan Cook wrote:
 I've been trying to use Eclipse with Python on Linux for a while and 
 have noticed something odd.  After running the code or debugging a few 
 times, its responsiveness gets really bad.  Upon checking the equivalent 
 of the task manager, I find several instances of Python running.  When I 
 kill these instances, the responsiveness comes back.  I'm not sure if 
 there is a better place to post this, but it is Python related.  Is this 
 just an issue with Eclipse or is there something else I should inspect?
 
 Any help would be appreciated.
 
 Regards,
 
 S Cook

Which Python plugin are you using? PyDev?


Bye,
Dennis
-- 
http://mail.python.org/mailman/listinfo/python-list


Yet Another Python Blog

2006-06-19 Thread Miki
Hello All,

Decided that there are not enough blogs out there so
http://pythonwise.blogspot.com/ is up :)

This blog will feature a weekly (or about) Python code examples.
I'll be glad to hear your comments.

Miki,
http://pythonwise.blogspot.com/

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


Re: Just out of curiosity: Which languages are they using at Google and what for?

2006-06-19 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
 I know Google are using Python for testing purposes.

Not only:

Where is Python used?

* The Google build system is written in python.  All of Google's
corporate code is checked into a repository and the dependency and
building of this code is managed by python.  Greg mentioned that to
create code.google.com took about 100 lines of python code.  But since
it has so many dependencies, the build system generated a 3 megabyte
makefile for it!
* Packaging.  Google has an internal packaging format like RPM.
These packages are created using python.
* Binary Data Pusher.  This is the area where Alex Martelli is
working, on optimizing pushing bits between thousands of servers
* Production servers.  All monitoring, restarting and data
collection functionality is done with python
* Reporting.  Logs are analyzed and reports are generated using Python.
* A few services including code.google.com and google groups.  Most
other front ends are in C++ (google.com) and Java (gmail).  All web
services are built on top of a highly optimizing http server wrapped
with SWIG.


http://panela.blog-city.com/python_at_google_greg_stein__sdforum.htm



-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple script to make .png thumbnails from .zip archive...

2006-06-19 Thread K P S
Thanks a lot.
  I'm really new to python, and haven't coded in over a decade, so
please be patient. :-)

I'm able to read a .jpg from a .zip archive, but can't seem to
manipulate it.  If I do this:

zip=zipfile.ZipFile(inURL,mode=r)
picture=zip.read(00.jpg)

I get the image, but it is of type ZipFile.  How can I change it to
type Image?  Or am I thinking about this in the wrong way?  I would
like to follow this with something like:

picture.thumbnail((128, 128), Image.ANTIALIAS)

But obviously I can't do this directly.  What am I missing?

hdante wrote:
 Hi,

  I don't know zipfile by heart, but python official documentation is
 always good ( docs.python.org ). You need a loop in the file list like
 this:

   for file in zip:
 process(file)

  Unfortunatelly, there are too many ways to create a thumbnail from an
 image. I'll cite one, using the python image external module, that
 I've found to be very easy:

 import Image
 def process(file):
   try:
 image = Image.open(file)
 image.thumbnail ((128,128), Image.ANTIALIAS)
 image.save (file + '.thumb.png')
   except:
 print 'Skipping file', file

  Links:
  http://docs.python.org/lib/lib.html - Python Library Reference
  http://www.pythonware.com/library/pil/handbook/image.htm - The Image
 Module

 K P S wrote:
  Hi.
I'm looking for a small script that will take a .zip archive and pull
  the first .jpg from the archive and convert it to a .png.
 
  The reason for this is I want to have tuhmbnails for these archives in
  nautilus under gnome.  I would like something similar to the following
  code, which will pull a thumbnail from an openoffice.org (oasis)
  document.  What I want is a little more involved, I guess, since I
  don't know the name of the file (for the zip.read command), and I need
  to convert the file from .jpg to .png once I get it.  Any help would be
  appreciated.  Including a pointer to a web page of a manual with
  examples. :-)
 
  #!/usr/bin/python
 
  import zipfile
  import sys
  import gnomevfs
 
  inURL=gnomevfs.get_local_path_from_uri(sys.argv[1])
  outURL=sys.argv[2]
 
  zip=zipfile.ZipFile(inURL,mode=r)
  picture=zip.read(Thumbnails/thumbnail.png)
  thumbnail=open(outURL,w)
  thumbnail.write(picture)
  thumbnail.write(/n)
  zip.close()
  thumbnail.close()

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


Re: Simple script to make .png thumbnails from .zip archive...

2006-06-19 Thread Ant
Try adapting the other posters example with something like:

 import Image, StringIO
 zip=zipfile.ZipFile(inURL,mode=r)
 picture=zip.read(00.jpg)
 image = Image.open(StringIO(picture))
 image.thumbnail ((128,128), Image.ANTIALIAS)
 image.save (file + '.thumb.png')

I haven't tested it, but something like this should work.

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


Re: Simple script to make .png thumbnails from .zip archive...

2006-06-19 Thread Fredrik Lundh
K P S wrote:

 I'm able to read a .jpg from a .zip archive, but can't seem to
 manipulate it.  If I do this:
 
 zip=zipfile.ZipFile(inURL,mode=r)
 picture=zip.read(00.jpg)
 
 I get the image, but it is of type ZipFile.

string, more likely (zip is a ZipFile object, picture is a string of 
bytes).  PIL expects a file name or a file object, so you need to use 
the StringIO adapter:

picture = zip.read(name) # returns a string
file = StringIO.StringIO(picture) # wrap string in file-like object
image = Image.open(file) # create image object from file-like object

/F

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


Re: Simple script to make .png thumbnails from .zip archive...

2006-06-19 Thread Fredrik Lundh
K P S wrote:

 What I want is a little more involved, I guess, since I
 don't know the name of the file (for the zip.read command)

the first example on this page shows you how to get the names of all 
files in a zip file:

 http://effbot.org/librarybook/zipfile.htm

/F

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


Re: Python with Eclipse

2006-06-19 Thread Fabio Zadrozny
On 6/18/06, Stan Cook [EMAIL PROTECTED] wrote:
I've been trying to use Eclipse with Python on Linux for awhile and have noticed something odd.After running thecode or debugging a few times, its responsiveness getsreally bad.Upon checking the equivalent of the task
manager, I find several instances of Python running.When Ikill these instances, the responsiveness comes back.I'mnot sure if there is a better place to post this, but it isPython related.Is this just an issue with Eclipse or is
there something else I should inspect?
If you're using pydev, the problem might be that you have PyLint
enabled. Having it enabled might have the effect of spawning several
shells for doing code-analysis. You can try disabling it or using pydev
extensions that gives you a faster code-analysis. You might also
restrict the number of shells that PyDev can spawn at a given time in
the pylint preferences (if that's not it, please report it as a bug in
the pydev tracker at sourceforge, so that we can check other
possibilities --
https://sourceforge.net/tracker/?group_id=85796atid=577329).

Cheers,

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

Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Torben Ægidius Mogensen
George Neuner gneuner2/@comcast.net writes:

 On 19 Jun 2006 10:19:05 +0200, [EMAIL PROTECTED] (Torben Ægidius
 Mogensen) wrote:

 I expect a lot of the exploration you do with incomplete programs
 amount to the feedback you get from type inference.
 
 The ability to write functions and test them immediately without
 writing a lot of supporting code is _far_ more useful to me than type
 inference.  

I can't see what this has to do with static/dynamic typing.  You can
test individula functions in isolation is statically typed languages
too.
 
 I'm not going to weigh in on the static v dynamic argument ... I think
 both approaches have their place.  I am, however, going to ask what
 information you think type inference can provide that substitutes for
 algorithm or data structure exploration.

None.  But it can provide a framework for both and catch some types of
mistakes early.

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


Amara installation

2006-06-19 Thread mirandacascade
O/S WinXP Home
Vsn of Python: 2.4

Wish to install Amara.  Using amara-allinone-1.0.win32-py2.4.exe
(2965KB)

Forder structure before installation:

c:
  python24
DLLs
Doc
Include
Lib
  site-packages
[previously installed stuff]
libs
scripts
tcl
tools

When I run install, the install program indicates:

Python directory: c:\python24\
Installation directory: c:\python24\lib\site-packages\

After install, folder structrue is:

Vsn of Python: 2.4

Wish to install Amara.  Using amara-allinone-1.0.win32-py2.4.exe
(2965KB)

Forder structure after installation:

c:
  python24
DLLs
Doc
Include
Lib
  site-packages
[previously installed stuff]
libs
python24 --
  lib --
site-packages--  new amara files/folders appear
  amara   --  to be installed here
  ft   --
scripts--
share  --
scripts
tcl
tools

I was expecting the new amara files/folders to be installed within the
existing c:\python24\ folder structure...wasn't expecting it to create
a new ...\python24\ folder within the parent ...\python24\ folder.

My questions:
1) has anyone else observed this when installing?
2) should I move the newly installed files/folders into the
previously-existing folder structure?  as long as I don't remove
files/folders, is there any risk of causing a previously installed site
package that worked to no longer work?

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


Re: Passing data to system command

2006-06-19 Thread Chris Hieronymus
Hi,

Holy mackerel, this really works; thanks a lot, guys.  I played  
around a little bit with the
suggestions by faulkner and hdante and pieced together the following  
script.  I like this
very much because I can write a bunch of data to the pipe, rather  
than making one big
string containing perhaps several thousand lines of x-y pairs.  I've  
tested the script for
up to 100,000 data pairs and it works; passing a single string with  
that many lines to
the psxy command generally leads to problems (?), I'm told...

For any other newbie's out there that are trying to use python and  
GMT together:
The script uses GMT's psxy command (with the required arguments),  
generates some
x-y data (just a sine function), and writes each x-y pair as a string  
to the pipe.  This should
work equally for any other GMT-commands.

I'm still trying to work out some of the details myself; I don't  
understand, yet, what exactly
the command communicate does; but it seems to be needed.

chris


=

#! /usr/bin/python

from subprocess import Popen, PIPE
from math import *
from os import system

psfile = 'output1.ps'
cmd = 'psxy -R0/100/0/10 -JX10 -B10/1'


my_output = file(psfile, 'w')
p1 = Popen(cmd,stdin = PIPE,stdout=my_output,shell=True)
for i in range(1):
   x = float(i)/100.0
   y = 4.*sin(x/10.)+5.0
   msg = str(x)+  +str(y)+\n
   p1.stdin.write(msg)

p1.communicate()
my_output.close()

cmd = 'gv '+psfile
print cmd
p2 = Popen(cmd,shell=True)
p2.communicate()

=


On Jun 18, 2006, at 11:27 PM, hdante wrote:

  Should be like this:

  from subprocess import Popen, PIPE

  my_output = file('output1.ps', 'w')
  p1 = Popen([psxy], stdin = PIPE, stdout=my_output)
  p1.stdin.write(my_format(array))
  p1.communicate()
  my_output.close()

  I've never used that, though, please tell us if it worked.

 Chris Hieronymus wrote:
 Hi,

 I have a bunch of x-y data contained in an array.  I would like to
 plot the data using an
 external program (psxy in GMT).  The plotting program takes x-y
 couples as standard
 input.  How do I get the data into the system call?  I used to do
 things in csh and awk,
 i.e., something like

 awk '{some manipulations here; print $1, $2}' filename | psxy some
 options ! output.ps

 The reason I'm trying to use python is because the manipulations are
 getting too cumbersome
 in awk.  Now I have all the manipulations done in python, but I'm
 missing that last step.

 I've tried various things with os.system, popen, and subprocess, but
 so far without success.
 Does anyone know how to do this?

 chris


 - 
 ---
 ---
 Christoph
 Hieronymus
 [EMAIL PROTECTED]
 Associate
 Professor
 phone: (+46) 18-471 2383
 Uppsala
 University
fax:   (+46) 18-501   110
 Dept. of Earth Sciences (Geophysics)
 Villavägen 16
 SE-752 36 Uppsala,  Sweden

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

 
---
Christoph  
Hieronymus 
[EMAIL PROTECTED]
Associate  
Professor
phone: (+46) 18-471 2383
Uppsala  
University   
   fax:   (+46) 18-501   110
Dept. of Earth Sciences (Geophysics)
Villavägen 16
SE-752 36 Uppsala,  Sweden




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


Re: Python is fun (useless social thread) ;-)

2006-06-19 Thread H J van Rooyen
Bruno wrote:

8(snip)--

| The answer is 42. That's all you need to know.


Right on, Ford Prefect !!!

What's for Lunch?

- Hendrik


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


Re: pyfcp

2006-06-19 Thread Thomas Moore
  http://www.python.org/pyfcp
 

It gets me to Error 404.



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


Re: pyfcp

2006-06-19 Thread aum
On Mon, 19 Jun 2006 14:45:19 +0800, Thomas Moore wrote:

  http://www.python.org/pyfcp
 
 
 It gets me to Error 404.

Apologies - that URL should have been:

http://www.python.org.nz/pyfcp

-- 

Cheers
aum


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


Re: Detecting key presses

2006-06-19 Thread peter
Not a stupid question at all - its something I was looking for, and was
(and still am) surprised not to find a cross platform implementation.
It must be possible - for a short while I dabbled with yabasic and
there the same source code would recognise a keypress in both Windows
and Linux.

My solution was:-

# Await key and return code - dos only
def _keycode_msvcrt(self):
#Loop till key pressed
while 1:
if msvcrt.kbhit():
k=ord(msvcrt.getch())
if k==0 or k==224:#Special keys
   k=1000+ord(msvcrt.getch()) #return 1000+ 2nd code
pass
break
pass
pass
return k

# Await key and return code - linux only
def _keycode_linux2(self):
# Loop till key pressed
# Set up keycode list
a=[0,0,0,0,0,0]

# Press a key and populate list
try:
os.system('stty -icanon')
os.system('stty -echo')
a[0]=ord(sys.stdin.read(1))
if a[0]==27:
a[1]=ord(sys.stdin.read(1))
if a[1]==91:
a[2]=ord(sys.stdin.read(1))
if (a[2]=49 and a[2]=54) or a[2]==91:
a[3]=ord(sys.stdin.read(1))
if a[3]=48 and a[3]=57:
a[4]=ord(sys.stdin.read(1))
finally:
os.system('stty echo')
os.system('stty icanon')

# Decode keypress
if   a==[ 10,  0,  0,   0,   0, 0]: k=  13   # Enter
elif a==[ 27, 27,  0,   0,   0, 0]: k=  27   # Esc (double
press)
elif a==[ 27, 91, 91,  65,   0, 0]: k=1059   # F1
elif a==[ 27, 91, 91,  66,   0, 0]: k=1060   # F2
elif a==[ 27, 91, 91,  67,   0, 0]: k=1061   # F3
elif a==[ 27, 91, 91,  68,   0, 0]: k=1062   # F4
elif a==[ 27, 91, 91,  69,   0, 0]: k=1063   # F5
elif a==[ 27, 91, 49,  55, 126, 0]: k=1064   # F6
elif a==[ 27, 91, 49,  56, 126, 0]: k=1065   # F7
elif a==[ 27, 91, 49,  57, 126, 0]: k=1066   # F8
elif a==[ 27, 91, 50,  48, 126, 0]: k=1067   # F9
elif a==[ 27, 91, 50,  49, 126, 0]: k=1068   # F10
elif a==[ 27, 91, 50,  51, 126, 0]: k=1133   # F11
elif a==[ 27, 91, 50,  52, 126, 0]: k=1134   # F12
elif a==[ 27, 91, 50, 126,   0, 0]: k=1082   # Ins
elif a==[ 27, 91, 51, 126,   0, 0]: k=1083   # Del
elif a==[ 27, 91, 49, 126,   0, 0]: k=1071   # Home
elif a==[ 27, 91, 52, 126,   0, 0]: k=1079   # End
elif a==[ 27, 91, 53, 126,   0, 0]: k=1073   # Pg Up
elif a==[ 27, 91, 54, 126,   0, 0]: k=1081   # Pg Dn
elif a==[ 27, 91, 65,   0,   0, 0]: k=1072   # Up
elif a==[ 27, 91, 66,   0,   0, 0]: k=1080   # Down
elif a==[ 27, 91, 68,   0,   0, 0]: k=1075   # Left
elif a==[ 27, 91, 67,   0,   0, 0]: k=1077   # Right
elif a==[127,  0,  0,   0,   0, 0]: k=   8   # Backspace
else:   k=a[0]   # Ascii code

# Done
return k


# Return key code
def key(self,case='NONE'):

# Get OS name and call platform specific function
a=sys.platform
if a=='linux2':   #Linux (works on Fedora
Core 1 and 3)
k=self._keycode_linux2()
elif a=='win32':  #windows
k=self._keycode_msvcrt()
else: #unknown
k=ord(raw_input())

# Adjust case
if case=='UPPER':
 if k=97 and k=122:
  k=k-32
if case=='LOWER':
 if k=65 and k=90:
  k=k+32

# Done
return k

A bit clumsy, I know (for example it needs a a double press to
recognise the escape key), and I'm not sure I understand why it works,
but for me it was a passable solution.

Peter

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


comparing two arrays

2006-06-19 Thread Sheldon
Hi,

I have two arrays that are identical and contain 1s and zeros. Only the
ones are valid and I need to know where both arrays have ones in the
same position. I thought logical_and would work but this example proves
otherwise:
 a = [0,1,2,5,6,6]
 b = [5,4,1,6,4,6]
 Numeric.logical_and(a==6,b==6)
0
 Numeric.where(a==b,1,0)
0
 Numeric.where(a==6 and b==6,1,0)
0

The where() statement is also worhtless here. Does anyone have any
suggestion on how to do this?

Thanks in advance,
Sheldon

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


Re: Seeking regex optimizer

2006-06-19 Thread John Machin
On 19/06/2006 7:06 PM, Kay Schluehr wrote:
 Mirco,
 
 with special characters I mentioned control characters of regular
 expressions i.e. one of .^$()?[]{}\|+* but not non ascii-127
 characters.
 
 For a workaround you simply have to mangle those using an escape
 control character:
 
 REGEXCHAR = .^$()?[]{}\\|+*
 def mangle(s):
 pattern = []
 for c in s:
 if c in REGEXCHAR:
 pattern.append(\\)
 pattern.append(c)
return .join(pattern)
  

What's wrong with re.escape()?
Have you not read (a) my response to Paddy's first posting (b) the manual?


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


Re: [OT] code is data

2006-06-19 Thread Anton Vredegoor
bruno at modulix wrote:

 I still don't get the point.

Well, I've got to be careful here, lest I'd be associated with the 
terr.., eh, the childp..., eh the macro-enablers.

The idea is to have a way to transform a Python (.py) module into XML 
and then do source code manipulations in XML-space using ElementTree.

But rest assured, there is no such module, nor will we ever need it for 
anything.

Anton

use cases are for the faint-hearted
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comparing two arrays

2006-06-19 Thread Diez B. Roggisch
Sheldon wrote:

 Hi,
 
 I have two arrays that are identical and contain 1s and zeros. Only the

Obviously they aren't identical. They may be of same size.

 ones are valid and I need to know where both arrays have ones in the
 same position. I thought logical_and would work but this example proves
 otherwise:
 a = [0,1,2,5,6,6]
 b = [5,4,1,6,4,6]
 Numeric.logical_and(a==6,b==6)
 0
 Numeric.where(a==b,1,0)
 0
 Numeric.where(a==6 and b==6,1,0)
 0
 
 The where() statement is also worhtless here. Does anyone have any
 suggestion on how to do this?


print [i for i, _ in enumerate((None for v in zip(a, b) where v == (1,1)))]

should give you the list of indices.

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


crawlers in python with graphing?

2006-06-19 Thread bryan rasmussen
Hi

I'm wondering if there is a toolkit in python anywhere for doing at a
high level web crawling, dumping links to a data set that could be
imported into R relatively easy or used in python natively to generate
a graph over the website.


It should hopefully be as high level as Wget, not download the pages
but just follow the links, and output graphs.



Cheers
Bryan Rasmussen
-- 
http://mail.python.org/mailman/listinfo/python-list


interactive multi-file search and replace

2006-06-19 Thread Ryan Krauss
I need to do some searching and replacing in about 10 latex files.
Does anyone have an existing script that does this on an interactive
basis?  I would like to show each match and ask whether or not it
should be replaced.

This seems like a fairly common task and I don't want to re-invent the wheel.

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


Re: code is data

2006-06-19 Thread Michele Simionato
John Roth wrote:
 I saw the make statement as a breath of fresh air.
 Then it got shot down for what were, to me, totally
 trivial reasons.

Which reasons? I as I recall, Guido cut it out without giving any
reason.
Of course Guido has the right to do so,  but it is not respectful of
all the work people like Steven Bethard and others did :-(

 Michele Simionato

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


Re: [Python-Dev] The baby and the bathwater (Re: Scoping, augmented assignment, 'fast locals' - conclusion)

2006-06-19 Thread Boris Borcic
Hello, just a couple points

On 6/17/06, Josiah Carlson [EMAIL PROTECTED] wrote:

[errors involving the shadowing of a variable by another]

   Of course everybody makes errors, but it doesn't follow from this, that
   all make the same errors, or should.
 
  If I implied that everyone has made this particular mistake, I'm sorry.
  I was trying to say that I made error X, and that I don't believe that
  I'm a unique butterfly to have made error X.

Well, don't be so certain you aren't the exceptional butterfly as regards the 
general issue - if not the error itself, perhaps the onlook. It deemed on me 
over the week-end that all three of me, you, and Guido indeed, have been acting 
out our own names in some way. Guido van Rossum's case is most direct : The 
guide by red lights. Me, well, the issue of comparing slightly different 
versions is kind of written in the relationship of my first name and my family 
name. As for you, your name is exceptional in that it makes your initials 
shadow 
those of Jesus-Christ (a builtin if any); and if you go to the bottom of it, 
that collision of identifiers goes slightly further than just the initials.

Is the idea that people may get subtly influenced by their own names, new to 
you 
? One's name is to language and thought as one's home is to space...

Bill Gates has always struck me as an injunction...

...
  One consequence of either a fixed or variable set of non-shadowables is
  that you would need to use arbitrarily unique names for lexically nested
  for loops, and/or specify that such variables are not referencing parent
  scopes.
 
  def foo(...):
  for i in ...:
  ...
  def bar(...):
  ...
  for i in ...: #unallowed
  ...
  ...
 
  You can replace the 'i' with a name of your choosing.  Is such
  desireable?  I would say no for the same reasons why I said no in
  regards to being able to explicitly name variables in different levels
  within lexically nested scopes: I would argue that one shouldn't be
  using closures in the first place, so encouraging its use with a syntax
  is right out the door.  But that's my opinion, and not really relevant
  to the current discussion.

I am surprised you would count the obligation of picking distinct names as an 
encouragement to use lexically nested scopes; compared to the current 
situation, 
it is in fact more -restrictive- and should thus count as -discouraging-. And 
imo picking different names for loop variables in such a case is rather a good 
thing. But, again, more good ain't more ease.

Nit : retrospectively I believe I let you push me into equating closures with 
lexically nested function scopes, but am I right in believing closures in 
fact implies functions defined with nested scopes be exported/returned outside 
of the parent scope ?

...
  I don't believe that Guido is the end-all-be-all of language
  design, but I do find that I agree with him more often than not (though
  perhaps not vv), and at least in regards to this particular
  functionality, I side with the 'status quo' end of things.

I dont understand the (though perhaps not vv). Is the vv intended to stand 
for you (eg, myself) ? I've always liked Guido's Python a lot, and part of it 
has to do with the ante-Bill-Gates magic of programming. For a looong while, 
my consistent experience with  the Where do you want to go today ? MS slogan 
- 
as illustrated by MS products - has been that whenever you tried to find 
imaginative programming solutions (as opposed to obeying the designer's 
obvious 
expectation despite his claim he lets you free) you would collide with glass 
walls... or end up at a billing gate (=some commercial extension product). 
I've had slightly better experience in later years.

Python always had a completely different feel, more like the restitution of the 
old magic to new generations. (btw, Prolog is the language that most gave me 
that feeling of allowing spectacular escapes from the designer's obvious 
expectations, so it is not a matter of constraints - prolog is quite 
constraining. I think it has to do with consistency and humbleness of a design 
that is not trying to out-think its users).

As concerns the case in point, I think it was unfortunate that you would not 
let 
come into the open that the (risk of) inadvertent capture of builtins by 
un-nested function scopes was critical to the shape of the feature. Indeed, 
speaking of status quo ante : augmented assignments arrived with Python 2.0, 
while nested scopes where first introduced with 2.1.

 
  Have a good weekend,

Thank you. I had a good weekend. I hope you too. And together with my thanks 
for 
your efforts, please recieve my apologies for temper...

   - Josiah
 
  [1] http://www.csmonitor.com/2006/0515/p13s01-stct.html

...as this seems to imply you would.

Boris
--
On naît tous les mètres du même monde
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: copyfile avoiding overwrites and race conditions

2006-06-19 Thread Larry Bates
[EMAIL PROTECTED] wrote:
 Here is a code fragment, where I am trying to copy a file, avoiding
 overwrites and race conditions.  The filename gets a '02','03','04' etc
 appended to the end if a file with that name already exists.
 
 I know the writing of the single space is overkill, but I am surprised
 I cannot find an example of this floating around the web and newsgroups
 
 my understanding of 'os.open' and 'os.fdopen' is minimal
 
 ## start fragment
 
 i = 0
 while True:
 
 if i = 100: raise RanOutFileNamesError(fullpath)
 i += 1
 
 if i  1:
 name0 = '%s_%02i%s' % (suggested_name, i, file_extension)
 else:
 assert i == 1
 name0 = '%s%s' % (suggested_name, file_extension)
 fullpath = os.path.join(path0, name0)
 
 # create dummy file, force overwrite
 
 try:
 fd = os.open(
 fullpath,
 os.O_CREAT | os.O_EXCL | os.O_WRONLY)
 except OSError:
 continue
 
 # is this really necessary?
 file = os.fdopen(fd, w)
 file.write(' ')
 file.close()
 
 shutil.copyfile(original_filepath, fullpath)
 
 return fullpath
 
 ## end fragment
 
I guess my approach would be different.  To eliminate any race
conditions, I would keep a small text file that always contained
the next filename that is to be written.  Something like:

nextfiletowrite=/path/filename006.dat

I would try to get a lock on this file, read it, extract next
filename, increment the counter portion of the filename,
write it back out and unlock it.  Now I have the name of the
file to write that is unique to my instance and I can write it
without worrying about other processes.

Hope this helps.

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


Tix Tree / HList widget?

2006-06-19 Thread Tim N. van der Leeuw
Hi,

I need to display some hierarchical data, and because I don't want to
force users to install too many things beyond Python itself, I'm hoping
to use Tix which is at least included with Python.

I've managed to use the Tix HList widget to display a tree of items (at
least in a proof-of-concept miniprogram) but I actually need to display
2 columns -- perhaps more.

I figured out that I can specify the number of columns and the headers
of the columns, but I haven't yet figured out how to set the values of
the columns independantly.

I tried using a tuple for the value of 'text' attribute, but that
doesn't really seem to work. My second column never seems to be filled
- all text goes into the first column.
Also, the header for the second column never shows.

I must be overlooking something rather basic in the manuals but for the
moment I'm stumped.

I'm also trying to figure out how to create a Tix 'Tree' widget instead
of a HList, and make it do the same, but I don't know how to pass it
the option for 2 columns: the 'Tree' widget refuses the option
'columns'. The samples in the Tix manual are for Tcl. I don't know how
to translate their samples into Python/TkInter. How should I tell the
Tix 'Tree' mega-widget that I need to pass an option to it's
sub-widget? (At creation-time of that sub-widget, because that's the
only time you can set the nr. of columns)

Any clues? Anyone who can help? Are there any samples -- there's
supposed to be a 'Demo' directory but I can't find it in my (windows)
Python installation.

Cheers,

--Tim

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


Re: Detecting key presses

2006-06-19 Thread blue99

 Someone suggested using curses, but that does crazy things with my
 output, and leaves the terminal unusable after the program closes.

It's very good suggestion but you should use also initscr
and endwin functions.

Regards,
Rob

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


Re: [OT] code is data

2006-06-19 Thread bruno at modulix
Anton Vredegoor wrote:
 bruno at modulix wrote:
 
 I still don't get the point.
 
 
 Well, I've got to be careful here, lest I'd be associated with the
 terr.., eh, the childp..., eh the macro-enablers.
 
 The idea is to have a way to transform a Python (.py) module into XML
 and then do source code manipulations in XML-space using ElementTree.

My my my... I'm not against the idea of dynamic source code
transformation, but for heaven's sake, *why* would one put XML in the
mix ???


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comparing two arrays

2006-06-19 Thread Bas
You are comparing a normal python list to a constant, which are
obviously unequal. Try converting your lists to arrays first
(untested):

import numeric/numpy as N
a =N.array([0,1,2,5,6,6])
b = N.array([5,4,1,6,4,6])
print a==6 and b==6
print N.where(a==6 and b==6)

hth,
Bas



Sheldon wrote:
 Hi,

 I have two arrays that are identical and contain 1s and zeros. Only the
 ones are valid and I need to know where both arrays have ones in the
 same position. I thought logical_and would work but this example proves
 otherwise:
  a = [0,1,2,5,6,6]
  b = [5,4,1,6,4,6]
  Numeric.logical_and(a==6,b==6)
 0
  Numeric.where(a==b,1,0)
 0
  Numeric.where(a==6 and b==6,1,0)
 0

 The where() statement is also worhtless here. Does anyone have any
 suggestion on how to do this?
 
 Thanks in advance,
 Sheldon

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


Re: wxPython GUI designer

2006-06-19 Thread DarkBlue
Take a look at pythoncard , we use it to produce 
database frontends  , but apparently it also can be used
for simple graphics apps and others.
However if you are used to things like the Delphi IDE to build
a gui app , then prepare to shed lots of tears before 
overcoming the initial disbelieve, that there is nothing
better available for python.







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


Re: comparing two arrays

2006-06-19 Thread Diez B. Roggisch
Diez B. Roggisch wrote:

 print [i for i, _ in enumerate((None for v in zip(a, b) where v ==
 (1,1)))]
 
 should give you the list of indices.

I musunderstood your question. Use


print [i for i, _ in enumerate((None for x, y in zip(a, b) where x == y))]

instead.

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


Re: wxPython GUI designer

2006-06-19 Thread Luis M. González

[EMAIL PROTECTED] wrote:
 I am newbie learning wxPython. I tried using GUI designer called
 wxGlade. When it generated code I couldnt get the same level of
 flexibility as writing the code by oneself.

 Any view on what you think about using GUI designer tools.

 Every help is appreciated.


Try PythonCard.
It's based on wxPython, and it's more higher level than Boa.
Very simple and very easy to learn and use.

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


Re: mapping None values to ''

2006-06-19 Thread imho
Roberto Bonvallet ha scritto:
 imho [EMAIL PROTECTED]:
 map(lambda x: , [i for i in [a,b,c] if i in (None,None) ])
 
 You don't need map when using list comprehensions:
 
[ for i in [a, b, c] if i in (None, None)]
 

I know that... I tried to match the idiom used by the o.p. :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] code is data

2006-06-19 Thread Laurent Pointal
bruno at modulix a écrit :
 Anton Vredegoor wrote:
 bruno at modulix wrote:

 I still don't get the point.

 Well, I've got to be careful here, lest I'd be associated with the
 terr.., eh, the childp..., eh the macro-enablers.

 The idea is to have a way to transform a Python (.py) module into XML
 and then do source code manipulations in XML-space using ElementTree.
 
 My my my... I'm not against the idea of dynamic source code
 transformation, but for heaven's sake, *why* would one put XML in the
 mix ???

Because its à la mode, and is better for a commercial point of view,
even if inefficient for this problem.


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


Re: Amara installation

2006-06-19 Thread tjreedy

[EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 O/S WinXP Home
 Vsn of Python: 2.4

 Wish to install Amara.  Using amara-allinone-1.0.win32-py2.4.exe
 (2965KB)

 Forder structure before installation:

 c:
  python24
DLLs
Doc
Include
Lib
  site-packages
[previously installed stuff]
libs
scripts
tcl
tools

 When I run install, the install program indicates:

 Python directory: c:\python24\
 Installation directory: c:\python24\lib\site-packages\

 After install, folder structrue is:

 Vsn of Python: 2.4

 Wish to install Amara.  Using amara-allinone-1.0.win32-py2.4.exe
 (2965KB)

 Forder structure after installation:

 c:
  python24
DLLs
Doc
Include
Lib
  site-packages
[previously installed stuff]
libs
python24 --
  lib --
site-packages--  new amara files/folders appear
  amara   --  to be installed here
  ft   --
scripts--
share  --
scripts
tcl
tools

 I was expecting the new amara files/folders to be installed within the
 existing c:\python24\ folder structure...wasn't expecting it to create
 a new ...\python24\ folder within the parent ...\python24\ folder.

That is probably because you told it to, without knowing what exactly was 
being asked.  It looks like this installer was intended for someone who does 
not already have Python installed.  You might inquire as to whether there is 
one for people who do.

 My questions:
 1) has anyone else observed this when installing?
 2) should I move the newly installed files/folders into the
 previously-existing folder structure?  as long as I don't remove
 files/folders, is there any risk of causing a previously installed site
 package that worked to no longer work?

I don't think so.
As long as the installer did not register file locations, this should work. 
If there are any shortcuts or start menu entries, you will have  to edit.

tjr



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


Re: Just out of curiosity: Which languages are they using at Google and what for?

2006-06-19 Thread Alex Martelli
bruno at modulix [EMAIL PROTECTED] wrote:
...
 * Packaging.  Google has an internal packaging format like RPM.
 These packages are created using python.
 * Binary Data Pusher.  This is the area where Alex Martelli is
 working, on optimizing pushing bits between thousands of servers
 * Production servers.  All monitoring, restarting and data
 collection functionality is done with python

Yep, Greg did say that at SDForum, but in fact I'm working on a much
wider range of problems than just the datapush -- I lead Production
Systems, which includes parts of all of the above and yet more stuff
(account management, network verification, etc etc) -- done mostly in
Python, but with substantial helpers in C++ as well (not so much for CPU
efficiency reasons, as for keeping memory use under strict control when
necessary, the area where C/C++ really shines;-).


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


Re: Just out of curiosity: Which languages are they using at Google and what for?

2006-06-19 Thread Alex Martelli
[EMAIL PROTECTED] wrote:

 I know Google are using Python for testing purposes.

...and many more besides, as per the other response.

 But for the rest ?
 is it PHP or Java or .NET?
 Which technology is rendering the google main page?

I think you can get a reasonable idea by perusing the 800+ job offers we
currently have open;-), and eyeballing the several papers published by
Googlers -- between one and the other, it becomes pretty clear that we
use mostly Python, C++ and Java, plus of course a host of others for
special purposes (Javascript for AJAX purposes, C and Assembly for
kernel-hacking of various sort, SQL for relational databases, etc, etc),
including some highly specialized ones invented within Google for highly
specialized purposes (e.g., Rob Pike's sawzall for log-processing).


 And of course th obvious question, why not Python?

You can read Pike et al's paper on sawzall to see why we would want a
special-purpose language for that specialized, very-high-volume task,
for example; I hope the reason for the other specialized ones, from
Javascript to Assembly to SQL, is pretty obvious in each case;-).

As among the three big ones -- Python, C++, Java -- there are good
reasons why the overall job is best done by a mix of them.  I won't
address Java (we don't use any in my group, nor any of the groups we
interact with intensely), but the tradeoffs between Python and C++
should, again, be pretty clear.  For example, C++ allows (and demands)
close control of where all your memory is going -- much harder to
achieve in garbage collected languages such as Python or Java (managing
memory IS a chore, but, under potentially heavy load, an important one).

Also, a consideration I also made at SDForum: at Google's volumes of
traffic, we need load-balancing among many machines, of course, but we
_also_ are unwilling to let user experience suffer from high latencies.
Now, you can scale the bandwidth of a cluster by throwing more servers
at the problem -- but latency does not work the same way: you can't make
a baby in 1 month by load-balancing among 9 mothers, as the saying goes.
So, having as few machine-instructions as feasible on the critical paths
that determine the user-perceived latency is important; even the very
first paper by Page and Brin describing what would later become Google
made the point indirectly -- they describe the crawling (where latency
is no big deal) as being implemented in Python, but the processing of
queries (where latency is crucial) in C++.


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


Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Chris Smith
Torben Ægidius Mogensen [EMAIL PROTECTED] wrote:
 That's not really the difference between static and dynamic typing.
 Static typing means that there exist a typing at compile-time that
 guarantess against run-time type violations.  Dynamic typing means
 that such violations are detected at run-time.  This is orthogonal to
 strong versus weak typing, which is about whether such violations are
 detected at all.  The archetypal weakly typed language is machine code
 -- you can happily load a floating point value from memory, add it to
 a string pointer and jump to the resulting value.  ML and Scheme are
 both strongly typed, but one is statically typed and the other
 dynamically typed.

Knowing that it'll cause a lot of strenuous objection, I'll nevertheless 
interject my plea not to abuse the word type with a phrase like 
dynamically typed.  If anyone considers untyped to be perjorative, 
as some people apparently do, then I'll note that another common term is 
type-free, which is marketing-approved but doesn't carry the 
misleading connotations of dynamically typed.  We are quickly losing 
any rational meaning whatsoever to the word type, and that's quite a 
shame.

By way of extending the point, let me mention that there is no such 
thing as a universal class of things that are called run-time type 
violations.  At runtime, there is merely correct code and incorrect 
code.  To the extent that anything is called a type at runtime, this 
is a different usage of the word from the usage by which we may define 
languages as being statically typed (which means just typed).  In 
typed OO languages, this runtime usage is often called the class, for 
example, to distinguish it from type.

This cleaner terminology eliminates a lot of confusion.  For example, it 
clarifies that there is no binary division between strongly typed 
languages and weakly typed languages, since the division between a type 
error and any other kind of error is arbitrary, depending only on 
whether the type system in a particular language happens to catch that 
error.  For example, type systems have been defined to try to catch unit 
errors in scientific programming, or to catch out-of-bounds array 
indices... yet these are not commonly called type errors only because 
such systems are not in common use.

This also leads us to define something like language safety to 
encapsulate what we previously would have meant by the phrase strongly 
dynamically typed language.  This also is a more general concept than 
we had before.  Language safety refers to a language having well-defined 
behavior for as many operations as feasible, so that it's less likely 
that someone will do something spectacularly bad.  Language safety may 
be achieved either by a type system or by runtime checks.  Again, it's 
not absolute... I'm aware of no language that is completely determinate, 
at least if it supports any kind of concurrency.

This isn't just a matter of preference in terminology.  The definitions 
above (which are, in my experience, used widely by most non-academic 
language design discussions) actually limit our understanding of 
language design by pretending that certain delicate trade-offs such as 
the extent of the type system, or which language behavior is allowed to 
be non-deterministic or undefined, are etched in stone.  This is simply 
not so.  If types DON'T mean a compile-time method for proving the 
absence of certain program behaviors, then they don't mean anything at 
all.  Pretending that there's a distinction at runtime between type 
errors and other errors serves only to confuse things and 
artificially limit which problems we are willing to concieve as being 
solvable by types.

 Anyway, type inference for statically typed langauges don't make them
 any more dynamically typed.

Indeed it does not.  Unless it weakens the ability of a compiler to 
prove the absence of certain program behaviors (which type inference 
does not), it doesn't move anything on the scale toward a type-free 
language.

That being said, though, it is considered a feature of some programming 
languages that the programmer is asked to repeat type information in a 
few places.  The compiler may not need the information, but for 
precisely the reason that the information is redundant, the compiler is 
then able to check the consistency of the programmer in applying the 
type.  I won't get into precisely how useful this is, but it is 
nevertheless present as an advantage to outweigh the wordiness.

-- 
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
-- 
http://mail.python.org/mailman/listinfo/python-list


Installing Python on Windows Vista

2006-06-19 Thread Padraig
Hi all,

Just a quick question... when I try to install Python on Windows Vista
Beta 2 the installer seems to hang after I select the destination
folder, saying that it will return when it has finished calculating
disk space requirements. I just can't seem to get past that step. I've
also tried installing both 2.4.3 and 2.4.2 with no luck.

Any help would be very much appreciated.

Many thanks

P

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


Formatted string to object

2006-06-19 Thread janama
Hi,

can such a thing be done somehow?


aaa = self.aaa
bbb = %s.%s % ('parent', 'bbb')

Can you use strings or %s strings like in the above or

aaa = 'string'
aaa.%s() % 'upper'

Somehow?

Thanks for taking a look at this

Regards
Janama

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


Re: crawlers in python with graphing?

2006-06-19 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], bryan rasmussen
wrote:

 It should hopefully be as high level as Wget, not download the pages
 but just follow the links, and output graphs.

How do you get at the links without downloading the page!?

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


Re: memory-leak in pysqlite 2.3.0 ?

2006-06-19 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Michael Husmann
wrote:

 After upgrading from pysqlite 2.0.5 to pysqlite 2.3.0 writing into a
 sqlite database increases memory consumption heavily. […]
 
 Here a short example:
 ---
 #!/usr/bin/env python
 
 import os
 from pysqlite2 import dbapi2
 print dbapi2.version
 
 db = dbapi2.connect(bla.db)
 c = db.cursor()
 
 c.execute(create table b (c integer))
 
 for i in xrange(1000):
 c.execute(insert into b values (%d) % i)

Just a guess: Commit the changes from time to time.

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

Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Rob Thorpe
Chris Smith wrote:
 Torben Ægidius Mogensen [EMAIL PROTECTED] wrote:
  That's not really the difference between static and dynamic typing.
  Static typing means that there exist a typing at compile-time that
  guarantess against run-time type violations.  Dynamic typing means
  that such violations are detected at run-time.  This is orthogonal to
  strong versus weak typing, which is about whether such violations are
  detected at all.  The archetypal weakly typed language is machine code
  -- you can happily load a floating point value from memory, add it to
  a string pointer and jump to the resulting value.  ML and Scheme are
  both strongly typed, but one is statically typed and the other
  dynamically typed.

 Knowing that it'll cause a lot of strenuous objection, I'll nevertheless
 interject my plea not to abuse the word type with a phrase like
 dynamically typed.  If anyone considers untyped to be perjorative,
 as some people apparently do, then I'll note that another common term is
 type-free, which is marketing-approved but doesn't carry the
 misleading connotations of dynamically typed.  We are quickly losing
 any rational meaning whatsoever to the word type, and that's quite a
 shame.

I don't think dynamic typing is that nebulous.  I remember this being
discussed elsewhere some time ago, I'll post the same reply I did then
..


A language is statically typed if a variable has a property - called
it's type - attached to it, and given it's type it can only represent
values defined by a certain class.

A language is latently typed if a value has a property - called it's
type - attached to it, and given it's type it can only represent values
defined by a certain class.

Some people use dynamic typing as a word for latent typing, others use
it to mean something slightly different.  But for most purposes the
definition above works for dynamic typing also.

Untyped and type-free mean something else: they mean no type checking
is done.

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


Re: [OT] code is data

2006-06-19 Thread Fredrik Lundh
Laurent Pointal wrote:

 The idea is to have a way to transform a Python (.py) module into XML
 and then do source code manipulations in XML-space using ElementTree.
 
 My my my... I'm not against the idea of dynamic source code
 transformation, but for heaven's sake, *why* would one put XML in the
 mix ???

because lots of people know how to describe XML transformations, and 
there are plenty of tools that implement such transformations efficiently ?

 Because its à la mode, and is better for a commercial point of view,
 even if inefficient for this problem.

why would XML be inefficient ?

/F

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


Re: pyfcp

2006-06-19 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], aum wrote:

 On Mon, 19 Jun 2006 14:45:19 +0800, Thomas Moore wrote:
 
  http://www.python.org/pyfcp
 
 
 It gets me to Error 404.
 
 Apologies - that URL should have been:
 
 http://www.python.org.nz/pyfcp

I get: Unknown host www.python.org.nz

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


Re: Installing Python on Windows Vista

2006-06-19 Thread [EMAIL PROTECTED]

Padraig wrote:
 Hi all,

 Just a quick question... when I try to install Python on Windows Vista
 Beta 2 the installer seems to hang after I select the destination
 folder, saying that it will return when it has finished calculating
 disk space requirements. I just can't seem to get past that step. I've
 also tried installing both 2.4.3 and 2.4.2 with no luck.

 Any help would be very much appreciated.

 Many thanks

 P

I've heard that Windows Vista has many restrictions on reading/writing
to the disk, perhaps you do not have an admin account?

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


Re: Which compiler will Python 2.5 / Windows (Intel) be built with?

2006-06-19 Thread meyer
Roel Schroeven wrote:
 [EMAIL PROTECTED] schreef:
  * The code created by the Windows GCC is not as good as the one created
  by the Microsoft compiler

 Isn't Python for other platforms built with GCC? Seems to me that if it
 GCC is good enough for other platforms, it's good enough for Windows.

Actually, GCC on Linux does provide worse machine code than say, the
Intel compiler for Linux. This is not a bug of GCC, but a feature,
because GCC was created for maximum portability and flexibility, not
for maximum performance on one single platform like the Intel compiler.
But GCC is truly free and can be distributed easily (because it's GPL),
so it is the default compiler for most (if not all) distros at the
moment. Also, there are many free software programs that use special
features of GCC and cannot be compiled using another compiler.

Of course I do acknowledge that often in the real world the IO forms
the bottleneck of a system and the efficiency of the machine code is
somewhat neglegible (other posters pointed that out already).


Markus

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


Re: comparing two arrays

2006-06-19 Thread Robert Kern
Bas wrote:
 You are comparing a normal python list to a constant, which are
 obviously unequal. Try converting your lists to arrays first
 (untested):
 
 import numeric/numpy as N
 a =N.array([0,1,2,5,6,6])
 b = N.array([5,4,1,6,4,6])
 print a==6 and b==6
 print N.where(a==6 and b==6)

Careful there. The and keyword cannot be overloaded and so neither Numeric nor
numpy does. Either N.logical_and() should be used or (since the results of a==6
and b==6 are known to be boolean arrays) the  operator works fine as well.


In [9]: import numpy as np

In [10]: a = np.array([0,1,2,5,6,6])

In [11]: b = np.array([5,4,1,6,4,6])

In [12]: (a==6)  (b==6)
Out[12]: array([False, False, False, False, False, True], dtype=bool)

In [13]: np.where((a==6)  (b==6))
Out[13]: (array([5]),)


The OP may also find that numpy questions are best handled on numpy-discussion
rather than comp.lang.python .

  https://lists.sourceforge.net/lists/listinfo/numpy-discussion

-- 
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: Installing Python on Windows Vista

2006-06-19 Thread Padraig

[EMAIL PROTECTED] wrote:
 Padraig wrote:
  Hi all,
 
  Just a quick question... when I try to install Python on Windows Vista
  Beta 2 the installer seems to hang after I select the destination
  folder, saying that it will return when it has finished calculating
  disk space requirements. I just can't seem to get past that step. I've
  also tried installing both 2.4.3 and 2.4.2 with no luck.
 
  Any help would be very much appreciated.
 
  Many thanks
 
  P

 I've heard that Windows Vista has many restrictions on reading/writing
 to the disk, perhaps you do not have an admin account?

I don't think there is such a thing as an admin account under vista but
I'm sure that the account I'm using is the Vista-equivalent of an admin
account. Perhaps running it in compatibility mode might help. Will try
that this evening... Thanks

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


Re: pyfcp

2006-06-19 Thread Fredrik Lundh
Marc 'BlackJack' Rintsch wrote:

 http://www.python.org.nz/pyfcp
 
 I get: Unknown host www.python.org.nz

for future announcements, I'd recommend using:

 http://www.google.com/search?q=pyfcp

/F

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


Re: [pysqlite] memory-leak in pysqlite 2.3.0 ?

2006-06-19 Thread Gerhard Häring
Michael Husmann wrote:
 Michael Husmann wrote:
 After upgrading from pysqlite 2.0.5 to pysqlite 2.3.0 writing into a
 sqlite database increases memory consumption heavily. A similar program
 with Ruby and sqlite-ruby 1.1.0 does not affect memory consumption at
 all.
 [...]
 Python 2.4.1, Sqlite3 3.3.6, Pysqlite 2.3.0
 You never COMMIT your changes here, that's probably what's causing
 memory consumption on the SQLite side of things.
 [...]
 
 I also tried that commit(). Memory consumption still grows permanently.

Thanks for the report. Upon debugging this a little, there's indeed a 
bug which crept in in pysqlite 2.2.1 because of incorrect usage of the 
weak references (*). This leads to the list of weak references per 
connection to always grow and never shrink. I'll try to provide a fix 
real soon.

-- Gerhard

(*) A missing PyWeakref_GetObject(), but I'll have to take a more 
careful look.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formatted string to object

2006-06-19 Thread Tim Chase
 Can you use strings or %s strings like in the above or
 
 aaa = 'string'
 aaa.%s() % 'upper'
 
 Somehow?

Looks like you want to play with the eval() function.

  aaa = 'hello'
  result = eval(aaa.%s() % 'upper')
  result
'HELLO'

Works for your second example.  May work on your first example too.

-tkc



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


Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Pascal Costanza
Chris Smith wrote:
 Torben Ægidius Mogensen [EMAIL PROTECTED] wrote:
 That's not really the difference between static and dynamic typing.
 Static typing means that there exist a typing at compile-time that
 guarantess against run-time type violations.  Dynamic typing means
 that such violations are detected at run-time.  This is orthogonal to
 strong versus weak typing, which is about whether such violations are
 detected at all.  The archetypal weakly typed language is machine code
 -- you can happily load a floating point value from memory, add it to
 a string pointer and jump to the resulting value.  ML and Scheme are
 both strongly typed, but one is statically typed and the other
 dynamically typed.
 
 Knowing that it'll cause a lot of strenuous objection, I'll nevertheless 
 interject my plea not to abuse the word type with a phrase like 
 dynamically typed.  If anyone considers untyped to be perjorative, 
 as some people apparently do, then I'll note that another common term is 
 type-free, which is marketing-approved but doesn't carry the 
 misleading connotations of dynamically typed.  We are quickly losing 
 any rational meaning whatsoever to the word type, and that's quite a 
 shame.

The words untyped or type-free only make sense in a purely 
statically typed setting. In a dynamically typed setting, they are 
meaningless, in the sense that there are _of course_ types that the 
runtime system respects.

Types can be represented at runtime via type tags. You could insist on 
using the term dynamically tagged languages, but this wouldn't change 
a lot. Exactly _because_ it doesn't make sense in a statically typed 
setting, the term dynamically typed language is good enough to 
communicate what we are talking about - i.e. not (static) typing.

 By way of extending the point, let me mention that there is no such 
 thing as a universal class of things that are called run-time type 
 violations.  At runtime, there is merely correct code and incorrect 
 code.

No, there is more: There is safe and unsafe code (i.e., code that throws 
exceptions or that potentially just does random things). There are also 
runtime systems where you have the chance to fix the reason that caused 
the exception and continue to run your program. The latter play very 
well with dynamic types / type tags.

 To the extent that anything is called a type at runtime, this 
 is a different usage of the word from the usage by which we may define 
 languages as being statically typed (which means just typed).  In 
 typed OO languages, this runtime usage is often called the class, for 
 example, to distinguish it from type.

What type of person are you to tell other people what terminology to use? ;)

Ha! Here I used type in just another sense of the word. ;)

It is important to know the context in which you are discussing things. 
For example, we Common Lispers use the term type as defined in 
http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_t.htm . You 
cannot possibly argue that our use of the word type is incorrect 
because in our context, when we talk about Common Lisp, the use of the 
word type better be consistent with that definition. (You can say that 
you don't like the definition, that it is unsound, or whatever, but that 
doesn't change anything here.)

 This cleaner terminology eliminates a lot of confusion.  For example, it 
 clarifies that there is no binary division between strongly typed 
 languages and weakly typed languages, since the division between a type 
 error and any other kind of error is arbitrary, depending only on 
 whether the type system in a particular language happens to catch that 
 error.  For example, type systems have been defined to try to catch unit 
 errors in scientific programming, or to catch out-of-bounds array 
 indices... yet these are not commonly called type errors only because 
 such systems are not in common use.

What type system catches division by zero? That is, statically? Would 
you like to program in such a language?

 This isn't just a matter of preference in terminology.  The definitions 
 above (which are, in my experience, used widely by most non-academic 
 language design discussions) actually limit our understanding of 
 language design by pretending that certain delicate trade-offs such as 
 the extent of the type system, or which language behavior is allowed to 
 be non-deterministic or undefined, are etched in stone.  This is simply 
 not so.  If types DON'T mean a compile-time method for proving the 
 absence of certain program behaviors, then they don't mean anything at 
 all.  Pretending that there's a distinction at runtime between type 
 errors and other errors serves only to confuse things and 
 artificially limit which problems we are willing to concieve as being 
 solvable by types.

Your problem doesn't exist. Just say types when you're amongst your 
own folks, and static types when you're amongst a broader audience, 
and everything's fine. Instead 

Re: code is data

2006-06-19 Thread Kay Schluehr

Ravi Teja wrote:

 People have however written various language interpreters (Scheme,
 Forth and yes, even Basic) in Python, just for kicks. Still does not
 make it a DSL language anymore than it makes C a DSL language.

 At present, the closest thing to writing a DSL in Python is Logix
 http://livelogix.net/logix/
 Too bad though, the project is defunct and there has never been enough
 interest in it.

You might be interested in EasyExtend:

http://www.fiber-space.de/EasyExtend/doc/EE.html

Unlike Logix there are no macros defined in application code and there
are no runtime macro expansions. So extension language semantics is
always fixed at compile time.

 Personally, I would like to see macros in Python (actually Logix
 succeeding is good enough). But I am no language designer and the
 community has no interest in it. When I absolutely need macros, I will
 go elsewhere.

Although Logix was written in Python and compiled to CPython bytecodes
it was a language on its own right: a Python / Lisp hybrid. Opposed to
this EasyExtend is a Python framework for language extensions and not
itself a language. A quite typical use case may not involve any new
grammar rules or terminals, but just generates code. See the coverage
fiber as an example.

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


Re: transfer rate limiting in socket.py

2006-06-19 Thread Peter Silva

I looked at twisted briefly.  It looks like it is server oriented.
Does it work in for clients initiating connections?


Jean-Paul Calderone wrote:
 On 16 Jun 2006 13:53:48 -0700, Peter Silva [EMAIL PROTECTED] wrote:
 Hi folks,
 
 I have a need in a network data distribution application to send out
 data to folks who want it using the protocol of their choice.   I´d
 like it to support a variety of protocols and I don´t want to
 implement any of them :-)
 http, ftp (via ftplib) , https (dunno how yet), ssl, ssh, sftp (via
 paramiko)
 
 The thing is... I want rate-limiting so that in the case of a failure
 of a single client
 I don´t penalize the other clients, or if my server (which is acting
 as a client pushing to remote servers.) goes down, it doesn´t saturate
 the link when it comes back.
 
 So I want to have all the protocols limit the number of bytes they send
 per second.
 It looks like the easiest way to do this is to dive into socket.py...
 and look! it says:
 
 # Wrapper module for _socket, providing some additional facilities
 # implemented in Python.
 
 note the ´additional facilities implemented in python´ ...
 
 so we just add logic to:
 -- add a ´maxrate´ argument to the constructor and/or an attribute to
 modify the setting...
 --  tally bytes, and time, and know when we are going ´too fast´
 --  when too fast..  in the ´flush´ routine, in the synchronous case,
 sleep for the correct time to come back under budget.  in the async,
 return without writing.
  -- do something similar for reading.
 
  Anybody think this would be fun?

 Use Twisted instead.  It supports every protocol you mentioned, and
 rate limiting too.
 
 Jean-Paul

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


multithreading windows and embedding python

2006-06-19 Thread freesteel
I have posted about this problem before. SInce then I found a much
better article to help with embedding python in a multithreaded
application:

http://www.linuxjournal.com/article/3641

I found this article very good and it clarified for me what needs
doing. Now I have an example application that almost works, but it is
far from reliable. If I run this several times I get crashes telling me
that the heap is modified after deallocation. Can anybody else
reproduce this?

At the bottom of this file I left a debug dump, and a stack dump.

Here is my application, compile in windows using a standard windows
application project.




#include afxmt.h
#include afxwin.h
#include stdio.h
#include Python.h
#include Windows.h
#include process.h

static int threadnum = 0;




UINT MyThread(LPVOID lpParam)
{
ASSERT(Py_IsInitialized());
threadnum++;


PyThreadState* mainThreadState = (PyThreadState *)lpParam;

// get the global lock
PyEval_AcquireLock();
// get a reference to the PyInterpreterState
PyInterpreterState * mainInterpreterState = mainThreadState-interp;
PyThreadState_Swap(mainThreadState);

// create a thread state object for this thread
PyThreadState * myThreadState =
PyThreadState_New(mainInterpreterState);
// free the lock
PyEval_ReleaseLock();


// lock - swap in thread state - swap out thread state - unlock
PyEval_AcquireLock();
PyThreadState_Swap(myThreadState);

int num = 0;
int ret = 0;
ret = PyRun_SimpleString(x = []);
ret = PyRun_SimpleString(for i in range(10):\n  x.append(i));
char cmd[100];
sprintf(cmd, f = open('c:/windows/temp/test%d.txt', 'w'),
threadnum);
ret = PyRun_SimpleString(cmd);
ret = PyRun_SimpleString(f.write('%s\\n' % x.__str__()));
sprintf(cmd, f.write('0x%d\\n'), myThreadState);
ret = PyRun_SimpleString(cmd);
ret = PyRun_SimpleString(f.close());

PyThreadState_Swap(NULL);
PyEval_ReleaseLock();


// clean up
// grab the lock
PyEval_AcquireLock();
// swap my thread state out of the interpreter
PyThreadState_Swap(NULL);
// clear out any cruft from thread state object
PyThreadState_Clear(myThreadState);
// delete my thread state object
PyThreadState_Delete(myThreadState);
// release the lock
PyEval_ReleaseLock();

return 0;
}

class CMyWinApp : public CWinApp
{
public:
CMyWinApp() { }
BOOL InitInstance()
{
Py_Initialize();
PyEval_InitThreads();

// save a pointer to the main PyThreadState object
PyThreadState * mainThreadState = PyThreadState_Get();
// release the lock
PyEval_ReleaseLock();

const int nhandles = 100;
HANDLE hnd[nhandles];
CWinThread* pThread[nhandles];
for (int ih = 0; ih  nhandles; ih++)
{
pThread[ih] = AfxBeginThread(MyThread, mainThreadState,
THREAD_PRIORITY_NORMAL, CREATE_SUSPENDED);
pThread[ih]-m_bAutoDelete = false;
pThread[ih]-ResumeThread();

hnd[ih] = pThread[ih]-m_hThread;
}

int nwaits, nfails;
do
{
nwaits = 0;
nfails = 0;
for (int ih = 0; ih  nhandles; ih++)
{
DWORD ret = WaitForSingleObject(hnd[ih], 
INFINITE);
switch (ret)
{
case WAIT_OBJECT_0:
printf(WAIT_OBJECT_0\n);
break;

case WAIT_TIMEOUT:
++nwaits;
printf(WAIT_TIMEOUT\n);
break;

case WAIT_FAILED:
++nfails;
printf(WAIT_FAILED\n);
break;
}
}
}
while (nwaits  0);
ASSERT(nfails == 0);

// delete all windows threads
for (int ih = 0; ih  nhandles; ++ih)
delete pThread[ih];

PyEval_AcquireLock();
PyThreadState_Swap(mainThreadState);
Py_Finalize();

return TRUE;
};
};

CMyWinApp app;




Debug dump:

'pyembed_test.exe': Loaded

Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Chris Smith
Rob Thorpe [EMAIL PROTECTED] wrote:
 A language is latently typed if a value has a property - called it's
 type - attached to it, and given it's type it can only represent values
 defined by a certain class.

I'm assuming you mean class in the general sense, rather than in the 
sense of a specific construct of some subset of OO programming 
languages.

Now I define a class of values called correct values.  I define these 
to be those values for which my program will produce acceptable results.  
Clearly there is a defined class of such values: (1) they are 
immediately defined by the program's specification for those lines of 
code that produce output; (2) if they are defined for the values that 
result from any expression, then they are defined for the values that 
are used by that expression; and (3) for any value for which correctness 
is not defined by (1) or (2), we may define its correct values as the 
class of all possible values.  Now, by your definition, any language 
which provides checking of that property of correctness for values is 
latently typed.  Of course, there are no languages that assign this 
specific class of values; but ANY kind of correctness checking on values 
that a language does (if it's useful at all) is a subset of the perfect 
correctness checking system above.  Apparently, we should call all such 
systems latent type systems.  Can you point out a language that is not 
latently typed?

I'm not trying to poke holes in your definition for fun.  I am proposing 
that there is no fundamental distinction between the kinds of problems 
that are type problems and those that are not.  Types are not a class 
of problems; they are a class of solutions.  Languages that solve 
problems in ways that don't assign types to variables are not typed 
languages, even if those same problems may have been originally solved 
by type systems.

 Untyped and type-free mean something else: they mean no type checking
 is done.

Hence, they don't exist, and the definitions being used here are rather 
pointless.

-- 
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formatted string to object

2006-06-19 Thread bruno at modulix
Tim Chase wrote:
 Can you use strings or %s strings like in the above or

 aaa = 'string'
 aaa.%s() % 'upper'

 Somehow?
 
 
 Looks like you want to play with the eval() function.
 
 aaa = 'hello'
 result = eval(aaa.%s() % 'upper')
 result
 'HELLO'

Using eval() or exec should be really avoided whenever possible IMHO.
This one is best done with getattr(obj, attribute_name [,default]), ie:

 aaa = string
 getattr(aaa, 'upper')()
'STRING'



-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting output from external programs...

2006-06-19 Thread Ten
On Monday 19 June 2006 03:44, Cameron Laird wrote:
 In article [EMAIL PROTECTED],
 Ten  [EMAIL PROTECTED] wrote:

 You can do this in various ways, ranging from the very simple and not very
  good
 
 from commands import getoutput
 
 x=getoutput(command)
 
 
 - to your more common and better popens.
 
 ie:
 
 import popen2
 
 (stdOut, stdIn) = popen2.popen4(command)
 
 x=stdOut.readlines()
 
 - asynchronously if appropriate.
 
 How are you running the command at the moment?

   .
   .
   .
 Why deprecate commands.getoutput()?  Are you merely
 observing that it's applicable in fewer circumstances?

Absolutely so.

Commands.getoutput is simple, quick and useful, just less versatile. Maybe 
not very good is a pretty vague, almost emotive-sounding way of putting it. 
My bad. :-)

Cheers,

Ten

-- 
There are 10 types of people in this world,
those who understand binary, and those who don't.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which compiler will Python 2.5 / Windows (Intel) be built with?

2006-06-19 Thread Scott David Daniels
[EMAIL PROTECTED] wrote:
   Also, there are many free software programs that use special
 features of GCC and cannot be compiled using another compiler.
This is precisely what bothers me about standardizing on GCC --
lock-in is lock-in whether you must pay cash or not.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formatted string to object

2006-06-19 Thread Steven Bethard
janama wrote:
 can such a thing be done somehow?
 
 aaa = self.aaa
 bbb = %s.%s % ('parent', 'bbb')
 
 Can you use strings or %s strings like in the above or
 
 aaa = 'string'
 aaa.%s() % 'upper'

Use the getattr() function::

  class parent(object):
 ... class bbb(object):
 ... pass
 ...
  module_ns = __import__(__name__)
  getattr(getattr(module_ns, 'parent'), 'bbb')
 class '__main__.bbb'
  import string
  getattr(getattr(module_ns, 'string'), 'upper')
 function upper at 0x00B502B0

I've imported the module itself here so you can use getattr, but you 
could also use globals() instead of the inner getattr() call::

  getattr(globals()['parent'], 'bbb')
 class '__main__.bbb'
  getattr(globals()['string'], 'upper')
 function upper at 0x00B502B0

HTH,

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


Re: Formatted string to object

2006-06-19 Thread bruno at modulix
janama wrote:
 Hi,
 
 can such a thing be done somehow?
 
 
 aaa = self.aaa
 bbb = %s.%s % ('parent', 'bbb')

Given the first line, I assume this is inside a method body, and parent
is a local var. Then the answer is:

bbb = getattr(locals()['parent'], 'bbb')

read the doc for these two functions to get more infos.

 Can you use strings or %s strings like in the above or
 
 aaa = 'string'
 aaa.%s() % 'upper'
 
 Somehow?

Not directly - but here again, getattr() is your friend.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-19 Thread George Neuner
On 19 Jun 2006 13:53:01 +0200, [EMAIL PROTECTED] (Torben Ægidius
Mogensen) wrote:

George Neuner gneuner2/@comcast.net writes:

 On 19 Jun 2006 10:19:05 +0200, [EMAIL PROTECTED] (Torben Ægidius
 Mogensen) wrote:

 I expect a lot of the exploration you do with incomplete programs
 amount to the feedback you get from type inference.
 
 The ability to write functions and test them immediately without
 writing a lot of supporting code is _far_ more useful to me than type
 inference.  

I can't see what this has to do with static/dynamic typing.  You can
test individul functions in isolation is statically typed languages
too.

It has nothing to do with static/dynamic typing and that was the point
... that support for exploratory programming is orthogonal to the
language's typing scheme.

George
--
for email reply remove / from address
-- 
http://mail.python.org/mailman/listinfo/python-list


Pydev 1.2.0 Released

2006-06-19 Thread Fabio Zadrozny
Hi All,  Pydev and Pydev Extensions 1.2.0 have been released  Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: 
http://pydev.sf.net  Details on its development: http://pydev.blogspot.com  Release Highlights in Pydev Extensions: -
 - This is the first version supporting Eclipse 3.2.
- Interactive console: content is now changed so that blocks are closed
with the interactive interpreter 'rules' (so that you don't have
invalid syntax errors when passing code-blocks to the interactive
console).
- An action was added to the menu so that you can use the Open
Declaration Quick-outline without needing focus on the pydev editor.
 Release Highlights in Pydev: -- - Eclipse 3.2 supported (and 3.1 support is now discontinued)
- Lot's of optimizations to make pydev faster
- Ctrl+Click now works with the find definition engine
- Comments that start with #--- are shown in the outline
- Attributes are shown in the outline
- Parse errors are now shown (again) in the editor
- Many other bugs fixed   What is PyDev? --- 
PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.   Cheers,  --  Fabio Zadrozny -- Software Developer  ESSS - Engineering Simulation and Scientific Software
 http://www.esss.com.br  Pydev Extensions http://www.fabioz.com/pydev  Pydev - Python Development Enviroment for Eclipse
 http://pydev.sf.net http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Chris Smith
Pascal Costanza [EMAIL PROTECTED] wrote:
 Types can be represented at runtime via type tags. You could insist on 
 using the term dynamically tagged languages, but this wouldn't change 
 a lot. Exactly _because_ it doesn't make sense in a statically typed 
 setting, the term dynamically typed language is good enough to 
 communicate what we are talking about - i.e. not (static) typing.

Okay, fair enough.  It's certainly possible to use the same sequence of 
letters to mean two different things in different contexts.  The problem 
arises, then, when Torben writes:

: That's not really the difference between static and dynamic typing.
: Static typing means that there exist a typing at compile-time that
: guarantess against run-time type violations.  Dynamic typing means
: that such violations are detected at run-time.

This is clearly not using the word type to mean two different things 
in different contexts.  Rather, it is speaking under the mistaken 
impression that static typing and dynamic typing are varieties of 
some general thing called typing.  In fact, the phrase dynamically 
typed was invented to do precisely that.  My argument is not really 
with LISP programmers talking about types, by which they would mean 
approximately the same thing Java programmers mean by class.  My point 
here concerns the confusion that results from the conception that there 
is this binary distinction (or continuum, or any other simple 
relationship) between a statically typed and a dynamically typed 
language.

Torben's (and I don't mean to single out Torben -- the terminology is 
used quite widely) classification of dynamic versus static type systems 
depends on the misconception that there is some universal definition to 
the term type error or type violation and that the only question is 
how we address these well-defined things.  It's that misconception that 
I aim to challenge.

 No, there is more: There is safe and unsafe code (i.e., code that throws 
 exceptions or that potentially just does random things). There are also 
 runtime systems where you have the chance to fix the reason that caused 
 the exception and continue to run your program. The latter play very 
 well with dynamic types / type tags.

Yes, I was oversimplifying.

 What type system catches division by zero? That is, statically?

I can define such a type system trivially.  To do so, I simply define a 
type for integers, Z, and a subtype for non-zero integers, Z'.  I then 
define the language such that division is only possible in an expression 
that looks like  z / z' , where z has type Z and z' has type Z'.  
The language may then contain an expression:

  z 0? t1 : t2

in which t1 is evaluated in the parent type environment, but t2 is 
evaluated in the type environment augmented by (z - Z'), the type of 
the expression is the intersection type of t1 and t2 evaluated in those 
type environments, and the evaluation rules are defined as you probably 
expect.

 Would you like to program in such a language?

No.  Type systems for real programming languages are, of course, a 
balance between rigor and usability.  This particular set of type rules 
doesn't seem to exhibit a good balance.  Perhaps there is a way to 
achieve it in a way that is more workable, but it's not immediately 
obvious.

As another example, from Pierce's text Types and Programming 
Languages, Pierce writes: Static elimination of array-bounds checking 
is a long-standing goal for type system designers.  In principle, the 
necessary mechanisms (based on dependent types) are well understood, but 
packaging them in a form that balances expressive power, predictability 
and tractability of typechecking, and complexity of program annotations 
remains a significant challenge.  Again, this could quite validly be 
described as a type error, just like division by zero or ANY other 
program error... it's just that the type system that solves it doesn't 
look appealing, so everyone punts the job to runtime checks (or, in some 
cases, to the CPU's memory protection features and/or the user's ability 
to fix resulting data corruption).

Why aren't these things commonly considered type errors?  There is only 
one reason: there exists no widely used language which solves them with 
types.  (I mean in the programming language type theory sense of type; 
since many languages tag arrays with annotations indicating their 
dimensions, I guess you could say that we do solve them with types in 
the LISP sense).

 Your problem doesn't exist. Just say types when you're amongst your 
 own folks, and static types when you're amongst a broader audience, 
 and everything's fine.

I think I've explained why that's not the case.  I don't have a 
complaint about anyone speaking of types.  It's the confusion from 
pretending that the two definitions are comparable that I'm pointing 
out.

-- 
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
-- 

operator comparison for php vs python

2006-06-19 Thread brandon.mcginty








Hi All,

Ive already done a large amount of searching on Google
to find out this information, but to no avale.

Does anyone here know of a list of operators in python and there
counterparts in php, or a website with this information?

It would also be helpful to have this information along with
perls syntax.

Im going to be trying to port some php and perl stuff
to python, and this information would be extremely useful, rather than going through
all the documentation and reinventing the wheel.

Thanks,





--

Brandon McGinty

Email:b[EMAIL PROTECTED]
Skype:brandon.mcginty
Msn:[EMAIL PROTECTED]
Aim:brandonmcginty0 (Not currently available.)
Cell:4802025790 (Weekends and nights only, please.)
Languages:python, php, autoit; Currently Learning:perl

Kindness is a language that the deaf can hear and the
blind can see.
Mark Twain








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

Re: Installing Python on Windows Vista

2006-06-19 Thread Padraig

[EMAIL PROTECTED] wrote:
 Padraig wrote:
  Hi all,
 
  Just a quick question... when I try to install Python on Windows Vista
  Beta 2 the installer seems to hang after I select the destination
  folder, saying that it will return when it has finished calculating
  disk space requirements. I just can't seem to get past that step. I've
  also tried installing both 2.4.3 and 2.4.2 with no luck.
 
  Any help would be very much appreciated.
 
  Many thanks
 
  P

 I've heard that Windows Vista has many restrictions on reading/writing
 to the disk, perhaps you do not have an admin account?

I've managed to install it by using the msiexec command to manipulate
windows installer directly. Running the installer in any mode that
requires user input makes the installer hang when you choose the
installation dir.

I did an automated install with the following command:

msiexec /i python-2.4.3.msi TARGETDIR=C:\Program Files\Python24
ALLUSERS=1 /qb

The '/qb' only displays a progress bar and cancel button. This seems to
bypass the installer problem. Wierd! I was going to try compatibility
mode but it doesn't work for msi packages.

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


Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Matthias Blume
George Neuner gneuner2/@comcast.net writes:

  I am, however, going to ask what
 information you think type inference can provide that substitutes for
 algorithm or data structure exploration.

Nobody wants to do such a substitution, of course.  In /my/
experience, however, I find that doing algorithm and data structure
exploration is greatly aided by a language with static types and type
inference.  YMMV.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python with Eclipse

2006-06-19 Thread Philippe Martin
Dennis Benzinger wrote:

 Stan Cook wrote:
 I've been trying to use Eclipse with Python on Linux for a while and
 have noticed something odd.  After running the code or debugging a few
 times, its responsiveness gets really bad.  Upon checking the equivalent
 of the task manager, I find several instances of Python running.  When I
 kill these instances, the responsiveness comes back.  I'm not sure if
 there is a better place to post this, but it is Python related.  Is this
 just an issue with Eclipse or is there something else I should inspect?
 
 Any help would be appreciated.
 
 Regards,
 
 S Cook
 
 Which Python plugin are you using? PyDev?
 
 
 Bye,
 Dennis

Hi,

What other plugins are there ?

Regards,

Philippe

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


Re: [OT] code is data

2006-06-19 Thread bruno at modulix
Fredrik Lundh wrote:
 Laurent Pointal wrote:

 Bruno Desthuilliers wrote:
 Anton Vredegoor wrote:

 The idea is to have a way to transform a Python (.py) module into XML
 and then do source code manipulations in XML-space using ElementTree.
 

 
 My my my... I'm not against the idea of dynamic source code
 transformation, but for heaven's sake, *why* would one put XML in the
 mix ???
 
 
 because lots of people know how to describe XML transformations, and
 there are plenty of tools that implement such transformations efficiently ?

Efficiently enough for dynamic (runtime) use ?

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Yet Another Dan
Chris Smith [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 Rob Thorpe [EMAIL PROTECTED] wrote:
 A language is latently typed if a value has a property - called it's
 type - attached to it, and given it's type it can only represent
 values defined by a certain class.
 
 Now I define a class of values called correct values.  I define
 these to be those values for which my program will produce acceptable
 results.  Clearly there is a defined class of such values: (1) they
 are immediately defined by the program's specification for those lines
 of code that produce output; ...

 I'm not trying to poke holes in your definition for fun.  I am
 proposing that there is no fundamental distinction between the kinds
 of problems that are type problems and those that are not.

That sounds like a lot to demand of a type system. It almost sounds like 
it's supposed to test and debug the whole program. In general, defining the 
exact set of values for a given variable that generate acceptable output 
from your program will require detailed knowledge of the program and all 
its possible inputs. That goes beyond simple typing. It sounds more like 
contracts. Requiring an array index to be an integer is considered a typing 
problem because it can be checked based on only the variable itself, 
whereas checking whether it's in bounds requires knowledge about the array.

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


Re: Need Help comparing dates

2006-06-19 Thread colincolehour
I kept getting a Python error for the following line:

month = m[webMonth]


I changed it to month = month_numbers[webMonth]

and that did the trick.


Tim Chase wrote:
  I am new to Python and am working on my first program. I am trying to
  compare a date I found on a website to todays date. The problem I have
  is the website only shows 3 letter month name and the date.
  Example: Jun 15

 No year, right?  Are you making the assumption that the year is
 the current year?

  How would I go about comparing that to a different date?

 Once you've got them as dates,

   from datetime import date

 you can just compare them as you would any other comparable items.

 If you need to map the month-strings back into actual dates, you
 can use this dictionary:

   month_numbers = dict([(date(2006, m, 1).strftime(%b), m)
 for m in range(1,13)])

 It happens to be locale specific, so you might have to tinker a
 bit if you're mapping comes out differently from what the website
 uses.  I also made the assumption the case was the same (rather
 than trying to normalize to upper/lower case)

 Then, you can use

   webpageDateString = Mar 21
   webMonth, webDay = webpageDateString.split()
   month = m[webMonth]
   day = int(webDay)
   webpageDate = date(date.today().year, month, day)
   compareDate = date.today()
   compareDate  webpageDate
 False
   compareDate  webpageDate
 True

 You can wrap the load in a function, something like

   def isNewer(dateString, year = date.today().year):
 ... monthString, dayString = dateString.split()
 ... month = month_numbers[monthString]
 ... day = int(dayString)
 ... return date.today()  date(year, month, day)

 which will allow you to do

   isNewer(Jul 1)
 True
   isNewer(Apr 1)
 False

 and the like.
 
 There's plenty of good stuff in the datetime module.
 
 -tkc

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


Re: What is Expressiveness in a Computer Language

2006-06-19 Thread Matthias Blume
Rob Thorpe [EMAIL PROTECTED] writes:

 I don't think dynamic typing is that nebulous.  I remember this being
 discussed elsewhere some time ago, I'll post the same reply I did then
 ..


 A language is statically typed if a variable has a property - called
 it's type - attached to it, and given it's type it can only represent
 values defined by a certain class.

By this definition, all languages are statically typed (by making that
certain class the set of all values).  Moreover, this definition,
when read the way you probably wanted it to be read, requires some
considerable stretch to accommodate existing static type systems such
as F_\omega.

Perhaps better: A language is statically typed if its definition
includes (or ever better: is based on) a static type system, i.e., a
static semantics with typing judgments derivable by typing rules.
Usually typing judgmets associate program phrases (expressions) with
types given a typing environment.

 A language is latently typed if a value has a property - called it's
 type - attached to it, and given it's type it can only represent values
 defined by a certain class.

This definition makes little sense.  Any given value can obviously
only represent one value: itself.  Dynamic types are nothing more
than sets of values, often given by computable predicates.

 Untyped and type-free mean something else: they mean no type checking
 is done.

Look up untyped lambda calculus.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >