ANN: eGenix mxODBC 3.0 Developer Licenses (mxODBC Database Interface)

2007-05-30 Thread eGenix Team: M.-A. Lemburg



  eGenix.com mxODBC 3.0 Developer Licenses Available



eGenix is pleased to announce the immediate availability of developer
licenses for our Python ODBC database interface, the eGenix mxODBC
Distribution 3.0 for Python.

This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/mxODBC-3.0-Developer-License-Announcement.html


INTRODUCTION

The eGenix mxODBC Distribution is an add-on distribution for our eGenix
mx Base Distribution. It comes with mxODBC, our universal ODBC database
interface for Python.



DEVELOPER LICENSES FOR mxODBC 3.0

eGenix is now shipping developer licenses for mxODBC which allow the
integration and redistribution of mxODBC into your products.

* Make use of the power and flexibility of this cross-platform,
  robust and stable interface and connect to most available
  databases with less hassles, fewer configuration problems and
  great performance.

* Enjoy the same database interface API on all supported platforms:
  Windows, Linux, Mac OS X, FreeBSD and Solaris.

* This is true write-once, deploy anywhere !



HOW DOES IT WORK ?

The setup works just like for a regular stand-alone installation of
mxODBC. eGenix will send you the required license files after purchase
and all you have to do, is install them in the product folder.

You can then work on your product and ship the license files together
with the product, so that your customers can use the product integrated
mxODBC just like you do on your development machines.

Once licensed, you don't have to pay eGenix royalties or fees for
distributing mxODBC together with your products.



WHICH RESTRICTIONS APPLY ?

Restrictions are very modest:

* you must get a proper license for all developer machines and
  developers working on the product

* the mxODBC version included in the product must be tied to your
  product, ie. it should not be usable outside your product

* you are not permitted to use mxODBC in a product that would
  introduce competition for eGenix products.

The full legal details are available in the eGenix.com Commercial License
Agreement 1.2.0. Please see the product page for details:

http://www.egenix.com/products/python/mxODBC/#Licensing



TRY BEFORE YOU BUY

You can request 30-day evaluation licenses by writing to
[EMAIL PROTECTED], stating your name (or the name of the company) and the
number of eval licenses that you need. We will then issue you licenses
and send them to you by email.

Please make sure that you can receive ZIP file attachments on the email
you specify in the request, since the license files are send out as
ZIP attachements.



PRICING

mxODBC 3.0 Developer CPU Licenses can be purchased in our eGenix Online
Shop at http://www.egenix.com/shop/.

Please see the mxODBC distribution page for details on buying licenses
or contact [EMAIL PROTECTED]



DOWNLOADS

The download archives and instructions for installing the package can
be found at:

http://www.egenix.com/products/python/mxODBC/

IMPORTANT:
In order to use the eGenix mx Commercial package you will first
need to install the eGenix mx Base package which can be downloaded
from here:

http://www.egenix.com/products/python/mxBase/

___

SUPPORT

Commercial support for these packages is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.


Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 29 2007)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611



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

Support the Python Software Foundation:

ANN: PyTables 2.0rc2 released

2007-05-30 Thread Francesc Altet

 Announcing PyTables 2.0rc2


PyTables is a library for managing hierarchical datasets and designed to
efficiently cope with extremely large amounts of data with support for
full 64-bit file addressing.  PyTables runs on top of the HDF5 library
and NumPy package for achieving maximum throughput and convenient use.

This is the second (and probably last) release candidate for PyTables
2.0.  On it, together with the traditional bunch of bug fixes, you will
find a handful of optimizations for dealing with very large tables.
Also, the Optimization tips chapter of User's Guide has been updated
and the manual is almost ready (bar some errors or typos we may have
introduced) for the long awaited 2.0 final release.  In particular, the
Indexed searches section shows pretty definitive plots on the
performance of the completely new and innovative indexing engine that
will be available in the Pro version (to be released very soon now).

You can download a source package of the version 2.0rc2 with
generated PDF and HTML docs and binaries for Windows from
http://www.pytables.org/download/preliminary/

For an on-line version of the manual, visit:
http://www.pytables.org/docs/manual-2.0rc2

In case you want to know more in detail what has changed in this
version, have a look at ``RELEASE_NOTES.txt``.  Find the HTML version
for this document at:
http://www.pytables.org/moin/ReleaseNotes/Release_2.0rc2

If you are a user of PyTables 1.x, probably it is worth for you to look
at ``MIGRATING_TO_2.x.txt`` file where you will find directions on how
to migrate your existing PyTables 1.x apps to the 2.0 version.  You can
find an HTML version of this document at
http://www.pytables.org/moin/ReleaseNotes/Migrating_To_2.x

Keep reading for an overview of the most prominent improvements in
PyTables 2.0 series.


New features of PyTables 2.0


- A complete refactoring of many, many modules in PyTables.  With this,
  the different parts of the code are much better integrated and code
  redundancy is kept under a minimum.  A lot of new optimizations have
  been included as well, making working with it a smoother experience
  than ever before.

- NumPy is finally at the core!  That means that PyTables no longer
  needs numarray in order to operate, although it continues to be
  supported (as well as Numeric).  This also means that you should be
  able to run PyTables in scenarios combining Python 2.5 and 64-bit
  platforms (these are a source of problems with numarray/Numeric
  because they don't support this combination as of this writing).

- Most of the operations in PyTables have experimented noticeable
  speed-ups (sometimes up to 2x, like in regular Python table
  selections).  This is a consequence of both using NumPy internally and
  a considerable effort in terms of refactorization and optimization of
  the new code.

- Combined conditions are finally supported for in-kernel selections.
  So, now it is possible to perform complex selections like::

  result = [ row['var3'] for row in
 table.where('(var2  20) | (var1 == sas)') ]

  or::

  complex_cond = '((%s = col5)  (col2 = %s)) ' \
 '| (sqrt(col1 + 3.1*col2 + col3*col4)  3)'
  result = [ row['var3'] for row in
 table.where(complex_cond % (inf, sup)) ]

  and run them at full C-speed (or perhaps more, due to the cache-tuned
  computing kernel of Numexpr, which has been integrated into PyTables).

- Now, it is possible to get fields of the ``Row`` iterator by
  specifying their position, or even ranges of positions (extended
  slicing is supported).  For example, you can do::

  result = [ row[4] for row in table# fetch field #4
 if row[1]  20 ]
  result = [ row[:] for row in table# fetch all fields
 if row['var2']  20 ]
  result = [ row[1::2] for row in   # fetch odd fields
 table.iterrows(2, 3000, 3) ]

  in addition to the classical::

  result = [row['var3'] for row in table.where('var2  20')]

- ``Row`` has received a new method called ``fetch_all_fields()`` in
  order to easily retrieve all the fields of a row in situations like::

  [row.fetch_all_fields() for row in table.where('column1  0.3')]

  The difference between ``row[:]`` and ``row.fetch_all_fields()`` is
  that the former will return all the fields as a tuple, while the
  latter will return the fields in a NumPy void type and should be
  faster.  Choose whatever fits better to your needs.

- Now, all data that is read from disk is converted, if necessary, to
  the native byteorder of the hosting machine (before, this only
  happened with ``Table`` objects).  This should help to accelerate
  applications that have to do computations with data generated in
  platforms with a byteorder different than the user machine.

- The modification of values in ``*Array`` objects (through 

Re: is and ==

2007-05-30 Thread Erik Max Francis
BlueJ774 wrote:

 Can someone please explain to me the difference between the is
 keyword and the == boolean operator.  I can't figure it out on my own
 and I can't find any documentation on it.
 
 I can't understand why this works:
 
 if text is None:
 
 and why this always returns false:
 
 if message is 'PING':
 
 even when message = 'PING'.
 
 What's the deal with that?

`x is y` means the same thing as:

id(x) == id(y)

You use the `is` operator for when you're testing for _object identity_, 
not value.  `None` is a special object sentinel that is not only a value 
but a special _object_, and so if you're testing whether or not an 
object is `None`, you do so with the `is` operator.

If you're testing whether an object is equal to the string PING then 
you do not want to do so by identity, but rather value, so you use the 
`==` operator, not `is`.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
  San Jose, CA, USA  37 20 N 121 53 W  AIM, Y!M erikmaxfrancis
   You could have another fate / You could be in another place
-- Anggun
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is and ==

2007-05-30 Thread BlueJ774
On May 30, 12:57 am, Erik Max Francis [EMAIL PROTECTED] wrote:
 BlueJ774 wrote:
  Can someone please explain to me the difference between the is
  keyword and the == boolean operator.  I can't figure it out on my own
  and I can't find any documentation on it.

  I can't understand why this works:

  if text is None:

  and why this always returns false:

  if message is 'PING':

  even when message = 'PING'.

  What's the deal with that?

 `x is y` means the same thing as:

 id(x) == id(y)

 You use the `is` operator for when you're testing for _object identity_,
 not value.  `None` is a special object sentinel that is not only a value
 but a special _object_, and so if you're testing whether or not an
 object is `None`, you do so with the `is` operator.

 If you're testing whether an object is equal to the string PING then
 you do not want to do so by identity, but rather value, so you use the
 `==` operator, not `is`.

 --
 Erik Max Francis  [EMAIL PROTECTED] http://www.alcyone.com/max/
   San Jose, CA, USA  37 20 N 121 53 W  AIM, Y!M erikmaxfrancis
You could have another fate / You could be in another place
 -- Anggun

Thanks.  That's exactly what I was looking for.

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


Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread Tim Roberts
Frank Swarbrick [EMAIL PROTECTED] wrote:

Then you'd really love COBOL!

:-)

Frank
COBOL programmer for 10+ years

Hey, did you hear about the object-oriented version of COBOL?  They call it
ADD ONE TO COBOL.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Key Listeners

2007-05-30 Thread kaens
On 29 May 2007 19:14:33 -0700, Mike [EMAIL PROTECTED] wrote:
 Are there key listeners for Python? Either built in or third party?

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


I'm pretty sure pygame's got some, don't know about built-ins.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Key Listeners

2007-05-30 Thread Gary Herron
Mike wrote:
 Are there key listeners for Python? Either built in or third party?

   
(As always on forums like this, you're most likely to get answers if you
define your terms.  A little Goggling informs me that in Java a key
listener is a Java term for a component that generates an event when the
keyboard is used. )

Yes, every GUI I've ever used from Python (Tk/Tcl, wxPython, Gtk++,
Win32 API, ...) has a way to catch keyboard events.  But you're going to
have to tell us which OS and which GUI you're interested in before you
get a more detailed answer.

Gary Herron

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


Re: RDFXML Parser For qualified Dublin Core Database File

2007-05-30 Thread Steve Holden
Brandon McGinty wrote:
 Hi All,
 
 My goal is to be able to read the www.gutenberg.org 
 http://www.gutenberg.org/ rdf catalog, parse it into a python 
 structure, and pull out data for each record.
 
 The catalog is a Dublin core RDF/XML catalog, divided into sections for 
 each book and details for that book.
 
 I have done a very large amount of research on this problem.
 
 I’ve tried tools such as pyrple, sax/dom/minidom, and some others both 
 standard and nonstandard to a python installation.
 
 None of the tools has been able to read this file successfully, and 
 those that can even see the data can take up to half an hour to load 
 with 2 gb of ram.
 
 So you all know what I’m talking about, the file is located at:
 
 http://www.gutenberg.org/feeds/catalog.rdf.bz2
 
 Does anyone have suggestions for a parser or converter, so I’d be able 
 to view this file, and extract data?
 
 Any help is appreciated.
 
Well, have you tried xml.etree.cElementTree, a part of the standard 
library since 2.5? Well worth a go, as it seems to outperform many XML 
libraries.

The iterparse function is your best bet, allowing you to iterate over 
the events as you parse the source, thus avoiding the need to build a 
huge in-memory data structure just to get the parsing done.

The following program took about four minutes to run on my not-terribly 
up-to-date Windows laptop with 1.5 GB of memory with the pure Python 
version of ElementTree:

import xml.etree.ElementTree as ET
events = ET.iterparse(open(catalog.rdf))
count = 0
for e in events:
   count += 1
   if count % 10 == 0: print count
print count, total events

Here's an example output after I changed to using the extension module - 
by default, only the end-element events are reported. I think you'll be 
impressed by the timing. The only change was to the import staement, 
which now reads

import xml.etree.cElementTree as ET

[EMAIL PROTECTED] ~/Projects/Python
$ time python test19.py
10
20
30
40
50
60
70
80
90
100
110
120
130
140
1469971 total events

real0m11.145s
user0m10.124s
sys 0m0.580s

Good luck!

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
-- Asciimercial -
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.comsquidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

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


Re: Professional Grant Proposal Writing Workshop (July 2007: University of Montana, Missoula)

2007-05-30 Thread Steve Holden
Anthony Jones wrote:
[...]
 
 At its foundation, this course will address the basics of foundation, 
 corporation, and government grant research. However, this course will 
 teach a strategic funding research approach that encourages students to 
 see research not as something they do before they write a proposal, but 
 as an integrated part of the grant seeking process. Students will be 
 exposed to online and database research tools, as well as publications 
 and directories that contain information about foundation, corporation, 
 and government grant opportunities. Focusing on funding sources and 
 basic social science research, this course teaches students how to use 
 research as part of a strategic grant acquisition effort.
 
  
 
 Registration
 
 $597.00 tuition includes all materials and certificates.
 
I wonder if I could get a grant to attend this course?

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
-- Asciimercial -
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.comsquidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

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


Re: Rats! vararg assignments don't work

2007-05-30 Thread Gary Herron
samwyse wrote:
 I'm a relative newbie to Python, so please bear with me.  After seeing 
 how varargs work in parameter lists, like this:
  def func(x, *arglist):
 and this:
  x = func(1, *moreargs)
 I thought that I'd try this:
  first, *rest = arglist
 Needless to say, it didn't work.  That leaves me with two questions.

 First, is there a good way to do this?  For now, I'm using this:
  first, rest = arglist[0], arglist[1:]
 but it leaves a bad taste in my mouth.
   
Well, your moreargs parameter is a tuple, and there are innumerable ways
to process a tuple. (And even more if you convert it to a list.)

If you are just interested in extracting only the first arg, then your
code is quite Pythonic.  However, if you are going to do that in a loop
to successively process  each arg, the you have several better options:

For instance:
  for arg in moreargs:   # Loop through each arg
  do something with arg

or

  for i in range(len(moreargs)):
  do something with morergs[i]  # Extract ith arg

or

argslist = list(moreargs)
while argslist:
  firstarg = argslist.pop(0) # Extract first arg
  do something with firstarg

Gary Herron

 Second, is there any good reason why it shouldn't work?  It seems like 
 such an obvious idiom that I can't believe that I'm the first to come up 
 with the idea.  I don't really have the time right now to go source 
 diving, so I can't tell if it would be wildly inefficient to implement.

 Thanks!
   

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


Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations

2007-05-30 Thread Xah Lee
Prefix, Infix, Postfix notations in Mathematica

2000-02-21, 2007-05

[In the following essay, I discuss prefix, infix, postfix notations
and Mathematica's syntax for them. The full HTML formatted article is
available at:
http://xahlee.org/UnixResource_dir/writ/notations.html
]

THE HEAD OF EXPRESSIONS

Lisp's nested parenthesis syntax is a Functional Notation. It has the
general form of “(f a b ...)” where any of the symbols inside the
matching parenthesis may again be that form. For example, here's a
typical code from Emacs Lisp.

; Recursively apply (f x i), where i is the ith element in the list
li.
; For example, (fold f x '(1 2)) computes (f (f x 1) 2)
(defun fold (f x li)
  (let ((li2 li) (ele) (x2 x))
(while (setq ele (pop li2))
  (setq x2 (funcall f x2 ele))
)
x2
  )
)

Vast majority of computer languages, interpret source code in a one-
dimensional, linear nature. Namely, from left to right, line by line,
as in written text. (Examples of computer languages's source code that
are not linear in nature, are spread sheets, cellular automata,
graphical programing languages) For languages that interprets source
code linearly, the logics of their syntax necessarily have a
hierarchical structure (i.e. tree). The lisp's notation, is the most
effective in visually showing the logics of the syntax. This is
because, a function and its arguments, are simply laid out inside a
parenthesis. The level of nesting corresponds to the “precedence” in
evaluating the expression.

The first element inside the matching parenthesis, is called the
“head” of the expression. For example, in “(f a b)”, the “f” is the
head. The head is a function, and the rest of the symbols inside the
matching parenthesis are its arguments.

The head of lisp's notation needs not to be defined as the first
element inside the parenthesis. For example, we can define the “head”
to be the last element inside the parenthesis. So, we write “(arg1
arg2 ... f)” instead of the usual “(f arg1 arg2 ...)” and its
syntactical analysis remains unchanged. Like wise, you can move the
head outside of the parenthesis.

In Mathematica, the head is placed in front of the parenthesis, and
square brackets are used instead of parenthesis for the enclosing
delimiter. For example, lisp's “(f a b c)” is syntactically equivalent
to Mathematica's “f[a,b,c]”. Other examples: “(sin θ)” vs “Sin[θ]”,
“(map f list)” vs “Map[f,list]”. Placing the head in front of the
matching bracket makes the notation more familiar, because it is a
conventional math notation.

However, there is a disadvantage in moving the head of a expression
from inside the matching bracket to outside. Namely: The nesting of
the matching delimiters, no longer corresponds to the logics of the
syntax, when the head is itself a compound expression.

For example, suppose Reflection(vectorV,pointP) is function that
returns a function f, such that f(graphicsData) will reflect the
graphicsData along a line passing pointP and parallel to vectorV. In
lisp, we would write “((Reflection vectorV pointP) graphicsData)”. In
Mathematica, we would write “Reflection[vectorV,pointP]
[graphicsData]”. In lisp's version, the nesting corresponds to the
logics of the evaluation. In the Mathematica's form, that is no longer
so.

For another example, suppose Deriv is a function that takes a function
f and returns a function g (the derivative of f), and we want to apply
g to a variable x. In lisp, we would write “((Deriv f) x)”. In
Mathematica, we would write “Deriv[f][x]”. In lisp's version, the
nesting corresponds to the logics of the evaluation. In the
Mathematica's form, the logics of the evaluation no longer corresponds
to the nesting level, because now the head is outside of the enclosing
delimiters, so the head of expressions no longer nests.

PREFIX, POSTFIX, INFIX

A prefix notation in Mathematica is represented as [EMAIL PROTECTED]
Essentially, a prefix notation in this context limits it to uses for
functions on only one argument. For example: [EMAIL PROTECTED]@[EMAIL 
PROTECTED] is equivalent
to “f[a[b[c]]]” or in lispy “(f (a (b c)))”. Mathematica also offers a
postfix notation using the operator “//”. For example, “c//b//a//f” is
syntactically equivalent to “f[a[b[c]]]”. (unix's pipe “|” syntax, is
a form of postfix notation. e.g. “c | b | a | f”).

For example, “Sin[List[1,2,3]]” can be written in postfix as
“List[1,2,3]//Sin”, or prefix [EMAIL PROTECTED],2,3]”. (by the way, they are
semantically equivalent to “Map[Sin, List[1,2,3]]” in Mathematica) For
infix notation, the function symbol is placed between its arguments.
In Mathematica, the generic form for infix notation is by sandwiching
the tilde symbol around the function name. e.g.
“Join[List[1,2],List[3,4]]” is syntactically equivalent to “List[1,2]
~Join~ List[3,4]”.

In Mathematica, there is quite a lot syntax variations beside the
above mentioned systematic constructs. For example, Plus[a,b,c] can be
written as “a+b+c”, “Plus[a+b,c]”, 

Re: How to print this character u'\u20ac' to DOS terminal

2007-05-30 Thread 人言落日是天涯,望极天涯不见家
On 5月30日, 下午1时23分, Martin v. Lowis [EMAIL PROTECTED] wrote:
 人言落日是天涯,望极天涯不见家 schrieb:

  Who could explain the follow issue ?
  print u'\u0394'
  Δ
  print u'\u20ac'
  Traceback (most recent call last):
File stdin, line 1, in module
  UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in
  position 0:
  illegal multibyte sequence

  My terminal is cmd.exe under windows XP.
  what's the different between the two character ? what can I do if I
  want to print the u'\u20ac'?

 The problem is that your terminal uses (some form of) the GBK encoding;
 seehttp://zh.wikipedia.org/wiki/GBKfor details on GBK.

 It seems that GBK (or, rather, code page 936) supports the delta
 character, but not the euro sign.

 To change that, you can use chcp in your terminal window.
 For example, if you do chcp 850, you should be able to
 display the euro sign (but will simultaneously use the ability
 to display the letter delta, and the chinese letters).

 I don't know whether the terminal supports an UTF-8 code
 page; you can try setting the terminal's code page to
 65001 (which should be UTF-8).

 Regards,
 Martin

Thanks, but it seems not work yet.


C:\WINDOWSchcp 850
Active code page: 850

C:\WINDOWSpython
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type help, copyright, credits or license for more information.
 print u'\u20ac'
Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Python25\lib\encodings\cp850.py, line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac'
in position
 0: character maps to undefined


C:\WINDOWSchcp 65001
Active code page: 65001

C:\WINDOWSpython
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type help, copyright, credits or license for more information.
 print u'\u20ac'
Traceback (most recent call last):
  File stdin, line 1, in module
LookupError: unknown encoding: cp65001
---
I find that the u'\u20ac' related 'mbcs' encode is 0x80, I could print
it directly
 print '\x80'
�


But the string contained the u'\u20ac' is get from remote host. Is
there any method to decode it to the local 'mbcs'?

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

print bypasses calling write method for objects inheriting from file?

2007-05-30 Thread MisterPete
I created an object that inherits from file and was a bit surprised to
find that print seems to bypass the write method for objects
inheriting from file.  An optimization I suppose.  Does this surprise
anyone else at all or am I missing something?

import sys

class FromObject(object):

def write(self, string):
# this works fine, gets called by print
sys.stdout.write(FromObject:  + string)

class FromFile(file):

def __init__(self, name, mode='w'):
file.__init__(self, name, mode)

def write(self, string):
# this does not get called by print
sys.stdout.write(FromFile:  + string)


a = FromObject()
b = FromFile(test.txt)

a.write(Foo\n) # works as expected
b.write(Bar\n) # works as expected

print  a, Baz\n
# FromFile: Baz\nFromFile:\n written to stdout.  That's fine.

print  b, Qux\n
b.flush()
# Qux\n written to test.txt. b.write wasn't called :(

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


Re: Periodic tasks.

2007-05-30 Thread Irmen de Jong
Ramashish Baranwal wrote:
 Hi,
 
 I am trying to execute some tasks periodically, those familiar with
 unix can think of it as equivalent to cron jobs. I have tried looking
 around, but couldn't find a way. Would appreciate any pointers or
 clues..
 
 Thanks,
 -Ram
 


Have a look at Kronos, a simple task scheduler I wrote a while ago,
based on sched. It's part of Turbogears as well:
http://trac.turbogears.org/browser/trunk/turbogears/scheduler.py


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


Re: Tkinter Listbox - Different Text colors in one listbox

2007-05-30 Thread Hendrik van Rooyen
 [EMAIL PROTECTED] wrote:


 Hi,
 Is it possible to have different items in a listbox in different
 colors? Or is it just one color for all items in a listbox?
 Thanks
 Rahul

You specify text and foreground colour when you make the box,
so I don't think its possible.

- Hendrik

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


Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread Hendrik van Rooyen
 Maric Michaud [EMAIL PROTECTED] wrote:

Is typist ok ? It's the google's translation for dactylo.


Typist is fine, although MCP that I am, I tend to think of
typist as female...

I would call a male one a typer, but I dont think it is correct English.

- Hendrik


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


Re: print bypasses calling write method for objects inheriting from file?

2007-05-30 Thread Peter Otten
MisterPete wrote:

 I created an object that inherits from file and was a bit surprised to
 find that print seems to bypass the write method for objects
 inheriting from file.  An optimization I suppose.  Does this surprise
 anyone else at all or am I missing something?

No, your analysis is correct, though I'd consider optimization an euphemism
for bug here. Noone was annoyed enough to write a patch, it seems.

Peter



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


Re: Unicode to HTML entities

2007-05-30 Thread Duncan Booth
Clodoaldo [EMAIL PROTECTED] wrote:

 On May 29, 12:57 pm, Richard Brodie [EMAIL PROTECTED] wrote:
 Clodoaldo [EMAIL PROTECTED] wrote in message

 news:[EMAIL PROTECTED]

 I was looking for a function to transform a unicode string into
 htmlentities.
  u'São Paulo'.encode('ascii', 'xmlcharrefreplace')

 'S#227;o Paulo'
 
 That was a fast answer. I would never find that myself.
 
You might actually want:

 cgi.escape(u'São Paulo  Espírito Santo').encode('ascii', 
 'xmlcharrefreplace')
'S#227;o Paulo amp; Esp#237;rito Santo'

as you have to be sure to escape any ampersands in your unicode 
string before doing the encode.

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


Re: Key Listeners

2007-05-30 Thread [EMAIL PROTECTED]
On 30 mai, 04:14, Mike [EMAIL PROTECTED] wrote:
 Are there key listeners for Python? Either built in or third party?

What is a key listener ?

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


binascii.unhexlify ... not clear about usage, and output

2007-05-30 Thread Vishal
Hi,

I have a file with a long list of hex characters, and I want to get a
file with corresponding binary characters

here's what I did:

 import binascii
 f1 = 'c:\\temp\\allhex.txt'
 f2 = 'c:\\temp\\allbin.txt'
 sf = open(f1, 'rU')
 df = open(f2, 'w')
 slines = sf.readlines()
 for line in slines:
... x = line.rstrip('\n')
... y = binascii.unhexlify(x)
... df.write(y)
...
 df.close()
 sf.close()

But what I get is all garbage, atleast textpad and notepad show that
I tried doing it for only one string, and this is what I am seeing on
the interpreter:

 x
'0164'
 y
'\x01d'

I was expecting 'y' would come out as a string with binary
characters!!!

What am i missing here? Can someone please help.

Thanks and best regards,
Vishal

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


Re: multiline regular expression (replace)

2007-05-30 Thread Zdenek Maxa
Hi,

Thanks a lot for useful hints to all of you who replied to my question. 
I could easily do now what I wanted.

Cheers,
Zdenek


Holger Berger wrote:
 Hi,

 yes:

 import re

 a=
 I Am
 Multiline
 but short anyhow

 b=(I[\s\S]*line)

 print re.search(b, a,re.MULTILINE).group(1)


 gives

 I Am
 Multiline

 Be aware that . matches NO newlines!!!
 May be this caused your problems?

 regards
 Holger


 Zdenek Maxa wrote:

   
 [EMAIL PROTECTED] wrote:
 
 On May 29, 2:03 am, Zdenek Maxa [EMAIL PROTECTED] wrote:
   
   
 Hi all,

 I would like to perform regular expression replace (e.g. removing
 everything from within tags in a XML file) with multiple-line pattern.
 How can I do this?

 where = open(filename).read()
 multilinePattern = ^tag  \/tag$
 re.search(multilinePattern, where, re.MULTILINE)

 Thanks greatly,
 Zdenek
 
 
 Why not use an xml package for working with xml files?  I'm sure
 they'll handle your multiline tags.

 http://effbot.org/zone/element-index.htm
 http://codespeak.net/lxml/

 ~Sean

   
   
 Hi,

 that was merely an example of what I would like to achieve. However, in
 general, is there a way for handling multiline regular expressions in
 Python, using presumably only modules from distribution like re?

 Thanks,
 Zdenek
 

   

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


Re: Tkinter Listbox - Different Text colors in one listbox

2007-05-30 Thread Eric Brunel
On Tue, 29 May 2007 19:02:03 +0200, [EMAIL PROTECTED] wrote:

 Hi,
 Is it possible to have different items in a listbox in different
 colors? Or is it just one color for all items in a listbox?
 Thanks
 Rahul


AFAIK, this is not possible with a listbox. You can however quite easily  
emulate the behaviour of a listbox with a text widget, which allows to mix  
fonts and colors in any way you like.

I did it once by creating a sub-class of Tkinter.Text (cannot post the  
code here - closed source, sorry...) and all I had to do was:
- make sure the text widget had its state to DISABLED all the time, except  
when modifying it;
- removing all the bindings defined in the text widgets (use  
widget.bind_class('Text') to get all the events, then widget.bind(event,  
lambda e: 'break') to remove them);
- define a new binding for a button click selecting the line under the  
cursor;
- define the insert, delete and getcurselection methods, taking care of  
treating the special index END.

All in all, this was just a few dozen lines.

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


Re: binascii.unhexlify ... not clear about usage, and output

2007-05-30 Thread Peter Otten
Vishal wrote:

 I have a file with a long list of hex characters, and I want to get a
 file with corresponding binary characters
 
 here's what I did:
 
 import binascii
 f1 = 'c:\\temp\\allhex.txt'
 f2 = 'c:\\temp\\allbin.txt'
 sf = open(f1, 'rU')
 df = open(f2, 'w')
 slines = sf.readlines()
 for line in slines:
 ...   x = line.rstrip('\n')
 ...   y = binascii.unhexlify(x)
 ...   df.write(y)
 ...
 df.close()
 sf.close()

Your code is OK, but you have to open f2 in binary mode if your data is
truly binary (an image, say).
 
 But what I get is all garbage, atleast textpad and notepad show that
 I tried doing it for only one string, and this is what I am seeing on
 the interpreter:
 
 x
 '0164'
 y
 '\x01d'
 
 I was expecting 'y' would come out as a string with binary
 characters!!!

What are binary characters?

 What am i missing here? Can someone please help.

What /exactly/ did you expect? Note that \x01d and \x01\x64 are just
different renderings of the same string chr(0x01) + chr(0x64).

Peter

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


writing to a file

2007-05-30 Thread montyphyton
as i understand there are two ways to write data to a file: using
f.write(foo) and print f, foo.
what i want to know is which one is faster (if there is any difference
in speed) since i'm working with very large files. of course, if there
is any other way to write data to a file, i'd love to hear about it

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


calling Postgresql stored procedure

2007-05-30 Thread Alchemist
I am using Python 2.4 and Postgresql 8.2 database server.

On the database I have created a stored function, example,
CREATE OR REPLACE FUNCTION calculateaverage()

I created a new python script and would like to call my database
stored function.

How can I call a database stored function/procedure in python?

Thanks

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


Re: Speex bindings for python 2.5

2007-05-30 Thread JarodEvans
On 30 mai, 02:30, momobear [EMAIL PROTECTED] wrote:
  I forgot to give the url http://www.freenet.org.nz/python/pySpeex/

 I Couldn't Open the website.

Maybe it was a temporary shutdown, I have no problem here.

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


Re: Speex bindings for python 2.5

2007-05-30 Thread David H Wild
In article [EMAIL PROTECTED],
   momobear [EMAIL PROTECTED] wrote:
  I forgot to give the url :http://www.freenet.org.nz/python/pySpeex/
 I Couldn't Open the website.
It works if you knock the colon off the front of the URL as given.

-- 
David Wild using RISC OS on broadband
www.davidhwild.me.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


A REAL money maker. IT WORKS!!!!

2007-05-30 Thread Signs Graphics Center
was up man does this stuff realy works


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


Re: writing to a file

2007-05-30 Thread Szabolcs Nagy

[EMAIL PROTECTED] wrote:
 as i understand there are two ways to write data to a file: using
 f.write(foo) and print f, foo.
well print will add a '\n' or ' ' if you use ',' after it

 what i want to know is which one is faster (if there is any difference
there shouldn't be any noticable difference

 in speed) since i'm working with very large files. of course, if there
 is any other way to write data to a file, i'd love to hear about it
other ways:
os.system('cat file1  file2')
or subprocess.Popen
or print but sys.stdout = f
or ctypes + printf/fputs/..

and probably there are other obscure ways, but the intended way is
obviously f.write

nsz

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


Re: Rats! vararg assignments don't work

2007-05-30 Thread samwyse
Gary Herron wrote:
 samwyse wrote:
 
I'm a relative newbie to Python, so please bear with me.  After seeing 
how varargs work in parameter lists, like this:
 def func(x, *arglist):
and this:
 x = func(1, *moreargs)
I thought that I'd try this:
 first, *rest = arglist
Needless to say, it didn't work.  That leaves me with two questions.

First, is there a good way to do this?  For now, I'm using this:
 first, rest = arglist[0], arglist[1:]
but it leaves a bad taste in my mouth.
  
 
 Well, your moreargs parameter is a tuple, and there are innumerable ways
 to process a tuple. (And even more if you convert it to a list.)

My use-case is (roughtly) this:
 first, *rest = f.readline().split()
 return dispatch_table{first}(*rest)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Key Listeners

2007-05-30 Thread Benedict Verheyen
[EMAIL PROTECTED] schreef:
 On 30 mai, 04:14, Mike [EMAIL PROTECTED] wrote:
 Are there key listeners for Python? Either built in or third party?
 
 What is a key listener ?
 

I thought it was a rather straightforward name.
Something that listens for a key. In other words, a piece of software
that detects what keys are being tapped.
In google, the first link is a link to the java sun home page.
The first sentence on that page: Key events indicate when the user is 
typing at the keyboard.

Regards,
Benedict

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


Re: Rats! vararg assignments don't work

2007-05-30 Thread samwyse
George Sakkis wrote:
 On May 29, 11:33 pm, Matimus [EMAIL PROTECTED] wrote:
 
 
Your attemtp:

[code]
first, rest = arglist[0], arglist[1:]
[/code]

Is the most obvious and probably the most accepted way to do what you
are looking for. As for adding the fucntionality you first suggested,
it isn't likely to be implemented. The first step would be to write a
PEP though.
 
 
 The time machine did it again: http://www.python.org/dev/peps/pep-3132/.

Thanks!  Now I just need to wait for Py3K and all of my problems will be 
solved.  ;-)

Actually, I'm surprised that the PEP does as much as it does.  If tuples 
are implemented as S-expressions, then something like this:
 car, *cdr = tuple
while leaving cdr a tuple would be trivial to implement.  Of course, I'm 
an old-school LISPer, so what I consider surprising behavior doesn't 
always surprise anyone else, and vice versa.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 2.5 and WXPython demo's

2007-05-30 Thread Andrew P
Hello,

I am new (very) to Python and have just down loaded the latest version
of Python (2.5) and WXPython (2.8).

For some reason I cannot get the WXPython demo to run at all. I run
windows XP and it can't find a program to run the demo. Any advice?
(apologies if this has been posted before).

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


Re: Rats! vararg assignments don't work

2007-05-30 Thread Wildemar Wildenburger
George Sakkis wrote:
 The time machine did it again: http://www.python.org/dev/peps/pep-3132/.

   

Uhm, John Swartzwelder, right?

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


Re: Python 2.5 and WXPython demo's

2007-05-30 Thread Steve Holden
Andrew P wrote:
 Hello,
 
 I am new (very) to Python and have just down loaded the latest version
 of Python (2.5) and WXPython (2.8).
 
 For some reason I cannot get the WXPython demo to run at all. I run
 windows XP and it can't find a program to run the demo. Any advice?
 (apologies if this has been posted before).
 
The demo is a separate download nowadays. Do you mean you just can't 
find it, or are you running it and does it give you some error message 
that you feel we shouldn't be told about?

A little more information, please ...

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
-- Asciimercial -
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.comsquidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-- Thank You for Reading 

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


Re: Python 2.5 and WXPython demo's

2007-05-30 Thread Wildemar Wildenburger
Andrew P wrote:
 Hello,

 I am new (very) to Python and have just down loaded the latest version
 of Python (2.5) and WXPython (2.8).

 For some reason I cannot get the WXPython demo to run at all. I run
 windows XP and it can't find a program to run the demo. Any advice?
 (apologies if this has been posted before).

   
There *should* be a link in your startmenu in the wxPython group. I'm 
quite positive, but not 100% sure. I think it has the snake-icon. But if 
it's really not there (as you suggested), simply go the the folder you 
installed the demo to and run demo.py.

Maybe there's a blunder in the installer for the 2.8 demo? Anyone?

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


Re: writing to a file

2007-05-30 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
 as i understand there are two ways to write data to a file: using
 f.write(foo) and print f, foo.
 what i want to know is which one is faster (if there is any difference
 in speed) since i'm working with very large files. of course, if there
 is any other way to write data to a file, i'd love to hear about it

You should look at the mmap-module.

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


Re: Rats! vararg assignments don't work

2007-05-30 Thread Bruno Desthuilliers
Matimus a écrit :
(snip)
  Remember, in Python there is only one way to do it.

Actually, it's :
There should be one-- and preferably only one --obvious way to do it..

... Which is quite different. Please notice the should, preferably 
and obvious.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python + Prolog

2007-05-30 Thread Jgressier
For those who may also work with Prolog :

http://code.google.com/p/pyswip/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Key Listeners

2007-05-30 Thread Bruno Desthuilliers
Benedict Verheyen a écrit :
 [EMAIL PROTECTED] schreef:
 On 30 mai, 04:14, Mike [EMAIL PROTECTED] wrote:
 Are there key listeners for Python? Either built in or third party?

 What is a key listener ?

(snip)
 In google, the first link is a link to the java sun home page.
 The first sentence on that page: Key events indicate when the user is 
 typing at the keyboard.

I do know what's a key listener in Java, thanks !-)

My question was supposed to have side effects - like the OP asking 
himself if he was really asking the right question.

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


Re: Unicode to HTML entities

2007-05-30 Thread Tommy Nordgren

On 29 maj 2007, at 17.52, Clodoaldo wrote:

 I was looking for a function to transform a unicode string into
 htmlentities. Not only the usual html escaping thing but all
 characters.

 As I didn't find I wrote my own:

 # -*- coding: utf-8 -*-
 from htmlentitydefs import codepoint2name

 def unicode2htmlentities(u):

htmlentities = list()

for c in u:
   if ord(c)  128:
  htmlentities.append(c)
   else:
  htmlentities.append('%s;' % codepoint2name[ord(c)])

return ''.join(htmlentities)

 print unicode2htmlentities(u'São Paulo')

 Is there a function like that in one of python builtin modules? If not
 is there a better way to do it?

 Regards, Clodoaldo Pinto Neto

In many cases, the need to use html/xhtml entities can be avoided by  
generating
utf8- coded pages.
--
Home is not where you are born, but where your heart finds peace -
Tommy Nordgren, The dying old crone
[EMAIL PROTECTED]


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


Re: pyAntTasks

2007-05-30 Thread kilnhead
On May 28, 7:56 am, kilnhead [EMAIL PROTECTED] wrote:
 I am trying to use pyAntTasks in Eclipse. I have followed the example
 in the ibm doc, but I get  the following error:

 [taskdef] Could not load definitions from resource
 pyAntTasks.properties. It could not be found.

 I have added pyAntTasks to my classpath and AntHome directory.

 Anybody have any ideas?

I found my major problem. It was spaces in my directory names.

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


Re: Tkinter Listbox - Different Text colors in one listbox

2007-05-30 Thread rfg007
On May 29, 2:02 pm, [EMAIL PROTECTED] wrote:
 Hi,
 Is it possible to havedifferentitems in alistboxindifferentcolors? Or is it 
 justonecolor for all items in alistbox?
 Thanks
 Rahul

from Tkinter import *

root = Tk()
l = Listbox(root)
l.pack()
for x in range(10):
l.insert(END, x)
l.itemconfig(2, bg='red', fg='white')
l.itemconfig(4, bg='green', fg='white')
l.itemconfig(5, bg='cyan', fg='white')
root.mainloop()

You can _only_ configurate 'background', 'foreground',
'selectbackground', 'selectforegroud', not font :(

HTH

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


Re: Rats! vararg assignments don't work

2007-05-30 Thread Maric Michaud
samwyse a écrit :
 George Sakkis wrote:
 On May 29, 11:33 pm, Matimus [EMAIL PROTECTED] wrote:


 Your attemtp:

 [code]
 first, rest = arglist[0], arglist[1:]
 [/code]

 Is the most obvious and probably the most accepted way to do what you
 are looking for. As for adding the fucntionality you first suggested,
 it isn't likely to be implemented. The first step would be to write a
 PEP though.

 The time machine did it again: http://www.python.org/dev/peps/pep-3132/.
 
 Thanks!  Now I just need to wait for Py3K and all of my problems will be 
 solved.  ;-)
 
 Actually, I'm surprised that the PEP does as much as it does.  If tuples 
 are implemented as S-expressions, then something like this:
  car, *cdr = tuple
 while leaving cdr a tuple would be trivial to implement.  Of course, I'm 
 an old-school LISPer, so what I consider surprising behavior doesn't 
 always surprise anyone else, and vice versa.

Remember all these are copies of the original sequence, the lisp
equivalent to car/cdr is feasible with an iterator :

it = iter(seq)
car, cdr = it.next(), it

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


Re: Key Listeners

2007-05-30 Thread kaens
On 5/30/07, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
 Benedict Verheyen a écrit :
  [EMAIL PROTECTED] schreef:
  On 30 mai, 04:14, Mike [EMAIL PROTECTED] wrote:
  Are there key listeners for Python? Either built in or third party?
 
  What is a key listener ?
 
 (snip)
  In google, the first link is a link to the java sun home page.
  The first sentence on that page: Key events indicate when the user is
  typing at the keyboard.

 I do know what's a key listener in Java, thanks !-)

 My question was supposed to have side effects - like the OP asking
 himself if he was really asking the right question.

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


What, he wants to know if there's a way in python to capture
keystrokes, and do something with them depending on what they are.

I mean, it's very unlikely that you would ask for something called a
key listener if you didn't want to do something like:

if keypress == 'a':
   do somem

right? Even if you're looking to do it the java way, all of the
listener functionality more or less boils down to wait for and report
keys being pressed.

He could have been less ambiguous, but I don't think that he was
asking the wrong question per se.

Not to mention asking the OP what's a key listener isn't going to
make them think about the question they asked - it makes it seem like
you don't know what a key listener is (and frankly, I think that if
you have done any work with doing stuff on different keystrokes,
you'll figure out what is meant by key listener pretty quickly, even
if you haven't heard the term before)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calling Postgresql stored procedure

2007-05-30 Thread Weinhandl Herbert
Alchemist schrieb:
 I am using Python 2.4 and Postgresql 8.2 database server.
 
 On the database I have created a stored function, example,
 CREATE OR REPLACE FUNCTION calculateaverage()
 
 I created a new python script and would like to call my database
 stored function.
 
 How can I call a database stored function/procedure in python?
 

with :

 SELECT calculateaverage() FROM ... WHERE ... ;

happy pythoning

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


Re: Periodic tasks.

2007-05-30 Thread vasudevram
Steve Howell wrote:

Thanks.  Here are two links, not sure those are
exactly what are being referenced here, but look in
the ballpark:

 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413137

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

You're welcome.

The ActiveState recipe you mention above is not the one I meant,
although it uses sched.
I saw the recipe that I mentioned, in the print version of the Python
Cookbook, when reading it a few days ago.

The second link above you mention is right, its about the sched
library.

Also just found these other recipes in the online Python Cookbook, may
or may not be of help to you:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496800
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/114644


Vasudev Ram
www.dancingbison.com


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


Re: Python 2.5 and WXPython demo's

2007-05-30 Thread stef
Wildemar Wildenburger wrote:
 Andrew P wrote:
 Hello,

 I am new (very) to Python and have just down loaded the latest version
 of Python (2.5) and WXPython (2.8).

 For some reason I cannot get the WXPython demo to run at all. I run
 windows XP and it can't find a program to run the demo. Any advice?
 (apologies if this has been posted before).

   
 There *should* be a link in your startmenu in the wxPython group. I'm 
 quite positive, but not 100% sure. I think it has the snake-icon. But 
 if it's really not there (as you suggested), simply go the the folder 
 you installed the demo to and run demo.py.

 Maybe there's a blunder in the installer for the 2.8 demo? Anyone?
Can't answer that, but on one from two (almost identical) PC's,
I had trouble too, the other went fluently.
On both PC's,
there was an older wxPython (2.6 I believe),
(which from what I've read should be no problem at all),
which wasn't overruled, by some specific file (wx.pth) to point to the 
newest.
The effect is that the demo tries to run, can't find aiw?? or something 
like that and crashes
(on fast PC's you actually just see a dos box flashing).
Editing the wx.pth file solved the problem.

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


Re: Rats! vararg assignments don't work

2007-05-30 Thread Sion Arrowsmith
samwyse  [EMAIL PROTECTED] wrote:
 samwyse wrote:
I thought that I'd try this:
 first, *rest = arglist
Needless to say, it didn't work.
 [ ... ]
My use-case is (roughtly) this:
 first, *rest = f.readline().split()
 return dispatch_table{first}(*rest)

first, rest = f.readline().split(None, 1)
return dispatch_table{first}(*rest.split())

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   Frankly I have no feelings towards penguins one way or the other
-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Key Listeners

2007-05-30 Thread momobear
On May 30, 10:14 am, Mike [EMAIL PROTECTED] wrote:
 Are there key listeners for Python? Either built in or third party?

try pykeylogger, that's maybe u want.

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


Re: SMTPAuthenticationError

2007-05-30 Thread Ramashish Baranwal
 To help debug this, you may want to try the following.

 1) Copy smptlib.py into your local directory.  On my
 box, you can find it here, or import sys; print
 sys.path to help find it on your box:

/usr/local/lib/python2.3

 2) Go the login() method, add some print statements
 there to see what's going on.

 I admit to not being an SMTP expert nor fully
 understanding the code at first glance, but here is
 some code iin smtplib.py that suggests you're close to
 getting this working, to the extent that your server
 wants base64 encoding:

 def encode_cram_md5(challenge, user,
 password):
 challenge = base64.decodestring(challenge)
 response = user +   +
 hmac.HMAC(password, challenge).hexdigest()
 return encode_base64(response, eol=)

 Hope this helps.

Thanks Steve, that helped a lot. smtplib was trying to a CRAM-MD5 auth
which wasn't working. I don't know why. But when I made it do a LOGIN
auth by changing its preferred_auth list, it worked. Login has its own
preferred list of auth methods which is nice except that not all
servers which advertise a particular method may be capable of handling
that.

It would have been good if there was optionally a way to specify in
login() what method to use. For now, I am simply going to derive SMTP
to form a class that does LOGIN auth.

Ram

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


Re: How to print this character u'\u20ac' to DOS terminal

2007-05-30 Thread momobear
On May 30, 3:05 pm, 人言落日是天涯,望极天涯不见家 [EMAIL PROTECTED] wrote:
 On 5月30日, 下午1时23分, Martin v. Lowis [EMAIL PROTECTED] wrote:



  人言落日是天涯,望极天涯不见家 schrieb:

   Who could explain the follow issue ?
   print u'\u0394'
   Δ
   print u'\u20ac'
   Traceback (most recent call last):
 File stdin, line 1, in module
   UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in
   position 0:
   illegal multibyte sequence

   My terminal is cmd.exe under windows XP.
   what's the different between the two character ? what can I do if I
   want to print the u'\u20ac'?

  The problem is that your terminal uses (some form of) the GBK encoding;
  seehttp://zh.wikipedia.org/wiki/GBKfordetails on GBK.

  It seems that GBK (or, rather, code page 936) supports the delta
  character, but not the euro sign.

  To change that, you can use chcp in your terminal window.
  For example, if you do chcp 850, you should be able to
  display the euro sign (but will simultaneously use the ability
  to display the letter delta, and the chinese letters).

  I don't know whether the terminal supports an UTF-8 code
  page; you can try setting the terminal's code page to
  65001 (which should be UTF-8).

  Regards,
  Martin

 Thanks, but it seems not work yet.

 
 C:\WINDOWSchcp 850
 Active code page: 850

 C:\WINDOWSpython
 Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
 (Intel)] on
 win32
 Type help, copyright, credits or license for more information. 
 print u'\u20ac'

 Traceback (most recent call last):
   File stdin, line 1, in module
   File C:\Python25\lib\encodings\cp850.py, line 12, in encode
 return codecs.charmap_encode(input,errors,encoding_map)
 UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac'
 in position
  0: character maps to undefined

 C:\WINDOWSchcp 65001
 Active code page: 65001

 C:\WINDOWSpython
 Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
 (Intel)] on
 win32
 Type help, copyright, credits or license for more information. 
 print u'\u20ac'

 Traceback (most recent call last):
   File stdin, line 1, in module
 LookupError: unknown encoding: cp65001
 ---
 I find that the u'\u20ac' related 'mbcs' encode is 0x80, I could print
 it directly

  print '\x80'
 �

 But the string contained the u'\u20ac' is get from remote host. Is
 there any method to decode it to the local 'mbcs'?

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

Re: Unicode to HTML entities

2007-05-30 Thread Clodoaldo
On May 30, 8:53 am, Tommy Nordgren [EMAIL PROTECTED] wrote:
 On 29 maj 2007, at 17.52, Clodoaldo wrote:



  I was looking for a function to transform a unicode string into
  htmlentities. Not only the usual html escaping thing but all
  characters.

  As I didn't find I wrote my own:

  # -*- coding: utf-8 -*-
  from htmlentitydefs import codepoint2name

  def unicode2htmlentities(u):

 htmlentities = list()

 for c in u:
if ord(c)  128:
   htmlentities.append(c)
else:
   htmlentities.append('%s;' % codepoint2name[ord(c)])

 return ''.join(htmlentities)

  print unicode2htmlentities(u'São Paulo')

  Is there a function like that in one of python builtin modules? If not
  is there a better way to do it?

  Regards, Clodoaldo Pinto Neto

 In many cases, the need to use html/xhtml entities can be avoided by
 generating
 utf8- coded pages.

Sure. All my pages are utf-8 encoded. The case I'm dealing with is an
email link which subject has non ascii characters like in:

a href=mailto:[EMAIL PROTECTED]Mail to/a

Somehow when the user clicks on the link the subject goes to his email
client with the non ascii chars as garbage.

And before someone points that I should not expose email addresses,
the email is only linked with the consent of the owner and the source
is obfuscated to make it harder for a robot to harvest it.

Regards, Clodoaldo

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


Re: How to print this character u'\u20ac' to DOS terminal

2007-05-30 Thread momobear
On May 30, 3:05 pm, 人言落日是天涯,望极天涯不见家 [EMAIL PROTECTED] wrote:
 On 5月30日, 下午1时23分, Martin v. Lowis [EMAIL PROTECTED] wrote:



  人言落日是天涯,望极天涯不见家 schrieb:

   Who could explain the follow issue ?
   print u'\u0394'
   Δ
   print u'\u20ac'
   Traceback (most recent call last):
 File stdin, line 1, in module
   UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in
   position 0:
   illegal multibyte sequence

   My terminal is cmd.exe under windows XP.
   what's the different between the two character ? what can I do if I
   want to print the u'\u20ac'?

  The problem is that your terminal uses (some form of) the GBK encoding;
  seehttp://zh.wikipedia.org/wiki/GBKfordetails on GBK.

  It seems that GBK (or, rather, code page 936) supports the delta
  character, but not the euro sign.

  To change that, you can use chcp in your terminal window.
  For example, if you do chcp 850, you should be able to
  display the euro sign (but will simultaneously use the ability
  to display the letter delta, and the chinese letters).

  I don't know whether the terminal supports an UTF-8 code
  page; you can try setting the terminal's code page to
  65001 (which should be UTF-8).

  Regards,
  Martin

 Thanks, but it seems not work yet.

 
 C:\WINDOWSchcp 850
 Active code page: 850

 C:\WINDOWSpython
 Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
 (Intel)] on
 win32
 Type help, copyright, credits or license for more information. 
 print u'\u20ac'

 Traceback (most recent call last):
   File stdin, line 1, in module
   File C:\Python25\lib\encodings\cp850.py, line 12, in encode
 return codecs.charmap_encode(input,errors,encoding_map)
 UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac'
 in position
  0: character maps to undefined

 C:\WINDOWSchcp 65001
 Active code page: 65001

 C:\WINDOWSpython
 Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
 (Intel)] on
 win32
 Type help, copyright, credits or license for more information. 
 print u'\u20ac'

 Traceback (most recent call last):
   File stdin, line 1, in module
 LookupError: unknown encoding: cp65001
 ---
 I find that the u'\u20ac' related 'mbcs' encode is 0x80, I could print
 it directly

  print '\x80'
 �

 But the string contained the u'\u20ac' is get from remote host. Is
 there any method to decode it to the local 'mbcs'?

forgot to unicode(string) before send it?

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

Re: Unicode to HTML entities

2007-05-30 Thread Clodoaldo
On May 30, 4:25 am, Duncan Booth [EMAIL PROTECTED] wrote:
 Clodoaldo [EMAIL PROTECTED] wrote:
  On May 29, 12:57 pm, Richard Brodie [EMAIL PROTECTED] wrote:
  Clodoaldo [EMAIL PROTECTED] wrote in message

 news:[EMAIL PROTECTED]

  I was looking for a function to transform a unicode string into
  htmlentities.
   u'São Paulo'.encode('ascii', 'xmlcharrefreplace')

  'S#227;o Paulo'

  That was a fast answer. I would never find that myself.

 You might actually want:

  cgi.escape(u'São Paulo  Espírito Santo').encode('ascii', 
  'xmlcharrefreplace')

 'S#227;o Paulo amp; Esp#237;rito Santo'

 as you have to be sure to escape any ampersands in your unicode
 string before doing the encode.

I will do it. Thanks.

Regards, Clodoaldo.

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


Pydev 1.3.4 Released

2007-05-30 Thread Fabio Zadrozny

Hi All,

Pydev and Pydev Extensions 1.3.4 have been released

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

Release Highlights in Pydev Extensions:
-

*  Mark Occurrences: 'global' used in the global scope is correctly treated.
* Code Analysis: __builtins__ considered in global namespace

Release Highlights in Pydev:
--

* Debugger: Breakpoints working correctly on external files opened with
'File  Open File...'.
* Debugger: Python 2.5 accepts breakpoints in the module level.
* Debugger: Unicode variables can be shown in the variables view.
* Editor: Coding try..except / try..finally auto-dedents.
* Code Completion: __builtins__ considered a valid completion
* Pydev Package Explorer: Opens files with correct editor (the pydev editor
was forced).



What is PyDev?
---

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


Cheers,

--
Fabio Zadrozny
--
Software Developer

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

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

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

Re: Periodic tasks.

2007-05-30 Thread momobear
On May 29, 2:33 pm, Ramashish Baranwal [EMAIL PROTECTED]
wrote:
 Hi,

 I am trying to execute some tasks periodically, those familiar with
 unix can think of it as equivalent to cron jobs. I have tried looking
 around, but couldn't find a way. Would appreciate any pointers or
 clues..

 Thanks,
 -Ram

I googled twisted cron, if u use twisted, that's maybe help u:
http://svn.zope.org/Zope3/trunk/src/scheduler/cron.py?rev=38967view=auto
http://twistedmatrix.com/pipermail/twisted-python/2006-June/013525.html

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


Re: How to print this character u'\u20ac' to DOS terminal

2007-05-30 Thread Tijs
??? wrote:

 But the string contained the u'\u20ac' is get from remote host. Is
 there any method to decode it to the local 'mbcs'?

remote_string = u'\u20ac'
try:
   local_string = remote_string.encode('mbcs')
except:
   # no mbcs equivalent available
   print encoding error
else:
   # local_string is now an 8-bit string
   print result:, local_string
   # if console is not mbcs, you should see incorrect result
   assert result == '\x80'

Mbcs is windows-only so I couldn't test this. 

If your application handles text, it may be easier to just leave everything
in Unicode and encode to utf-8 for storage?

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


Re: Malformed big5 reading bug

2007-05-30 Thread Facundo Batista
tsuraan wrote:

 Python enters some sort of infinite loop when attempting to read data from a
 malformed file that is big5 encoded (using the codecs library).  This
 behaviour can be observed under Linux and FreeBSD, using Python 2.4 and 2.5.
 A really simple example illustrating the bug follows:
 ...
 be a good but to have out there so a future version of python can
 (hopefully) fix this.

Please, file a bug in SourceForge, with the example and everything.

Thanks!
-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


Re: xmlrpclib hangs execution

2007-05-30 Thread Arno Stienen
I'm sorry to keep bumping my request, but I've been working on this 
problem for several months now and am stuck. Perhaps you do not have a 
direct answer, but know someone or someforum where I could ask these 
XML-RPC or TCP/IP package questions.

Thanks,
Arno.

Arno Stienen wrote:
 Perhaps I should be a bit more specific. When using this code to connect 
 to a remote XML-RPC server (C++, xmlrpc++0.7 library):
 
import xmlrpclib
server = xmlrpclib.Server(http://10.10.101.62:29500;)
print server.Connection_Request(roberto)
 
 the Python command line 'hangs' until I kill the server. Then, the 
 correct output is suddenly displayed:
 
{'state': 0, 'id_session': '2Z3EUSLJFA13', 'port': 29501,
'str': 'Connection accepted. Session attached.'}
 
 Yet a slightly simpler call works flawlessly:
 
import xmlrpclib
server = xmlrpclib.Server(http://10.10.101.62:29500;)
print server.Info_RT('Master')
 
{'state': 0, 'str': 'Info_RT'}
 
 Looking at the TCP packages (using Wireshark), the first 
 Connection_Request flow as follows (c=python client,s= xml-rpcserver):
 
   1   cs SYN
   2   sc SYN,ACK
   3   cs ACK
   4   cs PSH,ACK (setting content-type: text/xml)
   5   sc ACK
   6   cs PSH,ACK (xml-rpc request)
   7   sc ACK
   8   sc PSH,ACK (xml-rpc results, correct)
   9   cs ACK
 
 At this point, Python 'hangs' until I kill (-9) the server (28 seconds 
 later), and then these last packages are send:
 
 10sc FIN,ACK
 11cs FIN,ACk
 12sc ACK
 
 After which Python continues and prints the xml-rpc results on the 
 screen. Strangely, before Python hangs, it has already received the 
 package with the results, but doesn't do anything with it.
 
 For comparison, this is the package flow for the Info_RT method, which 
 returns within a second with the correct result on the Python command line:
 
   1   cs SYN
   2   sc SYN,ACK
   3   cs ACK
   4   cs PSH,ACK (setting content-type: text/xml)
   5   sc ACK
   6   cs PSH,ACK (xml-rpc request)
   7   sc ACK
   8   sc PSH,ACK (xml-rpc results, correct)
   9   sc FIN,ACK
 10cs ACK
 11cs FIN,ACk
 12sc ACK
 
 Notice the reverse order of packages 9 and 10. Could this be it? Is 
 Python waiting until the server sends a FIN package? But if so, why?
 
 Looking at the Python trace, this might be it. A diff between the trace 
 of the killed Connection_Request and the Info_RT resulted only in 
 expected differences (due to different length of parameters). But when 
 diffing the traces of the killed and non-killed Connection_Request, 
 something else is visible. The killed Connection_Request ends with:
 
 [...]
 string:318: return sep.join(words)
 xmlrpclib:866: self._type = params
 xmlrpclib:769: try:
 xmlrpclib:770: f = self.dispatch[tag]
 xmlrpclib:771: except KeyError:
 xmlrpclib:772: pass # unknown tag ?
 xmlrpclib:1273: if sock:
 xmlrpclib:1274: response = sock.recv(1024)
 xmlrpclib:1277: if not response:
 xmlrpclib:1278: break
 xmlrpclib:1283: file.close()
 socket:218: try:
 socket:219: if self._sock:
 socket:220: self.flush()
 socket:232: if self._wbuf:
 socket:222: self._sock = None
 xmlrpclib:1284: p.close()
 xmlrpclib:530: self._parser.Parse(, 1) # end of data
 xmlrpclib:531: del self._target, self._parser # get rid of 
 circular references
 xmlrpclib:1286: return u.close()
 xmlrpclib:741: if self._type is None or self._marks:
 xmlrpclib:743: if self._type == fault:
 xmlrpclib:745: return tuple(self._stack)
 socket:225: try:
 socket:226: self.close()
 socket:218: try:
 socket:219: if self._sock:
 socket:222: self._sock = None
 xmlrpclib:1386: if len(response) == 1:
 xmlrpclib:1387: response = response[0]
 xmlrpclib:1389: return response
 __main__:26: print result
 {'state': 0, 'id_session': 'QDLY3GP9FBM5', 'port': 29501, 'str': 
 'Connection accepted. Session attached.'}
 
 But the non-killed Connection_Request looks like:
 
 [...]
 return sep.join(words)
 xmlrpclib:866: self._type = params
 xmlrpclib:769: try:
 xmlrpclib:770: f = self.dispatch[tag]
 xmlrpclib:771: except KeyError:
 xmlrpclib:772: pass # unknown tag ?
 xmlrpclib:1273: if sock:
 xmlrpclib:1274: response = sock.recv(1024)
 socket:225: try:
 socket:226: self.close()
 socket:218: try:
 socket:219: if self._sock:
 socket:220: self.flush()
 socket:232: if self._wbuf:
 socket:222: self._sock = None
 
 (In the diff there is a gap 

Re: Scope - import and globals

2007-05-30 Thread Tijs
HMS Surprise wrote:

 
 In the file snippet below the value for the global hostName is
 determined at runtime. Functions imported from the parent  baseClass
 file such as logon also need access to this variable but cannot see it
 the with the implementation I have attempted here.

Use a class variable:

class baseClass:
hostName = None   # undefined yet

def someFunc(self):
assert self.hostName is not None, hostname not set yet
... # use hostName here

class temp(baseClass):
def runTest(self):
baseClass.hostName = getHostName()
...

or a global variable:

baseClass.py:

hostName = None
class baseClass:
def someFunc(self):
assert hostName is not None


testme.py:

import baseClass
class temp(baseClass.baseClass):

baseClass.hostName = getHostName()

although neither solution strikes me as very elegant. I would normally pass
the hostname to the constructor of baseClass or use a separate 'settings'
module.

Global variables are per-module. Use the global keyword when assigning a
global variable in the 'current' module. Global variables of other modules
are properties of the module, use module.name. 

 
 Also, functions in this file and in the imported parent class need
 PyHttpTestCase. Does there need to be an import statement in both
 files?

Yes. Don't worry, the work is done only once.

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


Re: Python 2.5 and WXPython demo's

2007-05-30 Thread kyosohma
On May 30, 7:29 am, stef [EMAIL PROTECTED] wrote:
 Wildemar Wildenburger wrote:
  Andrew P wrote:
  Hello,

  I am new (very) to Python and have just down loaded the latest version
  of Python (2.5) and WXPython (2.8).

  For some reason I cannot get the WXPython demo to run at all. I run
  windows XP and it can't find a program to run the demo. Any advice?
  (apologies if this has been posted before).

  There *should* be a link in your startmenu in the wxPython group. I'm
  quite positive, but not 100% sure. I think it has the snake-icon. But
  if it's really not there (as you suggested), simply go the the folder
  you installed the demo to and run demo.py.

  Maybe there's a blunder in the installer for the 2.8 demo? Anyone?

 Can't answer that, but on one from two (almost identical) PC's,
 I had trouble too, the other went fluently.
 On both PC's,
 there was an older wxPython (2.6 I believe),
 (which from what I've read should be no problem at all),
 which wasn't overruled, by some specific file (wx.pth) to point to the
 newest.
 The effect is that the demo tries to run, can't find aiw?? or something
 like that and crashes
 (on fast PC's you actually just see a dos box flashing).
 Editing the wx.pth file solved the problem.

 cheers,
 Stef Mientki

I haven't had any problems in with the demo...but then again, I
uninstalled the previous version before putting on the new demo. I did
have some minor problems choosing which version I wanted to run with
my scripts, but that has nothing to do with the demo.

Mike

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


Windows build of PostgreSQL library for 2.5

2007-05-30 Thread Ben Sizer
I've been looking for a Windows version of a library to interface to
PostgreSQL, but can only find ones compiled under Python version 2.4.
Is there a 2.5 build out there?

--
Ben Sizer

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


Re: Key Listeners

2007-05-30 Thread Bruno Desthuilliers
kaens a écrit :
 On 5/30/07, Bruno Desthuilliers
 [EMAIL PROTECTED] wrote:
 Benedict Verheyen a écrit :
  [EMAIL PROTECTED] schreef:
  On 30 mai, 04:14, Mike [EMAIL PROTECTED] wrote:
  Are there key listeners for Python? Either built in or third party?
 
  What is a key listener ?
 
 (snip)
  In google, the first link is a link to the java sun home page.
  The first sentence on that page: Key events indicate when the user is
  typing at the keyboard.

 I do know what's a key listener in Java, thanks !-)

 My question was supposed to have side effects - like the OP asking
 himself if he was really asking the right question.

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

 
 What, he wants to know if there's a way in python to capture
 keystrokes, and do something with them depending on what they are.

Which would have been a much better way to express the question.

 I mean, it's very unlikely that you would ask for something called a
 key listener if you didn't want to do something like:
 
 if keypress == 'a':
   do somem
 
 right?

Wrong. *You* can deduce this from the OP question because you know Java 
(and more exactly : GUI programming in Java).

As far as I'm concerned, a 'key listener' could be something observing 
adding/deletion of key/value couples in a dict !-)

 Not to mention asking the OP what's a key listener isn't going to
 make them think about the question they asked - it makes it seem like
 you don't know what a key listener is

Exactly. Which may lead the OP to the conclusion that not everybody 
knows Java GUI programming, and that it may be better to ask in more 
general terms...

Also, and FWIW, there are words that name very different concepts in 
different languages. And I don't know each and every concept of each and 
every language in the world (perhaps you do ?). So, just because I know 
what name X means in langage Y doesn't necessarily imply the OP isn't 
thinking of what it means in langage ZZ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Key Listeners

2007-05-30 Thread Benedict Verheyen
kaens schreef:
snip

 
 What, he wants to know if there's a way in python to capture
 keystrokes, and do something with them depending on what they are.
 
 I mean, it's very unlikely that you would ask for something called a
 key listener if you didn't want to do something like:
 
 if keypress == 'a':
do somem
 
 right? Even if you're looking to do it the java way, all of the
 listener functionality more or less boils down to wait for and report
 keys being pressed.
 
 He could have been less ambiguous, but I don't think that he was
 asking the wrong question per se.
 
 Not to mention asking the OP what's a key listener isn't going to
 make them think about the question they asked - it makes it seem like
 you don't know what a key listener is (and frankly, I think that if
 you have done any work with doing stuff on different keystrokes,
 you'll figure out what is meant by key listener pretty quickly, even
 if you haven't heard the term before)

That's how it came across for me too. Couldn't have said it better kaens.

Benedict

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


New-style classes and special methods

2007-05-30 Thread Raj B
Hi

My question is about how special methods are stored internally in  
Python objects.
Consider a new-style class which implements special methods such as  
__call__ and __new__

class C(type):
def __call__(...):
body

class B:
__metaclass__ = C
stuff

b= B()

The type of C is 'type', that of B is 'C'. When B is instantiated,  
the __call__ method of C is first invoked, since C is the metaclass  
for B.

Internally, when a Python callable object 'obj' is called, the actual  
function called seems to be
'obj-ob_type-tp_call'.

Does this that somehow the '__call__' method defined in C above is  
assigned to the 'tp_call' slot in the object representing the class  
C, instead of it just being stored in the dictionary like a normal  
attribute? Where and how does this magic happen exactly? I'd  
appreciate any level of detail.

Thanks!
Raj


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


Re: Windows build of PostgreSQL library for 2.5

2007-05-30 Thread Frank Millman
On May 30, 4:15 pm, Ben Sizer [EMAIL PROTECTED] wrote:
 I've been looking for a Windows version of a library to interface to
 PostgreSQL, but can only find ones compiled under Python version 2.4.
 Is there a 2.5 build out there?

 --
 Ben Sizer

Is this what you are looking for?

http://stickpeople.com/projects/python/win-psycopg/

Frank Millman

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


google maps api for py?

2007-05-30 Thread Bell, Kevin
I see that the weapon of choice for google maps is javascript...  Is
there anything for python?

 

Kev

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

Re: writing to a file

2007-05-30 Thread sturlamolden
On May 30, 1:41 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] schrieb:

  what i want to know is which one is faster (if there is any difference
  in speed) since i'm working with very large files. of course, if there
  is any other way to write data to a file, i'd love to hear about it

 You should look at the mmap-module.


Yes, memory mappings can be more efficient than files accessed using
file descriptors. But mmap does not take an offset parameter, and is
therefore not suited for working with large files. For example you
only have a virtual memory space of 4 GiB on a 32 bit system, so there
is no way mmap can access the last 4 GiB of an 8 GiB file on a 32 bit
system. If mmap took an offset parameter, this would not be a problem.

However, numpy has a properly working memory mapped array class,
numpy.memmap. It can be used for fast file access. Numpy also has a
wide range of datatypes that are efficient for working with binary
data (e.g. an uint8 type for bytes), and a record array for working
with structured binary data. This makes numpy very attractive when
working with binary data files.

Get the latest numpy here: www.scipy.org.

Let us say you want to memory map an 23 bit RGB image of 640 x 480
pixels, located at an offset of 4096 bytes into the file 'myfile.dat'.
Here is how numpy could do it:

import numpy

byte = numpy.uint8
desc = numpy.dtype({'names':['r','g','b'],'formats':[byte,byte,byte]})
mm = numpy.memmap('myfile.dat', dtype=desc, offset=4096,
shape=(480,640), order='C')
red = mm['r']
green = mm['g']
blue = mm['b']

Now you can access the RGB values simply by slicing the arrays red,
green, and blue. To set the R value of every other horizontal line to
0, you could simply write

red[::2,:] = 0

As always when working with memory mapped files, the changes are not
committed before the memory mapping is synchronized with the file
system. Thus, call

mm.sync()

when you want the actual write process to start.

The memory mapping will be closed when it is garbage collected
(typically when the reference count falls to zero) or when you call
mm.close().






























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


Re: xmlrpclib hangs execution

2007-05-30 Thread Tijs
Arno Stienen wrote:

 Arno Stienen wrote:
 Perhaps I should be a bit more specific. When using this code to connect
 to a remote XML-RPC server (C++, xmlrpc++0.7 library):
 
import xmlrpclib
server = xmlrpclib.Server(http://10.10.101.62:29500;)
print server.Connection_Request(roberto)
 
 the Python command line 'hangs' until I kill the server. Then, the
 correct output is suddenly displayed:
 
{'state': 0, 'id_session': '2Z3EUSLJFA13', 'port': 29501,
'str': 'Connection accepted. Session attached.'}
 
 Yet a slightly simpler call works flawlessly:
 
import xmlrpclib
server = xmlrpclib.Server(http://10.10.101.62:29500;)
print server.Info_RT('Master')
 
{'state': 0, 'str': 'Info_RT'}
 

After having a quick look at your files, I conclude that the problem is in a
combination of two problems:

1. Your server is crap. It answers an HTTP/1.0 request by an HTTP/1.1
response without specifying any Connection header and without closing the
connection. Normally, a simple client that is not HTTP/1.1-aware expects
the connection to close. HTTP/1.1 leaves the connection open by default.

2. The Python implementation of xmlrpc is not very robust. It just waits for
the connection to close. A well-written client (like your Java client)
would detect the presence of a Content-Length header and use that. 

The other request is OK because the server closes the connection after
having sent the response. Why the difference? Don't know, but it is
something server-side. 

Try to force the server to send HTTP/1.0 responses, or turn off keep-alive,
or something like that. Otherwise, adapt xmlrpclib.py to robustly handle
1.1 responses.

-- 

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


Re: New-style classes and special methods

2007-05-30 Thread Alex Martelli
Raj B [EMAIL PROTECTED] wrote:

 Hi
 
 My question is about how special methods are stored internally in  
 Python objects.
 Consider a new-style class which implements special methods such as  
 __call__ and __new__
 
 class C(type):
   def __call__(...):
   body
 
 class B:
   __metaclass__ = C
   stuff
 
 b= B()
 
 The type of C is 'type', that of B is 'C'. When B is instantiated,  
 the __call__ method of C is first invoked, since C is the metaclass  
 for B.
 
 Internally, when a Python callable object 'obj' is called, the actual
 function called seems to be
 'obj-ob_type-tp_call'.
 
 Does this that somehow the '__call__' method defined in C above is  
 assigned to the 'tp_call' slot in the object representing the class  
 C, instead of it just being stored in the dictionary like a normal  
 attribute? Where and how does this magic happen exactly? I'd  
 appreciate any level of detail.

Yes, special methods populate the slots in the structures which Python
uses to represent types.  Objects/typeobject.c in the Python source
distribution does the hard work, particularly in function type_new (line
1722 in my current SVN checkout).

If you're not comfortable reading C code you may want to try looking at
the Python implemented in Python project, pypy, or perhaps
alternatives such as Jython (in Java) or better IronPython (in C#), but
I am not familiar in detail with how they deal with the issue.


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


Re: How to print this character u'\u20ac' to DOS terminal

2007-05-30 Thread 人言落日是天涯,望极天涯不见家
On 5月30日, 下午9时03分, Tijs [EMAIL PROTECTED] wrote:
 ??? wrote:
  But the string contained the u'\u20ac' is get from remote host. Is
  there any method to decode it to the local 'mbcs'?

 remote_string = u'\u20ac'
 try:
local_string = remote_string.encode('mbcs')
 except:
# no mbcs equivalent available
print encoding error
 else:
# local_string is now an 8-bit string
print result:, local_string
# if console is not mbcs, you should see incorrect result
assert result == '\x80'

 Mbcs is windows-only so I couldn't test this.

 If your application handles text, it may be easier to just leave everything
 in Unicode and encode to utf-8 for storage?

 Regards,
 Tijs

Yes, it works, thank you.
But I doubt this way may not work on linux.  Maybe I should write some
additional code for supporting both windows and linux OS.

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

Re: Rats! vararg assignments don't work

2007-05-30 Thread Alex Martelli
samwyse [EMAIL PROTECTED] wrote:
   ...
 Actually, I'm surprised that the PEP does as much as it does.  If tuples
 are implemented as S-expressions, then something like this:

Tuples are implemented as compact arrays of pointer-to-PyObject (so are
lists, BTW).  So, for example, a 10-items tuple takes 40 bytes (plus a
small overhead for the header) on a 32-bit build, not 80 as it would if
implemented as a linked list of (pointer-to-object, pointer-to-next)
pairs; addressing sometuple[N] is O(1), NOT O(N); etc, etc.


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


Re: How to print this character u'\u20ac' to DOS terminal

2007-05-30 Thread Tijs
人言落日是天涯,望极天涯不见家 wrote:


 Yes, it works, thank you.
 But I doubt this way may not work on linux.  Maybe I should write some
 additional code for supporting both windows and linux OS.

Depends on what you want to do. Printing to a DOS terminal is hard in
Linux :-) If you write server code, best to keep all text in unicode. 

-- 

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

Re: writing to a file

2007-05-30 Thread sturlamolden
On May 30, 4:53 pm, sturlamolden [EMAIL PROTECTED] wrote:

 import numpy

 byte = numpy.uint8
 desc = numpy.dtype({'names':['r','g','b'],'formats':[byte,byte,byte]})
 mm = numpy.memmap('myfile.dat', dtype=desc, offset=4096,
 shape=(480,640), order='C')
 red = mm['r']
 green = mm['g']
 blue = mm['b']

An other thing you may commonly want to do is coverting between numpy
uint8 arrays and raw strings. This is done using the methods
numpy.fromstring and numpy.tostring.

# reading from file to raw string
rstr = mm.tostring()

# writing raw string to file
mm[:] = numpy.fromstring(rstr, dtype=numpy.uint8)
mm.sync()










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


Re: Windows build of PostgreSQL library for 2.5

2007-05-30 Thread Ben Sizer
On 30 May, 15:42, Frank Millman [EMAIL PROTECTED] wrote:
 On May 30, 4:15 pm, Ben Sizer [EMAIL PROTECTED] wrote:

  I've been looking for a Windows version of a library to interface to
  PostgreSQL, but can only find ones compiled under Python version 2.4.
  Is there a 2.5 build out there?

 Is this what you are looking for?

 http://stickpeople.com/projects/python/win-psycopg/

It may well be, thanks.

--
Ben Sizer


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


Creating a distro of python... What would you include in it?

2007-05-30 Thread farksimmons
I am creating a distro of Python to be licensed as GPL am
wondering, what would anyone suggest as to 3rd party modules being put
into it (non-commercial of course!)? I know I'd put MySQLdb into it at
the very least. Any suggestions?

Thanks,

Fark Simmons
[insert clever tagline here /]

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


Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread John DeRosa
+1 QOTW

On Wed, 30 May 2007 06:18:36 GMT, Tim Roberts [EMAIL PROTECTED] wrote:

Frank Swarbrick [EMAIL PROTECTED] wrote:

Then you'd really love COBOL!

:-)

Frank
COBOL programmer for 10+ years

Hey, did you hear about the object-oriented version of COBOL?  They call it
ADD ONE TO COBOL.
-- 
http://mail.python.org/mailman/listinfo/python-list


Anyone else has seen forrtl: error (200) ...

2007-05-30 Thread Alexander Eisenhuth
Hello,

Ctrl+C is not passed to the interpreter (i guess it) while I'm executing a 
script. Instead i get:
forrtl: error (200): program aborting due to control-C event

If I start python in interactive mode Ctrl+C is passed:

bash-3.2$ python
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win
32
Type help, copyright, credits or license for more information.
  raw_input()
Traceback (most recent call last):
   File stdin, line 1, in module
KeyboardInterrupt
 

Any idea ?

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


Call for Ruby Champion !!

2007-05-30 Thread IT Recruiter
Hello friends!

I am looking for a Ruby Champion to lead the race in Website
development within Java environment...

Who loves programming, with new techniques as well as old.
Who also enjoys hand coding open source technologies with in-depth
knowledge of statistical methods
Has a practical approach when it comes to problem solving
And aspires a team spirit to be agile...

It's very useful to have other programming languages and paradigms

About Client: Young Company, fastest growing in the web market

This is a permanent role in central London, paying as per market rate
for the excellent candidate


About Me: I am a Resourcing Consultant specialist in recruiting for
Open Source Technologies.

please do not hesitate to speak to me or write me back !

Really appreciable for a word of mouth with our friends !!!

Cheers,
Srini

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


Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread Szabolcs Nagy

John DeRosa wrote:
 +1 QOTW

 Hey, did you hear about the object-oriented version of COBOL?  They call it
 ADD ONE TO COBOL.

actually it is ADD 1 TO COBOL GIVING COBOL

http://en.wikipedia.org/wiki/COBOL#Aphorisms_and_humor_about_COBOL

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


How can an Exception pass over an except clause ?

2007-05-30 Thread Nebur
I'm using the contract.py library, running Python 2.4.4.

Now I'm confronted with the following exception backtrace:
 (...)
  File /usr/lib/python2.4/site-packages/contract.py, line 1265, in
_check_preconditions
p = f.__assert_pre
AttributeError: 'function' object has no attribute '__assert_pre'

For my surprise, I found that the code of contract.py around line 1265
looks like:

1264: try:
1265: p = f.__assert_pre
1266: except AttributeError:
1267: pass

I'd expect line 1267 to swallow the AttributeError siliently. But
the application stops with the above backtrace.
Someone familiar enough with the Python innards ? How can one manage
that an except seems to be ignored ?

 Ruben

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


Re: New-style classes and special methods

2007-05-30 Thread Raj B
  Yes, special methods populate the slots in the structures which  
Python
  uses to represent types.  Objects/typeobject.c in the Python source
  distribution does the hard work, particularly in function type_new



Thanks for that quick response. I am quite comfortable with C code  
and am trying to understand exactly what happens when a new-style  
class is created, and then instantiated.

I have been reading typeobject.c and type_new() inside it in detail,  
and there are a few issues I am trying to figure out.

I can see a lot of *SLOT() macros in the file that seem to set the  
slots to appropriate values. What I am having trouble figuring out is  
the connection i.e. at what point during construction of the class  
object in type_new() are those slots allotted? Is it the tp_alloc()  
function which does this?

Is there some kind of descriptor or other mechanism connecting  
special method names with their slots in the object representation?  
(e.g. __call__ with type-tp_call)

Also, what happens when a class inherits from multiple classes with  
their own __call__ methods? Where and how  is it decided which  
__call__ goes into the tp_call slot?

I'm sure I'll eventually figure it out if I stare at the code hard  
enough, but would totally appreciate any help I can get :)

Thanks again!

Raj





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


Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread Joe Riopel
Using camel case instead of the under_score means less typing. I am lazy.

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


Re: Call for Ruby Champion !!

2007-05-30 Thread Robin Becker
IT Recruiter wrote:
 Hello friends!
 
 I am looking for a Ruby Champion to lead the race in Website
 development within Java environment...
 
 Who loves programming, with new techniques as well as old.
 Who also enjoys hand coding open source technologies with in-depth
 knowledge of statistical methods
 Has a practical approach when it comes to problem solving
 And aspires a team spirit to be agile...
 
 It's very useful to have other programming languages and paradigms
 
 About Client: Young Company, fastest growing in the web market
 
 This is a permanent role in central London, paying as per market rate
 for the excellent candidate
 
 
 About Me: I am a Resourcing Consultant specialist in recruiting for
 Open Source Technologies.
 
 please do not hesitate to speak to me or write me back !
 
 Really appreciable for a word of mouth with our friends !!!
 
 Cheers,
 Srini
 
Boy have you got the wrong vampire ;)

-- 
Robin Becker

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


Re: Anyone else has seen forrtl: error (200) ...

2007-05-30 Thread Jason
On May 30, 9:33 am, Alexander Eisenhuth [EMAIL PROTECTED]
wrote:
 Hello,

 Ctrl+C is not passed to the interpreter (i guess it) while I'm executing a
 script. Instead i get:
 forrtl: error (200): program aborting due to control-C event

 If I start python in interactive mode Ctrl+C is passed:

 bash-3.2$ python
 Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on 
 win
 32
 Type help, copyright, credits or license for more information.
   raw_input()
 Traceback (most recent call last):
File stdin, line 1, in module
 KeyboardInterrupt
  

 Any idea ?

 Thanks
 Alexander

Forrtl indicates that your script is running a Fortran library or
program.  Remember that Python exceptions only apply during Python.
If a Fortran DLL performs a divide-by-zero error, or accesses invalid
memory, it will kill the interpreter instead of throwing a Python
exception.  With Compaq Visual Fortran, the Fortran library calls can
kill your entire program if a function receives an invalid value.
(Try raising a negative real number to a fractional exponent, for
example.)

I'd guess that the Fortran code is intercepting the CTRL-C signal and
killing the running script.

Without knowing anything about your script and the library calls it
makes, I can't give you much advice.  There may be little that you can
do, especially if you don't have the Fortran source code in question
and/or can't recompile it.  Maybe someone with some Fortran/Python
experience can assist you.

  --Jason

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


Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread projecktzero
On May 30, 12:36 am, Hendrik van Rooyen [EMAIL PROTECTED]
wrote:
  Maric Michaud [EMAIL PROTECTED] wrote:

 Typist is fine, although MCP that I am, I tend to think of
 typist as female...

 - Hendrik

What does being a Microsoft Certified Professional(MCP) have to do
with thinking of a typist as female? =)

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


Re: Creating a distro of python... What would you include in it?

2007-05-30 Thread Simon Hibbs
On 30 May, 16:25, [EMAIL PROTECTED] wrote:
 I am creating a distro of Python to be licensed as GPL am
 wondering, what would anyone suggest as to 3rd party modules being put
 into it (non-commercial of course!)? I know I'd put MySQLdb into it at
 the very least. Any suggestions?

What you put in it will depend on what it's for.

Which platforms will you support? Many Linux distros already provide
comprehensive package management systems, so developers on those would
probably be better off using the native package manager unless you're
offering something distinctive.

Does your distro target a particular developer community, such as web
developers, database developers or desktop developers? These
communities have very different requirements, but then again if you
target web developers do you include Turbo Gears, or Django or both?
Do you include an ORM and if so which one?

If you can clarify what you are trying to achieve, or what
defiiciencies in the existing distros that you're finding limiting
then that would realy help. Super-distros can definitely have a place.
In fact that's exactly what TurboGears is, but it has a very clear
mission statement and adds significant value of it's own. It also acts
as an add-on to the standard distro rather than an alternative and I
recommend you consider that strategy.


Simon Hibbs

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


Re: How can an Exception pass over an except clause ?

2007-05-30 Thread Gary Herron
Nebur wrote:
 I'm using the contract.py library, running Python 2.4.4.

 Now I'm confronted with the following exception backtrace:
  (...)
   File /usr/lib/python2.4/site-packages/contract.py, line 1265, in
 _check_preconditions
 p = f.__assert_pre
 AttributeError: 'function' object has no attribute '__assert_pre'

 For my surprise, I found that the code of contract.py around line 1265
 looks like:

 1264: try:
 1265: p = f.__assert_pre
 1266: except AttributeError:
 1267: pass

 I'd expect line 1267 to swallow the AttributeError siliently. But
 the application stops with the above backtrace.
 Someone familiar enough with the Python innards ? How can one manage
 that an except seems to be ignored ?

  Ruben

   
Under any normal circumstances, that code can't produce that error.  
The attribute error will be swallowed by the except clause. 

However by being *VERY* perverse, I was able to reproduce the above
error by overwriting AttributeError with some other exception class (say
SyntaxError):
AttributeError = SyntaxError
Then your code will be will produce a real AttributeError, but miss it
because (despite the spelling) it checks for a SyntaxError,

Question...  I don't know what contract.py is, but could it be doing
something that *bad*?
You could check py printing AttributeError and see what it really is. 
In my case it's:
 print AttributeError
exceptions.SyntaxError


Gary Herron

P.S.:  Anyone who does this kind of thing is a danger to society.  May
their finger fall off before they get a chance to distribute such a program.


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


Re: How can an Exception pass over an except clause ?

2007-05-30 Thread Tijs
Nebur wrote:

 I'm using the contract.py library, running Python 2.4.4.
 
 Now I'm confronted with the following exception backtrace:
  (...)
   File /usr/lib/python2.4/site-packages/contract.py, line 1265, in
 _check_preconditions
 p = f.__assert_pre
 AttributeError: 'function' object has no attribute '__assert_pre'
 
 For my surprise, I found that the code of contract.py around line 1265
 looks like:
 
 1264: try:
 1265: p = f.__assert_pre
 1266: except AttributeError:
 1267: pass
 
 I'd expect line 1267 to swallow the AttributeError siliently. But
 the application stops with the above backtrace.
 Someone familiar enough with the Python innards ? How can one manage
 that an except seems to be ignored ?
 
  Ruben

The 'raise' in line 1271 re-raises the last error instead of the exception
in whose block it is called. 

This:
try:
raise KeyError
except:
try:
raise IndexError
except: pass
raise

raises IndexError, not KeyError.

-- 

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


Re: Anyone else has seen forrtl: error (200) ...

2007-05-30 Thread Tijs
Alexander Eisenhuth wrote:

 Hello,
 
 Ctrl+C is not passed to the interpreter (i guess it) while I'm executing a
 script. Instead i get:
 forrtl: error (200): program aborting due to control-C event
 

I don't know what forrtl is, but I think it is hijacking your SIGINT signal
handler. Python installs an OS-level signal handler that raises the
KeyboardInterrupt in the main thread. If a library installs its own
handler, Python won't catch it.

-- 

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


Re: google maps api for py?

2007-05-30 Thread Daniel Nogradi
 I see that the weapon of choice for google maps is javascript...  Is
 there anything for python?

I wrote the following for finding the latitude/longitude of a
location. You need to set the variable 'key' to the actual key you got
from google.

(Indentation might get mixed up on the way.)

HTH,
Daniel


###
#   gmaps.py
###

import urllib
from time import sleep

key = here_goes_your_key

def location2latlong( query, key=key ):
Get the ( latitute, longitude ) coordinates corresponding
to the query. If something goes wrong return None.

output = 'csv'

params = { }
params[ 'key' ] = key
params[ 'output' ] = output
params[ 'q' ] = query

params = urllib.urlencode( params )

try:
f = urllib.urlopen( http://maps.google.com/maps/geo?%s; % params )
except IOError:
# maybe some local problem at google? let's try again
sleep( 3 )
try:
f = urllib.urlopen( http://maps.google.com/maps/geo?%s; % params )
except IOError:
# okay we give up
return None

response = f.read( ).split(',')
f.close( )

try:
status = response[0]
accuracy = response[1]
latitude = response[2]
longitude = response[3]
except:
return None

if status != '200':
return None
else:
return latitude, longitude

if __name__ == '__main__':
import sys

try:
q = sys.argv[1]
except:
print 'Usage: python gmaps.py query'
sys.exit( 1 )

r = location2latlong( q )
if r is not None:
print r
else:
print 'Something went wrong.'

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


Re: Creating a distro of python... What would you include in it?

2007-05-30 Thread BJörn Lindqvist
On 30 May 2007 08:25:48 -0700, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 I am creating a distro of Python to be licensed as GPL am
 wondering, what would anyone suggest as to 3rd party modules being put
 into it (non-commercial of course!)? I know I'd put MySQLdb into it at
 the very least. Any suggestions?

If your distro is to be GPL-licensed, does that mean that you want
your components to be GPL too? If so, the number of components you can
select is reduced drastically.

I'd like a distro with a good IDE, GUI toolkit (PyGTK for example),
Django and PyGame. Something you could point a newbie to and they
would be able to create real applications with, without needing to
download hundreds of dependencies.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Listbox - Different Text colors in one listbox

2007-05-30 Thread rahulnag22
On May 30, 6:04 am, [EMAIL PROTECTED] wrote:
 On May 29, 2:02 pm, [EMAIL PROTECTED] wrote:

  Hi,
  Is it possible to havedifferentitems in alistboxindifferentcolors? Or is it 
  justonecolor for all items in alistbox?
  Thanks
  Rahul

 from Tkinter import *

 root = Tk()
 l = Listbox(root)
 l.pack()
 for x in range(10):
 l.insert(END, x)
 l.itemconfig(2, bg='red', fg='white')
 l.itemconfig(4, bg='green', fg='white')
 l.itemconfig(5, bg='cyan', fg='white')
 root.mainloop()

 You can _only_ configurate 'background', 'foreground',
 'selectbackground', 'selectforegroud', not font :(

 HTH

Thanks for the feedback all. I tried the itemconfig method and it
works great.
Thanks

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


Re: writing to a file

2007-05-30 Thread sturlamolden
On May 30, 4:53 pm, sturlamolden [EMAIL PROTECTED] wrote:

 However, numpy has a properly working memory mapped array class,
 numpy.memmap.

It seems that NumPy's memmap uses a buffer from mmap, which makes both
of them defunct for large files. Damn.

mmap must be fixed.






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


Re: Creating a distro of python... What would you include in it?

2007-05-30 Thread Shane Geiger
This is for Windows only, but since your target audience is newbies, 
that might be fine.


Python Sumo-Distribution for Windows - Freely downloadable Python 
distributions for Windows with many extra packages already installed and 
ready for use.

 -- http://code.enthought.com/enthon/




BJörn Lindqvist wrote:

On 30 May 2007 08:25:48 -0700, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
  

I am creating a distro of Python to be licensed as GPL am
wondering, what would anyone suggest as to 3rd party modules being put
into it (non-commercial of course!)? I know I'd put MySQLdb into it at
the very least. Any suggestions?



If your distro is to be GPL-licensed, does that mean that you want
your components to be GPL too? If so, the number of components you can
select is reduced drastically.

I'd like a distro with a good IDE, GUI toolkit (PyGTK for example),
Django and PyGame. Something you could point a newbie to and they
would be able to create real applications with, without needing to
download hundreds of dependencies.

  


--
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
x-mozilla-html:FALSE
url:http://www.ncee.net
version:2.1
end:vcard

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

Re: Is PEP-8 a Code or More of a Guideline?

2007-05-30 Thread Szabolcs Nagy

Joe Riopel wrote:
 Using camel case instead of the under_score means less typing. I am lazy.

 fooBar
 foo_bar

camel case makes source code extremely ugly in weird disturbing way

YMMV

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


Help with ctypes and PAM

2007-05-30 Thread [EMAIL PROTECTED]
Hello,

I've been trying to write a PAM module using ctypes.  In the
conversation
function (my_conv in the script below), you're passed in a
pam_response**
pointer.  You're supposed to allocate an array of pam_response's and
set
the pointer's value to the new array.  Then you fill in the array with
appropriate data.

I can't seem to get it working in python...The authenticate function
always
returns PAM_AUTHTOK_RECOVER_ERR (21), which I think means the response
doesn't
make any sense.

I've tried saving the response array outside of my_conv to make sure
it
doesn't get garbage collected, but that doesn't seem to help.

Any pointers would be appreciated!

Cheers,
Chris

from ctypes import *

libpam = CDLL(libpam.so)

class pam_handle(Structure):
_fields_ = [
(handle, c_void_p)
]

def __init__(self):
self.handle = 0

class pam_message(Structure):
_fields_ = [
(msg_style, c_int),
(msg, c_char_p),
]

def __repr__(self):
return pam_message %i '%s' % (self.msg_style, self.msg)

class pam_response(Structure):
_fields_ = [
(resp, c_char_p),
(resp_retcode, c_int),
]

def __repr__(self):
return pam_response %i '%s' % (self.resp_retcode,
self.resp)

conv_func = CFUNCTYPE(c_int,
c_int, POINTER(POINTER(pam_message)),
POINTER(POINTER(pam_response)), c_void_p)

class pam_conv(Structure):
_fields_ = [
(conv, conv_func),
(appdata_ptr, c_void_p)
]

pam_start = libpam.pam_start
pam_start.restype = c_int
pam_start.argtypes = [c_char_p, c_char_p, POINTER(pam_conv),
POINTER(pam_handle)]

pam_authenticate = libpam.pam_authenticate
pam_authenticate.restype = c_int
pam_authenticate.argtypes = [pam_handle, c_int]

if __name__ == __main__:
import getpass, os, sys
@conv_func
def my_conv(nMessages, messages, pResponse, appData):
# Create an array of nMessages response objects
# Does r get GC'ed after we're all done?
r = (pam_response * nMessages)()
pResponse.contents = cast(r, POINTER(pam_response))
for i in range(nMessages):
if messages[i].contents.msg == Password: :
p = getpass.getpass()
pResponse.contents[0].resp_retcode = 0
pResponse.contents[0].resp = p
return 0

handle = pam_handle()
c = pam_conv(my_conv, 0)
retval = pam_start(login, os.getlogin(), pointer(c),
pointer(handle))

if retval != 0:
print Couldn't start pam session
sys.exit(-1)

retval = pam_authenticate(handle, 0)
if retval == 21:
print Authentication information cannot be recovered
sys.exit(-1)

print retval

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


Re: print bypasses calling write method for objects inheriting from file?

2007-05-30 Thread Gabriel Genellina
En Wed, 30 May 2007 04:24:30 -0300, Peter Otten [EMAIL PROTECTED]  
escribió:

 I created an object that inherits from file and was a bit surprised to
 find that print seems to bypass the write method for objects
 inheriting from file.  An optimization I suppose.  Does this surprise
 anyone else at all or am I missing something?

 No, your analysis is correct, though I'd consider optimization an  
 euphemism
 for bug here. Noone was annoyed enough to write a patch, it seems.

A one-line patch, I guess, PyFile_CheckExact instead of PyFile_Check. Or a  
few lines, checking if the write method is still the builtin one. As this  
is the third time I see this question I'll try to submit the patch.

-- 
Gabriel Genellina

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


Re: Python 2.5 and WXPython demo's

2007-05-30 Thread Andrew P
On May 30, 12:24 pm, Steve Holden [EMAIL PROTECTED] wrote:
 Andrew P wrote:
  Hello,

  I am new (very) to Python and have just down loaded the latest version
  of Python (2.5) and WXPython (2.8).

  For some reason I cannot get the WXPython demo to run at all. I run
  windows XP and it can't find a program to run the demo. Any advice?
  (apologies if this has been posted before).

 The demo is a separate download nowadays. Do you mean you just can't
 find it, or are you running it and does it give you some error message
 that you feel we shouldn't be told about?

 A little more information, please ...

 regards
   Steve
 --
 Steve Holden+1 571 484 6266   +1 800 494 3119
 Holden Web LLC/Ltd  http://www.holdenweb.com
 Skype: holdenweb  http://del.icio.us/steve.holden
 -- Asciimercial -
 Get on the web: Blog, lens and tag your way to fame!!
 holdenweb.blogspot.comsquidoo.com/pythonology
 tagged items: del.icio.us/steve.holden/python
 All these services currently offer free registration!
 -- Thank You for Reading 

Thanks for your reply, this is what I get when I click on the WXPthon
Icon:

Python Traceback Shell Stating:

Error getting traceback - cant import tracebackImportError: No
module named pywin.framework.startup

The Icon is the older python snake icon not the new coloured icon.

Thanks Andrew.

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


  1   2   >