Elisa Media Center 0.5.37 Release

2009-04-28 Thread Olivier Tilloy
Dear Python users,

The Elisa team is happy to announce the release of Elisa Media Center
0.5.37, code-named Doubledecker.

Elisa is a cross-platform and open-source Media Center written in Python.
It uses GStreamer [1] for media playback and pigment [2] to create an
appealing and intuitive user interface.

This release is a lightweight release, meaning it is pushed through
our automatic plugin update system. Additionally a windows installer is
available for download on our website.
As usual, for users running a version of Elisa = 0.5.35, the upgrade to
0.5.37 should be done automatically via the plugin repository.

As usual, tarballs are provided for distribution packagers.

A complete list of the issues fixed can be found at:

http://bugs.launchpad.net/elisa/+milestone/0.5.37

This is also summarised in the (attached) release notes.

Installers and sources can be downloaded from
http://elisa.fluendo.com/download/

Bug reports and feature requests are welcome at
http://bugs.launchpad.net/elisa/+filebug


Have a media-centered evening,


Olivier, for the Elisa team


[1] http://www.gstreamer.net/
[2] https://code.fluendo.com/pigment/trac
Elisa 0.5.37 Doubledecker
===

This is Elisa 0.5.37, thirty-seventh release of the 0.5 branch.

Bugs fixed since 0.5.36:

- 357097: Music scan partially fails on Ubuntu Jaunty
- 361558: amp master doesn't KILL dead slaves
- 330431: Previously played Audio track/video name appears on audio/video plugin
- 366152: [win32] Integrate a browser control in the installer
- 347174: Local videos thumbnail shown on Internet-video plugins


Download

You can find source releases of Elisa on the download page:
http://elisa.fluendo.com/download


Elisa Homepage

More details can be found on the project's website: http://elisa.fluendo.com


Support and Bugs

We use Launchpad for bug reports and feature requests:
https://bugs.launchpad.net/elisa/+filebug


Developers

All code is in a Bazaar branch and can be checked out from there.
It is hosted on Launchpad: https://code.launchpad.net/elisa


Contributors to this release:

- Anna Wojdel
- David McLeod
- Florian Boucault
- Guillaume Emont
- Jesús Corrius
- Julien Moutte
- Krzysztof Adamski
- Lionel Martin
- Loïc Molinari
- Marc Garcia
- Maxwell Young
- Olivier Tilloy
- Philippe Normand
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


CodeInvestigator version 0.11.1

2009-04-28 Thread hans moleman
CodeInvestigator version 0.11.1 was released on April 28.


Bug fix:
- A windows installation issue was resolved.


CodeInvestigator is a tracing tool for Python programs.

Running a program through CodeInvestigator creates a recording.
Program flow, function calls, variable values and conditions are all
stored for every line the program executes.
The recording is then viewed with an interface consisting of the
code. The code can be clicked: A clicked variable displays its
value,
a clicked loop displays its iterations.
You read code, and have at your disposal all the run time details of
that code. A computerized desk check tool and another way to learn
about your program.

http://sourceforge.net/project/showfiles.php?group_id=183942
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


[ANN] pyOpenSSL 0.9

2009-04-28 Thread Jean-Paul Calderone

I'm happy to announce the release of pyOpenSSL 0.9. This release includes
several new features and a very important bug fix:

 * APIs have been introduced to get and set the version of an X509 request
 * Contexts now support loading CA certificates for verification from a
   specified directory or from the platform's default certificate store
 * DTLS-related constants, OP_NO_QUERY_MTU, OP_COOKIE_EXCHANGE, and
   OP_NO_TICKET are now exposed
 * X509Extension now has the `get_short_name´ method for retrieving the
   short form of the extension type
 * It is now possible to create extensions which use any of the three
   possible OpenSSL implementation approaches
 * FILETYPE_TEXT can be used to dump keys, certificate, and CSRs in text
   format
 * Various compiler warnings have been fixed
 * A bug triggered by almost all uses of pyOpenSSL from multiple threads
   and leading to a crash has been fixed

Many thanks to numerous people who contributed patches to this release.

You can find pyOpenSSL 0.9 in the downloads area of the SourceForge project
page:

   https://sourceforge.net/project/showfiles.php?group_id=31249

Please use Launchpad to file any bug reports:

   https://bugs.launchpad.net/pyopenssl

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

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


Re: suggestion on a complicated inter-process communication

2009-04-28 Thread Jonathan Gardner
On Apr 27, 8:59 pm, Way csw...@gmail.com wrote:
 Hello friends,

 I have a little messy situation on IPC. Please if you can, give me
 some suggestion on how to implement. Thanks a lot!

 - denotes create

 MainProcess - Process1 - Process3 (from os.system)
                    |
                     - Process2 (from os.system) - Process4 (from
 os.system) -Process5

 I would like to make the communication between Process1 and Process5.
 Process1 needs Process5's output to provide argument to generate
 Process3, and in turn Process5 needs to wait Process3 finished.

 Thank you very much if you can give a hint.

Abstraction should resolve this. What I mean is that Process2
shouldn't be defined in terms of what it actually does, but what it
appears to do. If you look at each process and think only what its
child processes do and what its parent process expects it to do, then
your job should get a lot simpler. Process1 expects Process2 to
deliver a set of parameters to spawn Process3, and then it will wait
until Process3 terminates.

Looking at it this way, questions come to mind: Why can't Process2 run
Process3 itself? It's unusual to have one process tell another process
what to do when it can simply do it itself.

By the way, I've never seen a time when this kind of design is
necessary. There are other ways around your problem than spawning a
bunch of processes. Each process should really be independent of all
the other processes, doing only a very well-specified task in a well-
specified way. The only time I could think of doing something like
this is when you're getting a webserver setup and Process5 needs to
communicate with Process3 to render the page or something like that.
But even in that case, each process is really independently defined
and implemented.
--
http://mail.python.org/mailman/listinfo/python-list


Re: mailbox.mbox.add() sets access time as well as modification time

2009-04-28 Thread Lawrence D'Oliveiro
In message pan.2009.04.28.04.29...@remove.this.cybersource.com.au, Steven 
D'Aprano wrote:

 On Tue, 28 Apr 2009 11:19:51 +1200, Lawrence D'Oliveiro wrote:
 
 Either there are enough people using it to care about it, in which case
 somebody in the community will fix it, it or there are not, in which
 case it's not worth bothering with.
 
 That's EXACTLY the same as the proprietary software world.

No it's not. A proprietary product can have lots of users who care about it, 
yet the vendor can't be bothered keeping it up to date any more. For 
instance, it was estimated that there were 40 million people still using 
Windows 98 when Microsoft announced an end to support.

You don't get that with open-source products.

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


Why bool( object )?

2009-04-28 Thread Aaron Brady
What is the rationale for considering all instances true of a user-
defined type?  Is it strictly a practical stipulation, or is there
something conceptually true about objects?

'''
object.__bool__(self)
If a class defines neither __len__() nor __bool__(), all its instances
are considered true.
'''

This makes it so all objects except False, None, 0, and empty
containers are true by default.  I am not convinced that 'if a
generic object' should have any meaning; it should probably throw an
exception.  Is it part of Python's look and feel or its mentality?  Is
it part of the Zen?  Certainly other ideal types can't be cast from
generic objects, so why booleans?  Is it an ineffable component of the
author's vision for the language?  I think that giving arbitrary
syntactic constructs meaning is just space-filler.  It's worse than
syntactic sugar, it's semantic sugar.  Why not assign meanings willy-
nilly to other random juxtapositions of tokens?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread-killing, round 666 (was Re: Lisp mentality vs. Python mentality)

2009-04-28 Thread Aahz
In article 9a827369-b36f-4a86-870a-e5a505e34...@q33g2000pra.googlegroups.com,
Vsevolod  vselo...@gmail.com wrote:
On Apr 27, 8:18 pm, a...@pythoncraft.com (Aahz) wrote:
 
 If you want to talk about Python and problems you're running into, you
 should start a new thread.

I'm not at that level of proficiency with the language. I believe most
of my technical problems are connected with lack of knowledge or
experience, not the language's features. While conceptual problems
seem futile to discuss. There's another saying: when in Rome do as
the Romans do

c.l.py isn't just for the experts; if you have a question along the
lines of here's something I do in Lisp, how do I do it in Python?,
you're entirely on-topic.

Also, most of us are happy to explain why Python does things in certain
ways -- as with Lisp, the more you wrap your mind into the Python Way,
the easier you'll find your work.

Note that neither of these is why isn't Python more like Lisp?, that's
where you get into futility territory.  ;-)
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur.  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why bool( object )?

2009-04-28 Thread Stephen Hansen
On Mon, Apr 27, 2009 at 11:11 PM, Aaron Brady castiro...@gmail.com wrote:

 What is the rationale for considering all instances true of a user-
 defined type?  Is it strictly a practical stipulation, or is there
 something conceptually true about objects?

 '''
 object.__bool__(self)
 If a class defines neither __len__() nor __bool__(), all its instances
 are considered true.
 '''

 This makes it so all objects except False, None, 0, and empty
 containers are true by default.  I am not convinced that 'if a
 generic object' should have any meaning; it should probably throw an
 exception.  Is it part of Python's look and feel or its mentality?  Is
 it part of the Zen?  Certainly other ideal types can't be cast from
 generic objects, so why booleans?


Python simply defines a False value as:
  - None
  - False
  - 0
  - An empty sequence
  - An empty mapping
  - If an instance defines itself as false via either __nonzero__ or
__len__() with either method returning False.

Anything else is simply True.

These simple rules define Python's view of True or False. Any object is free
to define its own Truthfulness or Falseness as it sees fit. But in general,
these rules are extremely useful I think in the Pythonic realm of
Practicality beats Purity. It allows and encourages you to write
expressions like if thing instead of if thing == True or if thing is
True which enhance readability, IMHO.

Being able to ask, Is this list empy as if not lst instead of if
len(lst) == 0 is a highly useful property in expressiveness and usefulness.
For user defined classes it just defaults to assuming True.. but that class
is free to define its own truthfulness how it sees fit.

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


Re: Why bool( object )?

2009-04-28 Thread Lie Ryan

Aaron Brady wrote:

What is the rationale for considering all instances true of a user-
defined type?  


User-defined objects (or type) can override .__len__() [usually 
container types] or .__nonzero__() to make bool() returns False.



Is it strictly a practical stipulation, or is there
something conceptually true about objects?


Objects are true unless they define themself as false. The practical 
implication is we can do this:


def foo(args = None):
if args:
...

In python all objects are true except: None, False, 0/0L/0.0/0j, empty 
sequence or container, and on objects that defines .__len__() or 
.__nonzero__() that returns 0 or False.



'''
object.__bool__(self)
If a class defines neither __len__() nor __bool__(), all its instances
are considered true.
'''

This makes it so all objects except False, None, 0, and empty
containers are true by default.  I am not convinced that 'if a
generic object' should have any meaning; it should probably throw an
exception.  Is it part of Python's look and feel or its mentality?  Is
it part of the Zen?  Certainly other ideal types can't be cast from
generic objects, so why booleans?  Is it an ineffable component of the
author's vision for the language?  I think that giving arbitrary
syntactic constructs meaning is just space-filler.  It's worse than
syntactic sugar, it's semantic sugar.  Why not assign meanings willy-
nilly to other random juxtapositions of tokens?


It's part of the design decision. In almost all cases (in any language), 
a so-called Design Decision is rather random and prone to subjective 
judgment, just as the decision to make bool(int) returns False only on 
0, -1, or for all negative values; whether to make bool(100) and 
exception or True; or round() rounds down or up or even-odd; or the use 
of brackets vs. indentation; or whether to treat empty list as True or 
False.

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


Re: Why bool( object )?

2009-04-28 Thread Chris Rebert
On Mon, Apr 27, 2009 at 11:11 PM, Aaron Brady castiro...@gmail.com wrote:
 What is the rationale for considering all instances true of a user-
 defined type?  Is it strictly a practical stipulation, or is there
 something conceptually true about objects?

 '''
 object.__bool__(self)
 If a class defines neither __len__() nor __bool__(), all its instances
 are considered true.
 '''

 This makes it so all objects except False, None, 0, and empty
 containers are true by default.  I am not convinced that 'if a
 generic object' should have any meaning; it should probably throw an
 exception.  Is it part of Python's look and feel or its mentality?  Is
 it part of the Zen?  Certainly other ideal types can't be cast from
 generic objects, so why booleans?  Is it an ineffable component of the
 author's vision for the language?  I think that giving arbitrary
 syntactic constructs meaning is just space-filler.  It's worse than
 syntactic sugar, it's semantic sugar.  Why not assign meanings willy-
 nilly to other random juxtapositions of tokens?

I believe the justification is that in the case of objects with
otherwise undefined truth, it effectively serves as a test for
non-None-ness, which makes some sense and is apparently more useful in
practice than throwing an exception.
It was obviously a design decision made by the PSU, probably for
practicality over purity reasons; indeed, they could reasonably have
chose to make it throw an exception in such cases, but the current
behavior is also reasonable and justifiable.
For comparison, some other languages use a similar definition of truth
(if you can't show it's false, then it's true), such as Lisp/Scheme
and Ruby (if it's not equal to #f/false or nil, then it's true).
Admittedly, it's not a direct comparison since Python has fancier
semantics, but it's somewhat similar.

Cheers,
Chris
-- 
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why bool( object )?

2009-04-28 Thread Aaron Brady
On Apr 28, 1:35 am, Lie Ryan lie.1...@gmail.com wrote:
 Aaron Brady wrote:
  What is the rationale for considering all instances true of a user-
  defined type?  

 User-defined objects (or type) can override .__len__() [usually
 container types] or .__nonzero__() to make bool() returns False.

  Is it strictly a practical stipulation, or is there
  something conceptually true about objects?

 Objects are true unless they define themself as false. The practical
 implication is we can do this:

 def foo(args = None):
      if args:
          ...

 In python all objects are true except: None, False, 0/0L/0.0/0j, empty
 sequence or container, and on objects that defines .__len__() or
 .__nonzero__() that returns 0 or False.



  '''
  object.__bool__(self)
  If a class defines neither __len__() nor __bool__(), all its instances
  are considered true.
  '''

  This makes it so all objects except False, None, 0, and empty
  containers are true by default.  I am not convinced that 'if a
  generic object' should have any meaning; it should probably throw an
  exception.  Is it part of Python's look and feel or its mentality?  Is
  it part of the Zen?  Certainly other ideal types can't be cast from
  generic objects, so why booleans?  Is it an ineffable component of the
  author's vision for the language?  I think that giving arbitrary
  syntactic constructs meaning is just space-filler.  It's worse than
  syntactic sugar, it's semantic sugar.  Why not assign meanings willy-
  nilly to other random juxtapositions of tokens?

 It's part of the design decision. In almost all cases (in any language),
 a so-called Design Decision is rather random and prone to subjective
 judgment, just as the decision to make bool(int) returns False only on
 0, -1, or for all negative values; whether to make bool(100) and
 exception or True; or round() rounds down or up or even-odd; or the use
 of brackets vs. indentation; or whether to treat empty list as True or
 False.

Whether it's a good feature and whether it's a popular feature are two
different things.  (It's not always clear that the former is even real
anyway.)

I'm actually not sure that my question was /entirely/ scientifically
motivated.  Perhaps I'm expressing admiration (or maybe envy).  Maybe
I want to design a popular language too.

If I was really being scientific, I would have been wondering, what is
the balance of pros and cons of the decision?  pros - cons = ?  Is
that an objective expression?  Are there only measurable quantities in
both operands?  If it's a close call, I might not agree, or might not
have followed the same experimental method.

Trivially the answer is, 'the decision maker found sum( pros )  sum
( cons )'.  Many arts and disciplines do guesswork to a degree in
evaluating their 'sum( pros )', so perhaps I should expect a degree of
variation in what the experts all say that quantity is.

On a more idealist's level, perhaps I am asking the outside world
what /my/ evaluation of 'sum( pros )' is.  What's yours?

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


Re: Web based application development using python

2009-04-28 Thread Tim Hoffman
Calling mod_python a web framework is a bit of a stretch.

if you want to work at that level though mod_wsgi is worth a look,

on top of that you can put a range of frameworks such as
repose, django, turbo gears etc..

T


On Apr 28, 12:55 pm, Rahul r.warhe...@gmail.com wrote:
   2) I have my web based application written using mod_python
   a. It should be more based on framework type.
   b. It should have all the features present in mod_python.

  These two goals conflict.  You'll need to use your brain to discover
  what is best for your application.  In general have all the features
  of and but better conflict.

  --Scott David Daniels
  scott.dani...@acm.org

 hi scott,

 i am getting more specific, is there any web development framework
 better than mod python which is
 easy to maintain.

 thanks

 rahul

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


Re: Web based application development using python

2009-04-28 Thread Rahul
1) Do you have any idea about web based support (like mod_python)
provided by python.org (official web site)

Details: - As we know mod_python is used for embeding python code into
apache server.
so, i want to know whether mod_python is officially supported by
python.org or if there is
other such framework for embeding python on web server

Thanks,

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


Re: python segfaulting, MemoryError (PyQt)

2009-04-28 Thread Diez B. Roggisch

Denis L schrieb:

Hello,

I'm experiencing odd errors on both windows and linux with the following 
code:


import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Options(QDialog):
def __init__(self, values):
QDialog.__init__(self)

self.values = values

fooEdit = QLineEdit(values['foo'])
self.connect(fooEdit, SIGNAL('textChanged(QString)'),
 lambda value: self.optionChanged('foo', value))

barEdit = QLineEdit(values['bar'])
self.connect(barEdit, SIGNAL('textChanged(QString)'),
 lambda value: self.optionChanged('bar', value))

layout = QVBoxLayout()
layout.addWidget(fooEdit)
layout.addWidget(barEdit)

self.setLayout(layout)

def optionChanged(self, option, value):
self.values[option] = value
print self.values

def main(args):
app = QApplication(args)
values = dict(foo='', bar='')
dialog = Options(values)
dialog.show()
app.exec_()

if __name__ == '__main__':
main(sys.argv)


If I type a character in fooEdit, another character in barEdit, and then 
delete the character from barEdit I get an unhandled win32 exception occured 
in python.exe on windows and segfault on linux.


If I type a character in fooEdit, delete it, and then type a character in 
barEdit I get:


{'foo': PyQt4.QtCore.QString(u'a'), 'bar': ''}
{'foo': PyQt4.QtCore.QString(u''), 'bar': ''}
{'foo': Traceback (most recent call last):
  File L:\home\dev\python\test.py, line 17, in lambda
lambda value: self.optionChanged('bar', value))
  File L:\home\dev\python\test.py, line 27, in optionChanged
print self.values
MemoryError

I'm using Python 2.5.4 and PyQt 4.4.3-1


As the documentation of pyqt clearly states, connecting signals doesn't 
increment the refcount on a passed slot, thus

 you need to keep a reference to your slots around.

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


Re: Why bool( object )?

2009-04-28 Thread Steven D'Aprano
On Mon, 27 Apr 2009 23:11:11 -0700, Aaron Brady wrote:

 What is the rationale for considering all instances true of a user-
 defined type?  Is it strictly a practical stipulation, or is there
 something conceptually true about objects?

Seven years ago, in an attempt to convince Guido *not* to include 
booleans in Python, Laura Creighton wrote a long, detailed post 
explaining her opposition.

At the heart of her argument is the observation that Python didn't need 
booleans, at least not the ints-in-fancy-hats booleans that we've ended 
up with, because Python already made a far more useful and fundamental 
distinction: between Something and Nothing.

http://groups.google.com/group/comp.lang.python/msg/2de5e1c8384c0360?hl=en

All objects are either Something or Nothing. The instances of some 
classes are always Something, just as the instances of some classes are 
always Nothing. By default, instances are Something, unless __nonzero__ 
returns False, or __len__ returns 0, then they are Nothing.

In a boolean (or truth) context, Something and Nothing behave like True 
and False in languages with real booleans:

if obj:
print I am Something
else:
print I am Nothing


To steal an idiom from Laura: Python has a float-shaped Nothing 0.0, a 
list-shaped Nothing [], a dict-shaped Nothing {}, an int-shaped Nothing 
0, a singleton Nothing None, and so forth. It also has many corresponding 
Somethings.

All bool() does is convert Something or Nothing into a canonical form, 
the subclassed ints True and False.

I'm not sure whether Guido ever used the terms Something vs Nothing when 
describing Python's truth-testing model, but it is clearly there, at the 
heart of Python. Python didn't even get a boolean type until version 2.3.




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


Web framework for embedded system

2009-04-28 Thread Thomas Heller
I'm looking for a lightweight web-framework for an embedded system.
The system is running a realtime linux-variant on a 200 MHz ARM
processor, Python reports a performance of around 500 pystones.

The web application will not be too fancy, no databases involved
for example, but it will need to control some simple peripherals
(some parallel in/out, some dacs) attached to the system.

It should provide a user interface showing the current state and
allowing to manipulate it via a browser, and I will probably need
to support some rpc as well.

Does this sound sensible at all? Any suggestions?

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


sorted() erraticly fails to sort string numbers

2009-04-28 Thread uuid
I would be very interested in a logical explanation why this happens on 
python 2.5.1:


In order to sort an etree by the .text value of one child, I adapted 
this snippet from effbot.org:



import xml.etree.ElementTree as ET

tree = ET.parse(data.xml)

def getkey(elem):
return elem.findtext(number)

container = tree.find(entries)

container[:] = sorted(container, key=getkey)

tree.write(new-data.xml)


While working with a moderately sized xml file (2500 entries to sort 
by), I found that a few elements were not in order. It seems that 
numbers with seven digits were sorted correctly, while those with six 
digits were just added at the end.


I fixed the problem by converting the numbers to int in the callback:


def getkey(elem):
return int(elem.findtext(number))


So to my naive mind, it seems as if there was some error with the 
sorted() function. Would anyone be as kind as to explain why it could 
be happening? Thanks in advance!


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


Re: Presentation software for Python code

2009-04-28 Thread John Reid



Neal Becker wrote:

IPython offers something similar for giving demos. I've found that very
useful in the past.


Really?  Any pointers?


http://ipython.scipy.org/doc/manual/html/api/generated/IPython.demo.html

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


Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread Andre Engels
On Tue, Apr 28, 2009 at 9:47 AM, uuid m8r-r1c6...@mailinator.com wrote:
 I would be very interested in a logical explanation why this happens on
 python 2.5.1:

 In order to sort an etree by the .text value of one child, I adapted this
 snippet from effbot.org:

 import xml.etree.ElementTree as ET

 tree = ET.parse(data.xml)

 def getkey(elem):
    return elem.findtext(number)

 container = tree.find(entries)

 container[:] = sorted(container, key=getkey)

 tree.write(new-data.xml)

 While working with a moderately sized xml file (2500 entries to sort by), I
 found that a few elements were not in order. It seems that numbers with
 seven digits were sorted correctly, while those with six digits were just
 added at the end.

 I fixed the problem by converting the numbers to int in the callback:

 def getkey(elem):
    return int(elem.findtext(number))

 So to my naive mind, it seems as if there was some error with the sorted()
 function. Would anyone be as kind as to explain why it could be happening?
 Thanks in advance!

When sorting strings, including strings that represent numbers,
sorting is done alphabetically. In this alphabetical order the numbers
are all ordered the normal way, so two numbers with the same number of
digits will be sorted the same way, but any number starting with 1
will come before any number starting with 2, whether they denote
units, tens, hundreds or millions. Thus:

1  15999  16  2




-- 
André Engels, andreeng...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Memory leak on python 2.5 if using str(dict(a='a'))

2009-04-28 Thread Benjamin Liu
Hi, all.

I use guppy-pe to identify this issue in my program. The resources links are 
all embedded in source code already.

I developed a test case for your convenience and attached the log. Any gurus 
help out here? It's really python internal stuff which I can't easily peek into.

Thanks,
Benjamin

test_tuple_and_dict.py
Description: Binary data
TEST4
{'a': 'a_value', 'b': 'b_value'}
Partition of a set of 5 objects. Total size = 1064 bytes.
 Index  Count   % Size   % Cumulative  % Kind (class / dict of class)
 0  2  40  864  81   864  81 types.FrameType
 1  1  20  136  13  1000  94 dict (no owner)
 2  1  20   32   3  1032  97 list
 3  1  20   32   3  1064 100 str
=0=

Set of 2 types.FrameType objects. Total size = 864 bytes.
 Index Size   %   Cumulative  %   Name at Address
 0  448  51.9   448  51.9 heap at 0x822c2fc
 1  416  48.1   864 100.0 profileHeap at 0x824ddd4
--0--
frame object at 0x822c2fc
=1=

Set of 1 dict (no owner) object. Total size = 136 bytes.
 Index Size   %   Cumulative  %   Address*Length
 0  136 100.0   136 100.0 0x828b68c*1
--0--
{'Py_Repr': [{...}, [...]]}
=2=

Set of 1 list object. Total size = 32 bytes.
 Index Size   %   Cumulative  %   Address*Length
 0   32 100.032 100.0 0x826b58c*0
--0--
[[...]]
=3=

Set of 1 str object. Total size = 32 bytes.
 Index Size   %   Cumulative  %   Representation (limited)
 0   32 100.032 100.0 'Py_Repr'
--0--
Py_Repr
TEST5
a a_value
b b_value
Partition of a set of 2 objects. Total size = 736 bytes.
 Index  Count   % Size   % Cumulative  % Kind (class / dict of class)
 0  2 100  736 100   736 100 types.FrameType
=0=

Set of 2 types.FrameType objects. Total size = 736 bytes.
 Index Size   %   Cumulative  %   Name at Address
 0  372  50.5   372  50.5 profileHeap at 0x824fc94
 1  364  49.5   736 100.0 heap at 0x82edc04
--0--
frame object at 0x824fc94
TEST6
Partition of a set of 2 objects. Total size = 864 bytes.
 Index  Count   % Size   % Cumulative  % Kind (class / dict of class)
 0  2 100  864 100   864 100 types.FrameType
=0=

Set of 2 types.FrameType objects. Total size = 864 bytes.
 Index Size   %   Cumulative  %   Name at Address
 0  448  51.9   448  51.9 heap at 0x822c2fc
 1  416  48.1   864 100.0 profileHeap at 0x824ddd4
--0--
frame object at 0x822c2fc
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web based application development using python

2009-04-28 Thread Marco Mariani

Rahul wrote:


1) Do you have any idea about web based support (like mod_python)
provided by python.org (official web site)

Details: - As we know mod_python is used for embeding python code into
apache server.
so, i want to know whether mod_python is officially supported by
python.org or if there is
other such framework for embeding python on web server



Forget about mod_python, everything else is better.

This list (the first result upon googling for python web frameworks) 
is actually up to date, and a good start.


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

Just don't ask which one is best for everything, or which one is The 
Official Standard Way Of Doing Things.


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


Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread uuid
I am at the same time impressed with the concise answer and 
disheartened by my inability to see this myself.

My heartfelt thanks!


On 2009-04-28 10:06:24 +0200, Andre Engels andreeng...@gmail.com said:


When sorting strings, including strings that represent numbers,
sorting is done alphabetically. In this alphabetical order the numbers
are all ordered the normal way, so two numbers with the same number of
digits will be sorted the same way, but any number starting with 1
will come before any number starting with 2, whether they denote
units, tens, hundreds or millions. Thus:

1  15999  16  2



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


Re: python segfaulting, MemoryError (PyQt)

2009-04-28 Thread Phil Thompson
On Tue, 28 Apr 2009 03:53:34 +0200, Denis L n...@spam.com wrote:
 Hello,
 
 I'm experiencing odd errors on both windows and linux with the following 
 code:
 
 import sys
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 
 class Options(QDialog):
 def __init__(self, values):
 QDialog.__init__(self)
 
 self.values = values
 
 fooEdit = QLineEdit(values['foo'])
 self.connect(fooEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('foo', value))
 
 barEdit = QLineEdit(values['bar'])
 self.connect(barEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('bar', value))
 
 layout = QVBoxLayout()
 layout.addWidget(fooEdit)
 layout.addWidget(barEdit)
 
 self.setLayout(layout)
 
 def optionChanged(self, option, value):
 self.values[option] = value
 print self.values
 
 def main(args):
 app = QApplication(args)
 values = dict(foo='', bar='')
 dialog = Options(values)
 dialog.show()
 app.exec_()
 
 if __name__ == '__main__':
 main(sys.argv)
 
 
 If I type a character in fooEdit, another character in barEdit, and then 
 delete the character from barEdit I get an unhandled win32 exception
 occured 
 in python.exe on windows and segfault on linux.
 
 If I type a character in fooEdit, delete it, and then type a character in

 barEdit I get:
 
 {'foo': PyQt4.QtCore.QString(u'a'), 'bar': ''}
 {'foo': PyQt4.QtCore.QString(u''), 'bar': ''}
 {'foo': Traceback (most recent call last):
   File L:\home\dev\python\test.py, line 17, in lambda
 lambda value: self.optionChanged('bar', value))
   File L:\home\dev\python\test.py, line 27, in optionChanged
 print self.values
 MemoryError
 
 I'm using Python 2.5.4 and PyQt 4.4.3-1
 
 Thanks in advance for any help.

Works fine for me with current versions.

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


Re: python segfaulting, MemoryError (PyQt)

2009-04-28 Thread Phil Thompson
On Tue, 28 Apr 2009 09:35:31 +0200, Diez B. Roggisch
de...@nospam.web.de
wrote:
 Denis L schrieb:
 Hello,
 
 I'm experiencing odd errors on both windows and linux with the following

 code:
 
 import sys
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 
 class Options(QDialog):
 def __init__(self, values):
 QDialog.__init__(self)
 
 self.values = values
 
 fooEdit = QLineEdit(values['foo'])
 self.connect(fooEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('foo', value))
 
 barEdit = QLineEdit(values['bar'])
 self.connect(barEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('bar', value))
 
 layout = QVBoxLayout()
 layout.addWidget(fooEdit)
 layout.addWidget(barEdit)
 
 self.setLayout(layout)
 
 def optionChanged(self, option, value):
 self.values[option] = value
 print self.values
 
 def main(args):
 app = QApplication(args)
 values = dict(foo='', bar='')
 dialog = Options(values)
 dialog.show()
 app.exec_()
 
 if __name__ == '__main__':
 main(sys.argv)
 
 
 If I type a character in fooEdit, another character in barEdit, and then

 delete the character from barEdit I get an unhandled win32 exception
 occured
 in python.exe on windows and segfault on linux.
 
 If I type a character in fooEdit, delete it, and then type a character
in

 barEdit I get:
 
 {'foo': PyQt4.QtCore.QString(u'a'), 'bar': ''}
 {'foo': PyQt4.QtCore.QString(u''), 'bar': ''}
 {'foo': Traceback (most recent call last):
   File L:\home\dev\python\test.py, line 17, in lambda
 lambda value: self.optionChanged('bar', value))
   File L:\home\dev\python\test.py, line 27, in optionChanged
 print self.values
 MemoryError
 
 I'm using Python 2.5.4 and PyQt 4.4.3-1
 
 As the documentation of pyqt clearly states, connecting signals doesn't 
 increment the refcount on a passed slot, thus
   you need to keep a reference to your slots around.

But it does increase the refcount for lambda slots.

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


Re: python setup ?

2009-04-28 Thread Andreas Röhler
Xavier Maillard wrote:
 Hi

Xavier Maillard x...@gnu.org writes:

 I am starting to do some work with python. I am looking for
 options/setups to introduce into my .emacs file to have the best
 experience possible with this scripting language.

 Where should I start ?

I personnaly use python-mode.el that is much better than python.el (that
come with emacs).

 In what is it better ?

I use also ipython as python shell that integrate fine in emacs.

 Phew, how many new dependances should I install in order to have
 something simple to use ? :) I thought python was something for
 beginners, it is not. I find it easier to play lisp...

   Xavier
   
Hi Xavier,

as its well known, you are not a beginner with Emacs,
please permit to take your comment as occasion:

Your question and experience with Emacs and Python
reflects IMHO some general strength and likewise
present limitation.

The strength is, clearly: with that many files out
there, that many people who wrote already something for
python, with some Emacs Lisp knowledge you'll be able
to install a reasonable environment.

OTOH: how many people did that already, spent hours to
collect and adapt utilities from the net? And
afterwards? If we take together all this time from
users configuring an python-environment, we could
probably get more useful results from it. So there is a
lose of time.

Can we do better? ... :)

One thing, thats to realize IMO: times are gone where
one person with some knowledge of a language may write
a mode and thats it. Even maintaining it alone seems to
surpass any personal capacity. If we want to keep path,
we have to establish developer-groups caring for a
language. That happened already with C-modes AFAIS. We
need that for any major language.

Concerning python, we have enough man-power to
perform excellent things. To the extent, user have to do
`M-x python,' and an environment with all up-to-date
debugging facilities gets installed.

No question its great whats done at

http://www.emacswiki.org/emacs/PythonMode

Emacswiki was helpful many times for me.

However, for pure development issues, designed
platforms like Launchpad seem more suitable for the
purpose for me. Beside excellent bazaar behind, lets mention
its email- and bugreport integration.

As it happens we have with Barry Warsaw not just an
experienced Emacs Lisper, but a python core developer
with its python-mode account: we should try our chance
to proceed with his gentle help occasionally.

AFAIS we need tailored accounts, where we maintain
flavours of possible environments, learning and lifting
from each other, enabling distributions to select and
pull for delivering.

So far

Andreas

--
http://bazaar.launchpad.net/~a-roehler/python-mode/python-mode.el/
https://code.launchpad.net/s-x-emacs-werkstatt/



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


Re: Web framework for embedded system

2009-04-28 Thread Gerhard Häring
Thomas Heller wrote:
 I'm looking for a lightweight web-framework for an embedded system.
 The system is running a realtime linux-variant on a 200 MHz ARM
 processor, Python reports a performance of around 500 pystones.
 
 The web application will not be too fancy, no databases involved
 for example, but it will need to control some simple peripherals
 (some parallel in/out, some dacs) attached to the system.
 
 It should provide a user interface showing the current state and
 allowing to manipulate it via a browser, and I will probably need
 to support some rpc as well.
 
 Does this sound sensible at all? Any suggestions?

I'd try first what I know best. In my case Django. Despite the
restricted hardware, it might just work fine because you'll only use a
tiny fraction of it.

If this doesn't work because of CPU or memory requirements, I'd next try
to build my own using components like

- CherryPy for the web server, it should also be able to handle your
(XML)RPC requirements
- some templating language like Mako (my favourite)

It doesn't sound like you need much more.

You could even build upon wsgiref, string.Template and the XMLRPC stuff
in the standard library, but that's for people who like tinkering ;-)

-- Gerhard

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


Re: Lisp mentality vs. Python mentality

2009-04-28 Thread Dan Sommers
On Tue, 28 Apr 2009 02:00:22 -0300, namekuseijin wrote:

 Dan Sommers wrote:
 On Mon, 27 Apr 2009 07:57:00 +0300, Ciprian Dorin, Craciun wrote:
 I agree with your opinion about keeping the abstraction layers
 shallow, but in my view high-order and helper functions do not
 comprise a new abstraction layer. For example in Lisp, using map,
 reduce (fold), or any other high-order function is just like using
 for, or while in a normal imperative language.
 
 If I hit a call to map or to reduce, I've hit the bottom:  map and
 reduce are defined by Lisp and not by the programmer.
 
 You truly don't know Lisp.  *Everything* in Lisp can be _redefined_ and
 if you can't do something conveniently that way, you can use a _macro_
 to implement convenient new syntax for it.

Yes, I agree:  Python and Lisp are extremely dynamic languages.  I *can* 
redefine map, reduce, +, and other operators and functions, but I know 
better.  When is the last time you examined someone else's code, and 
asked them what their map function did (in Lisp or in Python)?





-- 
Dan Sommers   A death spiral goes clock-
http://www.tombstonezero.net/dan/   wise north of the equator.
Atoms are not things. -- Werner Heisenberg  -- Dilbert's PHB

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


Re: Restart generator when it is exhausted.

2009-04-28 Thread Chris Rebert
On Tue, Apr 28, 2009 at 2:54 AM, Lacrima lacrima.ma...@gmail.com wrote:
 Hello!

 I am quite new to Python and I have maybe simple (or maybe not)
 question.

 Is it possible to restart generator when it is exhausted?

No. You have to make a new instance of the generator.

 What should I do to get the initial state of g? So if I do again g.next
 () I receive 'a'.

g = (i for i in a) #that is, make a fresh generator instance

 If it is not possible what are common techniques to use iterator or
 generator objects that allow restarting when it is needed?

There's itertools.cycle() --
http://docs.python.org/library/itertools.html#itertools.cycle

Cheers,
Chris
-- 
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: mailbox.mbox.add() sets access time as well as modification time

2009-04-28 Thread tinnews
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote:
 In message jo2dnwpluopxvwjunz2dnuvz_qudn...@posted.usinternet, Grant 
 Edwards wrote:
 
  On 2009-04-26, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand
  wrote:
 
  In message _vqdnf6pny1gymzunz2dnuvz_qcdn...@posted.visi, Grant Edwards
  wrote:
 
  ... if one didn't care about backwards-compatiblity with old e-mail
  apps, then one would use a less broken mailbox format like
  maildir.
 
  It's only in the proprietary-software world that we need to worry about
  backward compatibility with old, obsolete software that the vendors
  cannot or will not fix. In the Free Software world, we fix the software
  to bring it up to date.
  
  Who's we?  Are you volunteering to fix all of the MUAs and
  MTAs out there that have mbox code in them that do follow the
  rules to make them compatible with _one_ broken library module?
 
 All the MUAs and MTAs I'm aware of that are worth bothering about have the 
 option to support maildir format these days.
 
Yes, but as I explained earlier in this thread there are reasons why
one might want to stay with mbox.  I use mutt which can quite happily
cope with either mbox or maildir (and some other formats), it can even
work with a mix of mailbox types.

I've used mutt for several years now and have tried to move to maildir
more than once and have always returned to mbox because the
disadvantages of maildir outweigh the benefits (for me).  Currently I
run mutt on a remote server where I have to use maildir because their
file systems are mounted noatime.  I am moving to reading mail on my
own Linux box just because I want to get back to mbox, this python
issue is about the only thing I have to overcome before I have what I
want. 

-- 
Chris Green

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


Using ascii numbers in regular expression

2009-04-28 Thread jorma kala
Hi,

How can I use the ascii number of a character in a regular expression
(module re) instead of the character itself?
Thanks very much
--
http://mail.python.org/mailman/listinfo/python-list


screen scraping with Python?

2009-04-28 Thread Meenakshi, Arun Kumar
Hi Friends,

Please let me know whether VT100 (Screen scrapping)
emulation is possible or not. If screen scrapping / VT100 emulation is
possible, please let me know how to do it. I will be happier, if you can
provide me steps and sample codes. I am a beginner in python. So kindly
help me by letting me know about the possibilities. EXPECTING THE REPLY
MAIL Thanks

 

Regards,

Arun

FoneNet : 390-13359

Mobile: 9884471702

 


This email and any attachments are confidential and may also be privileged.  If 
you are not the addressee, do not disclose, copy, circulate or in any other way 
use or rely on the information contained in this email or any attachments.  If 
received in error, notify the sender immediately and delete this email and any 
attachments from your system.  Emails cannot be guaranteed to be secure or 
error free as the message and any attachments could be intercepted, corrupted, 
lost, delayed, incomplete or amended.  Standard Chartered PLC and its 
subsidiaries do not accept liability for damage caused by this email or any 
attachments and may monitor email traffic.

 

Standard Chartered PLC is incorporated in England with limited liability under 
company number 966425 and has its registered office at 1 Aldermanbury Square, 
London, EC2V 7SB.

 

Standard Chartered Bank (SCB) is incorporated in England with limited 
liability by Royal Charter 1853, under reference ZC18.  The Principal Office of 
SCB is situated in England at 1 Aldermanbury Square, London EC2V 7SB. In the 
United Kingdom, SCB is authorised and regulated by the Financial Services 
Authority under FSA register number 114276.

 

If you are receiving this email from SCB outside the UK, please click 
http://www.standardchartered.com/global/email_disclaimer.html to refer to the 
information on other jurisdictions.

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


suggestion on a complicated inter-process communication

2009-04-28 Thread Way
Hello friends,

I have a little messy situation on IPC. Please if you can, give me
some suggestion on how to implement. Thanks a lot!

- denotes create


MainProcess - Process1 - Process3 (from os.system)
   |
- Process2 (from os.system) - Process4 (from
os.system) -Process5

I would like to make the communication between Process1 and Process5.
Process1 needs Process5's output to provide argument to generate
Process3, and in turn Process5 needs to wait Process3 finished.

Thank you very much if you can give a hint.

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


Re: python segfaulting, MemoryError (PyQt)

2009-04-28 Thread Phil Thompson
On Tue, 28 Apr 2009 11:18:31 +0200, Diez B. Roggisch
de...@nospam.web.de
wrote:
 As the documentation of pyqt clearly states, connecting signals doesn't
 increment the refcount on a passed slot, thus
   you need to keep a reference to your slots around.
 
 But it does increase the refcount for lambda slots.
 
 Has that changed? It has been a while, but I've been bitten by this
before,
 so I was pretty sure about my answer.

Support for lambda slots was add in PyQt v4.1.1 (released December 2006).

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


desperately looking for a howto on running my wxPython app on Vista

2009-04-28 Thread Paul Sijben
python 2.6, py2exe and Vista do not make a happy set.

Unfortunately I am in dire need to launch my app not only on WinXP but
also on Vista. I need 2.6 because of a number of support packages I am
using and some of which I am compiling myself (and python 2.5 needs a
version of visual studio that is no longer available.)

I can find all kinds of advice and discussions with google but I have
yet to find a clear explanation on what a poor developer like me is
supposed to do to get my python 2.6.2 , stackless, wxpython and all my
(self-built) pyds to work happily on Vista.

I am currently stuck on the infamous R6034 error but I understand that
after that there may be another issue with certain wxPython functions.

Can someone please point me to a howto on crafting the right Setup.py
and manifests etc. to make this work?

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


Python 2.6 ImportError: cannot import name SSLType

2009-04-28 Thread zerosumgame
I have built python 2.6.1 and 2.6.2 with ssl support (Redhat 3.4.6-9 /
Openssl 0.9.8j).

I am trying to use this with the Apache Qpid project but cannot bring
up an ssl connection because the code relies on socket.SSLType which
is missing from my build.  The only references to SSLType I can find
for python is that it is missing from the windows version which I am
not using.

I do not see what is going wrong.

Any tips greatly appreciated.

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


Re: screen scraping with Python?

2009-04-28 Thread David Lyon


On Mon, 27 Apr 2009 12:28:31 +0530, Meenakshi, Arun Kumar
arunkumar.meenak...@sc.com wrote:
 Hi Friends,
 
 Please let me know whether VT100 (Screen scrapping)
 emulation is possible or not. If screen scrapping / VT100 emulation is
 possible, please let me know how to do it. I will be happier, if you can
 provide me steps and sample codes. I am a beginner in python. So kindly
 help me by letting me know about the possibilities. EXPECTING THE REPLY
 MAIL Thanks

Of course...

VT-100 terminals were usually rs-232 devices connected at 9600 baud

If you can write some python code talking to the serial port, you can
easily read the data from the port... render it... and do whatever you
need...

If you are doing it over a network then you are using a terminal emulator.

Many of the top name termninal emulators provide a programming api.

If not.. go open source

There are just many.. many different ways these days... depending on
what platform and which terminal emulator you are using...

David

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


Restart generator when it is exhausted.

2009-04-28 Thread Lacrima
Hello!

I am quite new to Python and I have maybe simple (or maybe not)
question.

Is it possible to restart generator when it is exhausted?
For example:
 a = ['a', 'b', 'c']
 g = (i for i in a)
 g.next()
'a'
 g.next()
'b'
 g.next()
'c'
 g.next()
Traceback (most recent call last):
  File pyshell#31, line 1, in module
g.next()
StopIteration

What should I do to get the initial state of g? So if I do again g.next
() I receive 'a'.

If it is not possible what are common techniques to use iterator or
generator objects that allow restarting when it is needed?

With regards,
Max

(sorry if my English isn't very proper)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Restart generator when it is exhausted.

2009-04-28 Thread Lacrima
On Apr 28, 1:04 pm, Chris Rebert c...@rebertia.com wrote:
 On Tue, Apr 28, 2009 at 2:54 AM, Lacrima lacrima.ma...@gmail.com wrote:
  Hello!

  I am quite new to Python and I have maybe simple (or maybe not)
  question.

  Is it possible to restart generator when it is exhausted?

 No. You have to make a new instance of the generator.

  What should I do to get the initial state of g? So if I do again g.next
  () I receive 'a'.

 g = (i for i in a) #that is, make a fresh generator instance

  If it is not possible what are common techniques to use iterator or
  generator objects that allow restarting when it is needed?

 There's itertools.cycle() 
 --http://docs.python.org/library/itertools.html#itertools.cycle

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

Chris, thanks a lot for the help!
--
http://mail.python.org/mailman/listinfo/python-list


Efficient bits manipulation in Python

2009-04-28 Thread Li Wang
Hi:

I have a bit-code :'1011011', how can I reverse it to '1101101'?

Another question is I know how to transform the string '110' into
integer 6, does anyone know how to transform integer 6 to a string
'110'?

Thank you very much:)


-- 
Li
--
Time is all we have
and you may find one day
you have less than you think
--
http://mail.python.org/mailman/listinfo/python-list


RE: screen scraping with Python?

2009-04-28 Thread Meenakshi, Arun Kumar
David,

Thanks a ton for your swift reply. I will be more happy, if
you could direct me with right API with which I can walk further.

 

Regards,

Arun

FoneNet : 390-13359

Mobile: 9884471702

 

-Original Message-
From: David Lyon [mailto:david.l...@preisshare.net] 
Sent: Tuesday, April 28, 2009 4:52 PM
To: Meenakshi, Arun Kumar
Cc: python-list@python.org
Subject: Re: screen scraping with Python?

 

 

 

On Mon, 27 Apr 2009 12:28:31 +0530, Meenakshi, Arun Kumar

arunkumar.meenak...@sc.com wrote:

 Hi Friends,

 

 Please let me know whether VT100 (Screen scrapping)

 emulation is possible or not. If screen scrapping / VT100 emulation is

 possible, please let me know how to do it. I will be happier, if you
can

 provide me steps and sample codes. I am a beginner in python. So
kindly

 help me by letting me know about the possibilities. EXPECTING THE
REPLY

 MAIL Thanks

 

Of course...

 

VT-100 terminals were usually rs-232 devices connected at 9600 baud

 

If you can write some python code talking to the serial port, you can

easily read the data from the port... render it... and do whatever you

need...

 

If you are doing it over a network then you are using a terminal
emulator.

 

Many of the top name termninal emulators provide a programming api.

 

If not.. go open source

 

There are just many.. many different ways these days... depending on

what platform and which terminal emulator you are using...

 

David

 


This email and any attachments are confidential and may also be privileged.  If 
you are not the addressee, do not disclose, copy, circulate or in any other way 
use or rely on the information contained in this email or any attachments.  If 
received in error, notify the sender immediately and delete this email and any 
attachments from your system.  Emails cannot be guaranteed to be secure or 
error free as the message and any attachments could be intercepted, corrupted, 
lost, delayed, incomplete or amended.  Standard Chartered PLC and its 
subsidiaries do not accept liability for damage caused by this email or any 
attachments and may monitor email traffic.

 

Standard Chartered PLC is incorporated in England with limited liability under 
company number 966425 and has its registered office at 1 Aldermanbury Square, 
London, EC2V 7SB.

 

Standard Chartered Bank (SCB) is incorporated in England with limited 
liability by Royal Charter 1853, under reference ZC18.  The Principal Office of 
SCB is situated in England at 1 Aldermanbury Square, London EC2V 7SB. In the 
United Kingdom, SCB is authorised and regulated by the Financial Services 
Authority under FSA register number 114276.

 

If you are receiving this email from SCB outside the UK, please click 
http://www.standardchartered.com/global/email_disclaimer.html to refer to the 
information on other jurisdictions.

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


RE: screen scraping with Python?

2009-04-28 Thread Jean-Paul Calderone

On Tue, 28 Apr 2009 16:57:18 +0530, Meenakshi, Arun Kumar 
arunkumar.meenak...@sc.com wrote:

David,

   Thanks a ton for your swift reply. I will be more happy, if
you could direct me with right API with which I can walk further.



Twisted includes a vt102 API along with an in-memory emulator implementing
many (but not all) of the features of the terminal.  You can find the API
documentation online:

 http://twistedmatrix.com/documents/current/api/twisted.conch.insults.html

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


Re: Efficient bits manipulation in Python

2009-04-28 Thread Maxim Khitrov
On Tue, Apr 28, 2009 at 7:26 AM, Li Wang li.wan...@gmail.com wrote:
 Hi:

 I have a bit-code :'1011011', how can I reverse it to '1101101'?

 Another question is I know how to transform the string '110' into
 integer 6, does anyone know how to transform integer 6 to a string
 '110'?

 Thank you very much:)

Assuming that you are using 2.6:

a = 0b1011011
print bin(a)[:1:-1]

a = 6
print bin(a)[2:]

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


Re: Web based application development using python

2009-04-28 Thread Rahul
On Apr 28, 1:02 pm, Marco Mariani ma...@sferacarta.com wrote:
 Rahul wrote:
  1) Do you have any idea about web based support (like mod_python)
  provided by python.org (official web site)

  Details: - As we know mod_python is used for embeding python code into
  apache server.
  so, i want to know whether mod_python is officially supported by
  python.org or if there is
  other such framework for embeding python on web server

 Forget about mod_python, everything else is better.

 This list (the first result upon googling for python web frameworks)
 is actually up to date, and a good start.

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

 Just don't ask which one is best for everything, or which one is The
 Official Standard Way Of Doing Things.

but i want to know which is the official standard recommended by
python.
--
http://mail.python.org/mailman/listinfo/python-list


Unknown Visual C++ error

2009-04-28 Thread Stef Mientki




hello,

Anyone knows what this error message means ?

Python 2.5.2



thanks,
Stef


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


Re: Using ascii numbers in regular expression

2009-04-28 Thread jorma kala
Thanks very much for your reply.
What I mean is that I would like to use the ascii number in a regular
expression pattern.
For instance, if I want to substitute the occurrences of character 'a' for
the character 'b' in a string, instead of doing this:

re.subn('a','b','')

I'd like to specify the ascii number of a (which is 97)
I tried converting 97 to hexadecimal (with hex()) and tried this

re.subn(''\0x61,'b','')

but it doesnt work.
I need this because I'm working on non printable characters.

Thanks a lot



On Tue, Apr 28, 2009 at 12:45 PM, Chris Rebert c...@rebertia.com wrote:

  On Tue, Apr 28, 2009 at 4:05 AM, jorma kala jjk...@gmail.com wrote:
  Hi,
 
  How can I use the ascii number of a character in a regular expression
  (module re) instead of the character itself?
  Thanks very much

 I refer you to the chr() and ord() built-in functions, which can
 certainly be used to solve your problem, though they are not
 regex-specific in application.
 http://docs.python.org/library/functions.html

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

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


Re: Efficient bits manipulation in Python

2009-04-28 Thread Li Wang
 I have a bit-code :'1011011', how can I reverse it to '1101101'?

 Another question is I know how to transform the string '110' into
 integer 6, does anyone know how to transform integer 6 to a string
 '110'?

 Thank you very much:)

 Assuming that you are using 2.6:

 a = 0b1011011
 print bin(a)[:1:-1]

 a = 6
 print bin(a)[2:]

Thank you very much, that works:).


 - Max




-- 
Li
--
Time is all we have
and you may find one day
you have less than you think
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web based application development using python

2009-04-28 Thread Tim Hoffman
On Apr 28, 7:50 pm, Rahul r.warhe...@gmail.com wrote:
 On Apr 28, 1:02 pm, Marco Mariani ma...@sferacarta.com wrote:



  Rahul wrote:
   1) Do you have any idea about web based support (like mod_python)
   provided by python.org (official web site)

   Details: - As we know mod_python is used for embeding python code into
   apache server.
   so, i want to know whether mod_python is officially supported by
   python.org or if there is
   other such framework for embeding python on web server

  Forget about mod_python, everything else is better.

  This list (the first result upon googling for python web frameworks)
  is actually up to date, and a good start.

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

  Just don't ask which one is best for everything, or which one is The
  Official Standard Way Of Doing Things.

 but i want to know which is the official standard recommended by
 python.

But there isn't

There are a number of frameworks out there each with there own set of
strengths and weaknesses,  you shoul dbe
looking at each ones vibrancy (community), suitablility for your
application, etc...

T

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


Re: python segfaulting, MemoryError (PyQt)

2009-04-28 Thread Diez B. Roggisch
 As the documentation of pyqt clearly states, connecting signals doesn't
 increment the refcount on a passed slot, thus
   you need to keep a reference to your slots around.
 
 But it does increase the refcount for lambda slots.

Has that changed? It has been a while, but I've been bitten by this before,
so I was pretty sure about my answer.

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


Re: Why bool( object )?

2009-04-28 Thread Colin J. Williams

Lie Ryan wrote:

Aaron Brady wrote:

What is the rationale for considering all instances true of a user-
defined type?  


User-defined objects (or type) can override .__len__() [usually 
container types] or .__nonzero__() to make bool() returns False.



Is it strictly a practical stipulation, or is there
something conceptually true about objects?


Objects are true unless they define themself as false. The practical 
implication is we can do this:


def foo(args = None):
if args:
...

In python all objects are true except: None, False, 0/0L/0.0/0j, empty 
sequence or container, and on objects that defines .__len__() or 
..__nonzero__() that returns 0 or False.



'''
object.__bool__(self)
If a class defines neither __len__() nor __bool__(), all its instances
are considered true.
'''

This makes it so all objects except False, None, 0, and empty
containers are true by default.  I am not convinced that 'if a
generic object' should have any meaning; it should probably throw an
exception.  Is it part of Python's look and feel or its mentality?  Is
it part of the Zen?  Certainly other ideal types can't be cast from
generic objects, so why booleans?  Is it an ineffable component of the
author's vision for the language?  I think that giving arbitrary
syntactic constructs meaning is just space-filler.  It's worse than
syntactic sugar, it's semantic sugar.  Why not assign meanings willy-
nilly to other random juxtapositions of tokens?


It's part of the design decision. In almost all cases (in any language), 
a so-called Design Decision is rather random and prone to subjective 
judgment, just as the decision to make bool(int) returns False only on 
0, -1, or for all negative values; whether to make bool(100) and 
exception or True; or round() rounds down or up or even-odd; or the use 
of brackets vs. indentation; or whether to treat empty list as True or 
False.


I'm puzzled by the last sentence:

*** Python 2.6.2 (r262:71605, Apr 14 
2009, 22:40:02) [MSC v.1500 32 bit 
(Intel)] on win32. ***

bool(0)

False

bool(-1)

True

bool(-100)

True




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


Connecting/talking to OpenOffice Base files

2009-04-28 Thread deostroll
Hi,

I was wondering if the python interpretor can talk to files with
extension *.odb (OpenOffice Base files). They are like flat database
files, similar to Microsoft Access files. I want to store data into
them as well as extract data out of them.

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


Re: Using ascii numbers in regular expression

2009-04-28 Thread Chris Rebert
On Tue, Apr 28, 2009 at 4:58 AM, jorma kala jjk...@gmail.com wrote:
 Thanks very much for your reply.
 What I mean is that I would like to use the ascii number in a regular
 expression pattern.
 For instance, if I want to substitute the occurrences of character 'a' for
 the character 'b' in a string, instead of doing this:

 re.subn('a','b','')

 I'd like to specify the ascii number of a (which is 97)
 I tried converting 97 to hexadecimal (with hex()) and tried this

You should go the more direct route, as my function recommendation implied:

assert chr(97) == a
re.subn(chr(97),'b','')

Cheers,
Chris
-- 
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using ascii numbers in regular expression

2009-04-28 Thread Chris Rebert
On Tue, Apr 28, 2009 at 4:05 AM, jorma kala jjk...@gmail.com wrote:
 Hi,

 How can I use the ascii number of a character in a regular expression
 (module re) instead of the character itself?
 Thanks very much

I refer you to the chr() and ord() built-in functions, which can
certainly be used to solve your problem, though they are not
regex-specific in application.
http://docs.python.org/library/functions.html

Cheers,
Chris
-- 
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why bool( object )?

2009-04-28 Thread Lawrence D'Oliveiro
In message 54cb7f8a-
fef4-4bf8-8054-16dc9b5c8...@d2g2000pra.googlegroups.com, Aaron Brady wrote:

 What is the rationale for considering all instances true of a user-
 defined type?

It's a stupid idea, and there seem to be instances of users tripping over it 
here in comp.lang.python every week.

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


Re: The whole story

2009-04-28 Thread andrew cooke
Paul Hemans wrote:
 Hi Andrew,
 The reason I am using mapped objects is that I need to abstract from the
 database implementation allowing the replication to target a number of
 different platforms. This will definitely slow things down.

have you looked at sqlalchemy's generic sql support?  you can construct
sql statements using python classes/functions called select, update
etc and sqlalchemy automatically makes things work with different database
implementations.  it's not perfect, but i have the same code working with
mysql and oracle, which covers quite a range :o)

 process a whole pile in memory and then (perhaps every 10,000 - when
 your
 memory is about to run out and start paging) flush the session.
 Under windows how can I tell when memory is about to run out? I guess
 there
 is no cross-platform solution to this.

i don't know, sorry.

 Writing external files has all come about from a post titled Memory
 problems (garbage collection) by Carbon Man which I never got a
 resolution
 to.
 I was trying to execute gc.collect() when a process was complete because I
 was having huge problems with memory (though the problem still remains).
 If
 I stop at import schema There are 2524104 objects processed by
 gc.collect()

you shouldn't need to call gc.collect().

when you write everything out to the database, if you have no other
references to the objects, python will clean them up automatically. 
calling gc.collect() won't make any difference - python's gc already works
just fine.

if your memory use isn't going down then either (1) you are not writing
out/flushing correctly (if you want i can check my code later today and
tell you exactly what i do) or you are keeping references to your objects
elsewhere (eg in a dictionary in the code you use to construct them).

andrew


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


Re: Restart generator when it is exhausted.

2009-04-28 Thread Duncan Booth
Lacrima lacrima.ma...@gmail.com wrote:

 If it is not possible what are common techniques to use iterator or
 generator objects that allow restarting when it is needed?

The usual thing if you want to use the generator's output more than once  
would be to convert the generator to a list, then you can iterate over it 
as often as you want.

 a = ['a', 'b', 'c']
 g = (i for i in a)
 restartable = list(g)

If you want the output of the generator to potentially change each time you 
iterate then you need to create a new generator.

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why bool( object )?

2009-04-28 Thread Andre Engels
On Tue, Apr 28, 2009 at 2:22 PM, Colin J. Williams c...@ncf.ca wrote:
 Lie Ryan wrote:

 Aaron Brady wrote:

 What is the rationale for considering all instances true of a user-
 defined type?

 User-defined objects (or type) can override .__len__() [usually container
 types] or .__nonzero__() to make bool() returns False.

 Is it strictly a practical stipulation, or is there
 something conceptually true about objects?

 Objects are true unless they define themself as false. The practical
 implication is we can do this:

 def foo(args = None):
    if args:
        ...

 In python all objects are true except: None, False, 0/0L/0.0/0j, empty
 sequence or container, and on objects that defines .__len__() or
 ..__nonzero__() that returns 0 or False.

 '''
 object.__bool__(self)
 If a class defines neither __len__() nor __bool__(), all its instances
 are considered true.
 '''

 This makes it so all objects except False, None, 0, and empty
 containers are true by default.  I am not convinced that 'if a
 generic object' should have any meaning; it should probably throw an
 exception.  Is it part of Python's look and feel or its mentality?  Is
 it part of the Zen?  Certainly other ideal types can't be cast from
 generic objects, so why booleans?  Is it an ineffable component of the
 author's vision for the language?  I think that giving arbitrary
 syntactic constructs meaning is just space-filler.  It's worse than
 syntactic sugar, it's semantic sugar.  Why not assign meanings willy-
 nilly to other random juxtapositions of tokens?

 It's part of the design decision. In almost all cases (in any language), a
 so-called Design Decision is rather random and prone to subjective
 judgment, just as the decision to make bool(int) returns False only on 0,
 -1, or for all negative values; whether to make bool(100) and exception or
 True; or round() rounds down or up or even-odd; or the use of brackets vs.
 indentation; or whether to treat empty list as True or False.

 I'm puzzled by the last sentence:

 *** Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
 (Intel)] on win32. ***

 bool(0)

 False

 bool(-1)

 True

 bool(-100)

 True


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


bool has been defined thus in Python:

False are:
* False
* None
* empty containers, lists etc.
* The number zero

Everything else is true.

-100 is not equal to zero, so its boolean value is True.



-- 
André Engels, andreeng...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Connecting/talking to OpenOffice Base files

2009-04-28 Thread Krishnakant
hi,
On Tue, 2009-04-28 at 05:24 -0700, deostroll wrote:
 Hi,
 
 I was wondering if the python interpretor can talk to files with
 extension *.odb (OpenOffice Base files). They are like flat database
 files, similar to Microsoft Access files. I want to store data into
 them as well as extract data out of them.
 
This is done either  using ooolib if you want to do some simple read and
write tasks or then use odfpy which is a complete library.

I had asked the same question a few months back and come from the same
path you are coming.

But odfpy was initially difficult for me and would take a while to
understand.
It is a kind of wrapper around the xml structure of an odf document.

happy hacking.
Krishnakant.

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

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


[ANN] pyOpenSSL 0.9

2009-04-28 Thread Jean-Paul Calderone

I'm happy to announce the release of pyOpenSSL 0.9. This release includes
several new features and a very important bug fix:

 * APIs have been introduced to get and set the version of an X509 request
 * Contexts now support loading CA certificates for verification from a
   specified directory or from the platform's default certificate store
 * DTLS-related constants, OP_NO_QUERY_MTU, OP_COOKIE_EXCHANGE, and
   OP_NO_TICKET are now exposed
 * X509Extension now has the `get_short_name´ method for retrieving the
   short form of the extension type
 * It is now possible to create extensions which use any of the three
   possible OpenSSL implementation approaches
 * FILETYPE_TEXT can be used to dump keys, certificate, and CSRs in text
   format
 * Various compiler warnings have been fixed
 * A bug triggered by almost all uses of pyOpenSSL from multiple threads
   and leading to a crash has been fixed

Many thanks to numerous people who contributed patches to this release.

You can find pyOpenSSL 0.9 in the downloads area of the SourceForge project
page:

   https://sourceforge.net/project/showfiles.php?group_id=31249

Please use Launchpad to file any bug reports:

   https://bugs.launchpad.net/pyopenssl

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


Re: Is there a maximum size to a Python program?

2009-04-28 Thread Paul Boddie
On 27 Apr, 05:01, Carbon Man dar...@nowhere.com wrote:
 I have a program that is generated from a generic process. It's job is to
 check to see whether records (replicated from another system) exist in a
 local table, and if it doesn't, to add them. I have 1 of these programs for
 every table in the database.

Some people have discussed whether you need one or many programs. In
practice, you're going to need to execute many tasks to process all
your tables, and potentially this could mean generating many SQL
statements, as I will describe below.

[...]

 I am thinking that dynamically generating the programs to run might not be
 such a good idea. It would be a shame to drop it because the system needs to
 be generic and it runs from an XML file so the resulting code could be
 pretty complex, and I am new to Python. The program did generate a pyc so it
 was able to compile.
 Thoughts anyone?

This problem sounds as if it could be solved adequately using only the
database system, although I accept that sometimes some logic or
additional processing could be done in Python. If I were to receive
updates from a system, presumably as files, I'd want to bulk copy them
into the database and then perform the necessary inserts using SQL. If
the raw updates were not directly compatible with the database,
perhaps because data representations might differ, then I would want
to process them before doing the bulk copy.

In other words, the workflow for a single table would look like this:

 1. Obtain update files.
 2. Process files in order to make the data compatible with the
database.
 3. Create temporary tables for the updates in the database.
 4. Bulk copy the files into the temporary tables (using COPY or LOAD
DATA commands).
 5. Do the necessary inserts (where you have to either use the non-
standard
INSERT OR UPDATE or an INSERT involving a join between existing
and temporary tables).
 6. Drop the temporary tables (if not done automatically).

Now, it's almost certain that the details of the above workflow would
vary from table to table and from update to update. Even in the case
where you don't have to process the files, you still need to copy the
files into the database and to work with a different table each time.
This is where generating something for each table is unavoidable,
and one solution might be to have a generic template and to substitute
the table name and update filename into that template as you process
each table and its associated data. Whether you actually generate an
SQL command file for each table, or whether you have a program issue
the commands directly, is a matter of preference.

Anyway, from what you've described, that's how I would approach this
problem. Certainly, it's a lot more straightforward than dealing with
object-relational abstractions in programs generated by other
programs.

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


Re: Web framework for embedded system

2009-04-28 Thread bobicanprogram
On Apr 28, 3:43 am, Thomas Heller thel...@python.net wrote:
 I'm looking for a lightweight web-framework for an embedded system.
 The system is running a realtime linux-variant on a 200 MHz ARM
 processor, Python reports a performance of around 500 pystones.

 The web application will not be too fancy, no databases involved
 for example, but it will need to control some simple peripherals
 (some parallel in/out, some dacs) attached to the system.

 It should provide a user interface showing the current state and
 allowing to manipulate it via a browser, and I will probably need
 to support some rpc as well.

 Does this sound sensible at all? Any suggestions?

 Thomas


You should definitely check out the SIMPL toolkit (http://
www.icanprogram.com/simpl).  We have used this ultra lightweight
toolkit in several embedded Linux projects.   It will allow you to
seamlessly connect your Python bits with bits more appropriately
written in other languages like C.

There is a hello world level tutorial on the Python-SIMPL
capabilities (which includes a web CGI interface) at:

http://www.icanprogram.com/06py/main.html

If you have any questions about our SIMPL experiences don't hesitate
to ask.

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


Re: python segfaulting, MemoryError (PyQt)

2009-04-28 Thread Denis L
Phil Thompson p...@riverbankcomputing.com wrote in message 
news:mailman.4664.1240907352.11746.python-l...@python.org...
 On Tue, 28 Apr 2009 03:53:34 +0200, Denis L n...@spam.com wrote:
 Hello,

 I'm experiencing odd errors on both windows and linux with the following
 code:

 import sys
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *

 class Options(QDialog):
 def __init__(self, values):
 QDialog.__init__(self)

 self.values = values

 fooEdit = QLineEdit(values['foo'])
 self.connect(fooEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('foo', value))

 barEdit = QLineEdit(values['bar'])
 self.connect(barEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('bar', value))

 layout = QVBoxLayout()
 layout.addWidget(fooEdit)
 layout.addWidget(barEdit)

 self.setLayout(layout)

 def optionChanged(self, option, value):
 self.values[option] = value
 print self.values

 def main(args):
 app = QApplication(args)
 values = dict(foo='', bar='')
 dialog = Options(values)
 dialog.show()
 app.exec_()

 if __name__ == '__main__':
 main(sys.argv)


 If I type a character in fooEdit, another character in barEdit, and then
 delete the character from barEdit I get an unhandled win32 exception
 occured
 in python.exe on windows and segfault on linux.

 If I type a character in fooEdit, delete it, and then type a character in

 barEdit I get:

 {'foo': PyQt4.QtCore.QString(u'a'), 'bar': ''}
 {'foo': PyQt4.QtCore.QString(u''), 'bar': ''}
 {'foo': Traceback (most recent call last):
   File L:\home\dev\python\test.py, line 17, in lambda
 lambda value: self.optionChanged('bar', value))
   File L:\home\dev\python\test.py, line 27, in optionChanged
 print self.values
 MemoryError

 I'm using Python 2.5.4 and PyQt 4.4.3-1

 Thanks in advance for any help.

 Works fine for me with current versions.

 Phil

I have noticed that if I do self.values[option] = QString(value)
instead of self.values[option] = value in optionChanged I don't get any 
errors.

Is it perhaps not safe to keep the reference to the lambda QString argument? 


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


Getting the dir from the other ancestor ?

2009-04-28 Thread Stef Mientki

hello,

I have a class, derived from some user defined class 
(User_Defined_Ancestor) and some basic class (Basic_Ancestor).


One of the major tasks of the Basic_Ancestor,
is to hide all kinds of implementation details for the user,
so the user can concentrate on the functional design.

One of things I need to know are the methods and attributes of the 
Basic_Ancestor.

Both classes are dynamic, i.e. attributes are added during run time.

class Master ( User_Defined_Ancestor, Basic_Ancestor ) :
   def __init__ ( self, *args, **kwargs ) :
   Basic_Ancestor.__init__ ( self, *args, **kwargs )
   .

class Basic_Ancestor ( object ) :
   def __init__ ( self,  ) :
   self.other = dir ( User_Defined_Ancestor )

   def Get_Attributes ( self ) :
   return dir ( self ) - dir ( self.other )


Now the problem is, I don't know User_Defined_Ancestor in Basic_Ancestor.
I can't pass it through the parameter list, because I use *args, **kwargs
I possibly could use some global variable, but that's not my preference.

Any other suggestions ?

thanks,
Stef Mientki


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


Re: Getting the dir from the other ancestor ?

2009-04-28 Thread tuxagb
On 28 Apr, 15:01, Stef Mientki stef.mien...@gmail.com wrote:
 hello,

 I have a class, derived from some user defined class
 (User_Defined_Ancestor) and some basic class (Basic_Ancestor).

 One of the major tasks of the Basic_Ancestor,
 is to hide all kinds of implementation details for the user,
 so the user can concentrate on the functional design.

 One of things I need to know are the methods and attributes of the
 Basic_Ancestor.
 Both classes are dynamic, i.e. attributes are added during run time.

 class Master ( User_Defined_Ancestor, Basic_Ancestor ) :
     def __init__ ( self, *args, **kwargs ) :
         Basic_Ancestor.__init__ ( self, *args, **kwargs )
         .

 class Basic_Ancestor ( object ) :
     def __init__ ( self,  ) :
         self.other = dir ( User_Defined_Ancestor )

     def Get_Attributes ( self ) :
         return dir ( self ) - dir ( self.other )

 Now the problem is, I don't know User_Defined_Ancestor in Basic_Ancestor.
 I can't pass it through the parameter list, because I use *args, **kwargs
 I possibly could use some global variable, but that's not my preference.

 Any other suggestions ?

 thanks,
 Stef Mientki

In anytime, if you do dir() in a class B, that extends a class A, you
have all fields of A also.

Example:

 class A:
...def a(self):
...return 0
 class B(A):
...def b(self):
...return 5
 dir(A)
[., 'a']
 dir(B)
[.., 'a', 'b']

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


Re: mailbox.mbox.add() sets access time as well as modification time

2009-04-28 Thread Grant Edwards
On 2009-04-27, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote:
 In message gt3a7k$8d...@panix3.panix.com, Aahz wrote:

 In article gt0f2d$t5...@lust.ihug.co.nz,
 Lawrence D'Oliveiro  l...@geek-central.gen.new_zealand wrote:

It's only in the proprietary-software world that we need to worry about
backward compatibility with old, obsolete software that the vendors
cannot or will not fix. In the Free Software world, we fix the software
to bring it up to date.
 
 Are you volunteering to maintain trn3.6?

 Either there are enough people using it to care about it, in which case 
 somebody in the community will fix it, it or there are not, in which case
 it's not worth bothering with.

Except _it's_not_broken_.  It follows the established set of
rules for manipulating mbox mailboxes. It follows the set of
rules that all other mbox MUAs and MTAs use.  Python's library
is not following the rules, and your response is that the rest
of the world should change?

-- 
Grant Edwards   grante Yow! GOOD-NIGHT, everybody
  at   ... Now I have to go
   visi.comadminister FIRST-AID to my
   pet LEISURE SUIT!!
--
http://mail.python.org/mailman/listinfo/python-list


Re: mailbox.mbox.add() sets access time as well as modification time

2009-04-28 Thread Grant Edwards
On 2009-04-27, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote:

 Who's we?  Are you volunteering to fix all of the MUAs and
 MTAs out there that have mbox code in them that do follow the
 rules to make them compatible with _one_ broken library
 module?

 All the MUAs and MTAs I'm aware of that are worth bothering
 about have the option to support maildir format these days.

That sure seems like a rather unhelpful response when somebody
finds a bug in the standard library:

 1) Don't use that module.
 
 2) Change the rest of the world to work around Python's bug.

-- 
Grant Edwards   grante Yow! I've got an IDEA!!
  at   Why don't I STARE at you
   visi.comso HARD, you forget your
   SOCIAL SECURITY NUMBER!!
--
http://mail.python.org/mailman/listinfo/python-list


Re: python segfaulting, MemoryError (PyQt)

2009-04-28 Thread Phil Thompson
On Tue, 28 Apr 2009 14:54:41 +0200, Denis L n...@spam.com wrote:
 Phil Thompson p...@riverbankcomputing.com wrote in message 
 news:mailman.4664.1240907352.11746.python-l...@python.org...
 On Tue, 28 Apr 2009 03:53:34 +0200, Denis L n...@spam.com wrote:
 Hello,

 I'm experiencing odd errors on both windows and linux with the
following
 code:

 import sys
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *

 class Options(QDialog):
 def __init__(self, values):
 QDialog.__init__(self)

 self.values = values

 fooEdit = QLineEdit(values['foo'])
 self.connect(fooEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('foo', value))

 barEdit = QLineEdit(values['bar'])
 self.connect(barEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('bar', value))

 layout = QVBoxLayout()
 layout.addWidget(fooEdit)
 layout.addWidget(barEdit)

 self.setLayout(layout)

 def optionChanged(self, option, value):
 self.values[option] = value
 print self.values

 def main(args):
 app = QApplication(args)
 values = dict(foo='', bar='')
 dialog = Options(values)
 dialog.show()
 app.exec_()

 if __name__ == '__main__':
 main(sys.argv)


 If I type a character in fooEdit, another character in barEdit, and
then
 delete the character from barEdit I get an unhandled win32 exception
 occured
 in python.exe on windows and segfault on linux.

 If I type a character in fooEdit, delete it, and then type a character
 in

 barEdit I get:

 {'foo': PyQt4.QtCore.QString(u'a'), 'bar': ''}
 {'foo': PyQt4.QtCore.QString(u''), 'bar': ''}
 {'foo': Traceback (most recent call last):
   File L:\home\dev\python\test.py, line 17, in lambda
 lambda value: self.optionChanged('bar', value))
   File L:\home\dev\python\test.py, line 27, in optionChanged
 print self.values
 MemoryError

 I'm using Python 2.5.4 and PyQt 4.4.3-1

 Thanks in advance for any help.

 Works fine for me with current versions.

 Phil
 
 I have noticed that if I do self.values[option] = QString(value)
 instead of self.values[option] = value in optionChanged I don't get any

 errors.
 
 Is it perhaps not safe to keep the reference to the lambda QString
 argument? 

It shouldn't make any difference.

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


Re: Using ascii numbers in regular expression

2009-04-28 Thread MRAB

jorma kala wrote:

Thanks very much for your reply.
What I mean is that I would like to use the ascii number in a regular 
expression pattern.
For instance, if I want to substitute the occurrences of character 'a' 
for the character 'b' in a string, instead of doing this:
 
re.subn('a','b','')
 
I'd like to specify the ascii number of a (which is 97)

I tried converting 97 to hexadecimal (with hex()) and tried this
 
re.subn(''\0x61,'b','')
 
but it doesnt work.

I need this because I'm working on non printable characters.
 

[snip]
You're almost there:

re.subn('\x61','b','')

or better yet:

re.subn(r'\x61','b','')
--
http://mail.python.org/mailman/listinfo/python-list


Re: python segfaulting, MemoryError (PyQt)

2009-04-28 Thread Diez B. Roggisch
Phil Thompson wrote:

 On Tue, 28 Apr 2009 11:18:31 +0200, Diez B. Roggisch
 de...@nospam.web.de
 wrote:
 As the documentation of pyqt clearly states, connecting signals doesn't
 increment the refcount on a passed slot, thus
   you need to keep a reference to your slots around.
 
 But it does increase the refcount for lambda slots.
 
 Has that changed? It has been a while, but I've been bitten by this
 before,
 so I was pretty sure about my answer.
 
 Support for lambda slots was add in PyQt v4.1.1 (released December 2006).

Unfortunately after I had the chance to play with PyQt for the last time.
Thanks for clarifying!

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


Query related to matplotlib

2009-04-28 Thread srinivasan srinivas

I would like to draw a chart which takes 'dates' in x axes and some values in y 
axes.  
I would like to draw a simple chart using matplotlib. Can someone tell me which 
submodule i could use for this purpose? The module has to support in the way 
that i can draw more than one set can be passed to Y axes. So it will generate 
more than one line.

Thanks,
Srini



  Now surf faster and smarter ! Check out the new Firefox 3 - Yahoo! 
Edition http://downloads.yahoo.com/in/firefox/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help AIX 5.3 build on Python-3.1a2

2009-04-28 Thread Jeroen Ruigrok van der Werven
-On [20090427 20:31], prueba...@latinmail.com (prueba...@latinmail.com) wrote:
./Modules/ld_so_aix xlc_r -q64 -bI:Modules/python.exp build/
temp.aix-5.3-3.1//ptst/Python-3.1a2/Modules/_tkinter.o build/
temp.aix-5.3-3.1//ptst/Python-3.1a2/Modules/tkappinit.o -L/usr/X11R6/
lib64 -L/usr/X11R6/lib -L/usr/local/lib -ltk8.3 -ltcl8.3 -lX11 -o
build/lib.aix-5.3-3.1/_tkinter.so
ld: 0706-006 Cannot find or open library file: -l tk8.3
ld:open(): A file or directory in the path name does not
exist.

Well, do you have TK installed? It seems so, but are the paths passed to the
compiler/linker correct (-L) for locating libtk8.3.so?

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Time is a twofold teacher, harsh and yet patient like no-one...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web based application development using python

2009-04-28 Thread Rahul
On Apr 28, 5:07 pm, Tim Hoffman zutes...@gmail.com wrote:
 On Apr 28, 7:50 pm, Rahul r.warhe...@gmail.com wrote:



  On Apr 28, 1:02 pm, Marco Mariani ma...@sferacarta.com wrote:

   Rahul wrote:
1) Do you have any idea about web based support (like mod_python)
provided by python.org (official web site)

Details: - As we know mod_python is used for embeding python code into
apache server.
so, i want to know whether mod_python is officially supported by
python.org or if there is
other such framework for embeding python on web server

   Forget about mod_python, everything else is better.

   This list (the first result upon googling for python web frameworks)
   is actually up to date, and a good start.

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

   Just don't ask which one is best for everything, or which one is The
   Official Standard Way Of Doing Things.

  but i want to know which is the official standard recommended by
  python.

 But there isn't

 There are a number of frameworks out there each with there own set of
 strengths and weaknesses,  you shoul dbe
 looking at each ones vibrancy (community), suitablility for your
 application, etc...

 T

 T

Thanks tim
This information was really of help to me
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web framework for embedded system

2009-04-28 Thread Suraj Barkale
Thomas Heller theller at python.net writes:
 
 I'm looking for a lightweight web-framework for an embedded system.
 The system is running a realtime linux-variant on a 200 MHz ARM
 processor, Python reports a performance of around 500 pystones.

You can start with webpy (http://webpy.org/) and build up from there.

 
 The web application will not be too fancy, no databases involved
 for example, but it will need to control some simple peripherals
 (some parallel in/out, some dacs) attached to the system.
 
 It should provide a user interface showing the current state and
 allowing to manipulate it via a browser, and I will probably need
 to support some rpc as well.
 
 Does this sound sensible at all? Any suggestions?

I don't know how Python will affect the real-time tasks your system is
performing. You may want to look at a web framework in C (e.g.
http://www.koanlogic.com/klone/index.html).
Regards,
Suraj


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


Re: Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread John Posner

uuid wrote:
I am at the same time impressed with the concise answer and 
disheartened by my inability to see this myself.

My heartfelt thanks!
Don't be disheartened! Many people -- myself included, absolutely! -- 
occasionally let a blind spot show in their messages to this list. BTW:


   container[:] = sorted(container, key=getkey)

... is equivalent to:

   container.sort(key=getkey)

(unless I'm showing *my* blind spot here)

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


How to locate the bit in bits string?

2009-04-28 Thread Li Wang
Hi:

If I use an integer to represent bits:
e.g. 99 represents '1100011'

How can I locate, say the second bit of 99(i.e. '1')?

Although bin(99)[4] could be used to locate it, this transform cost
too much memory (99 only needs 2Bytes, while string '1100011' needs
7Bytes).

Anyone knows how to locate  the second bit without using bin() function?

Thank you very much:D

-- 
Li
--
Time is all we have
and you may find one day
you have less than you think
--
http://mail.python.org/mailman/listinfo/python-list


Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread uuid

On 2009-04-28 16:18:43 +0200, John Posner jjpos...@snet.net said:

Don't be disheartened! Many people -- myself included, absolutely! -- 
occasionally let a blind spot show in their messages to this list.


Thanks for the encouragement :)


BTW:

container[:] = sorted(container, key=getkey)

... is equivalent to:

container.sort(key=getkey)

(unless I'm showing *my* blind spot here)


I don't think etree element objects support the .sort method.
At least in lxml they don't 
(http://codespeak.net/lxml/api/elementtree.ElementTree.Element-class.html) 



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


Re: Best way to evaluate boolean expressions from strings?

2009-04-28 Thread Gustavo Narea
Thank you very much,  Gabriela and Peter!

I'm going for Pyparsing. :)

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


Re: How to locate the bit in bits string?

2009-04-28 Thread Tim Chase

Li Wang wrote:

Hi:

If I use an integer to represent bits:
e.g. 99 represents '1100011'

How can I locate, say the second bit of 99(i.e. '1')?

Although bin(99)[4] could be used to locate it, this transform cost
too much memory (99 only needs 2Bytes, while string '1100011' needs
7Bytes).

Anyone knows how to locate  the second bit without using bin() function?


You mean

  def get_bit(number, bit):
return (number  bit)  1

?

-tkc




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


Third Party Modules

2009-04-28 Thread Brock
Hi Everyone,

I know this is most likely a basic question and you will roll your
eyes, but I am just starting out with Python (hobbyist) and I see many
tutorials on the web referring to the use of external modules.

However, when I locate them, they often come as a zipped folder with a
number of files.  How do I install them?  In addition, is there an
easy way to manage external modules? Some I see require additional
modules not included.

Where I am coming from is R, which has a point-and-click way of
getting packages not distributed with the version of the software, so
that is my point of reference.

Many thanks!

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


What do you think of ShowMeDo

2009-04-28 Thread Astley Le Jasper
Hi,

I've just stumbled over this (http://showmedo.com/) and being the very
visual person I am, it seems like it could be a good way to learn
about python. However, before I smack down $60, I wondered if anyone
had any opinions on it. My gut feel is that it could be pretty good.

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


Re: python segfaulting, MemoryError (PyQt)

2009-04-28 Thread Denis L

Phil Thompson p...@riverbankcomputing.com wrote in message 
news:mailman.4690.1240925876.11746.python-l...@python.org...
 On Tue, 28 Apr 2009 14:54:41 +0200, Denis L n...@spam.com wrote:
 Phil Thompson p...@riverbankcomputing.com wrote in message
 news:mailman.4664.1240907352.11746.python-l...@python.org...
 On Tue, 28 Apr 2009 03:53:34 +0200, Denis L n...@spam.com wrote:
 Hello,

 I'm experiencing odd errors on both windows and linux with the
 following
 code:

 import sys
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *

 class Options(QDialog):
 def __init__(self, values):
 QDialog.__init__(self)

 self.values = values

 fooEdit = QLineEdit(values['foo'])
 self.connect(fooEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('foo', value))

 barEdit = QLineEdit(values['bar'])
 self.connect(barEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('bar', value))

 layout = QVBoxLayout()
 layout.addWidget(fooEdit)
 layout.addWidget(barEdit)

 self.setLayout(layout)

 def optionChanged(self, option, value):
 self.values[option] = value
 print self.values

 def main(args):
 app = QApplication(args)
 values = dict(foo='', bar='')
 dialog = Options(values)
 dialog.show()
 app.exec_()

 if __name__ == '__main__':
 main(sys.argv)


 If I type a character in fooEdit, another character in barEdit, and
 then
 delete the character from barEdit I get an unhandled win32 exception
 occured
 in python.exe on windows and segfault on linux.

 If I type a character in fooEdit, delete it, and then type a character
 in

 barEdit I get:

 {'foo': PyQt4.QtCore.QString(u'a'), 'bar': ''}
 {'foo': PyQt4.QtCore.QString(u''), 'bar': ''}
 {'foo': Traceback (most recent call last):
   File L:\home\dev\python\test.py, line 17, in lambda
 lambda value: self.optionChanged('bar', value))
   File L:\home\dev\python\test.py, line 27, in optionChanged
 print self.values
 MemoryError

 I'm using Python 2.5.4 and PyQt 4.4.3-1

 Thanks in advance for any help.

 Works fine for me with current versions.

 Phil

 I have noticed that if I do self.values[option] = QString(value)
 instead of self.values[option] = value in optionChanged I don't get any

 errors.

 Is it perhaps not safe to keep the reference to the lambda QString
 argument?

 It shouldn't make any difference.

 Phil

Last idea, C++ declaration of textChanged signal is this:

void textChanged (const QStringtext)

would self.values[option] = value store the reference to QString? And if so 
is that safe, to access that object after my slot returns?

As far as I can see C++ equivalent would be

QString* pointer = text; then derferencing that pointer later in the code. 
I can see how this could cause problems.

Btw you are using PyQt 4.4.4 correct? What version of python? 


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


Re: How to locate the bit in bits string?

2009-04-28 Thread tuxagb
On 28 Apr, 16:36, Li Wang li.wan...@gmail.com wrote:
 Hi:

 If I use an integer to represent bits:
 e.g. 99 represents '1100011'

 How can I locate, say the second bit of 99(i.e. '1')?

 Although bin(99)[4] could be used to locate it, this transform cost
 too much memory (99 only needs 2Bytes, while string '1100011' needs
 7Bytes).

 Anyone knows how to locate  the second bit without using bin() function?

 Thank you very much:D

 --
 Li
 --
 Time is all we have
 and you may find one day
 you have less than you think

If we consider 8 bit, a solution may be the follow:

   a = 99  # bin(a) = 0b1100011
   0b1101  a
  97
   0b1110  a
  99

as you view, you set the nth bit to 0, and view if the result is same
as 'a'. If is same
then the nth bit doesn't set. If you write the above code in a loop,
you can test which bit
you want.

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


Re: How to locate the bit in bits string?

2009-04-28 Thread Li Wang
2009/4/29 Tim Chase python.l...@tim.thechases.com:
 Li Wang wrote:

 Hi:

 If I use an integer to represent bits:
 e.g. 99 represents '1100011'

 How can I locate, say the second bit of 99(i.e. '1')?

 Although bin(99)[4] could be used to locate it, this transform cost
 too much memory (99 only needs 2Bytes, while string '1100011' needs
 7Bytes).

 Anyone knows how to locate  the second bit without using bin() function?

 You mean

  def get_bit(number, bit):
return (number  bit)  1

 ?

Hummm, I have tried this method too, the problem is its time
complexity. If the length of my bits is n, then the time complexity is
O(n). When I tried to implement this in practice, it did consume a lot
of time.

So do you know how could I locate the bit in O(1) time? Transform it
into a string is a method, but takes too much space (when I try to
process a 2M file, it used more than 100M memory.).

Thank you very much.

 -tkc








-- 
Li
--
Time is all we have
and you may find one day
you have less than you think
--
http://mail.python.org/mailman/listinfo/python-list


Re: Third Party Modules

2009-04-28 Thread tuxagb
On 28 Apr, 17:02, Brock btibe...@gmail.com wrote:
 Hi Everyone,

 I know this is most likely a basic question and you will roll your
 eyes, but I am just starting out with Python (hobbyist) and I see many
 tutorials on the web referring to the use of external modules.

 However, when I locate them, they often come as a zipped folder with a
 number of files.  How do I install them?  In addition, is there an
 easy way to manage external modules? Some I see require additional
 modules not included.

 Where I am coming from is R, which has a point-and-click way of
 getting packages not distributed with the version of the software, so
 that is my point of reference.

 Many thanks!

 - Brock

If you are on Unix-like machine, unzip the archive in a some
directory, do cd into the new directory
and, from command line, do: python ./setup.py build (verify there is
the script setup.py), and then
python ./setup.py install (with root's permissions). On Win32 usually
there are an automatic  installer.

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


Re: python segfaulting, MemoryError (PyQt)

2009-04-28 Thread Phil Thompson
On Tue, 28 Apr 2009 17:10:51 +0200, Denis L n...@spam.com wrote:
 Phil Thompson p...@riverbankcomputing.com wrote in message 
 news:mailman.4690.1240925876.11746.python-l...@python.org...
 On Tue, 28 Apr 2009 14:54:41 +0200, Denis L n...@spam.com wrote:
 Phil Thompson p...@riverbankcomputing.com wrote in message
 news:mailman.4664.1240907352.11746.python-l...@python.org...
 On Tue, 28 Apr 2009 03:53:34 +0200, Denis L n...@spam.com wrote:
 Hello,

 I'm experiencing odd errors on both windows and linux with the
 following
 code:

 import sys
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *

 class Options(QDialog):
 def __init__(self, values):
 QDialog.__init__(self)

 self.values = values

 fooEdit = QLineEdit(values['foo'])
 self.connect(fooEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('foo', value))

 barEdit = QLineEdit(values['bar'])
 self.connect(barEdit, SIGNAL('textChanged(QString)'),
  lambda value: self.optionChanged('bar', value))

 layout = QVBoxLayout()
 layout.addWidget(fooEdit)
 layout.addWidget(barEdit)

 self.setLayout(layout)

 def optionChanged(self, option, value):
 self.values[option] = value
 print self.values

 def main(args):
 app = QApplication(args)
 values = dict(foo='', bar='')
 dialog = Options(values)
 dialog.show()
 app.exec_()

 if __name__ == '__main__':
 main(sys.argv)


 If I type a character in fooEdit, another character in barEdit, and
 then
 delete the character from barEdit I get an unhandled win32 exception
 occured
 in python.exe on windows and segfault on linux.

 If I type a character in fooEdit, delete it, and then type a
character
 in

 barEdit I get:

 {'foo': PyQt4.QtCore.QString(u'a'), 'bar': ''}
 {'foo': PyQt4.QtCore.QString(u''), 'bar': ''}
 {'foo': Traceback (most recent call last):
   File L:\home\dev\python\test.py, line 17, in lambda
 lambda value: self.optionChanged('bar', value))
   File L:\home\dev\python\test.py, line 27, in optionChanged
 print self.values
 MemoryError

 I'm using Python 2.5.4 and PyQt 4.4.3-1

 Thanks in advance for any help.

 Works fine for me with current versions.

 Phil

 I have noticed that if I do self.values[option] = QString(value)
 instead of self.values[option] = value in optionChanged I don't get
 any

 errors.

 Is it perhaps not safe to keep the reference to the lambda QString
 argument?

 It shouldn't make any difference.

 Phil
 
 Last idea, C++ declaration of textChanged signal is this:
 
 void textChanged (const QStringtext)
 
 would self.values[option] = value store the reference to QString? And if
so
 
 is that safe, to access that object after my slot returns?

 As far as I can see C++ equivalent would be
 
 QString* pointer = text; then derferencing that pointer later in the
code.
 
 I can see how this could cause problems.

If there was a bug with lambda slots it's been fixed by now.

 Btw you are using PyQt 4.4.4 correct? What version of python? 

PyQt v4.5 snapshot, Python v2.6.2 and v3.0.1.

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


Re: How can I get Tkinter to work in Python? (I tried many things)

2009-04-28 Thread Peter Pearson
On Mon, 27 Apr 2009 17:49:26 -0700 (PDT), tom...@gmail.com wrote:
[snip]
 There are errors, but since there is many of them:
 here is a cut out of the _tkinter errors:

 libpython2.6.a(_tkinter.o): In function `Tkapp_CallProc':
 /home/tomzam/mylib6/Python-2.6.2/./Modules/_tkinter.c:1263: undefined
 reference to `Tcl_MutexLock'

I believe this message means that something named _tkinter.c
was previously compiled into an object file named
_tkinter.o, which was bundled into a library named
libpython2.6.a; and that when you attempt to use
libpython2.6.a to satisfy the external references of something
(not identified) that you're trying to link, the linker
discovers that _tkinter.o contains a function Tkapp_CallProc
that (on line 1263 of _tkinter.c) attempts to call function
Tcl_MutexLock, but the linker can't find anything named
Tcl_MutexLock to satisfy it.

Tcl_MutexLock is probably *supposed* to be provided by some
Tcl runtime library, but not being very knowledgeable, I
don't know what library.  Just before the beginning of the
list of error messages, you'll probably find the command line
that's running the linker, and it probably names a bunch of
libraries, one of which is supposed to include Tcl_Mutexlock
but doesn't.  I apologize for being so vague; with any luck,
someone much smarter will come along soon.

-- 
To email me, substitute nowhere-spamcop, invalid-net.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Restart generator when it is exhausted.

2009-04-28 Thread J. Cliff Dyer

On Tue, 2009-04-28 at 10:41 +, Duncan Booth wrote: 
 Lacrima lacrima.ma...@gmail.com wrote:
 
  If it is not possible what are common techniques to use iterator or
  generator objects that allow restarting when it is needed?
 
 The usual thing if you want to use the generator's output more than once  
 would be to convert the generator to a list, then you can iterate over it 
 as often as you want.
 
  a = ['a', 'b', 'c']
  g = (i for i in a)
  restartable = list(g)
 
 If you want the output of the generator to potentially change each time you 
 iterate then you need to create a new generator.
 

More verbosely, but without putting your generator in , you can use the
iterator protocol to create a reusable iterable:

An iterable is a class with an __iter__ method that returns an iterator.

So for example:

class Iterator(object):
def __init__(self, filename):
self.f = open(filename)

def __iter__(self):
return self

def next(self):
line = self.f.readline()
if not line:
raise StopIteration
return line.strip()[:8]

is an iterator (which is also an iterable), which will grab each line of
a file, returning the first eight non-whitespace characters until the
file is used up.  Then the iterator is exhausted, and will continue to
raise StopIteration each time it is called.

class Iterable(object):
def __init__(self, filename):
self.filename = filename

def __iter__(self):
return Iterator(self.filename)

This is a reusable iterable which returns a new instance of the Iterator
class above each time it is exhausted.

So given a file hello.txt:

  Hello world
Hola mundo
  Guten tag, weld.

The classes can be used as followed:
 iterator = Iterator('hello.txt')
 for i in xrange(3):
 print *** %d *** % i
 for j in iterator:
 print j
*** 0 ***
Hello wo
Hola mun
Guten ta
*** 1 ***
*** 2 ***
 iterable = Iterable('hello.txt')
 for i in xrange(3):
 print *** %d *** % i
 for j in iterable:
 print j
*** 0 ***
Hello wo
Hola mun
Guten ta
*** 1 ***
Hello wo
Hola mun
Guten ta
*** 2 ***
Hello wo
Hola mun
Guten ta

When Iterator hits a StopIteration, it passes out of the inner loop, and
when it comes back in, the inner loop calls iterator.__iter__(), and
gets the same exhausted iterator (which immediately breaks the inner
loop by raising StopIteration).  In Iterable, when the loop calls
iterable.__iter__(), it gets a fresh iterator, so it can loop over the
file again.

The important thing is that when you call x.__iter__() (which you do
when entering a loop), you get a fresh iterator that won't just call
StopIteration right away.

Cheers,
Cliff


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


Re: suggestion on a complicated inter-process communication

2009-04-28 Thread Way
Thanks a lot for reply. I understand it is abnormal to implement such
IPC, while it is worthy for my application.

Well, my process3 and 4 are from an outside application, which both
need License Check and os.system to involk.

From my experience, if Process5 involks Process3, such License Check
can be very very slow (even slower than its real run).

That is why I need to separate Process3 and 4 onto different processes
to proceed.

On Apr 28, 1:57 am, Jonathan Gardner jgard...@jonathangardner.net
wrote:
 On Apr 27, 8:59 pm, Way csw...@gmail.com wrote:



  Hello friends,

  I have a little messy situation on IPC. Please if you can, give me
  some suggestion on how to implement. Thanks a lot!

  - denotes create

  MainProcess - Process1 - Process3 (from os.system)
                     |
                      - Process2 (from os.system) - Process4 (from
  os.system) -Process5

  I would like to make the communication between Process1 and Process5.
  Process1 needs Process5's output to provide argument to generate
  Process3, and in turn Process5 needs to wait Process3 finished.

  Thank you very much if you can give a hint.

 Abstraction should resolve this. What I mean is that Process2
 shouldn't be defined in terms of what it actually does, but what it
 appears to do. If you look at each process and think only what its
 child processes do and what its parent process expects it to do, then
 your job should get a lot simpler. Process1 expects Process2 to
 deliver a set of parameters to spawn Process3, and then it will wait
 until Process3 terminates.

 Looking at it this way, questions come to mind: Why can't Process2 run
 Process3 itself? It's unusual to have one process tell another process
 what to do when it can simply do it itself.

 By the way, I've never seen a time when this kind of design is
 necessary. There are other ways around your problem than spawning a
 bunch of processes. Each process should really be independent of all
 the other processes, doing only a very well-specified task in a well-
 specified way. The only time I could think of doing something like
 this is when you're getting a webserver setup and Process5 needs to
 communicate with Process3 to render the page or something like that.
 But even in that case, each process is really independently defined
 and implemented.

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


Re: What do you think of ShowMeDo

2009-04-28 Thread tuxagb
On 28 Apr, 17:09, Astley Le Jasper astley.lejas...@gmail.com wrote:
 Hi,

 I've just stumbled over this (http://showmedo.com/) and being the very
 visual person I am, it seems like it could be a good way to learn
 about python. However, before I smack down $60, I wondered if anyone
 had any opinions on it. My gut feel is that it could be pretty good.

 ALJ

It can be useful, but there are many free howtos and tutorial ... and
the programming
can't be learned with video, but with books!

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


Re: suggestion on a complicated inter-process communication

2009-04-28 Thread Way
Thanks a lot for the reply. I am not familiar with multi-process in
Python. I am now using something like:
A_prog is an os.system to involk Process3
B_prog is an os.system to involk Process4
---
In Main Process:
Process1 = Popen([A_prog], stdin=PIPE, stdout=PIPE)
Process2 = Popen([B_prog], stdin=PIPE, stdout=PIPE)

cmd = Process2.stdout.readlines()
Process1.stdin.write(cmd)
if Process1.poll():
  Process2.stdin.write(trig from Process1)

-
In Process5 (another python program):
import sys
sys.stdout.write(process1 argument)
while 1:
if sys.stdin.readline().strip() == trig from Process1:
break
--

However, in this case, Process5's stdout cannot be passed to
MainProcess for Process1, since it has not finished (waiting Process.
1/3 finish).

I am now using Fifos (an external file) to inter-communicate Process1
and 5. But at first run, it compliants not file found.

Is there any possible solution to make it work? Thank you very much!

On Apr 28, 1:34 am, Aaron Brady castiro...@gmail.com wrote:
 On Apr 27, 10:59 pm, Way csw...@gmail.com wrote:



  Hello friends,

  I have a little messy situation on IPC. Please if you can, give me
  some suggestion on how to implement. Thanks a lot!

  - denotes create

  MainProcess - Process1 - Process3 (from os.system)
                     |
                      - Process2 (from os.system) - Process4 (from
  os.system) -Process5

  I would like to make the communication between Process1 and Process5.
  Process1 needs Process5's output to provide argument to generate
  Process3, and in turn Process5 needs to wait Process3 finished.

  Thank you very much if you can give a hint.

 The 'mmap' module can help with getting the data from 5 to 1.  It
 requires creating a file.  If it's a small amount of data, any old
 file will do.  You may need a socket in order to wait for Process3 to
 join, or write a small '.pyd' or '.so' file that gives you access to
 your system's synchronization object.

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


Re: How to locate the bit in bits string?

2009-04-28 Thread tuxagb
On 28 Apr, 17:24, Li Wang li.wan...@gmail.com wrote:
 2009/4/29 Tim Chase python.l...@tim.thechases.com:

  Li Wang wrote:

  Hi:

  If I use an integer to represent bits:
  e.g. 99 represents '1100011'

  How can I locate, say the second bit of 99(i.e. '1')?

  Although bin(99)[4] could be used to locate it, this transform cost
  too much memory (99 only needs 2Bytes, while string '1100011' needs
  7Bytes).

  Anyone knows how to locate  the second bit without using bin() function?

  You mean

   def get_bit(number, bit):
     return (number  bit)  1

  ?

 Hummm, I have tried this method too, the problem is its time
 complexity. If the length of my bits is n, then the time complexity is
 O(n). When I tried to implement this in practice, it did consume a lot
 of time.

 So do you know how could I locate the bit in O(1) time? Transform it
 into a string is a method, but takes too much space (when I try to
 process a 2M file, it used more than 100M memory.).

 Thank you very much.

  -tkc

 --
 Li
 --
 Time is all we have
 and you may find one day
 you have less than you think

The my solution is good, but the Tim's solution is better, and it is O
(1) in time and space.
What is you search? I dont'know you general problem, but search the
value of a bit in a 2M file ...
is strange .

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


Re: suggestion on a complicated inter-process communication

2009-04-28 Thread norseman

Way wrote:

Hello friends,

I have a little messy situation on IPC. Please if you can, give me
some suggestion on how to implement. Thanks a lot!

- denotes create


MainProcess - Process1 - Process3 (from os.system)
   |
- Process2 (from os.system) - Process4 (from
os.system) -Process5

I would like to make the communication between Process1 and Process5.
Process1 needs Process5's output to provide argument to generate
Process3, and in turn Process5 needs to wait Process3 finished.

Thank you very much if you can give a hint.

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


=

My first reaction is to use named pipes.

Process1 - P2 - P4 - Process5 NamedPipe (P5 outputs to NamedPipe)
   Process1 waits for NamedPipe to be made and starts creating Process3
   When Process3 is finished it can set an OS level environmental or
 create a dummy file as a signal to Process5 to finish.
   P1 becomes orchestrator, NamedPipe is courier, file is smoke signal.

This method works when IPC is not a good choice. (Like independent child 
processes run across the net. A specific file in a specific location 
effectively creates a specific signal. Whether or not contents are used 
or even existing is programmer choice.)


Hope this helps.

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


Re: Getting the dir from the other ancestor ?

2009-04-28 Thread Stef Mientki

tuxagb wrote:

On 28 Apr, 15:01, Stef Mientki stef.mien...@gmail.com wrote:
  

hello,

I have a class, derived from some user defined class
(User_Defined_Ancestor) and some basic class (Basic_Ancestor).

One of the major tasks of the Basic_Ancestor,
is to hide all kinds of implementation details for the user,
so the user can concentrate on the functional design.

One of things I need to know are the methods and attributes of the
Basic_Ancestor.
Both classes are dynamic, i.e. attributes are added during run time.

class Master ( User_Defined_Ancestor, Basic_Ancestor ) :
def __init__ ( self, *args, **kwargs ) :
Basic_Ancestor.__init__ ( self, *args, **kwargs )
.

class Basic_Ancestor ( object ) :
def __init__ ( self,  ) :
self.other = dir ( User_Defined_Ancestor )

def Get_Attributes ( self ) :
return dir ( self ) - dir ( self.other )

Now the problem is, I don't know User_Defined_Ancestor in Basic_Ancestor.
I can't pass it through the parameter list, because I use *args, **kwargs
I possibly could use some global variable, but that's not my preference.

Any other suggestions ?

thanks,
Stef Mientki



In anytime, if you do dir() in a class B, that extends a class A, you
have all fields of A also.
  

That's exactly the problem I encounter ;-)
After some trial and error, I found this solution:

class Basic_Ancestor ( object ) :
   def __init__ ( self,  ) :
   # Collect all methods and attributes of other classes
   self.Exclude_Dir  = []
   Base_Classes = self.__class__.__bases__
   for BC in Base_Classes :
   if BC != My_Control_Class :
   self.Exclude_Dir += dir ( BC )


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


Re: suggestion on a complicated inter-process communication

2009-04-28 Thread Paul Boddie
On 28 Apr, 17:40, Way csw...@gmail.com wrote:
 Thanks a lot for reply. I understand it is abnormal to implement such
 IPC, while it is worthy for my application.

 Well, my process3 and 4 are from an outside application, which both
 need License Check and os.system to involk.

Sounds delightful!

Anyway, looking at your diagram (edited to fit)...

Main
 | \- P1 - P3 (from os.system)
 \- P2 (from os.system) - P4 (from os.system) -P5

...if P1, P2 and P4 are able to propagate input and output, then this
is just a matter of having something in the main process which
monitors the input from P5 (via P4 and P2) and which relays the input
to P3 (via P1). This could be as simple as the following:

to_p1.write(from_p2.read())

If this isn't sophisticated enough, because you only want to read some
details from P2, you could either try and read a predetermined amount
from P2, or you could write a communications handler which monitors
the input from P2 using a select.poll object. If the main process is
supposed to be doing other things, then it's quite likely that you'll
have to do something involving either select.poll or threads, anyway.

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


stuck with PyOBEX

2009-04-28 Thread alejandro
So I installed the module and tryed to make it work but...
It gave me:

Traceback (most recent call last):
  File first.py, line 24, in module
client2.connect()
  File C:\Python25\lib\PyOBEX\client.py, line 359, in connect
return Client.connect(self, header_list = [headers.Target(uuid)])
  File C:\Python25\lib\PyOBEX\client.py, line 119, in connect
self.socket = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM,
AttributeError: 'module' object has no attribute 'AF_BLUETOOTH' Exit 
Code: 1


This module asks the socket module for AF_BLUETOOTH... in the socket module 
there is no such thing as AF_BLUETOOTH. Could it be that the person that 
made PyOBEX modified his socket module and forgot to give his socket module? 
Or am I missing something? Maybe AF_BLUETOOTH stands for something that a 
programmer would know but I am a beginner so...

Is there a OBEX module for Python on windows?


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


Re: Light (general) Inter-Process Mutex/Wait/Notify Synchronization?

2009-04-28 Thread John Nagle

Gunter Henriksen wrote:

If you don't want to use a 3rd party module you could
use the multiprocessing module


That is definitely good for when I have a tree of
processes which are all Python applications.  I use
it for that.  But I am looking for something where
the Python application can interact conveniently
with an arbitrary external application.  Using a
socket/pipe and shared memory is convenient, but
not feasible when system call overhead matters.


Linux doesn't do interprocess communication very well.
The options are pipes (clunky), sockets (not too bad, but
excessive overhead), System V IPC (nobody uses
that) and shared memory (unsafe).

If you want to see IPC right, what you really need is
the QNX microkernel, and its messaging system.  I've pumped
uncompressed video through the QNX messaging system and had
only 2% of the CPU devoted to message overhead.  The basic
primitives are MsgSend, MsgReceive, and MsgReply, which do
about what you'd expect and do it very fast.  Linux lacks
this.

   If you're using CPython, don't worry about socket overhead.
CPython is so slow you'll never notice it.

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


Re: How to locate the bit in bits string?

2009-04-28 Thread Tim Chase

Li Wang wrote:

2009/4/29 Tim Chase python.l...@tim.thechases.com:

Li Wang wrote:

If I use an integer to represent bits:

[snip]

Hummm, I have tried this method too, the problem is its time
complexity. If the length of my bits is n, then the time complexity is
O(n). When I tried to implement this in practice, it did consume a lot
of time.


I'm not sure I follow here -- your original post said that you 
have an integer.  With an integer, my function is O(1) as you 
request.  It sounds like you're *not* representing your bits as 
an integer.  Either that, or it's a gargantuan number (say, more 
than 64 bits?  Maybe more than 1k bits?) that you want to 
bit-slice.  In that case, you need to know a bit more about the 
storage structure.  However, assuming it's a raw bit-stream, you 
might be able to do something like this (untested, but should be 
fairly close)


  data = file('source.bin').read()
  def get_bit(source, bit):
idx, bit = divmod(bit, 8)
byte = ord(source[len(source) - (1+idx)])
return (byte  bit)  1

  print get_bit(data, 3141592) # the 3,141,592nd bit

you might have to tweak for endian'ness.

-tkc





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


Re: Why bool( object )?

2009-04-28 Thread Gabriel Genellina
En Tue, 28 Apr 2009 09:22:01 -0300, Colin J. Williams c...@ncf.ca  
escribió:

Lie Ryan wrote:

Aaron Brady wrote:



This makes it so all objects except False, None, 0, and empty
containers are true by default.  I am not convinced that 'if a
generic object' should have any meaning; it should probably throw an
exception.  Is it part of Python's look and feel or its mentality?  Is
it part of the Zen?  Certainly other ideal types can't be cast from
generic objects, so why booleans?  Is it an ineffable component of the
author's vision for the language?  I think that giving arbitrary
syntactic constructs meaning is just space-filler.  It's worse than
syntactic sugar, it's semantic sugar.  Why not assign meanings willy-
nilly to other random juxtapositions of tokens?


 It's part of the design decision. In almost all cases (in any  
language), a so-called Design Decision is rather random and prone to  
subjective judgment, just as the decision to make bool(int) returns  
False only on 0, -1, or for all negative values; whether to make  
bool(100) and exception or True; or round() rounds down or up or  
even-odd; or the use of brackets vs. indentation; or whether to treat  
empty list as True or False.


I'm puzzled by the last sentence:


bool(0)

False

bool(-1)

True

bool(-100)

True


That's the design decision. bool(-1) *might* have been False, and  
bool(-100) *might* raise an exception. They behave the way they do because  
of a conscious decision.


To Aaron: Programming language design is not a rational science. Most  
reasoning about is is at best rationalization of gut feelings, and at  
worst plain wrong.
(GvR in python-ideas:  
http://groups.google.com/group/python-ideas/msg/ac61f03c32578bae )


--
Gabriel Genellina

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


Re: inside-out range function

2009-04-28 Thread Scott David Daniels

Steven D'Aprano wrote:

... I wrote a similar function to do this:

def monge_shuffle(deck):
if len(deck) % 2: # Odd number of items.
deck[:] = deck[0::2] + deck[1::2][::-1]
else: # Even number of items.
deck[:] = deck[1::2] + deck[0::2][::-1]
return deck


Oooh, shiny fun!!!  How's this for that:

def monge_shuffle2(deck):
even = (len(deck) ^ 1)  1
return deck[even::2] + deck[-2::-2]

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


Re: suggestion on a complicated inter-process communication

2009-04-28 Thread Paul Boddie
On 28 Apr, 17:44, Way csw...@gmail.com wrote:
 Thanks a lot for the reply. I am not familiar with multi-process in
 Python. I am now using something like:
 A_prog is an os.system to involk Process3
 B_prog is an os.system to involk Process4
 ---
 In Main Process:
 Process1 = Popen([A_prog], stdin=PIPE, stdout=PIPE)
 Process2 = Popen([B_prog], stdin=PIPE, stdout=PIPE)

 cmd = Process2.stdout.readlines()

Careful here: this may want to read until process 2 has closed its
stream, which may only occur on exit, normally.

 Process1.stdin.write(cmd)
 if Process1.poll():
   Process2.stdin.write(trig from Process1)

 -
 In Process5 (another python program):
 import sys
 sys.stdout.write(process1 argument)

Careful here, too: this output may not be sent immediately, due to
buffering issues.

 while 1:
     if sys.stdin.readline().strip() == trig from Process1:
             break

And this test may not be satisfied, since the main process may still
be waiting for output from process 5 (via process 2), not reaching the
point where it writes a response.

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


Re: stuck with PyOBEX

2009-04-28 Thread Diez B. Roggisch
alejandro wrote:

 So I installed the module and tryed to make it work but...
 It gave me:
 
 Traceback (most recent call last):
   File first.py, line 24, in module
 client2.connect()
   File C:\Python25\lib\PyOBEX\client.py, line 359, in connect
 return Client.connect(self, header_list = [headers.Target(uuid)])
   File C:\Python25\lib\PyOBEX\client.py, line 119, in connect
 self.socket = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM,
 AttributeError: 'module' object has no attribute 'AF_BLUETOOTH' Exit
 Code: 1
 
 
 This module asks the socket module for AF_BLUETOOTH... in the socket
 module there is no such thing as AF_BLUETOOTH. Could it be that the person
 that made PyOBEX modified his socket module and forgot to give his socket
 module? Or am I missing something? Maybe AF_BLUETOOTH stands for something
 that a programmer would know but I am a beginner so...
 
 Is there a OBEX module for Python on windows?

AF_BLUETOOTH seems to be specific to *nix-systems. At least under debian and
ubuntu, I've got it defined.

So it seems it is not supported under windows - you should consider the
author if that's a mistake, or by design.

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


  1   2   3   >