AVC 0.5.0 released

2008-02-04 Thread f . pollastri
Announcing AVC 0.5.0

Webpage: http://avc.inrim.it/

What is AVC?
-
AVC is a multiplatform, fully automatic, live connection among
graphical interface widgets and application variables for the python
language. AVC supports in a uniform way the most popular widget
toolkits: GTK, Qt3, Qt4, Tk, wxWidgets. AVC is a python module that
can be imported by any python application.
The display and the control of some application data through a GUI
(Graphical User Interface) is a central problem in GUI programming, it
absorbs a relevant part of the programming effort. AVC makes this
programming very easy, far more easy than traditional solutions based
on MVC (Model View Controller).

Features
---
*  Fully transparent widget-variable connections
* Automatic connection by matching widgets and variables names
* No design pattern, no application redesign, no widget toolkit
dependent code.
* Multiple widget toolkits support: GTK, Qt3, Qt4, Tk, wxWidgets.
* Full compatibility and support for Glade, Qt Designer, Visual Tcl
and wxGlade interfacedesign tools.
* Widgets support: button, check button, combo box, entry, label,
radio button, slider, spin button, status bar, text view/edit, toggle
button.
* Variable types support: boolean, integer, float, string, list,
tuple.
* Multiple widgets to one variable connection
* Dual update timing of variable value views: immediate or periodic.
* Testing printout logging activity with selectable verbosity
* Python module written in pure python
* Free software ( GNU GPL license )

Changelog
--
AVC 0.5.0 released 4-Feb-2008

* Extended label widget output formatting to support generic
python objects and to have a fallback to the standard python string
representation (str()) when there is no formatting string or the
formatting string is not valid.
* New examples: a label formatting example program for each
supported toolkit.
* New examples: a programmatic version (GUI generated by program
instructions) of the spin button/box/control example for each
supported toolkit.
* Added testing capability: activity report printout with
selectable verbosity level.
* Rewrited the widget abstraction layer: improved code structure,
more compact, better separation among widget toolkit dependent code in
AVC bindings and in AVC core code.
* Anticipated the test for supported widget from coget creation
(Coget.__init__()) to connections detector (_bind()): more efficient.

AVC 0.4.0 released 15-Dec-2007

* Added support for wxWidgets widget toolkit, widgets: button,
bitmap button, check button, choice, combo box, radio box, slider,
spin control, static text, status bar, text control, toggle button.

AVC 0.3.0 released 30-Sep-2007

* Added support for TK widget toolkit, widgets: button, check
button, entry, label, radio button, scale, spin box, text.
* Fixed input from Qt4 QdoubleSpinBox.
* Fixed wrong type of formatting string for Qt3 and Qt4 label
widget.
* Added control type casting to string returned by entry widget.
* New web site structure, user documentation moved from one html
page to User Manual in different formats: pdf, html.

AVC 0.2.0 released 30-Jan-2007

* Added new widgets: combo box, slider, status bar (GTK only),
text view/edit.

AVC 0.1.0 released 10-Jan-2007

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

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


Python-URL! - weekly Python news and links (Feb 4)

2008-02-04 Thread Gabriel Genellina
QOTW:  Everyone with a PC knows that eventually their computer will slow down,
crash unexpectedly, and develop problems with applications. - promotional
materials for award-winning *Degunking Windows* book

It's a very good idea to read the entire FAQ as soon as you've gotten past
the very basic Python level, so that you can save yourself and others a lot
of time stumbling over the traditional problems that everyone goes through. 
You'll learn a lot of useful things in the process. - Peter Hansen


Module/package hierarchy and its separation from file structure:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/5a9580e76484f73/

Notes on running multiple interpreters in the same process:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/f044df524c426027/

Type annotations, type inference and static typing for Python:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e7d39693de66e6f1/

Is Python standardised or not? (Wikipedia entry):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/a828c6585be8a682/

Should be a better way of saying `do_something n
times` than this: `for i in range(n): do_something`

http://groups.google.com/group/comp.lang.python/browse_thread/thread/cd391ce323f3d8f6/

Dictionary comprehensions: discarded in the past, now on Python 3.0:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/8f3650ba5da77543/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python enthusiats:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among 

Pydev 1.3.13 Released

2008-02-04 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.3.13 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

* Debug Console: will print exceptions raised during the evaluation.
* Debug Console: will print the result of the evaluation if a valid
statement is sent (so, 'print' is not needed for simple evaluations
anymore).


Release Highlights in Pydev:
--

* Outline view: working correctly again.
* Keybinding conflict: Alt+shift+T+XXX refactoring keybindings are now
only defined in the pydev scope.
* Hyperlink: Using new hyperlink mechanism (added at Eclipse 3.3).


What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: SUMMON 1.8.5 Released: 2D Visualization prototyping and scripting

2008-02-04 Thread rasmus
SUMMON 1.8.5

SUMMON is a python extension module that provides rapid prototyping of
2D visualizations.  By heavily relying on the python scripting
language, SUMMON allows the user to rapidly prototype a custom
visualization for their data, without the overhead of a designing a
graphical user interface or recompiling native code. By simplifying
the task of designing a visualization, users can spend more time on
understanding their data.

SUMMON is designed to be a fast interface for developing interactive
scene graphs for OpenGL. Although python libraries already exist for
accessing OpenGL, python is relatively slow for real-time interaction
with large visualizations (trees with 100,000 leaves, sparse matrices
with a million non-zeros, etc.). Therefore, with SUMMON all real-time
interaction is handled with compiled native C++ code (via extension
module). Python is only executed in the construction and occasional
interaction with the visualization. This arrangement provides the best
of both worlds.

SUMMON 1.8.4 comes with the following features:
* a demo large sparse matrix visualizer (ideal for visualizing
  clusterings)
* a demo tree visualizer
* Python C++ extension module
* Fast OpenGL graphics
* Drawing arbitrary points, lines, polygons, text with python
  scripting
* Binding inputs (keyboard, mouse, hotspots) to any python
function
* Separate threads for python and graphics (allows use of python
  prompt and responsive graphics at the same time)
* Transparently handles graphics event loop, scrolling, zooming,
  text layout (auto-clipping, scaling, alignment), and click
  detection; allowing you to focus on viewing your data
* SVG output (also GIF/PNG/JPG/etc via ImageMagick)
* Cross-platform (Linux, Windows, OS/X)
* And lots of examples for how to prototype your own custom 2D
  visualizations

Web site and download:
http://people.csail.mit.edu/rasmus/summon/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Too many open files

2008-02-04 Thread Gabriel Genellina
En Mon, 04 Feb 2008 12:50:15 -0200, Christian Heimes [EMAIL PROTECTED]  
escribi�:

 Jeff wrote:
 Why don't you start around 50 threads at a time to do the file
 writes?  Threads are effective for IO.  You open the source file,
 start a queue, and start sending data sets to be written to the
 queue.  Your source file processing can go on while the writes are
 done in other threads.

 I'm sorry, but you are totally wrong. Threads are a very bad idea for IO
 bound operation. Asynchronous event IO is the best answer for any IO
 bound problem. That is select, poll, epoll, kqueue or IOCP.

The OP said that he has this problem on Windows. The available methods  
that I am aware of are:
- using synchronous (blocking) I/O with multiple threads
- asynchronous I/O using OVERLAPPED and wait functions
- asynchronous I/O using IO completion ports

Python does not (natively) support any of the latter ones, only the first.  
I don't have any evidence proving that it's a very bad idea as you claim;  
altough I wouldn't use 50 threads as suggested above, but a few more than  
the number of CPU cores.

-- 
Gabriel Genellina

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

Re: Elementary string-parsing

2008-02-04 Thread Marc 'BlackJack' Rintsch
On Mon, 04 Feb 2008 09:43:04 +, Odysseus wrote:

 In article [EMAIL PROTECTED],
  Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
 
 def extract_data(names, na, cells):
 found = dict()
 
 The problem with initializing the 'super-dictionary' within this 
 function is that I want to be able to add to it in further passes, with 
 a new set of names  cells each time.

Then you can either pass in `found` as argument instead of creating it
here, or you collect the passes in the calling code with the `update()`
method of `dict`.  Something like this:

found = dict()
for pass in passes:
# ...
found.update(extract_data(names, na, cells))

 BTW what's the difference between the above and found = {}?

I find it more explicit.  ``dict`` and ``list`` are easier to
distinguish than ``{}`` and ``[]`` after a lng coding session or when
printed/displayed in a small font.  It's just a matter of taste.

 for i, name in enumerate(names):
 data = dict()
 cells_index = 10 * i + na
 for cell_name, index, parse in (('epoch1', 0, parse_date),
 ('epoch2', 1, parse_date),
 ('time', 5, parse_number),
 ('score1', 6, parse_number),
 ('score2', 7, parse_number)):
 data[cell_name] = parse(cells[cells_index + index])
 
 This looks a lot more efficient than my version, but what about the 
 strings that don't need parsing? Would it be better to define a 
 'pass-through' function that just returns its input, so they can be 
 handled by the same loop, or to handle them separately with another loop?

I'd handle them in the same loop.  A pass-through function for strings
already exists:

In [255]: str('hello')
Out[255]: 'hello'

 assert name.startswith('Name: ')
 
 I looked up assert, but all I could find relates to debugging. Not 
 that I think debugging is something I can do without ;) but I don't 
 understand what this line does.

It checks if `name` really starts with 'Name: '.  This way I turned the
comment into code that checks the assertion in the comment.

 The `parse_number()` function could look like this:
 
 def parse_number(string):
 try:
 return float(string.replace(',', ''))
 except ValueError:
 return string
 
 Indeed the commas can be replaced a bit more elegant.  :-)
 
 Nice, but I'm somewhat intimidated by the whole concept of 
 exception-handling (among others). How do you know to expect a 
 ValueError if the string isn't a representation of a number?

Experience.  I just tried what happens if I feed `float()` with a string
that is no number:

In [256]: float('abc')
---
type 'exceptions.ValueError'Traceback (most recent call last)

/home/bj/ipython console in module()

type 'exceptions.ValueError': invalid literal for float(): abc

 Is there a list of common exceptions somewhere? (Searching for
 ValueError turned up hundreds of passing mentions, but I couldn't find
 a definition or explanation.)

The definition is quite vague.  The type of an argument is correct, but
there's something wrong with the value.

See http://docs.python.org/lib/module-exceptions.html for an overview of
the built in exceptions.

 As already said, that ``while`` loop should be a ``for`` loop.  But if
 you put `m_abbrevs` into a `list` you can replace the loop with a
 single call to its `index()` method: ``dlist[1] =
 m_abbrevs.index(dlist[1]) + 1``.
 
 I had gathered that lists shouldn't be used for storing constants. Is
 that more of a suggestion than a rule?

Some suggest this.  Others say tuples are for data where the position of
an element has a meaning and lists are for elements that all have the
same meaning for some definition of meaning.  As an example ('John',
'Doe', 'Dr.') vs. ['Peter', 'Paul', 'Mary'].  In the first example we have
name, surname, title and in the second example all elements are just
names.  Unless the second example models a relation like child, father,
mother, or something like that.  Anyway, if you can make the source simpler
and easier to understand by using the `index()` method, use a list.  :-)

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


Re: [2.4.2/Linux] Getting Python to fork?

2008-02-04 Thread Jon Ribbens
On 2008-02-04, Christian Heimes [EMAIL PROTECTED] wrote:
 Jon Ribbens wrote:
 Why? I don't think you do.
 Neither does BSD daemon.c or glibc daemon.c

 The problem is well documented at
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012

OK I understand what is being said here, although it seems a bit
unlikely (daemon process opens a tty), but what is puzzling me is
why, if it's so necessary, does neither Linux nor *BSD do this in
their daemon() functions? It would seem surprising if the operating
system authors don't know how to make a daemon process in their
own OS ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unexpected timing results with file I/O

2008-02-04 Thread rdahlstrom
It doesn't matter how many doors opening and closing there are, it
matters the order in which the opening, walking through, and closing
are done.  That's my point.  In the second example, all of the disk
operations are done at the same time.  That's what I meant by people
going through the doors.  Maybe it was more clear in my head.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Client side GUI-like web framework ?

2008-02-04 Thread USCode
[EMAIL PROTECTED] wrote:
 You just described what XUL aims to be
 http://developer.mozilla.org/en/docs/The_Joy_of_XUL
 http://developer.mozilla.org/en/docs/XULRunner
 
 At present it lacks for sure documentation (or maybe it isn't
 organized really well)

Just took a look at XUL and it in some ways describes what I was 
thinking except it doesn't appear to deliver it's interface via a 
browser/web server.  Then your application wouldn't be accessible via a 
web browser through the internet.  The XUL application still appears to 
only execute locally on the client machine?

Also, personally I find having to describe your interface directly via 
XML (XUL) is just plain ugly.

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


Re: Unexpected timing results with file I/O

2008-02-04 Thread Marc 'BlackJack' Rintsch
On Mon, 04 Feb 2008 10:48:32 -0800, rdahlstrom wrote:

 It doesn't matter how many doors opening and closing there are, it
 matters the order in which the opening, walking through, and closing
 are done.  That's my point.  In the second example, all of the disk
 operations are done at the same time.  That's what I meant by people
 going through the doors.  Maybe it was more clear in my head.

But my timing shows that method two is slower on my computer.  So there is
no obvious winner.

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


Re: Unexpected timing results with file I/O

2008-02-04 Thread Carl Banks
On Feb 4, 12:53 pm, rdahlstrom [EMAIL PROTECTED] wrote:
 On Feb 4, 10:17 am, Steven D'Aprano [EMAIL PROTECTED]



 cybersource.com.au wrote:
  After reading an earlier thread about opening and closing lots of files,
  I thought I'd do a little experiment.

  Suppose you have a whole lot of files, and you need to open each one,
  append a string, then close them. There's two obvious ways to do it:
  group your code by file, or group your code by procedure.

  # Method one: grouped by file.
  for each file:
  open the file, append the string, then close it

  # Method two: grouped by procedure.
  for each file:
  open the file
  for each open file:
  append the string
  for each open file:
  close the file

  If you have N files, both methods make the same number of I/O calls: N
  opens, N writes, N closes. Which is faster?

  Intuitively, the first method has *got* to be faster, right? It's got one
  loop instead of three and it doesn't build an intermediate list of open
  file objects. It's so *obviously* going to be faster that it is hardly
  worth bothering to check it with timeit, right?

  Well, I wouldn't be writing unless that intuitive result was wrong. So
  here's my test results:

  Method 1:

   import timeit
   names = ['afile' + str(n) for n in range(1000)]
   T = timeit.Timer('''for name in names:

  ... fp = open(name, 'a'); fp.write('xyz\\n'); fp.close()
  ... ''', 'from __main__ import names') min(T.repeat(6, 500))

  17.391216039657593

  Method 2:

   for name in names:  # reset the files to an empty state.

  ... fp = open(name, 'w'); fp.close()
  ... T = timeit.Timer('''files = [open(name, 'a') for name in names]

  ... for fp in files:
  ... fp.write('xyz\\n')
  ... for fp in files:
  ... fp.close()
  ... ''', '''from __main__ import names''') min(T.repeat(6, 500))

  16.823362112045288

  Surprisingly, Method 2 is a smidgen faster, by about half a second over
  500,000 open-write-close cycles. It's not much faster, but it's
  consistent, over many tests, changing many of the parameters (e.g. the
  number of files, the number of runs per timeit test, etc.).

  I'm using Linux and Python 2.5.

  So, what's going on? Can anyone explain why the code which does more work
  takes less time?

  --
  Steven

 The code that does more work takes more time.  The second one does
 quite a bit less work.  Think of it like this:

 You have 500,000 people to fit through a door.  Here are your options:

 1.  For each person, open the door, walk through the door, then close
 the door.
 2.  Open the door, allow everyone to walk through, then close the
 door.

 Which one would you say would be a more efficient way to fit 500,000
 people through the door?

Bad analogy.  A better analogy would be if each person has their own
door to walk through.

My hunch is that is has to do with the OS I/O scheduling.  Closing a
file triggers a cache flush, which in turn triggers the I/O to
schedule a write to disk; the OS scheduler is perhaps more efficient
(for a given number of total writes) when it can combine many writes
at the same time.


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


Re: Unexpected timing results with file I/O

2008-02-04 Thread rdahlstrom
On Feb 4, 10:17 am, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 After reading an earlier thread about opening and closing lots of files,
 I thought I'd do a little experiment.

 Suppose you have a whole lot of files, and you need to open each one,
 append a string, then close them. There's two obvious ways to do it:
 group your code by file, or group your code by procedure.

 # Method one: grouped by file.
 for each file:
 open the file, append the string, then close it

 # Method two: grouped by procedure.
 for each file:
 open the file
 for each open file:
 append the string
 for each open file:
 close the file

 If you have N files, both methods make the same number of I/O calls: N
 opens, N writes, N closes. Which is faster?

 Intuitively, the first method has *got* to be faster, right? It's got one
 loop instead of three and it doesn't build an intermediate list of open
 file objects. It's so *obviously* going to be faster that it is hardly
 worth bothering to check it with timeit, right?

 Well, I wouldn't be writing unless that intuitive result was wrong. So
 here's my test results:

 Method 1:

  import timeit
  names = ['afile' + str(n) for n in range(1000)]
  T = timeit.Timer('''for name in names:

 ... fp = open(name, 'a'); fp.write('xyz\\n'); fp.close()
 ... ''', 'from __main__ import names') min(T.repeat(6, 500))

 17.391216039657593

 Method 2:

  for name in names:  # reset the files to an empty state.

 ... fp = open(name, 'w'); fp.close()
 ... T = timeit.Timer('''files = [open(name, 'a') for name in names]

 ... for fp in files:
 ... fp.write('xyz\\n')
 ... for fp in files:
 ... fp.close()
 ... ''', '''from __main__ import names''') min(T.repeat(6, 500))

 16.823362112045288

 Surprisingly, Method 2 is a smidgen faster, by about half a second over
 500,000 open-write-close cycles. It's not much faster, but it's
 consistent, over many tests, changing many of the parameters (e.g. the
 number of files, the number of runs per timeit test, etc.).

 I'm using Linux and Python 2.5.

 So, what's going on? Can anyone explain why the code which does more work
 takes less time?

 --
 Steven



The code that does more work takes more time.  The second one does
quite a bit less work.  Think of it like this:

You have 500,000 people to fit through a door.  Here are your options:

1.  For each person, open the door, walk through the door, then close
the door.
2.  Open the door, allow everyone to walk through, then close the
door.

Which one would you say would be a more efficient way to fit 500,000
people through the door?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python feature request : operator for function composition

2008-02-04 Thread Kay Schluehr
This won't work for builtin functions. It hardly works for functions
and methods defined in 3rd party modules and in no way for functions
defined in C extensions. It adds boilerplate statically to remove it
at runtime.

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


Pydev 1.3.13 Released

2008-02-04 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.3.13 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

* Debug Console: will print exceptions raised during the evaluation.
* Debug Console: will print the result of the evaluation if a valid
statement is sent (so, 'print' is not needed for simple evaluations
anymore).


Release Highlights in Pydev:
--

* Outline view: working correctly again.
* Keybinding conflict: Alt+shift+T+XXX refactoring keybindings are now
only defined in the pydev scope.
* Hyperlink: Using new hyperlink mechanism (added at Eclipse 3.3).


What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too many open files

2008-02-04 Thread Duncan Booth
Steven D'Aprano [EMAIL PROTECTED] wrote:

 On Mon, 04 Feb 2008 13:57:39 +0100, AMD wrote:
 
 The problem I have under windows is that as soon as I get to 500 files I
 get the Too many open files message. I tried the same thing in Delphi
 and I can get to 3000 files. How can I increase the number of open files
 in Python?


 Windows XP has a limit of 512 files opened by any process, including 
 stdin, stdout and stderr, so your code is probably failing after file 
 number 509.

No, the C runtime has a limit of 512 files, the OS limit is actually 2048. 
See http://msdn2.microsoft.com/en-us/library/6e3b887c(VS.71).aspx

 I don't know how Delphi works around that issue. Perhaps one of the 
 Windows gurus can advise if there's a way to increase that limit from
 512? 
 

Call the C runtime function _setmaxstdio(n) to set the maxmimum the number 
of open files to n up to 2048. Alternatively os.open() and os.write() 
should bypass the C runtime limit.

It would probably be better though to implement some sort of caching scheme 
in memory and avoid having to mess with the limits at all. Or do it in two 
passes: creating 100 files on the first pass and splitting each of those in 
a second pass.

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


Re: Python GUI toolkit

2008-02-04 Thread Kevin Walzer
Chris Mellon wrote:

 Nitpick, but an important one. It emulates *look*. Not feel. Native
 look is easy and totally insufficient for a native app - it's the
 feel that's important.

Is this opinion based on firsthand experience with use of the Tile/ttk 
widgets on any of the relevant platforms?

I'm not a Windows user, so I can't speak about that platform, but I have 
worked very hard to make my Python-Tile-Tk app consistent with both the 
look and feel of OS X: keyboard shortcuts, menu behavior, and so on. 
It's mainly a matter of attention to detail, and listening to user 
feedback. I've gotten good feedback on my applications in recent months 
as I've implemented more and more platform native behavior, and sales of 
these applications (I'm a shareware developer) reflect that.

I'd be interested to hear how, in your experience, Tk/Tile is inherently 
unable to deliver native platform feel, in a way that reflects on the 
toolkit rather than the developer.  It's fine to focus on Windows if 
that's your area of expertise.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pysqlite issue no attribute 'autocommit' RESOLVED

2008-02-04 Thread Andy Smith
Ok, simple fix... Updated to MySQL_python-1.2.2 and all ok now! :D

  - Original Message - 
  From: Andy Smith 
  To: python-list@python.org 
  Sent: Monday, February 04, 2008 3:45 PM
  Subject: Pysqlite issue no attribute 'autocommit'



  Hi there,

Im trying to run a Python based program which uses MySQL with python-sqlite 
and Im recieving this error,

  'Connection' object has no attribute 'autocommit'

  I´ve had a google for this and its seems like it may be a bug python-sqlite 
or sqlite bug , but also I tried searching 
  for it on the python issue traker and didnt find anything. Is anyone else 
aware of this issue and any solution?

  thanks for any help! Andy.

  PS sorry if I didnt include much info, hoping its a known issue (and also I 
didnt write the code, so not sure what
  else to include off the top of my head! :P)-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Terse Syntax through External Methods

2008-02-04 Thread aggergren
On Jan 29, 11:50 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Jens schrieb:



  On Jan 25, 3:19 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
  Jens schrieb:

  Hello Everyone
  I'm newbie toZopeand i have a few questions regarding external
  methods. What i wan't to do
  is provide a terse syntax for converting  urls to special tracking
  urls:
  dtml-var track('http://myurl/')
  turns the provided url into something like
 http://host/tracking?url=http%3A%2F%2Fmyurl%2F
  in the output.
  i've been trying to use a external procedure like this.
  ## Script (Python) track_link
  ##bind container=container
  ##bind context=context
  ##bind namespace=_
  ##bind script=script
  ##bind subpath=traverse_subpath
  ##parameters=self,url
  ##title=track link
  ##
  return %s%s % (self.tracking_prefix, url_quote(url))
  This doesn't work because because the method doesn't have access to
  the environment. Obviously I don't wan't to pass everything explicitly
  into the function as this would defeat the purpose of the exercise,
  namely to provide a terse syntax.
  I have a background in other languages so I might be missing something
  conceptually with regardZopeand DTML.. Is there a better was of
  doing this, perhaps without using external methods? Currently im doing
  the following which isn't very elegant:
  in content document
  a href=dtml-let exturl='http://www.mylink.com/;dtml-var
  tracking/dtml-letlink/a
  ...
  tracking:
  dtml-var tracking_prefixdtml-var name=exturl url_quote_plus
  Appreciate any input you might have on this-
  Is it really needed to use an external method for this, or isn't a
  normal python script enough already?

  If it has to be an External method, you can't access such a context
  AFAIK. But then you can create a python script that _has_ this context,
  and passese it to the external method. Not the nicest solution, but
  should work.

  Diez

  Like I said i'm a newbie. I though the deal withZopewas that i
  couldn't really do inline scripting (for security reasons)
  like in php but had to use these external methods. how does one go
  about creating a normal python script exactly and
  how do I invoke it's functionality?

 Read the docs:

 http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/Scripting...

 There's everything in there you need.

 Diez

Thanks, this is exactly what i needed. And Btw. the answer is to use
the 'context' keyword.

- Jens

P.S. And thanks to everyone else for their feedback :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [2.4.2/Linux] Getting Python to fork?

2008-02-04 Thread Rolf van de Krol
To create a deamon, you indeed need to fork two times. For more 
information and a working example see: 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 . I'm 
quite sure this works, because I used it several times to create a deamon.


Jon Ribbens wrote:
 On 2008-02-04, Christian Heimes [EMAIL PROTECTED] wrote:
   
 Although bear in mind it's pretty UNIX-y.
   
 IIRC you have to fork a second time after you have changed the working
 dir and created a new session group.
 

 Why? I don't think you do.
 Neither does BSD daemon.c or glibc daemon.c
   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python feature request : operator for function composition

2008-02-04 Thread Dustan
On Feb 4, 10:11 am, Arnaud Delobelle [EMAIL PROTECTED] wrote:
 This is nice.

Thanks.

 * I wouldn't choose '' as the composing operator as when I read
 'double  square' I think 'take an x, double it  square it' which is
 the wrong interpretation (perhaps  instead?).

A very good point that I didn't think about; I just blindly took the
OP's chosen operator. Another thing I realized after writing this was
that I could have also written a corresponding __rand__ method
(__rlshift__ with your alternative operator), in case the object to
the right of the operator is a composer object and to the left is a
simple function.

 * I would call the decorator 'composable'.

The thing about that, though, is that this can also be used as a
composition in function style. However, I can't think of any name that
encompasses both uses. And you're right in that composer wasn't a very
good choice of name. As I say, it was written in haste.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python GUI toolkit

2008-02-04 Thread bockman


 Another toolkit you might look into is Tkinter. I think it is something
 like the official toolkit for python. I also think it is an adapter
 for other toolkits, so it will use gtk widgets on gnome, qt widgets on
 kde and some other strange widgets on windows.


Not t so,  AFAIK. Tkinter is the python adapter for Tk, the toolkit
originally developed for Tcl language.

The latest version of Tk (not yet integrated in Python, maybe in 2.6)
has themes, which emulates
the look-and-feel of native toolkit at list for XP and OS X. For unix,
the last time I checked, there was only a theme that looked like a
plainer version of Gtk default theme. No Gnome or Kde themes yet.

The latest version of Tk also increased the set of available widgets,
which now is similar to the set of widgets offered by Qt/Gtk..
However, how much of these widgets will be available through Tkinter
will depend on people stepping in and upgrading Tkinter beyond simpy
ensuring that the old widgets still works. Given that many GUI-
developing python programmers have moved to other toolkits, I'm not
sure this will ever happen.

Ciao

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


Re: Extending the import mechanism - what is recommended?

2008-02-04 Thread dbr517
On Jan 29, 2:36 pm, Steve Holden [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  I need to extend the import mechanism to support another file type.
  I've already written the necessary C library to read the file and
  return a python code object.

  I found one example which just sub-classed imputil.ImportManager like
  this:

  from myLib import pye_code as pye_code
  class MyImporter(imputil.ImportManager):
  def __init__(self):
  imputil.ImportManager.__init__(self)
  self.add_suffix('.pye', self.import_pye)
  self.install()

  def import_pye(self, filepath, fileinfo, filename):
  data = pye_code(filepath)
  return 0, data, {}

  This actually works fine if the module is just a few lines of code,
  but it won't chain to the built-in importers; if the module that I'm
  importing does something as simple as 'import re', it fails.

  It may be that my confusion here is because (even after reading the
  code), I'm not clear on the purposes of imputil.ImportManager vs.
  imputil.Importer :-(

  What is the preferred way to do this type of extension?  One other
  note; at this time, I just need to import individual module files with
  this extension; I don't need to import packages.

 Here's an importer I wrote some time ago to bring modules in from a
 relational database. I won't trouble you with the code to compile the
 modules/packages and add them into the database, but perhaps the
 attached code will be enough to show you what you are doing that's not
 working.

 regards
   Steve
 --
 Steve Holden+1 571 484 6266   +1 800 494 3119
 Holden Web LLC  http://www.holdenweb.com/

 [dbimp.py]#
 # Import modules from a database
 #
 # NOTE: could use sys version info to select appropriate module version
 #   - could ask whether to install if absent ... heh, heh :-)
 #
 import sys, db, marshal
 VER = sys.hexversion
---
 def install():
 sys.path_hooks.append(dbimporter)
 sys.path_importer_cache.clear() # probably not necessary
 sys.path.insert(0, *db*) # probably not needed with a metea-path hook?

Steve -

Thanks!  Got this to work with one interesting problem . . . if I use
sys.path.insert(0) and insert my hook at the head of the path,
then I can't import anything EXCEPT my special modules . . . If I use
sys.path.append(*pye*) then I'm OK.

One thing I changed was that my load_module function raises
ImportError if it fails; my understanding from reading PEP302 is that
that's what's SUPPOSED to happen . . .

At any rate, I can now import my custom modules . . . thanks!

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


Re: type, object hierarchy?

2008-02-04 Thread Jason
On Feb 3, 10:31 pm, 7stud [EMAIL PROTECTED] wrote:
 On Feb 3, 10:28 pm, 7stud [EMAIL PROTECTED] wrote:

  From the docs:

  issubclass(class, classinfo)
  Return true if class is a subclass (direct or indirect) of classinfo.

 print issubclass(Dog, object)  #True
 print issubclass(type, object)  #True
 print issubclass(Dog, type)   #False

Yes.  That is exactly what is expected.

Dog is not subclassed from type.  It is subclassed from Mammals, which
is subclassed from object.

Dog is, however, an instance of type.  This is true of all new-style
Python classes.

All of Python's classes are objects.  They have to be an instance of /
something/.  New-style classes are instances of the class type.  That
doesn't mean that they are considered subclasses from class type.
This means that the Dog object has all the methods, properties, and
class data that the class type has.  Class type is Dog's metaclass --
the class of the class.

If you create an instance of Dog, you can access the various class
attributes that Dog has through the instance.  It doesn't mean that
the instance of Dog is subclassed from Dog.

 terrier = Dog()
 issubclass(terrier, Dog)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: issubclass() arg 1 must be a class

In Python, you can create a subclass of class type.  This isn't very
useful in most cases.  If you set the __metaclass__ magick attribute,
however, your class object will be an instance of the class referred
to by that attribute.  This lets you experiment with the way classes
are created and how the MRO works, and lets you break Python at a
pretty low level.  For example:

 class NewTalky(type):
... def __new__(*args, **keyargs):
... print I am called when Python creates a class whose
metaclass is me.
... print I am responsible for creating a class object.
... print My ordered arguments:, args
... print My keyword arguments:, keyargs
... classObject = type.__new__(*args, **keyargs)
... print The result of type.__new__():, classObject
... return classObject
...
 class Reptile(object):
... __metaclass__ = NewTalky
...
I am called when Python creates a class whose metaclass is me.
I am responsible for creating a class object.
My ordered arguments: (class '__main__.NewTalky', 'Reptile', (type
'object',), {'__module__': '__main__', '__metaclass__': class
'__main__.NewTalky'})
My keyword arguments: {}
The result of type.__new__(): class '__main__.Reptile'

 type(Dog)  # Dog is an instance of class type
type 'type'
 type(Reptile)  # Reptile is an instance of class NewTalky
class '__main__.NewTalky'

 issubclass(Reptile, type)  # Reptile is not subclassed from type...
False
 issubclass( type(Reptile), type )  # ...but NewTalky is
True
 issubclass( type(Dog), type )
True



Again, everything in Python is an object.  Your Python classes are
class objects.  They are instances of the class type.  In the first
example above, terrier is an instance of class Dog, but is not a
subclass of class Dog.  Similarly, Dog is an instance of class type,
not a subclass of class type.  Since class Dog is an instance of class
type, class type is considered to be Dog's metaclass.

You can create your own metaclasses.  To quote another Pythoneer, if
you think you need a metaclass, you probably don't.  If you know you
need a metaclass, you definitely do not need a metaclass.  They are
tricky and mind-bending.

Hope this helps clear things up for you.

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


Re: [2.4.2/Linux] Getting Python to fork?

2008-02-04 Thread Jon Ribbens
On 2008-02-04, Gilles Ganault [EMAIL PROTECTED] wrote:
   I need to launch a Python script, and fork it so that the calling
 script can resume with the next step will the Python script keeps
 running.

 I tried those two, but they don't work, as the calling script is stuck
 until the Python script ends:

This should work I believe:

  if os.fork():
os._exit(0)
  os.setsid()
  os.chdir(/)
  fd = os.open(/dev/null, os.O_RDWR)
  os.dup2(fd, 0)
  os.dup2(fd, 1)
  os.dup2(fd, 2)
  if fd  2:
os.close(fd)
  # do stuff

Although bear in mind it's pretty UNIX-y.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyOpenGL

2008-02-04 Thread Mike C. Fletcher
[EMAIL PROTECTED] wrote:
 Hi all,

 I apologize if this question was already answered before but I was
 unable to find a proper solution to my problem. Anyways, I am trying
 to run shaderobjects.py on Windows (Python 2.5.1) by just double-
 clicking, and I got the following error:

 [...]
 File /usr/lib/python2.5/site-packages/OpenGL/extensions.py, line 13,
 in hasGLExtension
 AVAILABLE_GL_EXTENSIONS[:] = glGetString( GL_EXTENSIONS ).split()
 AttributeError: 'NoneType' object has no attribute 'split'

 _I think_ I have all requirements and packages properly installed.

 Any clues? Thanks in advance !
   
That *looks* like a problem with calling glGetString before you have a
valid context.  Normally that actually works on GLX platforms, but
apparently not in this case.  Try delaying your import until after you
have the context setup and see if that lets glGetString return a valid
pointer.

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: Python GUI toolkit

2008-02-04 Thread Eric Brunel
On Sun, 03 Feb 2008 20:38:41 +0100, Thomas Dybdahl Ahle [EMAIL PROTECTED]  
wrote:
[snip]
 Another toolkit you might look into is Tkinter. I think it is something
 like the official toolkit for python. I also think it is an adapter
 for other toolkits, so it will use gtk widgets on gnome, qt widgets on
 kde and some other strange widgets on windows.

No. Tkinter doesn't use any other library and draws its own widgets, which  
until now look like very old-style Motif widgets on Unix. There's a new  
version of tcl/tk (on which Tkinter is based) that has a new look for  
widgets, basically looking like gtk's default theme, but it doesn't use  
gtk at all.

This can be seen as an advantage or a drawback depending on what you're  
looking for:
- this keeps the toolkit very small and independent (no dependency hell)
- this basically ensures that the look won't be native

And BTW, the new version of tcl/tk is supposed to look native on Windows   
MacOS too. Unfortunately, this version is very new and the Tkinter module  
has not been adapted for it yet.

HTH
-- 
python -c print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb: commit before cursor close, or after?

2008-02-04 Thread Frank Aune
On Monday 04 February 2008 19:14:13 John Nagle wrote:
I'm getting some wierd commit-related behavior from MySQLdb.  I'm
 using InnoDB, so transactions really matter.

 I'm currently doing

   cursor = db.cursor()
   cursor.execute(...)
   cursor.close()
   db.commit()

 Is that the correct order, or should I call db.commit() before
 cursor.close()?  Does anyone know for sure?  The MySQLdb documentation
 (http://mysql-python.sourceforge.net/MySQLdb.html;) doesn't
 say.  There are some discussions of this in blogs, but nobody
 really seems to know.

   John Nagle


No, you obviously need to commit your changes before closing the cursor. I'm 
surprised if your code above even works if adding content to the db.

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


Re: When is min(a, b) != min(b, a)?

2008-02-04 Thread Albert van der Horst
In article [EMAIL PROTECTED],
Steven D'Aprano  [EMAIL PROTECTED] wrote:
On Thu, 24 Jan 2008 13:34:56 +, Antoon Pardon wrote:

 On 2008-01-21, Steven D'Aprano [EMAIL PROTECTED]
 wrote:
 On Sun, 20 Jan 2008 21:15:02 -0600, Albert Hopkins wrote:

 According to the IEEE-754 standard the usual trichotomy of x is less
 than y, x is equal to y, or x is greater than y has to be extended to
 include x and y are unordered. Comparisons with NaNs are unordered,
 and so expressions like x  nan should signal an exception.

 That doesn't follow. The problem is not that x  nan returns False
 because that is correct since x isn't smaller than nan.

Comparisons between things which are not comparable risk being terribly
misleading, and depend very much on how you define less than and
greater than. If you insist that everything must have a boolean yes/no
answer (Does the colour red have a better chance of becoming President
than a kick to the head?) then False is not an entirely unreasonable
result to return.

But if you consider that having x is not smaller than y be equivalent
to x is greater than or equal to y is more important than forcing a
boolean answer in the first place, then you need something to signal
Undefined, and an exception is the right solution unless you have multi-
valued logic system (True, False, Maybe, Undefined, ...)

SANE (Standard Apple Numerics Environment) explicitly states that it
signals an exception when doing ordered comparisons against NaNs because
to return False would be misleading. Apple went on to use the same rule
in their PowerPC Numerics. That's straight out of the Zen: Practicality
Beats Purity.

This is the more so, keeping in mind that the original motivation for
Nan's is to avoid exceptions. In principle to keep algorithms clean,
you would like to have exceptions as soon as you divide by zero, or
overflow. This is extremely costly on high efficiency floating point
hardware, (you may have a pipeline stall to allow the point of
exception to be defined, even if the exception doesn't occur)
so IEEE allows to propagate the exception via Nan to occur at
a convenient time, e.g. when the output of a matrix multiplication
is inspected.

Comparisons mark the moment that a decision is made.
Now masking the problem, by taking an invalid hence arbitrary
decision based on an invalid result, is insane. The Nan is
forever gone, something not allowed by IEEE only in code that

[A case can be made however that min and max just propagate a
Nan and don't throw an exception, yet. ]

So python should throw. That is practicality *and* purity.

--
Steven

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
[EMAIL PROTECTED]arc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: Client side GUI-like web framework ?

2008-02-04 Thread Salvatore
[EMAIL PROTECTED] a écrit :
 
 You just described what XUL aims to be
 http://developer.mozilla.org/en/docs/The_Joy_of_XUL
 http://developer.mozilla.org/en/docs/XULRunner

XUL is great but it does not allow yet to use Python.
There use to be such a beast, it was named 'Nufox'...

Give a try to  http://www.appcelerator.org/index.html

Regards

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


Re: type, object hierarchy?

2008-02-04 Thread 7stud
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Client side GUI-like web framework ?

2008-02-04 Thread [EMAIL PROTECTED]
On 4 Feb, 18:45, USCode [EMAIL PROTECTED] wrote:
 Wouldn't it be handy if there was a web framework that allowed you to
 create pages and control the interface like you would using a
 client-side GUI framework such as Tkinter?

 The framework would need a small, fast web server that would
 automatically fire up when you ran your application and you then control
 the interface just like you would with client-side GUI widgets (within
 the limitations of browsers of course).  It would handle all the
 complexities of HTTP, HTML, Javascript, etc. letting you focus on adding
 functionality to your application.

 Essentially you would be using the browser as your cross-platform
 client-side interface.  You would just interact with all the widgets
 like trees, grids, paned windows, checkboxes, buttons, etc.

 There wouldn't happen to be anything like that available, would there?
 I've seen CherryPy but that doesn't quite seem to be what I described.

 Thanks!


You just described what XUL aims to be
http://developer.mozilla.org/en/docs/The_Joy_of_XUL
http://developer.mozilla.org/en/docs/XULRunner

At present it lacks for sure documentation (or maybe it isn't
organized really well)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unexpected timing results with file I/O

2008-02-04 Thread Marc 'BlackJack' Rintsch
On Mon, 04 Feb 2008 15:17:18 +, Steven D'Aprano wrote:

 # Method one: grouped by file.
 for each file:
 open the file, append the string, then close it
 
 
 # Method two: grouped by procedure.
 for each file:
 open the file
 for each open file:
 append the string
 for each open file:
 close the file

 Method 1:
 
 17.391216039657593
 
 Method 2:
 
 16.823362112045288
 
 
 Surprisingly, Method 2 is a smidgen faster, by about half a second over 
 500,000 open-write-close cycles. It's not much faster, but it's 
 consistent, over many tests, changing many of the parameters (e.g. the 
 number of files, the number of runs per timeit test, etc.).
 
 I'm using Linux and Python 2.5.
 
 So, what's going on? Can anyone explain why the code which does more work 
 takes less time?

Can't confirm this (Linux, Python 2.5):

Method 1: 15.380897998809814
Method 2: 18.085366010665894

I guess it's really all about the disk IO as my system monitor applet
shows that almost all of the time is spend in the kernel and very little
in user space.

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


Re: Is it explicitly specified?

2008-02-04 Thread André Malo
* Steven D'Aprano wrote:

 On Sun, 03 Feb 2008 15:31:49 -0800, Paul Boddie wrote:
 
 I don't know whether I can offer much better advice than others, but I
 have noticed that a lot of my own code has moved in the direction of not
 having specific default values in function/method signatures. So,
 instead of this...
 
   def f(x=123):
 ...
 
 ...I have this:
 
   def f(x=None):
 if x is None:
   x = 123
 
 
 For the love of Pete, WHY??
 
 I understand why you would do it for a mutable default, but immutable???

I'm observing myself doing the same, for the following reason:

Consider the function being part of a bigger system, where it's called from
another function or method which should inherit the default value of the
function, like:

def g(foo, bar, x=None):
   ...
   f(x=x)

Now if you change the default value of f(x) for some reason, you don't have
to wind up all the possible caller signatures to reflect that change.

nd
-- 
Winnetous Erbe: http://pub.perlig.de/books.html#apache2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb: commit before cursor close, or after?

2008-02-04 Thread Carsten Haese
On Mon, 2008-02-04 at 19:53 +0100, Frank Aune wrote:
 No, you obviously need to commit your changes before closing the cursor. I'm 
 surprised if your code above even works if adding content to the db.

Why is that obvious? Is this some MySQL-specific oddity? In other
databases, it's the cursor's execute() method that adds the content to
the db (pending a commit of the transaction), and closing the cursor
simply means that you are explicitly releasing the resources that the
cursor used. Whether the cursor is closed before or after the
transaction is committed, or even whether the cursor is explicitly
closed at all or not, should make no difference whatsoever.

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Python GUI toolkit

2008-02-04 Thread Kevin Walzer
Chris Mellon wrote:

 
 I didn't say inherently unable, I said the toolkit doesn't provide it.
 Note that you said that you did a lot of work to follow OS X
 conventions and implement behavior. The toolkit doesn't help you with
 any of this. A mac-native toolkit (or one that strives for native
 behavior, like wxPython)  eliminates a lot of this work (although, of
 course, not all).


If the toolkit doesn't provide it, then I think that means inherently 
unable.

On the Mac, Tk provides a mechanism that allows hooking up arbitrary 
events to arbitrary keyboard. Something like:

  self.bind('Command-Key-N', lambda event: 
self.authorizeCommand(self.installPackage))

I have to specify the key-combination--that's all. One line of code. No 
implementing of keyboard bindings in C or at the Tcl/Tk or even 
Python-Tkinter level--it's all already defined by the toolkit.

By contrast, Cocoa/Objective-C has a rather complex system for defining 
keyboard events:

http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/chapter_6_section_1.html#//apple_ref/doc/uid/1060i-CH7-SW1

PyObjC is a thin wrapper over Objective-C, so you'd have to do the 
equivalent calls in Python to implement custom keyboard behavior.

It is true that Cocoa some convenience methods in Interface Builder, 
i.e. common menu commands don't require any extra code: if you are 
developing a document-based application, Command-C is implemented  in 
the menu and in the frameworks as copy (text, image, whatever) to 
clipboard. But Command-C also works identically in the Tk console.

Tk does lack some things. It doesn't support drag-and-drop on the Mac. 
It doesn't hook into some of the newer Mac visual styles. Getting access 
to this would require an extension or patching Tk's core. In those 
events, I emulate the behavior or appeareance, which Tk makes very easy.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: type, object hierarchy?

2008-02-04 Thread Eduardo O. Padoan
On Feb 4, 2008 1:36 AM, 7stud [EMAIL PROTECTED] wrote:
 print dir(type)  #__mro__ attribute is in here
 print dir(object)   #no __mro__ attribute


 class Mammals(object):
 pass
 class Dog(Mammals):
 pass

 print issubclass(Dog, type)   #False
 print Dog.__mro__

 --output:--
 (class '__main__.Dog', class '__main__.Mammals', type 'object')


 The output suggests that Dog actually is a subclass of type--despite
 the fact that issubclass(Dog, type) returns False.  In addition, the
 output of dir(type) and dir(object):


 ['__base__', '__bases__', '__basicsize__', '__call__', '__class__',
 '__cmp__', '__delattr__', '__dict__', '__dictoffset__', '__doc__',
 '__flags__', '__getattribute__', '__hash__', '__init__',
 '__itemsize__', '__module__', '__mro__', '__name__', '__new__',
 '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
 '__subclasses__', '__weakrefoffset__', 'mro']

 ['__class__', '__delattr__', '__doc__', '__getattribute__',
 '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__',
 '__repr__', '__setattr__', '__str__']

 suggests that type inherits from object since type has all the same
 attributes as object plus some additional ones.  That seems to
 indicate a hierarchy like this:


 object
  |
  V
 type
  |
  V
 Mammals
  |
  V
 Dog


 But then why does issubclass(Dog, type) return False?


Here you should find The Answer (tm):
http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html

(Beautifully ilustrated, BTW)

-- 
http://www.advogato.org/person/eopadoan/
Bookmarks: http://del.icio.us/edcrypt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [2.4.2/Linux] Getting Python to fork?

2008-02-04 Thread Jon Ribbens
On 2008-02-04, Rolf van de Krol [EMAIL PROTECTED] wrote:
 To create a deamon, you indeed need to fork two times. For more 
 information and a working example see: 
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 . I'm 
 quite sure this works, because I used it several times to create a deamon.

That doesn't mean it works. That just means it hasn't failed while
you were watching.

(Not that I am saying it's necessarily wrong, I'm just saying that
it worked when I tried it is a very bad way of deciding if something
is correct code.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Elementary string-parsing

2008-02-04 Thread Odysseus
In article [EMAIL PROTECTED],
 Dennis Lee Bieber [EMAIL PROTECTED] wrote:

snip

   Rather complicated description... A sample of the real/actual input
 /file/ would be useful.

Sorry, I didn't want to go on too long about the background, but I guess 
more context would have helped. The data actually come from a web page; 
I use a class based on SGMLParser to do the initial collection. The 
items in the names list were originally title attributes of anchor 
tags and are obtained with a start_a method, while cells holds the 
contents of the td tags, obtained by a handle_data method according 
to the state of a flag that's set to True by a start_td method and to 
False by an end_td. I don't care about anything else on the page, so I 
didn't define most of the tag-specific methods available.

snip

   cellRoot = 10 * i + na  #where did na come from?
   #heck, where do 
 names and cells
   #come from? 
 Globals? Not recommended..

The variable na is the number of 'not applicable' items (headings and 
whatnot) preceding the data I'm interested in.

I'm not clear on what makes an object global, other than appearing as an 
operand of a global statement, which I don't use anywhere. But na is 
assigned its value in the program body, not within any function: does 
that make it global? Why is this not recommended? If I wrap the 
assignment in a function, making na a local variable, how can 
extract_data then access it?

The lists of data are attributes (?) of my SGMLParser class; in my 
misguided attempt to pare irrelevant details from extract_data I 
obfuscated this aspect. I have a parse_page(url) function that returns 
an instance of the class, as captured, and the lists in question are 
actually called captured.names and captured.cells. The 
parse_page(url) function is called in the program body; does that make 
its output global as well?

   use
 
 def extract_data(names, na, cells):
 
   and 
 
   return something

What should it return? A Boolean indicating success or failure? All the 
data I want should all have been stored in the found dictionary by the 
time the function finishes traversing the list of names.

  for k in ('time', 'score1', 'score2'):
  v = found[name][k]
  if v != --- and v != n/a: # skip non-numeric data
  v = ''.join(v.split(,)) # remove commas between 000s
  found[name][k] = float(v)
 
   I'd suggest splitting this into a short function, and invoking it in
 the preceding... say it is called parsed
 
   time : parsed(cells[cellRoot + 5]),

Will do. I guess part of my problem is that being unsure of myself I'm 
reluctant to attempt too much in a single complex statement, finding it 
easier to take small and simple (but inefficient) steps. I'll have to 
learn to consolidate things as I go.

   Did you check the library for time/date parsing/formatting
 operations?
 
  import time
  aTime = 03 Feb 2008 20:35:46 UTC#DD Mth  HH:MM:SS UTC
  time.strptime(aTime, %d %b %Y %H:%M:%S %Z)
 (2008, 2, 3, 20, 35, 46, 6, 34, 0)

I looked at the documentation for the time module, including 
strptime, but I didn't realize the %b directive would match the 
month abbreviations I'm dealing with. It's described as Locale's 
abbreviated month name; if someone were to run my program on a French 
system e.g., wouldn't it try to find a match among jan, fév, ..., 
déc (or whatever) and fail? Is there a way to declare a locale that 
will override the user's settings? Are the locale-specific strings 
documented anywhere? Can one assume them to be identical in all 
English-speaking countries, at least? Now it's pretty unlikely in this 
case that such an 'international situation' will arise, but I didn't 
want to burn any bridges ...

I was also somewhat put off strptime on reading the caveat Note: This 
function relies entirely on the underlying platform's C library for the 
date parsing, and some of these libraries are buggy. There's nothing to 
be done about this short of a new, portable implementation of 
strptime(). If it works, however, it'll be a lot tidier than what I was 
doing. I'll make a point of testing it on its own, with a variety of 
inputs.

 Note that the %Z is a problematic entry...

 ValueError: time data did not match format:  data=03 Feb 2008 
 20:35:46 PST  fmt=%d %b %Y %H:%M:%S %Z

All the times are UTC, so fortunately this is a non-issue for my 
purposes of the moment. May I assume that leaving the zone out will 
cause the time to be treated as UTC?

Thanks for your help, and for bearing with my elementary questions and 
my fumbling about.

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


polling for output from a subprocess module

2008-02-04 Thread jakub . hrozek
Hello,
My program uses the subprocess module to spawn a child and capture its
output. What I'd like to achieve is that stdout is parsed after the
subprocess finishes, but anything that goes to stderr is printed
immediately. The code currently looks like:

  try:
test = Popen(test_path,
  stdout=PIPE,
  stderr=PIPE,
  close_fds=True,
  env=test_environ)

while test.poll() == None:
ready = select.select([test.stderr], [], [])

if test.stderr in ready[0]:
t_stderr_new = test.stderr.readlines()
if t_stderr_new != []:
print STDERR:, \n.join(t_stderr_new)
t_stderr.extend(t_stderr_new)

except OSError, e:
print sys.stderr, _(Test execution failed), e
else:
self.result.return_code = test.returncode
self.result.process(test.stdout.readlines(), t_stderr)


The problem is, that it seems that all the output from the subprocess
seems to be coming at once. Do I need to take a different approach?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too many open files

2008-02-04 Thread Larry Bates
AMD wrote:
 Hello,
 
 I need to split a very big file (10 gigabytes) into several thousand 
 smaller files according to a hash algorithm, I do this one line at a 
 time. The problem I have is that opening a file using append, writing 
 the line and closing the file is very time consuming. I'd rather have 
 the files all open for the duration, do all writes and then close them 
 all at the end.
 The problem I have under windows is that as soon as I get to 500 files I 
 get the Too many open files message. I tried the same thing in Delphi 
 and I can get to 3000 files. How can I increase the number of open files 
 in Python?
 
 Thanks in advance for any answers!
 
 Andre M. Descombes

Not quite sure what you mean by a hash algorithm but if you sort the file 
(with external sort program) on what you want to split on, then you only have 
to 
have 1 file at a time open.

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


Re: Is it explicitly specified?

2008-02-04 Thread George Sakkis
On Feb 4, 6:53 am, André Malo [EMAIL PROTECTED] wrote:
 * Steven D'Aprano wrote:
  On Sun, 03 Feb 2008 15:31:49 -0800, Paul Boddie wrote:

  I don't know whether I can offer much better advice than others, but I
  have noticed that a lot of my own code has moved in the direction of not
  having specific default values in function/method signatures. So,
  instead of this...

def f(x=123):
  ...

  ...I have this:

def f(x=None):
  if x is None:
x = 123

  For the love of Pete, WHY??

  I understand why you would do it for a mutable default, but immutable???

 I'm observing myself doing the same, for the following reason:

 Consider the function being part of a bigger system, where it's called from
 another function or method which should inherit the default value of the
 function, like:

 def g(foo, bar, x=None):
...
f(x=x)

 Now if you change the default value of f(x) for some reason, you don't have
 to wind up all the possible caller signatures to reflect that change.

You might find handy a decorator I've written exactly for this
scenario, reusing default arguments across functions:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440702

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


Re: Elementary string-parsing

2008-02-04 Thread Marc 'BlackJack' Rintsch
On Mon, 04 Feb 2008 12:25:24 +, Odysseus wrote:

 I'm not clear on what makes an object global, other than appearing as an 
 operand of a global statement, which I don't use anywhere. But na is 
 assigned its value in the program body, not within any function: does 
 that make it global?

Yes.  The term global usually means module global in Python.

 Why is this not recommended?

Because the functions depend on some magic data coming from nowhere and
it's much harder to follow the data flow in a program.  If you work with
globals you can't be sure what the following will print:

def spam():
global x
x = 42
beep()
print x

`beep()` might change `x` or any function called by `beep()` and so on. 

Another issue is testing.  If you rely on global names it's harder to test
individual functions.  If I want to test your `extract_data()` I first have
to look through the whole function body and search all the global
references and bind those names to values before I can call the function. 
This might not be enough, any function called by `extract_data()` might
need some global assignments too.  This way you'll get quite soon to a
point where the single parts of a program can't be tested in isolation and
are not reusable for other programs.

In programs without such global names you see quite clearly in the
``def`` line what the function expects as input.

 If I wrap the assignment in a function, making na a local variable, how
 can extract_data then access it?

Give it as an argument.  As a rule of thumb values should enter a function
as arguments and leave it as return values.

It's easy to enforce if you have minimal code on the module level.  The
usual idiom is:

def main():
# Main program comes here.

if __name__ == '__main__':
main()

Then main is called when the script is called as program, but not called if
you just import the script as module.  For example to test functions or to
reuse the code from other scripts.

 def extract_data(names, na, cells):
 
  and
 
  return something
 
 What should it return? A Boolean indicating success or failure? All the
 data I want should all have been stored in the found dictionary by the
 time the function finishes traversing the list of names.

Then create the `found` dictionary in that function and return it at the
end.

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


Re: Windows - remote system window text

2008-02-04 Thread [EMAIL PROTECTED]
I can understand that. But look at the bright side, you don't have to
rely on windows authentication, you just need an open port. Now i
don't know what you are building, but with a client/server setup you
can also get to other data that you might need, like mouse movement to
detect for activity, username, etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: type, object hierarchy?

2008-02-04 Thread Mel
7stud wrote:
 On Feb 3, 10:28 pm, 7stud [EMAIL PROTECTED] wrote:
 From the docs:

 issubclass(class, classinfo)
 Return true if class is a subclass (direct or indirect) of classinfo.
 
 
 print issubclass(Dog, object)  #True
 print issubclass(type, object)  #True
 print issubclass(Dog, type)   #False
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type help, copyright, credits or license for more information.
  issubclass (object, type)
False
  isinstance (object, type)
True

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


Re: Extending the import mechanism - what is recommended?

2008-02-04 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 On Jan 29, 2:36 pm, Steve Holden [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
 I need to extend the import mechanism to support another file type.
 I've already written the necessary C library to read the file and
 return a python code object.
 I found one example which just sub-classed imputil.ImportManager like
 this:
 from myLib import pye_code as pye_code
 class MyImporter(imputil.ImportManager):
 def __init__(self):
 imputil.ImportManager.__init__(self)
 self.add_suffix('.pye', self.import_pye)
 self.install()
 def import_pye(self, filepath, fileinfo, filename):
 data = pye_code(filepath)
 return 0, data, {}
 This actually works fine if the module is just a few lines of code,
 but it won't chain to the built-in importers; if the module that I'm
 importing does something as simple as 'import re', it fails.
 It may be that my confusion here is because (even after reading the
 code), I'm not clear on the purposes of imputil.ImportManager vs.
 imputil.Importer :-(
 What is the preferred way to do this type of extension?  One other
 note; at this time, I just need to import individual module files with
 this extension; I don't need to import packages.
 Here's an importer I wrote some time ago to bring modules in from a
 relational database. I won't trouble you with the code to compile the
 modules/packages and add them into the database, but perhaps the
 attached code will be enough to show you what you are doing that's not
 working.

[...]
 [dbimp.py]#
 # Import modules from a database
 #
 # NOTE: could use sys version info to select appropriate module version
 #   - could ask whether to install if absent ... heh, heh :-)
 #
 import sys, db, marshal
 VER = sys.hexversion
 ---
 def install():
 sys.path_hooks.append(dbimporter)
 sys.path_importer_cache.clear() # probably not necessary
 sys.path.insert(0, *db*) # probably not needed with a metea-path hook?
 
 Steve -
 
 Thanks!  Got this to work with one interesting problem . . . if I use
 sys.path.insert(0) and insert my hook at the head of the path,
 then I can't import anything EXCEPT my special modules . . . If I use
 sys.path.append(*pye*) then I'm OK.
 
 One thing I changed was that my load_module function raises
 ImportError if it fails; my understanding from reading PEP302 is that
 that's what's SUPPOSED to happen . . .
 
 At any rate, I can now import my custom modules . . . thanks!
 
Excellent news, thanks for letting me know. I can't say that code was 
particularly well-tested, so it's possible that my version makes some 
error that stops the import from running against further path elements 
if the search by the custom importer fails.

May have a few minutes to look at this later, but not for a while. 
Anyway, glad the code helped. Perhaps someone else with more PEP302-fu 
would be able to point out my error.

Any other changes you'd like to feed back besides the ImportError?

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: polling for output from a subprocess module

2008-02-04 Thread Christian Heimes
Thomas Bellman wrote:
 The readlines() method will read until it reaches end of file (or
 an error occurs), not just what is available at the moment.  You
 can see that for your self by running:

Bad idea ;)

readlines() on a subprocess Popen instance will block when you PIPE more
than one stream and the buffer of the other stream is full.

You can find some insight at http://bugs.python.org/issue1606. I
discussed the matter with Guido a while ago.

Christian

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


Re: Python GUI toolkit

2008-02-04 Thread Chris Mellon
On Feb 4, 2008 9:19 AM,  [EMAIL PROTECTED] wrote:

 
  Another toolkit you might look into is Tkinter. I think it is something
  like the official toolkit for python. I also think it is an adapter
  for other toolkits, so it will use gtk widgets on gnome, qt widgets on
  kde and some other strange widgets on windows.
 

 Not t so,  AFAIK. Tkinter is the python adapter for Tk, the toolkit
 originally developed for Tcl language.

 The latest version of Tk (not yet integrated in Python, maybe in 2.6)
 has themes, which emulates
 the look-and-feel of native toolkit at list for XP and OS X. For unix,
 the last time I checked, there was only a theme that looked like a
 plainer version of Gtk default theme. No Gnome or Kde themes yet.

Nitpick, but an important one. It emulates *look*. Not feel. Native
look is easy and totally insufficient for a native app - it's the
feel that's important.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project naming suggestions?

2008-02-04 Thread Kay Schluehr
On Feb 3, 7:17 pm, [EMAIL PROTECTED] wrote:
 I'm considering writing a little interpreter for a python-like
 language and I'm looking for name suggestions. :-)

 Basically, I don't want to change a whole lot about Python.  In fact,
 I see myself starting with the compiler module from Python 2.5 and
 building from there.

 This language would be more or less Python modulo a few
 (incompatible) changes, but it'd be recognizable by Python
 programmers.  I'm talking about stuff like allowing the character '?'
 in identifier names, and a better way to express 'for dummy in
 xrange (n):' when the index isn't needed.  I'd also like to
 implement  most of the planned Python 3000 changes.

 Any suggestions?  I'm thinking Ophidian, for the snake connection,
 or, possibly, Circus, from Monty Python's Flying Circus.

 Thanks :-)

What about Argh!. Sounds like Paul Grahams Arc but is more Monty
Pythonesque than Circus.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Smart Debugger (Python)

2008-02-04 Thread kraman
On Feb 3, 3:55 pm, Norm Matloff [EMAIL PROTECTED] wrote:
 I have something of an obsession with debuggers, so I was glad to see
 this posting.  While we're on the subject, I might as well add my own
 small contribution, which I call Xpdb.

 Xpdb is available athttp://heather.cs.ucdavis.edu/~matloff/xpdb.html
 Quoting from the beginning of that page:

I tend to use GUI debugging tools with Python, but often find that
PDB is adequate or even superior. It loads instantly, doesn't take up
much real estate on the screen, and its ability to set up aliases/macros
is very valuable. (Note too Rocky Bernstein's new PYDB, at
http://sourceforge.net/project/showfiles.php?
group_id=61395package_id=175827.)

However, I missed having a window that displays my source code and my
current position in it, so I added such a window to PDB, using
curses, somewhat analogously to the CGDB variant of GDB (and the -tui
option in GDB). The result, Xpdb, is available at
http://heather.cs.ucdavis.edu/~matloff/Python/Xpdb/Code/.  It is
nothing fancy at all, mainly just a source window capability added
to PDB (though with a couple of extra new features).

 Norm Matloff

It'll be helpful if you provide some screenshots on how this work
-- 
http://mail.python.org/mailman/listinfo/python-list


App idea, Any idea on implementation?

2008-02-04 Thread Dr Mephesto
Hi Guru's,

As a python newb, I was thinking about trying to implement a program
that converts whistled music into midi; the idea coming from a
proposed  application in the Mydreamapp competition hosted last year,
more details here: http://stratfordisland.com/whistler/

So, does anyone have a suggestion as to the best way to implement
this? I was thinking maybe a fast fourier ever 20th of a second,
selecting the dominant frequency, and then mapping that onto a real
musical scale, then stretching or cutting the notes to a preselected
timing scheme. Is this a stupid idea? Can one do a real time fourier
transform in python? Or is there some other way to find the frequency
of a whistle easily? I want to do this in real time, so as you whistle
a tune, you see the notes appear, but if this is too hard, the
prerecorded should be also good I guess.

Im just looking for some vague opinion on how to start, so please post
any idea you might have, every thing helps!  Also, If you know of any
code that already exist that might help, please post a link!

Thanks in Advance,
Dave
-- 
http://mail.python.org/mailman/listinfo/python-list


Windows - remote system window text

2008-02-04 Thread rdahlstrom
OK - I know how to get the text/title of the windows on a local system
by using the window handle.  What I want to do is to get the text/
title of the windows on a remote system.  Enumerating the window
handles will of course not work remotely, I know that.  Does anyone
know anything short of a client/server setup that *will* work?

Everything would be Windows 2003 server, and I can assume that I have
administrative rights to all affected machines.

Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unexpected timing results with file I/O

2008-02-04 Thread rdahlstrom
On Feb 4, 1:12 pm, Carl Banks [EMAIL PROTECTED] wrote:
 On Feb 4, 12:53 pm, rdahlstrom [EMAIL PROTECTED] wrote:



  On Feb 4, 10:17 am, Steven D'Aprano [EMAIL PROTECTED]

  cybersource.com.au wrote:
   After reading an earlier thread about opening and closing lots of files,
   I thought I'd do a little experiment.

   Suppose you have a whole lot of files, and you need to open each one,
   append a string, then close them. There's two obvious ways to do it:
   group your code by file, or group your code by procedure.

   # Method one: grouped by file.
   for each file:
   open the file, append the string, then close it

   # Method two: grouped by procedure.
   for each file:
   open the file
   for each open file:
   append the string
   for each open file:
   close the file

   If you have N files, both methods make the same number of I/O calls: N
   opens, N writes, N closes. Which is faster?

   Intuitively, the first method has *got* to be faster, right? It's got one
   loop instead of three and it doesn't build an intermediate list of open
   file objects. It's so *obviously* going to be faster that it is hardly
   worth bothering to check it with timeit, right?

   Well, I wouldn't be writing unless that intuitive result was wrong. So
   here's my test results:

   Method 1:

import timeit
names = ['afile' + str(n) for n in range(1000)]
T = timeit.Timer('''for name in names:

   ... fp = open(name, 'a'); fp.write('xyz\\n'); fp.close()
   ... ''', 'from __main__ import names') min(T.repeat(6, 500))

   17.391216039657593

   Method 2:

for name in names:  # reset the files to an empty state.

   ... fp = open(name, 'w'); fp.close()
   ... T = timeit.Timer('''files = [open(name, 'a') for name in names]

   ... for fp in files:
   ... fp.write('xyz\\n')
   ... for fp in files:
   ... fp.close()
   ... ''', '''from __main__ import names''') min(T.repeat(6, 500))

   16.823362112045288

   Surprisingly, Method 2 is a smidgen faster, by about half a second over
   500,000 open-write-close cycles. It's not much faster, but it's
   consistent, over many tests, changing many of the parameters (e.g. the
   number of files, the number of runs per timeit test, etc.).

   I'm using Linux and Python 2.5.

   So, what's going on? Can anyone explain why the code which does more work
   takes less time?

   --
   Steven

  The code that does more work takes more time.  The second one does
  quite a bit less work.  Think of it like this:

  You have 500,000 people to fit through a door.  Here are your options:

  1.  For each person, open the door, walk through the door, then close
  the door.
  2.  Open the door, allow everyone to walk through, then close the
  door.

  Which one would you say would be a more efficient way to fit 500,000
  people through the door?

 Bad analogy.  A better analogy would be if each person has their own
 door to walk through.

 My hunch is that is has to do with the OS I/O scheduling.  Closing a
 file triggers a cache flush, which in turn triggers the I/O to
 schedule a write to disk; the OS scheduler is perhaps more efficient
 (for a given number of total writes) when it can combine many writes
 at the same time.

 Carl Banks

The analogy holds.  It's faster to open the door, do what you need to
do, then close the door than it is to open and close the door each
time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows - remote system window text

2008-02-04 Thread rdahlstrom
On Feb 4, 2:17 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Well, i guess you will need a process on each machine you need to
 monitor, and then you do have a client server setup.

 This can be easily accomplished with fx Pyro (http://
 pyro.sourceforge.net/) for communication, and the Win32 Python library
 (https://sourceforge.net/projects/pywin32/) for creating a service.

Crap, that's what I didn't want to do.  I am slowly coming to the
realization that I'm going to have to, but I really didn't want to do
that.  That brings up a whole host of other things that I would then
have to do - remote installation, etc.  I guess I could do it, but I'd
really rather not.
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQLdb: commit before cursor close, or after?

2008-02-04 Thread John Nagle
   I'm getting some wierd commit-related behavior from MySQLdb.  I'm
using InnoDB, so transactions really matter.

I'm currently doing

cursor = db.cursor()
cursor.execute(...)
cursor.close()  
db.commit() 

Is that the correct order, or should I call db.commit() before 
cursor.close()?  Does anyone know for sure?  The MySQLdb documentation
(http://mysql-python.sourceforge.net/MySQLdb.html;) doesn't
say.  There are some discussions of this in blogs, but nobody
really seems to know.

John Nagle  

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


Re: polling for output from a subprocess module

2008-02-04 Thread jakub . hrozek
On 4 Ún, 11:49, Thomas Bellman [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
try:
  test = Popen(test_path,
stdout=PIPE,
stderr=PIPE,
close_fds=True,
env=test_environ)
  while test.poll() == None:
  ready = select.select([test.stderr], [], [])
  if test.stderr in ready[0]:
  t_stderr_new = test.stderr.readlines()
  if t_stderr_new != []:
  print STDERR:, \n.join(t_stderr_new)
  t_stderr.extend(t_stderr_new)
 [...]
  The problem is, that it seems that all the output from the subprocess
  seems to be coming at once. Do I need to take a different approach?

 The readlines() method will read until it reaches end of file (or
 an error occurs), not just what is available at the moment.  You
 can see that for your self by running:

 $ python -c 'import sys; print sys.stdin.readlines()'

 The call to sys.stdin.readlines() will not return until you press
 Ctrl-D (or, I think, Ctrl-Z if you are using MS-Windows).

 However, the os.read() function will only read what is currently
 available.  Note, though, that os.read() does not do line-based
 I/O, so depending on the timing you can get incomplete lines, or
 multiple lines in one read.


Right, I didn't realize that. I'll try the os.read() method. Reading
what's available (as opposed to whole lines) shouldn't be an issue in
this specific case. Thanks for the pointer!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb: commit before cursor close, or after?

2008-02-04 Thread Steve Holden
Carsten Haese wrote:
 On Mon, 2008-02-04 at 19:53 +0100, Frank Aune wrote:
 No, you obviously need to commit your changes before closing the cursor. I'm 
 surprised if your code above even works if adding content to the db.
 
 Why is that obvious? Is this some MySQL-specific oddity? In other
 databases, it's the cursor's execute() method that adds the content to
 the db (pending a commit of the transaction), and closing the cursor
 simply means that you are explicitly releasing the resources that the
 cursor used. Whether the cursor is closed before or after the
 transaction is committed, or even whether the cursor is explicitly
 closed at all or not, should make no difference whatsoever.
 
Certainly isn't obvious to me. The whole point of the way 
connection/cursor relationship is structured is to allow the possibility 
of several cursors on the same connection. So cursors can be created, 
used and closed at will without any effect on the underlying connection.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Pysqlite issue no attribute 'autocommit'

2008-02-04 Thread Paul McNett
Andy Smith wrote:

  
   Im trying to run a Python based program which uses MySQL with 
 python-sqlite and Im recieving this error,
  
 'Connection' object has no attribute 'autocommit'
  
 I´ve had a google for this and its seems like it may be a bug 
 python-sqlite or sqlite bug , but also I tried searching
 for it on the python issue traker and didnt find anything. Is anyone 
 else aware of this issue and any solution?
  
 thanks for any help! Andy.
  
 PS sorry if I didnt include much info, hoping its a known issue (and 
 also I didnt write the code, so not sure what
 else to include off the top of my head! :P)

What you should do is post the entire traceback.


Paul

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

Re: Very weird behavior in MySQLdb execute

2008-02-04 Thread Carsten Haese
On Mon, 2008-02-04 at 11:30 -0800, John Nagle wrote:
 Restarting the MySQL instance changes the database.  The entry google.com
 disappears, and is replaced by www.google.com.  This must indicate a hanging
 transaction that wasn't committed.
 
 But that transaction didn't come from the Python IDLE session I've been
 making test calls from.  Those queries should match the graphical client
 exactly.
 
 So why don't they agree?

I don't have a definitive answer, but I do have a piece of generic
advice. If two database sessions receive differing results, the cause
could be any of the following factors:

1) One session is in a transaction, but the other is not.

2) Both sessions are in a transaction, but they are at different
isolation levels.

3) Both sessions are in a transaction, but the transactions were started
at different times.

It's entirely possible that the graphical client was operating outside
of a transaction, showing you phantom rows of a transaction in progress,
whereas the Python IDLE session was inside a transaction at something
like read last committed (or whatever MySQL calls it) isolation level.

Any of the factors above determine which snapshot of the data will be
visible to the database clients. Unless you are *absolutely certain*
that both clients should have seen the exact same snapshot, it's really
not all that weird that you are seeing discrepancies, especially in
light of the fact that you had an uncommitted transaction hanging around
somewhere.

Hope this helps,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Unexpected timing results with file I/O

2008-02-04 Thread Marc 'BlackJack' Rintsch
On Mon, 04 Feb 2008 10:18:39 -0800, rdahlstrom wrote:

 On Feb 4, 1:12 pm, Carl Banks [EMAIL PROTECTED] wrote:
 On Feb 4, 12:53 pm, rdahlstrom [EMAIL PROTECTED] wrote:
  You have 500,000 people to fit through a door.  Here are your options:

  1.  For each person, open the door, walk through the door, then close
  the door.
  2.  Open the door, allow everyone to walk through, then close the
  door.

  Which one would you say would be a more efficient way to fit 500,000
  people through the door?

 Bad analogy.  A better analogy would be if each person has their own
 door to walk through.

 The analogy holds.  It's faster to open the door, do what you need to
 do, then close the door than it is to open and close the door each
 time.

It doesn't hold.  Read the code again.  The total count of open door and
close door is the same in both cases.

It's

  for every person:
  open his door; push him through the door; close his door

vs.

  for every person:
  open his door
  for every person:
  push him through the door
  for every person:
  close his door

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


Re: Windows - remote system window text

2008-02-04 Thread [EMAIL PROTECTED]
Well, i guess you will need a process on each machine you need to
monitor, and then you do have a client server setup.

This can be easily accomplished with fx Pyro (http://
pyro.sourceforge.net/) for communication, and the Win32 Python library
(https://sourceforge.net/projects/pywin32/) for creating a service.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Linux Journal Survey

2008-02-04 Thread Florian Diesch
Albert van der Horst [EMAIL PROTECTED] wrote:

 In article [EMAIL PROTECTED],
 Russ P. [EMAIL PROTECTED] wrote:
On Jan 23, 7:42 pm, George Sakkis [EMAIL PROTECTED] wrote:
 On Jan 23, 8:14 pm, [EMAIL PROTECTED] wrote:

  The annual Linux Journal survey is online now for any Linux users who
  want to vote for Python.  http://www.linuxjournal.com/node/1006101

 ...

 18. What is your favorite programming language?

 (15 choices, Python not included)

 19. What is your favorite scripting language?

 o Python

 o Perl

 (5 more choices)

 Python is much more than a scripting language (whatever this means,
 other than a semi-derogatory term used by clueless PHBs). Sorry, I'll
 pass.

 George


Someone please correct me if I am wrong, but I think of a Python
script as a flat source file with no (or few) functions or classes,
whereas a full-blown program has functions and classes. Both have
their place.

I agree it is unfortunate that the Linux World poll classified Python
as a scripting language. I suspect they did that because Python is
not (typically) compiled and does not have static typing.

 In the context of linux a programming language is
 a language that generates an ELF binary executable to be stored
 in a /.../bin/ directory.
 A scripting language is a language whose programs are normally
 distributed in human-readable form. It is appropriate to call

So a scripting language is a language that is usually used for Open
Source software while a programming language is usually used for
ClosedSource software?

What kind of language has C been in the good old days when gcc
produced aout binaries instead of ELF?

 such a program a script. If the first two characters is #!
 and the execution bit is set, it is a script in the linux sense.

Thanks to the binfmt_misc kernel module you can execute python byte 
code just like you execute native code:

[EMAIL PROTECTED]:~% bin/hello 
Hello world!
[EMAIL PROTECTED]:~% file bin/hello
bin/hello: python 2.5 byte-compiled
[EMAIL PROTECTED]:~% head -n1 bin/hello 
³ò

 So as far as I can tell it boils down to a clear technical
 distinction

IMHO it's neither a clear nor a useful one.


   Florian
-- 
http://www.florian-diesch.de/
---
**  Hi! I'm a signature virus! Copy me into your signature, please!  **
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project naming suggestions?

2008-02-04 Thread [EMAIL PROTECTED]
On 4 fév, 18:26, Kay Schluehr [EMAIL PROTECTED] wrote:
 On Feb 3, 7:17 pm, [EMAIL PROTECTED] wrote:



  I'm considering writing a little interpreter for a python-like
  language and I'm looking for name suggestions. :-)

  Basically, I don't want to change a whole lot about Python.  In fact,
  I see myself starting with the compiler module from Python 2.5 and
  building from there.

  This language would be more or less Python modulo a few
  (incompatible) changes, but it'd be recognizable by Python
  programmers.  I'm talking about stuff like allowing the character '?'
  in identifier names, and a better way to express 'for dummy in
  xrange (n):' when the index isn't needed.  I'd also like to
  implement  most of the planned Python 3000 changes.

  Any suggestions?  I'm thinking Ophidian, for the snake connection,
  or, possibly, Circus, from Monty Python's Flying Circus.

  Thanks :-)

 What about Argh!. Sounds like Paul Grahams Arc but is more Monty
 Pythonesque than Circus.

Lol !

And +1, BTW
-- 
http://mail.python.org/mailman/listinfo/python-list


Pysqlite issue no attribute 'autocommit'

2008-02-04 Thread Andy Smith

Hi there,

  Im trying to run a Python based program which uses MySQL with python-sqlite 
and Im recieving this error,

'Connection' object has no attribute 'autocommit'

I´ve had a google for this and its seems like it may be a bug python-sqlite or 
sqlite bug , but also I tried searching 
for it on the python issue traker and didnt find anything. Is anyone else aware 
of this issue and any solution?

thanks for any help! Andy.

PS sorry if I didnt include much info, hoping its a known issue (and also I 
didnt write the code, so not sure what
else to include off the top of my head! :P)-- 
http://mail.python.org/mailman/listinfo/python-list

Very weird behavior in MySQLdb execute

2008-02-04 Thread John Nagle
   This has me completely mystified.  Some SELECT operations performed through 
MySQLdb produce different results than with the MySQL graphical client.
This failed on a Linux server running Python 2.5, and I can reproduce it
on a Windows client running Python 2.4.  Both are running MySQL 2.5.

The table involved is:

CREATE TABLE domaincache
(
domain VARCHAR(255) NOT NULL UNIQUE PRIMARY KEY,
rating CHAR(1) NULL,
rating_info ENUM 
('error','no_domain','no_website','blocked','no_location','negative_info','non_commercial','unverified')
 
NULL,
special_case ENUM('normal','special'),  
rating_id BIGINT UNSIGNED NULL, 
last_update_end TIMESTAMP NOT NULL, 
version SMALLINT UNSIGNED NOT NULL, 
INDEX (rating_id)   

);

Nothing exciting there.

In the MySQL query browser, I can do either

select * from domaincache where domain = adwords.google.com
or
select * from domaincache where domain = google.com

and I get one record back from each, with the correct info.  That's correct.

Querying the database from Python gives different results.  The database
connection is made with:

db = MySQLdb.connect(host=localhost,
use_unicode = True, charset = utf8,
user=username, passwd=password, db=database)

When I make the same queries from Python, via IDLE, typing in commands:

cursor.execute('SELECT * FROM domaincache WHERE 
domain=adwords.google.com')

returns 0L, no rows, which is wrong. That domain is in the database, and
a SELECT from the graphical client will find it.

But

cursor.execute('SELECT * FROM domaincache WHERE domain=google.com')

returns 1L, one row, which is correct.

The database is InnoDB, and CHECK TABLE says the database is valid.

Restarting the MySQL instance changes the database.  The entry google.com
disappears, and is replaced by www.google.com.  This must indicate a hanging
transaction that wasn't committed.

But that transaction didn't come from the Python IDLE session I've been
making test calls from.  Those queries should match the graphical client
exactly.

So why don't they agree?




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


Re: Unexpected timing results with file I/O

2008-02-04 Thread Gabriel Genellina
En Mon, 04 Feb 2008 15:53:11 -0200, rdahlstrom [EMAIL PROTECTED]  
escribi�:

 On Feb 4, 10:17 am, Steven D'Aprano [EMAIL PROTECTED]
 cybersource.com.au wrote:

 Suppose you have a whole lot of files, and you need to open each one,
 append a string, then close them. There's two obvious ways to do it:
 group your code by file, or group your code by procedure.

 # Method one: grouped by file.
 for each file:
 open the file, append the string, then close it

 # Method two: grouped by procedure.
 for each file:
 open the file
 for each open file:
 append the string
 for each open file:
 close the file

 If you have N files, both methods make the same number of I/O calls: N
 opens, N writes, N closes. Which is faster?

 The code that does more work takes more time.  The second one does
 quite a bit less work.  Think of it like this:

 You have 500,000 people to fit through a door.  Here are your options:

 1.  For each person, open the door, walk through the door, then close
 the door.
 2.  Open the door, allow everyone to walk through, then close the
 door.

 Which one would you say would be a more efficient way to fit 500,000
 people through the door?

Mmmm, no, the second one should be:

2. Create 500,000 doors and open them.
Make each person enter the room -one at a time- using its own door.
Close each of the 500,000 doors.

-- 
Gabriel Genellina

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

Re: extending python with array functions

2008-02-04 Thread Gabriel Genellina
En Mon, 04 Feb 2008 18:44:42 -0200, Janwillem [EMAIL PROTECTED]  
escribió:

 I want to make numerical functions that can be called from python.
 I am programming in pascal the last few decades so I had a look at
 python for delphi (P4D). The demo09 gives as example  add(a,b) using
 integers and pyarg_parsetuple. That works!

 However, I cannot figure out what to do when a, b and the result are
 arrays (or matrices) of float (for i:=0 to high(a) do c[i]:=a[i]+b[i];
 and then return c to python). Although from the ALGOL60 school and
 always tried to keep far from pointers, I might also understand advise  
 in C.

First: do you know NumPy? http://numpy.scipy.org/
NumPy provides powerful functions to work with numeric arrays. Maybe using  
this library you don't even have to write an extension and you can keep  
all your code in Python with reasonable speed. It may be the best option  
depending on your needs.

In case you still have to write an extension:

- the usual container for Python objects is a list; it's a generic  
container and can hold any kind of objects, but there are other  
alternatives too. To access its elements from Delphi, use the  
PySequence_XXX family of functions (or PyList_XXX if you know it is an  
actual list).

- the array module http://docs.python.org/lib/module-array.html provides  
homogeneuos arrays that may be more efficient for your application. arrays  
don't have a special API, you have to import the module and use its  
functions the same as one would do in pure Python.

-- 
Gabriel Genellina

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


Dynamic Lookup in C#

2008-02-04 Thread bearophileHUGS
It seems C# 4.0 may become a bit closer to dynamic languages,
especially closer to the Boo language (that is mostly static):
http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx

As it develops, and its VM gains the method inlining capabilities of
HotSpot, it will be faster. Static languages like D may have a hard
time keeping up with that speed of language evolution.

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


Re: Problem with Image: Opening a file

2008-02-04 Thread Graham Dumpleton
On Feb 4, 6:51 pm, mcl [EMAIL PROTECTED] wrote:
 I am obviously doing something stupid or not understanding the
 difference between HTML file references and python script file
 references.

 I am trying to create a thumbnail of an existing .jpg file. It is in
 the directory 'temp', which is below my script

 I can display the file with img, but Image.open does not see it.

 I think it is probably a path problem, but I have tried '/temp/
 fred.jpg' and './temp/fred.jpg'

 Can anyone help, please

 PS I am usingmod_pythonon a Linux Apache 2 and python 2.5

 CODE =

 import os
 import StringIO

 def index(req):
 main(req)

 def writeHTMLHeader(req):

 req.content_type = text/html
 req.write('!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//
 EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;')
 req.write('html xmlns=http://www.w3.org/1999/xhtml; lang=en
 xml:lang=en')
 req.write('headtitleMy Tests: Python/title/head')
 req.write('body')

 def writeHTMLTrailer(req):
 req.write('/body')
 req.write('/html')

 def writelineHTML(req, htmlMSG):
 req.write(htmlMSG + 'BR\n')

 def createThumb(req, infile, maxwidth, maxheight):
 import Image
 import os
 infile = temp/fred.jpg
 outfile = temp/fred_th.jpg
 if infile != outfile:

 writelineHTML(req, Opening %s % str(infile))
 writelineHTML(req, 'img src=%s/img' % infile)  # Finds
 File OK ***
 im =
 Image.open(infile) #
 ERRORS on the same file *
 im.thumbnail((maxwidth,maxheight),Image.ANTIALIAS)
 im.save(outfile, JPEG)
 writelineHTML(req, Created:  + str(outfile))
 writelineHTML(req, 'img src=%s/img' % outfile)

 return outfile

 return 

 def showThumbnail(req, picture):
 myThumb = createThumb(req, picture, 60, 60)
 if myThumb:
 writelineHTML(req, 'img src=%s/img' % myThumb)
 else:
 writelineHTML(req, Thumb %s Not Created % myThumb)

 def main(req):
 writeHTMLHeader(req)
 picture = temp/fred.jpg
 showThumbnail(req, picture)
 writeHTMLTrailer(req)

 ERROR ==

   File /home/mcl/htdocs/timslists/thumbs2.py, line 33, in
 createThumb
 im = Image.open(infile)

   File /usr/lib/python2.5/site-packages/PIL/Image.py, line 1888, in
 open
 fp = __builtin__.open(fp, rb)

 IOError: [Errno 2] No such file or directory: 'temp/fred.jpg'

 Richard

Code under mod_python will typically run as Apache user. This means
that when writing files the location you use must be writable to the
Apache user. Do note though that the working directory of Apache is
not guaranteed and you must always use an absolute path to the
location you are saving files, you cannot reliably use relative paths
like you are.

BTW, do you perhaps mean '/tmp/fred.jpg'? There is no '/temp'
directory on Linux boxes.

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


Re: App idea, Any idea on implementation?

2008-02-04 Thread Dr Mephesto
thanks for the pointers!

I just found a program that does more or less what I want, but I would
still like to have a go myself. The link is: 
http://www.akoff.com/music-composer.html

I gave the program a go, as there is a free trial. I found that it had
a hard time doing the conversion (or I am a really bad whistler),
maybe there is room for improvements.

So, I know it can be done, the question is, does Python have to power
to do it? And how did they actually do it anyway...



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


Re: Windows - remote system window text

2008-02-04 Thread Gabriel Genellina
En Mon, 04 Feb 2008 17:25:00 -0200, rdahlstrom [EMAIL PROTECTED]  
escribió:
 On Feb 4, 2:17 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Well, i guess you will need a process on each machine you need to
 monitor, and then you do have a client server setup.

 Crap, that's what I didn't want to do.  I am slowly coming to the
 realization that I'm going to have to, but I really didn't want to do
 that.

Try WMI. I don't know for sure if you can enumerate windows, maybe yes. At  
least you can enumerate remote processes.

-- 
Gabriel Genellina

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


Re: Mysterious xml.sax Encoding Exception

2008-02-04 Thread JKPeck
On Feb 2, 12:56 am, Jeroen Ruigrok van der Werven [EMAIL PROTECTED]
nomine.org wrote:
 -On [20080201 19:06], JKPeck ([EMAIL PROTECTED]) wrote:

 In both of these cases, there are only plain, 7-bit ascii characters
 in the xml, and it really is valid utf-16 as far as I can tell.

 Did you mean to say that the only characters they used in the UTF-16 encoded
 file are characters from the Basic Latin Unicode block?

 --
 Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
 イェルーン ラウフロック ヴァン デル ウェルヴェンhttp://www.in-nomine.org/|http://www.rangaku.org/
 We have met the enemy and they are ours...

It appears that the root cause of this problem is indeed passing a
Unicode XML string to xml.sax.parseString with an encoding declaration
in the XML of utf-16.  This works with the standard distribution on
Windows.  It does not work with ActiveState on Windows even though
both distributions report
64K for sys.maxunicode.

So I don't know why the results are different, but the problem is
solved by encoding the Unicode string into utf-16 before passing it to
the parser.

Thanks to all for helping to track this down.

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

Re: Very weird behavior in MySQLdb execute

2008-02-04 Thread John Nagle
Carsten Haese wrote:
 On Mon, 2008-02-04 at 11:30 -0800, John Nagle wrote:
 Restarting the MySQL instance changes the database.  The entry google.com
 disappears, and is replaced by www.google.com.  This must indicate a 
 hanging
 transaction that wasn't committed.

 But that transaction didn't come from the Python IDLE session I've been
 making test calls from.  Those queries should match the graphical client
 exactly.

 So why don't they agree?
 
 I don't have a definitive answer, but I do have a piece of generic
 advice. If two database sessions receive differing results, the cause
 could be any of the following factors:
 
 1) One session is in a transaction, but the other is not.
 
 2) Both sessions are in a transaction, but they are at different
 isolation levels.
 
 3) Both sessions are in a transaction, but the transactions were started
 at different times.

 I see what's wrong, I think.  I haven't been doing a commit after
a SELECT.  I've been careful to commit after write-type actions,
but not after read-only actions.  I'm using InnoDB in default mode,
which is REPEATABLE READ, and I've recently switched to long-running
processes which keep the database connection open for hours.  So the
data view for a given connection never changes, regardless of what's
happening in other threads.

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


Re: Windows - remote system window text

2008-02-04 Thread rdahlstrom
On Feb 4, 2:50 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 I can understand that. But look at the bright side, you don't have to
 rely on windows authentication, you just need an open port. Now i
 don't know what you are building, but with a client/server setup you
 can also get to other data that you might need, like mouse movement to
 detect for activity, username, etc.

That is true, and I could use some of the additional functionality I
guess...
-- 
http://mail.python.org/mailman/listinfo/python-list


(websearch) script ?

2008-02-04 Thread Stef Mientki
hello,

Being very satisfied with Python as a general program language,
and having troubles with a number of PHP scripts, moving to another 
provider,
I wanted to replace the PHP scripts with Python Scripts.

The most important one is a PHP script that searches text in all 
documents on my website.
Does someone has such a script ?

Now in more general,
If I need such a script in PHP or Perl, I can find dozens on the web,
for Python I can not find None ???

Am I mistaken that these kind of tasks can be equally well performed by 
Python as PHP or Perl ?
If so, why can't I find all kinds of standard scripts on the web ?
Just curious.

thanks,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


extending python with array functions

2008-02-04 Thread Janwillem
I want to make numerical functions that can be called from python.
I am programming in pascal the last few decades so I had a look at 
python for delphi (P4D). The demo09 gives as example  add(a,b) using 
integers and pyarg_parsetuple. That works!

However, I cannot figure out what to do when a, b and the result are 
arrays (or matrices) of float (for i:=0 to high(a) do c[i]:=a[i]+b[i]; 
and then return c to python). Although from the ALGOL60 school and 
always tried to keep far from pointers, I might also understand advise in C.

Please get me started e.g. by giving a simple example.
Many thanks,
Janwillem
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: type, object hierarchy?

2008-02-04 Thread Steve Holden
Christian Heimes wrote:
 7stud wrote:
 The output suggests that Dog actually is a subclass of type--despite
 the fact that issubclass(Dog, type) returns False.  In addition, the
 output of dir(type) and dir(object):
 
 No, type is the meta class of the class object:
 
 issubclass(object, type)
 False
 isinstance(object, type)
 True
 
 As you can see object is not a subclass of type but an instance of type.
 This may look confusing at first but it's easy to explain. Like a class
 is the blue print of an instance, a meta class is the blue print of a
 class. In Python everything is a direct or indirect instance of type.
 
This might be helpful is the phrase indirect instance had any meaning 
whatseover ;-)

 o = someobject
 while o is not type:
 o = type(o)
 print o
 
 The code will eventually print type.
 
Except, of course, when someobject is type, when it won't print anything 
at all.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Module/package hierarchy and its separation from file structure

2008-02-04 Thread NickC
On Jan 31, 12:27 am, Gabriel Genellina [EMAIL PROTECTED] wrote:
 Python stores filename and line number information in code objects
 (only). If you have a reference to any code object (a method, a
 function, a traceback...) inspect can use it to retrieve that
 information.

Aside from general concerns about increasing the size of class objects
(and most programs don't contain enough of those to make a big
difference) I don't immediately see anything that would prevent the
interpreter being modified to add file and line number information to
class objects as well. While the information wouldn't always be
present (types implemented in C, types created by calling the
metaclass constructor directly), it would help address the inspect
module bugs Steven illustrated.

I would agree with Carl that modifying __module__ in the way he
suggests is legitimate - if it breaks the inspect module, then it is
the inspect module that needs fixing (and/or better support from the
interpreter to help find the real source code).

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


Re: MySQLdb: commit before cursor close, or after?

2008-02-04 Thread John Nagle
Steve Holden wrote:
 Carsten Haese wrote:
 On Mon, 2008-02-04 at 19:53 +0100, Frank Aune wrote:
 No, you obviously need to commit your changes before closing the 
 cursor. I'm surprised if your code above even works if adding content 
 to the db.

 Why is that obvious? Is this some MySQL-specific oddity? In other
 databases, it's the cursor's execute() method that adds the content to
 the db (pending a commit of the transaction), and closing the cursor
 simply means that you are explicitly releasing the resources that the
 cursor used. Whether the cursor is closed before or after the
 transaction is committed, or even whether the cursor is explicitly
 closed at all or not, should make no difference whatsoever.

 Certainly isn't obvious to me. The whole point of the way 
 connection/cursor relationship is structured is to allow the possibility 
 of several cursors on the same connection. So cursors can be created, 
 used and closed at will without any effect on the underlying connection.

 It really isn't clear.  MySQL has no concept of cursors.  See
the C api: http://dev.mysql.com/doc/refman/5.0/en/c-api-function-overview.html;
Cursors are an illusion created by the MySQLdb library.  What MySQL does
have is a current result set.  After doing something that generates a
result set, the C API call mysql_result_set() is called, then mysql_fetch_row()
is called for each row, followed by mysql_free_result().

 You can't really have multiple cursors on the same connection at the same
time.  MySQL doesn't allow issuing new queries until mysql_result_set() is done.
See http://dev.mysql.com/doc/refman/5.0/en/mysql-use-result.html;.   If
you try, a commands out of sync error should be generated.  The
MySQL C interface only allows one thing at a time per connection, and
MySQLdb is written on top of that.

 Given that, it makes sense to close the cursor before committing. That
frees up the connection for the next command.
But I'm not sure, and I have a bug that seems to be related to
a transaction not committing properly.

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


Re: Client side GUI-like web framework ?

2008-02-04 Thread Michael L Torrie
USCode wrote:
 [EMAIL PROTECTED] wrote:
 You just described what XUL aims to be
 http://developer.mozilla.org/en/docs/The_Joy_of_XUL
 http://developer.mozilla.org/en/docs/XULRunner

 At present it lacks for sure documentation (or maybe it isn't
 organized really well)
 
 Just took a look at XUL and it in some ways describes what I was 
 thinking except it doesn't appear to deliver it's interface via a 
 browser/web server.  Then your application wouldn't be accessible via a 
 web browser through the internet.  The XUL application still appears to 
 only execute locally on the client machine?

But it is served up in the firefox web browser.  A good example is:

http://www.faser.net/mab/chrome/content/mab.xul

The UI always, by definition, has to run on the client.  This is true
whether you're talking about a non-web-based GUI, or an html form.  XUL
is no different.  XUL does blend client and server-side logic into a
stateful app.

 
 Also, personally I find having to describe your interface directly via 
 XML (XUL) is just plain ugly.

I agree completey.

 


-- 
Michael Torrie
Assistant CSR, System Administrator
Chemistry and Biochemistry Department
Brigham Young University
Provo, UT 84602
+1.801.422.5771

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


Re: Spawn new process - get pid

2008-02-04 Thread Gabriel Genellina
En Mon, 04 Feb 2008 20:59:16 -0200, breal [EMAIL PROTECTED]  
escribió:

 I have a soap server written in Python that acts as an intermediary
 between a web service and an InDesign server.  The indesign server is
 non-threaded, so when all instances are used up I want to create a new
 instance, get the pid, use the process, then kill it.

 What is the best way to do this?  I don't want to replace the current
 process with the new one which is looks like os.exec* does.

Use the subprocess module:
http://docs.python.org/lib/module-subprocess.html

-- 
Gabriel Genellina

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


Re: Spawn new process - get pid

2008-02-04 Thread breal
On Feb 4, 3:34 pm, Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Mon, 04 Feb 2008 20:59:16 -0200, breal [EMAIL PROTECTED]
 escribió:

  I have a soap server written in Python that acts as an intermediary
  between a web service and an InDesign server.  The indesign server is
  non-threaded, so when all instances are used up I want to create a new
  instance, get the pid, use the process, then kill it.

  What is the best way to do this?  I don't want to replace the current
  process with the new one which is looks like os.exec* does.

 Use the subprocess module:http://docs.python.org/lib/module-subprocess.html

 --
 Gabriel Genellina

Thanks for the reply.  Using subprocess.Popen I am able to get and
kill the process.  However, the process I am running creates another
process (an instance of InDesign Server) so when I kill the first
process it doesn't kill the second.  Is there any way to capture both
PIDs and kill them?

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


Re: Unexpected timing results with file I/O

2008-02-04 Thread Steven D'Aprano
On Mon, 04 Feb 2008 17:08:02 +, Marc 'BlackJack' Rintsch wrote:

 Surprisingly, Method 2 is a smidgen faster, by about half a second over
 500,000 open-write-close cycles. It's not much faster, but it's
 consistent, over many tests, changing many of the parameters (e.g. the
 number of files, the number of runs per timeit test, etc.).
 
 I'm using Linux and Python 2.5.
 
 So, what's going on? Can anyone explain why the code which does more
 work takes less time?
 
 Can't confirm this (Linux, Python 2.5):
 
 Method 1: 15.380897998809814
 Method 2: 18.085366010665894

Hmmm... does your system use software RAID? Mine does. I wonder if that's 
a relevant factor?

 I guess it's really all about the disk IO as my system monitor applet
 shows that almost all of the time is spend in the kernel and very little
 in user space.

I wouldn't be surprised if it was something to do with the OS caching 
writes to disk. And saying that is really just me doing a lot of hand-
waving and saying it's magic of what we know naught.



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


Spawn new process - get pid

2008-02-04 Thread breal
I have a soap server written in Python that acts as an intermediary
between a web service and an InDesign server.  The indesign server is
non-threaded, so when all instances are used up I want to create a new
instance, get the pid, use the process, then kill it.

What is the best way to do this?  I don't want to replace the current
process with the new one which is looks like os.exec* does.

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


Re: Mysterious xml.sax Encoding Exception

2008-02-04 Thread John Machin
On Feb 5, 9:02 am, JKPeck [EMAIL PROTECTED] wrote:
 On Feb 2, 12:56 am, Jeroen Ruigrok van der Werven [EMAIL PROTECTED]

 nomine.org wrote:
  -On [20080201 19:06], JKPeck ([EMAIL PROTECTED]) wrote:

  In both of these cases, there are only plain, 7-bit ascii characters
  in the xml, and it really is valid utf-16 as far as I can tell.

  Did you mean to say that the only characters they used in the UTF-16 encoded
  file are characters from the Basic Latin Unicode block?


 It appears that the root cause of this problem is indeed passing a
 Unicode XML string to xml.sax.parseString with an encoding declaration
 in the XML of utf-16.  This works with the standard distribution on
 Windows.

It did NOT work for me with the standard 2.5.1 Windows distribution --
see the code + output that I posted.

  It does not work with ActiveState on Windows even though
 both distributions report
 64K for sys.maxunicode.

 So I don't know why the results are different, but the problem is
 solved by encoding the Unicode string into utf-16 before passing it to
 the parser.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Client side GUI-like web framework ?

2008-02-04 Thread USCode
Michael L Torrie wrote:
 
 But it is served up in the firefox web browser.  A good example is:
 
 http://www.faser.net/mab/chrome/content/mab.xul
 
That's pretty slick, but unfortunately then you're locked into only the 
Firefox web browser, which many folks don't use.  You're trading OS 
lock-in for browser lock-in.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Client side GUI-like web framework ?

2008-02-04 Thread Eric
On Feb 4, 9:45 am, USCode [EMAIL PROTECTED] wrote:
 Wouldn't it be handy if there was a web framework that allowed you to
 create pages and control the interface like you would using a
 client-side GUI framework such as Tkinter?

 The framework would need a small, fast web server that would
 automatically fire up when you ran your application and you then control
 the interface just like you would with client-side GUI widgets (within
 the limitations of browsers of course).  It would handle all the
 complexities of HTTP, HTML, Javascript, etc. letting you focus on adding
 functionality to your application.

 Essentially you would be using the browser as your cross-platform
 client-side interface.  You would just interact with all the widgets
 like trees, grids, paned windows, checkboxes, buttons, etc.

 There wouldn't happen to be anything like that available, would there?
 I've seen CherryPy but that doesn't quite seem to be what I described.

 Thanks!

The most all-encompassing Python web framework I know of is
Turbogears. It handles Javascript, your database, and everything in
between; CherryPy is its built-in server. The setup script for it is
kind of horrifying, on account of the huge number of separate packages
it grabs from around the Internet, but it's still a popular framework.
I think that's one thing you could use for an easy-peasy, highly
interactive web application.

There is actually no shortage of existing Python web frameworks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Make Money

2008-02-04 Thread GorskiKamil . 1993
Hello, do you want make money? Its easy :)) Just register on
alertpay.com.Register on http://bux.to/?r=kimozek ( pls dont delete
kimozek ) . While you do it, just click on links and get money!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Client side GUI-like web framework ?

2008-02-04 Thread Michael L Torrie
USCode wrote:
 Michael L Torrie wrote:
 But it is served up in the firefox web browser.  A good example is:

 http://www.faser.net/mab/chrome/content/mab.xul

 That's pretty slick, but unfortunately then you're locked into only the 
 Firefox web browser, which many folks don't use.  You're trading OS 
 lock-in for browser lock-in.

Which is a heck of lot better than OS lock in.  Of course you can use
xul-runner or something.  Gecko and XUL are both open source, so I'm not
quite sure what this lock in really is, though.


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


future multi-threading for-loops

2008-02-04 Thread castironpi
Some iterables and control loops can be multithreaded.  Worries that
it takes a syntax change.

for X in A:
def f( x ):
normal suite( x )
start_new_thread( target= f, args= ( X, ) )

Perhaps a control-flow wrapper, or method on iterable.

@parallel
for X in A:
normal suite( X )

for X in parallel( A ):
normal suite( X )

Discussion presued about multi-core systems.  Allow user certain
control over what runs on multi-core.  Clearly, not generally
applicable.  -- But, from __future__ import does change syntax.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Client side GUI-like web framework ?

2008-02-04 Thread USCode
Michael L Torrie wrote:
 Which is a heck of lot better than OS lock in.  Of course you can use
 xul-runner or something.  Gecko and XUL are both open source, so I'm not
 quite sure what this lock in really is, though.
 
Lock-in in the sense that your application would only run in the Firefox 
browser, not IE, Safari, Opera, etc...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very weird behavior in MySQLdb execute

2008-02-04 Thread Steve Holden
John Nagle wrote:
 Carsten Haese wrote:
 On Mon, 2008-02-04 at 11:30 -0800, John Nagle wrote:
 Restarting the MySQL instance changes the database.  The entry google.com
 disappears, and is replaced by www.google.com.  This must indicate a 
 hanging
 transaction that wasn't committed.

 But that transaction didn't come from the Python IDLE session I've been
 making test calls from.  Those queries should match the graphical client
 exactly.

 So why don't they agree?
 I don't have a definitive answer, but I do have a piece of generic
 advice. If two database sessions receive differing results, the cause
 could be any of the following factors:

 1) One session is in a transaction, but the other is not.

 2) Both sessions are in a transaction, but they are at different
 isolation levels.

 3) Both sessions are in a transaction, but the transactions were started
 at different times.
 
  I see what's wrong, I think.  I haven't been doing a commit after
 a SELECT.  I've been careful to commit after write-type actions,
 but not after read-only actions.  I'm using InnoDB in default mode,
 which is REPEATABLE READ, and I've recently switched to long-running
 processes which keep the database connection open for hours.  So the
 data view for a given connection never changes, regardless of what's
 happening in other threads.
 


I believe you are correct in your belief that a commit() is never 
required after SELECT. Once a database change is committed it should 
become visible to all other connections (under normal circumstances).

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Binary file Pt 1 - Only reading some

2008-02-04 Thread Mastastealth
I'm trying to create a program to read a certain binary format. I have
the format's spec which goes something like:

First 6 bytes: String
Next 4 bytes: 3 digit number and a blank byte
---
Next byte: Height (Number up to 255)
Next byte: Width (Number up to 255)
Next byte: Number 0 - 5
Every 2 bytes after that: Supposedly a number  - 0899?

Anyway, I'm able to do the first 2 objects fine:

a = info.read(6)
b = info.read(4)

Printing both gives me what I mentioned above, a string and a 3 digit
number with a space. However, as I continue, things get trickier.

c = info.read(1)
d = info.read(1)

Printing c and d in this case gives me a block in the SPE output, or
if I run in a DOS prompt, 2 funny symbols. How do I get an integer out
of this? I'll probably need help once I get to the every 2 byte
section, but that'll be a separate post.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Client side GUI-like web framework ?

2008-02-04 Thread jay graves
On Feb 4, 11:45 am, USCode [EMAIL PROTECTED] wrote:
 Wouldn't it be handy if there was a web framework that allowed you to
 create pages and control the interface like you would using a
 client-side GUI framework such as Tkinter?

What about GWT?
http://code.google.com/webtoolkit/

Or its python counterpart, pyjamas?
http://code.google.com/p/pyjamas/

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


Re: (websearch) script ?

2008-02-04 Thread Bernard
On 4 fév, 17:17, Stef Mientki [EMAIL PROTECTED] wrote:
 hello,

 Being very satisfied with Python as a general program language,
 and having troubles with a number of PHP scripts, moving to another
 provider,
 I wanted to replace the PHP scripts with Python Scripts.

 The most important one is a PHP script that searches text in all
 documents on my website.
 Does someone has such a script ?

Text File Searcher : 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/511431

you'll need to adapt it a bit but you'll get the main idea on how to
do it for your situation


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


Re: Elementary string-parsing

2008-02-04 Thread Odysseus
In article [EMAIL PROTECTED],
 Dennis Lee Bieber [EMAIL PROTECTED] wrote:

 On Mon, 04 Feb 2008 09:43:04 GMT, Odysseus
 [EMAIL PROTECTED] declaimed the following in
 comp.lang.python:
 
  
  Thanks, that will be very useful. I was casting about for a replacement 
  for PostScript's for loop, and the while loop (which PS lacks -- and 
  which I've never missed there) was all I could come up with.
 
   Have you read the language reference manual yet? It is a rather
 short document given that the language syntactic elements are not that
 complex -- but would have exposed you to the for statement (along with
 return and passing arguments).

Sorry, translation problem: I am acquainted with Python's for -- if 
far from fluent with it, so to speak -- but the PS operator that's most 
similar (traversing a compound object, element by element, without any 
explicit indexing or counting) is called forall. PS's for loop is 
similar to BASIC's (and ISTR Fortran's):

start_value increment end_value {procedure} for

I don't know the proper generic term -- indexed loop? -- but at any 
rate it provides a counter, unlike Python's command of the same name.

 If your only other programming experience is base PostScript you 
 wouldn't really be familiar with passing arguments or returning 
 values -- as an RPN stack-based language, argument passing is just 
 listing the arguments before a function call (putting a copy of them 
 on the stack), and returns are whatever the function left on the 
 stack at the end; hence they appear sort of global.

Working directly in the operand stack is efficient, but can make 
interpretation by humans -- and debugging -- very difficult. So for the 
sake of coder-friendliness it's generally advisable to use variables 
(i.e. assign values to keys in a dictionary) in most cases instead of 
passing values 'silently' via the stack. I'm beginning to realize that 
for Python the situation is just about the opposite ...

Anyway, I have been reading the documentation on the website, but much 
of the terminology is unfamiliar to me. When looking things up I seem to 
get an inordinate number of 404 errors from links returned by the search 
function, and often the language-reference or tutorial entries (if any) 
are buried several pages down. In general I'm finding the docs rather 
frustrating to navigate.

   After the language reference manual, the library reference manual
 chapter on built-ins and data types would be next for study -- the rest
 can usually be handled via search functions (working with time
 conversions, look for modules with date or time G).

As I mentioned elsethread, I did look at the time documentation; it 
was there that I found a reference to the calendar.timegm function I 
used in my first attempt.

   It looked a bit like you were using a SAX-style parser to collect
 names and cells -- and then passing the bunch to another function
 to trim out and convert data... It would take me a bit to restudy the
 SAX parsing scheme (I did it once, back in the days of v1.5 or so) but
 the way I'd /try/ to do it is to have the stream handler keep track of
 which cell (td tag) is currently being parsed, and convert the string
 data at that level. You'd initialize the record dictionary to {} (and
 cell position to 0) on the tr tag, and return the populated record on
 the /tr tag.

This is what my setup looks like -- mostly cribbed from _Dive Into 
Python_ -- where PageParser is a class based on SGMLParser:

from sgmllib import SGMLParser
from urllib import urlopen

# ...

def parse_page(url):
usock = urlopen(url)
parser = PageParser()
parser.feed(usock.read())
parser.close()
usock.close()
return parser

# ...

captured = parse_page(base_url + suffix)

I only use parse_page the once at this stage, but my plan was to call 
it repeatedly while varying suffix (depending on the data found by the 
previous pass). On each pass the class will initialize itself, which is 
why I was collecting the data into a 'standing' (global) dictionary. Are 
you suggesting essentially that I'd do better to make the text-parsing 
function into a method of PageParser? Can one add, to such a derived 
class, methods that don't have protoypes in the parent?

   Might want to check into making a class/instance of the parser so
 you can make the record dictionary and column (cell) position instance
 attributes (avoiding globals).

AFAICT my captured is an instance of PageParser, but I'm unclear on 
how I would add attributes to it -- and as things stand it will get 
rebuilt from scratch each time a page is read in.

  [...] I'm somewhat intimidated by the whole concept of 
  exception-handling (among others). How do you know to expect a 
  ValueError if the string isn't a representation of a number?
 
   Read the library reference for the function in question? Though it
 appears the reference doesn't list the error raised for an invalid
 string representation -- in which case 

Re: Binary file Pt 1 - Only reading some

2008-02-04 Thread Jared Grubb
You should look into the struct module. For example, you could do the same
thing via (using the variable names you used before):
header_str = info.read(13)
a,b,c,d,e = struct.unpack(6s4sBBB, header_str)

After that, you will probably be able to get the integers by (doing it one
at a time... read'ing more than 2 bytes at a time and processing it all at
once is going to be more efficient, but this is the basic idea):

read_str = info.read(2)
val = struct.unpack(H, read_str)

Read up on the struct module and I think you'll see what you need to do.
(note that if you arent getting the right numbers for val, you will need to
specify whether the data is big-endian or little-endian if you dont know
what that means, you will find it on Wikipedia)

Jared


On 4 Feb 2008, at 19:51, Mastastealth wrote:

I'm trying to create a program to read a certain binary format. I have
the format's spec which goes something like:

First 6 bytes: String
Next 4 bytes: 3 digit number and a blank byte
---
Next byte: Height (Number up to 255)
Next byte: Width (Number up to 255)
Next byte: Number 0 - 5
Every 2 bytes after that: Supposedly a number  - 0899?

Anyway, I'm able to do the first 2 objects fine:

a = info.read(6)
b = info.read(4)

Printing both gives me what I mentioned above, a string and a 3 digit
number with a space. However, as I continue, things get trickier.

c = info.read(1)
d = info.read(1)

Printing c and d in this case gives me a block in the SPE output, or
if I run in a DOS prompt, 2 funny symbols. How do I get an integer out
of this? I'll probably need help once I get to the every 2 byte
section, but that'll be a separate post.
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Client side GUI-like web framework ?

2008-02-04 Thread USCode
jay graves wrote:
 On Feb 4, 11:45 am, USCode [EMAIL PROTECTED] wrote:
 Wouldn't it be handy if there was a web framework that allowed you to
 create pages and control the interface like you would using a
 client-side GUI framework such as Tkinter?
 
 What about GWT?
 http://code.google.com/webtoolkit/
 
 Or its python counterpart, pyjamas?
 http://code.google.com/p/pyjamas/
 
 ...
 jay graves
Thanks Jay and I guess in my original post I didn't explicitly specify 
Python but that is what I was after.
After poking around a bit pyjamas looks like it might be exactly what I 
was after except the main pyjamas website http://pyjamas.pyworks.org 
appears to be down ... is it still an active project?
Anyone have any experience with pyjamas?
Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spawn new process - get pid

2008-02-04 Thread Gabriel Genellina
On 4 feb, 22:21, breal [EMAIL PROTECTED] wrote:
 On Feb 4, 3:34 pm, Gabriel Genellina [EMAIL PROTECTED] wrote:

  En Mon, 04 Feb 2008 20:59:16 -0200, breal [EMAIL PROTECTED]
  escribió:

   I have a soap server written in Python that acts as an intermediary
   between a web service and an InDesign server.  The indesign server is
   non-threaded, so when all instances are used up I want to create a new
   instance, get the pid, use the process, then kill it.

  Use the subprocess module:http://docs.python.org/lib/module-subprocess.html

 Thanks for the reply.  Using subprocess.Popen I am able to get and
 kill the process.  However, the process I am running creates another
 process (an instance of InDesign Server) so when I kill the first
 process it doesn't kill the second.  Is there any way to capture both
 PIDs and kill them?

I assume you're on *nix. Can you modify the first process? Make it a
project group leader, then kill the whole group. I don't remember the
details, try `man setpgrp` (or setpg?)

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


Re: future multi-threading for-loops

2008-02-04 Thread castironpi
On Feb 4, 9:22 pm, [EMAIL PROTECTED] wrote:
 Some iterables and control loops can be multithreaded.  Worries that
 it takes a syntax change.

 for X in A:
     def f( x ):
         normal suite( x )
     start_new_thread( target= f, args= ( X, ) )

 Perhaps a control-flow wrapper, or method on iterable.

 @parallel
 for X in A:
     normal suite( X )

 for X in parallel( A ):
     normal suite( X )

 Discussion presued about multi-core systems.  Allow user certain
 control over what runs on multi-core.  Clearly, not generally
 applicable.  -- But, from __future__ import does change syntax.

Some timing stats: On Windows XP, Python 3.0a2.

[timing code, 10,000 calls]
[ f( X ) ]: 0.0210021106034
[ start_new_thread( f, X ) ]: 1.15759908033
[ Thread( f, X ).start() ]: 1.85400099733
[ Thread( f, X ).start and .join() ]: 1.93716743329

Are threads an OS bottleneck?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Elementary string-parsing

2008-02-04 Thread Odysseus
In article [EMAIL PROTECTED],
 Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:

snip

 The term global usually means module global in Python.

Because they're like the objects obtained from import?

 [T]he functions depend on some magic data coming from nowhere and 
 it's much harder to follow the data flow in a program.  If you work 
 with globals you can't be sure what the following will print:
 
 def spam():
 global x
 x = 42
 beep()
 print x
 
 `beep()` might change `x` or any function called by `beep()` and so on. 

I think I get the general point, but couldn't beep() get at x even 
without the global statement, since they're both in spam()?

It seems natural to me to give the most important objects in a program 
persistent names: I guess this something of a 'security blanket' I need 
to wean myself from. I can appreciate the benefits of 
context-independence when it comes to reusing code.

 Another issue is testing.  If you rely on global names it's harder to test
 individual functions. [...]
 
 In programs without such global names you see quite clearly in the
 ``def`` line what the function expects as input.

Good points, although thorough commenting can go a long way to help on 
both counts. In theory, at least ...

snip

 It's easy to enforce if you have minimal code on the module level.  The
 usual idiom is:
 
 def main():
 # Main program comes here.
 
 if __name__ == '__main__':
 main()
 
 Then main is called when the script is called as program, but not called if
 you just import the script as module.  For example to test functions or to
 reuse the code from other scripts.

I'm using if __name__ == 'main' now, but only for test inputs (which 
will eventually be read from a config file or passed by the calling 
script -- or something). I hadn't thought of putting code that actually 
does something there. As for writing modules, that's way beyond where I 
want to go at this point: I don't know any C and am not sure I would 
want to ...
 
[consolidating]

In article [EMAIL PROTECTED],
 Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:

snip

 Then you can either pass in `found` as argument instead of creating it
 here, or you collect the passes in the calling code with the `update()`
 method of `dict`.  Something like this:
 
 found = dict()
 for pass in passes:
 # ...
 found.update(extract_data(names, na, cells))

Cool. I'll have to read more about dictionary methods.

snip

  assert name.startswith('Name: ')

 It checks if `name` really starts with 'Name: '.  This way I turned the
 comment into code that checks the assertion in the comment.

Good idea to check, although this is actually only one of many 
assumptions I make about the data -- but what happens if the assertion 
fails? The program stops and the interpreter reports an AssertionError 
on line whatever?

snip

 [I]f you can make the source simpler and easier to understand by 
 using the `index()` method, use a list.  :-)

Understood; thanks for all the tips.

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


  1   2   >