Re: dict is really slow for big truck

2009-04-30 Thread Bruno Desthuilliers

[email protected] a écrit :

Sion Arrowsmith:

The keys aren't integers, though, they're strings.


You are right, sorry. I need to add an int() there.


Which is not garanteed to speed up the code FWIW

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


Re: import and package confusion

2009-04-30 Thread Gabriel Genellina

En Thu, 30 Apr 2009 03:04:40 -0300, alex23  escribió:


On Apr 30, 1:10 pm, Dale Amon  wrote:

I do not really see any other way to do what I want. If
there is a way to get rid of the exec in the sample code
I have used, I would love to know... but I can't see how
to import something where part of the name comes from user
command line input without interpreting the code via exec.


Are you familiar with __import__?

iotypes = ["WINGTL","VLMPC","VLM4997"]
for iotype in iotypes:
  packagename = "VLMLegacy." + iotype + ".Conditions"
  classname   = iotype + "_Conditions"
  module  = __import__(packagename)
  cls = getattr(module, classname)
  # etc


(doesn't work as written, because __import__ returns the top package when  
given a dotted name)

Replace the last three lines with:

__import__(packagename)
module = sys.modules[packagename]
cls = getattr(module, "Conditions")

--
Gabriel Genellina

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


Re: Geohashing

2009-04-30 Thread Marco Mariani

norseman wrote:

The posting needs (its creation) ... DATE. ...  The code needs to state 
OS and program and version used to write it.  And from there - user 
beware."


Which would reduce the confusion greatly.  I got the same error message 
and decided it was from an incompatible version, using incompatible 
modules.  Looks as if I guessed right.  I pity the poor first timer.


Raymond is living in a parallel universe (Fahrenheit 3K) where all the 
previous Python releases have been burned ;)



dystopianl-ly yours,
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict is really slow for big truck

2009-04-30 Thread Bruno Desthuilliers

forrest yang a écrit :

i try to load a big file into a dict, which is about 9,000,000 lines,
something like
1 2 3 4
2 2 3 4
3 4 5 6


How "like" is it ?-)


code
for line in open(file)
   arr=line.strip().split('\t')
   dict[arr[0]]=arr

but, the dict is really slow as i load more data into the memory,


Looks like your system is starting to swap. Use 'top' or any other 
system monitor to check it out.



by
the way the mac i use have 16G memory.
is this cased by the low performace for dict to extend memory


dicts are Python's central data type (objects are based on dicts, all 
non-local namespaces are based on dicts, etc), so you can safely assume 
they are highly optimized.



or
something other reason.


FWIW, a very loose (and partially wrong, cf below)  estimation based on 
wild guesses: assuming an average size of 512 bytes per object (remember 
that Python doesn't have 'primitive' types), the above would use =~ 22G.


Hopefully, CPython does some caching for some values of some immutable 
types (specifically, small ints and strings that respect the grammar for 
Python identifiers), so depending on your real data, you might need a 
bit less RAM. Also, the 512 bytes per object is really more of a wild 
guess than anything else (but given the internal structure of a CPython 
object, I think it's about that order - please someone correct me if I'm 
plain wrong).


Anyway: I'm afraid the problem has more to do with your design than with 
your code or Python's dict implementation itself.



is there any one can provide a better solution


Use a DBMS. They are designed - and highly optimised - for fast lookup 
over huge data sets.


My 2 cents.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Noob - a couple questions involving a web app

2009-04-30 Thread Bruno Desthuilliers

David Smith a écrit :

Kyle T. Jones wrote:


(snip question and answers recommending Django)


Thanks everyone!  Wow, pretty much a consensus - a rarity with these
"types" of questions, at least in my experience.

>>

Ok, sounds like I need to be looking at Django.  Thanks for the advice!

Cheers!


Consensus?! ... that just won't do. :-)

>

I've started with Pylons and have found it very nice.  Loose enough to
tinker with the inner workings but complete and working right out of the
box (or paster in Pylons case).


Pylons is great too. But it requires much more Python knowledge, and 
learning half a dozen dictinct packages. Which is why I wouldn't 
recommand it here.

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


Re: Tools for web applications

2009-04-30 Thread Marco Mariani

Mario wrote:

I used JCreator LE, java IDE for windows because, when I add documentation 
of some new library, I have it on a F1 and index. So how you manage 
documentation and code completion ? I asume that you are geek but not even 
geeks could know every method of every class.



What you call "code completion" cannot work in many cases with dynamic 
languages. Nobody knows which methods are available to an object until 
the program is running.
Dynamic access to attributes/methods that don't explicitly exist in 
Python code, is much more common than you might think.
As an example, your object might be an instance of a class mapped to SQL 
tables that are reflected at runtime. Attributes would represent 
database columns and other things that are never declared in Python code.
Or suppose the object is returned by an XML/HTML/JSON parser from a 
document the program has just downloaded from Argentina. Methods here 
would be the sub-elements or tag attributes for traversing the document.
The instance we're talking of might even be deserialized from ... 
somewhere, without any need to declare type or any interface at all.


I must admit that I've never used completion of anything while 
developing. I routinely it do with the IPython shell, and I would suffer 
if I didn't have it in postgres, but not while editing python.


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


Re: bug with os.rename in 2.4.1?

2009-04-30 Thread Nick Craig-Wood
Steven D'Aprano  wrote:
>  On Tue, 28 Apr 2009 14:30:02 -0500, Nick Craig-Wood wrote:
> 
> > t123  wrote:
> >>  It's running on solaris 9.  Here is some of the code.  It's actually
> >>  at the beginning of the job.  The files are ftp'd over.  The first
> >>  thing that happens is that the files get renamed before any processing
> >>  of the file.  And when it fails, it always fails at the first file,
> >>  comm.dat.  What I can't understand is why the inconsistent behavior.
> >> 
> >>  try:
> >>  if os.path.exists(paths.xferin_dir+'/COMM.DAT'):
> >>os.rename(paths.xferin_dir+'/COMM.DAT',paths.xferin_dir+'/
> > 
> > This code is inherently racy... What if two copies of your code started
> > simultaneously?  They might both run the os.path.exists but only one
> > will succeed in the os.rename.
> > 
> > You could write instead
> > 
> > try:
> > os.rename(paths.xferin_dir+'/COMM.DAT',paths.xferin_dir+'/
>  COMM.DAT'+'.0')
> > except OSError:
> > pass
> > 
> > Which isn't racy.
> 
>  The race condition is still there. The only difference is that in the 
>  first case it fails noisily, with an exception, and in the second it 
>  fails quietly and does nothing.

I'd argue that since os.rename implements the syscall rename() and
that is defined to be atomic (give or take) then the above is atomic
and can't possibly be racy.

Wikipedia's definition :-

  A race condition or race hazard is a flaw in a system or process
  whereby the output and/or result of the process is unexpectedly and
  critically dependent on the sequence or timing of other events. The
  term originates with the idea of two signals racing each other to
  influence the output first.

The original example was clearly racy.

I guess using the wikipedia definition, the fact that I've caught the
exception makes it no longer unexpected and hence no longer racy.

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython menu creation refactoring

2009-04-30 Thread Nick Craig-Wood
alex  wrote:

>  I am still trying to refactor a simple GUI basing on an example in
>  "wxPython In Action", "Listing 5.5 A refactored example" where the
>  menue creation is "automatized".  I understand the problem (each
>  second for loop in "def createMenuData (self)" creates a distinct
>  menu) but I tried now for some evenings and do not get to any
>  possible solution.  I am still learning Python and hope to use it
>  as a front end for my Fortran programs (subprocess and ctypes work
>  very well...)  with the aim of increasing the Python part (text
>  parsing) in the future.  The following code shows the problem and
>  works out of the DOS box.  Any help would be greatly apreciated.
[snip]
> def createMenu(self, itemLabel, itemHandler):
> menu = wx.Menu()
> menuItem = menu.Append(wx.NewId(), itemLabel)
> self.Bind(wx.EVT_MENU, itemHandler, menuItem)
> return menu
> 
>  def createMenuData(self):
>  menuBar = wx.MenuBar()
>  for eachMenuData in self.menuData():
>  menuLabel = eachMenuData[0]
>  for eachLabel, eachHandler in eachMenuData[1:]:
>  menuBar.Append(self.createMenu(eachLabel,
>  eachHandler), menuLabel)
>  self.SetMenuBar(menuBar)

I think you want this instead

def createMenuData(self):
menuBar = wx.MenuBar()
for eachMenuData in self.menuData():
menuLabel = eachMenuData[0]
submenu = wx.Menu()
for eachLabel, eachHandler in eachMenuData[1:]:
item = wx.MenuItem(submenu, -1, eachLabel)
submenu.AppendItem(item)
self.Bind(wx.EVT_MENU, eachHandler, item)
menuBar.Append(submenu, menuLabel)
self.SetMenuBar(menuBar)

That is the way I normally do it anyway!

You create the submenu as a seperate menu then attach it to the
menuBar with the label.

Note there is a wxpython list also which you may get more help in!

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you think of ShowMeDo

2009-04-30 Thread Astley Le Jasper
Gosh ... it's all gone quite busy about logging in, gui etc.
Certainly, I would try to make it clearer what is free and what isn't.
But flash ... using that doesn't bother me. Loggin in ... fine ... I
don't care as long as it's quick and there is something I might want.

i just wanted to know if the content was of a suitable quality that's
worth paying $60 for.

You'll never get anywhere without also having a good collection of
books or online references, but there is something really appealing
about watching someone else walk you through. It get you started. It's
another perspective on the same topic.

I do have a suggestion though. Consider micro-payments. If there is
only one video that I might be interested in, then I think I'd be
happy to pay $1 (or whatever) for. Lower risk. Lower barrier to entry.
I think that the site might be loosing out on a lot of users that may
only want one or a few tutorials. And then once you've used it once,
you're more likely to use it again.

Micropayments could also be the basis of rating the videos. It'll
perhaps give an indication of demand, which could guide further
development and publication of videos.

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


Re: regular expression, unicode

2009-04-30 Thread Simon Strobl
Thanks for your hints. Usually, all my files are utf-8. Obviously, I
somehow managed to inadvertently switch the encoding when creating
this specific file. I have no idea how this could happen.

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


Measure the memory cost in Python

2009-04-30 Thread Li Wang
Hi everyone:

I want to measure the actual memory cost of a particular step in my program
(Python program), does anyone know if there is some function in Python could
help me to do this job? Or should I seek other tools to help me?

Thank you very much!


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


print(f) for files .. and is print % going away?

2009-04-30 Thread Esmail

Hello all,

I use the print method with % for formatting my output to
the console since I am quite familiar with printf from my
C days, and I like it quite well.

I am wondering if there is a way to use print to write
formatted output to files?

Also, it seems like I read that formatting with print is
going away eventually and we should start using something
else? Is that true and if so, what?

Thanks,
Esmail

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


Re: Dictionary, integer compression

2009-04-30 Thread dineshv
Yes, "integer compression" as in Unary, Golomb, and there are a few
other schemes.

It is known that for large (integer) data sets, encoding and decoding
the integers will save space (memory and/or storage) and doesn't
impact performance.

As the Python dictionary is a built-in (and an important data
structure), I wondered if the Python internals used integer
compression for the dictionary (especially as the size of the
dictionary grew)?

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


Please explain this strange Python behaviour

2009-04-30 Thread Train Bwister
Please explain: http://python.pastebin.com/m401cf94d

IMHO this behaviour is anything but the usual straight forward and
obvious way of Python.

Can you please point out the benefits of this behaviour?

All the best,
TrainBwister
--
http://mail.python.org/mailman/listinfo/python-list


Re: print(f) for files .. and is print % going away?

2009-04-30 Thread Duncan Booth
Esmail  wrote:

> Hello all,
> 
> I use the print method with % for formatting my output to
> the console since I am quite familiar with printf from my
> C days, and I like it quite well.
> 
> I am wondering if there is a way to use print to write
> formatted output to files?

Run python interactively and then enter help('print'), you'll get a long 
description of what print does the last paragraph of which I've 
reproduced here (but I've trimmed some of the output from the middle).

>>> help('print')
The ``print`` statement
***

   print_stmt ::= "print" ([expression ("," expression)* [","]]
  | ">>" expression [("," expression)+ [","]])

...
``print`` also has an extended form, defined by the second portion of
the syntax described above. This form is sometimes referred to as
"``print`` chevron." In this form, the first expression after the
``>>`` must evaluate to a "file-like" object, specifically an object
that has a ``write()`` method as described above.  With this extended
form, the subsequent expressions are printed to this file object.  If
the first expression evaluates to ``None``, then ``sys.stdout`` is
used as the file for output.


> Also, it seems like I read that formatting with print is
> going away eventually and we should start using something
> else? Is that true and if so, what?

With python2.6 and later you can use the print function instead (but on 
python 2.x you have to enable it with an import):

>>> from __future__ import print_function
>>> help(print)
Help on built-in function print in module __builtin__:

print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout)

Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current 
sys.stdout.
sep:  string inserted between values, default a space.
end:  string appended after the last value, default a newline.

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


Re: Please explain this strange Python behaviour

2009-04-30 Thread Diez B. Roggisch
Train Bwister wrote:

> Please explain: http://python.pastebin.com/m401cf94d
> 
> IMHO this behaviour is anything but the usual straight forward and
> obvious way of Python.
> 
> Can you please point out the benefits of this behaviour?

http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm

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


unbinding a global variable in Python

2009-04-30 Thread Mark Tarver
In Lisp this is done so

> (setq *g* 0)
0

> *g*
0

> (makunbound '*g*)
*g*

> *g*
error: unbound variable

How is this done in Python?

Mark

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


Re: Dictionary, integer compression

2009-04-30 Thread bearophileHUGS
dineshv:
> Yes, "integer compression" as in Unary, Golomb, and there are a few
> other schemes.

OK. Currently Python doesn't uses Golomb and similar compression
schemes.
But in Python3 all integers are multi-precision ones (I don't know yet
what's bad with the design of Python2.6 integers), and a multi-
precision integer takes a space that is proportional to its number of
bits, so this is a compression scheme (even if not designed for small
integers as you ask for).

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


Re: unbinding a global variable in Python

2009-04-30 Thread Diez B. Roggisch
Mark Tarver wrote:

> In Lisp this is done so
> 
>> (setq *g* 0)
> 0
> 
>> *g*
> 0
> 
>> (makunbound '*g*)
> *g*
> 
>> *g*
> error: unbound variable
> 
> How is this done in Python?
> 
> Mark

>>> foo = "bar"
>>> del foo
>>> foo
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'foo' is not defined
>>> 

Be aware of functions that declare global variables though:


>>> def foo():
... global bar
... bar = 10
...
>>> foo()
>>> bar
10
>>> del bar
>>> bar
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'bar' is not defined
>>> foo()
>>> bar
10


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


Re: unbinding a global variable in Python

2009-04-30 Thread Mark Tarver
On 30 Apr, 12:36, "Diez B. Roggisch"  wrote:
> Mark Tarver wrote:
> > In Lisp this is done so
>
> >> (setq *g* 0)
> > 0
>
> >> *g*
> > 0
>
> >> (makunbound '*g*)
> > *g*
>
> >> *g*
> > error: unbound variable
>
> > How is this done in Python?
>
> > Mark
> >>> foo = "bar"
> >>> del foo
> >>> foo
>
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'foo' is not defined
>
>
>
> Be aware of functions that declare global variables though:
>
> >>> def foo():
>
> ...     global bar
> ...     bar = 10
> ...>>> foo()
> >>> bar
> 10
> >>> del bar
> >>> bar
>
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'bar' is not defined>>> foo()
> >>> bar
>
> 10
>
> Diez- Hide quoted text -
>
> - Show quoted text -

Great; and how can I test to see if a global is bound?

e.g Lisp

> (setq *g* 0)
0

> (boundp '*g*)
t

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


Re: Please explain this strange Python behaviour

2009-04-30 Thread Tim Chase

Train Bwister wrote:

Please explain: http://python.pastebin.com/m401cf94d

IMHO this behaviour is anything but the usual straight forward and
obvious way of Python.

Can you please point out the benefits of this behaviour?


http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions

Note the section marked "Important warning" in bold.  That single 
dict-as-default-argument is evaluated once when the function is 
defined, and shared between function-objects (the things created 
by "def" statements).


The way to do it is:

  def my_method(self, your_param, d=None):
if d is None:
  d = {}
do_stuff(d)

There _are_ cases where it's a useful behavior, but they're rare, 
so I don't advocate getting rid of it.  But it is enough of a 
beginner gotcha that it really should be in the Python FAQ at 
www.python.org/doc/faq/general/


-tkc



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


Re: Dictionary, integer compression

2009-04-30 Thread Diez B. Roggisch
dineshv wrote:

> Yes, "integer compression" as in Unary, Golomb, and there are a few
> other schemes.
> 
> It is known that for large (integer) data sets, encoding and decoding
> the integers will save space (memory and/or storage) and doesn't
> impact performance.
> 
> As the Python dictionary is a built-in (and an important data
> structure), I wondered if the Python internals used integer
> compression for the dictionary (especially as the size of the
> dictionary grew)?

I doubt that, as even integers are python-objects that might be reused. Thus
every integer-entry costs at least sizeof(void*) bytes.

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


Re: Python SocketServer with IPv6

2009-04-30 Thread godshorse
On Apr 30, 1:02 pm, "Martin v. Löwis"  wrote:
> > I am working on a overlay network implementation with python. I need
> > to use both IPv4 and IPv6 at each node. Python socketserver is being
> > used for this task. can anybody pls suggest me how to input an IPv6
> > address to the socketserver.
>
> I'm not quite sure I understand the question, so here is a complete
> example
>
> import SocketServer, socket
>
> class SimpleHandler(SocketServer.BaseRequestHandler):
>     def handle(self):
>         print "Received connection from", self.client_address
>         self.request.send("Hello\r\n")
>
> class V6Server(SocketServer.TCPServer):
>     address_family = socket.AF_INET6
>
> s = V6Server(("::",), SimpleHandler)
> s.serve_forever()
>
> Hope this helps,
> Martin
>
> P.S. I recommend to dual-stack sockets, i.e. to turn off the
> IPV6_V6ONLY socket option, and to bind to both v4 and v6 interfaces.

Thank you very much Martin,

that was the one I exactly wanted to know. I was searching how I can
specify address_family.
Thanks once again.

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


Re: Python servlet for Java applet ?

2009-04-30 Thread Piet van Oostrum
> Linuxguy123  (L) wrote:

>L> On Sat, 2009-04-25 at 02:00 +0200, Piet van Oostrum wrote:
>>> > Linuxguy123  (L) wrote:
>>> 
>>> >L> Hi guys.
>>> >L> Is there a way to use a python application as the back end (ie rpc) for
>>> >L> a Java based applet ?
>>> 
>>> Yes, you can use Corba, XMLRPC, SOAP, JSON-RPC. Corba probably will have
>>> to be tunnelled through port 80 (the others already do this by default
>>> because they are based on HTTP).
>>> 
>>> >L> How does it work compared to a Java servlet with a Java applet ?
>>> 
>>> With a Java applet communicating with a Java servlet you also have the
>>> option of using RMI. For the rest it is similar.

>L> How does one "connect" the servlet to the applet ?  Does anyone know of
>L> an example program that demonstrates a Python servlet with a Java
>L> applet ?

Well, for a start, in the Python world the word 'servlet' isn't used
much. So I assume it comes from your Java legacy and you actually mean
'any server-side python script' (in webware they use the term
'servlet', however).

I have constructed an example for you that uses XMLRPC for the
communication. Use asked for RPC in the original posting, and I think
for applets XMLRPC is one of the easiests, especially since it avoids
the port problems with firewalls that you have with RMI or Corba. But
you didn't give any indication of what kind of application you had in
mind, so maybe RPC isn't necessary and a REST-style communication would
also be possible.

Also I have just used CGI for the 'servlet', as it is the easiest to
install on the server. If this is for a high-volume site then you should
choose something with better performance, such as WSGI, but then you
would have to install  mod_wsgi in Apache. Another possibility would be
to use a Web framework like Zope, Webware or Django.

I have created a simple applet and a python 'servlet' with a RPC that
just returns a string containing the current dat and time on the server,
prefixed by a parameter string. 

AFAIK, Java doesn't have XMLRPC support in its standard library
(javax.xml.rpc is for SOAP) therefore I have used the Apache XMLRPC
implementation from http://apache.org/dist/ws/xmlrpc/. You have to copy
3 jar files to your website together with the applet. Also, because of
the 'same origin' security policy of applets the python 'servlet' must
be on the same machine (same IP address) as the applet.

With SOAP you can do in principle the same but I consider it more
complicated.

You can test the applet at
http://www.pietvanoostrum.com/xmlrpc/xmlrpc.html.
Here is the code:

The Python code:
,[ xmlrpcsrv.py ]
| #! /usr/bin/env python
| 
| '''
| Example XML-RPC server in Python.
| Use as CGI script
| '''
| 
| from SimpleXMLRPCServer import CGIXMLRPCRequestHandler
| from datetime import datetime
| 
| def get_date_time(label):
| '''Get the current date and time on the server as a string
| preceded by label'''
| return label + ": " + str(datetime.now())
| 
| handler = CGIXMLRPCRequestHandler()
| handler.register_function(get_date_time)
| handler.handle_request()
`

HTML page containing the applet:
,[ xmlrpc.html ]
|  
| Hello XML-RPC 
|  XML-RPC Applet Demo  
| 
| The Python server says:
|  
|  
|  
| 
`

The applet code:
,[ XMLRPCApplet.java ]
| package examples; 
| 
| import java.applet.Applet; 
| import java.awt.Graphics; 
| import org.apache.xmlrpc.client.XmlRpcClient;
| import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
| import java.net.URL;
| 
| public class XMLRPCApplet extends Applet { 
| 
| String message = "blank"; 
|   
| public void init() { 
| try { 
| XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
| // This will become something like 
| // "http://www.pietvanoostrum.com/cgi-bin/xmlrpcsrv.py";
| String url = "http://"; +  getCodeBase().getHost() 
|+ "/cgi-bin/xmlrpcsrv.py";
| System.out.println(url);
| config.setServerURL(new URL(url));
| XmlRpcClient xmlrpc = new XmlRpcClient();
| xmlrpc.setConfig(config);
| Object[] params = new Object[]{new String("Current time")};
| message = (String) xmlrpc.execute ("get_date_time", params);
| } catch (Exception e) {
| message = "Exception??";
| System.out.println("HelloApplet exception: " + 
| e.getMessage()); 
| e.printStackTrace(); 
| }
| }
| 
| public void paint(Graphics g) { 
|   g.drawString(message, 25, 50); 
| } 
| }
`

The directory structure on the website is:

xmlrpc/
xmlrpc.html
examples
XMLRPCApplet.class
xmlrpc-client-3.1.2.jar  
xmlrpc-common-3.1.2.jar
ws-commons-util-1.0.2.jar  

cgi-bin/
xmlrpcsrv.py

Hope this helps.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostr

Re: unbinding a global variable in Python

2009-04-30 Thread Duncan Booth
Mark Tarver  wrote:

> Great; and how can I test to see if a global is bound?
> 
> e.g Lisp
> 
>> (setq *g* 0)
> 0
> 
>> (boundp '*g*)
> t

By trying to access it and catching the NameError exception if it isn't 
defined.


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


Re: Please explain this strange Python behaviour

2009-04-30 Thread Tim Chase

Duncan Booth wrote:

Tim Chase  wrote:

There _are_ cases where it's a useful behavior, but they're rare, 
so I don't advocate getting rid of it.  But it is enough of a 
beginner gotcha that it really should be in the Python FAQ at 
www.python.org/doc/faq/general/




That's an excellent idea!

So excellent in fact that it already is:
http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects


Dang...I thought I did a search on that page for "default" and 
must have totally missed it (either for searching on the wrong 
page, misspelling "default", or having my eyes distracted by the 
neighboring FAQ about "goto" which I certainly remember seeing in 
my hunt).  Guess that's what I get for responding before breakfast.


Thanks,

-tkc



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


Re: Please explain this strange Python behaviour

2009-04-30 Thread Duncan Booth
Tim Chase  wrote:

> There _are_ cases where it's a useful behavior, but they're rare, 
> so I don't advocate getting rid of it.  But it is enough of a 
> beginner gotcha that it really should be in the Python FAQ at 
> www.python.org/doc/faq/general/
> 

That's an excellent idea!

So excellent in fact that it already is:
http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects


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


Re: print(f) for files .. and is print % going away?

2009-04-30 Thread Esmail

Matt Nordhoff wrote:

Esmail wrote:

Hello all,

I use the print method with % for formatting my output to
the console since I am quite familiar with printf from my
C days, and I like it quite well.

I am wondering if there is a way to use print to write
formatted output to files?

Also, it seems like I read that formatting with print is
going away eventually and we should start using something
else? Is that true and if so, what?

Thanks,
Esmail




Hi Matt,


String formatting has nothing to do with the print statement/function.
It's an operator, just like doing "foo" + "bar"; you can use it wherever
you want.


Ah .. so this means I could use this formatting with the
write method for files .. that is great news (you don't
want to see the ugly code I put together there .. :-)


See 
Also see  for
information on the replacement for the old string formatting, Python
2.6's new str.format().


Will do .. so do you think it's good to move to the new format,
or will the older one still be around for a while?

Thanks again!

Esmail

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


Re: print(f) for files .. and is print % going away?

2009-04-30 Thread Esmail

Hi Duncan,

Thanks for the information, I'll dig deeper :-)

(for some reason I can't get the from __future__ import
to work,

>>> from __future__ import print_function
  File "", line 1

SyntaxError: future feature print_function is not defined

but I am probably making some silly mistake, plus
I have been meaning to find out more about this too, so
this is a good chance to learn something new).

Thanks again!

Esmail

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


Re: print(f) for files .. and is print % going away?

2009-04-30 Thread Duncan Booth
Esmail  wrote:

> (for some reason I can't get the from __future__ import
> to work,
> 
> >>> from __future__ import print_function
>File "", line 1
> 
> SyntaxError: future feature print_function is not defined
> 
> but I am probably making some silly mistake, plus
> I have been meaning to find out more about this too, so
> this is a good chance to learn something new).
> 
You can only use the print function on 2.6 and later. If you have an older 
version of Python then you'll get that error.


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


Re: print(f) for files .. and is print % going away?

2009-04-30 Thread Matt Nordhoff
Esmail wrote:
> Hello all,
> 
> I use the print method with % for formatting my output to
> the console since I am quite familiar with printf from my
> C days, and I like it quite well.
> 
> I am wondering if there is a way to use print to write
> formatted output to files?
> 
> Also, it seems like I read that formatting with print is
> going away eventually and we should start using something
> else? Is that true and if so, what?
> 
> Thanks,
> Esmail

String formatting has nothing to do with the print statement/function.
It's an operator, just like doing "foo" + "bar"; you can use it wherever
you want.

Look:

>>> "%s" % ('foo',)
'foo'
>>> len("%s" % ('foo',))
3
>>> d = {}
>>> d["%s" % ('foo',)] = 1
>>> d
{'foo': 1}
>>> ("%s" % ('foo',)).upper()
'FOO'
>>>

See 
Also see  for
information on the replacement for the old string formatting, Python
2.6's new str.format().
-- 
--
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing, pool and process crashes

2009-04-30 Thread Jesse Noller
On Wed, Apr 29, 2009 at 10:50 AM,   wrote:
> I want to use the multiprocessing.Pool object to run multiple tasks in
> separate processes.
>
> The problem is that I want to call an external C function (from a
> shared library, with help from ctypes) and this function tends to
> crash (SIGSEGV,SIGFPE,etc.) on certain data sets (the purpose of this
> thing is to test the behavior of the function and see when it
> crashes).
>
> My question is if the Pool object is able to spawn a new process in
> place of the crashed one and resume operation.  I killed with SIGSEGV
> the subprocesses and the script locked up :(
>
> Any ideas/alternatives?
>

You're going to want to use a custom pool, not the built in pool. In
your custom pool, you'll need to capture the signals/errors you want
and handle them accordingly. The built in pool was not designed for
your use case.

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


Re: print(f) for files .. and is print % going away?

2009-04-30 Thread Esmail

Duncan Booth wrote:

Esmail  wrote:


(for some reason I can't get the from __future__ import
to work,


You can only use the print function on 2.6 and later. If you have an older 
version of Python then you'll get that error.


Ooops, yes, you wrote that and I tried with 2.6 under Windows
(my Ubuntu has 2.5) .. I must have typed something wrong when I
tried this with 2.6 because it's working fine now :-)

Thanks again Duncan,

Esmail

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


Re: Multiprocessing Pool and functions with many arguments

2009-04-30 Thread Jesse Noller
On Wed, Apr 29, 2009 at 2:01 PM, [email protected]
 wrote:
> I'm trying to get to grips with the multiprocessing module, having
> only used ParallelPython before.
>
> based on this example:
>
> http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers
>
> what happens if I want my "f" to take more than one argument? I want
> to have a list of tuples of arguments and have these correspond the
> arguments in f, but it keeps complaining that I only have one argument
> (the tuple). Do I have to pass in a tuple and break it up inside f? I
> can't use multiple input lists, as I would with regular map.
>
> Thanks,
>
> Peter

Perhaps these articles will help you:

http://www.doughellmann.com/PyMOTW/multiprocessing/communication.html#pool-map
http://www.doughellmann.com/PyMOTW/multiprocessing/mapreduce.html#simplemapreduce

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


Re: unbinding a global variable in Python

2009-04-30 Thread Hrvoje Niksic
Mark Tarver  writes:

>> (setq *g* 0)
> 0
>
>> (boundp '*g*)
> t

'foo' in globals()
--
http://mail.python.org/mailman/listinfo/python-list


Re: unbinding a global variable in Python

2009-04-30 Thread Peter Otten
Mark Tarver wrote:

> In Lisp this is done so
> 
>> (setq *g* 0)
> 0
> 
>> *g*
> 0
> 
>> (makunbound '*g*)
> *g*
> 
>> *g*
> error: unbound variable
> 
> How is this done in Python?

Often it is a better choice to initialize the global with a sentinel:

g = None

# ...
g = "something meaningful"

# the equivalent of checking whether it's bound:
if g is not None:
   # use g

# the eqivalent of unbinding:
g = None

Peter







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


Re: Python servlet for Java applet ?

2009-04-30 Thread Linuxguy123
On Wed, 2009-04-29 at 15:37 +0200, Marco Bizzarri wrote:
> On Wed, Apr 29, 2009 at 3:14 PM, Linuxguy123  wrote:
> >
> > How does one "connect" the servlet to the applet ?  Does anyone know of
> > an example program that demonstrates a Python servlet with a Java
> > applet ?
> >
> > Thanks !
> >
> 
> 
> Ok, let's make some basic questions:
> 
> 1) do you know how to program an applet in order to invoke an URL on a server?

I know how to invoke a URL with an application.  I assume its the same
doing it with an applet.

> 2) do you know how to program a server in order to answer to HTTP requests?

I've got a good idea how to do that.

I thought that applets weren't allowed to access URLs directly.  If they
can, this problem becomes trivial. 

Thanks for the reply.


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


Saturday May 2 - Python @ Global FSW Conference via VOIP - BerkeleyTIP - 21 Videos - For forwarding

2009-04-30 Thread john_re
Python 2.6 & 3.0 Compatibility, from PyCon 2009

==
Join with the friendly productive Global FreeSW HW & Culture community,
in the TWICE monthly, Voice over internet Global Conference:

  BerkeleyTIP-Global:   GNU(Linux), BSD, & All Free SW, HW, & Culture

  TIP = Talks, Installfest, Project/Programming Party
  Educational, Productive, Social.
http://sites.google.com/site/berkeleytip/


=  TWO meetings each month:
 1st Saturday - May 2
 3rd Sunday   - May 17
 10AM-6PM Pacific (GMT -8H) time,
   =  1P - 9P Eastern
   =  6PM - 2AM (Saturday to Sunday) GMT
   Join in as short or long as you like.
http://sites.google.com/site/berkeleytip/schedule


=  Join the Global BerkeleyTIP mailing list
http://groups.google.com/group/BerkTIPGlobal
Say "Hi" & your interests & where you're from.


=  LOCATION - ONLINE, IN YOUR AREA, OR AT U. California Berkeley
  Voice over Internet (VOIP) info:
http://sites.google.com/site/berkeleytip/remote-attendance
http://sites.google.com/site/berkeleytip/directions

Local meetings outside Berkeley - Alpha test:
Someone might try to connect from UCLA, SanJose State or SanFran State.
You are invited to join the tests by attending there.
For details, read the BT-Global mailing list.


===
=  NEW VIDEOS for 2009 May: Saturday 2nd , & Sunday 17th
21 Videos/Talks this month. ~5 are short - 1-10 minutes.

Ubuntu 9.04 Just out - Jaunty Jackalope, Mark Shuttleworth
Overview of Ext4, Theodore Tso
Python 2.6 & 3.0 Compatibility, from PyCon 2009
The Linux Framebuffer, Heather Stern
Free Culture: One Laptop Per Child, NPR/PRI
Free Culture: Akamai, For streaming TED video over the internet
Development on the OpenMoko with hackable, Pierre Pronchery
State of the X window, Keith Packard & Barton Massey
Diversity in KDE, Till Adam and Adriaan deGroot
Voice over Internet Protocol (VOIP) using Asterisk, Sameer Verma

== The 2009 Linux Foundation Collaborative Summit:
Tux's Superpowers - If Tux were a superhero, what powers would he have?
When did you hear about Linux for the First Time?
Linux Foundation "We're Linux" Contest winners

== BSD CON DC 2009:
Faster Packets: Performance tuning in OpenBSD networks  Henning Brauer
Network Perimeter Redundancy with pfsense, Chris Buechler
Network Security Monitoring Using FreeBSD, Richard Bejtlich
Process Isolation for NetBSD and OpenBSD, Kristaps Dzonsons
OpenBSD vs SMP, Threading, and Concurrency, Ted Unangst
Isolating Cluster Jobs for Performance and Predictability, Brooks Davis

== Debconf 2008
Healthy CDDs Strategies for building a Custom Deb Distro, Andreas Tille
Packaging with version control systems, martin f. krafft


Thanks to all the speakers, videographers, & organizations.   :)
Please excuse if I mistyped names.  <8-0
I hereby invite the speakers to attend BTIP for Q&A & discussion.
Please notify the speakers if you know how to contact them, thanks.  :)

Download the videos & watch them before or during the meeting.
Join online during the relevant topic hour to discuss each video.
See longer talk descriptions, & download URLs, here:
http://sites.google.com/site/berkeleytip/talk-videos
===


=  YOU GIVE A 5 MINUTE LIGHTNING TALK
4 PM.  Let us know in advance what you'd like to talk about.  :)


= SCHEDULE / AGENDA 10AM - 6PM Pacific time (= GMT - 8 Hours)
TIMETOPIC / ACTIVITY
 10 A   Set up.  Get on IRC & VOIP
 11 A   INSTALLFEST begins;
PROJECT/PROGRAMMING PARTY begins:
  Group ProgP: VOIP Conference client/server - Ekiga & Asterisk
 12 N   OLPC; Games; Education; Database; Business
 1 PSys/Net Admin; GUI: KDE & GNOME
 2 PFree Culture - Wikipedia, CreativeCommons, etc.; Law; GNU
 3 PDistros: Debian, Ubuntu, BSD, etc.; Science & Engineering;
Programming Languages
 4 PLIGHTNING TALKS; Hardware- Ex: OpenMoko Phone;
Bio/Medicine/Health
 5 PArt/Literature/Music/Humanities;
Internet/Website; Local meetings arrangements


= Voice/VOIP CONFERENCE MEETING TECHNOLOGY
Join in on IRC, & we'll help you get on VOIP.   :) 

IRC: #BerkeleyTIP, irc.freenode.net
Hardware: VOIP Headset- (USB recommended for echo cancellation?)
Software: Ekiga(GnomeMeeting) recommended. SIP
VOIP server: Ekiga.net
http://sites.google.com/site/berkeleytip/remote-attendance


=  PROJECT / PROGRAMMING PARTY
Work on your own project, or the group project.
Share details of your project on IRC, VOIP & the mailing list.  Invite
others to join in your project.
Or, work on the group project - Learning about & Improving Ekiga,
Asterisk, & our VOIP conference system/technology.


=  THANKS, HOPE YOU JOIN;  FOR FORWARDING
Mark you calendar: May 2 Saturday, May 19 Sunday

I hope you join in the meeting.   :)

Join by yourself, or invite  your friends over & have a party.  Have a
party at your home, or at a local to you location - a WiFi cafe, or at a
college or univer

ANN: python-ldap-2.3.8

2009-04-30 Thread Michael Ströder
Find a new release of python-ldap:

  http://www.python-ldap.org/

python-ldap provides an object-oriented API to access LDAP directory
servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for
that purpose. Additionally it contains modules for other LDAP-related
stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema).

Ciao, Michael.

-- 
Michael Ströder
E-Mail: [email protected]
http://www.stroeder.com


Released 2.3.8 2009-04-30

Changes since 2.3.7:

Lib/
* ldap.schema.models: More fault-tolerant parsing of SYNTAX in
  AttributeTypeDescription
* ldap.schema.tokenizer.split_tokens():
  More tolerant parsing of items separated only with a DOLLAR without
  surrounding white-spaces (because WSP is declared as zero or more
  spaces in RFC 4512)
--
http://mail.python.org/mailman/listinfo/python-list


Replacing files in a zip archive

2009-04-30 Thread Дамјан Георгиевски
I'm writing a script that should modify ODF files. ODF files are just 
.zip archives with some .xml files, images etc. 

So far I open the zip file and play with the xml with lxml.etree, but I 
can't replace the files in it.

Is there some recipe that does this ?




-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

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


Re: Dictionary, integer compression

2009-04-30 Thread dineshv
Hi bearophile

Thanks for that about Python3.  My integers range from 0 to 9,999,999
and I have loads of them.  Do you think Python3 will help?

I want to do testing on my local machine with the large numbers of
integers and was wondering if I can get away with an existing Python
data structure or will I have to code a compression scheme.

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


Re: Using ascii numbers in regular expression

2009-04-30 Thread Lie Ryan

MRAB wrote:

You're almost there:

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

or better yet:

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


Wouldn't that becomes a literal \x61 instead of "a" as it is inside raw 
string?

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


Re: sorted() erraticly fails to sort string numbers

2009-04-30 Thread Lie Ryan

John Posner wrote:

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

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


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

 is equivalent to:

   container.sort(key=getkey)



Equivalent, and in fact better since the sorting is done in-place 
instead of creating a new list, then overwriting the old one.

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


Re: Please explain this strange Python behaviour

2009-04-30 Thread John Posner

Duncan Booth wrote:

Tim Chase  wrote:
  
There _are_ cases where it's a useful behavior, but they're rare, 
so I don't advocate getting rid of it.  But it is enough of a 
beginner gotcha that it really should be in the Python FAQ at 
www.python.org/doc/faq/general/

That's an excellent idea!

So excellent in fact that it already is:
http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects
  


A couple of minor quibbles:

* This writeup, and the virtually identical one at effbot.org that Diez 
referenced, address the *what* of default arguments, but don't really 
address the *why*, beyond the statement that "Default values are created 
exactly once, when the function is defined (by executing the *def* 
 statement)". After all, if parameter 
values are supplied to a function when it is called, a newly minted set 
of default values could be supplied at that time, also. So *why* was 
Python designed one way instead of the other?


* I'd change this sentence near the beginning of the writeup, because 
it's just ambiguous enough in the exact area that the writeup is 
attempting to clarify:


from:

 The first time you call this function, D contains a single item.
 The second time, D contains two items ...

to:

 After the first call to this function, D contains a single item.
 After the second call, D contains two items ...

-John

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


Re: Python servlet for Java applet ?

2009-04-30 Thread Piet van Oostrum
> Linuxguy123  (L) wrote:

>L> I thought that applets weren't allowed to access URLs directly.  If they
>L> can, this problem becomes trivial. 

They are allowed if the URL is on the same IP address as where the
applet came from (same origin policy). But in your original post you
wanted RPC.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]

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


Re: import and package confusion

2009-04-30 Thread Dale Amon
On Thu, Apr 30, 2009 at 08:32:31AM +0200, Jeroen Ruigrok van der Werven wrote:
-On [20090430 02:21], Dale Amon ([email protected]) wrote:
>>import sys
>>sys.path.extend (['../lib', '../bin'])
>>
>>from VLMLegacy.CardReader import CardReader
>>rdr = CardReader ("../example/B767.dat","PRINTABLE")
>>
>>iotypes = ["WINGTL","VLMPC","VLM4997"]
>>for iotype in iotypes:
>>packagename = "VLMLegacy." + iotype + ".Conditions"
>>classname   =  iotype + "_Conditions"
>>code= "from %s import Conditions as %s" \
>>   % (packagename, classname)
>>x   = compile (code,"foo","exec")
>>exec x
>>cls = globals()[classname]
>>a = cls(rdr,2)
>>a.test()
>
> Right now your code boils down to:
> 
> from VLMLegacy.VLM4997.Conditions import Conditions as VLM4997_Conditions
> from VLMLegacy.VLMPC.Conditions import Conditions as VLMPC_Conditions
> from VLMLegacy.WINGTL.Conditions import Conditions as WINGTL_Conditions
> 
> And while you are, of course, allowed to do so, it's not the way you would
> want to approach it in Python.
> 
> For each subpackage/module you could add an import and __all__ to
> __init__.py to expose Conditions and then shorten it all to:
> 
> import VLMLegacy.VLM4997 as VLM4997
> import VLMLegacy.VLMPC as VLMPC
> import VLMLegacy.WINGTL as WINGTL
> 
> So that you can do:
> 
> a = VLM4997.Conditions(rdr, 2)
> a.test()

If my proof of concept test code were actually all there was
you would be correct. But what I wish to accomplish is that
a string supplied from the command line does a run time load
of code that is not even explicitely mentioned in the main
body of the system.

myprogram --type NEWTYPE old.dat

Where NEWTYPE did not exist when the above code was written and
distributed. Think of the following scenario. 

* Customer tells me, we have old data decks which are not
  quite in any of the supported formats.

* I supply a new subpackage NEWTYPE with the varient code.

* They copy it into the package directory, VLMLegacy/NEWTYPE.

* They type the name of that package as a command line arg as
  above.

* The code I wrote takes their string and dynamically binds
  and uses the new code without changing anything else in
  the code base.

Now I agree it is hackish. I don't really want to eval,
I just want to import a module whose name is contained
in a variable. I'm not unhappy with the second part where
I use globals()[thestring] to get from a string to a 
class object; I am indeed bothered that I have to eval
to do the import as I have been unable so far to find
a way to make it work dynamically. I'd be perfectly happy
if something like this worked:

from VLMLegacy.CardReader import *
opts, args  = p.parse_args()
iotype  = opts.type
targetname  = "Deck"
packagename = "VLMLegacy." + iotype + "." targetname
classname   =  iotype + "_" + targetname

# I only wish something like this worked...
from packagename import targetname as classname

cls = globals()[classname]

file = args[0]
rdr  = CardReader(file,opts.punchtype)
a = cls(rdr,2)
a.read()



but it doesn't. Oh, and it gets worse later. The data I'm
reading is potentially straight off ancient Fortran decks
with no spaces between numbers. ;-)


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: import and package confusion

2009-04-30 Thread Dale Amon
On Thu, Apr 30, 2009 at 02:38:03AM -0400, Dave Angel wrote:
> As Scott David Daniels says, you have two built-in choices, depending on  
> Python version.  If you can use __import__(), then realize that
> mod = __import__("WINGTL")
>
> will do an import, using a string as the import name.  I don' t have the  
> experience to know how it deals with packages, but I believe I've heard  
> it does it the same as well.

> One more possibility, if you're only trying to get a single package  
> hierarchy at a time, it might be possible to arrange them in such a way  
> that the sys.path search order gets you the package you want.  Rather  
> than the top level being a package, it'd be an ordinary directory, and  
> you'd add it to the sys.path variable so that when you import a  
> subpackage (which would now really just be a package), you'd get the  
> right one.

That would be too unpredictable. But I find the first option
very interesting. I was looking at the __import__  in the Python 
book and thought it *might* be able to do it, but I was not sure 
if it was a solution or an enticing event horizon.

I'm using 2.5 btw.





signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: print(f) for files .. and is print % going away?

2009-04-30 Thread pruebauno
On Apr 30, 8:30 am, Esmail  wrote:
> Matt Nordhoff wrote:
> > Esmail wrote:
> >> Hello all,
>
> >> I use the print method with % for formatting my output to
> >> the console since I am quite familiar with printf from my
> >> C days, and I like it quite well.
>
> >> I am wondering if there is a way to use print to write
> >> formatted output to files?
>
> >> Also, it seems like I read that formatting with print is
> >> going away eventually and we should start using something
> >> else? Is that true and if so, what?
>
> >> Thanks,
> >> Esmail
>
> Hi Matt,
>
> > String formatting has nothing to do with the print statement/function.
> > It's an operator, just like doing "foo" + "bar"; you can use it wherever
> > you want.
>
> Ah .. so this means I could use this formatting with the
> write method for files .. that is great news (you don't
> want to see the ugly code I put together there .. :-)
>
> > See 
> > Also see  for
> > information on the replacement for the old string formatting, Python
> > 2.6's new str.format().
>
> Will do .. so do you think it's good to move to the new format,
> or will the older one still be around for a while?
>
> Thanks again!
>
> Esmail

There is also the Template class in the stdlib string module, for unix
shell/perl style "formatting".

The old mod (%) formatting will be around in 3.1 and that version not
even out yet, so it will be around for a couple more years at the very
least. Although the new format is more powerful and slightly less
error prone, there is so much old code using % that there is
resistance to drop it. The printf format is also well known among C
programmers. One thing many Python programmers don't like is that it
is a single character operator (%). It makes formatting hard to spot.
Maybe printf formatting will be moved to some module in the stdlib in
the future as a compromise.

I hope that the information will help you decide what to use.
--
http://mail.python.org/mailman/listinfo/python-list


don't understand namespaces...

2009-04-30 Thread Lawrence Hanser
Dear Pythoners,

I think I do not yet have a good understanding of namespaces.  Here is
what I have in broad outline form:


import Tkinter

Class App(Frame)
  define two frames, buttons in one and Listbox in the other

Class App2(Frame)
  define one frame with a Text widget in it

root = Tk()
app = App(root)
win2 = Toplevel(root)
app2 = App2(win2)
root.mainloop()


My understanding of the above goes like this:
1) create a root window
2) instantiate a class that defines a Frame in the root window
3) create another Toplevel window
4) instantiate another class that defines a frame in the Toplevel window (win2)

What I cannot figure out is how to reference a widget in app2 from app...

I hope this is sort of clear.

Any assistance appreciated.

Thanks,

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


Re: Using ascii numbers in regular expression

2009-04-30 Thread MRAB

Lie Ryan wrote:

MRAB wrote:

You're almost there:

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

or better yet:

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


Wouldn't that becomes a literal \x61 instead of "a" as it is inside raw 
string?



Yes. The re module will understand the \x sequence within a regular
expression.

The reason I say that the second solution is better is because you say:

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

Certain characters have a special meaning in regular expressions, eg
'*', so if you tried to search for '*' (or '\x2A') you would get an
exception. The solution would be to search for r'\*' or r'\x2A'.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Replacing files in a zip archive

2009-04-30 Thread MRAB

Дамјан Георгиевски wrote:
I'm writing a script that should modify ODF files. ODF files are just 
.zip archives with some .xml files, images etc. 

So far I open the zip file and play with the xml with lxml.etree, but I 
can't replace the files in it.


Is there some recipe that does this ?


You'll have to create a new zip file and copy the files into that.
--
http://mail.python.org/mailman/listinfo/python-list


Re: import and package confusion

2009-04-30 Thread Dale Amon
On Thu, Apr 30, 2009 at 04:33:57AM -0300, Gabriel Genellina wrote:
> En Thu, 30 Apr 2009 03:04:40 -0300, alex23  escribió:
>> Are you familiar with __import__?
>>
>> iotypes = ["WINGTL","VLMPC","VLM4997"]
>> for iotype in iotypes:
>>   packagename = "VLMLegacy." + iotype + ".Conditions"
>>   classname   = iotype + "_Conditions"
>>   module  = __import__(packagename)
>>   cls = getattr(module, classname)
>>   # etc
>
> (doesn't work as written, because __import__ returns the top package when 
> given a dotted name)
> Replace the last three lines with:
>
> __import__(packagename)
> module = sys.modules[packagename]
> cls = getattr(module, "Conditions")

Thanks. That works marvelously. I just knew there
had to be a better way.




signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Please explain this strange Python behaviour

2009-04-30 Thread Stephen Hansen
>
>
> * This writeup, and the virtually identical one at effbot.org that Diez
> referenced, address the *what* of default arguments, but don't really
> address the *why*, beyond the statement that "Default values are created
> exactly once, when the function is defined (by executing the *def* <
> http://effbot.org/pyref/def.htm> statement)". After all, if parameter
> values are supplied to a function when it is called, a newly minted set of
> default values could be supplied at that time, also. So *why* was Python
> designed one way instead of the other?
>

I have a feeling this might start one of those uber-massive "pass by value /
reference / name / object / AIEE" threads where everyone goes around in
massive circles explaining how Python uses one or another parameter passing
paradigm and why everyone else is wrong... but... :)

The thing is, parameter values are NOT supplied to a function when it is
called.

When you call a function, there's no creation or copying of any values of
any kind. The objects you pass in are passed in and the function receives
those exact same objects. Within the function a local name is made which
binds to an existing object that is specified when it is called-- or if a
default is provided, that. In all cases these objects already exist before
the call happens.

Despite the fact that using mutable objects as default arguments is a
frequent source of quirked-eyebrows and head-scratching for those new to
Python, to do anything else would be weirdly magical. You'd basically have
to go and call copy() on any default arguments specified in the function; at
which point why are you copying those and not the other arguments? It just
doesn't make sense with how Python handles name
binding consistently throughout the entire language. In this corner case
that just seems weird at first to people.

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


Re: import and package confusion

2009-04-30 Thread MRAB

Dale Amon wrote:

On Thu, Apr 30, 2009 at 08:32:31AM +0200, Jeroen Ruigrok van der Werven wrote:
-On [20090430 02:21], Dale Amon ([email protected]) wrote:

import sys
sys.path.extend (['../lib', '../bin'])


>from VLMLegacy.CardReader import CardReader

rdr = CardReader ("../example/B767.dat","PRINTABLE")

iotypes = ["WINGTL","VLMPC","VLM4997"]
for iotype in iotypes:
   packagename = "VLMLegacy." + iotype + ".Conditions"
   classname   =  iotype + "_Conditions"
   code= "from %s import Conditions as %s" \
  % (packagename, classname)
   x   = compile (code,"foo","exec")
   exec x
   cls = globals()[classname]
   a = cls(rdr,2)
   a.test()

Right now your code boils down to:

from VLMLegacy.VLM4997.Conditions import Conditions as VLM4997_Conditions
from VLMLegacy.VLMPC.Conditions import Conditions as VLMPC_Conditions
from VLMLegacy.WINGTL.Conditions import Conditions as WINGTL_Conditions

And while you are, of course, allowed to do so, it's not the way you would
want to approach it in Python.

For each subpackage/module you could add an import and __all__ to
__init__.py to expose Conditions and then shorten it all to:

import VLMLegacy.VLM4997 as VLM4997
import VLMLegacy.VLMPC as VLMPC
import VLMLegacy.WINGTL as WINGTL

So that you can do:

a = VLM4997.Conditions(rdr, 2)
a.test()


If my proof of concept test code were actually all there was
you would be correct. But what I wish to accomplish is that
a string supplied from the command line does a run time load
of code that is not even explicitely mentioned in the main
body of the system.

myprogram --type NEWTYPE old.dat

Where NEWTYPE did not exist when the above code was written and
distributed. Think of the following scenario. 


* Customer tells me, we have old data decks which are not
  quite in any of the supported formats.

* I supply a new subpackage NEWTYPE with the varient code.

* They copy it into the package directory, VLMLegacy/NEWTYPE.

* They type the name of that package as a command line arg as
  above.

* The code I wrote takes their string and dynamically binds
  and uses the new code without changing anything else in
  the code base.

Now I agree it is hackish. I don't really want to eval,
I just want to import a module whose name is contained
in a variable. I'm not unhappy with the second part where
I use globals()[thestring] to get from a string to a 
class object; I am indeed bothered that I have to eval

to do the import as I have been unable so far to find
a way to make it work dynamically. I'd be perfectly happy
if something like this worked:

from VLMLegacy.CardReader import *
opts, args  = p.parse_args()
iotype  = opts.type
targetname  = "Deck"
packagename = "VLMLegacy." + iotype + "." targetname
classname   =  iotype + "_" + targetname

# I only wish something like this worked...
from packagename import targetname as classname

Try:

cls = getattr(__import__(packagename), targetname)



cls = globals()[classname]

file = args[0]
rdr  = CardReader(file,opts.punchtype)
a = cls(rdr,2)
a.read()



but it doesn't. Oh, and it gets worse later. The data I'm
reading is potentially straight off ancient Fortran decks
with no spaces between numbers. ;-)


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


Re: import and package confusion

2009-04-30 Thread Dale Amon
Gabriel gave me the key to a fine solution, so
just to put a bow tie on this thread:

#!/usr/bin/python

import sys
sys.path.extend (['../lib', '../bin'])

from VLMLegacy.CardReader import CardReader
rdr = CardReader ("../example/B767.dat","PRINTABLE")

iotypes = ["WINGTL","VLMPC","VLM4997"]
for iotype in iotypes:
classname  = "Conditions"
__import__("VLMLegacy." + iotype + "." + classname)
module = sys.modules[packagename]
cls = getattr(module, classname)
a = cls(rdr,2)
a.test()

Works like a champ!

It would have taken days for me to find that by trial and
error and rtfm and google. So thank you all. Even if at times
I was rather unclear about what I was trying to accomplish.

Now I can move on to parsing those pesky Fortran card
images... There wouldn't happen to be a way to take n
continguous slices from a string (card image) where each 
slice may be a different length would there? Fortran you 
know. No spaces between input fields. :-)

I know a way to do it, iterating over a list of slice sizes,
perhaps in a list comprehension, but some of the august python 
personages here no doubt know better ways.


signature.asc
Description: Digital signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: don't understand namespaces...

2009-04-30 Thread Mike Driscoll
On Apr 30, 9:11 am, Lawrence Hanser  wrote:
> Dear Pythoners,
>
> I think I do not yet have a good understanding of namespaces.  Here is
> what I have in broad outline form:
>
> 
> import Tkinter
>
> Class App(Frame)
>       define two frames, buttons in one and Listbox in the other
>
> Class App2(Frame)
>       define one frame with a Text widget in it
>
> root = Tk()
> app = App(root)
> win2 = Toplevel(root)
> app2 = App2(win2)
> root.mainloop()
> 
>
> My understanding of the above goes like this:
> 1) create a root window
> 2) instantiate a class that defines a Frame in the root window
> 3) create another Toplevel window
> 4) instantiate another class that defines a frame in the Toplevel window 
> (win2)
>
> What I cannot figure out is how to reference a widget in app2 from app...
>
> I hope this is sort of clear.
>
> Any assistance appreciated.
>
> Thanks,
>
> Larry

It depends on how you're doing this. If the first frame opens the 2nd
frame, then you can have a handle to the 2nd in the 1st. Something
like this:

self.newFrame = NewFrame()

Then you can get at the attributes of the 2nd frame:

self.newFrame.SomeWidget.GetSomeValue()

If you're opening both at the same time, you'll have to come up with
something else, like Queues or pubsub.

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


Re: Installing Python 2.5.4 from Source under Windows

2009-04-30 Thread Jim Carlock
"Paul Franz" wrote...
: I have looked and looked and looked. But I can not find directions
: on installing the version of Python built using Microsoft's 
: compiler. It builds. I get the dlls and the exe's. But there is no 
: documentation that says how to install what has been built. I have
: read every readme and stop by the IRC channel and there seems to
: be nothing.
: 
: Any ideas where I can look?

Hi Paul,

Try the following. Create a file called python.reg. Then open it
with an editor and add the following lines to it. The lines should
get a CRLF termination, but LF works just fine as well.

You'll need to edit the paths to the files to point to the proper
location of your python executables/dlls.


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.py]
@="Python.File"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\.pyc]
@="Python.CompiledFile"

[HKEY_CLASSES_ROOT\.pyo]
@="Python.CompiledFile"

[HKEY_CLASSES_ROOT\.pyw]
@="Python.NoConFile"
"Content Type"="text/plain"

[HKEY_CLASSES_ROOT\Python.CompiledFile]
@="Compiled Python File"

[HKEY_CLASSES_ROOT\Python.CompiledFile\DefaultIcon]
@="C:\\Python\\DLLs\\pyc.ico"

[HKEY_CLASSES_ROOT\Python.CompiledFile\shell]

[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open]

[HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command]
@="\"C:\\Python\\python.exe\" \"%1\" %*"

[HKEY_CLASSES_ROOT\Python.CompiledFile\shellex]

[HKEY_CLASSES_ROOT\Python.CompiledFile\shellex\DropHandler]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"

[HKEY_CLASSES_ROOT\Python.File]
@="Python File"

[HKEY_CLASSES_ROOT\Python.File\DefaultIcon]
@="C:\\Python\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.File\shell]

[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE]

[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command]
@="\"C:\\Python\\pythonw.exe\" \"C:\\Python\\Lib\\idlelib\\idle.pyw\" -n -e 
\"%1\""

[HKEY_CLASSES_ROOT\Python.File\shell\open]

[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Python\\python.exe\" \"%1\" %*"

[HKEY_CLASSES_ROOT\Python.File\shellex]

[HKEY_CLASSES_ROOT\Python.File\shellex\DropHandler]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"

[HKEY_CLASSES_ROOT\Python.NoConFile]
@="Python File (no console)"

[HKEY_CLASSES_ROOT\Python.NoConFile\DefaultIcon]
@="C:\\Python\\DLLs\\py.ico"

[HKEY_CLASSES_ROOT\Python.NoConFile\shell]

[HKEY_CLASSES_ROOT\Python.NoConFile\shell\Edit with IDLE]

[HKEY_CLASSES_ROOT\Python.NoConFile\shell\Edit with IDLE\command]
@="\"C:\\Python\\pythonw.exe\" \"C:\\Python\\Lib\\idlelib\\idle.pyw\" -n -e 
\"%1\""

[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open]

[HKEY_CLASSES_ROOT\Python.NoConFile\shell\open\command]
@="\"C:\\Python\\pythonw.exe\" \"%1\" %*"

[HKEY_CLASSES_ROOT\Python.NoConFile\shellex]

[HKEY_CLASSES_ROOT\Python.NoConFile\shellex\DropHandler]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"

[HKEY_CLASSES_ROOT\CLSID\{60254CA5-953B-11CF-8C96-00AA00B8708C}]
@="Shell Extension For Windows Script Host"

[HKEY_CLASSES_ROOT\CLSID\{60254CA5-953B-11CF-8C96-00AA00B8708C}\InProcServer32]
@="C:\\WINDOWS\\system32\\wshext.dll"
"ThreadingModel"="Apartment"




NOTE: Make sure there are a couple blank lines at the end of the
file. No need to mess with setting the PATH EV anywhere. The above
registry script registers everything to execute Python as needed.
Double-click upon a test.py file and you'll see the test.pyc file
get created and then you'll see the file run as needed.

If you're curious about to see if those extensions are already set
you can use a cmd.exe prompt to do so with the assoc.exe and the
ftype.exe commands. Not sure if those get installed by default for
Windows though. They might need to get downloaded from Microsoft
in some sort of resource kit. They work with Windows 2000, XP and
possibly earlier versions of Windows.

Let me know if this helps and works for you? Thanks.

-- 
Jim Carlock
http://www.microcosmotalk.com/contact/


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


decode command line parameters - recomendend way

2009-04-30 Thread Jax
Hello

I want add full Unicode support in my scripts. Now I have encoutered theoretical
problem with command line parameters. I can't find anything in that mater. But
I develop solution which seems to work. Question is: Is it recommendend way to
decode command line parameters:

lFileConfig = None
if len(sys.argv) > 1:
   lFileConfig = unicode(sys.argv[1], locale.getpreferredencoding())

Or maybe there is other solution?

Jax

ps:
$ python --version
Python 2.5.2

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


Re: ctypes

2009-04-30 Thread Stefan Behnel
luca72 wrote:
> [3x the same thing]

You should learn to calm down and wait for an answer. Even if the problem
is urgent for you, it may not be to everyone, and spamming a newsgroup will
not help to get people in a friendly mood to write a helpful reply.

This is always worth a read:
http://www.catb.org/~esr/faqs/smart-questions.html

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


Re: Python 2.6 Install on OSX Server 10.5: lWhich flag to use in "configure" to Change the Install location?

2009-04-30 Thread Piet van Oostrum
> Omita  (O) wrote:

>O> Long story short... I am installing Python 2.6 on OSX Server.  By
>O> default the Python.framework is installing in /Library:

>O> /Library/Frameworks/Python.framework

>O> However, as I am using OSX Server I would ideally like the install
>O> location to be here:

>O> /System/Library/Frameworks/Python.framework/

That's a good recipe to ruin your system software.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: sorted() erraticly fails to sort string numbers

2009-04-30 Thread Paddy O'Loughlin
2009/4/30 Lie Ryan 

>   container[:] = sorted(container, key=getkey)
>>
>>  is equivalent to:
>>
>>   container.sort(key=getkey)
>>
>>
> Equivalent, and in fact better since the sorting is done in-place instead
> of creating a new list, then overwriting the old one.


Not when, as pointed out by uuid, container is not list-like (at least as
far as the sort() method goes).
:)

Paddy

-- 
"Ray, when someone asks you if you're a god, you say YES!"
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you think of ShowMeDo

2009-04-30 Thread Peter Pearson
On Wed, 29 Apr 2009 20:13:32 -0400, David Robinow  wrote:
> On Wed, Apr 29, 2009 at 9:29 AM,   wrote:
> ...
>> To reiterate, I responded to this thread because I think Ben's posting
>> gave an unfair impression of the site and i felt the need to address
>> some misconceptions. I am sorry you failed to find the videos, but
>> many tens of thousands are found every week and I really haven't heard
>> of anyone failing to find their way to the content. In this sense I
>> think you are exceptional.

> Count me as one who couldn't find his way.
[snip]

Me too.  Of course, showmedo was just one of several promising
leads, so rather than lingering to figure it out, I just moved
on to the next promising lead.

Many web pages would be greatly improved if their owners simply
watched over the shoulder of a new visitor.  Find someone who
resembles your target audience and who is completely unfamiliar
with your site.  State a specific goal to be reached by navigating
your site.  Watch silently over the subject's shoulder.

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


Re: print(f) for files .. and is print % going away?

2009-04-30 Thread Lie Ryan

Esmail wrote:

Hello all,

I use the print method with % for formatting my output to
the console since I am quite familiar with printf from my
C days, and I like it quite well.


There has never been print-with-formatting in python, what we have is 
the % string substitution operator, which is a string operation instead 
of print operation.



I am wondering if there is a way to use print to write
formatted output to files?


Of course:

f = open(...)
open.write('%s' % foo)

or

f = open(...)
print > f, '%s' % foo

or in python 3:
f = open(...)
print('%s' % foo, file=f)

or using the new superpowerful str.format()
>>> 'foo: {0} bar: {baz:3.1f} {1:e}'.format(123, 456.789, baz = 123.456)
'foo: 123 bar: 123.5 4.567890e+02'
--
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Please explain this strange Python behaviour

2009-04-30 Thread John Posner

Stephen Hansen wrote:
I have a feeling this might start one of those uber-massive "pass by 
value / reference / name / object / AIEE" threads where everyone goes 
around in massive circles explaining how Python uses one or another 
parameter passing paradigm and why everyone else is wrong... but... :)

Believe me, I don't want that to happen!
The thing is, parameter values are NOT supplied to a function when it 
is called.


When you call a function, there's no creation or copying of any values 
of any kind. The objects you pass in are passed in and the function 
receives those exact same objects. Within the function a local name is 
made which binds to an existing object that is specified when it is 
called-- or if a default is provided, that. In all cases these objects 
already exist before the call happens.
This is the kind of explanation I was looking for in the "why are 
default values shared" writeup.


Despite the fact that using mutable objects as default arguments is a 
frequent source of quirked-eyebrows and head-scratching for those new 
to Python, to do anything else would be weirdly magical. You'd 
basically have to go and call copy() on any default arguments 
specified in the function; at which point why are you copying those 
and not the other arguments?
The interpreter *could* take the extra trouble to do that with default 
arguments, because many users seems to expect that behavior. But I now 
understand how the decision *not* to treat default arguments as special 
cases produces the actual behavior. Many thanks, Stephen.


-John

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


Re: ctypes

2009-04-30 Thread Aahz
In article ,
Lawrence D'Oliveiro   wrote:
>
>-- 
>Lawrence "Death To Wildcard Imports" D'Oliveiro

+1 QOTW
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

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


Re: decode command line parameters - recomendend way

2009-04-30 Thread Martin v. Löwis
> I want add full Unicode support in my scripts. Now I have encoutered 
> theoretical
> problem with command line parameters. I can't find anything in that mater. But
> I develop solution which seems to work. Question is: Is it recommendend way to
> decode command line parameters:
> 
> lFileConfig = None
> if len(sys.argv) > 1:
>lFileConfig = unicode(sys.argv[1], locale.getpreferredencoding())
> 
> Or maybe there is other solution?

That is the right way. Expect that decoding may fail, though - see PEP
383 how this issue will be solved in Python 3.1.

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


Re: Python Noob - a couple questions involving a web app

2009-04-30 Thread Carl Banks
On Apr 28, 1:47 pm, "Kyle T. Jones"
 wrote:
> Been programming for a long time, but just starting out with Python.
> Not a professional programmer, just that guy in one of those
> organizations that won't hire a pro, instead saying "Hey, Kyle knows
> computer stuff - let's have him do this (and that, and the other, etc)".
>
> So, the higher ups want a web app that'll let them enter (from an
> intranet page) a rather simple, but quite lengthy, list - details to be
> stored in a MySQL database... just normal stuff here, entering, editing,
> and deleting entries, sorting, etc.
>
> On the internet side of things, folks get the info served up to them,
> can sort it in a few ways, etc - it's pretty basic stuff.
>
> So, normally, I'd just put something together with Javascript and some
> PHP scripts on the back end - so the Javascript is used to make
> requests, the php stuff makes the calls to the database then returns the
> appropriate info.
>
> I was thinking of doing the backend using Python instead of PHP - more
> just to get some hands-on experience with the language than anything else.
>
> So, first - is that a non-starter? - in other words, is it just
> something that lends itself more to PHP than Python?  That's how I would
> normally do it, just thought this would be a good opportunity to get
> some "practice" with Python.  And I know Python supports MySQL
> interactions, which, other than returning some info, is all that really
> needs to be done server-side.
>
> In a broader sense, any suggestions in terms of what I should be wary of
> on the security side of things - the internet component I mentioned is
> universally accessible... but the database itself can't be accessed that
> way directly (requests have to be sent to the PHP/Python scripts, which
> do have access to the MySQL stuff...)
>
> Any thoughts or suggestions are appreciated!

I will echo the recommendations for Django.

I looked at Django hoping to write a personal little app to manage
some personal data.  It turns out I didn't have to write an app at
all.  Django comes with a spiffy and versatile content editor, all I
had to do was input the database schema and configure the data entry
fields.

I figure you and your bosses can do the same thing to manage your
private Wolverine image stash.


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


string processing question

2009-04-30 Thread Kurt Mueller
Hi,


on a Linux system and python 2.5.1 I have the
following behaviour which I do not understand:



case 1
> python -c 'a="ä"; print a ; print a.center(6,"-") ; b=unicode(a, "utf8"); 
> print b.center(6,"-")'
ä
--ä--
--ä---
>


case 2
- an UnicodeEncodeError in this case:
> python -c 'a="ä"; print a ; print a.center(20,"-") ; b=unicode(a, "utf8"); 
> print b.center(20,"-")' | cat
Traceback (most recent call last):
  File "", line 1, in 
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 9: 
ordinal not in range(128)
ä
--ä--
>


The behaviour changes if I pipe the output to another prog or to a file.
and
centering with the string a is not correct, but with string b.



Could somebody please explain this to me?




Thanks in advance
-- 
Kurt Müller, [email protected]

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


Re: Geohashing

2009-04-30 Thread norseman

Marco Mariani wrote:

norseman wrote:

The posting needs (its creation) ... DATE. ...  The code needs to 
state OS and program and version used to write it.  And from there - 
user beware."


Which would reduce the confusion greatly.  I got the same error 
message and decided it was from an incompatible version, using 
incompatible modules.  Looks as if I guessed right.  I pity the poor 
first timer.


Raymond is living in a parallel universe (Fahrenheit 3K) where all the 
previous Python releases have been burned ;)



dystopianl-ly yours,
--
http://mail.python.org/mailman/listinfo/python-list




AH! That explains it. :)

He must have worked at Apple in it's earlier days.  Those were the days 
that when a new OS version came out you basically picked up your current 
computer and threw the whole thing in the trash.  Once the new OS 
version was installed ALL third party purchased programs and probably 
all those you had written stop functioning.  Maybe your data could be 
salvaged, maybe not.  To make matters worse, the new upgraded program 
probably failed to accomplish the one thing you bought the original to 
accomplish.  Not to mention the price tag was now more.


Maintaining upward compatibility was what gave Gates the edge. With 
Gates' OS a small company did not need a 100 geeks to be constantly 
rewriting the envelope addressing program.  He (or whoever he hired) 
could build the tool and then he could proceed to making a better living 
by letting the computer do the same-o same-o time killers while he 
serviced the customers.  For most it is all about the coin of the realm. 
For a few it is about the extra leisure time.  What ever your goal it's 
a cinch you hate to be constantly paying to remake things that already 
worked perfectly.


Gates trouble began when he started playing the Apple game.
Apple is on the rise because it took the lesson from Gates.

Several of my teachers along the way noted:  "Evolve or Perish."
I agree with that.  Thing is, they all had a problem with the one 
question I asked each:
"When the evolution proceeds to the point the latest one born is no 
longer compatible with the existing, how is it gonna make babies?"



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


Re: Replacing files in a zip archive

2009-04-30 Thread Scott David Daniels

MRAB wrote:

Дамјан Георгиевски wrote:
I'm writing a script that should modify ODF files. ODF files are just 
.zip archives with some .xml files, images etc.
So far I open the zip file and play with the xml with lxml.etree, but 
I can't replace the files in it.


Is there some recipe that does this ?


You'll have to create a new zip file and copy the files into that.


I agree.  In particular, even if there _were_ a good way to replace a
file in a zip, you risk the entire .zip if anything goes wrong
while you make changes like removing a file from the zip (and it
is essentially impossible to replace-in-place a zip element).  Since
zips are often used to store collections of files, that is a problem.
You can write multiple versions of a file in the zip, but "which one
wins" becomes problematic (often defined by implementation), and that
approach means that your zip grows with every change.

--Scott David Daniels
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: string processing question

2009-04-30 Thread Paul McGuire
On Apr 30, 11:55 am, Kurt Mueller  wrote:
> Hi,
>
> on a Linux system and python 2.5.1 I have the
> following behaviour which I do not understand:
>
> case 1> python -c 'a="ä"; print a ; print a.center(6,"-") ; b=unicode(a, 
> "utf8"); print b.center(6,"-")'
>
> ä
> --ä--
> --ä---
>
>

Weird.  What happens if you change the second print statement to:

print b.center(6,u"-")

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


Re: What do you think of ShowMeDo

2009-04-30 Thread Jim Carlock
"Astley Le Jasper" wrote...
: Gosh ... it's all gone quite busy about logging in, gui
: etc. Certainly, I would try to make it clearer what is
: free and what isn't.

Problems with their website probably means more problems to
come...

1) The website does not fit on one page.
2) It's a lot of yack about how beautiful, nice, wonderful
   and no substance, no proof, nothing to back up the yack.
3) They're interested in selling a product. What else?

What do you want to know about Python? What OS do you use?

I'm messing around with a program right at the moment. It
ends up as two applications, one runs as a server and one
as a client which presents a Window. It almost works, so I
need to work through it to work out it's bugs, and I'll be
rewriting it in a couple other languages.

Python looks fairly simple. It's a lot of "import" commands
and then "from" statements to do more importing. So I need
to figure out what the difference is between the two, as
the "from" seems to provide a way to identify what it wants
to import from the library/module.

I find it odd that no one includes the FQFN and employs a
short name. Nothing seems to get SET in the Environment to
identify where the library gets configured. I have to run
off to find help on the differences between "import" and
"from".

Good luck! Feel free to leave a reply.

-- 
Jim Carlock

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


using zip() and dictionaries

2009-04-30 Thread Sneaky Wombat
I'm really confused by what is happening here.  If I use zip(), I
can't update individual dictionary elements like I usually do.  It
updates all of the dictionary elements.  It's hard to explain, so here
is some output from an interactive session:

In [52]: header=['a','b','c','d']
In [53]: columnMap={}
In [54]: for (k,v) in zip(header,[[]]*len(header)):
   : #print "%s,%s"%(k,v)
   : columnMap[k] = v
   :
In [55]: columnMap
Out[55]: {'a': [], 'b': [], 'c': [], 'd': []}
In [56]: columnMap['a'].append('something')
In [57]: columnMap
Out[57]:
{'a': ['something'],
 'b': ['something'],
 'c': ['something'],
 'd': ['something']}

Why does ['something'] get attached to all columnMap elements instead
of just element 'a'?


In [58]: columnMap={'a': [], 'b': [], 'c': [], 'd': []}
In [59]: columnMap['a'].append('something')
In [60]: columnMap
Out[60]: {'a': ['something'], 'b': [], 'c': [], 'd': []}

creating the dictionary without using zip, it works as normal.
--
http://mail.python.org/mailman/listinfo/python-list


Re: string processing question

2009-04-30 Thread norseman

Kurt Mueller wrote:

Hi,


on a Linux system and python 2.5.1 I have the
following behaviour which I do not understand:



case 1

python -c 'a="ä"; print a ; print a.center(6,"-") ; b=unicode(a, "utf8"); print 
b.center(6,"-")'

ä
--ä--
--ä---


case 2
- an UnicodeEncodeError in this case:

python -c 'a="ä"; print a ; print a.center(20,"-") ; b=unicode(a, "utf8"); print 
b.center(20,"-")' | cat

Traceback (most recent call last):
  File "", line 1, in 
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 9: 
ordinal not in range(128)
ä
--ä--


The behaviour changes if I pipe the output to another prog or to a file.
and
centering with the string a is not correct, but with string b.



Could somebody please explain this to me?




Thanks in advance



Let me add to the confusion:
===
stevet:> python -c 'a="ä"; print a ; print a.center(6,"-") ; 
b=unicode(a, "utf8"); print b.center(6,"-")'

ä
--ä---
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe4 in position 0: 
unexpected end of data

stevet:>


stevet:> python -c 'a="ä"; print a ; print a.center(20,"-") ; 
b=unicode(a, "utf8"); print b.center(20,"-")' | cat

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe4 in position 0: 
unexpected end of data

ä
-ä--
stevet:>


stevet:> python -c 'a="ä"; print a ; print a.center(20,"-") ; 
b=unicode(a, "utf8"); print b.center(20,"-")'

ä
-ä--
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe4 in position 0: 
unexpected end of data

stevet:>

===

I'm using Python 2.5.2 on Linux Slackware 10.2
Line wraps (if showing) are Email induced.

Your first line bombs for me at unicode.
  a is centered (even number field len)
The second line bombs for me at unicode. (Has a pipe)
  a is centered (even number field len)
The third  line bombs for me at unicode. (No pipe)
  a is centered (even number field len)

In no case does the 'b' print.


If I put the code into a file and   python zz   #(a dummy file)
I get:

File zz:
---
a="ä"
print a
print a.center(20,"-")
b=unicode(a, "utf8")
print b.center(20,"-")


Output:
--
stevet:> py zz
  File "zz", line 2
SyntaxError: Non-ASCII character '\xe4' in file zz on line 2, but no 
encoding declared; see http://www.python.org/peps/pep-0263.html for details

stevet:>
--
It don't like "ä"

Python is cooking print. It is disallowing the full ASCII set in the 
print routine. (Yes - Yes, ASCII is 128 bytes (0->127) high bit off. But 
the full set allows the high bits to be used 'undefined' AKA use at your 
own risk.)


Look for special handling routines/docs whatever.
Seek  8Bit binary,  8Bit ASCII, etc..

Steve

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


Re: Measure the memory cost in Python

2009-04-30 Thread Gabriel Genellina

En Thu, 30 Apr 2009 08:00:07 -0300, Li Wang  escribió:

I want to measure the actual memory cost of a particular step in my  
program
(Python program), does anyone know if there is some function in Python  
could

help me to do this job? Or should I seek other tools to help me?


It's hard to compute from inside the program; I'd use OS tools to monitor  
memory usage.
Python 2.6 has sys.getsizeof() -- you have to apply it recursively, but  
not count objects more than once.


--
Gabriel Genellina

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


Re: Which flag to use in "configure" to Change the Install location?

2009-04-30 Thread Piet van Oostrum
> Omita  (O) wrote:

>O> Long story short... I am installing Python 2.6 on OSX.  By default the
>O> Library is installing here:

>O> /Library/Frameworks/Python.framework

>O> However, as I am using OSX Server I would ideally like the location to
>O> be here:

>O> /System/Library/Frameworks/Python.framework/

>O> Do I need to use the "--libdir" flag? Or is that referring to "lib"
>O> not "Library"?

Why do you ask the same question twice, and with different subjects?
This makes answering difficult.

To repeat my answer:

That's a good recipe to ruin your system software.

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: using zip() and dictionaries

2009-04-30 Thread Sneaky Wombat
quick update,

#change this line:
for (k,v) in zip(header,[[]]*len(header)):
#to this line:
for (k,v) in zip(header,[[],[],[],[]]):

and it works as expected.  Something about the [[]]*len(header) is
causing the weird behavior.  I'm probably using it wrong, but if
anyone can explain why that would happen, i'd appreciate it.  My guess
is that it's iterating through the the whole dictionary because of the
value on the right in zip().


On Apr 30, 12:45 pm, Sneaky Wombat <> wrote:
> I'm really confused by what is happening here.  If I use zip(), I
> can't update individual dictionary elements like I usually do.  It
> updates all of the dictionary elements.  It's hard to explain, so here
> is some output from an interactive session:
>
> In [52]: header=['a','b','c','d']
> In [53]: columnMap={}
> In [54]: for (k,v) in zip(header,[[]]*len(header)):
>    :     #print "%s,%s"%(k,v)
>    :     columnMap[k] = v
>    :
> In [55]: columnMap
> Out[55]: {'a': [], 'b': [], 'c': [], 'd': []}
> In [56]: columnMap['a'].append('something')
> In [57]: columnMap
> Out[57]:
> {'a': ['something'],
>  'b': ['something'],
>  'c': ['something'],
>  'd': ['something']}
>
> Why does ['something'] get attached to all columnMap elements instead
> of just element 'a'?
>
> In [58]: columnMap={'a': [], 'b': [], 'c': [], 'd': []}
> In [59]: columnMap['a'].append('something')
> In [60]: columnMap
> Out[60]: {'a': ['something'], 'b': [], 'c': [], 'd': []}
>
> creating the dictionary without using zip, it works as normal.

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


Re: using zip() and dictionaries

2009-04-30 Thread Chris Rebert
> On Apr 30, 12:45 pm, Sneaky Wombat <> wrote:
>> I'm really confused by what is happening here.  If I use zip(), I
>> can't update individual dictionary elements like I usually do.  It
>> updates all of the dictionary elements.  It's hard to explain, so here
>> is some output from an interactive session:
>>
>> In [52]: header=['a','b','c','d']
>> In [53]: columnMap={}
>> In [54]: for (k,v) in zip(header,[[]]*len(header)):
>>    :     #print "%s,%s"%(k,v)
>>    :     columnMap[k] = v
>>    :
>> In [55]: columnMap
>> Out[55]: {'a': [], 'b': [], 'c': [], 'd': []}
>> In [56]: columnMap['a'].append('something')
>> In [57]: columnMap
>> Out[57]:
>> {'a': ['something'],
>>  'b': ['something'],
>>  'c': ['something'],
>>  'd': ['something']}
>>
>> Why does ['something'] get attached to all columnMap elements instead
>> of just element 'a'?
>>
>> In [58]: columnMap={'a': [], 'b': [], 'c': [], 'd': []}
>> In [59]: columnMap['a'].append('something')
>> In [60]: columnMap
>> Out[60]: {'a': ['something'], 'b': [], 'c': [], 'd': []}
>>
>> creating the dictionary without using zip, it works as normal.

On Thu, Apr 30, 2009 at 11:00 AM, Sneaky Wombat  wrote:
> quick update,
>
> #change this line:
> for (k,v) in zip(header,[[]]*len(header)):
> #to this line:
> for (k,v) in zip(header,[[],[],[],[]]):
>
> and it works as expected.  Something about the [[]]*len(header) is
> causing the weird behavior.  I'm probably using it wrong, but if
> anyone can explain why that would happen, i'd appreciate it.  My guess
> is that it's iterating through the the whole dictionary because of the
> value on the right in zip().

Read 
http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list
Basically, the multiplication doesn't create new sub-lists, it just
copies references to the one original empty sublist.

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


Re: using zip() and dictionaries

2009-04-30 Thread Sneaky Wombat
quick update,

#change this line:
for (k,v) in zip(header,[[]]*len(header)):
#to this line:
for (k,v) in zip(header,[[],[],[],[]]):

and it works as expected.  Something about the [[]]*len(header) is
causing the weird behavior.  I'm probably using it wrong, but if
anyone can explain why that would happen, i'd appreciate it.  My guess
is that it's iterating through the the whole dictionary because of the
value on the right in zip().


On Apr 30, 12:45 pm, Sneaky Wombat <> wrote:
> I'm really confused by what is happening here.  If I use zip(), I
> can't update individual dictionary elements like I usually do.  It
> updates all of the dictionary elements.  It's hard to explain, so here
> is some output from an interactive session:
>
> In [52]: header=['a','b','c','d']
> In [53]: columnMap={}
> In [54]: for (k,v) in zip(header,[[]]*len(header)):
>    :     #print "%s,%s"%(k,v)
>    :     columnMap[k] = v
>    :
> In [55]: columnMap
> Out[55]: {'a': [], 'b': [], 'c': [], 'd': []}
> In [56]: columnMap['a'].append('something')
> In [57]: columnMap
> Out[57]:
> {'a': ['something'],
>  'b': ['something'],
>  'c': ['something'],
>  'd': ['something']}
>
> Why does ['something'] get attached to all columnMap elements instead
> of just element 'a'?
>
> In [58]: columnMap={'a': [], 'b': [], 'c': [], 'd': []}
> In [59]: columnMap['a'].append('something')
> In [60]: columnMap
> Out[60]: {'a': ['something'], 'b': [], 'c': [], 'd': []}
>
> creating the dictionary without using zip, it works as normal.

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


Is there any way this queue read can possibly block?

2009-04-30 Thread John Nagle

def draininput(self) :  # consume any queued input
try:
while True :
ch = self.inqueue.get_nowait()  # get input, if any
except Queue.Empty: # if empty
return  # done

"self.inqueue" is a Queue object.  The intent here is to drain the
queue, then return.  Is there any way this can possibly block or hang?
I wouldn't think so.  Another thread is doing "put" operations,
but slowly, never more than 5 per second.

(It's working for me, but a user of a program of mine is having a problem.)

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


Re: suggestion on a complicated inter-process communication

2009-04-30 Thread norseman

Aaron Brady wrote:

Um, that's the limit of what I'm familiar with, I'm afraid.  I'd have
to experiment.

On Apr 28, 10:44 am, Way  wrote:

Thanks a lot for the reply. I am not familiar with multi-process in
Python. I am now using something like:

snip

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


If you are using a Named Pipe for P1's input, you won't have P5's stdout 
to worry about.  Besides, P1 should know the Named Pipe P5 is using 
without Main telling P1.   Give them their own "Open_Channel_D" to 
communicate via.  (The Man from U.N.C.L.E. -- probably before your time.)





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


Won't find it until P5 starts dumping into it OR P1 creates it for P5 to 
use.  Either way - P1 simply needs to poll it if/while there and for P5 
going ByeBye to know when to stop polling. If P5 is gone, once the pipe 
is empty, there will be no more data.  If both (or either) P1, P5 are 
constantly running they will need a "I'm done" signal for one to let the 
other know it's going to sleep until needed.  Last item passed is 
something the sending program will NEVER generate on its own.

"Close_Channel_D"  :)



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

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



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


Re: string processing question

2009-04-30 Thread Scott David Daniels

Kurt Mueller wrote:

on a Linux system and python 2.5.1 I have the
following behaviour which I do not understand:
case 1

python -c 'a="ä"; print a ; print a.center(6,"-") ; b=unicode(a, "utf8"); print 
b.center(6,"-")'

ä
--ä--
--ä---

To discover what is happening, try something like:
python -c 'for a in "ä", unicode("ä"): print len(a), a'

I suspect that in your encoding, "ä" is two bytes long, and in
unicode it is converted to to a single character.

--Scott David Daniels
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: using zip() and dictionaries

2009-04-30 Thread Sneaky Wombat
Thanks!  That certainly explains it.  This works as expected.

columnMap={}
for (k,v) in zip(header,[[] for i in range(len(header))]):
#print "%s,%s"%(k,v)
columnMap[k] = v

columnMap['a'].append('test')


(sorry about the double post, accidental browser refresh)

On Apr 30, 1:09 pm, Chris Rebert  wrote:
> > On Apr 30, 12:45 pm, Sneaky Wombat <> wrote:
> >> I'm really confused by what is happening here.  If I use zip(), I
> >> can't update individual dictionary elements like I usually do.  It
> >> updates all of the dictionary elements.  It's hard to explain, so here
> >> is some output from an interactive session:
>
> >> In [52]: header=['a','b','c','d']
> >> In [53]: columnMap={}
> >> In [54]: for (k,v) in zip(header,[[]]*len(header)):
> >>    :     #print "%s,%s"%(k,v)
> >>    :     columnMap[k] = v
> >>    :
> >> In [55]: columnMap
> >> Out[55]: {'a': [], 'b': [], 'c': [], 'd': []}
> >> In [56]: columnMap['a'].append('something')
> >> In [57]: columnMap
> >> Out[57]:
> >> {'a': ['something'],
> >>  'b': ['something'],
> >>  'c': ['something'],
> >>  'd': ['something']}
>
> >> Why does ['something'] get attached to all columnMap elements instead
> >> of just element 'a'?
>
> >> In [58]: columnMap={'a': [], 'b': [], 'c': [], 'd': []}
> >> In [59]: columnMap['a'].append('something')
> >> In [60]: columnMap
> >> Out[60]: {'a': ['something'], 'b': [], 'c': [], 'd': []}
>
> >> creating the dictionary without using zip, it works as normal.
> On Thu, Apr 30, 2009 at 11:00 AM, Sneaky Wombat  wrote:
> > quick update,
>
> > #change this line:
> > for (k,v) in zip(header,[[]]*len(header)):
> > #to this line:
> > for (k,v) in zip(header,[[],[],[],[]]):
>
> > and it works as expected.  Something about the [[]]*len(header) is
> > causing the weird behavior.  I'm probably using it wrong, but if
> > anyone can explain why that would happen, i'd appreciate it.  My guess
> > is that it's iterating through the the whole dictionary because of the
> > value on the right in zip().
>
> Readhttp://www.python.org/doc/faq/programming/#how-do-i-create-a-multidim...
> Basically, the multiplication doesn't create new sub-lists, it just
> copies references to the one original empty sublist.
>
> Cheers,
> Chris
> --http://blog.rebertia.com

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


Re: using zip() and dictionaries

2009-04-30 Thread Scott David Daniels

Sneaky Wombat wrote:

quick update,

#change this line:
for (k,v) in zip(header,[[]]*len(header)):
#to this line:
for (k,v) in zip(header,[[],[],[],[]]):

and it works as expected.  Something about the [[]]*len(header) is
causing the weird behavior.  I'm probably using it wrong, but if
anyone can explain why that would happen, i'd appreciate it.


I'll bet the output below explains it:
header = 'a', 'b', 'c', 'd'
print [id(x) for x in [[]] * len(header)]
print [id(x) for x in [[],[],[],[]]]
and (what I think you want):
print [id(x) for x in [[] for x in header]]

So, I think you should use:
  columnMap = dict(zip(header, ([] for x in header)))

--Scott David Daniels
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list


urlgrabber for Python 3.0

2009-04-30 Thread Robert Dailey
urlgrabber 3.1.0 currently does not support Python 3.0. Is there a
version out there that does support this? Perhaps Python 3.0 now has
built in support for this? Could someone provide some guidance here?
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: using zip() and dictionaries

2009-04-30 Thread Arnaud Delobelle
Sneaky Wombat  writes:

> I'm really confused by what is happening here.  If I use zip(), I
> can't update individual dictionary elements like I usually do.  It
> updates all of the dictionary elements.  It's hard to explain, so here
> is some output from an interactive session:
>
> In [52]: header=['a','b','c','d']
> In [53]: columnMap={}
> In [54]: for (k,v) in zip(header,[[]]*len(header)):
>: #print "%s,%s"%(k,v)
>: columnMap[k] = v
>:
> In [55]: columnMap
> Out[55]: {'a': [], 'b': [], 'c': [], 'd': []}
> In [56]: columnMap['a'].append('something')
> In [57]: columnMap
> Out[57]:
> {'a': ['something'],
>  'b': ['something'],
>  'c': ['something'],
>  'd': ['something']}
>
> Why does ['something'] get attached to all columnMap elements instead
> of just element 'a'?
>
>
> In [58]: columnMap={'a': [], 'b': [], 'c': [], 'd': []}
> In [59]: columnMap['a'].append('something')
> In [60]: columnMap
> Out[60]: {'a': ['something'], 'b': [], 'c': [], 'd': []}
>
> creating the dictionary without using zip, it works as normal.

It's a FAQ:

http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list

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


Re: wxPython menu creation refactoring

2009-04-30 Thread alex
Good evening Nick
Thank you for answer I will study your code and learn from it.
I subscribed to the wxPython users mailing list which is for my actual
questions probably the more accurate place.
But I always apreciate that when I post even a probably simple
question I always get an answer from this group.
Thank you
Alex
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] PEP 383: Non-decodable Bytes in System Character Interfaces

2009-04-30 Thread Barry Scott


On 30 Apr 2009, at 05:52, Martin v. Löwis wrote:


How do get a printable unicode version of these path strings if they
contain none unicode data?


Define "printable". One way would be to use a regular expression,
replacing all codes in a certain range with a question mark.


What I mean by printable is that the string must be valid unicode
that I can print to a UTF-8 console or place as text in a UTF-8
web page.

I think your PEP gives me a string that will not encode to
valid UTF-8 that the outside of python world likes. Did I get this
point wrong?





I'm guessing that an app has to understand that filenames come in  
two forms
unicode and bytes if its not utf-8 data. Why not simply return  
string if

its valid utf-8 otherwise return bytes?


That would have been an alternative solution, and the one that 2.x  
uses

for listdir. People didn't like it.


In our application we are running fedora with the assumption that the
filenames are UTF-8. When Windows systems FTP files to our system
the files are in CP-1251(?) and not valid UTF-8.

What we have to do is detect these non UTF-8 filename and get the
users to rename them.

Having an algorithm that says if its a string no problem, if its
a byte deal with the exceptions seems simple.

How do I do this detection with the PEP proposal?
Do I end up using the byte interface and doing the utf-8 decode
myself?

Barry

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


Re: using zip() and dictionaries

2009-04-30 Thread Simon Forman
On Apr 30, 2:00 pm, Sneaky Wombat  wrote:
> quick update,
>
> #change this line:
> for (k,v) in zip(header,[[]]*len(header)):
> #to this line:
> for (k,v) in zip(header,[[],[],[],[]]):
>
> and it works as expected.  Something about the [[]]*len(header) is
> causing the weird behavior.  I'm probably using it wrong, but if
> anyone can explain why that would happen, i'd appreciate it.  My guess
> is that it's iterating through the the whole dictionary because of the
> value on the right in zip().
>
> On Apr 30, 12:45 pm, Sneaky Wombat <> wrote:
>
> > I'm really confused by what is happening here.  If I use zip(), I
> > can't update individual dictionary elements like I usually do.  It
> > updates all of the dictionary elements.  It's hard to explain, so here
> > is some output from an interactive session:
>
> > In [52]: header=['a','b','c','d']
> > In [53]: columnMap={}
> > In [54]: for (k,v) in zip(header,[[]]*len(header)):
> >    :     #print "%s,%s"%(k,v)
> >    :     columnMap[k] = v
> >    :
> > In [55]: columnMap
> > Out[55]: {'a': [], 'b': [], 'c': [], 'd': []}
> > In [56]: columnMap['a'].append('something')
> > In [57]: columnMap
> > Out[57]:
> > {'a': ['something'],
> >  'b': ['something'],
> >  'c': ['something'],
> >  'd': ['something']}
>
> > Why does ['something'] get attached to all columnMap elements instead
> > of just element 'a'?
>
> > In [58]: columnMap={'a': [], 'b': [], 'c': [], 'd': []}
> > In [59]: columnMap['a'].append('something')
> > In [60]: columnMap
> > Out[60]: {'a': ['something'], 'b': [], 'c': [], 'd': []}
>
> > creating the dictionary without using zip, it works as normal.
>
>

You figured out your original question, I just wanted to point out
that your code as posted is less efficient than it could be.
Rather than creating a list of empty lists to feed to zip() you could
just assign a new empty list to columnMap in your loop body, like so:

In [54]: for k in header:
   : columnMap[k] = []

That avoids creating a list of lists just to pass to zip() the call to
zip() too.
~S
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] PEP 383: Non-decodable Bytes in System Character Interfaces

2009-04-30 Thread Martin v. Löwis
>>> How do get a printable unicode version of these path strings if they
>>> contain none unicode data?
>>
>> Define "printable". One way would be to use a regular expression,
>> replacing all codes in a certain range with a question mark.
> 
> What I mean by printable is that the string must be valid unicode
> that I can print to a UTF-8 console or place as text in a UTF-8
> web page.
> 
> I think your PEP gives me a string that will not encode to
> valid UTF-8 that the outside of python world likes. Did I get this
> point wrong?

You are right. However, if your *only* requirement is that it should
be printable, then this is fairly underspecified. One way to get
a printable string would be this function

def printable_string(unprintable):
  return ""

This will always return a printable version of the input string...

> In our application we are running fedora with the assumption that the
> filenames are UTF-8. When Windows systems FTP files to our system
> the files are in CP-1251(?) and not valid UTF-8.

That would be a bug in your FTP server, no? If you want all file names
to be UTF-8, then your FTP server should arrange for that.

> Having an algorithm that says if its a string no problem, if its
> a byte deal with the exceptions seems simple.
> 
> How do I do this detection with the PEP proposal?
> Do I end up using the byte interface and doing the utf-8 decode
> myself?

No, you should encode using the "strict" error handler, with the
locale encoding. If the file name encodes successfully, it's correct,
otherwise, it's broken.

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


Re: Tools for web applications

2009-04-30 Thread Scott David Daniels

Marco Mariani wrote:

Mario wrote:

I used JCreator LE, java IDE for windows because, when I add 
documentation of some new library, I have it on a F1 and index. So how 
you manage documentation and code completion ? I asume that you are 
geek but not even geeks could know every method of every class.



What you call "code completion" cannot work in many cases with dynamic 
languages. Nobody knows which methods are available to an object until 
the program is running 
I must admit that I've never used completion of anything while 
developing. I routinely it do with the IPython shell, and I would suffer 
if I didn't have it in postgres, but not while editing python.

You'd be amazed at how much ActiveState's Python _can_ and _does_
guess/infer about available methods.  It is pretty fancy (even for
an old stick-in-the-mud "Lave my keyboard alone" guy like me.

--Scott David Daniels   [no affiliation, except former customer]
[email protected]

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


Re: import and package confusion

2009-04-30 Thread Terry Reedy

Dale Amon wrote:


Now I can move on to parsing those pesky Fortran card
images... There wouldn't happen to be a way to take n
continguous slices from a string (card image) where each 
slice may be a different length would there? Fortran you 
know. No spaces between input fields. :-)


I know a way to do it, iterating over a list of slice sizes,


Yes.

perhaps in a list comprehension, but some of the august python 
personages here no doubt know better ways.


No.  Off the top of my head, here is what I would do something like 
(untested)


def card_slice(card, sizes):
  "Card is data input string. Sizes is an iterable of int field sizes, 
where negatives are skipped fields.  Return list of strings."

  pos, ret = 0, []
  for i in sizes:
if i > 0:
  ret.append(card[pos:pos+i])
else:
  i = -i
pos += i
  return ret

To elaborate this, make sizes an iterable of (size, class) pairs, where 
class is str, int, or float (for Fortran) or other for more generel use. 
 Then

  ...
  for i,c in sizes:
if i > 0:
  ret.append(c(card[pos:pos+i]))

Terry Jan Reedy

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


Multiprocessing.Queue - I want to end.

2009-04-30 Thread Luis Zarrabeitia

Hi. I'm building a script that closely follows a producer-consumer model. In 
this case, the producer is disk-bound and the consumer is cpu-bound, so I'm 
using the multiprocessing module (python2.5 with the multiprocessing backport 
from google.code) to speed up the processing (two consumers, one per core, 
and one producer). The consumers are two multiprocessing.Process instances, 
the producer is the main script, and the data is sent using a 
multiprocessing.Queue instance (with bounded capacity).

The problem: when there is no more data to process, how can I signal the 
consumers to consume until the queue is empty and then stop consuming? I need 
them to do some clean-up work after they finish (and then I need the main 
script to summarize the results)

Currently, the script looks like this:

===
from multiprocessing import Queue, Process

def consumer(filename, queue):
outfile = open(filename,'w')
for data in iter(queue.get, None):
process_data(data, outfile) # stores the result in the outfile
outfile.close()
cleanup_consumer(filename)

if __name__ == "__main__":
queue = Queue(100)
p1 = Process(target=consumer, args=("file1.txt", queue))
p2 = Process(target=consumer, args=("file1.txt", queue))
p1.start(); p2.start()
for item in read_from_disk(): # this is the disk-bound operation
queue.put(item)
queue.put(None); queue.put(None)
p1.join() # Wait until both consumers finish their work
p2.join()
# Tried to put this one before... but then the 'get' raises
# an exception, even if there are still items to consume.
queue.close() 
summarize() # very fast, no need to parallelize this.
===

As you can see, I'm sending one 'None' per consumer, and hoping that no 
consumer will read more than one None. While this particular implementation 
ensures that, it is very fragile. Is there any way to signal the consumers? 
(or better yet, the queue itself, as it is shared by all consumers?) 
Should "close" work for this? (raise the exception when the queue is 
exhausted, not when it is closed by the producer).

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tools for web applications

2009-04-30 Thread Trent Mick

Scott David Daniels wrote:

Marco Mariani wrote:
What you call "code completion" cannot work in many cases with dynamic 
languages. Nobody knows which methods are available to an object until 
the program is running I must admit that I've never used 
completion of anything while developing. I routinely it do with the 
IPython shell, and I would suffer if I didn't have it in postgres, but 
not while editing python.


As Scott indicates, one can often do a fairly good job. I'm definitely 
not a Java guy, but I've heard that Java generics (don't ask me to 
identify one of them! :) can cause similar pains for Java 
autocomplete/calltips as some dynamic language patterns can.



You'd be amazed at how much ActiveState's Python _can_ and _does_
guess/infer about available methods.  It is pretty fancy (even for
an old stick-in-the-mud "Lave my keyboard alone" guy like me.


Do you mean Komodo?
http://www.activestate.com/komodo/

Trent

--
Trent Mick
trentm at activestate.com
--
http://mail.python.org/mailman/listinfo/python-list


On replacing % formatting with str.format

2009-04-30 Thread Terry Reedy
Guido intends that the new str.format and associated facilities 
eventually replace the old % formatting operator.  But when? (Why is a 
different question discussed elsewhere, but includes elimination of a 
couple of problems and greatly increased flexibility and extendibility.)


A few month ago, Guido asked about barriers to switching and two primary 
issues came up:


1. No automatic conversion.  A couple of people said that would work on 
this but I do not know the status.


2. Simple replacement made harder.  For example, "Put the $s in the $s 
until $s." had to be rewritten as "Put the {0} in the {1} until {2},". 
This is harder to write because each replacement field requires not just 
an extra character, but also two shift-unshift sequences instead of one. 
 Plus, one could make a mistake in numbering, or add and delete a field 
and have to renumber.  Ugh.


So I suggested that we let the interpreter autonumber positional fields, 
so we could just write "Put the {} in the {} until {}.", which is about 
as easy to type as the $s version.  Eric Smith wrote and committed a 
patch for 3.1 so we will be able to do that.


So I believe that people just starting with Python, with 2.6, 3.0 (which 
should definitely be upgraded to 3.1 when possible), or some with 3.1 
should start with the new .format.


Terry Jan Reedy

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


Re: [Python-Dev] PEP 383: Non-decodable Bytes in System Character Interfaces

2009-04-30 Thread Barry Scott


On 30 Apr 2009, at 21:06, Martin v. Löwis wrote:

How do get a printable unicode version of these path strings if  
they

contain none unicode data?


Define "printable". One way would be to use a regular expression,
replacing all codes in a certain range with a question mark.


What I mean by printable is that the string must be valid unicode
that I can print to a UTF-8 console or place as text in a UTF-8
web page.

I think your PEP gives me a string that will not encode to
valid UTF-8 that the outside of python world likes. Did I get this
point wrong?


You are right. However, if your *only* requirement is that it should
be printable, then this is fairly underspecified. One way to get
a printable string would be this function

def printable_string(unprintable):
 return ""


Ha ha! Indeed this works, but I would have to try to turn enough of the
string into a reasonable hint at the name of the file so the user can
some chance of know what is being reported.




This will always return a printable version of the input string...


In our application we are running fedora with the assumption that the
filenames are UTF-8. When Windows systems FTP files to our system
the files are in CP-1251(?) and not valid UTF-8.


That would be a bug in your FTP server, no? If you want all file names
to be UTF-8, then your FTP server should arrange for that.


Not a bug its the lack of a feature. We use ProFTPd that has just  
implemented
what is required. I forget the exact details - they are at work - when  
the ftp client
asks for the FEAT of the ftp server the server can say use UTF-8.  
Supporting

that in the server was apparently none-trivia.






Having an algorithm that says if its a string no problem, if its
a byte deal with the exceptions seems simple.

How do I do this detection with the PEP proposal?
Do I end up using the byte interface and doing the utf-8 decode
myself?


No, you should encode using the "strict" error handler, with the
locale encoding. If the file name encodes successfully, it's correct,
otherwise, it's broken.


O.k. I understand.

Barry

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


Re: urlgrabber for Python 3.0

2009-04-30 Thread Terry Reedy

Robert Dailey wrote:

urlgrabber 3.1.0 currently does not support Python 3.0.


URLs are nice.  I presume you mean the package at

http://linux.duke.edu/projects/urlgrabber/

Development appears to have stopped over two years ago with the 3.1.0 
release, which was for 2.3-2.5.


> Is there a version out there that does support this?

Perhaps 2to3 would come close to producing such a version.  You might 
ask the authors if they plan any further development or support.



Perhaps Python 3.0 now has
built in support for this? Could someone provide some guidance here?


I do not think there were any major changes in the library modules.

tjr

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


Re: getting linux distro used...

2009-04-30 Thread JanC
deostroll wrote:

> I just found that you could use platform.system() to get the
> underlying os used. But is there a way to get the distro used...?

Major modern distros support 'lsb_release', I suppose:

$ lsb_release -i -r -c -d
Distributor ID: Ubuntu
Description:Ubuntu 9.04
Release:9.04
Codename:   jaunty


If that doesn't work; try '/etc/issue'.


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


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

2009-04-30 Thread JanC
John Nagle wrote:

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

+ dbus


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


Re: import and package confusion

2009-04-30 Thread MRAB

Terry Reedy wrote:

Dale Amon wrote:


Now I can move on to parsing those pesky Fortran card
images... There wouldn't happen to be a way to take n
continguous slices from a string (card image) where each slice may be 
a different length would there? Fortran you know. No spaces between 
input fields. :-)


I know a way to do it, iterating over a list of slice sizes,


Yes.

perhaps in a list comprehension, but some of the august python 
personages here no doubt know better ways.


No.  Off the top of my head, here is what I would do something like 
(untested)


def card_slice(card, sizes):
  "Card is data input string. Sizes is an iterable of int field sizes, 
where negatives are skipped fields.  Return list of strings."

  pos, ret = 0, []
  for i in sizes:
if i > 0:
  ret.append(card[pos:pos+i])
else:
  i = -i
pos += i


I would shorten that a little to:

if i > 0:
  ret.append(card[pos:pos+i])
pos += abs(i)


  return ret

To elaborate this, make sizes an iterable of (size, class) pairs, where 
class is str, int, or float (for Fortran) or other for more generel use. 
 Then

  ...
  for i,c in sizes:
if i > 0:
  ret.append(c(card[pos:pos+i]))

Terry Jan Reedy

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



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


  1   2   >