UK Python Conference - 19-20 April 2006

2006-02-28 Thread Andy Robinson

The ACCU is once again hosting a UK Python Conference on the above dates 
at the Randolph Hotel in Oxford.  Sign up now.

   http://www.accu.org/index.php/conferences/2006/schedule

PROGRAMME
=
I am happy to announce that Guido van Rossum is once again a keynote 
speaker for the entire ACCU conference.   Following his keynote we have 
a single, 2-day Python track on Wednesday and Thursday including...

Steve Holden: The Best of PyCon
Michael Hudson: Error Handling with Recovery
Phil Thompson: PyQT 4
Michael Hudson: PyPy - a progress report
Simon Willison: Django
Remi Delon:  CherryPy and TurboGears
Chris Withers: Templating systems
Andy Robinson: Metadata and models in Python
Andrew Thompson: Financial Programming in Python

...and of course lightning talks and BOFS will be welcome


Friday 21st will feature a Dynamic Languages track with in-depth talks 
on Javascript, Ruby and Groovy, which I am sure will be of great 
interest to Python developers; and of course the dinner.

PRE CONFERENCE PYTHON TUTORIAL:
===
John Pinner will be giving a full day Python for Programmers tutorial 
on Tuesday prior to the main event.  This tutorial is aimed at 
programmers who have no previous knowledge of Python but who would like 
to know more about it. If you want to convert your colleagues, this is 
where to send them


ABOUT THE ACCU CONFERENCE
=
For those not familiar with the event, the ACCU conference is one of the 
foremost gatherings of programming talent in the world, regularly 
featuring authors and major figures from the C/C++/C#/Java/Python and 
other communities.The cheapest way to attend is to join the ACCU

This will be the LAST CHANCE to attend this fantastic event; after more 
than 5 years of being nurtured by the ACCU, the UK Python community will 
hopefully be organising a standalone conference in future years.  Python 
talks will continue to be welcome (and we hope numerous) on the ACCU 
programme, but not as an advertised mini-conference; instead we'll be 
shifting focus to dynamic languages in general.



Best Regards,


Andy Robinson
ACCU Conference Committee






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

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


Re: different ways to strip strings

2006-02-28 Thread Steven D'Aprano
On Mon, 27 Feb 2006 13:28:44 -0500, rtilley wrote:

 s = ' qazwsx '
 
 # How are these different?
 print s.strip()
 print str.strip(s)

s.strip() strips white space from the start and end of string s. That is
standard object-oriented behaviour: you have an instance, s, and you call
its method, strip.

str.strip(s) is a little more tricky, but not much. str is the built-in
type for strings. Due to historical reasons, Python types and
user-definable classes are slightly different, but at the level we're
discussing here, you can imagine there is no difference.

In effect, you can think of str.strip(s) as calling the strip method
of the class (technically type) str, with s as the first argument. That is
equivalent to calling the strip method of the instance s with no arguments.


 Do string objects all have the attribute strip()? 

Yes, via inheritance. That is, each string object doesn't have a copy of
each method (strip, split, join, etc.) as that would be wasteful. The
same goes for all objects in Python, including ints, floats, lists,
as well as custom classes.

Python's inheritance rules mean that:

object_instance.method()

and 

object_type.method(object_instance) 

are equivalent.



 If so, why is str.strip() needed? 

Because that is the machinery by which string objects get the attribute
strip.


 Really, I'm just curious... there's a lot  don't fully understand :)

Gazing into my crystal ball, I'm going to answer your next question before
you answer it. Use the form s.strip() in preference to str.strip(s). It is
easier to read, faster, and generates smaller code.


-- 
Steven.

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


Re: expat

2006-02-28 Thread Katja Suess
Merci à Frederik et Jarek!
According to your hints I did tests with a different coding and another option 
in OpenOffice 'Size optimization for XML format'.
Went fine! - Back to my files from yesterday the same proper converting... uups
Anyway, it's running!
Katja
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flash

2006-02-28 Thread Sybren Stuvel
SamFeltus enlightened us with:
 PS.  Here is an example...

 http://sonomasunshine.com/sonomasunshine/FrontPage.html

The HTML version of that site is crap, by the way. Check out 
http://sonomasunshine.com/cgi-bin/old_school.py?pagename=FrontPage

The HTML is sent as text/plain, and if interpreted as HTML, it's not
compliant with any HTML standard.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


HTML/DOM parser

2006-02-28 Thread Xah Lee
is there a module that lets me parse validated html files and store it
as a tree?

for example, i want to be able to easily, say, replace the following

hrpReferences/p
pre
• a href=aa.../a
...
/pre

to

hrpReferences/p
ul
lia href=aa.../a/li
...
/ul

Thanks.

   Xah
   [EMAIL PROTECTED]
 ∑ http://xahlee.org/

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

Re: HTML/DOM parser

2006-02-28 Thread Sybren Stuvel
Xah Lee enlightened us with:
 is there a module that lets me parse validated html files and store
 it as a tree?

http://docs.python.org/lib/module-xml.dom.html

Assuming you're using XHTML.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scientific Computing with NumPy

2006-02-28 Thread Travis E. Oliphant
[EMAIL PROTECTED] wrote:
 Terry Reedy wrote:
 
kpp9c [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

Numeric, Numarray,  Numpy... some one stick a screwdriver in my
forehead and end the madness that Numeric has become.

For crying all night! Numpy was Numeric's nickname

Given that NumPy *is* an updated version of Numeric, with the same basic
interface, I think the name quite appropriate.  It also works well as a
partner for SciPy.

Exactly!

I suppose people must vent, but the truth is that satisfying the 
diversity of scientific Python users is *very* hard.

NumPy *is* trying to do something about the confusion between Numeric 
and Numarray.   I'm sorry you don't like the name, but it was properly 
discussed and a host of other names were suggested before settling on 
NumPy as the *least bad*.

Yes, it will be confusing for a few months, but then it will probably be 
*less* confusing as people realize that NumPy *is* Numeric 3K

The interface is not that different.  For example, you can usually 
compile extensions simply by replacing Numeric/arrayobject.h   with
numpy/arrayobject.h

If you don't like things then start suggesting specific improvements at 
[EMAIL PROTECTED] instead of just ranting on the 
python list which most of us don't have the time to read anyway (notice 
how late I'm responding to this...)

-Travis


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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread Magnus Lycka
Tim Chase wrote:
 ...throw UnthrowableKoan
 ...
 
 (okay...maybe it's a little too early on a weekdays.mon morning)

Probably, since a SyntaxError slipped in. Throw is C++ Tim.
It's raise UnRaisableKoan.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython: help(wx) causes segfaulting?

2006-02-28 Thread Magnus Lycka
Franz Steinhaeusler wrote:
 maybe you have 2.4.2 and I 2.4.

This looks like a wxPython problem, not a Python problem.
It might well be a version issue for you guys, but it's
more likely that a certain wxPython version is the culprit,
not a certain Python version.

Note however that the OP is using Linux, where the wxWidgets
uses completely different libraries, and that's where the
problem occurs. Besides, it's not a Python exception in the
Debian testing case, it's a segmentation fault in the
underlying GLib code that causes Python to crash.

BTW, Is the current Debian testing really equipped with
Python 2.3.5? It's a very sorry state of affairs if the
testing version of a major Linux release isn't using
Python 2.4, which was released in November 2004.

I can understand why people a leaving stock Debian for
Ubuntu...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Indentation Problems

2006-02-28 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
 I am a newbie to Python. I am mainly using Eric as the IDE for coding.
 Also, using VIM and gedit sometimes.
 
 I had this wierd problem of indentation. My code was 100% right but it
 wont run because indentation was not right. 

If indentation is not right, then your code is not 100% right !-)

 I checked time and again
 but still no success. I rewrote the code over again in VI and it ran.
 
 Can you please explain whats the trick behind the correct indentation.

1/ use spaces not tabs. Hint : all decent code editors I know have a way
to configure this - just make sure all the editors you use have the
correct settings.
2/ preferably, stick to 4 spaces indent
3/ if you run into troubles, check the code with tabnanny:
http://effbot.org/librarybook/tabnanny.htm


 Thanks
 


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


Re: newbie trying understand sys.path

2006-02-28 Thread Fredrik Lundh
MARK LEEDS wrote:

 So, as it said in Beginning Python, I went into my .bashrc file and did

 export PYTHONPATH=$PYTHONPATH:~/mytemp

 then, i typed pprint.pprint(sys.path) and it worked.
 it was in there 

 but, now I want to take it out.

 i deleted the command from the .bashrc file and resourced it but it was still 
 in there.

removing the PYTHONPATH variable from the bashrc script won't
remove the current value from the current environment.

 So, then I tried ( inside a python program )

 sys.path = sys.path[1:]

 and it works inside the program so that sys.path changed while the program
 was running.
  but, then i checked it again, by taking out the above command
 and typing pprint.pprint(sys.path) and it was still there ?

 Basically, my question is : Is there a permanent way of taking things out of
 sys.path that you put in sort of by accident or for experimentation ?

you can log out and log in again.

or you can use export to set PYTHONPATH to whatever value you
want it to have.

or you can use unset PYTHONPATH to remove it from the environment:

$ echo $PYTHONPATH

$ export PYTHONPATH=spam
$ echo $PYTHONPATH
spam
$ python -c import sys; print sys.path[:2]
['', '/home/fredrik/spam']
$ unset PYTHONPATH
$ echo $PYTHONPATH

$ python -c import sys; print sys.path[:2]
['', '/usr/local/lib/python2.5']

/F



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


C++ OpenGL rendering, wxPython GUI?

2006-02-28 Thread tobfon
I'm creating a scientific visualization application with rather high
demands on performance. I've created a nice rendering engine for it in
C++/OpenGL and a python interface to the rendering engine. Now I'm
looking to build a GUI in python with the rendering engine as an
integrated window. I will most likely use wxPython for the GUI and I
know it has support for adding an OpenGL canvas.

After looking around in these groups and others it seems to me that
most people doing 3D-applications simply opt to use PyOpenGL. Since my
application uses VBOs, shader programs and similar things this is not
an option for me.

My rendering engine currently uses GLUT for window handling, but what I
want to do is to create the canvas in python for use with wxPython and
then somehow toss it down to C++ for rendering and avoid using GLUT at
all. I've yet to come across an example of how this could be done.

Maybe including wxWidgets in the C++ program and just using the
wxPython-created canvas ID there will somehow be possible? I'll look
into that but any help or ideas are most welcome.

Tobias Forslöw

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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread Stefan Rank
on 28.02.2006 07:50 Carl Banks said the following:
 Ben Finney wrote:
 This PEP specifies an enumeration data type for Python.
 
[snip]
 
 Here's why I think it's not too useful to begin with: the benefits of
 the enum you describe here are pretty weak.

I need to disagree heavily here :)

+1 from me for the general idea of a builtin enum.

(and for 'real world' use cases: I use this type of enum, the PEP one, 
in my code regularly)

 It's a pretty weak case to have a dedicated builtin to prevent
 duplicates in something that changes maybe once a month, as enums tend
 to change rather slowly.  (At least, that's the way enums in other
 languages are used, and the design you present here seems to suggest
 you intend to use them that way as well.)  And frankly, a unit test or
 assertion could check this.
[snip]

I don't understand what you mean by 'change rather slowly'?
The dominant use case for an explicit enum is to make it clear for the 
code user that the values are a separate type, and prevent errors 
occurring because the abused underlying type shows through (be it 
strings or integers) or at least give informative warnings for them. If 
you want more than that something, like a dict, will probably be better.

recent examples from this list:

2006-01-03: http://www.nabble.com/Re%3A-Regex-anomaly-p2179421.html
2006-02-20: 
http://www.nabble.com/Re%3A-Regular-expression-gone-mad-p3029028.html

 The nonsensical comparisions should throw value errors.

That's a valid point.

I hope someone knowledgeable will go through the standard library and 
check each flag-like thing (which is not directly dependent on an 
underlying c-library idiom) against the proposed enum type.

One thing that is probably missing to allow this, is a enum-set-creation 
with the | operator::

   Weekdays = enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
   daysihate = Weekdays.mon | Weekdays.thu

(and this discussion needs to move to python-dev ?)

As for the metaclass versions: For myself, the above version feels more 
natural and straightforward (in the same way as the PEP author describes 
it), though I understand the subclassing ideas.

But are there use cases for subclassing, that aren't better served with 
a new enum or something homegrown?
Can C++/Pascal/Java enums be subclassed?

cheers,
stefan

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


Fetching the Return results of a spawned Thread

2006-02-28 Thread Alvin A. Delagon
Is there any way to fetch the Return results of spawned threads within 
the parent script? I would like to do that because I'm having problems 
with Threads that do queries to a database, I often encounter Threads 
failing due to MySQL connection failures. As much as possible I plan to 
make the threads return the query string and let the parent script do 
the actual query. Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fetching the Return results of a spawned Thread

2006-02-28 Thread Fredrik Lundh
Alvin A. Delagon wrote:

 Is there any way to fetch the Return results of spawned threads within
 the parent script? I would like to do that because I'm having problems
 with Threads that do queries to a database, I often encounter Threads
 failing due to MySQL connection failures. As much as possible I plan to
 make the threads return the query string and let the parent script do
 the actual query. Thanks in advance.

use a shared Queue object, let the worker threads write their result to this
queue, and let the parent thread poll the queue:

http://docs.python.org/lib/module-Queue.html

/F



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


Re: sort one list using the values from another list

2006-02-28 Thread bearophileHUGS
_ is just a plain variable name in Python. It is sometimes when a variable is 
needed to receive a value that won't be used.

Like in some other interactive systems (Mathematica, etc, but with a
different syntax) _ has a use in the interactive shell, it contains the
last unassigned result:

 a = 2 * 5
 _
Traceback (most recent call last):
  File interactive input, line 1, in ?
NameError: name '_' is not defined
 2 * 5
10
 _
10

Bye,
bearophile

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


Re: bsddb3 database file, are there any unexpected file size limits occuring in practice?

2006-02-28 Thread Claudio Grondi
Klaas wrote:
 Claudio writes:
 
I am on a Windows using the NTFS file system, so I don't expect problems
with too large file size.
 
 
 how large can files grow on NTFS?  I know little about it.
No practical limit on current harddrives. i.e.:
Maximum file size
   Theory:  16 exabytes  minus  1 KB (2**64 bytes minus  1 KB)
   Implementation:  16 terabytes minus 64 KB (2**44 bytes minus 64 KB)
Maximum volume size
   Theory:2**64 clusters minus 1
   Implementation: 256 terabytes minus 64 KB (2**32 clusters minus 1)
Files per volume
   4,294,967,295 (2**32 minus 1 file)
 
 
(I suppose it in having only 256 MB RAM available that time) as it is
known that MySQL databases larger than 2 GByte exist and are in daily
use :-( .
 
 
 Do you have more ram now?  
I have now 3 GByte RAM on my best machine, but Windows allows a process 
not to exceed 2 GByte, so in practice a little bit less than 2 GByte are 
the actual upper limit.

I've used berkeley dbs up to around 5 gigs
 in size and they performed fine.  However, it is quite important that
 the working set of the database (it's internal index pages) can fit
 into available ram.  If they are swapping in and out, there will be
 problems.
Thank you very much for your reply.

In my current project I expect the data to have much less volume than 
the indexes. In my failed MySQL project the size of the indexes was 
appr. same as the size of the indexed data (1 GByte).
In my current project I expect the total size of the indexes to exceed 
by far the size of the data indexed, but because Berkeley does not 
support multiple indexed columns (i.e. only one key value column as 
index) if I access the database files one after another (not 
simultaneously) it should work without problems with RAM, right?

Do the data volume required to store the key values have impact on the 
size of the index pages or does the size of the index pages depend only 
on the number of records and kind of the index (btree, hash)?

In last case, I were free to use for the key values also larger sized 
data columns without running into the problems with RAM size for the 
index itself, else I were forced to use key columns storing a kind of 
hash to get their size down (and two dictionaries instead of one).

What is the upper limit of number of records in practice?

Theoretical, as given in the tutorial, Berkeley is capable of holding up 
to billions of records with sizes of up to 4 GB each single record with 
tables up to total storage size of 256 TB of data.
By the way: are billions in the given context multiple of 1.000.000.000 
or of 1.000.000.000.000 i.e. in US or British sense?

I expect the number of records in my project in the order of tens of 
millions (multiple of 10.000.000).

I would be glad to hear if someone has already successful run Berkeley 
with this or larger amount of records and how much RAM and which OS had 
the therefore used machine (I am on Windows XP with 3 GByte RAM).

Claudio

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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread Carl Banks
Stefan Rank wrote:
 on 28.02.2006 07:50 Carl Banks said the following:
  Ben Finney wrote:
  This PEP specifies an enumeration data type for Python.
 
 [snip]
 
  Here's why I think it's not too useful to begin with: the benefits of
  the enum you describe here are pretty weak.

 I need to disagree heavily here :)

the benefits of the enum you describe here [beyond my example which I
claimed enum was only a minor improvement over] are pretty weak.


  It's a pretty weak case to have a dedicated builtin to prevent
  duplicates in something that changes maybe once a month, as enums tend
  to change rather slowly.  (At least, that's the way enums in other
  languages are used, and the design you present here seems to suggest
  you intend to use them that way as well.)  And frankly, a unit test or
  assertion could check this.
 [snip]

 I don't understand what you mean by 'change rather slowly'?

Construct data structure on-the-fly from an XML file edited by multiple
people every day  = changes rather quickly

Construct data structure from a Python file that was last edited a year
and a half ago = changes rather slowly

Typically, enums fall into the latter category.  You set the enum
values, and then pretty much leave them alone, adding new values only
occasionally.  (Come on, how often do the days of the week change?)
All I was saying is, changes to the enum values are infrequent enough
that having a special type just to make sure there are no duplicates is
a waste.  The only justification for a built-in enum is the other stuff
you mentioned.


 One thing that is probably missing to allow this, is a enum-set-creation
 with the | operator::

Weekdays = enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
daysihate = Weekdays.mon | Weekdays.thu

 (and this discussion needs to move to python-dev ?)

What's wrong with set((Weekdays.mon,Weekdays.thu))?  Explicit is better
than implicit.


 As for the metaclass versions: For myself, the above version feels more
 natural and straightforward (in the same way as the PEP author describes
 it), though I understand the subclassing ideas.

 But are there use cases for subclassing, that aren't better served with
 a new enum or something homegrown?
 Can C++/Pascal/Java enums be subclassed?

In C++, enum is a type but not a class.  Same thing with Ada.  Java
didn't have enums last time I checked.  Don't know about Pascal.  I
didn't care too much about subclassing; I just thought different enum
constant that couldn't (or, rather, oughtn't) be compared probably
should be instances of a separate class.  It doesn't matter much,
though.

Should something like this work:

day = Weekdays.mon
isinstance(day,Weekdays)

?


Carl Banks

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


Printing a file

2006-02-28 Thread Fabian Steiner
Hello!

I am currently working on an application where the user is able to 
create new worksheets and to delete existing ones. All of these 
worksheets have the same structure (-- template?), only some values 
should be changed. A minimal example would be something like this:

Name: ...
Role: 
Address: 

The values are stored in a SQLite database. Now I would like to offer 
the possibility to print out a single record on a DinA4 paper. In order 
to do this, the dots (...) above of course have to be replaced by the 
current record's values and the different parts have to fit on one page.

Unfortunately I don't know how to realize this, since also some images 
and different boxes should be printed out. As the whole application is 
based on QT, QPrinter might be used, but I couldn't find any examples 
how to use it.

What do you suggest? Which format should the template have? (XML, etc.?)

Any hints appreciated!

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


Re: Printing a file

2006-02-28 Thread Jeremy Sanders
Fabian Steiner wrote:

 Unfortunately I don't know how to realize this, since also some images
 and different boxes should be printed out. As the whole application is
 based on QT, QPrinter might be used, but I couldn't find any examples
 how to use it.

QPrinter is easy to use. You just draw to the page the same way as you talk
to the screen with a QPainter.

prnt = qt.QPrinter()
# you can also vary options like colour, doc name, dpi here

# display dialog box to user (you can actually leave this out)
if prnt.setup():
 painter = qt.QPainter()
 painter.begin(printer)
 # do stuff to draw to painter
 painter.end(printer)
 # do this between each page
 printer.newPage()

 # ... more pages can be printed to a painter

It's very easy to do. If you want to handle multiple pages and so on,
there's a bit of work to do to interface to the dialog to get the
user-selected page range, etc.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++ OpenGL rendering, wxPython GUI?

2006-02-28 Thread Carl Banks
[EMAIL PROTECTED] wrote:
 I'm creating a scientific visualization application with rather high
 demands on performance. I've created a nice rendering engine for it in
 C++/OpenGL and a python interface to the rendering engine. Now I'm
 looking to build a GUI in python with the rendering engine as an
 integrated window. I will most likely use wxPython for the GUI and I
 know it has support for adding an OpenGL canvas.

 After looking around in these groups and others it seems to me that
 most people doing 3D-applications simply opt to use PyOpenGL. Since my
 application uses VBOs, shader programs and similar things this is not
 an option for me.

 My rendering engine currently uses GLUT for window handling, but what I
 want to do is to create the canvas in python for use with wxPython and
 then somehow toss it down to C++ for rendering and avoid using GLUT at
 all. I've yet to come across an example of how this could be done.

 Maybe including wxWidgets in the C++ program and just using the
 wxPython-created canvas ID there will somehow be possible? I'll look
 into that but any help or ideas are most welcome.

You should be able to create and realize the OpenGL canvas (which will
create an OpenGL context), then make the OpenGL calls from C++ without
any worries.  Realizing (i.e., creating the window for) the canvas
would create the OpenGL context, and somewhere along the way the
context gets bound (probably during the canvas's draw callback).

BTW, though you can't use PyOpenGL for the VBO stuff, it might be
useful to install it anyways to do high-level stuff (set up flags,
position the camera, etc.).  Calls from C and PyOpenGL can be freely
mixed.

I've done similar things in GTK on Linux.  I had a gtkglarea canvas,
PyOpenGL, and my own C extension all making OpenGL calls.



Carl Banks

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


Re: Printing a file

2006-02-28 Thread David Boddie
Jeremy Sanders wrote:
 Fabian Steiner wrote:

  Unfortunately I don't know how to realize this, since also some images
  and different boxes should be printed out. As the whole application is
  based on QT, QPrinter might be used, but I couldn't find any examples
  how to use it.

[...]

 It's very easy to do. If you want to handle multiple pages and so on,
 there's a bit of work to do to interface to the dialog to get the
 user-selected page range, etc.

That's where QPrintDialog comes in:

  http://doc.trolltech.com/4.1/qprintdialog.html

It's also secretly available in Qt 3 via the QPrinter.setup() method:

  printer = QPrinter()
  printer.setup()
  # Now, paint onto the printer as usual.

David

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


Re: Python advocacy in scientific computation

2006-02-28 Thread Cameron Laird
In article [EMAIL PROTECTED],
Georg Brandl  [EMAIL PROTECTED] wrote:
Michael Tobis wrote:
 Someone asked me to write a brief essay regarding the value-add
 proposition for Python in the Fortran community. Slightly modified to
 remove a few climatology-related specifics, here it is.

Great text. Do you want to put it onto a Wiki page at wiki.python.org?
.
.
.
URL: http://wiki.python.org/moin/PythonAdvocacyInScientificComputation 
-- 
http://mail.python.org/mailman/listinfo/python-list


Multicolumn in Tix scrolledListBox

2006-02-28 Thread anil . pundoor
hi
 iam using Tix ScrolledListBox widget. is there any option so that i
can disply the items in multiple colums
thanks 
Anil

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


Re: Fetching the Return results of a spawned Thread

2006-02-28 Thread Kent Johnson
Alvin A. Delagon wrote:
 Is there any way to fetch the Return results of spawned threads within 
 the parent script? 

There are several examples of this in the threading section of the 
Python Cookbook for example
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/84317
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/435883

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


Multicolumn in Tix scrolledListBox

2006-02-28 Thread anil . pundoor
hi
 iam using Tix ScrolledListBox widget. is there any option so that i
can disply the items in multiple colums
thanks 
Anil

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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread Cyril Bazin
What about that?

SomeNumbers = enum('0', '1', '2', '3', '4', '5', '6', '7')

or

Rooms = enum('1bed', '2beds', 'moreThan2beds')

or even

Comments = enum('#', ';', '//')


CyrilOn 28 Feb 2006 03:14:25 -0800, Carl Banks [EMAIL PROTECTED] wrote:
Stefan Rank wrote: on 28.02.2006 07:50 Carl Banks said the following:  Ben Finney wrote:  This PEP specifies an enumeration data type for Python.  [snip] 
  Here's why I think it's not too useful to begin with: the benefits of  the enum you describe here are pretty weak. I need to disagree heavily here :)the benefits of the enum you describe here [beyond my example which I
claimed enum was only a minor improvement over] are pretty weak.  It's a pretty weak case to have a dedicated builtin to prevent  duplicates in something that changes maybe once a month, as enums tend
  to change rather slowly.(At least, that's the way enums in other  languages are used, and the design you present here seems to suggest  you intend to use them that way as well.)And frankly, a unit test or
  assertion could check this. [snip] I don't understand what you mean by 'change rather slowly'?Construct data structure on-the-fly from an XML file edited by multiplepeople every day= changes rather quickly
Construct data structure from a Python file that was last edited a yearand a half ago = changes rather slowlyTypically, enums fall into the latter category.You set the enumvalues, and then pretty much leave them alone, adding new values only
occasionally.(Come on, how often do the days of the week change?)All I was saying is, changes to the enum values are infrequent enoughthat having a special type just to make sure there are no duplicates is
a waste.The only justification for a built-in enum is the other stuffyou mentioned. One thing that is probably missing to allow this, is a enum-set-creation with the | operator::Weekdays = enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
daysihate = Weekdays.mon | Weekdays.thu (and this discussion needs to move to python-dev ?)What's wrong with set((Weekdays.mon,Weekdays.thu))?Explicit is betterthan implicit.
 As for the metaclass versions: For myself, the above version feels more natural and straightforward (in the same way as the PEP author describes it), though I understand the subclassing ideas.
 But are there use cases for subclassing, that aren't better served with a new enum or something homegrown? Can C++/Pascal/Java enums be subclassed?In C++, enum is a type but not a class.Same thing with Ada.Java
didn't have enums last time I checked.Don't know about Pascal.Ididn't care too much about subclassing; I just thought different enumconstant that couldn't (or, rather, oughtn't) be compared probablyshould be instances of a separate class.It doesn't matter much,
though.Should something like this work:day = Weekdays.monisinstance(day,Weekdays)?Carl Banks--http://mail.python.org/mailman/listinfo/python-list

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

Vectorization and Numeric (Newbie)

2006-02-28 Thread Ronny Mandal
Assume you have a mathematical function, e.g. f(x) = x + 4

To calculate all the values from 1 to n, a loop is one alternative.

But to make this function work with vectors instead i.e
f(x_vector) = result_vector,
how should the function then be implemented?

Thanks

RM

--

Support bacteria - it's the only culture some people have!
-- 
http://mail.python.org/mailman/listinfo/python-list


compiled program input

2006-02-28 Thread mehmetmutigozel

i have a compiled program named m.exe. when i execute it asks me to
enter a parameter like me.dat. the coder didn't manage the argv for
this program and i only have the executable.

is there a vay to call this executeable from python and give parameters
to it?

m.exe
input1 ? me.dat


something like this

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


Re: Vectorization and Numeric (Newbie)

2006-02-28 Thread Cyril Bazin
Are you looking for the map function?

 def f(x): return x+4
 map(f, [1,2,3,3,70])
[5, 6, 7, 7, 74]

CyrilOn 2/28/06, Ronny Mandal [EMAIL PROTECTED] wrote:
Assume you have a mathematical function, e.g. f(x) = x + 4To calculate all the values from 1 to n, a loop is one alternative.But to make this function work with vectors instead i.ef(x_vector) = result_vector,
how should the function then be implemented?ThanksRM--Support bacteria - it's the only culture some people have!--http://mail.python.org/mailman/listinfo/python-list

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

Re: PyQT: QDialog and QMainWindow interacting with each other

2006-02-28 Thread Kai Teuber
Fabian Steiner schrieb:
 MyDialog is closed by calling MyDialog.accept(). What can I do so that 
 self.showListViewItems() is called after MyDialog has been closed?
 
 Thank you for any input!


Hi Fabian,

override the accept() method and call self.showListViewItems() there.
But remember to call QDialog.accept() at the end.

def accept( self ):
self.showListViewItems()
QDialog.accept( self )


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


Re: compiled program input

2006-02-28 Thread mehmetmutigozel

i found something like

import os

os.system(c\\m.exe)

but it gives

An endfile record was detected in a READ statement (unit=40).
 Error occurs at or near line 51 of _MAIN__
12

still don't have anything :(

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


Re: compiled program input

2006-02-28 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 i have a compiled program named m.exe. when i execute it asks me to
 enter a parameter like me.dat. the coder didn't manage the argv for
 this program and i only have the executable.

 is there a vay to call this executeable from python and give parameters
 to it?

m.exe
input1 ? me.dat


 something like this

does

echo me.dat | m.exe

work ?

/F 



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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread JW
It seems the concensus is that empty enums should be allowed for
consistancy, and to support the loop that doesn't.  I thought I'd find
some data points in other languages as a guide:

* C - builtin, empty enumerations not allowed
* C++ - builtin, empty enumerations allowed.  C++ doesn't have
iteration over a enumeration, except as a side-effect of direct
translation from elements to integerts (and then, only for a
sequentially assigned enumeration).  An enumeration is a type, so it
can be thrown (raised) as an exception -
http://oopweb.com/CPP/Documents/CPPAnnotations/Volume/cplusplus16.html#EMPTYENUM
* Java - builtin, empty enumerations allowed previously to 1.5, but
maybe not after -
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5081785
* OCaml - library, empty enumerations allowed as a consequence of being
able to add and remove enumeration elememts:
http://ocaml-lib.sourceforge.net/doc/Enum.html

I realize this is a strange and short list, but it's all I can do with
5 min of Google and a little testing.

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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread Stefan Rank
on 28.02.2006 12:14 Carl Banks said the following:
[snip]
 
 It's a pretty weak case to have a dedicated builtin to prevent
 duplicates in something that changes maybe once a month, as enums tend
 to change rather slowly.  (At least, that's the way enums in other
 languages are used, and the design you present here seems to suggest
 you intend to use them that way as well.)  And frankly, a unit test or
 assertion could check this.
 [snip]

 I don't understand what you mean by 'change rather slowly'?
 
 Construct data structure on-the-fly from an XML file edited by multiple
 people every day  = changes rather quickly
 
 Construct data structure from a Python file that was last edited a year
 and a half ago = changes rather slowly
 
 Typically, enums fall into the latter category.  You set the enum
 values, and then pretty much leave them alone, adding new values only
 occasionally.  (Come on, how often do the days of the week change?)
 All I was saying is, changes to the enum values are infrequent enough
 that having a special type just to make sure there are no duplicates is
 a waste.  The only justification for a built-in enum is the other stuff
 you mentioned.

agreed

 One thing that is probably missing to allow this, is a enum-set-creation
 with the | operator::

Weekdays = enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
daysihate = Weekdays.mon | Weekdays.thu

 (and this discussion needs to move to python-dev ?)
 
 What's wrong with set((Weekdays.mon,Weekdays.thu))?  Explicit is better
 than implicit.

agreed again.
the | idea would only be for (interface) backwards compatibility.

 As for the metaclass versions: For myself, the above version feels more
 natural and straightforward (in the same way as the PEP author describes
 it), though I understand the subclassing ideas.

 But are there use cases for subclassing, that aren't better served with
 a new enum or something homegrown?
 Can C++/Pascal/Java enums be subclassed?
 
 In C++, enum is a type but not a class.  Same thing with Ada.  Java
 didn't have enums last time I checked.  Don't know about Pascal.

Was more of a question for subclassing use cases in other languages.
BTW Java has an enum now, which cannot be subclassed either AFAIK. And 
it's the same for (Delphi) Pascal.

 I
 didn't care too much about subclassing; I just thought different enum
 constant that couldn't (or, rather, oughtn't) be compared probably
 should be instances of a separate class.  It doesn't matter much,
 though.
 Should something like this work:
 
 day = Weekdays.mon
 isinstance(day,Weekdays)
 
 ?

I think in the PyPI package `type(Weekdays)` is `Enum` and 
`type(Weekdays.mon)` is `EnumValue`, so this would not work.
But membership testing `if day in Weekdays: ...` could do the same, and 
type-checking for enum values `isinstance(day, EnumValue)` would work 
(might be unpythonic though).

In the cookbook recipe `enum('..')` is a function and constructs two new 
types on the fly, so the values of two different enums would be of a 
different type, but you would not be able to name it easily...

cheers

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


Re: Vectorization and Numeric (Newbie)

2006-02-28 Thread Juho Schultz
Ronny Mandal wrote:
 Assume you have a mathematical function, e.g. f(x) = x + 4
 
 To calculate all the values from 1 to n, a loop is one alternative.
 

Numeric and friends (numarray,numpy) have something like numarray.arange 
- they return arrays similar to the lists returned by standard libs 
range function. I would recommend using the built-in array operations as 
much as possible - in most cases they are much faster than looping, and 
your code remains simpler.

 But to make this function work with vectors instead i.e
 f(x_vector) = result_vector,
 how should the function then be implemented?
 

In most numeric libraries, vectors and scalars can be added etc.
For the simple f(x) case you can use just the simplest approach:

def f(x):
 return x+4

and call this with scalar and vector args.
f_pi = f(3.14159265)
f_1to200 = f(numarray.arange(1,200))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++ OpenGL rendering, wxPython GUI?

2006-02-28 Thread Michael Ekstrand
On 28 Feb 2006 01:14:15 -0800
[EMAIL PROTECTED] wrote:
 I'm creating a scientific visualization application with rather high
 demands on performance. I've created a nice rendering engine for it in
 C++/OpenGL and a python interface to the rendering engine. Now I'm
 looking to build a GUI in python with the rendering engine as an
 integrated window. I will most likely use wxPython for the GUI and I
 know it has support for adding an OpenGL canvas.

 Maybe including wxWidgets in the C++ program and just using the
 wxPython-created canvas ID there will somehow be possible? I'll look
 into that but any help or ideas are most welcome.

I banged my head on this for quite a while trying to integrate
OpenInventor and wxPython (and later PyGTKGLext). Basically, the OpenGL
callers don't need to know what the current canvas is. You tell the
canvas to activate itself, it tells OpenGL hey, I'm the current canvas
now. Then OpenGL commands draw themselves on that canvas. It's really
much simpler than I initially thought. You just have to make sure that
there's a Python function somewhere in your begin-rendering sequence
that activates the canvas before OpenGL calls begin.

- Michael

-- 
mouse, n: a device for pointing at the xterm in which you want to type.
-- Fortune
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compiled program input

2006-02-28 Thread mehmetmutigozel
:) yes it does. thank you very much fredrick.

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


ANN: Leo 4.4a7 released

2006-02-28 Thread Edward K. Ream
Leo 4.4 alpha 7 is now available at:
http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

This version fixes some minor problems with Leo 4.4a6 and adds 
autocompletion and calltips. There are no known problems with this release. 
It may be better than beta quality.  Or not.

Leo is a text editor, data organizer, project manager and much more. See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4:
--
- An Emacs-like mini-buffer: you can now execute any command by typing its 
long name, with tab completion.

- Many new commands, including cursor and screen movement, basic character, 
word and paragraph manipulation, and commands to manipulate buffers, the 
kill ring, regions and rectangles. You can use Leo without using a mouse.

- Flexible key bindings and input modes. You can emulate the operation of 
Emacs, Vim, or any other editor.

- A tabbed log pane. The Find and Spell Check commands now use tabs instead 
of dialogs, making those commands much easier to use. Plugins or scripts can 
easily create new tabs. The Completion tab shows possible typing 
completions.

- Autocompletion and calltips.

- Dozens of other new features and bug fixes since Leo 4.3.3.

Quote of the month:
---
Thanks for a wonderful program - everybody should be using it! It blows the 
socks off that Java Mind mapping software that won project of the month a 
while back on sourceforge! -- Derick van Niekerk.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Home: http://sourceforge.net/projects/leo/
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:  http://sourceforge.net/cvs/?group_id=3458
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


Re: Firebird and Python

2006-02-28 Thread Claudio Grondi
Ray Cote wrote:
 At 5:07 PM +0100 2/27/06, Magnus Lycka wrote:
 
 SNIP
  I'm still interested
 in experiences from Pythonistas using Firebird--
 especially embedded.
 
 
 Works great.
 Python and Firebird embedded (at least on Windows) is very simple to use.
 Not currently using it on other platforms.
 --Ray
 

May I ask what do I need to use embedded Firebird from Python on Windows?

Which Firebird download
(http://www.firebirdsql.org/download/prerelease/win32/Firebird-2.0.0.12169-0_embed_win32.zip
 
  ?)
and which Python module
(http://kinterbasdb.sourceforge.net/ ?)

Do I understand it right, that I can use Firebird database in the same 
way as I can use the Berkeley one provided in Python standard distribution?

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


Deleting items from Tix Tree

2006-02-28 Thread anil . pundoor
hi
 iam using Tix tree widget in my python script. how can i delete the
entire tree. i tried the following

self.msgTree = Tix.Tree(self.msgWin)
self.msgTree.hlist.delete()

but it thorws the following error

self.msgTree.hlist.delete()
  File /usr/local/lib/python2.2/lib-tk/Tix.py, line 320, in
__getattr__
raise AttributeError, name
AttributeError: delete


can some one help me

thanks 
Anil

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


Re: HTML/DOM parser

2006-02-28 Thread Michael Ekstrand
On 28 Feb 2006 00:33:11 -0800
Xah Lee [EMAIL PROTECTED] wrote:
 is there a module that lets me parse validated html files and store it
 as a tree?

BeautifulSoup will parse valid HTML (not just XHTML), and also crummy
HTML while it's at it. And generates a tree structure. Warning: I
haven't actually used this myself, I've just looked at it.

http://www.crummy.com/software/BeautifulSoup/

- Michael

-- 
mouse, n: a device for pointing at the xterm in which you want to type.
-- Fortune
-- 
http://mail.python.org/mailman/listinfo/python-list


UK Python Conference - 19-20 April 2006

2006-02-28 Thread Andy Robinson

The ACCU is once again hosting a UK Python Conference on the above dates 
at the Randolph Hotel in Oxford.  Sign up now.

   http://www.accu.org/index.php/conferences/2006/schedule

PROGRAMME
=
I am happy to announce that Guido van Rossum is once again a keynote 
speaker for the entire ACCU conference.   Following his keynote we have 
a single, 2-day Python track on Wednesday and Thursday including...

Steve Holden: The Best of PyCon
Michael Hudson: Error Handling with Recovery
Phil Thompson: PyQT 4
Michael Hudson: PyPy - a progress report
Simon Willison: Django
Remi Delon:  CherryPy and TurboGears
Chris Withers: Templating systems
Andy Robinson: Metadata and models in Python
Andrew Thompson: Financial Programming in Python

...and of course lightning talks and BOFS will be welcome


Friday 21st will feature a Dynamic Languages track with in-depth talks 
on Javascript, Ruby and Groovy, which I am sure will be of great 
interest to Python developers; and of course the dinner.

PRE CONFERENCE PYTHON TUTORIAL:
===
John Pinner will be giving a full day Python for Programmers tutorial 
on Tuesday prior to the main event.  This tutorial is aimed at 
programmers who have no previous knowledge of Python but who would like 
to know more about it. If you want to convert your colleagues, this is 
where to send them


ABOUT THE ACCU CONFERENCE
=
For those not familiar with the event, the ACCU conference is one of the 
foremost gatherings of programming talent in the world, regularly 
featuring authors and major figures from the C/C++/C#/Java/Python and 
other communities.The cheapest way to attend is to join the ACCU

This will be the LAST CHANCE to attend this fantastic event; after more 
than 5 years of being nurtured by the ACCU, the UK Python community will 
hopefully be organising a standalone conference in future years.  Python 
talks will continue to be welcome (and we hope numerous) on the ACCU 
programme, but not as an advertised mini-conference; instead we'll be 
shifting focus to dynamic languages in general.



Best Regards,


Andy Robinson
ACCU Conference Committee






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


comple list slices

2006-02-28 Thread William Meyer
Hi,

I have a list of rows which contains a list of cells (from a html table), and I
want to create an array of logical row groups (ie group rows by the rowspan). I
am only concerned with checking the rowspan of specific columns, so that makes
it easier, but I am having trouble implementing it in python. In perl/c I could
use a for loop and modify the control variable as I walked the array:

my (@rowgroups);
for (my ($i) = 0; $i  $#rows; $i++) {
my ($rowspan) = $rows[$i][0]-attr(rowspan) || 1;
$rowspan--; # 0 indexed

push @rowgroups, $rows[$i .. $i+$rowspan];

$i += $rowspan;
}

but in python I can only come up with this:

rowgroups = []
rowspan = 0
for i in rows:
if rowspan  0:
rowspan -= 1
continue

rowspan = rows[j][0][rowspan] or 1
rowgroups.append(rows[ rows.index(i) : rows.index(i) + rowspan ])

rowspan -= 1

I really dont like this solution. Any ideas?

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


Re: Python and Flash

2006-02-28 Thread SamFeltus
I aint a professional coder, but a gardener.  However, the
Flash-JSON-Python technique works.  It is poorly coded, but it is IMO
a very simple way to integrate Flash and Python compared to the methods
normally suggested on the net.

The HTML is just some junk thrown up for people with lower tech
browsers without much thought or consideration.

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


error: argument after ** must be a dictionary

2006-02-28 Thread abcd
I have class like this...

import threading
class MyBlah(object):
def __init__(self):
self.makeThread(self.blah, (4,9))

def blah(self, x, y):
print X and Y:, x, y

def makeThread(self, func, args=(), kwargs={}):
threading.Thread(target=self.blah, args=args,
kwargs=kwargs).start()

When I do...
b = MyBlah()

I am getting this error:
TypeError:  MyBlah object argument after ** must be a dictionary

What am I missing?

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


Re: error: argument after ** must be a dictionary

2006-02-28 Thread Fredrik Lundh
abcd [EMAIL PROTECTED] wrote:

I have class like this...

 import threading
 class MyBlah(object):
def __init__(self):
self.makeThread(self.blah, (4,9))

def blah(self, x, y):
print X and Y:, x, y

def makeThread(self, func, args=(), kwargs={}):
threading.Thread(target=self.blah, args=args,
 kwargs=kwargs).start()

 When I do...
 b = MyBlah()

 I am getting this error:
 TypeError:  MyBlah object argument after ** must be a dictionary

I'm getting

X and Y: 4 9

are you sure you posted the right code ?

where's the rest of the traceback, btw ?

/F 



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


Get my airlines boarding pass

2006-02-28 Thread rh0dium
Hi all,

Has any of you fine geniuses figured out a nice python script to go to
the Southwest airlines website and check in, and retrieve your boarding
pass - automatically 24 hours in advance

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


Re: comple list slices

2006-02-28 Thread shandy . b
A couple questions:

1- what is j?
2- what does the rows[x][y] object look like?  I assume it's a dict
that has a rowspan key.  Can rows[x][y][rowspan] sometimes be 0?

Perhaps you're looking for something like this:
rowgroups = []
rowspan = 0
for i in range( len(rows) ):
if rowspan = 0:
rowspan = rows[j][0][rowspan]
if rowspan == 0:
rowspan = 1

rowgroups.append(rows[ i : i + rowspan ])

rowspan -= 1

-sjbrown

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


Re: Python advocacy in scientific computation

2006-02-28 Thread tooper
Maybe I'd also emphasize the nice COM interface that allow your wrapped
Fortran to be made available in your Excel macros in a snap. It happens
that Fortran programmers/users tends to be poor Office users except for
Excel which they master at unbelievable level...
My own best low work/high user satisfaction ever is just this, wrap
LOWTRAN call to make is usable from Excel, a 1/2h work and a 100+ users
2 days later !

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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread Steven Bethard
Ben Finney wrote:
 This PEP specifies an enumeration data type for Python.
 
 An enumeration is an exclusive set of symbolic names bound to
 arbitrary unique values.  Values within an enumeration can be iterated
 and compared, but the values have no inherent relationship to values
 outside the enumeration.

-1 on the proposal as-is.  I don't have many use cases for enumerations, 
and I don't think they merit appearing in the builtins.  If you put them 
in the collections module instead, I'd probably be +0.

 This allows the operation to succeed, evaluating to a boolean value::
 
  gym_night = Weekdays.wed
  gym_night  Weekdays.mon
 False
  gym_night  Weekdays.wed
 False
  gym_night  Weekdays.fri
 True
  gym_night  23
 False
  gym_night  23
 True
  gym_night  wed
 True
  gym_night  Grades.B
 True

For the few cases of enumerations that I've needed, I've never wanted 
them to be comparable with , , etc.  If there were two classes, say 
``collections.Enum`` and ``collections.OrderedEnum`` where only the 
latter made the enumerated items comparable, you might even get me as 
high as +0.5.  (I only care about the non-comparable one, but I 
understand that others may have a need for the comparable one.)

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


Re: Firebird and Python

2006-02-28 Thread Magnus Lycka
Claudio Grondi wrote:
 Do I understand it right, that I can use Firebird database in the same 
 way as I can use the Berkeley one provided in Python standard distribution?

That depends on what you mean by the same way...

As with Berkeley, you can use it in-process, and don't need a
separate server process. On the other hand, it's a full SQL
database, not a persistent mapping as Berkeley DB etc. It's
better to compare it with SQLite, but it's not as lite. That
is, it support more of the SQL standards. Firebird can also be
used as a database server, not just as an embedded database.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comple list slices

2006-02-28 Thread johnzenger
Python lets you iterate through a list using an integer index, too,
although if you do so we will make fun of you.  You can accomplish it
with a while loop, as in:

i = 0
while i  len(rows):
   if rows[i] == This code looks like BASIC without the WEND, doesn't
it?:
  rowgroups.append(Pretty much.)
   i += 1 # or i += rowspan, whatever.

Do not try to do this with a for loop.  In Python, for i in xrange(5)
is more like a foreach $i ( {0,1,2,3,4,5}) in Perl, so changing i in
the loop will not change the value of i on the next loop iteration.

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


Re: time.sleep(1) sometimes runs for 200 seconds under windows

2006-02-28 Thread Mladen Adamovic
Magnus Lycka wrote:
 On Windows that it. At least on Linux and Solaris, time.clock() returns
 CPU time. If time.clock() returns significantly different values before
 and after time.sleep(1), there's something seriously broken in sleep on
 such platforms.

No!
When process run the sleep, the operating system give other processes to 
run and it takes time (so called time slice)  to get back to the 
original process.

Recently I invoked Runtime.sleep() from Java on Centos 4.2 and it might 
take up to 1 sec(!) to come from the sleep no matter what you put as the 
sleep parameter.

Basically each process runs for around 20ms and then the other process 
get priority. I'm not sure why those Codecs run OK when I watch DVD 
movie while running other Java application which use processor and hard 
disc quite intensivly, it seems that they got slices regulary, I'm not 
sure way.

So, once more when you go to sleep other process get the slice so it 
could take more time then predicted to continue.

-- 
Mladen Adamovic
http://home.blic.net/adamm
http://www.shortopedia.com
http://www.froola.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vectorization and Numeric (Newbie)

2006-02-28 Thread johnzenger
map takes a function and a list, applies the function to each item in
a list, and returns the result list.  For example:

 def f(x): return x + 4

 numbers = [4, 8, 15, 16, 23, 42]
 map(f, numbers)
[8, 12, 19, 20, 27, 46]

So, rather that ask if there is a different way to write f, I'd just
use f in a different way.

Another way to accomplish the same result is with a list comprehension:

 [f(x) for x in numbers]
[8, 12, 19, 20, 27, 46]

As you can see, if you wanted to calculate all the values from 1 to
n, you could also use these techniques instead of a loop.

 n = 10
 [f(x) for x in xrange(1, n+1)]
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

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


Re: comple list slices

2006-02-28 Thread William Meyer
 shandy.b at gmail.com writes:

 
 A couple questions:
 
 1- what is j?
 2- what does the rows[x][y] object look like?  I assume it's a dict
 that has a rowspan key.  Can rows[x][y][rowspan] sometimes be 0?
 
 Perhaps you're looking for something like this:
 rowgroups = []
 rowspan = 0
 for i in range( len(rows) ):
 if rowspan = 0:
 rowspan = rows[j][0][rowspan]
 if rowspan == 0:
 rowspan = 1
 
 rowgroups.append(rows[ i : i + rowspan ])
 
 rowspan -= 1
 
 -sjbrown
 

oops, typo
row[j] should be i
that line should read:
rowspan = i[0][rowspan]

rows is a list of lists which contains td tag objects from beautifulsoup.
rowspan is a tag attribute. You solution is clearer then mine, but the approach
is the same. Is there finer grained control of loops in python? (or in a perfect
world a way to group rows this way with list comprehensions?)

Rowspan can be none, meaning 1, and it can be zero. Zero means the row extends
from the current cell until the end of the table. That isnt used much, and not
in the table I am scraping at all.




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


Re: comple list slices

2006-02-28 Thread William Meyer
 johnzenger at gmail.com writes:

 
 Python lets you iterate through a list using an integer index, too,
 although if you do so we will make fun of you.  You can accomplish it
 with a while loop, as in:
 
 i = 0
 while i  len(rows):
if rows[i] == This code looks like BASIC without the WEND, doesn't
 it?:


ahh, that would work. Yea its really ugly too. I will probably just use the
shandy.b's suggestion squirreled away in a method. I shouldnt even care, its
just one extra conditional per row



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


Re: Best python module for Oracle, but portable to other RDBMSes

2006-02-28 Thread dananrg
What would be the next best Oracle database module for Python next to
cx_oracle? I'd like to compare two and choose one, just for the sake of
seeing how two modules doing the same thing operate.

Also, does installing cx_oracle create registry entries or require
admin privs on a Windows XP machine? I see that cx_oracle is
distributed as an EXE.

Thanks.

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


Re: Best python module for Oracle, but portable to other RDBMSes

2006-02-28 Thread dananrg
Also, what's the difference between something like cx_oracle and an
ODBC module? If I were to use an ODBC module (not trying to torture
myself here, I promise, but I just want to see what alternatives exist
and how they work).

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


Re: comple list slices

2006-02-28 Thread johnzenger
Although I don't know if this is faster or more efficient than your
current solution, it does look cooler:

def grouprows(inrows):
rows = []
rows[:] = inrows  #  makes a copy because we're going to be
deleting
while len(rows)  0:
rowspan = rows[0][rowspan]
yield rows[0:rowspan]  # returns this value, but control flow
unaffected
del rows[0:rowspan]  # remove what we just returned from the
list, and loop

grouper = grouprows(copyrows)
print [x for x in grouper]

This is basically just a simple function that rips chunks off the front
of a list and returns them.  Because the function uses yield rather
than return, it becomes a generator, which can be treated by Python
as an iterator.

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


Re: Is Python a Zen language?

2006-02-28 Thread Mc Osten
On 26 Feb 2006 14:55:04 -0800, Andrea Griffini wrote:

 IMO another language that would be hard to classify is COBOL ... but
 for other reasons :-)

According to Dijkstra:

The use of COBOL cripples the mind; its teaching should, therefore, be
regarded as a criminal offence. 

That makes Cobol a Zen language (since it not only changes, but also
cripples the mind).

And BASIC too:
It is practically impossible to teach good programming to students that
have had a prior exposure to BASIC: as potential programmers they are
mentally mutilated beyond hope of regeneration.

-- 
USB Priests for only 10$
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Flash

2006-02-28 Thread SamFeltus
By the way Sybren, if you don't mind, what kinda computer and browser
were you using, trying to figure out which browsers get redirected to
html and which get the Flash Site.  If you have Flash plugin, what
version was it?

Thanks,

Sam the Gardener

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


Re: minimize a program into an icon on the taskbar.

2006-02-28 Thread Frank Niessink
Rajesh Sathyamoorthy:
 Hi,
 
 I would know how to minimize a program (wxpython app) into an icon on 
 the taskbar on windows (the one at the side near the clock, i can't 
 remember what is it called.)
 
 Is it easy to be done? Is there a way to do the same thing on Linux?

Did you look into wx.TaskBarIcon?

Cheers, Frank


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


Re: Python and Flash

2006-02-28 Thread [EMAIL PROTECTED]
SamFeltus wrote:
 I aint a professional coder, but a gardener.  However, the
 Flash-JSON-Python technique works.  It is poorly coded, but it is IMO
 a very simple way to integrate Flash and Python compared to the methods
 normally suggested on the net.

 The HTML is just some junk thrown up for people with lower tech
 browsers without much thought or consideration.

Some people with high-tech browsers don't use Flash for non-technical
reason.  The audit clauses in the license allow Macromedia to audit
your computers for license compliance at any time, so some companies
that feel strongly about their data staying away from prying eyes won't
allow it to be installed.  It's illegal to install Flash on some
versions of Windows, let alone more esoteric operating systems.  Using
the version bundled with IE may skirt some of these issues, I'm not
sure.

see http://www.macromedia.com/shockwave/download/license/desktop/
especially 2(b) and 3(a).

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


Re: Python and Flash

2006-02-28 Thread Sybren Stuvel
SamFeltus enlightened us with:
 By the way Sybren, if you don't mind, what kinda computer and
 browser were you using, trying to figure out which browsers get
 redirected to html and which get the Flash Site.

Mozilla Firefox 1.5, on Ubuntu Linux Breezy.

 If you have Flash plugin, what version was it?

Shockwave Flash 7.0 r25

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib logarithmic scatter plot

2006-02-28 Thread John Hunter
 Derek == Derek Basch [EMAIL PROTECTED] writes:

Derek Great! That worked fine after I played with it for a
Derek bit. One last question though. How do I label the ticks
Derek with the product of the exponentiation? For instance:

Derek 100

Derek instead of

Derek 10**2

You can supply your own custom tick formatters (and locators).  See

  http://matplotlib.sf.net/matplotlib.ticker.html 

and examples

  http://matplotlib.sourceforge.net/examples/custom_ticker1.py
  http://matplotlib.sourceforge.net/examples/major_minor_demo1.py
  http://matplotlib.sourceforge.net/examples/major_minor_demo2.py

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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread [EMAIL PROTECTED]
Ben Finney wrote:
 PEP 354: Enumerations in Python has been accepted as a draft PEP. The
 current version can be viewed online:

-1 on the proposal as a builtin, -0 on including any kind of
enumeration in the standard library unless I can see a compelling use
case; Carl Banks' approach seems more flexible and doesn't add yet more
to the burgeoning Python distro.

Add me to the me, too! list of people who think enumerations would be
better off without  or  comparison.

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


Re: comple list slices

2006-02-28 Thread William Meyer
 johnzenger at gmail.com writes:

 Although I don't know if this is faster or more efficient than your
 current solution, it does look cooler:
 
 def grouprows(inrows):
 rows = []
 rows[:] = inrows  #  makes a copy because we're going to be
 deleting
 while len(rows)  0:
 rowspan = rows[0][rowspan]
 yield rows[0:rowspan]  # returns this value, but control flow
 unaffected
 del rows[0:rowspan]  # remove what we just returned from the
 list, and loop
 
 grouper = grouprows(copyrows)
 print [x for x in grouper]

wow, i think this is much better then my solution. And you can easily call it
for subgroups:

grouper = grouprows(rows)
for x in grouper
grouperTwo = grouprows(x)
for y in grouperTwo

Do i need to copy the list in the iterator? (if I am not planning on using rows
again) The reference count for the list members will get bumped on yield right? 


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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread Toby Dickenson
On Monday 27 February 2006 02:49, Ben Finney wrote:

 Coercing a value from an enumeration to a ``str`` results in the
 string that was specified for that value when constructing the
 enumeration::

That sentence seems to assume that all enumeration values will have been 
specified as strings. Thats reasonable, but your description of the creation 
of an enumeration doesnt specify that.

 An enumerated type is created from a sequence of arguments to the
 type's constructor::
 
  Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')
  Grades = enum('A', 'B', 'C', 'D', 'F')

s/arguments/strings/

?

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


Looking for Pythonic Examples

2006-02-28 Thread G. Völkl
Hello 

I am looking for examples of Pythonic Thinking:

One example I found:

Here some lines of the web side of Bruce Eckel:
http://www.mindview.net/WebLog/log-0053

How to read a text file:
for line in file(FileName.txt):
  # Process line
It is a easy and sophisticated thing in python,
but hard to do or more complicated in other languages 
like java.

Does anyone know more examples ?

Does anyone know books about real good python programming ?

Best Regards

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


escaping quotes

2006-02-28 Thread John Salerno
I'm reading through the tutorial and found this in section 3:

  'Isn\'t, she said.'
'Isn\'t, she said.'


Why doesn't the escape sequence work in this case?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: MySQLdb compile error with AMD64

2006-02-28 Thread keith
Can anyone offer any assistance on this one?

Is it unsupported on AMD64 ? Nothing in the README points to that. I
thought it would default to 32bit if not supported under 64.
 
 Hi,
 
 I have been using MySQLdb on a 32-bit processor, no worries. Love it.
 
 I went to install on an AMD64 running the 64-bit version of SUSE 10.0.
 
 I get the following error during the python setup.py build
 
 gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -fmessage-length=0 -Wall
 -D_FORTIFY_SOURCE=2 -g -fPIC -I/usr/include/mysql
 -I/usr/include/python2.4 -c _mysql.c -o
 build/temp.linux-x86_64-2.4/_mysql.o -I/usr/include/mysql -g
 -march=i586 -mcpu=i686 -fmessage-length=0
 `-mcpu=' is deprecated. Use `-mtune=' or '-march=' instead.
 _mysql.c:1: error: CPU you selected does not support x86-64 instruction
 set
 _mysql.c:1: error: CPU you selected does not support x86-64 instruction
 set
 error: command 'gcc' failed with exit status 1
 
 Any ideas on what I have to do to make this work?
 
 Any help appreciated!
 
 Cheers
 Keith

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


Numerical solver

2006-02-28 Thread Laszlo Zsolt Nagy

  Hello,

I would like to use a numerical solver for a specific problem. My 
problem looks like this:

   1. I have numeric constants, named A,B,C etc.
   2. I have numeric variables, named x,y,z etc.
   3. I have functions, like f1(x), f2(x), f3(x,y), f4(y) etc.
   4. I have constraints like f1(x)  A  f3(x,y)  B etc.

Fortunately, all of the variables can be limited to a closed finite 
interval. (E.g.   0 = x = 100)
There is a specific function, called P(x,y,z) that needs to be optimized 
(need to find its maximum/minimum).

I'm looking for a native Python solution: I would like to define the 
functions and the constraints in Python.
I have looked at the cheeseshop and found LogiLab's constraint:

http://www.logilab.org/projects/constraint/documentation

It is almost perfect for me, but it is working with finite sets.
I'm not sure about SciPy or NumPy. Do you have an idea about what is the 
package I need?
I'll gladly read any documentation or tutorial, just I do not know which 
one is the best to start with.

Thanks,

   Laszlo

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


Re: Best python module for Oracle, but portable to other RDBMSes

2006-02-28 Thread Gerhard Häring
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
 What would be the next best Oracle database module for Python next to
 cx_oracle? 

That would probably be DCOracle2.

 I'd like to compare two and choose one, just for the sake of
 seeing how two modules doing the same thing operate.
 
 Also, does installing cx_oracle create registry entries or require
 admin privs on a Windows XP machine? I see that cx_oracle is
 distributed as an EXE.

It's most probably created using distutils and python setup.py
bdist_wininst. These installers only use the registry to look up the
path Python where is installed. Of course it will need a correctly
working Oracle client to operate.

- -- Gerhard
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFEBJxBdIO4ozGCH14RAqXCAJ9Vq6L8SLvnhlBCDc4EzwloJYp28ACfVt8J
TNN+XgNxFLmQscu9wpPIK4M=
=txAA
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: escaping quotes

2006-02-28 Thread Fredrik Lundh
John Salerno wrote:

 I'm reading through the tutorial and found this in section 3:

   'Isn\'t, she said.'
 'Isn\'t, she said.'

 Why doesn't the escape sequence work in this case?

because the interactive prompt echos the result back to you as
a Python literal, where possible.  compare

 'Isn\'t, she said.'
'Isn\'t, she said.'

with

 print 'Isn\'t, she said.'
Isn't, she said.

(this is explained a little later in the chapter you're reading)

/F



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


Re: Numerical solver

2006-02-28 Thread Robert Kern
Laszlo Zsolt Nagy wrote:
   Hello,
 
 I would like to use a numerical solver for a specific problem. My 
 problem looks like this:
 
1. I have numeric constants, named A,B,C etc.
2. I have numeric variables, named x,y,z etc.
3. I have functions, like f1(x), f2(x), f3(x,y), f4(y) etc.
4. I have constraints like f1(x)  A  f3(x,y)  B etc.
 
 Fortunately, all of the variables can be limited to a closed finite 
 interval. (E.g.   0 = x = 100)
 There is a specific function, called P(x,y,z) that needs to be optimized 
 (need to find its maximum/minimum).

In [7]: scipy.optimize.fmin_cobyla?

Type:   function
Base Class: type 'function'
String Form:function fmin_cobyla at 0x4fff3b0
Namespace:  Interactive
File:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/scipy-
0.4.7.1607-py2.4-macosx-10.4-ppc.egg/scipy/optimize/cobyla.py
Definition: scipy.optimize.fmin_cobyla(func, x0, cons, args=(),
consargs=None, rhobeg=1.0, rhoen
d=0.0001, iprint=1, maxfun=1000)
Docstring:
Minimize a function using the Contrained Optimization BY Linear
Approximation (COBYLA) method

Arguments:

func -- function to minimize. Called as func(x, *args)

x0   -- initial guess to minimum

cons -- a sequence of functions that all must be =0 (a single function
if only 1 constraint)

args -- extra arguments to pass to function

consargs -- extra arguments to pass to constraints (default of None means
use same extra arguments as those passed to func).
Use () for no extra arguments.

rhobeg --  reasonable initial changes to the variables

rhoend --  final accuracy in the optimization (not precisely guaranteed)

iprint  -- controls the frequency of output: 0 (no output),1,2,3

maxfun  -- maximum number of function evaluations.


Returns:

x -- the minimum

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter

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


telnetlib problems

2006-02-28 Thread vercingetorix52
I'm trying to use a python script to access an embedded computer
running linux and connected via a crossover ethernet cable using the
following script...

...and I realize the username and password is not realistic... I'm
still in proof of concept stage here :)

#
import telnetlib

tn = telnetlib.Telnet('192.168.100.11')

tn.read_until('login: ', 5)

tn.write('user\n')

tn.read_until('Password: ', 5)

tn.write('password\n')

tn.read_until('bash-2.05$ ', 5)

tn.write('ls\n')

print tn.read_very_eager()
#

As a script, this doesn't work.  However, if I execute the same
commands interactively, it works fine.  If I insert some time delays as
follows...

#
import telnetlib
import time

tn = telnetlib.Telnet('192.168.100.11')

tn.read_until('login: ', 5)
time.sleep(2)
tn.write('user\n')

tn.read_until('Password: ', 5)
time.sleep(2)
tn.write('password\n')

tn.read_until('bash-2.05$ ', 5)

tn.write('ls\n')
time.sleep(2)
print tn.read_very_eager()
#

...and it works fine.  Can anyone tell me what's going on here? TIA

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


Re: sort one list using the values from another list

2006-02-28 Thread Ron Adam
[EMAIL PROTECTED] wrote:
 Following Ron Adam solution (and using [] instead of list() in the last
 line), this may be a possible solution of the problem, that is often
 quite fast:
 
 def psort16(s1, s2):
 try:
 d = dict(izip(s2, s1))
 except TypeError:
 _indices = range(len(s1))
 _indices.sort(key=s2.__getitem__)
 s1[:] = map(s1.__getitem__, _indices)
 else:
 if len(d) == len(s1):
 s1[:] = [d[v] for v in sorted(d)]
 else:
 _indices = range(len(s1))
 _indices.sort(key=s2.__getitem__)
 s1[:] = map(s1.__getitem__, _indices)
 
 Bye,
 bearophile

Looks good, but I think It would be simpler to just do.

def psort17(s1, s2):
 try:
 d = dict(izip(s2, s1))
 assert len(d) != len(s2)
 s1[:] = [d[v] for v in sorted(d)]
 except Exception:
 _indices = range(len(s1))
 _indices.sort(key=s2.__getitem__)
 s1[:] = map(s1.__getitem__, _indices)

We don't need to specify which exception.  Any problems will just get 
raised again on the second try it also fails.

Cheers,
Ron




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


Threading - will threads run in parallel?

2006-02-28 Thread SolaFide
I have 2 threads that I want to run at the same time: for instance:

from threading import Thread

class test(Thread):
 def run(self):
  while True:
  get(asdf)

class test2(Thread):
   def run(self):
 while True:
  get(jkl)
ack=test()
jkl=test2()
ack.start()
jkl.start()

(get() is a function which waits for a ping on a specific port, thus
stopping the program for a while.)

Will these run together, or do I have to find some other way of running
in parallel?

Also, is it possible to split off a program for the terminal that
started it? As in I type in python test.py and test.py runs in the
background and lets me do other things in that terminal?

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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread Terry Reedy

Stefan Rank [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 recent examples from this list:

 2006-01-03: http://www.nabble.com/Re%3A-Regex-anomaly-p2179421.html
 2006-02-20:
 http://www.nabble.com/Re%3A-Regular-expression-gone-mad-p3029028.html

If the re flags were implemented as instances of object instead of int,
then misuse of them as int args would be excepted.  I don't know if such a 
change would otherwise cause a problem.

I wonder whether a subclass of object (EnumSet?) that allowed for 
initialization with a better string representation and that disabled order 
comparisons would fill the bill for unordered enum.

As Steven Bethard also noted, there seem to be a need for two Enum 
subclasses:
EnumSet and EnumSeq.

Terry Jan Reedy



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


Re: telnetlib problems

2006-02-28 Thread vercingetorix52
I just hit upon something that seems to work...

##
import telnetlib
from select import select

tn = telnetlib.Telnet('192.168.100.11')
sock = tn.get_socket()

tn.read_until('login: ', 5)
select([sock], [], [], 5)
tn.write('user\n')

tn.read_until('Password: ', 5)
select([sock], [], [], 5)
tn.write('password\n')

tn.read_until('bash-2.05$ ', 5)
tn.write('ls\n')
select([sock], [], [], 5)
print tn.read_very_eager()
##

If anyone sees any potential problems with this, I would appreciate it.
 TIA

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


Thread Question

2006-02-28 Thread D
I have a client application that I want (behind the scenes) to check
and make sure a remote host is up (i.e. by ping or TCP connect).  I'm
assuming that, since I want this to go on unknowingly to the user,
that I would put this in a thread.  My question is, how would I go
about creating the thread?  I have seen examples that used classes, and
other examples that just called one thread start command - when should
you use one over another?  Thanks in advance.

Doug

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


Re: Threading - will threads run in parallel?

2006-02-28 Thread Ido Yehieli
 Also, is it possible to split off a program for the terminal that
 started it? As in I type in python test.py and test.py runs in the
 background and lets me do other things in that terminal?

try:
python test.py 

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


Re: Threading - will threads run in parallel?

2006-02-28 Thread Rene Pijlman
SolaFide:
(get() is a function which waits for a ping on a specific port, thus
stopping the program for a while.)

Will these run together, 

Thread 2 can run while thread 1 is blocked for I/O and v.v.

Also, is it possible to split off a program for the terminal that
started it? As in I type in python test.py and test.py runs in the
background and lets me do other things in that terminal?

Platform? Shell?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threading - will threads run in parallel?

2006-02-28 Thread SolaFide
Thanks!

The problem is on Windows: when I run c:\python24\myprogram.py, it has
a command window open up. If I close it, the program ends. So I want it
to run without opening that window.

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


Re: Looking for Pythonic Examples

2006-02-28 Thread Ido Yehieli
This one is from our very own BDFL, behold- wget implemented in 7 lines
of python code:

import sys, urllib
def reporthook(*a): print a
for url in sys.argv[1:]:
 i = url.rfind('/')
 file = url[i+1:]
 print url, -, file
 urllib.urlretrieve(url, file, reporthook)

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


Re: Threading - will threads run in parallel?

2006-02-28 Thread Jarek Zgoda
SolaFide napisał(a):

 The problem is on Windows: when I run c:\python24\myprogram.py, it has
 a command window open up. If I close it, the program ends. So I want it
 to run without opening that window.

Give it .pyw extension or start using pythonw.exe instead of python.exe.

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


Re: escaping quotes

2006-02-28 Thread John Salerno
Fredrik Lundh wrote:

 because the interactive prompt echos the result back to you as
 a Python literal, where possible.  compare

Ah, of course! I forgot it wasn't 'print'ing it.

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


Re: Thread Question

2006-02-28 Thread Grant Edwards
On 2006-02-28, D [EMAIL PROTECTED] wrote:

 I have a client application that I want (behind the scenes) to check
 and make sure a remote host is up (i.e. by ping or TCP connect).  I'm
 assuming that, since I want this to go on unknowingly to the user,
 that I would put this in a thread.

Probably.

 My question is, how would I go about creating the thread?

Assuming foo is the function you want to start in a thread:

   threading.Thread(target=foo).start()

 I have seen examples that used classes, and other examples
 that just called one thread start command - when should you
 use one over another?

I'm not sure what you mean by use classes vs. calling a
thread start command.  My example above uses a class
(threading.Thread) to create a thread object, and then calls
its start method.

-- 
Grant Edwards   grante Yow!  HELLO, little boys!
  at   Gimme a MINT TULIP!! Let's
   visi.comdo the BOSSA NOVA!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comple list slices

2006-02-28 Thread johnzenger
You don't need to copy the list; but if you don't, your original list
will be emptied.

Len(rows) recalculates each time the while loop begins.  Now that I
think of it, rows != [] is faster than len(rows)  0.

By the way, you can also do this using (gasp) a control index:

def grouprows(rows):
index = 0
while len(rows)  index:
rowspan = rows[index][rowspan]
yield rows[index:rowspan + index]
index += rowspan

...which kind of brings us back to where we started.

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


Re: Thread Question

2006-02-28 Thread Felipe Almeida Lessa
Em Ter, 2006-02-28 às 20:24 +, Grant Edwards escreveu:
  I have seen examples that used classes, and other examples
  that just called one thread start command - when should you
  use one over another?
 
 I'm not sure what you mean by use classes vs. calling a
 thread start command.  My example above uses a class
 (threading.Thread) to create a thread object, and then calls
 its start method.

# He meant calling direct vs. subclassing. In your example you called
the Thread class directly, but you could have subclassed it.

# In your case, Edwards, I'd prefer subclassing because then you could
put some states in the class. A (bad) example:

class Foo(Thread):
def __init__(self):
Thread.__init__(self)
self.alive = False
self.running = True

def run(self):
while self.running:
self.alive = ping('myhost')
sleep(10)

def stop(self):
self.running = False

# Then you could:

a = Foo()
do_something()
print a.alive
do_something_more()
print a.alive
finish_everything()
print a.alive
a.stop()
# quit

-- 
Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas.

  -- Sun Tzu, em A arte da guerra

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

Re: Thread Question

2006-02-28 Thread D
Thanks, Grant.  I apologize for not being clear on what I meant by
using classes.  This is an example of what I was referring to:
http://www.wellho.net/solutions/python-python-threads-a-first-example.html

See the second (threaded) example.  

Doug

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


Make staticmethod objects callable?

2006-02-28 Thread Nicolas Fleury
Hi everyone,
I was wondering if it would make sense to make staticmethod objects 
callable, so that the following code would work:

class A:
 @staticmethod
 def foo(): pass
 bar = foo()

I understand staticmethod objects don't need to implement __call__ for 
their other use cases, but would it still make sense to implement 
__call__ for that specific use case?  Would it be error-prone in any way?

Thx and regards,
Nicolas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Firebird and Python

2006-02-28 Thread haxier
All the info you need is in the kinterbasdb module. I've worked with it
under windows and Linux and... it just works. Really well indeed. I'd
recommend it a lot.

http://kinterbasdb.sourceforge.net/dist_docs/usage.html#faq_fep_embedded_using_with

--
Asier.

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


Re: comple list slices

2006-02-28 Thread Felipe Almeida Lessa
Em Ter, 2006-02-28 às 09:10 -0800, [EMAIL PROTECTED] escreveu:
 Although I don't know if this is faster or more efficient than your
 current solution, it does look cooler:
[snip]
 print [x for x in grouper]

This is not cool. Do

print list(grouper)

-- 
Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas.

  -- Sun Tzu, em A arte da guerra

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

Re: Thread Question

2006-02-28 Thread Grant Edwards
On 2006-02-28, D [EMAIL PROTECTED] wrote:

 Thanks, Grant.  I apologize for not being clear on what I
 meant by using classes.  This is an example of what I was
 referring to:
 http://www.wellho.net/solutions/python-python-threads-a-first-example.html

Ah, I see.  I had forgotten that people subclass Thread like
that.  It's mostly just a matter of style.  There aren't any
practical differences that I can think of.

-- 
Grant Edwards   grante Yow!  BARBARA STANWYCK
  at   makes me nervous!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comple list slices

2006-02-28 Thread Fredrik Lundh
[EMAIL PROTECTED]:

 Len(rows) recalculates each time the while loop begins.  Now that I
 think of it, rows != [] is faster than len(rows)  0.

the difference is very small, and len(rows) is faster than rows != []
(the latter creates a new list for each test).

and as usual, using the correct Python spelling (rows) is a lot faster
(about three times in 2.4, according to timeit).

/F



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


Re: Thread Question

2006-02-28 Thread Felipe Almeida Lessa
Em Ter, 2006-02-28 às 20:38 +, Grant Edwards escreveu:
 On 2006-02-28, D [EMAIL PROTECTED] wrote:
 
  Thanks, Grant.  I apologize for not being clear on what I
  meant by using classes.  This is an example of what I was
  referring to:
  http://www.wellho.net/solutions/python-python-threads-a-first-example.html
 
 Ah, I see.  I had forgotten that people subclass Thread like
 that.  It's mostly just a matter of style.  There aren't any
 practical differences that I can think of.

Within a class you can maintain lots of internal states and make it
easily changable by other threads. Sure, you could archive this with
functions, but IMHO it's not pythonic. But for simple cases both would
suffice.

-- 
Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas.

  -- Sun Tzu, em A arte da guerra

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

Re: PEP 354: Enumerations in Python

2006-02-28 Thread Terry Hancock
On Tue, 28 Feb 2006 14:26:49 -0500
Terry Reedy [EMAIL PROTECTED] wrote:
 Stefan Rank [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
  recent examples from this list:
 
  2006-01-03:
  http://www.nabble.com/Re%3A-Regex-anomaly-p2179421.html
  2006-02-20:
  http://www.nabble.com/Re%3A-Regular-expression-gone-mad-p3029028.html
 
 If the re flags were implemented as instances of object
 instead of int, then misuse of them as int args would be
 excepted.  I don't know if such a  change would otherwise
 cause a problem.
 
 I wonder whether a subclass of object (EnumSet?) that
 allowed for  initialization with a better string
 representation and that disabled order  comparisons would
 fill the bill for unordered enum.
 
 As Steven Bethard also noted, there seem to be a need for
 two Enum  subclasses:
 EnumSet and EnumSeq.

And one other distinction -- mutable versus immutable. A
immutable enum is the usual use case, a mutable one is a
vocabulary (i.e. an open set of symbols, which
nevertheless requires controlled access).

The key thing about symbols like enums etc is that they
don't really represent anything (or that which they
represent is inconvenient to bind to the symbols -- perhaps
its even an abstract concept that has no programmatic
representation beyond the enumerated value).

One thing about an enumerated value is that it should know
what enum it belongs to. For example, I'm currently working
on a project that has the following rather unfortunate
near-collision of symbols:

sym.ABSTRACTS  scope of abstract nouns in 
   SCOPE vocabulary

sym.ABSTR  definiteness of abstract noun in 
   ARTICLE enum

sym.ABST   number of noun which has no
   count because abstract (not mass)
   NUMBER enum

It's quite useful that I can ask sym.ABST which one of
the above domains it's in:

 sym.ABST.domain
NUMBER

or even better:

 sym.ABST
!NUMBER: ABST

Which makes the enumeration values somewhat
self-documenting.  I'm currently trying to figure out how
best to make this instead show (e.g.):

 sym.ABST
!NUMBER: ABST - Noun uncountable because abstract.

I can of course, also use this to catch errors by checking
that the pluralization function in my locale module has
been passed a NUMBER or an explicit int, instead of say, a
SCOPE, by accident.

Another feature here is that all of these symbols, though
also defined within their domain collections is also made
into an attribute of the sym object (which is a trivial
class or convenience namespace).

I also raise an error if any domain tries to overwrite a
symbol in sym, so I can avoid accidental collisions.

I'm still tinkering with this, and the above is from memory,
but I do have it working on another machine. I'm currently
subclassing from dict, not set, though I'm unsure if this is
really wise (but I'm more familiar with dict, and I'm
currently making use of the mapping internally, though I'm
not sure I really need to).

I'm not sure this would be a smart way to do this in another
application, but it looks promising for this one (which is
a kind of artificial locale-neutral language
representation).

I'm not sure that the enum described in the PEP would be as
useful to me as this.  So  I'm -0 on it becoming a built-in,
though I'm +0 on it becoming a module (it's not that hard
to type from enum import Enum).  But I'm not sure it's the
best enum, or even that one size fits all with enums
(though having fewer implementations might improve clarity
if they are really equivalent).

Cheers,
Terry

-- 
Terry Hancock ([EMAIL PROTECTED])
Anansi Spaceworks http://www.AnansiSpaceworks.com

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


Long running Script stops responding, CPU usage increases

2006-02-28 Thread Jeff Quandt
Title: Long running Script stops responding, CPU usage increases






This is running Python 2.3 on windows 2003/windows xp.


I have written a script to display and filter the Win32 event log in a scrolling list to the command line (it also does some summary tasks). It uses the win32evtlog.ReadEventLog to seek or scan the event log based on filter parameters. It is supposed to run until the user kills it, so there are repeated calls to ReadEventLog. 

The problem is that after the script has run from some time (usually several hours), the call to ReadEventLog seems to hang and the CPU usage increases dramatically (from nil to 30-50%). The script does not exit this stage, and has to be broken manually with Ctrl-C. I've tried closing and reopening the event log handle after it has been open for an hour. I've added explicit calls to the garbage collector. Neither helped at all.

I realize that this is an API call, so it may not be a python issue. But I have seen this type of behavior on other scripts (not event loggers), but they were test/debug tools and weren't important enough to track down the issue.

Any help would be appreciated.


code example:


 def OpenLog( self ):

 #

 #open event log

 #

 self.mHandle = win32evtlog.OpenEventLog( self.mComputer

 , self.mLogType

 )

 if not self.mHandle:

 raise ValueError, invalid handle


 self.mLogOpenTmst = time.time()


 def CloseLog( self ):


 win32evtlog.CloseEventLog( self.mHandle )


 def ReadLog( self ):


 self.mFlags = win32evtlog.EVENTLOG_FORWARDS_READ|win32evtlog.EVENTLOG_SEEK_READ

 vEventScon = win32evtlog.ReadEventLog( self.mHandle

 , self.mFlags

 , self.mLogOffset

 )

 #

 # if not found, try again in 5 seconds

 #

 if not vEventScon:


 #

 # If we've had the log open for more than 1 hour, dump it and reopen

 #

 if ( time.time()  (self.mLogOpenTmst + 3600) ):

 self.CloseLog()

 self.OpenLog()


 time.sleep( 5 )

 return bOk


 #

 # snip...

 # manipulate event records here

 #


#

# main

#

OpenLog

Ok = 1

while Ok:

 Ok = ReadLog()

CloseLog()




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

  1   2   >