PyOpenGL Release 3.0.0 (final)

2009-04-02 Thread Mike C. Fletcher
PyOpenGL is the traditional OpenGL binding for the Python language 
(Python 2.x series).  This release is the first major release of the 
package in more than 4 years.  PyOpenGL 3.x is a complete rewrite of the 
PyOpenGL project which attempts to retain compatibility with the 
original PyOpenGL 2.x API while providing support for many more 
data-formats and extensions than were wrapped by the previous 
code-base.  It attempts to retain the easy approachable API of the 
original PyOpenGL bindings, focusing more on ease of development (both 
for client code and the library itself) than speed.


Build and installation has been dramatically simplified.  It is possible 
to work directly from a PyOpenGL bzr branch or to merely unpack the 
package into your PYTHONPATH.  To install from source and/or participate 
in development:


   bzr branch lp:pyopengl
   bzr branch lp:pyopengl-demo

then add the pyopengl/OpenGL directory to your PYTHONPATH.  You can also 
download the source distributions from:


   http://pyopengl.sourceforge.net

and use standard distutils commands to install.  PyOpenGL 3.x is already 
supported by the PyInstaller exe packaging utility, and can be made to 
work with Py2exe with inclusion statements.


PyOpenGL may be installed using the easy_install script if desired.  
There are no setuptools/package-resources dependencies in PyOpenGL 3.0.0 
final.  You can install PyOpenGL on supported platforms (currently 
Linux, Win32 and OSX) with the following if you have setuptools, PIL and 
Numpy installed:


   easy_install PyOpenGL
   easy_install PyOpenGL-Demo

You can then run the scripts in the PyOpenGL-Demo package.

PyOpenGL 3.x introduces package-level configuration flags which allow 
you to modify the behavior of the entire PyOpenGL package, e.g. by 
introducing extremely verbose logging, or turning off all error-checking 
to improve performance.  Of particular note is a flag which allows you 
to disable APIs which have been deprecated by the ARB in OpenGL 3.0.  
Other flags allow you to control the trade-off between ease-of-use and 
performance during the development and release process.


PyOpenGL 3.x provides access to the entire OpenGL 3.0 API, as well as 
most extensions which have been entered in the OpenGL extension 
registry.  Commonly used extensions can have Pythonic wrappers written 
easily, and many of the commonly used extensions already have simplified 
APIs provided.  It also provides wrappers for the GLUT, GLE and GLX 
libraries.  The AGL and WGL modules are not provided with PyOpenGL 3.x, 
as most devs are using window-manager-based GL operations.


PyOpenGL 3.x provides a simple plug-in API that allows you to write 
data-format or platform plugins.  These can be used to easily add 
native support for your array-friendly data-formats (vector classes 
and the like).  There is a sample data-format plug-in which wraps the 
Vertex Buffer Objects extensions (in the OpenGL/arrays/vbo.py module).


PyOpenGL 3.x's documentation has been regenerated and the build process 
for the documentation has been updated so that it can be easily 
regenerated to include pointers to other Open Source PyOpenGL project's 
online code viewers.  If you would like to add your project to the list 
of referenced projects, please contact the author with details of your 
code viewer's url, code license and project name.


Notes in the reference documentation indicates the deprecated entry 
points for OpenGL 3.0.  If you have a PyOpenGL code-base you should be 
looking at reworking the code in order to eliminate the use of legacy 
APIs before OpenGL 3.1 drivers become mainstream.  At minimum you should 
be converting away from per-vertex operations and the use of display 
lists toward using array-based geometry.


You should expect a performance decline with the use of PyOpenGL 3.x 
versus PyOpenGL 2.x!  PyOpenGL 3.x will have an accelerator module 
released in time to provide better performance, but the development 
method (ctypes) is inherently slower than the C (SWIG) method previously 
used.  If your code is performance critical you should likely use the 
accelerator module when it becomes available.  Also consider using the 
package-level configuration flags to remove support functionality as 
you near release, use of these flags can provide more than 2x speedup in 
most cases.


The 3.0.0 final release has a few bugs fixed from the previous 3.0.0c1 
release.  Users of the release candidate should upgrade.  PyOpenGL 3.0.0 
is intended for use with the Python 2.x series, porting to Python 3.x is 
not currently on the roadmap.  There will likely be a PyOpenGL 3.0.1 
release in the near future which will introduce a few more optimizations 
and likely will be synchronized with the first public release of the 
accelerator modules.


Since the release of PyOpenGL 2.x another common OpenGL binding for 
Python has become popular and may be an appropriate choice for your 
projects.  The Pyglet project 

Re: Display directory pyqt4 and Python

2009-04-02 Thread Wolfgang Rohdewald
On Donnerstag, 2. April 2009, Dunwitch wrote:
 for x in (fileList):
 self.ui.displayVideo.setText(x) # This only shows the last


self.ui.displayVideo.setText('\n'.join(fileList))


but I would go for a solution with QDirModel / QListView

http://doc.trolltech.com/4.5/itemviews-dirview.html

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


Re: python for loop

2009-04-02 Thread Lie
On Apr 2, 4:05 pm, Aaron Brady castiro...@gmail.com wrote:
 On Apr 1, 11:58 pm, Lie lie.1...@gmail.com wrote:

  On Apr 1, 7:06 pm, Steven D'Aprano

  ste...@remove.this.cybersource.com.au wrote:
   There is a major clash between the names of ordinals in human languages
   and zero-based counting. In human languages, the Nth-ordinal item comes
   in position N. You can keep that useful convention with zero-based
   counting by inventing the ugly word zeroth, but that just leads to
   bizarro-talk like the zeroeth item comes first, the first item comes
   second, and so on.

  No, there won't be any bizarro-talk. There is no argument: the zeroeth
  item comes zeroeth, the first item comes first, and so on. The index
  for the very zeroeth thing in a list is 0, so to get the zeroeth item
  you use s[0]. While to get the first item you use s[1]. It's very
  intuitive, isn't it?

 Robot 1: I won zeroeth place at the contest, honey!
 Robot 2: Congratulations!  I knew you could do it.

That should be Robot 0 and Robot 1.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A design problem I met again and again.

2009-04-02 Thread Steven D'Aprano
On Thu, 02 Apr 2009 18:47:29 +1300, Lawrence D'Oliveiro wrote:

 The question is not how many lines or how many methods, but whether it
 makes sense to remain as one piece or not. In one previous project, I
 had one source file with nearly 15,000 lines in it. Did it make sense
 to split that up? Not really.
 
 What are the average size of source files in your project?   If it's
 far lower than 15,000,  don't feel it's a little unbalance?
 
 Why?

If you have too much code in one file, it will upset the balance of the 
spinning hard drive platter, and it will start to wobble and maybe even 
cause a head-crash.



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


Re: python for loop

2009-04-02 Thread Steven D'Aprano
On Thu, 02 Apr 2009 04:23:32 +, John O'Hagan wrote:

 Beyond being part of a conventionally-ordered set of keys, what can an
 ordinality of zero actually mean? (That's a sincere question.)

In set theory, you start by defining the integers like this:

0 is the cardinality (size) of the empty set, the set with nothing in it.

1 is the cardinality of the set of empty sets, that is, the set 
containing nothing but the empty set.

2 is the cardinality of the set of the empty set plus the set of empty 
sets.

3 is the cardinality of the set containing the empty set, plus the set of 
empty sets, plus the set of (the empty set plus the set of empty sets).

And so forth, to infinity and beyond.

Or to put it another way:


0 = len( {} )
1 = len( {{}} )
2 = len( {{}, {{}}} )
3 = len( {{}, {{}}, {{}, {{}}} )
etc.

For non-infinite sets, you can treat ordinal numbers and cardinal numbers 
as more or less identical. So an ordinality of zero just means the number 
of elements of something that doesn't exist.

How that relates to whether indexing should start at one or zero, I have 
no idea.

Oh, and speaking of... I'm shocked, SHOCKED I say, that nobody has given 
that quote about the compromise of 0.5.


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


Re: python for loop

2009-04-02 Thread Steven D'Aprano
On Wed, 01 Apr 2009 21:58:47 -0700, Lie wrote:

 On Apr 1, 7:06 pm, Steven D'Aprano
 ste...@remove.this.cybersource.com.au wrote:
 
 There is a major clash between the names of ordinals in human languages
 and zero-based counting. In human languages, the Nth-ordinal item comes
 in position N. You can keep that useful convention with zero-based
 counting by inventing the ugly word zeroth, but that just leads to
 bizarro-talk like the zeroeth item comes first, the first item comes
 second, and so on.
 
 No, there won't be any bizarro-talk. There is no argument: the zeroeth
 item comes zeroeth, the first item comes first, and so on. The index for
 the very zeroeth thing in a list is 0, so to get the zeroeth item you
 use s[0]. While to get the first item you use s[1]. It's very intuitive,
 isn't it?

No, because first, second, third etc. have existed in the English 
language for hundreds of years and everybody knows them. Zeroeth was 
probably invented a few decades ago, and is known by maybe 1% of the 
English-speaking population.

Given the list [a, b, c], if you ask even a C programmer *in English* 
what's the first item?, they will almost invariably answer a rather 
than b.


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


Re: Regex trouble

2009-04-02 Thread akshat agarwal
Thanks Andrew. I was also of the same view that perl handled this via some
special cases.

On Wed, Apr 1, 2009 at 8:32 PM, andrew cooke and...@acooke.org wrote:


 more exactly, my guess is perl has a special case for this that avoids
 doing a search over all possible matchers via the pushdown stack.

 andrew cooke wrote:
 
  .*? is a not greedy match, which is significantly more difficult to
  handle than a normal .*.  so the performance will depend on quite
  complex details of how the regular expression engine is implemented.  it
  wouldn't surprise me if perl was better here, because it comes from a
  background with a much stronger emphasis on regular expressions.
 
  i know that not an exact answer, but unless you find the author of the re
  library i am not sure you will get a much better explanation.  it comes
  down to whether the regular expression can be implemented using a
  deterministic finite automaton (rather than an indeterministic one).  if
  you look at the table at the bottom of
  http://en.wikipedia.org/wiki/Finite_state_machine then i believe (i am
 not
  100% sure) that the .*? match requires at least a pushdown automota,
  while .* can be handled with a simple finite automaton.
 
  disclaimer: this is all fairly new to me as i just recently implemented a
  regular expression matcher myself, and i may be wrong on some of the
  details.
 
  andrew
 
 
  akshat agarwal wrote:
  Hi,
 
  I am trying to use the following snippet of code to print a regex match.
 
  s = '01234567890123456789x012'
 
  pat = r'(.*?x|[^a]+)*y'
 
  mo = re.search(pat, s)
  if mo is not None:
  print mo.group(0)
 
  By adding one character before the 'x' in the input string, the time
  taken
  to print the match doubles. This behaviour is not observed in perl. I am
  curious to know about the difference the in regex implementations of
  perl
  and python which causes this.
 
  Thanks
  --
  http://mail.python.org/mailman/listinfo/python-list
 
 
 



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


Re: python for loop

2009-04-02 Thread Carl Banks
On Apr 1, 9:23 pm, John O'Hagan resea...@johnohagan.com wrote:
 Despite being thoroughly acclimatised to zero-based indexing and having no
 wish to change it, I'm starting to see the OP's point.

 Many of the arguments presented in this thread in favour of zero-based
 indexing have rather been arguments for half-open intervals, which I don't
 think are in dispute. We all want these to be true:

 foo[:n] is the first n items of the sequence foo
 foo[:n] + foo[n:] == foo
 len(foo[n:m]) == m-n
 (foo[n:n]) is an empty sequence
 etc.

 and they are true with 0-based indexing if we exclude the last number, or
 equally with 1-based indexing if we exclude the first.

Unless I'm missing something, wouldn't that mean:

range(0,10) - [1,2,3,4,5,6,7,8,9,10]

Even though it's theoretically just another way to line up the open
interval, as practical matter it's going to be a lot more confusing.
Of course you could exclude the last number with one-based indexing
also, but that would be confusing too, since you would have to use
something like range(1,len(x)+1) to iterate over the items of x.

Given that, I'm going to disagree that a half-open interval is
desirable in the case of one-based indexing.

Furthermore, I know of no languages that use both one-based indexing
and half-open intervals.  Do you know of any?


 Beyond being part of a conventionally-ordered set of keys, what can an
 ordinality of zero actually mean? (That's a sincere question.)

I think people were being facetious.  To me the first item in the list
is x[0]--ordinal does not match cardinal.  However, I don't use
ordinals much when talking about list items; I'll say item 2, not
third item.


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


Re: python for loop

2009-04-02 Thread Aaron Brady
On Apr 2, 1:29 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 On Wed, 01 Apr 2009 21:58:47 -0700, Lie wrote:
  On Apr 1, 7:06 pm, Steven D'Aprano
  ste...@remove.this.cybersource.com.au wrote:

  There is a major clash between the names of ordinals in human languages
  and zero-based counting. In human languages, the Nth-ordinal item comes
  in position N. You can keep that useful convention with zero-based
  counting by inventing the ugly word zeroth, but that just leads to
  bizarro-talk like the zeroeth item comes first, the first item comes
  second, and so on.

  No, there won't be any bizarro-talk. There is no argument: the zeroeth
  item comes zeroeth, the first item comes first, and so on. The index for
  the very zeroeth thing in a list is 0, so to get the zeroeth item you
  use s[0]. While to get the first item you use s[1]. It's very intuitive,
  isn't it?

 No, because first, second, third etc. have existed in the English
 language for hundreds of years and everybody knows them. Zeroeth was
 probably invented a few decades ago, and is known by maybe 1% of the
 English-speaking population.

 Given the list [a, b, c], if you ask even a C programmer *in English*
 what's the first item?, they will almost invariably answer a rather
 than b.

 --
 Steven

However, if you ask him/er, What is the item that is 0 items from the
start of the list?, what will s/he say?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Display directory pyqt4 and Python

2009-04-02 Thread Diez B. Roggisch

Dunwitch schrieb:

I've looked around for the answer and have decided to ask an expert
for the solution. Whats suppose to happen is a user pushes a button
and displays the directory content in the text edit window on the gui.
Everything works, apart from the fact that it only shows the last file
in the directory, not a full listing. Here is the code for reference.
Any help would be appreciated, I'm missing something simple.
--
Dunwitch

# File : Video Search
import sys, os, win32net

from PyQt4 import QtGui, QtCore
from findVideos import Ui_MainWindow # UI Files from QT Designer

# New class derived from QMainWindow
class TestApp(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)

# Connect the signals andslots
QtCore.QObject.connect(self.ui.findFiles,QtCore.SIGNAL(clicked
()), self.showVideoFiles)

#- Code In Question
-
def showVideoFiles(self):
enc7 = ('1.2.3.4\\somefolder')
fileList=os.listdir(enc7)
for x in (fileList):
self.ui.displayVideo.setText(x) # This only shows the last
file in the directory?


Of course, if you always only set the *full* text of the displayVideo to 
the current list-item, it will end showing the last set item.


self.ui.displayVideo(\n.join(fileList))

should do the trick (of course you can get rid of the for-loop)

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


Re: python for loop

2009-04-02 Thread Hrvoje Niksic
Carl Banks pavlovevide...@gmail.com writes:

 This is unforgiveable, not only changing the indexing semantics of
 Python (because a user would have NO CLUE that something underlying
 has been changed, and thus it should never be done), but also for
 the needless abuse of exec.

Then I guess you'd fire Guido, too -- from socket.py:

class _socketobject(object):
[...]
_s = (def %s(self, *args): return self._sock.%s(*args)\n\n
  %s.__doc__ = _realsocket.%s.__doc__\n)
for _m in _socketmethods:
exec _s % (_m, _m, _m, _m)
del _m, _s
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for loop

2009-04-02 Thread Arnaud Delobelle
Carl Banks wrote:

 On Apr 1, 2:32 pm, Arnaud Delobelle arno...@googlemail.com wrote:

Check the date on the line above (and the PS in that post).


 If I were your boss and you ever pulled something like this, your ass
 would be so fired.

 This is unforgiveable, not only changing the indexing semantics of
 Python (because a user would have NO CLUE that something underlying
 has been changed, and thus it should never be done), but also for the
 needless abuse of exec.

Gotcha ;)

--
Arnaud

PS.  I disagree about the 'needless abuse of exec'.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a PIL image object to a buffer

2009-04-02 Thread Diez B. Roggisch

Simon Hibbs schrieb:

On 1 Apr, 21:43, Gary Herron gher...@islandtraining.com wrote:

Simon Hibbs wrote:

I'm trying to dump a snapshot of my application window to the
clipboard. I can use ImageGrab in PIL to get the screen data into a
PIL image object, which i have converted to a bitmap using ImageWin,
but when I try to pass this to the clipboard using -
win32clipboard.SetClipboardData(win32clipboard.CF_BITMAP, img)
It fails, telling be that The object must support the buffer
interface.
How can I convert a PIL image into a buffer object? I can't find any
clues.

PIL images have a tostring method that returns a string containing all
the pixel data.  Would that help you to either create the needed
buffer?  Or perhaps you could by-pass the need for a buffer, and just
use the byte string.


If I use tostring I get a string which I can put on the clipboard, but
it isn't any kind of image. I can make a PIL image from the string but
them I'm back to square one again.


Did you actually try that? Strings support the buffer interface, and the 
type of the binary data you set should be defined by the first argument.


Alternatively (if the string is not of the proper format), maybe storing 
the image to a (c)StringIO-object as BMP and retrieving it's value would 
help.


However, I think your concerns about wasting memory when using a file 
are moot - creating an extra memory buffer isn't less memory consuming, 
and if the file is living only a few seconds it might not even actually 
hit the disk at all. In the end, the important thing is the working 
clipboard.


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


Re: How to get the version of a file on WinOS?

2009-04-02 Thread Hill
On 3月26日, 下午4时27分, Tim Golden m...@timgolden.me.uk wrote:
 Hill wrote:
  As you know , we can see the file version from by right click menu
  and click the detail tab.
  Now i am wondering how to get this version number using python?
  Thanks very much!

 If you're talking about a .DLL then this is probably
 what you're looking for:

 http://timgolden.me.uk/python/win32_how_do_i/get_dll_version.html

 If you're talking about something else, say a Word doc
 or some other structured storage file, the answer's
 more complicated.

 TJG

That's what i need. Thank you very much!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help for Toplevel

2009-04-02 Thread Eric Brunel
Muddy Coder wrote:
 Hi Folks,

 I have a problem of handling Toplevel window. Basically, I wrote a
 listbox viewer with scrollbars, and saved in file listbo.py. Then in
 my main GUI window, with menu, I need to launch the listbox viewer, in
 a new window. Obviously, a Toplevel window is needed. But, I failed at
 passing parameters over to Toplevel window. Please take a look at my
 code:

 Listbox viewer:
 class ScrolledList(Frame):
 def __init__(self, options, parent=None):

So the first parameter to the constructor is the scrolled list options, and
the second one is its parent widget, right?

 Frame.__init__(self, parent)
 self.pack(expand=YES, fill=BOTH)
 self.makeWidgets(options)

 In my main GUI:
 from XXX import ScrolledList
 class Foo:
  def __init__(self):
  
  def call_listbox(self, params):
new = Toplevel()
alist = ['foor','bar']
ScrolledList(new,alist)

So why are you passing the parent widget as first parameter and something else
as second...?


On a more general level, unless really needed, I try to avoid creating
subclasses of exisiting classes with a constructor with completely different
parameters than the super-class's one. I'm usually doing something like:

class ScrolledList(Frame):
  def __init__(self, *args, **options):
Frame.__init__(self, *args, **options)

The only thing I (rarely...) allow myself to do is to pass custom options and
getting/removing them with options.pop('my_option') before calling the
super-class's constructor. Otherwise, I just add specific methods; it's far
less confusing.

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


Python3: to add, remove and change

2009-04-02 Thread bearophileHUGS
Here an informal list in random order of things that I may like to add
or to remove to/from Python3.x+.

The things I list here don't come from fifty hours of thinking of
mine, and they may be often wrong. But I use Python2.x often enough,
so such things aren't totally random either.

To remove: map and filter (ex-ifilter/imap).
I don't use them often enough, because generator expression are an
obvious way to map and filter, and to me they seem usually good
enough. (So far ShedSkin has done well without map/filter). (they can
be moved into the itertools module, of course).


To add: I use groupby often enough, so I may like to see it as a
builtin.


To change and improve: the API of the re module. I think several of
its APIs can be improved and made more intuitive, reducing both memory
and cognitive load. Despite having used the re module many times I
need still to look up details into the docs. So its API may be bad.


To add: Python3 is much more lazy-flavour than Python 2.x (see lazy
range, lazy dict views, etc). So islice becomes even more useful and
more commonly used. So I may like to have a lazy slicing as built-in.
But if you make it built-in, then why not add a syntax too? So I'd
like the usual slicing syntax [::] to be added to all lazy generators
too (to generator expressions, as an automatically created method of
iterators, and of course usable by iterable classes too).
Examples:
 foo = (i for i in range(2, 1000) if all(i % d for d in range(2, i)))
 list(foo[3: 14])
[7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]
 def bar():
...   for i in range(2, 1000):
... if all(i % d for d in range(2, i)):
...   yield i
...
 list(bar()[3: 14])
[7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]



To change: + is a commutative operation, while the concatenation of
two sequences is not. So after using the D language for some time I
have started to not appreciate anymore to use + to concatenate strings
and lists. D language uses ~ for such operation (this isn't a perfect
symbol, because I don't have it on my keyword, so on Windows I have to
type ALT+126 to insert it, or I have to redefine/remap a keyboard
key).
D also has a specific operator that can be overloaded: opCat, opCat_r
and opCatAssign, that map to ~ and ~= (the _r is the inverted order,
like the __radd__):
http://www.digitalmars.com/d/2.0/operatoroverloading.html#Binary
So if you define a vector-like collection you can define both opAdd
and opCat, the first may the sum between two vectors and the opCat is
their joining.


To add: in Python3 you use lazy constructs much more often, so
itertools.chain may become more used. So it may be good to have chain
as built-in. But then it can be good to have a better syntax support
too. So I'd like all lazy iterables to support chaining. If you use
the ~ operator you can write:
range(100) ~ (i for i in range(2, 1000) if all(i % d for d in range(2,
i)))
(I have implemented most of itertools in D language, and I have added
this ~ operator to all lazy constructs, plus I have added an easy way
to add it to user-defined lazy iterables).


Unladen Swallow for official CPython 2.x/3.x: yes, thank you, if it
will be good enough. It can be what Psyco isn't able to become, and
what PyPy has so far failed to be (PyPy seems Open Souce public-money-
funded vaporwere that has tried to do too much).


To add again: tuple unpacking in function arguments: it's handy, hi-
level, de-clutters the code and shortens it too.


To change: I'd like {:} as empty dict literal, and {} as empty set
literal.


To do nothing: probably I will never fully like the syntax of tuple
literals. It's not clean. But in practice I can live with it, and I
have so far failed to invent a better syntax. The main problem is that
ASCII (and keyboards too, maybe) was created for business purposes and
it has too few delimiters. While the sytax for lists: [] [1] [1, 2, 3]
is perfect.

To add: I use defaultdicts often enough, so I may even like to see it
as built-in. But this isn't essential, using the import from the
collections module is usually acceptable.

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


Re: Sending SMS using python script

2009-04-02 Thread Matteo
I use a programme, written in Python, which sends sms through the sms
providers. You might want to have a look to the source code:

http://www.moioli.net/Progetti___1/MoioSMS___Messaggi_GRATIS_da_Internet22.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass one HTML values to another HTML

2009-04-02 Thread Gabriel Genellina

En Tue, 31 Mar 2009 08:27:18 -0300, Kalyan kalyan...@gmail.com escribió:

   by using python and google app engine how can i pass one HTML values  
to

another HTML  .. i am very new to Python programing

Example :
 in one HTML i entered Name and Address fields and i submit the page at  
that
time i want to see those two values in another HTML page.. please reply  
me..


You don't. The first page saves data into a database (datastore in
AppEngine). The second page retrieves data from the datastore. Both pages
aren't directly connected.

There are many tutorials available about AppEngine, you may start here:
http://code.google.com/intl/en/appengine/docs/

--
Gabriel Genellina

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


Re: Hands on Python - Problem with Local Cgi Server

2009-04-02 Thread Gabriel Genellina

En Tue, 31 Mar 2009 09:56:48 -0300, Gary Wood python...@sky.com escribió:


I have the DOS box with the message
Localhost CGI server started

But when i try this I get the Windows Error
Failed to Connect
  The connection was refused when attempting to contact localhost:8080.


Try a different port instead of 8080 (e.g. 8765) both in the browser
address and the Python script.


The py file brings up the DOS box as if its running ok


And you don't see any error message in the console?
It doesn't close automatically?

--
Gabriel Genellina

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


Re: pygame and socket.recv

2009-04-02 Thread Hendrik van Rooyen
Aaron Brady cast...@gmail.com  wrote:


 Hi,
 
 I tried writing a small game on a pygame layer.  The graphics are
 fine, and at the moment, it is not graphics intensive.  It is multi-
 player, and for the communication, I am sending a pickle string across
 a LAN, once per frame.

How big is this pickle - i.e. how many packets does it translate to
on the wire, given that an ethernet packet is less than 1500 bytes?

What is the maximum number of full size packets that a simple 
echo server will echo per second on your setup?  I predict that
you will find that this is far less than what a calculation based on 
the bit rate will suggest...

 
 I'm observing some latency.  It seems that socket.recv isn't
 performing consistently.  The server is using time.clock and
 time.sleep to keep the frame rate at 40 frames per second.  Latency
 occurred regardless of whether the connection was ethernet or
 wireless, although worse with wireless.

What does some latency mean? - barely visible jitter, or a half
second freeze?

What do you do when the total round trip time takes longer
than your target of one fortieth of a second?

The fact that wireless is worse (54Mb/s? - down from 100Mb/s) 
makes me think you are running out of bandwidth, or that the 
LAN is busy and that the bandwidth is wasted on collisions.

What happens when you drop the frame rate to 20 per second?
(it is parameterised, isn't it?)

 
 Does anyone have any hints or suggestions?  I am on Windows XP.

What else is running on the machines at the same time? - your game
may be sucking at the hind tit of processor time...

- Hendrik

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


Re: Help for Toplevel

2009-04-02 Thread Gabriel Genellina
En Wed, 01 Apr 2009 21:55:52 -0300, Muddy Coder cosmo_gene...@yahoo.com  
escribió:



I have a problem of handling Toplevel window. Basically, I wrote a
listbox viewer with scrollbars, and saved in file listbo.py. Then in
my main GUI window, with menu, I need to launch the listbox viewer, in
a new window. Obviously, a Toplevel window is needed. But, I failed at
passing parameters over to Toplevel window. Please take a look at my
code:

Listbox viewer:
class ScrolledList(Frame):
def __init__(self, options, parent=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makeWidgets(options)

In my main GUI:
from XXX import ScrolledList
class Foo:
 def __init__(self):
 ...
 def call_listbox(self, params):
   new = Toplevel()
   alist = ['foor','bar']
   ScrolledList(new,alist)


shouldn't the last line be ScrolledList(alist,new)?

--
Gabriel Genellina

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


Re: python for loop

2009-04-02 Thread Carl Banks
On Apr 1, 11:28 pm, Hrvoje Niksic hnik...@xemacs.org wrote:
 Carl Banks pavlovevide...@gmail.com writes:
  This is unforgiveable, not only changing the indexing semantics of
  Python (because a user would have NO CLUE that something underlying
  has been changed, and thus it should never be done), but also for
  the needless abuse of exec.

 Then I guess you'd fire Guido, too -- from socket.py:

 class _socketobject(object):
     [...]
     _s = (def %s(self, *args): return self._sock.%s(*args)\n\n
           %s.__doc__ = _realsocket.%s.__doc__\n)
     for _m in _socketmethods:
         exec _s % (_m, _m, _m, _m)
     del _m, _s

Damn straight I would, recklessly using exec like he owns the language
or something.


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


Re: python for loop

2009-04-02 Thread John O'Hagan
On Thu, 2 Apr 2009, Steven D'Aprano wrote:
 On Thu, 02 Apr 2009 04:23:32 +, John O'Hagan wrote:
  Beyond being part of a conventionally-ordered set of keys, what can an
  ordinality of zero actually mean? (That's a sincere question.)


[snip erudite definition of cardinality]

 For non-infinite sets, you can treat ordinal numbers and cardinal numbers
 as more or less identical. So an ordinality of zero just means the number
 of elements of something that doesn't exist.

This is the bit I don't get - I had thought of ordinality as something 
attached to each item - ['a','b','c'] has a cardinality of 3, and elements of 
ordinality 1, 2 and 3 (first,second, third) respectively. So it's possible to 
have a cardinality of zero (an empty sequence does) but only something that 
doesn't exist can have an ordinality of zero; as soon as there is an item, 
its ordinality is 1. Shoot me down, please!

 How that relates to whether indexing should start at one or zero, I have
 no idea.
 
Only insofar as the weirdness of indexing being out of step with 
ordinality/cardinality matters, i.e. not that much. :)

John



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


Re: how to optimize zipimport

2009-04-02 Thread Gabriel Genellina

En Mon, 30 Mar 2009 09:39:20 -0300, Coonay fla...@gmail.com escribió:

On Mar 26, 1:38 pm, John Machin sjmac...@lexicon.net wrote:



Why are you explicitly using the zipimport module? In other words, why
don't you put the full path of the zip file in sys.path and then just
use the normal import module_in_the_zip mechanism? Note that this


i found the the module in the zip reloaded  everytime the code is
called,i mean, say ,first time it take me 1 second to call a method in
the zip,but it take another 1 second to call the mothod for another
time ,and so on


Uh? Which Python version?
Once a module is imported, it isn't loaded again, even from a zip file.
Surely there is another reason for the delay, not the import itself.

--
Gabriel Genellina

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


Re: Display directory pyqt4 and Python

2009-04-02 Thread Dunwitch
On Apr 2, 3:02 am, Diez B. Roggisch de...@nospam.web.de wrote:
 Dunwitch schrieb:



  I've looked around for the answer and have decided to ask an expert
  for the solution. Whats suppose to happen is a user pushes a button
  and displays the directory content in the text edit window on the gui.
  Everything works, apart from the fact that it only shows the last file
  in the directory, not a full listing. Here is the code for reference.
  Any help would be appreciated, I'm missing something simple.
  --
  Dunwitch

  # File : Video Search
  import sys, os, win32net

  from PyQt4 import QtGui, QtCore
  from findVideos import Ui_MainWindow # UI Files from QT Designer

  # New class derived from QMainWindow
  class TestApp(QtGui.QMainWindow):
      def __init__(self):
          QtGui.QMainWindow.__init__(self)
          self.ui = Ui_MainWindow()
          self.ui.setupUi(self)

          # Connect the signals andslots
          QtCore.QObject.connect(self.ui.findFiles,QtCore.SIGNAL(clicked
  ()), self.showVideoFiles)

  #- Code In Question
  -
      def showVideoFiles(self):
          enc7 = ('1.2.3.4\\somefolder')
          fileList=os.listdir(enc7)
          for x in (fileList):
              self.ui.displayVideo.setText(x) # This only shows the last
  file in the directory?

 Of course, if you always only set the *full* text of the displayVideo to
 the current list-item, it will end showing the last set item.

 self.ui.displayVideo(\n.join(fileList))

 should do the trick (of course you can get rid of the for-loop)

 Diez

Thank you! I was having a rough time with that, time to keep digging
deeper in the docs!
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for loop

2009-04-02 Thread Arnaud Delobelle
Steven D'Aprano wrote:

 In set theory, you start by defining the integers like this:

 0 is the cardinality (size) of the empty set, the set with nothing in it.

 1 is the cardinality of the set of empty sets, that is, the set
 containing nothing but the empty set.

 2 is the cardinality of the set of the empty set plus the set of empty
 sets.

 3 is the cardinality of the set containing the empty set, plus the set of
 empty sets, plus the set of (the empty set plus the set of empty sets).

 And so forth, to infinity and beyond.

 Or to put it another way:


 0 = len( {} )
 1 = len( {{}} )
 2 = len( {{}, {{}}} )
 3 = len( {{}, {{}}, {{}, {{}}} )

FWIW this is the way I learnt it AFAIK:

Ordinals
===

0 *is* the empty set
1 *is* the the the singleton composed of the empty set, i.e. {0}
2 *is* the set {0, 1}
3 *is* the set {0, 1, 2}
...
n + 1 := n U {n}

It's nice because:
* the  interval [0, n) is just the number n
* n  m iff n is a subset of m iff n is a member of m

Cardinals
=

A cardinal is an equivalence class under the equivalence relation S ~
S' iff there is a bijection between S and S'.  Obviously, finite
cardinals contain only one ordinal so finite cardinals can be
identified with their ordinal representative.

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


Re: New super python vm

2009-04-02 Thread locoyfeo
 Sounds good, but do you have binaries yet? because i can't compile
 from source distros.

Binaries?? Hmm... ok, I filed a bug.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A design problem I met again and again.

2009-04-02 Thread Martin P. Hellwig

Steven D'Aprano wrote:
cut
If you have too much code in one file, it will upset the balance of the 
spinning hard drive platter, and it will start to wobble and maybe even 
cause a head-crash.


That is why proper designed operating systems, like windows 95,rarely 
write one continuous block but spread the file all over the HD.


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


Re: py2exe fails to make valid exe

2009-04-02 Thread Gabriel Genellina
En Wed, 01 Apr 2009 01:30:39 -0300, prakash jp prakash.st...@gmail.com  
escribió:



On -- python setup.py py2exe

the dist folder is created but the exe creted is not working it throws an
error pythons ps.popen function


Please copy  paste the actual error message and the stack trace.


setup.py:

#python setup.py py2exe
from distutils.core import setup
import py2exe
setup(console=['nameofprg.py'])


This would be the minimal setup.py, and works with most simple programs.  
Note that some modules and libraries have special needs.

What modules do you use in your code?

--
Gabriel Genellina

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


Re: py2exe problem

2009-04-02 Thread Gabriel Genellina
En Wed, 01 Apr 2009 17:51:52 -0300, Wolfgang Forstmeier mail...@supai.de  
escribió:



what kind of error do I have with getting this error at starting my app.
Im am not using IdleConf.GetOption right now.

  Warning: configHandler.py - IdleConf.GetOption -
  problem retrieving configration option 'name'
  from section 'Keys'.
  returning default value: ''


but do you use idle or idlelib in your application?

--
Gabriel Genellina

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


Re: modifying a list element from a function

2009-04-02 Thread Gabriel Genellina
En Mon, 30 Mar 2009 13:19:57 -0300, TP tribulati...@paralleles.invalid  
escribió:

Adrian Dziubek wrote:


Could you explain your high level goal for this? It looks like a very
wicked way of doing things. Have You tried to read the list methods'
documentation? Maybe there you find something you need (like
list.index)?


I have a disambiguation function that modifies a text
contained somewhere in each element of a list. The way this text is
accessed by the function should depend on an external accessor, or  
setter,

so that any list could be processed, in a generic way.


Use a setter function (as oposed to a getter that you used in your  
example). A direct translation woud be:


def set_elem_1(elem, value):
elem[1] = value

def assign(setter, list_elem, new_textvalue):
setter(list_elem, new_textvalue)

assign(set_elem_1, a[0], co)

I imagine that you process the whole list:

for elem in some_list:
  set_elem_1(elem, new_value)

--
Gabriel Genellina

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


Re: pygame and socket.recv

2009-04-02 Thread Tim Wintle
On Wed, 2009-04-01 at 18:45 -0700, Aaron Brady wrote:
 
 My game loop looks like this:
 
 poll events, get 1 at most
 send to server
 wait for server reply
 render entire frame

The look I'm suggesting is:

poll events
write to (non-blocking) socket
render frame
check non-blocking socket and add events to the event queue

 Yes, I am blocking for the data to come down the network.
 Unfortunately, if I use any prediction, I will have to go back and
 un-render the previous frame, then redraw with the new information.
Sounds like that may have to be re-factored slightly, afraid this is why
real-time networked games are tough to make.
 
 40 transmissions per second in each way can't be too much to ask, it's
 just that they have to alternate, up one, down one.
IMO It's very unlikely to be a bandwidth issue. It's more likely to just
be a latency issue.

 
 I don't understand your solution.  I can't picture it for my favorite
 RTS game or the one I'm writing.  Are you saying that the slower
 machine just jumps ahead, and its user just doesn't have the
 opportunity to make moves on the omitted frames?


a) How much to move etc. is decided based on some real-time solution
(not on the number of frames). Ideally all movement methods take a
parameter that is a delta in time. (i.e. 1/40th of a second)

b) That time is the time that is synced across machines - if machine B
has to put it's timer forward 1/50 of a second, you call all the methods
above with a timedelta of 1/50 before continuing.

c) Obviously things like which frame a sprite is on isn't really
necessary for the sake of a game, it's only game state variables that
would be required.

d) If you end up with jumping objects then you can create ghost
objects for the other player's objects. When you get the state of a
foreign object, update the real object with the properties, but draw the
sprite at the position of your ghost object - and every frame move the
ghost object towards the real one a little bit. That gets rid of the
effect of jumping from one place to another, but keeps collision
detection etc. correct wrt the other player.


 
 I am using TCP, socket.SOCK_STREAM.  UDP is a potential solution, but
 it still doesn't fix my main loop.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: python for loop

2009-04-02 Thread Gabriel Genellina
En Wed, 01 Apr 2009 08:04:12 -0300, andrew cooke and...@acooke.org  
escribió:



something i don't think has been mentioned much - if you're using
range() in your python code then you're almost always doing it wrong.

i just grepped lepl and i use range 20 times in 9600 lines of code.  out
of those, all but 3 are in quick and dirty tests or experimental code,
not in the main library itself (which is 6300 lines).

(1) where i need to access two adjacent members of a list, and which has  
a

comment in the code explaining why it is not an error (in other words, i
was so unhappy with my code i needed to leave a note explaining why it  
was

like that)


From your description I guess this range usage could have been avoided,  
using enumerate instead. A silly example:


for i,elem in enumerate(some_list):
  if i0:
prev = some_list[i-1]
print (elem+prev)/2

instead of:

for i in range(1, len(some_list)):
  elem = some_list[i]
  prev = some_list[i-1]
  print ...


(2) a use irrelevant to this discussion because i do not use the value to
an index an array.

(3) in the rather complex implementation of a circular buffer.


I can't tell, but perhaps enumerate() could have been used here too?


so in a small/moderate size library of 6000 lines (including blanks and
comments, but excluding tests and exploratory code) the only time i have
used range with array indices i was either unhappy with the code, or
implementing a complex data structure.


Maybe the ratio is even less than that.

--
Gabriel Genellina

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


Re: A design problem I met again and again.

2009-04-02 Thread Tim Rowe
2009/4/1 一首诗 newpt...@gmail.com:
 Hi all,

 I am a programmer who works with some different kinds of programming
 languages, like python, C++(in COM), action script, C#, etc.

 Today, I realized that, what ever language I use, I always meet a same
 problem and I think I never solve it very well.

 The problem is : how to break my app into functional pieces?

One approach is to go through the specification of the program,
underline all of the significant nouns and try to implement each of
the nouns as a class. That won't take you all the way to a good design
-- some of the resulting classes will be too trivial, and it won't
give you the derived classes you need, but it's a good first step to
breaking a problem down, and might help break your one big class
habit.

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


Re: how to optimize zipimport

2009-04-02 Thread John Machin
On Mar 30, 11:39 pm, Coonay fla...@gmail.com wrote:
 On Mar 26, 1:38 pm, John Machin sjmac...@lexicon.net wrote:

  On Mar 26, 2:06 pm, Coonay fla...@gmail.com wrote:


   On Mar 26, 10:41 am, Coonay fla...@gmail.com wrote:

in my mudule ,i import another mudule from a zip ,

when i call  my mudle method,the module in the zip will be import from
the zip every time,that slow down the operation,

i try to search the some workarodnd or solution but i don't get one,

 i don't use zipimport directly,just like u said i put the zip in the
 sys.path


 i found the the module in the zip reloaded  everytime the code is
 called,i mean, say ,first time it take me 1 second to call a method in
 the zip,but it take another 1 second to call the mothod for another
 time ,and so on


How do you know that it is being reloaded each time a methos is
called?



  Note: it may help when you reply to show a stripped-down version of
  your calling module, sufficient to back up your description of what is
  happening.

We can only guess if you don't show us what is actually happening.
Vague descriptions are not very useful. Show us how exactly you are
importing the modules, how you are calling methods, with timing
calls ...

By the way, have you read this part of the documentation:
Note that if an archive only contains .py files, Python will not
attempt to modify the archive by adding the corresponding .pyc or .pyo
file, meaning that if a ZIP archive doesn't contain .pyc files,
importing may be rather slow.
?

Do you have .pyc files in your ZIP file? If not that would make the
first import slower than it should be.

However second, third, ... imports (if you do any) should be
instantaneous -- unless you are messing about deleting modules from
sys.modules.

And *method* calls should be instantaneous.

Does your app run at the same speed when you have all the modules in a
directory instead of inside a zip file?

Apart from code executed once at app start to inject the path to the
zip file into sys.path, have you made any other changes to accommodate
using import from zip? If so, what changes?

Have you tried running your app from the shell (Windows translation:
in a Command Prompt window) like this:

python -v app_start.py

This will show you all the imports as they happen.

HTH ... but a clear description from you (plus code samples) of
exactly what you are doing woul dhelp a whole lot more.

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


Re: Sending SMS using python script

2009-04-02 Thread Banibrata Dutta
Hi Guptha:
Most SMS providers (you'd be dealing with resellers mostly) have some kind
of HTTP API to send SMS (even bulk SMS, upto a point). So you using standard
Python HTTP module to invoke the SMS provider API.

For SMS service providers, just google thru or search yellow pages in your
region of operation. There are several Global providers as well, who provide
ability to send SMS to almost any country around the world.

As for Matteo's site, it is Italian (I think). Try Google or Altavista
website translation engine, and you should manage to browse thru it.

HTH,
bani


On Thu, Apr 2, 2009 at 4:17 PM, guptha gjango...@gmail.com wrote:

 On Apr 2, 12:41 pm, Matteo tadweles...@gmail.com wrote:
  I use a programme, written in Python, which sends sms through the sms
  providers. You might want to have a look to the source code:
 
  http://www.moioli.net/Progetti___1/MoioSMS___Messaggi_GRATIS_da_Inter...

 Thanks for your reply Matteo
 It will be more helpful if you mention the concept of your programme.
 i.e .How your programme works(I can't understand the posting from your
 site - is not in English)

 As for my knowledge on this subject i can say
 1. The sms send by us will reach SMS center of the service provider
 (example : Airtel , Vodofone etc)
 2. Each service provider has their own SMS center
 3. From SMS center  the message reach to the recipient.

 In this scenario how can i make use of service providers SMS center to
 send my sms
 Is it possible to write our own sms gateway in python to interact with
 all type of sms centers.
 Do we have pay any charge to access  providers SMS center, or comes
 free of cast.

 i supposes Most of mobile carriers offer free Email To SMS gateways
 which can be used to forward simple text emails to a mobile phones.
 Thanks
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
--
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe problem

2009-04-02 Thread Wolfgang Forstmeier

On 02.04.2009 11:34, Gabriel Genellina wrote:

En Wed, 01 Apr 2009 17:51:52 -0300, Wolfgang Forstmeier
mail...@supai.de escribió:


what kind of error do I have with getting this error at starting my app.
Im am not using IdleConf.GetOption right now.

Warning: configHandler.py - IdleConf.GetOption -
problem retrieving configration option 'name'
from section 'Keys'.
returning default value: ''


but do you use idle or idlelib in your application?


Ah yes,

after some research in my code I found the following import

from idlelib.OutputWindow import tkMessageBox

Maybe someone could assist me with fixing that issue,
because I am really new to python and does not exactly know what to do now.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sending SMS using python script

2009-04-02 Thread guptha
On Apr 2, 12:41 pm, Matteo tadweles...@gmail.com wrote:
 I use a programme, written in Python, which sends sms through the sms
 providers. You might want to have a look to the source code:

 http://www.moioli.net/Progetti___1/MoioSMS___Messaggi_GRATIS_da_Inter...

Thanks for your reply Matteo
It will be more helpful if you mention the concept of your programme.
i.e .How your programme works(I can't understand the posting from your
site - is not in English)

As for my knowledge on this subject i can say
1. The sms send by us will reach SMS center of the service provider
(example : Airtel , Vodofone etc)
2. Each service provider has their own SMS center
3. From SMS center  the message reach to the recipient.

In this scenario how can i make use of service providers SMS center to
send my sms
Is it possible to write our own sms gateway in python to interact with
all type of sms centers.
Do we have pay any charge to access  providers SMS center, or comes
free of cast.

i supposes Most of mobile carriers offer free Email To SMS gateways
which can be used to forward simple text emails to a mobile phones.
Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Low level hard drive reading

2009-04-02 Thread Gabriel

Hello,
I have to write linux application that will analyze disk/partition (ext3 
filesystem) on really low level. It has to find/analyze files on the 
disk by reading disk blocks to analyze file's headers to find out file 
type and  then blocks related to file to  get file content. The second 
part have to be searching deleted files by this blocks reading (is this 
even possible?)


Can i do this in python? For example can i open disk image file and read 
it block by block?
Or is there even better solution? .) I tried search web but I wasn't 
successful..


I will appreciate any help. Thank you in advice..

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


Re: A design problem I met again and again.

2009-04-02 Thread andrew cooke
Lawrence D'Oliveiro wrote:
 What are the average size of source files in your project?   If it's
 far lower than 15,000,  don't feel it's a little unbalance?

 Why?

one reason is that it becomes inefficient to find code.  if you structure
code as a set of nested packages, then a module, and finally classes and
methods, then you have a tree structure.  and if you divide the structure
along semantic lines then you can efficiently descend the tree to find
what you want.  if you choose the division carefully you can get a
balanced tree, giving O(log(n)) access time.  in contrast a single file
means a linear scan, O(n).

(i am talking about human use here - people reading and trying to
understand code, perhaps during debugging or code review or whatever).

andrew

(you could argue that the file contents can be sorted in some way - you
could even map from the tree to the file a traversal - but in practice
humans seem to be a lot better at making a series of decisions descending
a tree than holding the entire structure in their head as a sort order)

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


Re: speech recognition help

2009-04-02 Thread Murali kumar
hi all..

I tried following tools by ur advice..

1. cmu sphinx:
   tried and managed run the demo programs.. but the accuracy is
so bad. for that i tried for how to train the grammer. but for that i had no
guidance.. docs give me the headache.. after 2 weeks.. i concluded that it
will not be commercially useful for distributed application.

2. Naturally speaking:
downloads only provided for cost. so no try.

3. windows sapi:
windows provides redistributeable copies. also there are some
python bindings available for to connect this engine. training with each
user is easy in windows sapi ( for that i choosed this.) only limitation is
usage within windows.

so , concluded that using windows sapi..

am i correct?

if u know any best articles/links for using windows sapi from python..
kindly give me that..




On Sat, Mar 21, 2009 at 8:40 PM, Stef Mientki stef.mien...@gmail.comwrote:

 Tim Chase wrote:

 do u know which one
 1. cmu sphinx
 2. natural speaking
 3. windows sapi

 is best ( in accuray and speed ) for predefined vocabulary.. and worth
 for
 learning as well.?


 For a pre-defined vocabulary, they should all be pretty good.  In general
 (for non-predefined vocabularies), I've heard that NS beats both Sphinx and
 SAPI in terms of recognition quality.

 +1

 I haven't seen any comparisons between Sphinx and SAPI.

 Other considerations may also come into play:

  - do you expect all your users to have a copy of NS?  Then you might have
 to look into something other than NS if they won't. Or perhaps NS has a
 developers' toolkit that allows for redistribution when built into your app.

  - do you expect all your users to run Windows (as I type this from my
 Linux box...)?  If not, then SAPI won't be available to your
 Mac/Linux/BSD/BeOS/Amiga/whatever users.

  - do you need TTS (text-to-speech) capabilities as well?  SAPI includes
 them.  (there are other TTS libraries available such as mbrola/festival that
 are available for this if needed)

  - how easy is it to bind to Python?  Sphinx has Python bindings detailed
 on the website.  I can't speak for NS or SAPI.

 both are covered by DragonFly

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

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


Re: Python Goes Mercurial

2009-04-02 Thread Paul Boddie
On 2 Apr, 04:27, Lawrence D'Oliveiro l...@geek-
central.gen.new_zealand wrote:
 In message 7a1dd0d8-1978-470b-

 a80d-57478d7f7...@q16g2000yqg.googlegroups.com, Paul Boddie wrote:
  And I've heard stories of bait and
  switch with Git: you can do XYZ with Git but not with ... followed
  by the discovery that you can't realistically do XYZ with Git, either.

 Cite?

Well, I heard stories rather than read them, so I can't cite them,
but I believe that one argument crafted to favour Git was that it is
great for history editing, but it turns out that it isn't so great, as
the following commentary points out:

You can do it, but as soon as you go to merge with another repo that
had the unedited commit history, you’ll bump into weirdness (and
probably invalidate your whole reason for rebasing, which was to clean
up the history).

 - http://adam.blog.heroku.com/past/2008/6/30/rebasing_is_editing_commits/

I'm sure other people have their own tales of a similar nature.

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


Re: Low level hard drive reading

2009-04-02 Thread Jeremiah Dodds
On Thu, Apr 2, 2009 at 12:36 PM, Gabriel dun...@dreams.sk wrote:

 Hello,
 I have to write linux application that will analyze disk/partition (ext3
 filesystem) on really low level. It has to find/analyze files on the disk by
 reading disk blocks to analyze file's headers to find out file type and
  then blocks related to file to  get file content. The second part have to
 be searching deleted files by this blocks reading (is this even possible?)

 Can i do this in python? For example can i open disk image file and read it
 block by block?
 Or is there even better solution? .) I tried search web but I wasn't
 successful..

 I will appreciate any help. Thank you in advice..

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


I may be wrong, but I'd assume that you could just read by block size,
opening the file that represents the disk in /dev (/dev/sda or similar). I
don't see why you would want to do that to find out file type/headers
though. You should be able to see the contents of deleted files that
haven't been (entirely) overwritten on disk - I believe that when you delete
a file, you really just delete the inode, or reference that tells the
filesystem that there's a file there.

Someone else who's keener on the details of these things will probably come
with better information.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Goes Mercurial

2009-04-02 Thread Jeremiah Dodds
The one thing that makes me want to use git more than any other dvcs is that
you don't have to create a new directory for branches. This may be possible
in other dvcs's , but git is the only one I've seen advertise the
capability.
--
http://mail.python.org/mailman/listinfo/python-list


python installer

2009-04-02 Thread Murali kumar
hi all..

To distribute my application.. what will be the best..?

python installer.. or py2exe..?

using : python 2.6 , wxpython 2.8.9
--
http://mail.python.org/mailman/listinfo/python-list


simple iterator question

2009-04-02 Thread Neal Becker
How do I interleave 2 sequences into a single sequence?

How do I interleave N sequences into a single sequence?


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


Incomplete exception tracebacks when importing from zipped modules

2009-04-02 Thread arve.knud...@gmail.com
I can't seem to get complete tracebacks when modules imported from zip
archives raise exceptions. For instance, consider the following
module:
def i_raise():
raise Exception(Test!)

i_raise()


When I import this module, within a .zip, from a script, I get the
following traceback:
Traceback (most recent call last):
  File tst.py, line 1, in module
import tst_mod
  File build\bdist.win32\egg\tst_mod.py, line 4, in module
  File build\bdist.win32\egg\tst_mod.py, line 2, in i_raise
Exception: Test!


As you can see, the code for each stack entry is omitted. Is this
normal??

traceback.print_exc() has the same problem, BUT; if I happen to call
traceback.print_stack within tst_mod, traceback.print_exc prints a
complete traceback in the calling script (i.e., including source code
per stack frame). Mysterious ..
--
http://mail.python.org/mailman/listinfo/python-list


Re: xml to xhtml

2009-04-02 Thread jud779
On Apr 1, 11:16 am, Joe Riopel goo...@gmail.com wrote:
 On Wed, Apr 1, 2009 at 10:43 AM,  jud...@gmail.com wrote:
  If anyone can give me some guidance what should be the best way to
  generate html/xhtml page using python would be great. I am open to
  other options like xsl or anything else that can make things simple.

 Since you're open to other options, I would take a look at XSLT.

 http://www.w3schools.com/xsl/

XSLT sounds good. I have already created temporary XSL and its working
fine. Still question is how to put up this on web server index.html.
I am planning to create one index.html and call cgi python which in
return produces html page from xml/xsl. Does this sounds like a good
plan??
Is there any other options than the one i describe above. If, then pls
help me out.

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


Re: Python Goes Mercurial

2009-04-02 Thread David Cournapeau
On Thu, Apr 2, 2009 at 9:12 PM, Paul Boddie p...@boddie.org.uk wrote:


 You can do it, but as soon as you go to merge with another repo that
 had the unedited commit history, you’ll bump into weirdness (and
 probably invalidate your whole reason for rebasing, which was to clean
 up the history).

  - http://adam.blog.heroku.com/past/2008/6/30/rebasing_is_editing_commits/

 I'm sure other people have their own tales of a similar nature.

It is explained in this article why rebase can't be used for something
which will be the base for upcoming merges; not all branches are
intended this way (but most public ones are). I would say this shows
one feature which I think matters a lot in git, more than rebasing
itself: multiple branches in a repo, and very cheap branching (in CPU
cost, space and workflow) so that you can use private branches for
experimentation.

cheers,

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


Any library to bind python with Yahoo mail service

2009-04-02 Thread guptha
Hi friends,
I came across libgmail library that can be used to bind python with
Google Gmail's service .Likewise is there any library available to
access the service of Yahoo mail  from python code .
I like to send sms from my application  via Yahoo mail Service .
Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Goes Mercurial

2009-04-02 Thread Kay Schluehr
On 1 Apr., 07:56, Lawrence D'Oliveiro l...@geek-
central.gen.new_zealand wrote:
 In message 35d429fa-5d13-4703-

 a443-6a95c740c...@o6g2000yql.googlegroups.com, John Yeung wrote:
  Here's one that clearly expresses strong antipathy:

   http://mail.python.org/pipermail/python-dev/2009-March/087971.html

 There are lots of GUI- and Web-based front ends to Git. And look at on-line
 services like GitHub and Gitorious. The level of support for it is huge.

Ironically Mercurials most popular UI frontend Tortoise is going to
crash Python tools ( like Wing-IDE ) on Windows. That's a known issue
for about a year and more and the developers are not inclined to fix
it. This doesn't really increase my trust that Mercurials UI tools are
of a higher quality than Git's no matter which platform is used.
--
http://mail.python.org/mailman/listinfo/python-list


Re: simple iterator question

2009-04-02 Thread George Sakkis
On Apr 2, 8:32 am, Neal Becker ndbeck...@gmail.com wrote:

 How do I interleave 2 sequences into a single sequence?

 How do I interleave N sequences into a single sequence?

http://lmgtfy.com/?q=python+interleave+sequences
http://code.activestate.com/recipes/511480/
http://code.activestate.com/recipes/528936/

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


Re: simple iterator question

2009-04-02 Thread andrew cooke
Neal Becker wrote:
 How do I interleave 2 sequences into a single sequence?

 How do I interleave N sequences into a single sequence?

don't know if there's a better way, but

from itertools import izip

def interleave(*doodahs):
  for together in izip(*doodahs):
for single in together:
  yield single

seems like it should work (warning: untried).

will terminate on shortest length doodah.

andrew


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


Re: Python Goes Mercurial

2009-04-02 Thread David Smith
Kay Schluehr wrote:
 On 1 Apr., 07:56, Lawrence D'Oliveiro l...@geek-
 central.gen.new_zealand wrote:
 In message 35d429fa-5d13-4703-

 a443-6a95c740c...@o6g2000yql.googlegroups.com, John Yeung wrote:
 Here's one that clearly expresses strong antipathy:
  http://mail.python.org/pipermail/python-dev/2009-March/087971.html
 There are lots of GUI- and Web-based front ends to Git. And look at on-line
 services like GitHub and Gitorious. The level of support for it is huge.
 
 Ironically Mercurials most popular UI frontend Tortoise is going to
 crash Python tools ( like Wing-IDE ) on Windows. That's a known issue
 for about a year and more and the developers are not inclined to fix
 it. This doesn't really increase my trust that Mercurials UI tools are
 of a higher quality than Git's no matter which platform is used.

The conflict between TortoiseHg and Wing IDE can be fixed by simply
uninstalling the Tortoise Overlays.  You loose the graphic overlay on
folders, but otherwise everything works.

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


Re: pygame and socket.recv

2009-04-02 Thread Aaron Brady
On Apr 2, 1:19 am, Hendrik van Rooyen m...@microcorp.co.za wrote:
 Aaron Brady cast...@gmail.com  wrote:

  Hi,

  I tried writing a small game on a pygame layer.  The graphics are
  fine, and at the moment, it is not graphics intensive.  It is multi-
  player, and for the communication, I am sending a pickle string across
  a LAN, once per frame.

 How big is this pickle - i.e. how many packets does it translate to
 on the wire, given that an ethernet packet is less than 1500 bytes?

The client sends a dictionary to the server.  If it doesn't have any
news, it's an empty dictionary, ~10 bytes.  If it does, it's one or
two entries, a short string to a short string or integer, ~40 bytes
total.

The server sends a dictionary back: { str: str, str: num, str: { int:
X, int: Y, ..., int: Z } }, where X, Y and Z are the dictionaries it
received from the individual clients, ~100 bytes total.  I don't
anticipate this number growing past 1K at later stages in the game,
and I can always make it a fixed-length struct or CSV.

 What is the maximum number of full size packets that a simple
 echo server will echo per second on your setup?  I predict that
 you will find that this is far less than what a calculation based on
 the bit rate will suggest...

The test on localhost-localhost and back reached 700 cycles per
second.  The test on localhost-other machine and back ranged 100-300
cycles per second, IIRC recently.

  I'm observing some latency.  It seems that socket.recv isn't
  performing consistently.  The server is using time.clock and
  time.sleep to keep the frame rate at 40 frames per second.  Latency
  occurred regardless of whether the connection was ethernet or
  wireless, although worse with wireless.

 What does some latency mean? - barely visible jitter, or a half
 second freeze?

I've got a rather amateur loop keeping the frame rate capped at 40
fps.  The game won't exceed that, but when it drops /below/ it, it can
fall to 30 or 20 or 15 fps.  That was just a per-second averaging
calculation; the bad freezes are about half a second.  I'll try to get
a reading of individual calls to 'recv' that are themselves below the
threshold.

Here's the loop: wait half the time left, then half that, then half
that, and so on, until less than 1/1000th second is left.

while 1:
tcurr= time.clock( )
delay= ( ( tprev+ secsperframe )- tcurr )* 0.5
if delay 0.001:
break
time.sleep( delay )
tprev= tcurr

I don't know if it could be responsible.  Would a mutex or Queue be
better using a threading.Timer?

 What do you do when the total round trip time takes longer
 than your target of one fortieth of a second?

I want to know that too!

 The fact that wireless is worse (54Mb/s? - down from 100Mb/s)
 makes me think you are running out of bandwidth, or that the
 LAN is busy and that the bandwidth is wasted on collisions.

Another party (friend, participant, colleague, etc.) and I tested it
with wires.  It improved it, but didn't eliminate it.

 What happens when you drop the frame rate to 20 per second?
 (it is parameterised, isn't it?)

Yes.  It still gets half-second freezes, and the aggregate per-second
average still reads as low as 15.  Yes it's parameterized, in the
'secsperframe' variable, seconds per frame, or fps**-1.

  Does anyone have any hints or suggestions?  I am on Windows XP.

 What else is running on the machines at the same time? - your game
 may be sucking at the hind tit of processor time...

On one test, one machine ran only the server, and the other machine
ran only one client!  That is where the numbers I gave were
generated.  When one machine runs a server and a client, it's not much
worse, though I didn't try that since I moved the delay loop to the
client side.

Thank you for your questions!
--
http://mail.python.org/mailman/listinfo/python-list


Class methods read-only by default?

2009-04-02 Thread Emanuele D'Arrigo
Hi Everybody!

I just tried this:

 class C(object):
...def method(self):
...pass
...
 c = C()
 delattr(c, method)

Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'C' object attribute 'method' is read-only

How come? Who told the class to make the method read-only? I didn't!

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


Re: Sending SMS using python script

2009-04-02 Thread Matteo
I don't really know, because I didn't write it myself ;)
I think it basically logs in into a service provider site with pycurl,
follows the right links, reads captcha's and writes an SMS, which is
then sent by the provider itself.

I can give you the direct link to the source code from the same site:
http://www.moioli.net/files/MoioSMS2.18-src.zip
--
http://mail.python.org/mailman/listinfo/python-list


Re: simple iterator question

2009-04-02 Thread KDr2
 def xl(a):
... return list(reduce(lambda x,y:x+y,zip(*a)))
...
 xl([[1,2],[3,4]])
[1, 3, 2, 4]

like this?

Best Regards,
   -- KDr2, at x-macro.com.


On Thu, Apr 2, 2009 at 8:32 PM, Neal Becker ndbeck...@gmail.com wrote:

 How do I interleave 2 sequences into a single sequence?

 How do I interleave N sequences into a single sequence?


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

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


Re: simple iterator question

2009-04-02 Thread John O'Hagan
On Thu, 2 Apr 2009, Neal Becker wrote:
 How do I interleave 2 sequences into a single sequence?

 How do I interleave N sequences into a single sequence?

Here's one way:

def interleave(*args):
for n in range(min(len(i) for i in args)) :
for i in args:
yield i[n]

HTH,

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


Python Client for Second Life

2009-04-02 Thread Lawson English
hey all, a reminder for anyone interested in the python second life 
client, pyogp, we have our own irc channel on freenode called pyogp, and 
our own in-world discussion group, also called pyogp.


Lawson (Saijanai in Second Life)
___
mmox mailing list
m...@ietf.org
https://www.ietf.org/mailman/listinfo/mmox

pyogp mailing list
https://lists.secondlife.com/cgi-bin/mailman/listinfo/pyogp
http://wiki.secondlife.com/wiki/Pyogp
--
http://mail.python.org/mailman/listinfo/python-list


Python wrapper for Ebay

2009-04-02 Thread nagraj
Hi

Can anyone suggest me which is the best python wrapper for Ebay APIs?
I've currently gone thru PyEbay and EasyBay. But have not seen much
activities on them since couple of years. Also I'm not able to find
any particular forums or discussion groups. I could find PyAWS for
Amazon which is really helpful. I'm wondering whether I shud write the
wrapper classes all by myself in this case?

Please suggest.

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


Re: Class methods read-only by default?

2009-04-02 Thread andrew cooke
Emanuele D'Arrigo wrote:
 Hi Everybody!

 I just tried this:

 class C(object):
 ...def method(self):
 ...pass
 ...
 c = C()
 delattr(c, method)

 Traceback (most recent call last):
   File stdin, line 1, in module
 AttributeError: 'C' object attribute 'method' is read-only

 How come? Who told the class to make the method read-only? I didn't!

i'm just guessing, but i suspect this is because of how it's implemented. 
class methods don't exist in the instance.  instead, they exist in the
class (which is itself an object, hence metaclasses etc), and the
instance forwards them to the class for evaluation (if the term vtable
makes any sense to you then the vtable for class methods is owned by the
class, not the instance).

so you may be able to delete the method from the class, but then it will
affect all instances.  you can't delete it from one instance because it's
not in that instance.

as i said, just a guess, based on vague ideas about how python works.

andrew


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


Re: Help with dict and iter

2009-04-02 Thread Sion Arrowsmith
mattia  ger...@gmail.com wrote:
 So, I'm looking for a way to reset the next() value every 
time i complete the scan of a list.

itertools.cycle ?

-- 
\S

   under construction

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


Re: Low level hard drive reading

2009-04-02 Thread Kushal Kumaran
On Thu, 02 Apr 2009 13:36:24 +0200
Gabriel dun...@dreams.sk wrote:

 Hello,
 I have to write linux application that will analyze disk/partition
 (ext3 filesystem) on really low level. It has to find/analyze files
 on the disk by reading disk blocks to analyze file's headers to find
 out file type and  then blocks related to file to  get file content.
 The second part have to be searching deleted files by this blocks
 reading (is this even possible?)
 
 Can i do this in python? For example can i open disk image file and
 read it block by block?
 Or is there even better solution? .) I tried search web but I wasn't 
 successful..
 
 I will appreciate any help. Thank you in advice..
 

Searching for ext3 recovering deleted files has this as one of the
results:

http://projects.izzysoft.de/trac/ext3undel/

That said, if you want to read the disk, you can simply open the
appropriate device (maybe one of the /dev/[hs]d*) and read it.  You'll
need root access, and knowledge of the on-disk layout of the
filesystem.

Also, writing to the wrong place into this file can badly mess up your
filesystem, or even partition table.  A good backup of the entire disk
is a very good idea.

-- 
kushal

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


Re: pygame and socket.recv

2009-04-02 Thread Aaron Brady
On Apr 2, 4:13 am, Tim Wintle tim.win...@teamrubber.com wrote:
 On Wed, 2009-04-01 at 18:45 -0700, Aaron Brady wrote:

  My game loop looks like this:

  poll events, get 1 at most
  send to server
  wait for server reply
  render entire frame

 The look I'm suggesting is:

 poll events
 write to (non-blocking) socket
 render frame
 check non-blocking socket and add events to the event queue

  Yes, I am blocking for the data to come down the network.
  Unfortunately, if I use any prediction, I will have to go back and
  un-render the previous frame, then redraw with the new information.

 Sounds like that may have to be re-factored slightly, afraid this is why
 real-time networked games are tough to make.

+1 understatement of the week.  Are you saying that there aren't that
many out there?  I.e., if average and worst-case packet times were
faster, there would be more?

  40 transmissions per second in each way can't be too much to ask, it's
  just that they have to alternate, up one, down one.

 IMO It's very unlikely to be a bandwidth issue. It's more likely to just
 be a latency issue.

The actual mechanics can't be that hard.  If I had a dedicated pathway
that the OS didn't even intervene in, 40 fps would be a trifle; and I
would also have a custom OS.  'Doom 25: Now including operating
system!'

  I don't understand your solution.  I can't picture it for my favorite
  RTS game or the one I'm writing.  Are you saying that the slower
  machine just jumps ahead, and its user just doesn't have the
  opportunity to make moves on the omitted frames?

 a) How much to move etc. is decided based on some real-time solution
 (not on the number of frames). Ideally all movement methods take a
 parameter that is a delta in time. (i.e. 1/40th of a second)

 b) That time is the time that is synced across machines - if machine B
 has to put it's timer forward 1/50 of a second, you call all the methods
 above with a timedelta of 1/50 before continuing.

I must be writing a very peculiar game.  Frame-for-frame matching is
important.  The game space is a grid, a logical space, zero mass, not
a real one.  I started to tell Terry yesterday that arbitrary
discontinuities in position and momentum are possible.

Your method ensures than an object is moving at a constant rate,
distance over time, as it is perceived by the player.  I want
something like it, so that if I'm anticipating an upcoming turn, I can
press the key at the time I want, and the model on every machine is
informed, regardless of what the graphics did in the interim.

 c) Obviously things like which frame a sprite is on isn't really
 necessary for the sake of a game, it's only game state variables that
 would be required.

Yes, this.

 d) If you end up with jumping objects then you can create ghost
 objects for the other player's objects. When you get the state of a
 foreign object, update the real object with the properties, but draw the
 sprite at the position of your ghost object - and every frame move the
 ghost object towards the real one a little bit. That gets rid of the
 effect of jumping from one place to another, but keeps collision
 detection etc. correct wrt the other player.

It's just that if you register a collision in between the time that
one object has changed its position and momentum, and the time you
learn about it, you have to retroactively edit the collision, restore
hit points, and recalculate the other object's position and momentum,
to name a few.  For example, if you hit some kind of power-up that
warps your position to another place, you can't get hit by a weapon
that is colliding with your old extrapolated place.  Maybe each
collision has to take a branch: if the collision turns out to have
succeeded, proceed from state X-Y1, else from state X-Y2.  That
sounds combinatoric, when multiple collisions may or may not be
interacting.  { (X,Y)-(X1,Y1), (X,Y)-(X1,Y2), (X,Y)-(X2,Y1), (X,Y)-
(X2,Y1) }.  Or, you could just freeze the models of some objects
pending update, and continue with the models of the rest.

This is all not to mention the balance between pre-transmission and
post-transmission calculations, which is a time-space trade-off IMCAC
if my calculations are correct.
--
http://mail.python.org/mailman/listinfo/python-list


Re: complaints about no replies last week

2009-04-02 Thread Aaron Brady
On Mar 31, 4:34 pm, Arnaud Delobelle arno...@googlemail.com wrote:
 a...@pythoncraft.com (Aahz) writes:
  Arnaud Delobelle  arno...@googlemail.com wrote:

 There are no comments - I don't have the time to add any, sorry!

  The margin is too small to contain the proof?

 I wish I could come up with such a resilient conjecture!

 Ah but in this case, the proof is in the program, as Curry-Howard may
 well have said.

Is it simple, complex, or complicated?  IS IT FLAT OR NESTED!  /
shouting
--
http://mail.python.org/mailman/listinfo/python-list


Re: Class methods read-only by default?

2009-04-02 Thread Steven D'Aprano
On Thu, 02 Apr 2009 06:07:20 -0700, Emanuele D'Arrigo wrote:

 Hi Everybody!
 
 I just tried this:
 
 class C(object):
 ...def method(self):
 ...pass
 ...
 c = C()
 delattr(c, method)
 
 Traceback (most recent call last):
   File stdin, line 1, in module
 AttributeError: 'C' object attribute 'method' is read-only
 
 How come? Who told the class to make the method read-only? I didn't!

Nobody told the class to make the method read-only, because it isn't. You 
are trying to delete an *instance* attribute (one that lives inside the 
instance dictionary) but the method is a *class* attribute (it lives 
inside the class dictionary).


 class C(object):
... def method(self): pass
...
 c = C()
 C.__dict__.keys()  # class attributes
['__dict__', '__module__', '__weakref__', 'method', '__doc__']
 c.__dict__.keys()  # instance attributes
[]

To remove the method, this will work:

delattr(C, 'method')  # call on the class


But beware, if method is defined in a superclass of C, then that won't 
work either.

This is a little confusing, it is a definite Gotcha, because getattr 
succeeds. But notice:

 getattr(c, 'method')
bound method C.method of __main__.C object at 0x82ec14c

See how it tells you that c.method is actually C.method?


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


Re: Any library to bind python with Yahoo mail service

2009-04-02 Thread Kushal Kumaran
On Thu, 2 Apr 2009 05:45:18 -0700 (PDT)
guptha gjango...@gmail.com wrote:

 Hi friends,
 I came across libgmail library that can be used to bind python with
 Google Gmail's service .Likewise is there any library available to
 access the service of Yahoo mail  from python code .
 I like to send sms from my application  via Yahoo mail Service .
 Thanks

You can always simply use the mail handling libraries available in
python.  I'm not familiar with sms sending facilities provided by
Yahoo, but if it only requires sending a mail, you can simply use
smtplib.

-- 
kushal

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


Re: simple iterator question

2009-04-02 Thread Sion Arrowsmith
Neal Becker  ndbeck...@gmail.com wrote:
How do I interleave 2 sequences into a single sequence?

How do I interleave N sequences into a single sequence?

itertools.chain(*itertools.izip(*Nsequences))


-- 
\S

   under construction

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


Re: simple iterator question

2009-04-02 Thread andrew cooke
Sion Arrowsmith wrote:
 Neal Becker  ndbeck...@gmail.com wrote:
How do I interleave 2 sequences into a single sequence?

How do I interleave N sequences into a single sequence?

 itertools.chain(*itertools.izip(*Nsequences))

aha!  thanks.  andrew

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


Re: A design problem I met again and again.

2009-04-02 Thread Steven D'Aprano
On Thu, 02 Apr 2009 07:45:46 -0400, andrew cooke wrote:

 Lawrence D'Oliveiro wrote:
 What are the average size of source files in your project?   If it's
 far lower than 15,000,  don't feel it's a little unbalance?

 Why?
 
 one reason is that it becomes inefficient to find code.  if you
 structure code as a set of nested packages, then a module, and finally
 classes and methods, then you have a tree structure.  and if you divide
 the structure along semantic lines then you can efficiently descend the
 tree to find what you want.  if you choose the division carefully you
 can get a balanced tree, giving O(log(n)) access time.  in contrast a
 single file means a linear scan, O(n).

What's n supposed to be? The number of lines in a file? No, I don't think 
so -- you said it yourself: if you divide the structure along semantic 
lines then you can efficiently descend the tree to find what you want. 
Not arbitrarily divide the files after n lines. If one semantic 
division requires 15,000 lines, and another semantic division requires 15 
lines, then the most efficient way to divide the code base is 15,000 
lines in one module and 15 lines in another.

Admittedly, I'd expect that any python module with 15,000 lines 
(approximately 900KB in size) could do with some serious refactoring into 
modules and packages, but hypothetically it could genuinely make up a 
single logical, semantic whole. That's only four and a half times 
larger than decimal.py.

I can't imagine what sort of code would need to be that large without 
being divided into modules, but it could be possible.



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


Re: Creating huge data in very less time.

2009-04-02 Thread Grant Edwards
On 2009-04-02, Tim Roberts t...@probo.com wrote:
 Grant Edwards inva...@invalid wrote:

On 2009-03-31, Dave Angel da...@ieee.org wrote:

 They were added in NTFS, in the Windows 2000 timeframe, to my
 recollection.

NTFS was added in NT 3.1 (which predates Win2K by 7-8 years).

 Although that's true, you didn't read his sentence.

I read it, but interpreted it differently.  To me that phrase
X was added in NTFS means X was added when NTFS was added.

 Sparse file support was not added to NTFS until Windows 2000,
 exactly as he said.

Now that you've explained what was meant, I would have written
it They were added to NTFS in the Windows 2000 timeframe.

-- 
Grant Edwards   grante Yow! Well, O.K.
  at   I'll compromise with my
   visi.comprinciples because of
   EXISTENTIAL DESPAIR!
--
http://mail.python.org/mailman/listinfo/python-list


Re: simple iterator question

2009-04-02 Thread Arnaud Delobelle
Neal Becker ndbeck...@gmail.com writes:

 How do I interleave 2 sequences into a single sequence?

Here's a way:

 a = [1,2,3,4]
 b = [5,6,7,8]
 [x for S in zip(a, b) for x in S]
[1, 5, 2, 6, 3, 7, 4, 8]

 How do I interleave N sequences into a single sequence?

In the same way as above.

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


Re: Low level hard drive reading

2009-04-02 Thread Grant Edwards
On 2009-04-02, Gabriel dun...@dreams.sk wrote:

 For example can i open disk image file and read it block by
 block?

Sure.  Just open the file, seek to where you want and read it.
Or, it'll probably be simpler to just mmap the file and then
grab blocks using slices as indexes.

-- 
Grant Edwards   grante Yow! World War III?
  at   No thanks!
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: pygame and socket.recv

2009-04-02 Thread Hendrik van Rooyen
Aaron Brady cast@gmail.com wrote:


On Apr 2, 1:19 am, Hendrik van Rooyen m...@microcorp.co.za wrote:

 Aaron Brady cast...@gmail.com wrote:


8  stuff showing small packets and adequate bandwidth --

 What does some latency mean? - barely visible jitter, or a half
 second freeze?

I've got a rather amateur loop keeping the frame rate capped at 40
fps.  The game won't exceed that, but when it drops /below/ it, it can
fall to 30 or 20 or 15 fps.  That was just a per-second averaging
calculation; the bad freezes are about half a second.  I'll try to get
a reading of individual calls to 'recv' that are themselves below the
threshold.

Here's the loop: wait half the time left, then half that, then half
that, and so on, until less than 1/1000th second is left.

while 1:
tcurr= time.clock( )
delay= ( ( tprev+ secsperframe )- tcurr )* 0.5
if delay 0.001:
break
time.sleep( delay )
tprev= tcurr

This will hand control to the OS more than once.  It may be 
worth it to try making a target completion date and to then
sleep the difference between now and then, once.

I don't know if it could be responsible.  Would a mutex or Queue be
better using a threading.Timer?

Good question - I don't know.  I am just assuming that the OS is somehow
giving you short shrift in its task scheduling.  Does anybody know what
the granularity of task swapping is in XP?  - Forty per second is only 25
milliseconds - Is a task more or less guaranteed to get a bite at the cherry 
in that time?  We need a windoze expert to tell us what the minimum time is
for swapping a task out and in.   If you are less than that time away from
your scheduled completion date, it makes no sense to sleep...


 What do you do when the total round trip time takes longer
 than your target of one fortieth of a second?

I want to know that too!

Well if you were to know that it has happened, it would make
sense to do the stuff immediately, and to reschedule your
future target completion dates

8  more stuff showing adequate bandwidth 

- Hendrik




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


Re: Python3: to add, remove and change

2009-04-02 Thread MRAB

bearophileh...@lycos.com wrote:

Here an informal list in random order of things that I may like to add
or to remove to/from Python3.x+.


[snip]

To add: Python3 is much more lazy-flavour than Python 2.x (see lazy
range, lazy dict views, etc). So islice becomes even more useful and
more commonly used. So I may like to have a lazy slicing as built-in.
But if you make it built-in, then why not add a syntax too? So I'd
like the usual slicing syntax [::] to be added to all lazy generators
too (to generator expressions, as an automatically created method of
iterators, and of course usable by iterable classes too).
Examples:

foo = (i for i in range(2, 1000) if all(i % d for d in range(2, i)))
list(foo[3: 14])

[7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]

def bar():

...   for i in range(2, 1000):
... if all(i % d for d in range(2, i)):
...   yield i
...

list(bar()[3: 14])

[7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]


How about adding [x : y : z] as a shortcut for range(x, y, z)?

 foo = (i for i in [2 : 1000] if all(i % d for d in [2 : i]))




To change: + is a commutative operation, while the concatenation of
two sequences is not. So after using the D language for some time I
have started to not appreciate anymore to use + to concatenate strings
and lists. D language uses ~ for such operation (this isn't a perfect
symbol, because I don't have it on my keyword, so on Windows I have to
type ALT+126 to insert it, or I have to redefine/remap a keyboard
key).
D also has a specific operator that can be overloaded: opCat, opCat_r
and opCatAssign, that map to ~ and ~= (the _r is the inverted order,
like the __radd__):
http://www.digitalmars.com/d/2.0/operatoroverloading.html#Binary
So if you define a vector-like collection you can define both opAdd
and opCat, the first may the sum between two vectors and the opCat is
their joining.


-1.


To add: in Python3 you use lazy constructs much more often, so
itertools.chain may become more used. So it may be good to have chain
as built-in. But then it can be good to have a better syntax support
too. So I'd like all lazy iterables to support chaining. If you use
the ~ operator you can write:
range(100) ~ (i for i in range(2, 1000) if all(i % d for d in range(2,
i)))
(I have implemented most of itertools in D language, and I have added
this ~ operator to all lazy constructs, plus I have added an easy way
to add it to user-defined lazy iterables).


For lazy concatenation/chaining, perhaps +1.


To add again: tuple unpacking in function arguments: it's handy, hi-
level, de-clutters the code and shortens it too.


+1.


To change: I'd like {:} as empty dict literal, and {} as empty set
literal.


+1.


To do nothing: probably I will never fully like the syntax of tuple
literals. It's not clean. But in practice I can live with it, and I
have so far failed to invent a better syntax. The main problem is that
ASCII (and keyboards too, maybe) was created for business purposes and
it has too few delimiters. While the sytax for lists: [] [1] [1, 2, 3]
is perfect.


[snip]
Could you wrap tuples in ...? I'd need to check the syntax to see
whether it's unambiguous.
--
http://mail.python.org/mailman/listinfo/python-list


Tab completion

2009-04-02 Thread Steven D'Aprano
Does anyone use the tab-completion recipe in the docs?

http://docs.python.org/library/rlcompleter.html#module-rlcompleter

suggests using this to enable tab-completion:

try:
import readline
except ImportError:
print Module readline not available.
else:
import rlcompleter
readline.parse_and_bind(tab: complete)

which is all very nice, but it makes it rather difficult to indent code 
blocks:

 def func(x):
...
Display all 174 possibilities? (y or n)


I like tab-completion, but I'd rather not be reduced to typing spaces for 
indents in the interpreter. What do other people do?

Can I bind Ctrl-tab to the completion instead of regular tab? I tried 
readline.parse_and_bind(C-tab: complete) but it still completes on 
regular tab.

The GNU readline library claims that M-tab (which I guess is Alt-tab) 
will enter a tab character. Problem is that Alt-tab is intercepted by my 
window manager for something else.

Any other suggestions or hints?

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


Re: A design problem I met again and again.

2009-04-02 Thread 一首诗
You get it.  Sometimes I feel that my head is trained to work in a
procedural way.  I use a big class just as a container of functions.

About the data-based approach, what if these functions all shares a
little data, e.g. a socket, but nothing else?

On Apr 2, 5:58 am, Carl Banks pavlovevide...@gmail.com wrote:
 On Apr 1, 12:44 am, 一首诗 newpt...@gmail.com wrote:

  I got the same problem when writing C#/C++ when I have to provide a
  lot of method to my code's user.  So I create a big class as the entry
  point of my code.  Although these big classes doesn't contains much
  logic,  they do grow bigger and bigger.

 This seems to be a classic result of code-based organization, that
 is, you are organizing your code according to how your functions are
 used.  That's appropriate sometimes.  Procedural libraries are often
 organized by grouping functions according to use.  The os module is a
 good example.

 However, it's usually much better to organize code according to what
 data it acts upon: data-based organization.  In other words, go
 though your big class and figure out what data belongs together
 conceptually, make a class for each conceptual set of data, then
 assign methods to classes based on what data the methods act upon.

 Consider the os module again.  It's a big collection of functions, but
 there are a group of functions is os that all act on a particular
 piece of data, namely a file descriptor.  This suggests tha all the
 functions that act upon file descriptors (os.open, os.close, os.seek,
 etc.) could instead be methods of a single class, with the file
 descriptor as a class member.

 (Note: the os library doesn't do that because functions like os.open
 are supposed to represent low-level operations corresponding to the
 underlying system calls, but never mind that. Ordinarily a bunch of
 functions operating on common data should be organized as a class.)

 Carl Banks

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


Re: pygame and socket.recv

2009-04-02 Thread Miguel Prada
I don't know if this might be causing your problem, but most socket
implementations use quite a big buffer for incoming data by default. I
had a lot of trouble with another real-time networked application
until I realised this. Reducing this buffer to the minimum helped a
lot in my case. Also, I would strongly recommend using UDP instead of
TCP.

BTW, does anyone know if any good bibliography about real-time
networked games, or real-time networked general applications?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tab completion

2009-04-02 Thread Chris Rebert
On Thu, Apr 2, 2009 at 7:59 AM, Steven D'Aprano
st...@remove-this-cybersource.com.au wrote:
 Does anyone use the tab-completion recipe in the docs?

 http://docs.python.org/library/rlcompleter.html#module-rlcompleter

 suggests using this to enable tab-completion:

 try:
    import readline
 except ImportError:
    print Module readline not available.
 else:
    import rlcompleter
    readline.parse_and_bind(tab: complete)

 which is all very nice, but it makes it rather difficult to indent code
 blocks:

 def func(x):
 ...
 Display all 174 possibilities? (y or n)


 I like tab-completion, but I'd rather not be reduced to typing spaces for
 indents in the interpreter. What do other people do?

 Can I bind Ctrl-tab to the completion instead of regular tab? I tried
 readline.parse_and_bind(C-tab: complete) but it still completes on
 regular tab.

 The GNU readline library claims that M-tab (which I guess is Alt-tab)
 will enter a tab character. Problem is that Alt-tab is intercepted by my
 window manager for something else.

 Any other suggestions or hints?

You could write a ~/.inputrc to change the bindings.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


PEP 382: Namespace Packages

2009-04-02 Thread Martin v. Löwis
I propose the following PEP for inclusion to Python 3.1.
Please comment.

Regards,
Martin

Abstract


Namespace packages are a mechanism for splitting a single Python
package across multiple directories on disk. In current Python
versions, an algorithm to compute the packages __path__ must be
formulated. With the enhancement proposed here, the import machinery
itself will construct the list of directories that make up the
package.

Terminology
===

Within this PEP, the term package refers to Python packages as defined
by Python's import statement. The term distribution refers to
separately installable sets of Python modules as stored in the Python
package index, and installed by distutils or setuptools. The term
vendor package refers to groups of files installed by an operating
system's packaging mechanism (e.g. Debian or Redhat packages install
on Linux systems).

The term portion refers to a set of files in a single directory (possibly
stored in a zip file) that contribute to a namespace package.

Namespace packages today


Python currently provides the pkgutil.extend_path to denote a package as
a namespace package. The recommended way of using it is to put::

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

int the package's ``__init__.py``. Every distribution needs to provide
the same contents in its ``__init__.py``, so that extend_path is
invoked independent of which portion of the package gets imported
first. As a consequence, the package's ``__init__.py`` cannot
practically define any names as it depends on the order of the package
fragments on sys.path which portion is imported first. As a special
feature, extend_path reads files named ``*.pkg`` which allow to
declare additional portions.

setuptools provides a similar function pkg_resources.declare_namespace
that is used in the form::

import pkg_resources
pkg_resources.declare_namespace(__name__)

In the portion's __init__.py, no assignment to __path__ is necessary,
as declare_namespace modifies the package __path__ through sys.modules.
As a special feature, declare_namespace also supports zip files, and
registers the package name internally so that future additions to sys.path
by setuptools can properly add additional portions to each package.

setuptools allows declaring namespace packages in a distribution's
setup.py, so that distribution developers don't need to put the
magic __path__ modification into __init__.py themselves.

Rationale
=

The current imperative approach to namespace packages has lead to
multiple slightly-incompatible mechanisms for providing namespace
packages. For example, pkgutil supports ``*.pkg`` files; setuptools
doesn't. Likewise, setuptools supports inspecting zip files, and
supports adding portions to its _namespace_packages variable, whereas
pkgutil doesn't.

In addition, the current approach causes problems for system vendors.
Vendor packages typically must not provide overlapping files, and an
attempt to install a vendor package that has a file already on disk
will fail or cause unpredictable behavior. As vendors might chose to
package distributions such that they will end up all in a single
directory for the namespace package, all portions would contribute
conflicting __init__.py files.

Specification
=

Rather than using an imperative mechanism for importing packages, a
declarative approach is proposed here, as an extension to the existing
``*.pkg`` mechanism.

The import statement is extended so that it directly considers ``*.pkg``
files during import; a directory is considered a package if it either
contains a file named __init__.py, or a file whose name ends with
.pkg.

In addition, the format of the ``*.pkg`` file is extended: a line with
the single character ``*`` indicates that the entire sys.path will
be searched for portions of the namespace package at the time the
namespace packages is imported.

Importing a package will immediately compute the package's __path__;
the ``*.pkg`` files are not considered anymore after the initial import.
If a ``*.pkg`` package contains an asterisk, this asterisk is prepended
to the package's __path__ to indicate that the package is a namespace
package (and that thus further extensions to sys.path might also
want to extend __path__). At most one such asterisk gets prepended
to the path.

extend_path will be extended to recognize namespace packages according
to this PEP, and avoid adding directories twice to __path__.

No other change to the importing mechanism is made; searching
modules (including __init__.py) will continue to stop at the first
module encountered.

Discussion
==

With the addition of ``*.pkg`` files to the import mechanism, namespace
packages can stop filling out the namespace package's __init__.py.
As a consequence, extend_path and declare_namespace become obsolete.

It is recommended that distributions put a file distribution.pkg
into 

Re: how to handle/generate pcap file

2009-04-02 Thread Jorgen Grahn
On Wed, 1 Apr 2009 18:59:12 -0700 (PDT), Evan xdi...@gmail.com wrote:
 On Apr 2, 6:59 am, Rhodri James rho...@wildebst.demon.co.uk wrote:
 On Wed, 01 Apr 2009 14:53:34 +0100, Evan xdi...@gmail.com wrote:

  Hello -

  I'm trying to decode thepcapfilewhich is packet capture by tcpdump
  or wireshark.   Is there a python module that I can use it for this
  problem?

  Can python-libpcap or pycap or dpkt do that?

 A quick browse of the pypcap website suggests that yes, it can.

 --
 Rhodri James *-* Wildebeeste Herder to the Masses


 Yap, I found that dpkt can do this, Thanks all.

I have used the 'pcapy' module successfully for this. Might be better
than the ones mentioned above, might be worse.

Also, the pcap file format isn't really hard: you can write such code
by yourself in a few hours. I've done that too.

/Jorgen

-- 
  // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se  R'lyeh wgah'nagl fhtagn!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Introducing Python to others

2009-04-02 Thread David C. Ullrich
In article mailman.3007.1238515574.11746.python-l...@python.org,
 andrew cooke and...@acooke.org wrote:

 David C. Ullrich wrote:
  In article tm6dnzxrviq0qfbunz2dnuvz_rmdn...@pdx.net,
   Scott David Daniels scott.dani...@acm.org wrote:
[...]
 
   class Vector(list):
   def __add__(self, other):
   return type(self)(x + y for x, y in zip(self, other))
 
  Question: I would have thought it would be
 
return type(self)([x + y for x, y in zip(self, other)])
 
  What's this thing that looks like a list comprehension but isn't?
 
 it's a generator expression. 
 http://docs.python.org/3.0/reference/expressions.html#index-3735

Ah, thanks. I see dict comprehensions there too - keen.

Sometime I gotta get around to actually learning this 2.x
stuff. Thought I had an idea how 1.x worked...

 andrew

-- 
David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list


Re: Any library to bind python with Yahoo mail service

2009-04-02 Thread Mike Driscoll
On Apr 2, 7:45 am, guptha gjango...@gmail.com wrote:
 Hi friends,
 I came across libgmail library that can be used to bind python with
 Google Gmail's service .Likewise is there any library available to
 access the service of Yahoo mail  from python code .
 I like to send sms from my application  via Yahoo mail Service .
 Thanks

Google's first hit was this:

http://developer.yahoo.com/python/

It's not a library, but it's the way that Yahoo itself recommends.

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


Re: A design problem I met again and again.

2009-04-02 Thread Jorgen Grahn
[top-posting fixed]

On Thu, 2 Apr 2009 08:02:23 -0700 (PDT), =?GB2312?B?0rvK18qr?= 
newpt...@gmail.com wrote:
 On Apr 2, 5:58 am, Carl Banks pavlovevide...@gmail.com wrote:
 On Apr 1, 12:44 am, ?? newpt...@gmail.com wrote:

  I got the same problem when writing C#/C++ when I have to provide a
  lot of method to my code's user.  So I create a big class as the entry
  point of my code.  Although these big classes doesn't contains much
  logic,  they do grow bigger and bigger.

 This seems to be a classic result of code-based organization, that
 is, you are organizing your code according to how your functions are
 used.  That's appropriate sometimes.  Procedural libraries are often
 organized by grouping functions according to use.  The os module is a
 good example.

 However, it's usually much better to organize code according to what
 data it acts upon: data-based organization.  In other words, go
 though your big class and figure out what data belongs together
 conceptually, make a class for each conceptual set of data, then
 assign methods to classes based on what data the methods act upon.

 Consider the os module again.  It's a big collection of functions, but
 there are a group of functions is os that all act on a particular
 piece of data, namely a file descriptor.  This suggests tha all the
 functions that act upon file descriptors (os.open, os.close, os.seek,
 etc.) could instead be methods of a single class, with the file
 descriptor as a class member.
...

 You get it.  Sometimes I feel that my head is trained to work in a
 procedural way.  I use a big class just as a container of functions.

If that's true, then your problems are not surprising.
A real class normally doesn't get that big.

 About the data-based approach, what if these functions all shares a
 little data, e.g. a socket, but nothing else?

If that is true, then those functions *are* the Python socket class
and everything has already been done for you.

Turn your question around and it makes more sense (to me, at least).
You don't primarily work with functions: you work with data, a.k.a.
state, a.k.a. objects.  The functions follow from the data.

To me, if I can find something with a certain lifetime, a certain set
of invariants, and a suitable name and catchphrase describing it, then
that's probably a class. Then I keep my fingers crossed and hope it
works out reasonably well. If it doesn't, I try another approach.

/Jorgen

-- 
  // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se  R'lyeh wgah'nagl fhtagn!
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for loop

2009-04-02 Thread Lou Pecora
In article pan.2009.04.02.06.28...@remove.this.cybersource.com.au,
 Steven D'Aprano ste...@remove.this.cybersource.com.au wrote:

 So an ordinality of zero just means the number 
 of elements of something that doesn't exist.


You do realize that will give most people headaches.   :-)

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


Re: Tab completion

2009-04-02 Thread sjbrown
readline.parse_and_bind('\C-n: complete')

Makes it Ctrl-n do the completion, like vim.

On Apr 2, 7:59 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 Does anyone use the tab-completion recipe in the docs?

 http://docs.python.org/library/rlcompleter.html#module-rlcompleter

 suggests using this to enable tab-completion:

 try:
     import readline
 except ImportError:
     print Module readline not available.
 else:
     import rlcompleter
     readline.parse_and_bind(tab: complete)

 which is all very nice, but it makes it rather difficult to indent code
 blocks:

  def func(x):

 ...
 Display all 174 possibilities? (y or n)

 I like tab-completion, but I'd rather not be reduced to typing spaces for
 indents in the interpreter. What do other people do?

 Can I bind Ctrl-tab to the completion instead of regular tab? I tried
 readline.parse_and_bind(C-tab: complete) but it still completes on
 regular tab.

 The GNU readline library claims that M-tab (which I guess is Alt-tab)
 will enter a tab character. Problem is that Alt-tab is intercepted by my
 window manager for something else.

 Any other suggestions or hints?

 --
 Steven

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


with open('com1', 'r') as f:

2009-04-02 Thread gert
from subprocess import *

check_call(['mode', 'COM1:9600,N,8,1,P'],shell=True)
while True:
with open('com1', 'r') as f:
for line in f:
 print('line')

This works very well except for one thing. After a reboot I have to
launch 1 time any windows serial exe application no mater with one,
that just opens an closes the com port, before i can launch this
script. The script keeps on working even after closing and reopening
it, until i reboot the pc. Then again I have to launch one time a
serial.exe and close it again. The exe does not run anything in the
background it just does something in windows python does not do when
it reads from the com port after a fresh reboot.

And i really appreciate it if somebody knew what it was.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-02 Thread P.J. Eby

At 10:32 AM 4/2/2009 -0500, Martin v. Löwis wrote:

I propose the following PEP for inclusion to Python 3.1.
Please comment.


An excellent idea.  One thing I am not 100% clear on, is how to get 
additions to sys.path to work correctly with this.  Currently, when 
pkg_resources adds a new egg to sys.path, it uses its existing 
registry of namespace packages in order to locate which packages need 
__path__ fixups.  It seems under this proposal that it would have to 
scan sys.modules for objects with __path__ attributes that are lists 
that begin with a '*', instead...  which is a bit troubling because 
sys.modules doesn't always only contain module objects.  Many major 
frameworks place lazy module objects, and module proxies or wrappers 
of various sorts in there, so scanning through it arbitrarily is not 
really a good idea.


Perhaps we could add something like a sys.namespace_packages that 
would be updated by this mechanism?  Then, pkg_resources could check 
both that and its internal registry to be both backward and forward compatible.


Apart from that, this mechanism sounds great!  I only wish there was 
a way to backport it all the way to 2.3 so I could drop the messy 
bits from setuptools.


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


RE: Introducing Python to others

2009-04-02 Thread Sells, Fred
When doing the same thing, I like
Using a dictionary to return a function or a class definition based on a
msg id and let that returned value handle the message that contained
the id.  Something like
Class XYZ:
...

MyHandlers = {42:XYZ, ...

Message = read_from_somewhere_else()
HandlerDefn = MyHandlers[Message.id]
Handler = HandlerDefn(Message)
Handler.processMessage()

As opposed to a switch statement in other languages.

I get my fellow codes to install Eclipse+PyDev as I find it easier to
comprehend that IDLE.  It's nice to just hit F9; although ^c^c is cool
for emacs folks.

I prefer turbogears over Django because it is simpler (and thus less
robust) but it sure is cool to edit your server side code, save it and
watch the server reload it automatically.  Of couse I hate HTML and use
Flex for the client side and turbogears JSON or my own XML converter
make Flex a joy.
Good luck
Fred.

 -Original Message-
 From: python-list-bounces+frsells=adventistcare@python.org
 [mailto:python-list-bounces+frsells=adventistcare@python.org] On
 Behalf Of Paddy O'Loughlin
 Sent: Thursday, March 26, 2009 5:36 AM
 To: python-list@python.org
 Subject: Introducing Python to others
 
 Hi,
 As our resident python advocate, I've been asked by my team leader to
 give a bit of a presentation as an introduction to python to the rest
 of our department.
 It'll be less than an hour, with time for taking questions at the end.
 
 There's not going to be a whole lot of structure to it. First, I'm
 going to open up a python terminal and show them how the interpreter
 works and a few basic syntax things and then a file .py files (got to
 show them that python's indenting structure is not something to be
 afraid of :P). I think I'll mostly show things in the order that they
 appear in the python tutorial (http://docs.python.org/tutorial/).
 
 My question to you, dear python-list, is what suggestions do you have
 for aspects of python that I should show them to make them maybe think
 that python is better than what they are using at the moment.
 All of the audience will be experienced (4+ years) programmers, almost
 all of them are PHP developers (2 others, plus myself, work in C, know
 C#, perl, java, etc.).
 Because of this, I was thinking of making sure I included exceptions
 and handling, the richness of the python library and a pointing out
 how many modules there were out there to do almost anything one could
 think of.
 Anything else you think could make PHP developers starting think that
 python is a better choice?
 If I were to do a (very) short demonstration one web framework for the
 PHP devs, what should I use? CherryPy (seems to be the easiest),
 Django (seems to be the biggest/most used), or something else?
 
 Any other suggestions for a possible wow reaction from an audience
like
 that?
 
 Thanks,
 Paddy
 
 --
 Ray, when someone asks you if you're a god, you say YES!
 --
 http://mail.python.org/mailman/listinfo/python-list
---[Notification]
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
--

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


openNetcam open source project recruiting developers

2009-04-02 Thread bobicanprogram
A new open source project has been started with the aim of building an
open Linux framework for TCP/IP enabled video camera systems.

http://www.openNetcam.net

The framework will be layered on the ultra lightweight SIMPL toolkit
(http://www.icanprogram.com/simpl) and when the framework is complete
it will be a kind webservices lite taylored to camera systems.

The target webserver is the lighttpd. There will be opportunities
for openNetcam developers to create a mod-simpl plugin for that
technology.

Most of the systems will be deployed in an embedded Linux
appliance.  This will restrict the choice of programming languages
for the target code somewhat. SIMPL supports C, C++, Python,  Tcl/
Tk and JAVA.   Of those C and C++ are probably the most embedded
friendly.

However,  there will be lots of other aspects of the this project
where Python could play a significant role.  eg.  test stubs.

If this sort of project interests you (or if you know of anyone who
might be interested) please don't hesitate to contact me offlist.

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


web application for scientific puposes

2009-04-02 Thread Saurabh Kabra
Dear Group,
I am new to python and I mostly use basic python scripts for small
mathematical/scientific/intrumentation applications.

Now, I want to make these application available to others by converting them
to web based applications (so that it can be used by several people on our
internal network without them having to install the application and python
on every single computer).

I am looking for the best available web framework for python which would be
well suited for a scientific application. My requirements are lots of
interactability like buttons, menus, drop downs etc. and good plotting -
preferably interactive. The faster the better but speed is not a huge issue
here - neither is web traffic. Can you guys recommend packages or
combination of packages for such an application.

Thanks in advance

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


Re: Tab completion

2009-04-02 Thread Chris Jones
On Thu, Apr 02, 2009 at 10:59:29AM EDT, Steven D'Aprano wrote:
 Does anyone use the tab-completion recipe in the docs?
 
 http://docs.python.org/library/rlcompleter.html#module-rlcompleter
 
 suggests using this to enable tab-completion:
 
 try:
 import readline
 except ImportError:
 print Module readline not available.
 else:
 import rlcompleter
 readline.parse_and_bind(tab: complete)
 
 which is all very nice, but it makes it rather difficult to indent code 
 blocks:
 
  def func(x):
 ...
 Display all 174 possibilities? (y or n)
 
 
 I like tab-completion, but I'd rather not be reduced to typing spaces for 
 indents in the interpreter. What do other people do?
 
 Can I bind Ctrl-tab to the completion instead of regular tab? I tried 
 readline.parse_and_bind(C-tab: complete) but it still completes on 
 regular tab.
 
 The GNU readline library claims that M-tab (which I guess is Alt-tab) 
 will enter a tab character. Problem is that Alt-tab is intercepted by my 
 window manager for something else.
 
 Any other suggestions or hints?

CTRL+V TAB
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for loop

2009-04-02 Thread Tim Wintle
On Thu, 2009-04-02 at 06:28 +, Steven D'Aprano wrote:
 In set theory, you start by defining the integers like this:
snip
 
 0 = len( {} )
 1 = len( {{}} )
 2 = len( {{}, {{}}} )
 3 = len( {{}, {{}}, {{}, {{}}} )
 etc.
not quite len() - surely you mean something like any object along with
an algebra in which the left hand side is equivalent to the right in the
algebra of set theory? - at least for ordinals.

The cardinal is then (for finite numbers) the length of that.


Or, in a pythonic sense (taking 0,1,2,... to be variable names):
 0 = set()
 1 = set(0)
 2 = set(1,0)
 3 = set(2,1,0)
 3 = set(3,2,1,0)
 etc.


 How that relates to whether indexing should start at one or zero, I
 have 
 no idea.

so in this sense, range(n) is actually very close to the ordinal value
of 0 (except for being a list and not a set - but it's not in 3.0)

i.e. range(n) returns something very similar to the ordinal n, and
with cardinality n. That seems very sensible to me.


 Oh, and speaking of... I'm shocked, SHOCKED I say, that nobody has
 given that quote about the compromise of 0.5.
God made the integers, all else is the work of man - Leopold Kronecker

...holding myself back from complaining about integer division in Py3K
when the philosophical question of whether irrational numbers even exist
(in a physics sense) is fairly open.

Tim W


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


Re: A design problem I met again and again.

2009-04-02 Thread Carl Banks
On Apr 2, 8:02 am, 一首诗 newpt...@gmail.com wrote:
 You get it.  Sometimes I feel that my head is trained to work in a
 procedural way.  I use a big class just as a container of functions.

 About the data-based approach, what if these functions all shares a
 little data, e.g. a socket, but nothing else?

Then perhaps your problem is that you are too loose with the
interface.  Do you write new functions that are very similar to
existing functions all the time?  Perhaps you should consolidate, or
think about how existing functions could do the job.

Or perhaps you don't have a problem.  There's nothing wrong with large
classes per se, it's just a red flag.  If you have all these functions
that really all operate on only one piece of data, and really all do
different things, then a large class is fine.


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


Re: Python Goes Mercurial

2009-04-02 Thread Kay Schluehr
On 2 Apr., 15:05, David Smith d...@cornell.edu wrote:
 Kay Schluehr wrote:
  On 1 Apr., 07:56, Lawrence D'Oliveiro l...@geek-
  central.gen.new_zealand wrote:
  In message 35d429fa-5d13-4703-

  a443-6a95c740c...@o6g2000yql.googlegroups.com, John Yeung wrote:
  Here's one that clearly expresses strong antipathy:
   http://mail.python.org/pipermail/python-dev/2009-March/087971.html
  There are lots of GUI- and Web-based front ends to Git. And look at on-line
  services like GitHub and Gitorious. The level of support for it is huge.

  Ironically Mercurials most popular UI frontend Tortoise is going to
  crash Python tools ( like Wing-IDE ) on Windows. That's a known issue
  for about a year and more and the developers are not inclined to fix
  it. This doesn't really increase my trust that Mercurials UI tools are
  of a higher quality than Git's no matter which platform is used.

 The conflict between TortoiseHg and Wing IDE can be fixed by simply
 uninstalling the Tortoise Overlays.  You loose the graphic overlay on
 folders, but otherwise everything works.

 --David

Good to know. Uninstalling a major feature that enhances usability
just to make it usable isn't much less ironic though.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sending SMS using python script

2009-04-02 Thread Brent Bloxam

guptha wrote:

hi group,
my application needs to send SMS occasionally to all the clients  .Is
there any library in python that supports in sending SMS.
I like to conform few information i gathered in this regard.

I can send SMS by two ways

1. Sending SMS using Email clients
2. Using sms gateway to send message(we can implement SMS Gateway API
's ,provided by vendor and ,send SMS -- we will be charged
accordingly )

In case of First approach
1. We can make use of libgamil library to send SMS using gmail ( I
ref : http://blog.datasingularity.com/?p=63 )
i suppose sending sms through gmail is not supported in India
 2. Can we use Skype4py library,

In case of second approach
1. Is there any way to send SMS for free inside India ,or ,Any free
SMS gateway providers in India
Any information regarding this is appreciable
  Thanks
--
http://mail.python.org/mailman/listinfo/python-list
  
While this may not be exactly what you want to do, I thought I'd offer 
this as an alternative. MultiModem has a hardware product that works as 
a GPRS modem (with either a serial or ethernet interface, see here: 
http://www.multitech.com/PRODUCTS/Families/MultiModemGPRS/), allowing 
direct access to standard AT commands. The modems require a regular SIM 
card with an account setup for it. For our needs we got a basic plan 
with unlimited SMS. This is after we went with a couple 3rd party SMS 
gateways and found their delivery unreliable for our clients.


I've written a daemon in python called mmsmsd (multimodem sms daemon) 
for their ethernet model (MTCBA-G-EN-F4). It queues messages via an HTTP 
GET request, which are then handled by threads that maintain telnet 
connections to the GPRS modems AT command interface. You can check out 
the project here: http://code.google.com/p/mmsmsd/ (it's BSD licensed)


If you go this route, feel free to submit any bug reports or requests. 
If anyone out there feels like doing a quick audit of the code, that 
would be appreciated as well :) This is my first project with Python.


--
|  .- brent bloxam ~-.  brentb @ beanfield.com
| () beanfield metroconnect
|  `~- wgxolq +uajq -'  416.532.1555 ext. 2004
--

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


Re: league problem in python

2009-04-02 Thread Andrew Henshaw

Ross ross.j...@gmail.com wrote in message 
news:d5cc0ec7-5223-4f6d-bab4-3801dee50...@r37g2000yqn.googlegroups.com...
... snip ...
 I would like to create a simple program where the pro could enter in
 how many people were in the league, the number of courts available,
 and the number of weeks the schedule would run and then generate a
 schedule where everybody played everybody else once and got the same
 number of bye weeks, preferably spaced out evenly.

 How should I go about starting this problem...I'm feel like this is a
 really simple problem, but I'm having writer's/coder's block. Can you
 guys help?

At least as a start, you want the round-robin tournament algorithm (see 
http://en.wikipedia.org/wiki/Round-robin_tournament).  Here's some code that 
I use:

## begin code  ###
def roundrobin(teams, rounds=1):
# if odd number of teams, add a bye team
if len(teams) % 2:
teams.append(None)
mid = len(teams) // 2
for i in range(rounds):
yield zip(teams[:mid], teams[mid:])
teams = teams[0:1] + teams[mid:mid+1] + teams[1:mid-1] + 
teams[mid+1:] + teams[mid-1:mid]

### test code ###
if __name__ == '__main__':
ROUNDS = 10
# two test cases - even number of teams and odd number of teams
for teams in  (range(6), range(5)):
print \nteams =, teams
for round in roundrobin(teams, ROUNDS):
print round

## end code  ###

And the output:

teams = [0, 1, 2, 3, 4, 5]
[(0, 3), (1, 4), (2, 5)]
[(0, 4), (3, 5), (1, 2)]
[(0, 5), (4, 2), (3, 1)]
[(0, 2), (5, 1), (4, 3)]
[(0, 1), (2, 3), (5, 4)]
[(0, 3), (1, 4), (2, 5)]
[(0, 4), (3, 5), (1, 2)]
[(0, 5), (4, 2), (3, 1)]
[(0, 2), (5, 1), (4, 3)]
[(0, 1), (2, 3), (5, 4)]

teams = [0, 1, 2, 3, 4]
[(0, 3), (1, 4), (2, None)]
[(0, 4), (3, None), (1, 2)]
[(0, None), (4, 2), (3, 1)]
[(0, 2), (None, 1), (4, 3)]
[(0, 1), (2, 3), (None, 4)]
[(0, 3), (1, 4), (2, None)]
[(0, 4), (3, None), (1, 2)]
[(0, None), (4, 2), (3, 1)]
[(0, 2), (None, 1), (4, 3)]
[(0, 1), (2, 3), (None, 4)]

-- 
Andy 


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


Re: PEP 382: Namespace Packages

2009-04-02 Thread Carl Banks
On Apr 2, 8:32 am, Martin v. Löwis mar...@v.loewis.de wrote:
 I propose the following PEP for inclusion to Python 3.1.
 Please comment.

 Regards,
 Martin

 Abstract
 

 Namespace packages are a mechanism for splitting a single Python
 package across multiple directories on disk. In current Python
 versions, an algorithm to compute the packages __path__ must be
 formulated. With the enhancement proposed here, the import machinery
 itself will construct the list of directories that make up the
 package.

-0

My main concern is that we'll start seeing all kinds of packages with
names like:

com.dusinc.sarray.ptookkit.v_1_34_beta.btree.BTree

The current lack of global package namespace effectively prevents
bureaucratic package naming, which in my mind makes it worth the
cost.  However, I'd be willing to believe this can be kept under
control some other way.


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


Re: *args question

2009-04-02 Thread Aahz
In article 50d06eb9-2b87-43a0-a7e2-6b68e35fc...@y34g2000prb.googlegroups.com,
grocery_stocker  cdal...@gmail.com wrote:

Given the following code...

import thread

Here's your problem; subclass threading.Thread instead, much easier.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.  --Brian W. Kernighan
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   >