Jython 2.5.0 Final is out!

2009-06-17 Thread Frank Wierzbicki
On behalf of the Jython development team, I'm pleased to announce that
Jython 2.5.0 final is available for download:
http://downloads.sourceforge.net/jython/jython_installer-2.5.0.jar see
the installation instructions:
http://wiki.python.org/jython/InstallationInstructions

Jython 2.5.0 brings us up to language level compatibility with the 2.5
version of CPython.  This release has had a strong focus on CPython
compatibility, and so this release of Jython can run more pure Python
apps then any previous release.  Please see the NEWS file for detailed
release notes.

I want to thank all of the amazing people who have contributed in
large and small ways to this important Jython release.  For the first
time in a long time we have Jython that is a modern version of Python.
 Enjoy!

Please report any bugs that you find: http://bugs.jython.org

Thanks!

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

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


[ANN] first full alpha release of PyLab_Works v0.3

2009-06-17 Thread Stef Mientki

hello,

I am pleased to announce the first full alpha release of PyLab_Works, v0.3.

PyLab_Works is a modular Visual Development Environment, based on 
data-flow programming technics. PyLab_Works is specially aimed at 
Education, Engineering and Science. The ideas behind PyLab_Works are, 
that the final user should not be burdened with programming details and 
domain details, whereas the domain expert should be able to implement 
the specific  domain knowledge without being a full educated programmer.


You can always find my notes on PyLab_Works on
  http://pic.flappie.nl
Most of these pages are also collected in a single pdf document, which 
can be found here:

 http://pylab-works.googlecode.com/files/pw_manual.pdf

The source code and a one-button-Windows-Installer can be found on 
codegoogle:

 http://code.google.com/p/pylab-works/
The files are rather large, because they contain some data samples.
The Windows-Installer contains everything you need to get started with 
PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle,  
Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy, 
Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython. 
Although the PyLab_Works programs are compiled with Py2Exe, all the 
source files are explicitly included.


have fun,
Stef Mientki
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


Sphinx 0.6.2 released

2009-06-17 Thread Georg Brandl
Hi all,

I'm proud to announce the release of Sphinx 0.6.2, which is a
bugfix-only release in the 0.6 series.

What is it?
===

Sphinx is a tool that makes it easy to create intelligent and beautiful
documentation for Python projects (or other documents consisting of
multiple reStructuredText source files).

Website: http://sphinx.pocoo.org/

What's new in 0.6.2 (short version)?


Over 25 bugs and problems have been fixed.
The full list is at http://sphinx.pocoo.org/changes.html.


cheers,
Georg




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

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


py-postgresql 0.9 Released: Speed Query Libraries

2009-06-17 Thread jwp
I'm pleased to announce the release of py-postgresql 0.9.0 and 0.8.2.

py-postgresql is a Python programmer's client (driver) for PostgreSQL
and
general toolkit for working with PostgreSQL in Python.


   
http://python.projects.postgresql.org/?utm_source=releaseutm_medium=emailutm_campaign=py-postgresql-0.9.0


Changes in 0.9:

 * Performance Improvements. Always nice. =)
 * Query Libraries--statement management.
 * Display of line and relative location of the POSITION for syntax
errors.
 * DB-API now extends PG-API.
 * Many under-the-hood improvements.


Special thanks to the following bug reporters:

 Mike Bayer [Broken DB-API row counts]
 Dallas Morisett [Broken procedure reference generation]


... Bugs, while of crunchy consistency, are fearlessly squashed.
... If you find a bug, a report would be greatly appreciated.
http://pgfoundry.org/tracker/?atid=442group_id=194
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: pdfrecycle 0.05

2009-06-17 Thread Florian Diesch

I'm happy to announce pdfrecycle 0.05

Get it at http://www.florian-diesch.de/software/pdfrecycle/


pdfrecycle creates a PDF file by composing pages from other PDF
files. It can add PDF bookmarks and metadata, scale, rotate and crop
pages and put multiple logical pages onto each physical sheet.

pdfrecycle uses a simple text file format to define the layout and
what pages to include. From this input file pdfrecycle creates a LaTeX
file and then runs pdflatex to produced the PDF file.


With version 0.05 you can put pages of different input files on one
output sheet and/or cut of parts of input pages.





   Florian
-- 
http://www.florian-diesch.de/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: walking a directory with very many files

2009-06-17 Thread Lawrence D'Oliveiro
In message 20090617091858.432f8...@malediction, Mike Kazantsev wrote:

 On Wed, 17 Jun 2009 14:52:28 +1200
 Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote:
 
 In message
 234b19ac-7baf-4356-9fe5-37d00146d...@z9g2000yqi.googlegroups.com,
 thebjorn wrote:
 
  Not proud of this, but...:
  
  [django] www4:~/datakortet/media$ ls bfpbilder|wc -l
   174197
  
  all .jpg files between 40 and 250KB with the path stored in a
  database field... *sigh*
 
 Why not put the images themselves into database fields?
 
  Oddly enough, I'm a relieved that others have had similar folder
  sizes ...
 
 One of my past projects had 40-odd files in a single folder. They
 were movie frames, to allow assembly of movie sequences on demand.
 
 For both scenarios:
 Why not use hex representation of md5/sha1-hashed id as a path,
 arranging them like /path/f/9/e/95ea4926a4 ?
 
 That way, you won't have to deal with many-files-in-path problem ...

Why is that a problem?

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


Re: Measuring Fractal Dimension ?

2009-06-17 Thread Paul Rubin
Jaime Fernandez del Rio jaime.f...@gmail.com writes:
 I am pretty sure that a continuous sequence of
 curves that converges to a continuous curve, will do so uniformly.

I think a typical example of a curve that's continuous but not
uniformly continuous is

   f(t) = sin(1/t), defined when t  0

It is continuous at every t0 but wiggles violently as you get closer
to t=0.  You wouldn't be able to approximate it by sampling a finite
number of points.  A sequence like 

   g_n(t) = sin((1+1/n)/ t)for n=1,2,...

obviously converges to f, but not uniformly.  On a closed interval,
any continuous function is uniformly continuous.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-17 Thread Paul Rubin
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes:
  Reference counting is an implementation detail used by CPython but not
  [implementations built on runtimes designed for corporate-herd-oriented
  languages, like] IronPython or Jython.
 
 I rest my case.

You're really being pretty ignorant.  I don't know of any serious Lisp
system that uses reference counting, both for performance reasons and
to make sure cyclic structures are reclaimed properly.  Lisp is
certainly not a corporate herd language.

Even CPython doesn't rely completely on reference counting (it has a
fallback gc for cyclic garbage).  Python introduced the with
statement to get away from the kludgy CPython programmer practice of
opening files and relying on the file being closed when the last
reference went out of scope.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parsing json using simplejson

2009-06-17 Thread Tim Roberts
deostroll deostr...@gmail.com wrote:

I want to be able to parse it into python objects. Any ideas?

What did you not like about the very useful replies you have already
received?
-- 
Tim Roberts, t...@probo.com
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-17 Thread Steven D'Aprano
On Wed, 17 Jun 2009 17:52:30 +1200, Lawrence D'Oliveiro wrote:

 In message pan.2009.06.16.07.34...@remove.this.cybersource.com.au,
 Steven D'Aprano wrote:
 
 On Tue, 16 Jun 2009 16:45:43 +1200, Lawrence D'Oliveiro wrote:
 
 In message m2eitowaf2@cs.uu.nl, Piet van Oostrum wrote:
 
 The exact time of the destruction of objects is an implementation
 detail and should not be relied upon.
 
 That may be true in Java and other corporate-herd-oriented languages,
 but we know that dynamic languages like Perl and Python make heavy use
 of reference-counting wherever they can. If it's easy to satisfy
 yourself that the lifetime of an object will be delimited in this way,
 I don't see why you can't rely upon it.
 
 Reference counting is an implementation detail used by CPython but not
 [implementations built on runtimes designed for corporate-herd-oriented
 languages, like] IronPython or Jython.
 
 I rest my case.

CLPython and Unladen Swallow do not use reference counting. I suppose you 
might successfully argue that Lisp is a corporate-herd-oriented language, 
and that Google (the company behind Unladen Swallow) is a corporate-herd. 
But PyPy doesn't use reference counting either. Perhaps you think that 
Python is a language designed for corporate-herds too?



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


Re: How to get the total size of a local hard disk?

2009-06-17 Thread Tim Roberts
willgun will...@live.cn wrote:

Unfortunately,I'm on win32.
Actually,I prefer a cross-platform method.

Why do you need this?  This kind of information is not very useful in a
cross-platform application.
-- 
Tim Roberts, t...@probo.com
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization?

2009-06-17 Thread Diez B. Roggisch

higer schrieb:

My Python version is 2.5.2; When I reading the bytecode of some pyc
file, I always found that there are many jump command from different
position,but to the same position. You can see this situation in
following code(this bytecode is just from one .pyc file and I don't
have its source .py file):

.
526 POP_TOP   ''
527 LOAD_FAST 'imeHandle'
530 LOAD_ATTR 'isCnInput'
533 CALL_FUNCTION_0   ''
536 JUMP_IF_FALSE '574'
539 POP_TOP   ''
540 LOAD_FAST 'GUIDefine'
543 LOAD_ATTR 'CandidateIsOpen'
546 JUMP_IF_TRUE  '574'
549 POP_TOP   ''
550 LOAD_FAST 'GUIDefine'
553 LOAD_ATTR 'CompositionWndIsOpen'
556 JUMP_IF_TRUE  '574'
559 POP_TOP   ''
560 LOAD_FAST 'isWanNengWB'
563 JUMP_IF_FALSE '574'
566 POP_TOP   ''
567 LOAD_FAST 'state'
570 LOAD_CONST1
573 BINARY_AND''
574_0   COME_FROM ''
574_1   COME_FROM ''
574_2   COME_FROM ''
574_3   COME_FROM ''
...

From the above bytecode,we know that line 574 is the point that many
position jumps to.So,it just looks like the 'goto' function in C, but
we know that there is none such function in Python.
One 'JUMP**' command is companied with a 'COME_FROM' command,so more
than one 'COME_FROM' OPs are listed on line 574...

But ,the question is, I have tried a lot of ways(e.g.for loop,while
loop and mixed) to re-present 'goto' style bytecodes like this, but
the result depressed me.
So,I think maybe it is just a compiler optimization in Python2.5? I'm
not sure,so I'm appreciated that if anyone can help me.


Getting a depression because of a compiler is a bit strong...

However, yes, bytecode is similar to assembler, and in that respect 
higher-level control-structures are created using (conditional) jumps.


The same is true for other bytecode-languages, see here for the JVM:

http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#6493

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


Managing a multiple threaded service

2009-06-17 Thread Paul Hemans
Hi,
New to Python 
I've got 2 threads 1 is the SimpleHTTPRequestHandler, the other polls a site 
for data. I want to run the program as a windows service.
My questions are:
Should both of them run as threads and then just have an infinite loop with 
a sleep in the main thread in order to stop the main program from just 
terminating?
Or should I choose one of the threads to run as the main program and spawn 
the other off? That was my original intention, but I am concerned that if I 
use SimpleHTTPRequestHandler in the main thread, will it block any attempt 
to terminate the service.

Just looking for pointers to the best practice approach. This is where I am 
at:

if __name__==__main__:
import SocketServer
import threading
import monitor

## Monitor changes on the server (separate thread)
monitor = monitor.monitor(fnLog=self.logStatus)
monitor.start()

## Service interface
port = 8081
server=SocketServer.TCPServer(('',port),ScriptRequestHandler)
server.serve_forever()
## To run the web server on a different thread...
##t = threading.Thread(target=server.serve_forever)
##t.setDaemon(True) # don't hang on exit
##t.start()

server.socket.close()



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


Re: simple GUI for my application?

2009-06-17 Thread Tim Roberts
Tim Harig user...@ilthio.net wrote:

IronPython is not a GUI toolkit per se.  It is a python implementation
build on top of .Net like Jython is built on top of Java.  I therefore has
access to the MFCs which can be used to create native Windows GUIs. 

That's not correct.  MFC is strictly a native C++ concept.  IronPython,
being a .NET language, has access to the .NET GUIs, which means either
Windows Forms or the incredibly powerful Windows Presentation Framework.

However, if I may be allowed to express an opinion, if you're going to play
in that world, you are swimming upstream unless you write in C#. Otherwise,
you end up spending most of your time translating C# concepts into Python.

This can also be done from Cpython using the pywin extensions.

Here, you are correct.  Pywin32 does include a Python implementation of
MFC.
-- 
Tim Roberts, t...@probo.com
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: first full alpha release of PyLab_Works v0.3

2009-06-17 Thread Martin P. Hellwig

edexter wrote:

On Jun 16, 12:27 pm, Stef Mientki stef.mien...@gmail.com wrote:

hello,

I am pleased to announce the first full alpha release of PyLab_Works, v0.3.

PyLab_Works is a modular Visual Development Environment, based on
data-flow programming technics. PyLab_Works is specially aimed at
Education, Engineering and Science. The ideas behind PyLab_Works are,
that the final user should not be burdened with programming details and
domain details, whereas the domain expert should be able to implement
the specific  domain knowledge without being a full educated programmer.

You can always find my notes on PyLab_Works on
   http://pic.flappie.nl
Most of these pages are also collected in a single pdf document, which
can be found here:
 http://pylab-works.googlecode.com/files/pw_manual.pdf

The source code and a one-button-Windows-Installer can be found on
codegoogle:
 http://code.google.com/p/pylab-works/
The files are rather large, because they contain some data samples.
The Windows-Installer contains everything you need to get started with
PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle,  
Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy,

Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython.
Although the PyLab_Works programs are compiled with Py2Exe, all the
source files are explicitly included.

have fun,
Stef Mientki


program didn't start because .dll is missing (sorry I don't have the
name)...  I don't know if that is just an issue with the installer
with vista or not (missing msv something 71. dll)


You probably mean the microsoft visual C++ runtime (msvcr71.dll), 
windows vista has a brand new way (via manifest files) to make it more 
difficult to install compiled binaries.


Search for 'Microsoft Visual C++ 2005 Redistributable Package' and 
install it.


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization?

2009-06-17 Thread Tim Roberts
higer higerinbeij...@gmail.com wrote:

My Python version is 2.5.2; When I reading the bytecode of some pyc
file, I always found that there are many jump command from different
position,but to the same position. You can see this situation in
following code(this bytecode is just from one .pyc file and I don't
have its source .py file):
...
From the above bytecode,we know that line 574 is the point that many
position jumps to.So,it just looks like the 'goto' function in C, but
we know that there is none such function in Python.
...
But ,the question is, I have tried a lot of ways(e.g.for loop,while
loop and mixed) to re-present 'goto' style bytecodes like this, but
the result depressed me.
So,I think maybe it is just a compiler optimization in Python2.5? I'm
not sure,so I'm appreciated that if anyone can help me.

I can't figure out what you're asking here.  Are you annoyed that the byte
code contains GOTOs?  This is a silly thing to worry about.  The whole
purpose of a compiler is to translate a program express in high-level
constructs into a lower-level and more primitive format.  The simplest form
of an if statement or a while statement always includes unconditional
branches.

This exact same thing happens with every compiler.  Assembly languages, for
example, do not have if/then/else instructions, nor while instructions,
nor switch instructions.  If you write a C program with an if
statement, the resulting assembly program will contain a goto (usually
called jump or branch).

Don't worry about it.
-- 
Tim Roberts, t...@probo.com
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Managing a multiple threaded service

2009-06-17 Thread Mark Hammond

On 17/06/2009 4:23 PM, Paul Hemans wrote:

Hi,
New to Python 
I've got 2 threads 1 is the SimpleHTTPRequestHandler, the other polls a site
for data. I want to run the program as a windows service.
My questions are:
Should both of them run as threads and then just have an infinite loop with
a sleep in the main thread in order to stop the main program from just
terminating?


No need for a loop - just have the main thread wait forever for the stop 
request.  The main problem I forsee is asking the socketserver thread to 
terminate as it is likely to be inside 'accept' or some other blocking 
function.


HTH,

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


Re: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

2009-06-17 Thread Gabriel Rossetti

John Machin wrote:

On Jun 17, 1:41 am, Gabriel Rossetti gabriel.rosse...@arimaz.com
wrote:
  

Hello everyone,

I get an OperationalError with sqlite3 if I put the wrong column name,
but shouldn't that be a ProgrammingError instead? I read PEP 249 and it
says :



[snip]
  

and to me it sounds more like a programming error than an operational
error.



How about showing us the code you used and the exact error message and
traceback?


  

Well, the code isn't really relevant to the problem, but here is is :

import sqlite3

conn = sqlite3.connect(/tmp/test.db)
conn.execute(SELECT name, value FROM local_param)

for row in conn:
   print row

And I get :

Traceback (most recent call last):
 File stdin, line 1, in module
sqlite3.OperationalError: no such table: local_param


Which I think should be a ProgrammingError

If I fix the table name I but use a wrong column name I also get an 
OperationalError



import sqlite3

conn = sqlite3.connect(/tmp/test.db)
conn.execute(SELECT name, valu FROM local_parameters)

for row in conn:
   print row

Traceback (most recent call last):
 File stdin, line 1, in module
sqlite3.OperationalError: no such column: valu

Which should also be a ProgrammingError as I see it and as my 
interpretation of the documention.


Gabriel

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


Re: strange behavior with os.system

2009-06-17 Thread kmw
That's it. I am calling my own program and not coreutils' sort, what
explains the unrequested output. Many thanks.

Cheers,
Kay

On 16 Jun., 22:16, Piet van Oostrum p...@cs.uu.nl wrote:
  kmw wuerz...@gmail.com (k) wrote:
 k Hi,
 k I wanted to write a simple script (in 5 minutes or so) which replaces
 k the option '+1' given to the command 'sort' by '-k 2' and than runs
 k 'sort' with the modified argument list. After two hours I am giving up
 k and ask you for help. This is what I tried (please excuse the verbose
 k code, it is due to my various efforts to understand the error):

 [snip]

 k Please note the unrequested output of 'type 'NoneType''. The strange
 k thing about this all is the fact that  the whole thing works as
 k expected when typed  into the interpreter. I would be glad if anyone
 k could help.

 MRAB has already given you some insight, I hope.
 But are you aware that you are calling your own program again?
 Or did you want to call the standard sort program? In that case you
 shouldn't call ./sort as it is in argv[0], but just sort (assuming '.'
 is not in your PATH) or the full path, like /usr/bin/sort.
 --
 Piet van Oostrum p...@cs.uu.nl
 URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
 Private email: p...@vanoostrum.org

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


Re: Newbie question about method options

2009-06-17 Thread Dave Angel

python-newbie113 wrote:

I am new to python and have a question about using methods.

Here is the link i am looking at:
http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm

If i use, create_arc(bbox, options) = id
what is id? and how do i find the parameter list representing options?

Thanks for help in advance

Andrew

  
This is a tkinter question, not a python one, and it's really all about 
how the docs for tkinter are organized.  I don't use tkinter, so I had 
to spelunk a little bit (try search).  You're looking at a summary 
page.  You want to see the details for a given one of those methods.


Search for create_arc, and you'll find
http://www.pythonware.com/library/tkinter/introduction/x2861-options.htm
  as one of the links.  The link Back will get you to:
http://www.pythonware.com/library/tkinter/introduction/canvas-arc.htm


which is the beginning of Chapter 14, The Canvas Arc Item

As for 'id' I have no idea, but if you read further, you'll probably 
find out.  The fact that all of these methods return one indicates it's 
some sort of object reference for those widgets.



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


Re: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization?

2009-06-17 Thread Hendrik van Rooyen
 Diez B. Roggisch d...@n...m.web.de wrote:

 Getting a depression because of a compiler is a bit strong...

 However, yes, bytecode is similar to assembler, and in that respect
 higher-level control-structures are created using (conditional) jumps.

 The same is true for other bytecode-languages, see here for the JVM:

 http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#6493

This is right.

It is my opinion that it is not possible to make a useful machine,
virtual or real, which executes instructions sequentially, if the
instruction set does not contain a conditional jump of some sort.

I have tried doing it using conditional calls, and it fails on
the equivalent of the first if ..., elif ...  you try to write.

- Hendrik



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


Re: Tool for browsing python code

2009-06-17 Thread Hendrik van Rooyen
Horace Blegg  wrote:

I've heard from my cousin that his former high school classmate's
uncle did a research on a large statistical sample of programmers and
found that emacs users' brains are about 12% smaller than vi users' :)

I'm afraid it's the other way around, really. You see, emacs contains 5
characters, thus requiring MORE brainpower to understand, where as vi is only 2
characters, requiring LESS brainpower. It's like that old joke. Why do blondes
move to L.A? Because it's easy to spell. I guess what I'm saying is vi users are
blondes. :)

All this stuff is nonsense. It is a well known fact that the size of your
brain is not governed by what editor you use, but by what you drink.

The conjecture that some editors might drive you to drink is at the
moment only a theory.  I am not aware of any hard evidence
that correlates hard tack drinking patterns with editor usage.

So any research on brain size vs editor usage that does not also
include drinking pattern data is essentially invalid.

- Hendrik



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


Re: walking a directory with very many files

2009-06-17 Thread Mike Kazantsev
On Wed, 17 Jun 2009 17:53:33 +1200
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote:

  Why not use hex representation of md5/sha1-hashed id as a path,
  arranging them like /path/f/9/e/95ea4926a4 ?
  
  That way, you won't have to deal with many-files-in-path problem ...
 
 Why is that a problem?

So you can os.listdir them?
Don't ask me what for, however, since that's the original question.
Also not every fs still in use handles this situation effectively, see
my original post.

-- 
Mike Kazantsev // fraggod.net


signature.asc
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exotic Logics

2009-06-17 Thread Steven D'Aprano
On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:

 I was staring at a logic table the other day, and I asked myself, what
 if one wanted to play with exotic logics; how might one do it?


First question: what's an exotic logics?

Do you mean things like three-value logic, fuzzy logic, probabilistic 
reasoning, etc?

Or do you mean logical operators others than and, or, xor, nand, nor, etc?

Or both? Something else?



 I did
 some searching but not being too sure of what to look for and carried
 away with my own enthusiasm for the idea, I didn't find much. What I've
 come up with is, no doubt, inefficient, naive, poor python style, and
 probably wrong in fundamental ways too subtle for me, but here it is:
 
 import itertools
 import operator
 
 class Logic():
 class of generic logic operators
[...]

If (nearly) all your methods are static methods, chances are a class is 
the wrong solution. Why not just define the static methods as top-level 
functions?


 This seemed to be working for the limited tests I did on it, while I was
 doing them. The following checked out last time I tried:
 
 and_ = Logic(2, 8)
 or_ = Logic(2, 14)
 xor = Logic(2, 6)
 
 I have no idea how to validate the results of the trinary and beyond
 logics.

The same way you would validate and_, or_ and xor: to validate something, 
you need to know what the correct answer is, then compare the answer you 
get with the answer you should get. For a binary operator and binary 
operands, you can exhaustively check every valid input:

flag1 op flag2

there are four combinations of input flags: 

0 op 0
0 op 1
1 op 0
1 op 1

For three-valued logic, there are 9 combinations. For four-valued, 16. So 
exhaustively testing all the possible inputs is quite simple.

As far as getting the correct answers, you have to decide which three-
valued logic(s) you want to use, then go look them up. Or just make them 
up yourself!

E.g. given trinary flags 0, 1, 2, (say), you might want the operators to 
give the same results with 0, 1 as they would if you were applying it to 
binary flags 0, 1. E.g.:

# binary operands
0 and 0 = 0
0 and 1 = 0
1 and 0 = 0
1 and 1 = 1

# trinary operands

0 and 0 = 0
0 and 1 = 0
0 and 2 = ?  # probably 0
1 and 0 = 0
1 and 1 = 1
1 and 2 = ?  # could be 0, or maybe 1
2 and 0 = ?  # probably 0
2 and 1 = ?  # 0 or 1
2 and 2 = ?  # probably 2

Different choices lead to different versions of ternary logic.




 Thanks for reading and trying this out. Corrections? Criticism?
 Comments?

You're implementation seems rather confusing. I think that's partly 
because you use lots of abbreviated jargon terms that mean little or 
nothing to me: rdx, opr (operator?), lsd, pute.




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


Re: Exotic Logics

2009-06-17 Thread Steven D'Aprano
On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:

 I was staring at a logic table the other day, and I asked myself, what
 if one wanted to play with exotic logics; how might one do it?


This might be useful for you, and if not useful, at least it might blow 
your mind like it did mine.

(This is not original to me -- I didn't create it. However, I can't find 
the original source.)

Imagine for a moment that there are no boolean values. 
There are no numbers.  They were never invented.
There are no classes.
There are no objects.
There are only functions.

Could you define functions that act like boolean values? And could you 
define other functions to operate on them?


def true(x, y):
return x

def false(x, y):
return y

def print_bool(b):
print b(true, false)

print_bool(true)
print_bool(false)


def Not(b):
def not_b(x, y):
return b(y, x)
return not_b

print_bool(Not(true))
print_bool(Not(false))
print_bool(Not(Not(true)))

def And(a, b):
return a(b, a)

def Or(a, b):
return a(a, b)

print_bool(And(true, true))
print_bool(And(true, false))
print_bool(Or(false, true))
print_bool(Or(false, false))



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


Re: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization?

2009-06-17 Thread higer
Hi,all:

I'm sorry that I did not make my question clear. What I mean is that
what the souce code would look like that will be compiled to such
bytecodes.


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


Re: Need to know if a file as only ASCII charaters

2009-06-17 Thread Wolfgang Rohdewald
On Wednesday 17 June 2009, Lie Ryan wrote:
 Wolfgang Rohdewald wrote:
  On Wednesday, 17. June 2009, Steven D'Aprano wrote:
  while text:
  for c in text:
  if c not in printable: return False
  
  that is one loop per character.
 
 unless printable is a set

that would still execute the line if c not in... 
once for every single character, against just one
regex call. With bigger block sizes, the advantage
of regex should increase.
 
  wouldn't it be faster to apply a regex to text?
  something like
  
  while text:
  if re.search(r'\W',text): return False
  
 
 regex? Don't even start...

Here comes a cProfile test. Note that the first variant of Steven
would always have stopped after the first char. After fixing that
making it look like variant 2 with block size=1, I now have 
3 variants:

Variant 1 Blocksize 1
Variant 2 Blocksize 65536
Variant 3 Regex on Blocksize 65536

testing for a file with 400k bytes shows regex as a clear winner.
Doing the same for an 8k file: variant 2 takes 3ms, Regex takes 5ms.

Variants 2 and 3 take about the same time for a file with 20k.


python ascii.py | grep CPU
 398202 function calls in 1.597 CPU seconds
 13 function calls in 0.104 CPU seconds
 1181 function calls in 0.012 CPU seconds

import re
import cProfile

from string import printable

def ascii_file1(name):
with open(name, 'rb') as f:
c = f.read(1)
while c:
if c not in printable: return False
c = f.read(1)
return True

def ascii_file2(name):
bs = 65536
with open(name, 'rb') as f:
text = f.read(bs)
while text:
for c in text:
if c not in printable: return False
text = f.read(bs)
return True

def ascii_file3(name):
bs = 65536
search = r'[^%s]' % re.escape(printable)
reco = re.compile(search)
with open(name, 'rb') as f:
   text = f.read(bs)
   while text:
   if reco.search(text): return False
   text = f.read(bs)
return True

def test(fun):
if fun('/tmp/x'):
   print 'is ascii'
else:
   print 'is not ascii'

cProfile.run(test(ascii_file1))
cProfile.run(test(ascii_file2))
cProfile.run(test(ascii_file3))




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


Re: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization?

2009-06-17 Thread Diez B. Roggisch
higer wrote:

 Hi,all:
 
 I'm sorry that I did not make my question clear. What I mean is that
 what the souce code would look like that will be compiled to such
 bytecodes.

 import dis
 def foo():
... for i in xrange(10):
... if i == 5:
...break
... if i == 4:
...continue
... i *= 100
...
 dis.disassemble(foo.func_code)
  2   0 SETUP_LOOP  68 (to 71)
  3 LOAD_GLOBAL  0 (xrange)
  6 LOAD_CONST   1 (10)
  9 CALL_FUNCTION1
 12 GET_ITER
   13 FOR_ITER54 (to 70)
 16 STORE_FAST   0 (i)

  3  19 LOAD_FAST0 (i)
 22 LOAD_CONST   2 (5)
 25 COMPARE_OP   2 (==)
 28 JUMP_IF_FALSE5 (to 36)
 31 POP_TOP

  4  32 BREAK_LOOP
 33 JUMP_FORWARD 1 (to 37)
   36 POP_TOP

  537 LOAD_FAST0 (i)
 40 LOAD_CONST   3 (4)
 43 COMPARE_OP   2 (==)
 46 JUMP_IF_FALSE7 (to 56)
 49 POP_TOP

  6  50 JUMP_ABSOLUTE   13
 53 JUMP_FORWARD 1 (to 57)
   56 POP_TOP

  757 LOAD_FAST0 (i)
 60 LOAD_CONST   4 (100)
 63 INPLACE_MULTIPLY
 64 STORE_FAST   0 (i)
 67 JUMP_ABSOLUTE   13
   70 POP_BLOCK
   71 LOAD_CONST   0 (None)
 74 RETURN_VALUE
   


Pretty much everything with control-structures.

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


Re: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

2009-06-17 Thread John Machin

On 17/06/2009 5:15 PM, Gabriel Rossetti wrote:

John Machin wrote:

On Jun 17, 1:41 am, Gabriel Rossetti gabriel.rosse...@arimaz.com
wrote:
 

Hello everyone,

I get an OperationalError with sqlite3 if I put the wrong column name,
but shouldn't that be a ProgrammingError instead? I read PEP 249 and it
says :



[snip]
 

and to me it sounds more like a programming error than an operational
error.



How about showing us the code you used and the exact error message and
traceback?


  

Well, the code isn't really relevant to the problem, but here is is :

import sqlite3

conn = sqlite3.connect(/tmp/test.db)
conn.execute(SELECT name, value FROM local_param)

for row in conn:
   print row

And I get :

Traceback (most recent call last):
 File stdin, line 1, in module
sqlite3.OperationalError: no such table: local_param


Which I think should be a ProgrammingError

If I fix the table name I but use a wrong column name I also get an 
OperationalError


OK OK alright already ... I agree with you ... report a bug.

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


class or instance method

2009-06-17 Thread Paul Johnston
Hi,

I would like to have a method that is both a classmethod and an
instancemethod. So:

class MyClass(object):
  @class_or_instance
  def myfunc(cls_or_self):
pass

The semantics I'd like are:
When you call MyClass.myfunc, it gets passed a class
When you call MyClass().myfunc, it gets passed an instance

I'm sure I've seen some code to do this somewhere, but I can't find it
now. Any help appreciated.

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


Re: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization?

2009-06-17 Thread pdpi
On Jun 17, 9:01 am, Hendrik van Rooyen m...@microcorp.co.za wrote:
  Diez B. Roggisch d...@n...m.web.de wrote:

  Getting a depression because of a compiler is a bit strong...

  However, yes, bytecode is similar to assembler, and in that respect
  higher-level control-structures are created using (conditional) jumps.

  The same is true for other bytecode-languages, see here for the JVM:

 http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc

 This is right.

 It is my opinion that it is not possible to make a useful machine,
 virtual or real, which executes instructions sequentially, if the
 instruction set does not contain a conditional jump of some sort.

 I have tried doing it using conditional calls, and it fails on
 the equivalent of the first if ..., elif ...  you try to write.

 - Hendrik

Not a matter of opinion. One of the requisite elements of a Turing
Machine is conditional jumping.
-- 
http://mail.python.org/mailman/listinfo/python-list


GAEUnit testing

2009-06-17 Thread Mike
Hello I'm using GAEUnit to develop an app for google appengine and am having
a little trouble.

I'm trying to make a test as follows:

I have a file (say model.py) which contains Model.db model classes and some
methods for accessing them. The methods are not part of the class.

In my test I can call model.save_person(person) which will call
Person(name=person) and Person.put(). I can confirm this is being saved to
the db (app engine db stub) by logging the result of Person.all() under the
call to put.

What I want to do is create a method in model.py called get_people which
will return Person.all().

If I do this the second test returns an empty result set. I think this is
because the second test is not getting the same reference.

In my set up I'd like to set up a Person with details such as address,
phone, preferences and have each test get the data for this person and test
the result of some transformations.

I'd like to do this using the methods in my model.py class, and avoid
importing the database to the test unit and using references to self.

Am I approaching this correctly? How would I implement this?

Thanks for any assistance, I'm new to python and especially unittesting.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: class or instance method

2009-06-17 Thread Bruno Desthuilliers

Paul Johnston a écrit :

Hi,

I would like to have a method that is both a classmethod and an
instancemethod. So:

class MyClass(object):
  @class_or_instance
  def myfunc(cls_or_self):
pass

The semantics I'd like are:
When you call MyClass.myfunc, it gets passed a class
When you call MyClass().myfunc, it gets passed an instance

I'm sure I've seen some code to do this somewhere, but I can't find it
now. Any help appreciated.


IIRC, there's something quite similar in formencode.

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


Re: Question about None

2009-06-17 Thread Bruno Desthuilliers

John Yeung a écrit :

On Jun 13, 2:29 am, Steven D'Aprano
st...@removethis.cybersource.com.au wrote:

Paul LaFollette wrote:

3) (this is purely philosophical but I am curious)
Would it not be more intuitive if
isinstance(None, anything at all) returned true?

Good grief no!!!

None is an object. It has a type, NoneType. It's *not* a
string, or a float, or an int, or a list, so why would
you want isinstance() to *lie* and say that it is?


Because you might want None to behave as though it were nothing at
all.

Paul LaFollette is probably thinking along the lines of formal logic
or set theory.  It's a little bit confused because programming isn't
quite the same as math, and so it's a common question when designing
and implementing programming languages how far to take certain
abstractions.  In some languages, nil, null, or none will try to
behave as mathematically close to nothing (complete absence of
anything) as possible, even though in reality they have to have some
concrete implementation, such as perhaps being a singleton object.
But mathematically speaking, it's intuitive that nothing would match
any type.


IOW, what's the OP is after is not the None type, but some yet 
unexisting Anything type !-)


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


Re: walking a directory with very many files

2009-06-17 Thread Lawrence D'Oliveiro
In message 20090617142431.2b25f...@malediction, Mike Kazantsev wrote:

 On Wed, 17 Jun 2009 17:53:33 +1200
 Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote:
 
  Why not use hex representation of md5/sha1-hashed id as a path,
  arranging them like /path/f/9/e/95ea4926a4 ?
  
  That way, you won't have to deal with many-files-in-path problem ...
 
 Why is that a problem?
 
 So you can os.listdir them?

Why should you have a problem os.listdir'ing lots of files?

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


Re: TypeError: int argument required

2009-06-17 Thread Lawrence D'Oliveiro
In message n4qzl.19093$y61.17...@news-server.bigpond.net.au, Lie Ryan 
wrote:

 out.write (
 '''
 function JSString(Str)
   {
 var Result = '\'
 for (var i = 0; i  Str.length; ++i)
   {
 var ThisCh = Str.charAt(i)
 if (ThisCh == '\\')
   {
 ThisCh = ''
   }
 else if (ThisCh == '\')
   {
 ThisCh = '\\\'
   }
 else if (ThisCh == '\t')
   {
 ThisCh = '\\t'
   }
 else if (ThisCh == '\n')
   {
 ThisCh = '\\n'
   } /*if*/
 Result += ThisCh
   } /*for*/
 return Result + '\'
 } /*JSString*/
 '''
 )

You haven't managed to get rid of the backslashes.

 I might go even further:
 
 out.write (
 '''
 function JSString(Str)
   {
 const dq = '\'
 const slash = '\\'
 
 var Result = dq
 for (var i = 0; i  Str.length; ++i)
   {
 var ThisCh = Str.charAt(i)
 if (ThisCh == slash)
   {
 ThisCh = slash + slash
   }
 else if (ThisCh == dq)
   {
 ThisCh = slash + dq
   }
 else if (ThisCh == '\t')
   {
 ThisCh = slash + 't'
   }
 else if (ThisCh == '\n')
   {
 ThisCh = slash + 'n'
   } /*if*/
 Result += ThisCh
   } /*for*/
 return Result + dq
 } /*JSString*/
 '''
 )

Now you've lost track of the original point of the discussion, which is 
about using alternate quotes to avoid backslashes.

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


Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-17 Thread Lawrence D'Oliveiro
In message 7x7hzbv14a@ruckus.brouhaha.com,  wrote:

 Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes:

  Reference counting is an implementation detail used by CPython but not
  [implementations built on runtimes designed for corporate-herd-oriented
  languages, like] IronPython or Jython.
 
 I rest my case.
 
 You're really being pretty ignorant.  I don't know of any serious Lisp
 system that uses reference counting, both for performance reasons and
 to make sure cyclic structures are reclaimed properly.

Both of which, oddly enough, more modern dynamic languages like Python 
manage perfectly well.

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


Re: Measuring Fractal Dimension ?

2009-06-17 Thread Charles Yeomans


On Jun 17, 2009, at 2:04 AM, Paul Rubin wrote:


Jaime Fernandez del Rio jaime.f...@gmail.com writes:

I am pretty sure that a continuous sequence of
curves that converges to a continuous curve, will do so uniformly.


I think a typical example of a curve that's continuous but not
uniformly continuous is

  f(t) = sin(1/t), defined when t  0

It is continuous at every t0 but wiggles violently as you get closer
to t=0.  You wouldn't be able to approximate it by sampling a finite
number of points.  A sequence like

  g_n(t) = sin((1+1/n)/ t)for n=1,2,...

obviously converges to f, but not uniformly.  On a closed interval,
any continuous function is uniformly continuous.


Isn't (-∞, ∞) closed?

Charles Yeomans

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


Regarding Python is scripting language or not

2009-06-17 Thread abhishek goswami
Hi,
I have very basic question about Python that do we consider pyhton as script 
language.
I searched in google but it becomes more confusion for me. After some analysis 
I came to know that Python support oops .

Can anyone Guide me that Python is Oject oriented programming language or 
Script language

Abhishek Goswami

Chennai

Phone No -0996227099


  ICC World Twenty20 England #39;09 exclusively on YAHOO! CRICKET 
http://cricket.yahoo.com-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-17 Thread Charles Yeomans


On Jun 17, 2009, at 2:13 AM, Paul Rubin wrote:


Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes:
Reference counting is an implementation detail used by CPython but  
not
[implementations built on runtimes designed for corporate-herd- 
oriented

languages, like] IronPython or Jython.


I rest my case.


You're really being pretty ignorant.  I don't know of any serious Lisp
system that uses reference counting, both for performance reasons and
to make sure cyclic structures are reclaimed properly.  Lisp is
certainly not a corporate herd language.

Even CPython doesn't rely completely on reference counting (it has a
fallback gc for cyclic garbage).  Python introduced the with
statement to get away from the kludgy CPython programmer practice of
opening files and relying on the file being closed when the last
reference went out of scope.


I'm curious as you why you consider this practice to be kludgy; my  
experience with RAII is pretty good.


Charles Yeomans

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


Re: Measuring Fractal Dimension ?

2009-06-17 Thread Mark Dickinson
On Jun 17, 7:04 am, Paul Rubin http://phr...@nospam.invalid wrote:
 I think a typical example of a curve that's continuous but not
 uniformly continuous is

    f(t) = sin(1/t), defined when t  0

 It is continuous at every t0 but wiggles violently as you get closer
 to t=0.  You wouldn't be able to approximate it by sampling a finite
 number of points.  A sequence like

    g_n(t) = sin((1+1/n)/ t)    for n=1,2,...

 obviously converges to f, but not uniformly.  On a closed interval,
 any continuous function is uniformly continuous.

Right, but pointwise convergence doesn't imply uniform
convergence even with continuous functions on a closed
bounded interval.  For an example, take the sequence
g_n (n = 0), of continuous real-valued functions on
[0, 1] defined by:

g_n(t) = nt if 0 = t = 1/n else 1

Then for any 0 = t = 1, g_n(t) - 0 as n - infinity.
But the convergence isn't uniform:  max_t(g_n(t)-0) = 1
for all n.

Maybe James is thinking of the standard theorem
that says that if a sequence of continuous functions
on an interval converges uniformly then its limit
is continuous?

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


Re: Perl's @foo[3,7,1,-1] ?

2009-06-17 Thread Jean-Michel Pichavant

On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote:

What's np.arange?



import numpy as np

--
Pierre delroth Bourdon delr...@gmail.com
Étudiant à l'EPITA / Student at EPITA
  


Perfect example of why renaming namespaces should be done only when 
absolutely required, that is, almost never.


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


Re: class or instance method

2009-06-17 Thread Xavier Ho
I'm quite curious as to why you would like it, because:

 MyClass
(returns the MyClass class representation)
 MyClass()
(returns a instance of the MyClass class)

So, are you just looking for a method that does exactly the above?

Best regards,

Ching-Yun Xavier Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: cont...@xavierho.com
Website: http://xavierho.com/


On Wed, Jun 17, 2009 at 8:39 PM, Bruno Desthuilliers
bruno.42.desthuilli...@websiteburo.invalid wrote:

 Paul Johnston a écrit :

 Hi,

 I would like to have a method that is both a classmethod and an
 instancemethod. So:

 class MyClass(object):
  @class_or_instance
  def myfunc(cls_or_self):
pass

 The semantics I'd like are:
 When you call MyClass.myfunc, it gets passed a class
 When you call MyClass().myfunc, it gets passed an instance

 I'm sure I've seen some code to do this somewhere, but I can't find it
 now. Any help appreciated.


 IIRC, there's something quite similar in formencode.


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

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


Re: Measuring Fractal Dimension ?

2009-06-17 Thread Jaime Fernandez del Rio
On Wed, Jun 17, 2009 at 1:52 PM, Mark Dickinsondicki...@gmail.com wrote:
 Maybe James is thinking of the standard theorem
 that says that if a sequence of continuous functions
 on an interval converges uniformly then its limit
 is continuous?

Jaime was simply plain wrong... The example that always comes to mind
when figuring out uniform convergence (or lack of it), is the step
function , i.e. f(x)= 0 if x in [0,1), x(x)=1 if x = 1, being
approximated by the sequence f_n(x) = x**n if x in [0,1), f_n(x) = 1
if x=1, where uniform convergence is broken mostly due to the
limiting function not being continuous.

I simply was too quick with my extrapolations, and have realized I
have a lot of work to do for my real and functional analysis
exam coming in three weeks...

Jaime

P.S. The snowflake curve, on the other hand, is uniformly continuous, right?

-- 
(\__/)
( O.o)
(  ) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus
planes de dominación mundial.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization?

2009-06-17 Thread John Machin
On Jun 17, 1:40 pm, higer higerinbeij...@gmail.com wrote:
 My Python version is 2.5.2; When I reading the bytecode of some pyc
 file, I always found that there are many jump command from different
 position,but to the same position. You can see this situation in
 following code(this bytecode is just from one .pyc file and I don't
 have its source .py file):


Why don't you (a) read the answers you got on stackoverflow to the
identical question (b) WRITE some code instead of inspecting the
entrails of the code of others?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding Python is scripting language or not

2009-06-17 Thread Jean-Michel Pichavant

abhishek goswami wrote:

Hi,
I have very basic question about Python that do we consider pyhton as 
script language.
I searched in google but it becomes more confusion for me. After some 
analysis I came to know that Python support oops .


Can anyone Guide me that Python is Oject oriented programming language 
or Script language


Abhishek Goswami
Chennai
Phone No -0996227099



ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET 
http://in.rd.yahoo.com/tagline_cricket_3/*http://cricket.yahoo.com 

Depends on what you are calling a scripting language.
Refering to wikipedia,
A *scripting language*, *script language* or *extension language* is a 
programming language http://en.wikipedia.org/wiki/Programming_language 
that allows some control of a single or many software application(s) 
http://en.wikipedia.org/wiki/Application_software.


Python is definitely OOP oriented and I don't think it fits in the 
script definition above.
Python is interpreted and platform independent, but you can still build 
standalone platform dependent binaries if required.


Regarding your last question, I'm not sure scripting and OOP language 
are not compatible, I'm pretty sure you'll be able to find OOP scripting 
language.


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


Re: Regarding Python is scripting language or not

2009-06-17 Thread Jochen Schulz
abhishek goswami:
 
 Can anyone Guide me that Python is Oject oriented programming language
 or Script language

In my opinion, Python is both. But an objective answer would require
you to define what you means by these terms.

If, by object-oriented you mean everything has to be put into
classes, then Python is not object-oriented. If, by scripting
language you mean Python is an error-prone toy language, unsuitable for
large, serious projects, then Python is not a scripting language either.

J.
-- 
My clothes aren't just fashion. They're a lifestyle.
[Agree]   [Disagree]
 http://www.slowlydownward.com/NODATA/data_enter2.html


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-17 Thread Mark Dickinson
On Jun 17, 1:26 pm, Jaime Fernandez del Rio jaime.f...@gmail.com
wrote:
 On Wed, Jun 17, 2009 at 1:52 PM, Mark Dickinsondicki...@gmail.com wrote:
  Maybe James is thinking of the standard theorem
  that says that if a sequence of continuous functions
  on an interval converges uniformly then its limit
  is continuous?

s/James/Jaime.   Apologies.

 P.S. The snowflake curve, on the other hand, is uniformly continuous, right?

Yes, at least in the sense that it can be parametrized
by a uniformly continuous function from [0, 1] to the
Euclidean plane.  I'm not sure that it makes a priori
sense to describe the curve itself (thought of simply
as a subset of the plane) as uniformly continuous.

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


Re: question about a command like 'goto ' in Python's bytecode or it's just a compiler optimization?

2009-06-17 Thread higer
On Jun 17, 8:29 pm, John Machin sjmac...@lexicon.net wrote:
 On Jun 17, 1:40 pm, higer higerinbeij...@gmail.com wrote:

  My Python version is 2.5.2; When I reading the bytecode of some pyc
  file, I always found that there are many jump command from different
  position,but to the same position. You can see this situation in
  following code(this bytecode is just from one .pyc file and I don't
  have its source .py file):

 Why don't you (a) read the answers you got on stackoverflow to the
 identical question (b) WRITE some code instead of inspecting the
 entrails of the code of others?

Thanks, I read the answer just now.
And thank everbody for your suggestion!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perl's @foo[3,7,1,-1] ?

2009-06-17 Thread Scott David Daniels

Jean-Michel Pichavant wrote:

On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote:

What's np.arange?


import numpy as np


Perfect example of why renaming namespaces should be done only when 
absolutely required, that is, almost never.


Jean-Michel


Actually, np. is quite commonly used in the numpy community,
so it is a bit of a term of art.  Since you can often use
several numpy elements in an expression, brevity is appreciated,
and at least they've stopped assuming from numpy import * in
their documents.  Unfortunately, if you work in a numpy world long
enough, you'll forget that not everyone uses numpy.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding Python is scripting language or not

2009-06-17 Thread Martin P. Hellwig

Jochen Schulz wrote:

abhishek goswami:

Can anyone Guide me that Python is Oject oriented programming language
or Script language


In my opinion, Python is both. But an objective answer would require
you to define what you means by these terms.

If, by object-oriented you mean everything has to be put into
classes, then Python is not object-oriented. If, by scripting
language you mean Python is an error-prone toy language, unsuitable for
large, serious projects, then Python is not a scripting language either.

J.


IMHO Python is an programming environment where you can chose the right 
approach for your particular problem. Because it seems to favour clarity 
over classification purity, it can not be so easily defined. This 
approach should be fine for everybody unless you are the type that 
insist on using one approach because in theory it should be suitable for 
everything.


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about method options

2009-06-17 Thread Scott David Daniels

Dave Angel wrote:

python-newbie113 wrote:

I am new to python and have a question about using methods.

Here is the link i am looking at:
http://www.pythonware.com/library/tkinter/introduction/x2102-methods.htm

If i use, create_arc(bbox, options) = id
what is id? and how do i find the parameter list representing options?


Search for create_arc, and you'll find
http://www.pythonware.com/library/tkinter/introduction/x2861-options.htm
  as one of the links.  The link Back will get you to:
http://www.pythonware.com/library/tkinter/introduction/canvas-arc.htm

which is the beginning of Chapter 14, The Canvas Arc Item

As for 'id' I have no idea, but if you read further, you'll probably 
find out.  The fact that all of these methods return one indicates it's 
some sort of object reference for those widgets.


Everything drawn on a canvas has an 'id' which just happens to be an
integer (treat it as a magic cookie).  You specify that id to the
canvas to talk about that particular element, but you often group
canvas elements together via tags, and use the same canvas operations
on a tag so that you can do your operation to everything with that tag.
operations include such things as color manipulation, delete, clone,
and move.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: UDP queue size

2009-06-17 Thread Scott David Daniels
找尋自己的一片天 wrote:
 I got a problem about UDP.
 
 How do I get the UDP buffer size?
 
 When the server had some delay in handling incoming UDP, it will lost
 some package. I wonder it's because the system buffer size, is there any
 ways to find the exactly size of the buffer?

UDP is defined as best effort then give up, so _everything_ that
handles a UDP packet is allowed to drop it; that means switchers,
routers, ..., anything along the path to the target application.
So, you cannot expect to do any better than a conservative guess,
perhaps augmented by dynamic scaling.

--Scott David Daniels
scott.dani...@acm.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie queue question

2009-06-17 Thread Jure Erznožnik
Hi,
I'm pretty new to Python (2.6) and I've run into a problem I just
can't seem to solve.
I'm using dbfpy to access DBF tables as part of a little test project.
I've programmed two separate functions, one that reads the DBF in main
thread and the other which reads the DBF asynchronously in a separate
thread.
Here's the code:

def demo_01():
'''DBF read speed only'''

dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1)
for i1 in xrange(len(dbf1)):
rec = dbf1[i1]
dbf1.close()

def demo_03():
'''DBF read speed into a FIFO queue'''

class mt(threading.Thread):

q = Queue.Queue(64)
def run(self):
dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1)
for i1 in xrange(len(dbf1)):
self.q.put(dbf1[i1])
dbf1.close()
del dbf1
self.q.join()

t = mt()
t.start()
while t.isAlive():
try:
rec = t.q.get(False, 0.2)
t.q.task_done();
except:
pass

del t


However I'm having serious issues with the second method. It seems
that as soon as I start accessing the queue from both threads, the
reading speed effectively halves.

I have tried the following:
1. using deque instead of queue (same speed)
2. reading 10 records at a time and inserting them in a separate loop
(hoped the congestion would help)
3. Increasing queue size to infinite and waiting 10 seconds in main
thread before I started reading - this one yielded full reading speed,
but the waiting took away all the threading benefits

I'm sure I'm doing something very wrong here, I just can't figure out
what.

Can anyone help me with this?

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


Re: first full alpha release of PyLab_Works v0.3

2009-06-17 Thread edexter
On Jun 17, 12:29 am, Martin P. Hellwig martin.hell...@dcuktec.org
wrote:
 edexter wrote:
  On Jun 16, 12:27 pm, Stef Mientki stef.mien...@gmail.com wrote:
  hello,

  I am pleased to announce the first full alpha release of PyLab_Works, v0.3.

  PyLab_Works is a modular Visual Development Environment, based on
  data-flow programming technics. PyLab_Works is specially aimed at
  Education, Engineering and Science. The ideas behind PyLab_Works are,
  that the final user should not be burdened with programming details and
  domain details, whereas the domain expert should be able to implement
  the specific  domain knowledge without being a full educated programmer.

  You can always find my notes on PyLab_Works on
     http://pic.flappie.nl
  Most of these pages are also collected in a single pdf document, which
  can be found here:
   http://pylab-works.googlecode.com/files/pw_manual.pdf

  The source code and a one-button-Windows-Installer can be found on
  codegoogle:
   http://code.google.com/p/pylab-works/
  The files are rather large, because they contain some data samples.
  The Windows-Installer contains everything you need to get started with
  PyLab_Works: ConfigObj, gprof2dot, HTTPlib, MatPlotLib, Numpy, Pickle,  
  Psyco, pyclbr, PyGame, PyLab_Works, PyODBC, Python, RLCompleter, Scipy,
  Sendkeys, SQLite3, SQLObject, URLparse, wave, Visual, win32*, wxPython.
  Although the PyLab_Works programs are compiled with Py2Exe, all the
  source files are explicitly included.

  have fun,
  Stef Mientki

  program didn't start because .dll is missing (sorry I don't have the
  name)...  I don't know if that is just an issue with the installer
  with vista or not (missing msv something 71. dll)

 You probably mean the microsoft visual C++ runtime (msvcr71.dll),
 windows vista has a brand new way (via manifest files) to make it more
 difficult to install compiled binaries.

 Search for 'Microsoft Visual C++ 2005 Redistributable Package' and
 install it.

 --
 MPHhttp://blog.dcuktec.comm
 'If consumed, best digested with added seasoning to own preference.'

it says I am missing msvcp71.dll installing Microsoft Visual C++ 2005
Redistributable Package
 did not help..  I had simular problems
 with alot of installers I had saved (from installing on xp) but when
I grabbed newer installers
they all worked, could be the manifast  I was looking forward to
trying it out..


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


Re: Measuring Fractal Dimension ?

2009-06-17 Thread Mark Dickinson
On Jun 17, 2:18 pm, pdpi pdpinhe...@gmail.com wrote:
 On Jun 17, 1:26 pm, Jaime Fernandez del Rio jaime.f...@gmail.com
 wrote:

  P.S. The snowflake curve, on the other hand, is uniformly continuous, right?

 The definition of uniform continuity is that, for any epsilon  0,
 there is a delta  0 such that, for any x and y, if x-y  delta, f(x)-f
 (y)  epsilon. Given that Koch's curve is shaped as recursion over the
 transformation from ___ to _/\_, it's immediately obvious that, for a
 delta of at most the length of , epsilon will be at most the
 height of /. It follows that, inversely, for any arbitrary epsilon,
 you find the smallest / that's still taller than epsilon, and delta is
 bound by the respective . (hooray for ascii demonstrations)

I think I'm too stupid to follow this.  It looks as though
you're treating (a portion of?) the Koch curve as the graph
of a function f from R - R and claiming that f is uniformly
continuous.  But the Koch curve isn't such a graph (it fails
the 'vertical line test', in the language of precalculus 101),
so I'm confused.

Here's an alternative proof:

Let K_0, K_1, K_2, ... be the successive generations of the Koch
curve, so that K_0 is the closed line segment from (0, 0) to
(1, 0), K_1 looks like _/\_, etc.

Parameterize each Kn by arc length, scaled so that the domain
of the parametrization is always [0, 1] and oriented so that
the parametrizing function fn has fn(0) = (0,0) and fn(1) = (1, 0).

Let d = ||f1 - f0||, a positive real constant whose exact value
I can't be bothered to calculate[*] (where ||f1 - f0|| means
the maximum over all x in [0, 1] of the distance from
f0(x) to f1(x)).

Then from the self-similarity we get ||f2 - f1|| = d/3,
||f3 - f2|| = d/9, ||f4 - f3|| = d/27, etc.

Hence, since sum_{i = 0} d/(3^i) converges absolutely,
the sequence f0, f1, f2, ... converges *uniformly* to
a limiting function f : [0, 1] - R^2 that parametrizes the
Koch curve.  And since a uniform limit of uniformly continuous
function is uniformly continuous, it follows that f is
uniformly continuous.

Mark

[*] I'm guessing 1/sqrt(12).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tool for browsing python code

2009-06-17 Thread Paul Boddie
On 16 Jun, 14:48, Lucas P Melo lukepada...@gmail.com wrote:
 Is there any tool for browsing python code? (I'm having a hard time
 trying to figure this out)
 Anything like cscope with vim would be great.

Are you limiting your inquiry to text editors or IDEs, or are Web-
based solutions also interesting? Often, convenient browsing tools
index the code and try and provide reasonable links from the place
where a particular name or symbol may be used to the definition of
that name or symbol elsewhere in a system. Initially, for a Web-based
code browser, I looked at LXR [1], but it seemed that OpenGrok [2] was
probably a better solution except for the fact that it uses the usual
Java parallel universe of Web and application servers.

Meanwhile, there are pages on the python.org Wiki about IDEs, editors
and documentation tools, all of which might be relevant here:

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

Paul

[1] http://lxr.linux.no/
[2] http://opensolaris.org/os/project/opengrok/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tool for browsing python code

2009-06-17 Thread Kurt Smith
On Tue, Jun 16, 2009 at 7:48 AM, Lucas P Melolukepada...@gmail.com wrote:
 Is there any tool for browsing python code? (I'm having a hard time trying
 to figure this out)
 Anything like cscope with vim would be great.

Check out pycscope:

http://pypi.python.org/pypi/pycscope/0.3

I use it myself, and it works fine.  Better than ctags/etags for python.

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


Re: ANN: pyTenjin 0.8.0 - much faster template engine than Django

2009-06-17 Thread Igor Katson

kwatch wrote:

I have released pyTenjin 0.8.0
  
Thanks for your project. I have used it a little, and there is a 
question to you.


import tenjin
from tenjin.helpers import *
shared_cache = tenjin.GaeMemcacheCacheStorage()
engine = tenjin.Engine(cache=shared_cache)

1. Why should I import tenjin.helpers if I don't use the helpers in my code?
2. Why does the code not work if I don't import the helpers?

I think you should manage this issue inside the library.
--
http://mail.python.org/mailman/listinfo/python-list


Re: persistent composites

2009-06-17 Thread Aaron Brady
On Jun 16, 10:09 am, Mike Kazantsev mk.frag...@gmail.com wrote:
 On Tue, 16 Jun 2009 06:57:13 -0700 (PDT)

 Aaron Brady castiro...@gmail.com wrote:
  Making the charitable interpretation that this was the extent of c-l-
  py's support and enthusiasm for my idea, I will now go into mourning.
  Death occurred at oh-eight-hundred.  Rest in peace, support 
  enthusiasm.

 I've read this thread from the beginning, being tempted to insert
 remarks about shelve module or ORMs like SQLAlchemy, but that'd be
 meaningless without the problem description, which I haven't seen
 anywhere. Is it some trick idea like let's walk on our heads?

More like bronze them, or hang them on a tackboard.  You haven't
convinced me that it's not a problem, or that it's an easy one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about None

2009-06-17 Thread Aaron Brady
On Jun 17, 5:47 am, Bruno Desthuilliers bruno.
42.desthuilli...@websiteburo.invalid wrote:
 John Yeung a écrit :
  But mathematically speaking, it's intuitive that nothing would match
  any type.

 IOW, what's the OP is after is not the None type, but some yet
 unexisting Anything type !-)

The behaviors of the 'anything' object are a subset of those of any
other object.

I don't believe that 'subset' is a proper characterization of the
relationship between the methods of a subclass and the methods of its
superclass.  But 'superset' may be.

Should 'object' inherit from None?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-17 Thread Mark Dickinson
On Jun 17, 3:46 pm, Paul Rubin http://phr...@nospam.invalid wrote:
 Mark Dickinson dicki...@gmail.com writes:
  It looks as though you're treating (a portion of?) the Koch curve as
  the graph of a function f from R - R and claiming that f is
  uniformly continuous.  But the Koch curve isn't such a graph (it
  fails the 'vertical line test',

 I think you treat it as a function f: R - R**2 with the usual
 distance metric on R**2.

Right.  Or rather, you treat it as the image of such a function,
if you're being careful to distinguish the curve (a subset
of R^2) from its parametrization (a continuous function
R - R**2).  It's the parametrization that's uniformly
continuous, not the curve, and since any curve can be
parametrized in many different ways any proof of uniform
continuity should specify exactly which parametrization is
in use.

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


Re: UDP queue size

2009-06-17 Thread Nick Craig-Wood
§ä´m¦Û¤vª�...@¤ù¤Ñ command@alexbbs.twbbs.org wrote:
  I got a problem about UDP.
 
  How do I get the UDP buffer size?
 
  When the server had some delay in handling incoming UDP, it will lost
  some package. I wonder it's because the system buffer size, is there any
  ways to find the exactly size of the buffer?
 
  ex:
 
  client.py
  import socket
 
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  for i in xrange(1000):
  s.sendto('xxx', ('192.168.1.135',1))
 
 
 
  server.py: in ip (192.168.1.135)
  import socket
  import time
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.bind(('',1))
  time.sleep(10)
 
  # here will only recv 255 package, others are lost...
  for i in xrange(1000):
  msg, addr = s.recvfrom(500)
  print i

I think you want setsockopt...

 import socket
 import time
 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 s.bind(('',1))
 s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
112640
 s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1048576)
 s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
262142


I ran the above on linux and I expect the limit 262144 is settable in
/proc/sys/net somewhere.

No idea whether the above works on windows!


-- 
Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: walking a directory with very many files

2009-06-17 Thread Mike Kazantsev
On Wed, 17 Jun 2009 23:04:37 +1200
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote:

 In message 20090617142431.2b25f...@malediction, Mike Kazantsev wrote:
 
  On Wed, 17 Jun 2009 17:53:33 +1200
  Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote:
  
   Why not use hex representation of md5/sha1-hashed id as a path,
   arranging them like /path/f/9/e/95ea4926a4 ?
   
   That way, you won't have to deal with many-files-in-path problem ...
  
  Why is that a problem?
  
  So you can os.listdir them?
 
 Why should you have a problem os.listdir'ing lots of files?

I shouldn't, and I don't ;)

-- 
Mike Kazantsev // fraggod.net


signature.asc
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-17 Thread pdpi
On Jun 17, 4:18 pm, Mark Dickinson dicki...@gmail.com wrote:
 On Jun 17, 3:46 pm, Paul Rubin http://phr...@nospam.invalid wrote:

  Mark Dickinson dicki...@gmail.com writes:
   It looks as though you're treating (a portion of?) the Koch curve as
   the graph of a function f from R - R and claiming that f is
   uniformly continuous.  But the Koch curve isn't such a graph (it
   fails the 'vertical line test',

  I think you treat it as a function f: R - R**2 with the usual
  distance metric on R**2.

 Right.  Or rather, you treat it as the image of such a function,
 if you're being careful to distinguish the curve (a subset
 of R^2) from its parametrization (a continuous function
 R - R**2).  It's the parametrization that's uniformly
 continuous, not the curve, and since any curve can be
 parametrized in many different ways any proof of uniform
 continuity should specify exactly which parametrization is
 in use.

 Mark

I was being incredibly lazy and using loads of handwaving, seeing as I
posted that (and this!) while procrastinating at work.

an even lazier argument: given the _/\_ construct, you prove that its
vertical growth is bound: the height of / is less than 1/3 (given a
length of 1 for ___), so, even if you were to build _-_ with the
middle segment at height = 1/3, the maximum vertical growth would be
sum 1/3^n from 1 to infinity, so 0.5. Sideways growth has a similar
upper bound. 0.5  1, so the chebyshev distance between any two points
on the curve is = 1. Ergo, for any x,y, f(x) is at most at chebyshev
distance 1 of (y). Induce the argument for smaller values of one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UDP queue size

2009-06-17 Thread Martin P. Hellwig
Scott David Daniels wrote:
 找尋自己的一片天 wrote:
 I got a problem about UDP.

 How do I get the UDP buffer size?

 When the server had some delay in handling incoming UDP, it will lost
 some package. I wonder it's because the system buffer size, is there any
 ways to find the exactly size of the buffer?
 
 UDP is defined as best effort then give up, so _everything_ that
 handles a UDP packet is allowed to drop it; that means switchers,
 routers, ..., anything along the path to the target application.
 So, you cannot expect to do any better than a conservative guess,
 perhaps augmented by dynamic scaling.
 
 --Scott David Daniels
 scott.dani...@acm.org

I would like to add, that you are most likely to lose packages because
they are to big, I can not remember for sure if UDP had a fixed limit
above what the MTU does, but you might want to look at that direction too.

-- 
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing a python script while it is running

2009-06-17 Thread bobicanprogram
On Jun 17, 1:42 am, Zach Hobesh hob...@gmail.com wrote:
 On Tue, Jun 16, 2009 at 6:37 PM, Chris Rebertc...@rebertia.com wrote:
  On Tue, Jun 16, 2009 at 6:21 PM, hob...@gmail.com wrote:
  Hey Dave,

  Thanks for the helpful responses.

  Option 2 is what you get by default.  Naturally it depends on what the
  application  is using to launch the batch file, but the most common cases
  will launch a separate process.

  The app ended up delaying starting the second batch file until it finished
  the first. I had the app trigger an infinite loop on completion, and sent
  two files through at the same time. The second file finished seconds after
  the first, but the batch file didn't trigger until I closed the first one.

  Are you sure you aren't unknowingly having the app wait on the first
  batch file process until it terminates? How exactly are you launching
  the batch files?

  Cheers,
  Chris
  --
 http://blog.rebertia.com

 Hey Chris,

 I actually think that's what's happening, which is fine in my case
 (for now anyway) as I just need them all to complete, we don't need
 them running at the same time.  I'm using a job management system, and
 they have the option of triggering a command line after completing a
 job.

 A better/safer solution might be spawning another job and re-inserting
 to the jms queue.

 Thanks again,

 Zach


You might want to take a look at the Python-SIMPL toolkit (http://
www.icanprogram.com/06py/main.html).   SIMPL uses a Send/Receive/Reply
interprocess messaging scheme which will naturally queue requests for
you.   Without too much effort you may be able to reorient your scheme
to eliminate the batch file entirely.

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


exit() or sys.exit()

2009-06-17 Thread Brendan
What is the difference on exit() and sys.exit() when called in the
main body of a script? From the command line they seem to have the
same effect.

Aside: Just used a python dictionary in which the keys were compiled
regular expressions. Provided a very elegant solution. Have to love it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exit() or sys.exit()

2009-06-17 Thread Tim Chase

Brendan wrote:

What is the difference on exit() and sys.exit() when called in the
main body of a script? From the command line they seem to have the
same effect.


In Python =2.4 you had to use sys.exit() because 
__builtins__.exit() griped:


  tch...@asgix:~$ python2.4
  Python 2.4.4 (#2, Apr 15 2008, 23:43:20)
  [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type help, copyright, credits or license for more 
information.

   type(exit)
  type 'str'
   exit()
  Traceback (most recent call last):
File stdin, line 1, in ?
  TypeError: 'str' object is not callable

In 2.5, it's an instance of site.Quitter which is callable, 
allowing it to behave like sys.exit()  (from my observations, 
__builtins__.exit() and sys.exit() behave the same).


I tend to use sys.exit() because I've still got code running on 
machines mired at 2.4


-tkc




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


Re: Executing a python script while it is running

2009-06-17 Thread Aaron Brady
On Jun 16, 3:48 pm, Zach Hobesh hob...@gmail.com wrote:
  A lot more information would be useful.  What version of Python, and what
  operating system environment?  Exactly what would you like to happen when
  the batch file is invoked a second time?

 I'm running Python 2.6.2 on Windows.  I'm passing filenames to the
 batch files and I need all filenames to be processed.  I can't have
 any fails.  I'm working on logging any fails I do have so that I can
 maybe batch process at the end of the day.

   2) let them both run as separate processes

 This sounds like a good option, but I'm not totally sure on how to go
 about this?

   4) queue something to be processed when the first run finishes

 I had the same idea, but I believe it would involve having another
 python script run all day long, which wouldn't necessarily be a bad
 thing, but I'd like to explore other options as well.

This sort of falls under both categories, 2  4, and it will probably
be judged 'poor practice' by history.  We're all historians now, I
guess.

Windows has what's called a 'named mutex' for interprocess
synchro'tion.  Start your new process, acquire their shared mutex by
name, and block on it.  You will have one process for each file, but
only one will run at once.

You won't even need to build a shared library; 'ctypes' will suffice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exotic Logics

2009-06-17 Thread Lie Ryan
Steven D'Aprano wrote:
 On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:
 
 I was staring at a logic table the other day, and I asked myself, what
 if one wanted to play with exotic logics; how might one do it?
 
 
 This might be useful for you, and if not useful, at least it might blow 
 your mind like it did mine.
 
 (This is not original to me -- I didn't create it. However, I can't find 
 the original source.)
 
 Imagine for a moment that there are no boolean values. 
 There are no numbers.  They were never invented.
 There are no classes.
 There are no objects.
 There are only functions.
 
 Could you define functions that act like boolean values? And could you 
 define other functions to operate on them?
 
 
 def true(x, y):
 return x
 
 def false(x, y):
 return y
 
 def print_bool(b):
 print b(true, false)
 

String isn't considered object?

Also, b/true()/false() is a function object, isn't it? Unless function
is first-class, you can't pass them around like that, since you need a
function pointer (a.k.a number); but if function is first-class then
there it is an object.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exotic Logics

2009-06-17 Thread Aaron Brady
On Jun 17, 1:44 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:
  I was staring at a logic table the other day, and I asked myself, what
  if one wanted to play with exotic logics; how might one do it?

 This might be useful for you, and if not useful, at least it might blow
 your mind like it did mine.

 (This is not original to me -- I didn't create it. However, I can't find
 the original source.)

 Imagine for a moment that there are no boolean values.
 There are no numbers.  They were never invented.
 There are no classes.
 There are no objects.
 There are only functions.

 Could you define functions that act like boolean values? And could you
 define other functions to operate on them?
snip

I think high and low /voltages/, though continuous and approximate,
might satisfy this.

There are no such things as electrons, only variations in density of
the luminiferous ether.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ODE, GUI, plotter in Python

2009-06-17 Thread Rob Clewley
There was just an announcement on this list and the scipy list for
PyLab_Works, which sounds exactly like what you're looking for. I
would not recommend starting over with a new simulator at this point.
-Rob

On Tue, Jun 16, 2009 at 12:00 PM, Alashaib...@ymail.com wrote:
 Hello everyone.

 I am starting on implementing a simulator using python, and since it's
 the first time I code in python would appreciate a few pointers:

 The simulator will use a coupled ODE for the most part of the
 simulation, I plan to use scipy. (Anything considered faster/better
 than scipy for solving coupled ODEs? )

 I plan for a GUI program with network graph plotting. I am leaning
 towards using Qt for the GUI (internet forums seem to recommend it,
 anyone got other preferences? )

 Since the GUI application will contain few buttons and a plot, I am
 planning to implement matplotlib into the GUI. But does anyone know if
 matplotlib allows for interaction with the graph plot? (say for a
 network simulation, allowing to right click on nodes and disable them
 for instance, or alter some other properties of nodes and/or links
 across them).

 I am just starting out, hence I'd rather get some advice and experiment
 a bit for my self as I go along.

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


Re: Exotic Logics

2009-06-17 Thread Aaron Brady
On Jun 17, 1:28 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:
  I was staring at a logic table the other day, and I asked myself, what
  if one wanted to play with exotic logics; how might one do it?

 First question: what's an exotic logics?

 Do you mean things like three-value logic, fuzzy logic, probabilistic
 reasoning, etc?

You (OP) may be interested in the definitions of the fuzzy operators:

and( x, y ) := min( x, y )
or( x, y ) := max( x, y )
not( x ) := 1 (one)- x
nand( x, y ) := not( and( x, y ) ) = 1- min( x, y )

Defining 'xor' as '( x or y ) and ( not( x and y ) )', we have:

xor( x, y ) := min( max( x, y ), 1- min( x, y ) )

However, defining 'xor' as '( x and not y ) or ( y and not x )', we
don't have:

xor( x, y ) := max( min( x, 1- y ), min( y, 1-x ) )

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


Re: Exotic Logics

2009-06-17 Thread pdpi
On Jun 17, 5:37 pm, Lie Ryan lie.1...@gmail.com wrote:
 Steven D'Aprano wrote:
  On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:

  I was staring at a logic table the other day, and I asked myself, what
  if one wanted to play with exotic logics; how might one do it?

  This might be useful for you, and if not useful, at least it might blow
  your mind like it did mine.

  (This is not original to me -- I didn't create it. However, I can't find
  the original source.)

  Imagine for a moment that there are no boolean values.
  There are no numbers.  They were never invented.
  There are no classes.
  There are no objects.
  There are only functions.

  Could you define functions that act like boolean values? And could you
  define other functions to operate on them?

  def true(x, y):
      return x

  def false(x, y):
      return y

  def print_bool(b):
      print b(true, false)

 String isn't considered object?

 Also, b/true()/false() is a function object, isn't it? Unless function
 is first-class, you can't pass them around like that, since you need a
 function pointer (a.k.a number); but if function is first-class then
 there it is an object.

What Steven was doing was implementing some of the more basic stuff
from Lambda calculus in python. If you're implementing a different
system in an existing language, you'll need to use _some_ facilities
of the original language to interface with the outside world. Anyway,
here's a sample interactive session I just tried:

 def a(stuff):
... print stuff
...
 def b(stuff):
...  stuff(abc)
...
 b(a)
abc

functions are first-class citizens in python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exit() or sys.exit()

2009-06-17 Thread Brendan
On Jun 17, 1:33 pm, Tim Chase python.l...@tim.thechases.com wrote:
 Brendan wrote:
  What is the difference on exit() and sys.exit() when called in the
  main body of a script? From the command line they seem to have the
  same effect.

 In Python =2.4 you had to use sys.exit() because
 __builtins__.exit() griped:

    tch...@asgix:~$ python2.4
    Python 2.4.4 (#2, Apr 15 2008, 23:43:20)
    [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
 Type help, copyright, credits or license for more
 information.
     type(exit)
    type 'str'
     exit()
    Traceback (most recent call last):
      File stdin, line 1, in ?
    TypeError: 'str' object is not callable

 In 2.5, it's an instance of site.Quitter which is callable,
 allowing it to behave like sys.exit()  (from my observations,
 __builtins__.exit() and sys.exit() behave the same).

 I tend to use sys.exit() because I've still got code running on
 machines mired at 2.4

 -tkc

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


Re: Exotic Logics

2009-06-17 Thread Aaron Brady
On Jun 17, 10:04 am, Aaron Brady castiro...@gmail.com wrote:
snip
 You (OP) may be interested in the definitions of the fuzzy operators:

 and( x, y ) := min( x, y )
 or( x, y ) := max( x, y )
 not( x ) := 1 (one)- x
 nand( x, y ) := not( and( x, y ) ) = 1- min( x, y )

 Defining 'xor' as '( x or y ) and ( not( x and y ) )', we have:

 xor( x, y ) := min( max( x, y ), 1- min( x, y ) )

 However, defining 'xor' as '( x and not y ) or ( y and not x )', we
 don't have:

 xor( x, y ) := max( min( x, 1- y ), min( y, 1-x ) )

Corollary:

xor1( x, y ) === xor2( x, y ).

Non-exhaustive demonstration, excerpt:

 def xor1( x, y ):
... return min( max( x, y ), 1- min( x, y ) )
...
 def xor2( x, y ):
... return max( min( x, 1- y ), min( y, 1- x ) )
...
 for i in range( 0, 11, 2 ):
... for j in range( 0, 11, 2 ):
... print i, j, xor2( x, y )*10, '  ',
... print

0 0 0.00 2 2.00 4 4.00 6 6.00 8 8.0
2 0 2.02 2 2.02 4 4.02 6 6.02 8 8.0
4 0 4.04 2 4.04 4 4.04 6 6.04 8 6.0
6 0 6.06 2 6.06 4 6.06 6 4.06 8 4.0
8 0 8.08 2 8.08 4 6.08 6 4.08 8 2.0
10 0 10.0  10 2 8.0   10 4 6.0   10 6 4.0   10 8 2.0

They appear to be equal.

I forgot to mention, fuzzy values take on values from the continuous
open or closed range 0 to 1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exotic Logics

2009-06-17 Thread Mensanator
On Jun 17, 11:59 am, Aaron Brady castiro...@gmail.com wrote:
 On Jun 17, 1:44 am, Steven D'Aprano



 ste...@remove.this.cybersource.com.au wrote:
  On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:
   I was staring at a logic table the other day, and I asked myself, what
   if one wanted to play with exotic logics; how might one do it?

  This might be useful for you, and if not useful, at least it might blow
  your mind like it did mine.

  (This is not original to me -- I didn't create it. However, I can't find
  the original source.)

  Imagine for a moment that there are no boolean values.
  There are no numbers.  They were never invented.
  There are no classes.
  There are no objects.
  There are only functions.

  Could you define functions that act like boolean values? And could you
  define other functions to operate on them?

 snip

 I think high and low /voltages/, though continuous and approximate,
 might satisfy this.

 There are no such things as electrons,

I've got a Tesla coil if you'd like to meet some electrons personally.

 only variations in density of
 the luminiferous ether.

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


Re: Exotic Logics

2009-06-17 Thread Aaron Brady
On Jun 17, 10:05 am, pdpi pdpinhe...@gmail.com wrote:
 On Jun 17, 5:37 pm, Lie Ryan lie.1...@gmail.com wrote:



  Steven D'Aprano wrote:
   On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:

   I was staring at a logic table the other day, and I asked myself, what
   if one wanted to play with exotic logics; how might one do it?

   This might be useful for you, and if not useful, at least it might blow
   your mind like it did mine.

   (This is not original to me -- I didn't create it. However, I can't find
   the original source.)

   Imagine for a moment that there are no boolean values.
   There are no numbers.  They were never invented.
   There are no classes.
   There are no objects.
   There are only functions.

   Could you define functions that act like boolean values? And could you
   define other functions to operate on them?

   def true(x, y):
       return x

   def false(x, y):
       return y

   def print_bool(b):
       print b(true, false)

  String isn't considered object?

  Also, b/true()/false() is a function object, isn't it? Unless function
  is first-class, you can't pass them around like that, since you need a
  function pointer (a.k.a number); but if function is first-class then
  there it is an object.

 What Steven was doing was implementing some of the more basic stuff
 from Lambda calculus in python. If you're implementing a different
 system in an existing language, you'll need to use _some_ facilities
 of the original language to interface with the outside world.

Sir!  Entropy levels are approaching dangerously low levels.  We don't
even have enough entropy to fi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exotic Logics

2009-06-17 Thread Aaron Brady
On Jun 17, 10:23 am, Mensanator mensana...@aol.com wrote:
 On Jun 17, 11:59 am, Aaron Brady castiro...@gmail.com wrote:



  On Jun 17, 1:44 am, Steven D'Aprano

  ste...@remove.this.cybersource.com.au wrote:
   On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:
I was staring at a logic table the other day, and I asked myself, what
if one wanted to play with exotic logics; how might one do it?

   This might be useful for you, and if not useful, at least it might blow
   your mind like it did mine.

   (This is not original to me -- I didn't create it. However, I can't find
   the original source.)

   Imagine for a moment that there are no boolean values.
   There are no numbers.  They were never invented.
   There are no classes.
   There are no objects.
   There are only functions.

   Could you define functions that act like boolean values? And could you
   define other functions to operate on them?

  snip

  I think high and low /voltages/, though continuous and approximate,
  might satisfy this.

  There are no such things as electrons,

 I've got a Tesla coil if you'd like to meet some electrons personally.

The Wall Street Journal ran an article about Asian pleasure markets;
they provide a-- quote-- perfectly reasonable professional option.
-- 
http://mail.python.org/mailman/listinfo/python-list


Pythonic way to overwrite a file

2009-06-17 Thread Cameron Pulsford
Hey all, hopefully a simple question.
I'm writing a simple python tool that opens a file, and does something like

for line in file.readlines():
temp.write(line.doStuff())

However, I want to provide the option do this in place, as in have the
destination file be the same as the source file. Currently, I am writing to
a temp file and then using os.system('mv %s %s' % (dstfile, srcfile)) to
copy the destination file onto the soruce file. This is extremely ugly
though, and will only work on unix based systems (I'm guessing, unless
windows has mv too). Is there a more pythonic way to do this? Ideally I'd
like to change the file as I go through it and not deal with a second file
at all. That wouldn't have any atomicity though... What would be the most
pythonic+safest way to do this?

Thanks in advance
-- 
http://mail.python.org/mailman/listinfo/python-list


Create 3D Surface / Contour (with vpython?)

2009-06-17 Thread Philip Gröger
Hi!
How can I create a 3D surface (or something like the picture on the FAQ page
http://www.vpython.org/contents/FAQ.html ) with python [or vpython]. Didnt
find anything in the Documentation under graph
Basically like a contourf diagram in 3D (
http://www.techsoft.de/german/documents/images/3D_contour2.jpg). I think you
know what I mean.

Reason: I want to simulate waves in a square basin. Hope I dont need to use
hundrets of little spheres (in case of vpython) for the surface ;)

Thanks alot

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


Re: Pythonic way to overwrite a file

2009-06-17 Thread Ben Charrow

Cameron Pulsford wrote:
 Hey all, hopefully a simple question.
 
 I'm writing a simple python tool that opens a file, and does something like
 
 for line in file.readlines():
 temp.write(line.doStuff())
 
 However, I want to provide the option do this in place, as in have the
 destination file be the same as the source file. 
snip
 

Is loading the whole file into memory an option?  If so, this should work:

filename = spam.txt
lines = open(filename).readlines()# Read
new = [somefunction(line) for line in lines]  # Change
open(filename, 'w').writelines(new)   # Write

If you want to stick with your original approach, but want it to work cross
platform, then I think this is what you want:

http://docs.python.org/library/shutil#shutil.move

HTH,
Ben
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way to overwrite a file

2009-06-17 Thread Jean-Michel Pichavant

Cameron Pulsford wrote:

Hey all, hopefully a simple question.

I'm writing a simple python tool that opens a file, and does something 
like


for line in file.readlines():
temp.write(line.doStuff())

However, I want to provide the option do this in place, as in have 
the destination file be the same as the source file. Currently, I am 
writing to a temp file and then using os.system('mv %s %s' % 
(dstfile, srcfile)) to copy the destination file onto the soruce 
file. This is extremely ugly though, and will only work on unix based 
systems (I'm guessing, unless windows has mv too). Is there a more 
pythonic way to do this? Ideally I'd like to change the file as I go 
through it and not deal with a second file at all. That wouldn't have 
any atomicity though... What would be the most pythonic+safest way to 
do this? 


Thanks in advance



Altering directly the file is dangerous, what if something goes wrong 
during the process ?

Create a temp file and copying it if successful is your best bet.

I guess using python modules like tempfile and shutil are  a pythonic 
way to do it :


import tempfile
import shutil

In [14]: tempfile.NamedTemporaryFile?
Definition: tempfile.NamedTemporaryFile(mode='w+b', bufsize=-1, 
suffix='', prefix='tmp', dir=None)

Docstring:
   Create and return a temporary file.
   Arguments:
   'prefix', 'suffix', 'dir' -- as for mkstemp.
   'mode' -- the mode argument to os.fdopen (default w+b).
   'bufsize' -- the buffer size argument to os.fdopen (default -1).
   The file is created as mkstemp() would do it.

   Returns an object with a file-like interface; the name of the file
   is accessible as file.name.  The file will be automatically deleted
   when it is closed.


In [7]: shutil.copy?
Definition: shutil.copy(src, dst)
Docstring:
   Copy data and mode bits (cp src dst).

   The destination may be a directory.


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


Re: Pythonic way to overwrite a file

2009-06-17 Thread Cameron Pulsford
Essentially it just cleans up a source file of erroneous spaces and tabs and
can also convert tabs to spaces so loading the whole file into memory is
possibly an option. I am making this utility for personal use, and that
would definitely be fine, but if it turned out well I'd open source it and
then I wouldn't be so sure. This is only supposed to handle text files, so
when would reading it all into memory become too much for most computers?
I'm guessing there aren't many source files of too great a size.

On Wed, Jun 17, 2009 at 2:09 PM, Jean-Michel Pichavant 
jeanmic...@sequans.com wrote:

 Cameron Pulsford wrote:

 Hey all, hopefully a simple question.

 I'm writing a simple python tool that opens a file, and does something
 like

 for line in file.readlines():
temp.write(line.doStuff())

 However, I want to provide the option do this in place, as in have the
 destination file be the same as the source file. Currently, I am writing to
 a temp file and then using os.system('mv %s %s' % (dstfile, srcfile)) to
 copy the destination file onto the soruce file. This is extremely ugly
 though, and will only work on unix based systems (I'm guessing, unless
 windows has mv too). Is there a more pythonic way to do this? Ideally I'd
 like to change the file as I go through it and not deal with a second file
 at all. That wouldn't have any atomicity though... What would be the most
 pythonic+safest way to do this?
 Thanks in advance


 Altering directly the file is dangerous, what if something goes wrong
 during the process ?
 Create a temp file and copying it if successful is your best bet.

 I guess using python modules like tempfile and shutil are  a pythonic way
 to do it :

 import tempfile
 import shutil

 In [14]: tempfile.NamedTemporaryFile?
 Definition: tempfile.NamedTemporaryFile(mode='w+b', bufsize=-1,
 suffix='', prefix='tmp', dir=None)
 Docstring:
   Create and return a temporary file.
   Arguments:
   'prefix', 'suffix', 'dir' -- as for mkstemp.
   'mode' -- the mode argument to os.fdopen (default w+b).
   'bufsize' -- the buffer size argument to os.fdopen (default -1).
   The file is created as mkstemp() would do it.

   Returns an object with a file-like interface; the name of the file
   is accessible as file.name.  The file will be automatically deleted
   when it is closed.


 In [7]: shutil.copy?
 Definition: shutil.copy(src, dst)
 Docstring:
   Copy data and mode bits (cp src dst).

   The destination may be a directory.



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


Re: Observer implementations

2009-06-17 Thread Mike C. Fletcher
Tobias Weber wrote:
 In article mailman.1631.1245160392.8015.python-l...@python.org,
  Mike C. Fletcher mcfle...@vrplumber.com wrote:

   
 See PyDispatcher for code to do this.
 

 That was the original problem. Got it now: if used inside the class 
 definition dispatcher.connect will raise cannot create weak reference 
 to 'classmethod' object. Outside (using Class.method) it works fine.
   
Ah, I think you've got a logic problem there.  The classmethod during
class creation has no reference to the class being created, so if you
were to call *that* thing it would blow up:

class x( object ):
@classmethod
def y( cls, text ):
print text
y( 'No you do not!' )

if you were to create a reference to *that* thing (the decorated
un-bound class method) it would never have the binding for cls, so it
wouldn't do anything.  The correct way IMO to bind after-class-creation
(e.g. by a class decorator or metaclass) where you reference a bound
class method.  If you *really* want to do it this way, you can do
something like this:

class x( object ):
@classmethod
def y( cls, value ):
pass
dispatcher.connect( lambda *args: x.y( *args ), signal='hello' )

but ick.

HTH,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: Regarding Python is scripting language or not

2009-06-17 Thread Ken Seehart

abhishek goswami wrote:

Hi,
I have very basic question about Python that do we consider pyhton as 
script language.
I searched in google but it becomes more confusion for me. After some 
analysis I came to know that Python support oops .


Can anyone Guide me that Python is Oject oriented programming language 
or Script language


Abhishek Goswami
Chennai
Phone No -0996227099

ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET 
http://in.rd.yahoo.com/tagline_cricket_3/*http://cricket.yahoo.com 
Both.  Especially if you define the terms object oriented and 
scripting in terms of positive space (attributes that are present) 
instead of negative space (attributes that are not present).


Python has all of the important features of OOP, but lacks some of the 
imposed constraints that some consider to be part of the definition of 
OOP (I personally do not consider the constraints to be central to a 
useful definition of OOP)


Python has all of the important features that one would want in a 
scripting language (although it has a larger memory footprint than some 
scripting languages), but lacks many of limitations associated with toy 
languages.


Python is somewhat unique in it's ability to fill both of these areas so 
well without being unnatural.  In my opinion, it is extremely useful to 
have one language that serves as both a highly scalable full-featured 
OOP language and as an extremely simple scripting language, because it 
allows one to build a large complex system within which one can easily 
do scripting tasks.


Proof that python is a scripting language:

   print Hello world

Proof that python is an OOP language benefiting from scripting capabilities:

  Django comes to mind.  There are hundreds of others out there, but 
instead of listing them, I think I will get back to programming.


Ken


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


Re: Regarding Python is scripting language or not

2009-06-17 Thread Terry Reedy

Jochen Schulz wrote:

abhishek goswami:

Can anyone Guide me that Python is Oject oriented programming language
or Script language


In my opinion, Python is both. But an objective answer would require
you to define what you means by these terms.

If, by object-oriented you mean everything has to be put into
classes, then Python is not object-oriented.


That depends on what you mean by 'put into classes' (and 'everything').

If you mean 'be an instance of a class', which I think is the most 
natural reading, then Python *is* object-oriented and, if I understand 
what I have read correctly (so that ints are just (unboxed) ints and not 
members of an int class), Java *is not*!


If you mean 'be an attribute of a class' (which to me is not 'in') or 
textually located within a class statement, then I doubt an language 
qualifies. It is impossible for every class statement to lie within a 
class statement and I wonder whether any language requires all classes 
to be attributes of some class (as opposed to subclasses or instances).


However, if 'everything' means 'everything but classes', then, as I 
understand, Java and some others qualify.


If fact, if one views modules as classes that cannot be instanced or as 
classes with one instance, themselves, then Python also qualifies.


Python also qualifies if you mean 'be in some attribute of a class' and 
view modules as classes.  *All* modules are values of sys.modules, 
including builtins, __main__, and sys itself.


 If, by scripting

language you mean Python is an error-prone toy language, unsuitable for
large, serious projects, then Python is not a scripting language either.


On the other hand, CPython is designed to be extended by and thereby 
script code written in C and C-wrapped Fortran. This is a big part of 
why it uses reference-counting for garbage collection.  It also has 
functions for running other processes and interacting with other processes.


Terry Jan Reedy


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


Re: Exotic Logics

2009-06-17 Thread William Clifford
On Jun 17, 1:28 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote:
  I was staring at a logic table the other day, and I asked myself, what
  if one wanted to play with exotic logics; how might one do it?

 First question: what's an exotic logics?

 Do you mean things like three-value logic, fuzzy logic, probabilistic
 reasoning, etc?

 Or do you mean logical operators others than and, or, xor, nand, nor, etc?

 Or both? Something else?

The short answer is 'yes'.

Obviously, I don't know much about this stuff. I was looking a table
of different
operators and their truth values and saw that these were just
different ways of
reading and comparing numbers. I wrote this code to explore this idea
in a
general sense and see where it leads and learn something about
computers.

 [...]

 If (nearly) all your methods are static methods, chances are a class is
 the wrong solution. Why not just define the static methods as top-level
 functions?

That is exactly how they started. I wrapped them up in an class
because I
thought I might want to create a bunch of them for testing and
experimentation. I'm curious to see how combinations of functions give
the
same (or different) results. I've read one can do all of the 16
binary
operations with clever uses of NAND or NOR.

[SNIP]

 You're implementation seems rather confusing. I think that's partly
 because you use lots of abbreviated jargon terms that mean little or
 nothing to me: rdx, opr (operator?), lsd, pute.

Sorry about the confusion. It's because I'm confused. I should check
out a book on the subject. Thanks for your help.

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


Re: strptime issue in multi-threaded application

2009-06-17 Thread Joe Holloway
Christian wrote:

 Joe Holloway schrieb:
  ImportError: Failed to import _strptime because the import lockis
  [sic] held by another thread.

 The error message is my fault. The cause of the mistake is obvious:

No worries. The error message is clear even with the minor typo, I
just wanted to recreate it here in case someone is searching for it
down the road.

  Like I mentioned, it's only happened on a couple occasions because the
  right conditions have to be in place, but something doesn't seem right
  about it.  I thought I'd ask on the mailing list before going so far
  as to open a ticket, but feel free to direct me there if that's the
  appropriate place for this.

 I have an idea what might happen in your application. Is an import
 triggering the start of a thread?

Not that I'm aware of.  When the error is triggered, my module is
simply calling into a library that's then calling into
time.striptime().  The import that fails seems to be just a side
effect of this.

 You can get around the issue by decoupling imports from thread
 startups. Your application should import all modules before it
 starts its threaded components.

To give you a better idea of the scenario, this is a Django web
application deployed inside a WSGI container (mod_wsgi+Apache2).
Ultimately, I'm not sure I have any control over when the imports
occur since the WSGI container is what's managing the threads and my
application is just being plugged into that container, if that makes
sense.

Consider that two URL handlers are likely be implemented in separate
modules and hence both require a different set of imports.  If both
are served concurrently and one of them is making the first call to
strptime while the other one has acquired the import lock, this can
fail.  Failing is obviously better than deadlocking, but it seems like
pushing the workaround higher up in the call stack would cause some
serious abstraction leaks.  I don't fully understand what was causing
the original deadlock, but my module should be able to call into
time.strptime without incurring an ImportError or a deadlock under any
circumstance?

 For now you can decrease the severity of your issue by placing import
 _strptime next to import time somewhere in your code. Once it a
 module is loaded PyImport_ImportModuleNoBlock() will not fail to import
 it a second time.

Thanks for the workaround. I'm not all that concerned about the
functional impact this has on my application since it has only
happened a couple of times over the course of 6 weeks or so.  My
intent was more to make it visible in case there's a deeper design
issue that can be addressed.

Take care,
Joe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A simpler logging configuration file format?

2009-06-17 Thread Vinay Sajip
On Jun 5, 9:07 pm, geoff.ba...@gmail.com wrote:
 Hi all,

Some discussion about this has already taken place on the issue
tracker:

http://bugs.python.org/issue6136

and I thought I would summarise my comments there on this thread, for
people who have no need to look at that issue.

 At the moment, if I want to add a new logger foo writing to its own
 file foo to my config file, I have to repeat the name 7(!) times,
 editing 3 different sections in the process:

Strictly speaking, you don't need to repeat the name foo 7 times.

 1) Add foo to [loggers] and [handlers]. (These seem completely
 pointless and were apparently added in anticipation of new
 functionality that never happened).

You don't have to call the logger foo and the handler foo. The
names in the [loggers] and [handlers] section are just to allow the
system to cross-refer different entities (loggers, handlers,
formatters) declared in the config file. You could give the logger a
name of L1 and the handler a name of H1, for example.

 2) Create the section
 [logger_foo]
 handler:foo
 qualname:foo
 level:INFO

Here, if you named your logger L1, the section would be [logger_L1],
not [logger_foo]. If you called your handler H1, then the handler line
would be handlers=H1. The qualname is foo because you choose to log
events to the logger named foo. It could be more specific, e.g.
myapp.mymodule.myfunctionalarea.

 3) Create the section
 [handler_foo]
 class: FileHandler
 args:(foo, a)

Here, if you named your handler H1, the section would be [handler_H1],
not [handler_foo]. You've also called the log file foo, which more
conventionally you might name foo.log.

In your simple example where everything is named foo, and you've
chosen to call cross-referencing handles within the file foo, then
naturally you repeat foo a lot of times. In an equivalent file

[loggers]
keys=root,L1

[handlers]
keys=H1

[logger_L1]
level=INFO
handlers=H1
qualname=foo

[handler_H1]
class=FileHandler
args=('foo.log', 'w')


foo only occurs twice.

 Wondering how it got like this, I found this blog from soon after it
 was released in 2004:

 http://www.mechanicalcat.net/richard/log/Python/Simple_usage_of_Pytho...

 Some of the verdicts are full of dead chickens and error prone,
 horribly complicated , over-engineered. So along comes the
 basicConfig method in 2005 which is supposed to address thes
 concerns. But this can only be applied globally, not even to
 individual loggers, so is only helpful for extremely basic usage
 (everything to one target) as far as I can see. The config file is
 still much as it was then.

Some of this is just a consequence of using ConfigParser. The existing
file format is not perfect or even complete (for example - no support
for filters), and was proposed on python-dev for review before the
logging package went into Python. The general consensus was that it
was OK for basic use, and IIRC several people considered it as +0 or
-0 because they envisaged doing their own thing (e.g. having the
logging configuration as just part of an application's overall
configuration). This is the reason configuration was put in a separate
sub-module - if it's not needed, it needn't be loaded. AFAICT since
basicConfig was introduced and later refined, there has not been much
feedback about the configuration file format being a problem - and
while that could be because no-one is using it, that's not borne out
by the evidence. There have been numerous instances on c.l.py where
questions have been raised about how to specify custom handlers in the
configuration file, so at least some people are using it or have used
it (the configuration functionality, I mean).

 I'd really like to see the concept extended to encompass multiple
 loggers and the config file. Allowing Logger.basicConfig should be
 trivial. Writing a configuration format which took a section and
 passed all the options in it to basicConfig would in my view lead to a
 much friendlier syntax for normal usage.

Well, basicConfig is for basic configuration of the logging package as
a whole, not for configuring individual loggers or handlers. It's best
not to conflate loggers and handlers - basicConfig might appear to do
this because its arguments are partly specifying handler configuration
and partly logger configuration. This is because it's the simplest
case - one logger (the root logger) and one handler (according to the
relevant arguments passed in). The handler-related arguments are used
to create a default handler and/or formatter, the logging level is
specified by the level argument, and it's applied to the root logger.

It doesn't make sense to use the same approach if you are going to
configure multiple loggers and handlers; if the existing format is not
palatable, it's relatively easy to create your own format and write
code to parse it and load it, and then call the programmatic API to
configure logging appropriately. You mentioned on the bug tracker that
you are coming from a background of 

Re: Exotic Logics

2009-06-17 Thread Terry Reedy

William Clifford wrote:


same (or different) results. I've read one can do all of the 16
binary
operations with clever uses of NAND or NOR.


The book Laws of Form, by Spencer-Brown' is based on that observation, 
with nand/nor expanded to n-ary 'bag' functions (like sum() is).

I recommend it, especially if you can find it in a library.

tjr

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


Re: Regarding Python is scripting language or not

2009-06-17 Thread Christian Heimes
Terry Reedy wrote:
 If you mean 'be an instance of a class', which I think is the most
 natural reading, then Python *is* object-oriented and, if I understand
 what I have read correctly (so that ints are just (unboxed) ints and not
 members of an int class), Java *is not*!

A friend of mine calls Java and C++ class centric programming languanges. ;)

Christian

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


Re: Create 3D Surface / Contour (with vpython?)

2009-06-17 Thread Gökhan SEVER
On Wed, Jun 17, 2009 at 12:58 PM, Philip Gröger 
philip.groe...@googlemail.com wrote:

 Hi!
 How can I create a 3D surface (or something like the picture on the FAQ
 page http://www.vpython.org/contents/FAQ.html ) with python [or vpython].
 Didnt find anything in the Documentation under graph
 Basically like a contourf diagram in 3D (
 http://www.techsoft.de/german/documents/images/3D_contour2.jpg). I think
 you know what I mean.

 Reason: I want to simulate waves in a square basin. Hope I dont need to use
 hundrets of little spheres (in case of vpython) for the surface ;)

 Thanks alot

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


I suggest two alternatives, second one being the fancier:

http://matplotlib.sourceforge.net/examples/mplot3d/surface3d_demo.html

http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/mlab_helper_functions.html#enthought.mayavi.mlab.surf
-- 
http://mail.python.org/mailman/listinfo/python-list


SHM and Touchpad

2009-06-17 Thread Sparky
Hello! I am writing an application that requires access to the state
of a synaptics touch pad on a laptop running Ubuntu Linux (for the
number of fingers, pressure, x location, y location, etc). A different
program using C++ accesses the information through SHM and I was
hoping to do the same with Python. I looked in PyPi and I noticed that
there was a module for SHM but I can not figure out where to download
it from (http://pypi.python.org/pypi/shm). Does anyone have any
suggestions?

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


Re: Perl's @foo[3,7,1,-1] ?

2009-06-17 Thread J. Cliff Dyer
On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote:
 On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote:
  What's np.arange?
  
 
  import numpy as np
 
  --
  Pierre delroth Bourdon delr...@gmail.com
  Étudiant à l'EPITA / Student at EPITA

 
 Perfect example of why renaming namespaces should be done only when 
 absolutely required, that is, almost never.
 
 Jean-Michel

I disagree.  Renaming namespaces should always be done if it will help
stop people from doing a 'from package import *'.  However, example code
should always include relevant imports.

Cheers,
Cliff


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


Re: SHM and Touchpad

2009-06-17 Thread Philip Semanchuk


On Jun 17, 2009, at 3:56 PM, Sparky wrote:


Hello! I am writing an application that requires access to the state
of a synaptics touch pad on a laptop running Ubuntu Linux (for the
number of fingers, pressure, x location, y location, etc). A different
program using C++ accesses the information through SHM and I was
hoping to do the same with Python. I looked in PyPi and I noticed that
there was a module for SHM but I can not figure out where to download
it from (http://pypi.python.org/pypi/shm). Does anyone have any
suggestions?



Hi Sam,
I'm not familiar with that shm, however there was (and still is) a old  
Python IPC module called shm. It uses Sys V semaphores, not POSIX  
semaphores like the shm in pypi.


The old shm module has been replaced by two newer ones. For Sys V IPC:
http://semanchuk.com/philip/sysv_ipc/

For POSIX IPC:
http://semanchuk.com/philip/posix_ipc/

The old shm module is still around on semanchuk.com but I'm not  
updating it anymore (the author is AWOL and I'm just the maintainer)  
and I don't recommend using it.


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


Re: first full alpha release of PyLab_Works v0.3

2009-06-17 Thread Martin P. Hellwig

edexter wrote:
cut


it says I am missing msvcp71.dll installing Microsoft Visual C++ 2005
Redistributable Package
 did not help..  I had simular problems
 with alot of installers I had saved (from installing on xp) but when
I grabbed newer installers
they all worked, could be the manifast  I was looking forward to
trying it out..




Did you tried this one?
http://www.microsoft.com/downloads/details.aspx?FamilyID=200b2fd9-ae1a-4a14-984d-389c36f85647displaylang=en
Found via:
http://lmgtfy.com/?q=Microsoft+Visual+C%2B%2B+2005+SP1+Redistributable+Package+(x86)l=1

--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


logging.fileConfig limitations?

2009-06-17 Thread Mani Ghasemlou
Hi all,

I have an application that writes out its logs in a subfolder of the
user's local data directory. Let's say our user's name is ßéäöÜ2.

On my Windows XP machine, this logging path turns out to be:

C:\Documents and Settings\ßéäöÜ2\Local Settings\Application Data\MyApp\MyApp.log

My application has a bootstrap kind of application that sets up the
application's subfolder and writes out the log config file. Notice
that the user's name contains non-ASCII characters. So, I encode the
path in UTF8 format before writing the log config file. My resulting
log config is (the last line is the most important):

- BEGIN
[formatters]
keys: normal

[handlers]
keys: rotatingfile

[loggers]
keys: root

[formatter_normal]
format: %(asctime)s %(levelname)s %(module)s: %(message)s

[logger_root]
level: DEBUG
handlers: rotatingfile

[handler_rotatingfile]
class: handlers.RotatingFileHandler
formatter: normal
args: [C:/Documents and Settings/ßéäöÜ2/Local
Settings/Application Data/MyApp/MyApp.log, a, 2*1024*1024, 5, None]
- END

Now it turns out that the logging module can't find C:/Documents and
Settings/ßéäöÜ2/Local Settings/Application Data/MyApp/MyApp.log
specified in the args section, and rightfully so because this is an
encoded string. *There does not seem to be a way for me to specify the
encoding of the string so that the logging module resolves the proper
unicode path.* This is my key problem!

Is there some way to accomplish what I want?

One interesting observation: I did some poking around in the logging
module shipped with Python 2.5. I put in some code in the Python
logging module to force UTF8 decoding of the filename argument, the
result of which was interesting: it would end up logging in
C:\Documents and Settings\ßéäöÜ2\Local Settings\Application
Data\MyApp\MyApp.txt (not MyApp.log !). I've done a little debugging
and can't immediately figure out why this is happening.

Any help would be greatly appreciated!

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


Re: SHM and Touchpad

2009-06-17 Thread Sparky
On Jun 17, 2:09 pm, Philip Semanchuk phi...@semanchuk.com wrote:
 On Jun 17, 2009, at 3:56 PM, Sparky wrote:

  Hello! I am writing an application that requires access to the state
  of a synaptics touch pad on a laptop running Ubuntu Linux (for the
  number of fingers, pressure, x location, y location, etc). A different
  program using C++ accesses the information through SHM and I was
  hoping to do the same with Python. I looked in PyPi and I noticed that
  there was a module for SHM but I can not figure out where to download
  it from (http://pypi.python.org/pypi/shm). Does anyone have any
  suggestions?

 Hi Sam,
 I'm not familiar with that shm, however there was (and still is) a old  
 Python IPC module called shm. It uses Sys V semaphores, not POSIX  
 semaphores like the shm in pypi.

 The old shm module has been replaced by two newer ones. For Sys V 
 IPC:http://semanchuk.com/philip/sysv_ipc/

 For POSIX IPC:http://semanchuk.com/philip/posix_ipc/

 The old shm module is still around on semanchuk.com but I'm not  
 updating it anymore (the author is AWOL and I'm just the maintainer)  
 and I don't recommend using it.

 HTH
 Philip

Dear Philip,

Thank you for your quick response, I will take a look at the link you
provided.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >