Re: Delete values from a string using the index

2007-09-27 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], 
[EMAIL PROTECTED] wrote:

 How do I delete or remove values from a list or string using the
 index.

Note you can't do it with a string, since that's not mutable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using closures and partial functions to eliminate redundant code

2007-09-27 Thread Gabriel Genellina
En Wed, 26 Sep 2007 23:01:17 -0300, Matthew Wilson [EMAIL PROTECTED]  
escribi�:

 I wrote some code to create a user and update a user on a remote box by
 sending emails to that remote box.  When I was done, I realized that my
 create_user function and my update_user function were effectively
 identical except for different docstrings and a single different value
 inside:

I would have used an object with two methods... But this is just another  
example of the closure/object dichotomy. Some enlightment:
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html

-- 
Gabriel Genellina

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

Re: database persistence with mysql, sqlite

2007-09-27 Thread Bryan Olson
Lawrence D'Oliveiro wrote:
 Bryan Olson wrote:
 
 Lawrence D'Oliveiro wrote:
 In Bryan Olson wrote:

 coldpizza wrote:
 It turned out that the method above ('SELECT * FROM TABLE LIMIT L1,
 L2') works ok both with mysql and sqlite3, therefore I have decided to
 stick with it until I find something better. With Sqlite3 you are
 supposed to use LIMIT 10 OFFSET NN, but it also apparently supports
 the mysql syntax (LIMIT NN, 10) for compatibility reasons.

 A more reliable form is along the lines:

  SELECT keyfield, stuff
  FROM table
  WHERE keyfield  ?
  ORDER BY keyfield
  LIMIT 10

 With the right index, it's efficient.

 But that involves keeping track of the right starting keyfield value for
 the next batch of records, which is complicated and nontrivial.

 We write the link so that the browser will send back the parameter we
 need. If the largest keyfield value on the page is
 Two-Sheds the link might read:

 A HREF=http://rfh.uk/tablnext.cgi?start=Two-Sheds;Next/A
 
 That's assuming keyfield is a) unique, 

Exactly; that was was the idea behind the name choice. The
method extends to multi-column keys, so it is generally
applicable.

 and b) a relevant ordering for
 displaying to the user.

That's a nice-to-have, but not required.

 Keeping a cursor with pending data across HTTP requests is
 a world of hurt.
 
 limit offset, count avoids all that.

It can be stateless, but then it is unreliable. Here's an
example with Python 2.5:


import sqlite3

db = sqlite3.connect(:memory:)

# Simple table, an integer and the hex for that integer
db.execute(
   CREATE TABLE numbers (num INTEGER PRIMARY KEY, hex TEXT))

# Start with 10-29 in the table
for i in range(10, 30):
 db.execute(INSERT INTO numbers VALUES (?, ?), (i, hex(i)))


# Print 4 records starting at offset
def next4(offset):
 cur = db.execute(
   SELECT * FROM numbers LIMIT 4 OFFSET ?,
   (offset,))
 for x in cur:
 print x


# Walk the table with LIMIT and OFFSET

next4(0)   # Good, prints 10-13
next4(4)   # Good, prints 14-17

# Another transaction inserts new records
for i in range(0, 4):
 db.execute(INSERT INTO numbers VALUES (?, ?), (i, hex(i)))

next4(8)   # Bad, prints 14-17 again

# Another transaction deletes records
for i in range(0, 4):
 db.execute(DELETE FROM numbers WHERE num = ?, (i,))

next4(12)  # Bad, we're missing 18-21



The method I advocated is still not the same as doing the
whole thing in a serializable transaction, but it will
return any record that stays in the table the whole time,
and will not return any record multiple times.


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


Re: Python class method as an argument of a function in a C extension

2007-09-27 Thread mauro
On 26 Set, 19:00, Matimus [EMAIL PROTECTED] wrote:
  Can anybody give me an hint (or some link) on how to define
  'aCFunction' and how to call 'self.myMethod' in the C source code?

 A python function defined in C accepts a pointer to self and a tuple
 of arguments, each of which is also a PyObject. If you pass a function
 or method, it will be included in the tuple of arguments. I don't
 think there is any difference between passing a method and a function.
 You can call that method using functions in the `Object Protocol'
 section of the API, such as PyObject_Call(...).

 Here is an example from the Python 
 documentation:http://docs.python.org/ext/callingPython.html

 The first part shows how to get a function as an argument. The
 following bits of code show how to actually call that function.The
 example uses PyEval_CallObject, which I can't find documentation to.
 I'm not sure if it even exists (it may be a documentation error). But
 from the example it seems to work exactly the same as
 PyObject_CallObject.

 Matt

Thanks a lot!
At last I succeeded in finding an example:
http://mail.python.org/pipermail/python-list/1999-May/003441.html
This uses exactly the PyObject_CallObject, as you suggest.

Mauro

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


Re: Asynchronous Messaging

2007-09-27 Thread Gabriel Genellina
En Thu, 27 Sep 2007 01:43:32 -0300, wink [EMAIL PROTECTED] escribi�:

 You are most correct, but Queue is slow compared to deque but
 not for the reason I guessed. Apparently it's because deque is
 implemented in C while Queue is in python. Using the program below
 it looks there is about a 35:1 speed difference.

That't not the reason. A Queue is built around a container, and it happens  
to be a deque in the default implementation. But the important thing is  
that a Queue is a synchronized object - it performs the necesary  
synchronization to ensure proper operation even from multiple threads  
attempting to use it at the same time.
So your comparison is meaningless, apart from telling that using mutexes  
is not cheap.

-- 
Gabriel Genellina

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

Re: ~ bit-wise unary operator

2007-09-27 Thread Ladislav Andel
Wow, so many answers :). Thank you, guys :).

Lada

Michal Bozon wrote:
 cau,
 maybe int is represented internally as a signed integer

 you can use numpy types:

   
 import numpy
 ~ numpy.uint16(7978)
 
 57557

  -m.


 On Thu, 27 Sep 2007 00:14:49 +0200, Ladislav Andel wrote:

   
 Hello,
 why ~ bit-wise unary operator returns -(x+1) and not bit inversion of 
 the given integer?

 example:
 a = 7978
 a = ~a
 python returns -7979

 but I need to get back 57557 as in C language.

 which is also in binary
 000100101010
 and inverted
 111011010101

 Is here any other operator or do I have to write it on my own?

 Thank you,
 Lada
 

   

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


Re: Google and Python

2007-09-27 Thread Hendrik van Rooyen
Nick Craig-Wood od.com wrote:

 Hendrik van Rooyen ma.p.co.za wrote:
   Paul Rubin http://lid wrote:
 
   Hendrik van Rooyen m..orp.co.za writes:

   Ok got it - so instead of starting a thread, as is current practice, you
fork
   a process (possibly on another machine) and hand over the client.

 It is trivial to pass a socket to a new thread or a forked child - you
 don't need this mechanism for that.  It doesn't work on different
 machines though - it has to be on the same machine.

8 - nice explanation by Nick---

How does a very large volume site work then? - there must be some
way of sharing the load without bottlenecking it through one machine?

- Hendrik

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-27 Thread Antoon Pardon
On 2007-09-26, Mark Summerfield [EMAIL PROTECTED] wrote:
 On 26 Sep, 13:22, Antoon Pardon [EMAIL PROTECTED] wrote:

 Well you should decide what you want. In a previous exchange one of the
 things that was wanted was that you could already seed a tree by using
 key word arguments so that you could do the following:

 t=Tree(a=15, b=30)

 which would be equivallent to:

 t=Tree()
 t.update(a=15,b=30)

 But with the above proposal

 t=Tree(cmp=cmp)

 is not equivallent to

 t=Tree()
 t.update(cmp=cmp)

 So it seems the API needs some more sorting out.

 I think you missed some of the previous postings.

That is possible.

 The sorteddict API that has emerged so far is (1) apart from the
 constructor, everything is identical to dict, (2) the constructor
 takes the same args as sorted(), so if you want to seed with a dict or
 with keywords you write sorteddict(dict(a=1,b=2), ...), (or you could
 create a sorteddict and use update() since that takes the same args as
 dict's constructor).

 Could your AVLTree support cmp and keys and reverse?

It already supports cmp. Although for the moment it is done by
subclassing. Like the following.

class myTree(AVLTree):
  @staticmethod
  def cmp(a, b);
return 

I don't think adding support for keys will be difficult but it may be
tedious.

I would prefer not to support reverse because the effect can be acquired
by the other two and in contradiction with sorting, I think using it
will slow things down instead of speeding things up.

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


Re: strange behavious of the logging module?

2007-09-27 Thread Christian Meesters
Thanks Peter and Vinay,

I finally understood.
And indeed, removing the pyc-file in questions solves the problem - at least
temporarily. 

Christian

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


Re: How do I get the value out of a DOM Element

2007-09-27 Thread Stefan Behnel
kj7ny wrote:
 I have been able to get xml.dom.minidom.parse('somefile.xml') and then
 dom.getElementsByTagName('LLobjectID') to work to the point where I
 get something like: [DOM Element: LLobjectID at 0x13cba08] which I
 can get down to DOM Element: LLobjectID at 0x13cba08 but then I
 can't find any way to just get the value out from the thing!
 
 .toxml() returns something like: u'LLobjectID![CDATA[1871203]]/
 LLobjectID'.
 
 How do I just get the 1871203 out of the DOM Element?

It contains a CDATA node which in turn contains a Text node (AFAIR), so you
have to walk through the children to get what you want.

Alternatively, try an XML API that makes it easy to handle XML, like
ElementTree (part of the stdlin in Python 2.5) or lxml, both of which have
compatible APIs. The code would look like this:

   tree = etree.parse(some_file.xml)
   id = tree.find(//LLobjectID)
   print id.text

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


Re: Using closures and partial functions to eliminate redundant code

2007-09-27 Thread Bruno Desthuilliers
Matthew Wilson a écrit :
 I wrote some code to create a user and update a user on a remote box by
 sending emails to that remote box.  When I was done, I realized that my
 create_user function and my update_user function were effectively
 identical except for different docstrings and a single different value
 inside:
 
 ### VERSION ONE
 
 def create_user(username, userpassword, useremail):
 Send an email that will create a user in the remote system.
 
 # Build email
 email_body = 
 USERNAME = %s
 USERPASSWORD = %s
 USEREMAIL = %s
  % (username, userpassword, useremail)
 
 # send it.
 send_email(subject=CREATE, body=email_body)
 
 
 def update_user(username, userpassword, useremail):
 Send an email that will update a user's password in the remote 
 system.
 
 # Build email
 email_body = 
 USERNAME = %s
 USERPASSWORD = %s
 USEREMAIL = %s
  % (username, userpassword, useremail)
 
 # send it.
 send_email(subject=UPDATE, body=email_body)
 
 ### END

(snip)
 
 Finally, I came up with this approach:
 
 ### VERSION THREE
 
 from functools import partial
 
 def _h(mode, username, userpassword, useremail):
 
 if mode not in (create, update): 
 raise ValueError(mode must be create or update!)
 
 # Build email
 email_body = 
 USERNAME = %s
 USERPASSWORD = %s
 USEREMAIL = %s
  % (username, userpassword, useremail)
 
 # send it.  
 send_email(subject=mode.upper(), body=email_body)
 
 # I can't figure out how to set up the docstring on these.
 
 v3_create_user = partial(_h, mode=create)
 v3_update_user = partial(_h, mode=update)
 
 ### END
 
 I'm interested to hear how other people deal with really similar code.

Depends.

 The similarity just bugs me.  However, I wonder if using stuff like
 closures or partial function application is needlessly showy.

Not necessarily, but in this case, it's just overkill IMHO - I'd just 
have factored out the common code:

def _build_email(username, userpassword, useremail):
  builds the email body used by create_uer and update_user 
 return 
 USERNAME = %s
 USERPASSWORD = %s
 USEREMAIL = %s
  % (username, userpassword, useremail)


 def create_user(username, userpassword, useremail):
 Send an email that will create a user in the remote system.
 send_email(subject=CREATE,
body=_build_email(username, userpassword, useremail)
)


 def update_user(username, userpassword, useremail):
 Send an email that will update a user's password in the remote 
system.
 send_email(subject=UPDATE,
body=_build_email(username, userpassword, useremail)
)



Now there are of course cases where either closures and/or partials are 
the right thing to do.

 Also, I hope anyone here can help me figure out how to attach a
 meaningful docstring for my version three code.

Didn't try, but what about:
p = partial(func, arg)
p.__doc__ = yadda yadda

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-27 Thread Duncan Booth
Paul Hankin [EMAIL PROTECTED] wrote:

 A key which is in dict must be either in __keycache or in __addkeys, but
 never in both.
 
 Yes, I'm sorry: you're right.
 
 But there's a different bug: if you delete a key that's not in the
 dict, you'll add it to the deleted list before the exception for the
 missing key is raised.
 
 sd = sorteddict.sorteddict()
 sd['a'] = 'a'
 print sd.keys() = ['a']
 try:
 del sd['b']
 except:
 pass
 sd['b'] = 'b'
 print sd.keys()
 
 The second print statement produces ['a'] rather than ['a', 'b']

Yes, I think there are probably several cases where I need to account for 
exceptions.

There's another serious problem: if Mark wants this module to be used and 
stand any chance at all of eventually being incorporated into the standard 
library, then he will have to change the license on his code: the GPL 
simply isn't an option here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google and Python

2007-09-27 Thread David
  It is trivial to pass a socket to a new thread or a forked child - you
  don't need this mechanism for that.  It doesn't work on different
  machines though - it has to be on the same machine.

 8 - nice explanation by Nick---

 How does a very large volume site work then? - there must be some
 way of sharing the load without bottlenecking it through one machine?


Large sites do load balancing (caching, dns round robin, reverse
proxies, etc) over many hosts. Passing connection handles around on a
single host is a different type of optimization.

See this link for info on how Wikipedia handles their load-balancing:

http://en.wikipedia.org/wiki/Wikipedia#Software_and_hardware
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-27 Thread Bryan Olson
Mark Summerfield wrote:
 The sorteddict API that has emerged so far is (1) apart from the
 constructor, everything is identical to dict, (2) the constructor
 takes the same args as sorted(), so if you want to seed with a dict or
 with keywords you write sorteddict(dict(a=1,b=2), ...), (or you could
 create a sorteddict and use update() since that takes the same args as
 dict's constructor).
 
 Could your AVLTree support cmp and keys and reverse?


I think you are expending too much effort on the no-brainers.
Yes, AVL-trees can support cmp and keys and reverse. I cannot
speak for Antoon, but have no doubt that adapting his code to
do so is within his ability.

Hrvoje Niksic is right that a simple layer over existing
hashed dicts dooms the PEP to rejection. Thus the candidate
algorithms are the approximately-balanced tree structures:
AVL trees, red-black trees, 2-3 trees, b-trees, splay trees,
or skip-lists.

Implementing these is non-trivial, but easily within the
ability of many people here. Don't worry about the coding.


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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-27 Thread Mark Summerfield
On 27 Sep, 08:32, Duncan Booth [EMAIL PROTECTED] wrote:
 Paul Hankin [EMAIL PROTECTED] wrote:
  A key which is in dict must be either in __keycache or in __addkeys, but
  never in both.

  Yes, I'm sorry: you're right.

  But there's a different bug: if you delete a key that's not in the
  dict, you'll add it to the deleted list before the exception for the
  missing key is raised.

  sd = sorteddict.sorteddict()
  sd['a'] = 'a'
  print sd.keys() = ['a']
  try:
  del sd['b']
  except:
  pass
  sd['b'] = 'b'
  print sd.keys()

  The second print statement produces ['a'] rather than ['a', 'b']

 Yes, I think there are probably several cases where I need to account for
 exceptions.

 There's another serious problem: if Mark wants this module to be used and
 stand any chance at all of eventually being incorporated into the standard
 library, then he will have to change the license on his code: the GPL
 simply isn't an option here.

I have fixed __addkey() and __removekey():

def __addkey(self, key):
if key in self.__delkeys:
self.__delkeys.remove(key)
else:
self.__addkeys.add(key)


def __removekey(self, key):
if key in self.__addkeys:
self.__addkeys.remove(key)
else:
self.__delkeys.add(key)

I have also fixed __delitem__():

try:
dict.__delitem__(self, key)
except KeyError:
raise
else:
self.__removekey(key)

As for the license, while it is on PyPI, I'll leave it as GPL v 3. If
it was wanted for the standard library (and I can't see that ever
happening), I will happily change it to the one that is preferred for
Python modules.

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


Re: sorteddict [was a PEP proposal, but isn't anymore!]

2007-09-27 Thread Mark Summerfield
On 26 Sep, 18:59, Raymond Hettinger [EMAIL PROTECTED] wrote:
 [Mark Summerfield]

  Below is a PEP proposal for a sorteddict. It arises out of a
  discussion on this list that began a few weeks ago with the subject of
  An ordered dictionary for the Python library?

 It is worth remembering that the long sought after datatype was a dict
 that could loop over keys in *insertion* order, not based on some
 function of the key itself.

  If there is positive feedback I will submit the PEP to the reviewers,
  so if you think it is a good idea please say so.

 As one who was submitted many PEPs, I can advise that the quickest way
 to irrevocably kill an idea is to submit a PEP to early (we almost
 didn't get genexps because the PEP was submitted pre-maturely).
 Instead, I advise posting an ASPN recipe so the details can be
 hammered-out and a fan club can be grown.

 For this particular idea, I am -1 on inclusion in the standard
 library.  The PEP focuses mainly on implementation but is weakest in
 the rationale section.  Its advantages over for k in sorted(d) are
 miniscule.  To be considered for the collections module, there needs
 to be compelling use case advantages either in terms of usability or
 performance.
[snip]

I gave up on the idea of submitting it as a PEP many postings ago:-)
I've now changed the subject line to reflect that.

I will leave the pure python sorteddict on PyPI for anyone who wants
it.

I won't put it on the cookbook site for the time being, simply because
it is eating up much  more time than I thought!


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


Re: How do I get the value out of a DOM Element

2007-09-27 Thread Paul Boddie
On 27 Sep, 07:50, kj7ny [EMAIL PROTECTED] wrote:
 I have been able to get xml.dom.minidom.parse('somefile.xml') and then
 dom.getElementsByTagName('LLobjectID') to work to the point where I
 get something like: [DOM Element: LLobjectID at 0x13cba08] which I
 can get down to DOM Element: LLobjectID at 0x13cba08 but then I
 can't find any way to just get the value out from the thing!

 .toxml() returns something like: u'LLobjectID![CDATA[1871203]]/
 LLobjectID'.

 How do I just get the 1871203 out of the DOM Element?

DOM Level 3 provides the textContent property:

http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent

You'll find this in libxml2dom and possibly some other packages such
as pxdom. For the above case with minidom specifically (at least with
versions I've used), you need to iterate over the childNodes of the
element, obtaining the nodeValue for each node and joining them
together. Something like this might do it:

.join([n.nodeValue for n in element.childNodes])

It's not pretty, but encapsulating stuff like this is what functions
are good for.

Paul

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


Re: Using closures and partial functions to eliminate redundant code

2007-09-27 Thread Paul Hankin
On Sep 27, 3:01 am, Matthew Wilson [EMAIL PROTECTED] wrote:
 I wrote some code to create a user and update a user on a remote box by
 sending emails to that remote box.  When I was done, I realized that my
 create_user function and my update_user function were effectively
 identical except for different docstrings and a single different value
 inside:

 ### VERSION ONE

 def create_user(username, userpassword, useremail):
 Send an email that will create a user in the remote system.

 # Build email
 email_body = 
 USERNAME = %s
 USERPASSWORD = %s
 USEREMAIL = %s
  % (username, userpassword, useremail)

 # send it.
 send_email(subject=CREATE, body=email_body)

 def update_user(username, userpassword, useremail):
 Send an email that will update a user's password in the remote 
 system.

 # Build email
 email_body = 
 USERNAME = %s
 USERPASSWORD = %s
 USEREMAIL = %s
  % (username, userpassword, useremail)

 # send it.
 send_email(subject=UPDATE, body=email_body)

If you don't mind what order the lines of your email appear in, you
might get more reuse out of something like this. As other's have said
partial isn't needed here.

def send_command_email(subject, **kwargs):
Send an email to the with the given subject, and lines of the
   body of the form A = B for each keyword argument.
email_body = '\n'.join('%s = %s' % (k, kwargs[k]) for k in kwargs)
send_email(subject=subject, body='\n' + email_body + '\n'

def create_user(name, password, email):
Create a user by sending an email to the server
send_command_email('CREATE', USERNAME=name,
USERPASSWORD=password, USEREMAIL=email)

def update_user(name, password, email):
Update a user's details by sending an email to the server
send_command_email('UPDATE', USERNAME=name,
USERPASSWORD=password, USEREMAIL=email)

--
Paul Hankin

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


Re: Tkinter / Tk 8.5

2007-09-27 Thread Eric Brunel
On Thu, 27 Sep 2007 04:41:48 +0200, Scott David Daniels  
[EMAIL PROTECTED] wrote:

 Michal Bozon wrote:
 Today has been released a first beta of Tk 8.5, including a Ttk
 (tile) style engine, which makes possible the native look
 of widgets on MS platform, without having to install any extension.
  Is there a chance it will be included in 2.5.x, 2.6 or 3.0 ?

 This is just a guess, but:
 The beta: no way for anything.
 2.5.x: also very unlikely
 2.6: unlikely unless release is _soon_ (first alpha of 2.6 is out)

It won't be: tcl/tk development is quite slow. There have been several  
months between each 5 or 6 alpha release and between the last alpha and  
the beta. So don't expect the official release to come soon...

 3.0: much more likely, 3.0 won't be out for some time.

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


Load balancing and passing sockets; was: Re: Google and Python

2007-09-27 Thread Bryan Olson
Hendrik van Rooyen wrote:
 Nick Craig-Wood wrote: [about passing sockets between processes]
 It is trivial to pass a socket to a new thread or a forked child - you
 don't need this mechanism for that.  It doesn't work on different
 machines though - it has to be on the same machine.

 
 How does a very large volume site work then? - there must be some
 way of sharing the load without bottlenecking it through one machine?

Several ways. The Domain Name System can provide multiple IP
addresses for the same name. IP addresses often often lead
to HTTP reverse proxies that shoot back cached replies to
common simple requests, and forward the harder ones to the
file/application servers, with intelligent load balancing.

The services are surprisingly basic, and some excellent
software is free:

   http://en.wikipedia.org/wiki/Round_robin_DNS
   http://en.wikipedia.org/wiki/Reverse_proxy
   http://en.wikipedia.org/wiki/Squid_proxy


Web apps tend to scale just great, except when they need
data that is both shared and modifiable.


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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-27 Thread Duncan Booth
Mark Summerfield [EMAIL PROTECTED] wrote:

 As for the license, while it is on PyPI, I'll leave it as GPL v 3. If
 it was wanted for the standard library (and I can't see that ever
 happening), I will happily change it to the one that is preferred for
 Python modules.

Ok, your choice, just be aware that by using such a restrictive license you 
will dissuade a lot of people from using your code. You've prevented your 
module being used in any existing projects with Python license, GPL v2, or 
probably any license other than GPL v3.
-- 
http://mail.python.org/mailman/listinfo/python-list


No backend servers available using httplib

2007-09-27 Thread Henrik Lied
Hi there!

I'm using a recipe found on ASPN [1] to upload some data to an
external server.

The request fails, and all I get in response is No backend servers
available.

So I'm wondering: Is this a known exception-message in httplib, or
could it be an error in the requested external resource?

[1]: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306

-
Thanks,
Henrik

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


Re: Using closures and partial functions to eliminate redundant code

2007-09-27 Thread Bjoern Schliessmann
Matthew Wilson wrote:

 I'm interested to hear how other people deal with really similar
 code.
 The similarity just bugs me.  However, I wonder if using stuff
 like closures or partial function application is needlessly showy.

ACK -- but not because it's showy, but because it may be more
error-prone and less readable. I'd often use an approach like this:

def create_user(username, userpassword, useremail, create = False):

Send an email that will update a user in the remote system.
If create evaluates to True, don't update the user, but create
her instead.

if not create:
subject = UPDATE
else:
subject = CREATE

# Build email
email_body = 
USERNAME = %s
USERPASSWORD = %s
USEREMAIL = %s
 % (username, userpassword, useremail)
# send it.
send_email(subject=subject, body=email_body)

Regards,


Björn

-- 
BOFH excuse #353:

Second-system effect.

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


Re: sorteddict PEP proposal [started off as orderedict]

2007-09-27 Thread Paul Rubin
Duncan Booth [EMAIL PROTECTED] writes:
 Ok, your choice, just be aware that by using such a restrictive license you 
 will dissuade a lot of people from using your code. You've prevented your 
 module being used in any existing projects with Python license, GPL v2, or 
 probably any license other than GPL v3.

GPL2 projects seem to be migrating nicely to GPL3 so GPL2 shouldn't be
too much of a problem.  

Since one of the Python license's goals is to allow re-use in
proprietary programs, and the GPL family's main goal is the exact
opposite, I'd say if someone chooses a GPL, then preventing the code
from being used in a Python-licensed project was part of the intention
and not an undesired consequence.  While Python itself is unlikely to
switch to a new license in order to import GPL code, other projects
can and have done exactly that.
-- 
http://mail.python.org/mailman/listinfo/python-list


URGENT REQUIREMENT FOR PYTHON DEVELOPERS

2007-09-27 Thread kishore
HI 

 

THIS IS KRISHNA KISHORE FROM MindRiver. We have an Urgent requirement for
Python Developers who have 5-7 YRS of EXP.

 

 SKILLS  :PYTHON AND C/C++

 

   WORK LOCATION:  BANGALROE

 

 PLEASE REVERT US WITH YOUR UPDATED PROFILES.

 

Thanks  Regards,

Kishore Seethanraju |Senior Associate-People Consulting| MindRiver
Information Technologies Pvt. Ltd.
Suite# 512, 4th Floor and Suite # 104, Ground Floor ,Oxford Towers, 139,
Airport Road, Bangalore 560 008| Tel: +91.80.3052.1600 |Direct:
+91.80.3057.5799| Mobile: + 91.9901 96 1696 | Fax: +91.80.3057.5797| Email:
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]  | Web
www.mindriver-it.com http://www.mindriver-it.com/  

Information transmitted by this-mail is proprietary to MindRiver and / or
its Customers and is intended for use only by the individual or entity to
which it is addressed, and may contain information that is privileged,
confidential or exempt from disclosure under applicable law. If you are not
the intended recipient or it appears that this mail has been forwarded to
you without proper authority, you are notified that any use or dissemination
of this information in any manner is strictly prohibited. In such cases,
please notify us immediately at the above mentioned telephone number or
email to [EMAIL PROTECTED] and delete this mail from your records.
We believe this email to be virus free but do not warrant that this is the
case and we will not accept liability for any losses arising from any virus
being transmitted unintentionally by us'

 

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

Re: No backend servers available using httplib

2007-09-27 Thread Bruno Desthuilliers
Henrik Lied a écrit :
 Hi there!
 
 I'm using a recipe found on ASPN [1] to upload some data to an
 external server.
 
 The request fails, and all I get in response is No backend servers
 available.
 
 So I'm wondering: Is this a known exception-message in httplib,

If it was, you should have a full traceback then.

 or
 could it be an error in the requested external resource?


 [1]: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306

 From the recipe's code and the message, looks like you're connecting to 
(or via) a proxy which fails to relay to the real server.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comparing elements of a list with a string

2007-09-27 Thread Shriphani
Hello,
Would that mean that if I wanted to append all the (date, time) tuples
to a list, I should do something like:

for file in list_of_backup_files:
some_list.append(file)
By the way I did this:

def listAllbackups(filename):
list_of_backups = glob(home+'/Desktop/backupdir/*%s*'%filename)
for element in list_of_back:
if element.find(file) != -1:
date_components = element.split('-')[-4:-1]
date = str(date_components[0]) + : + 
str(date_components[1]) +
: + str(date_components[2])
time = element.split('-')[-1]
yield (date, time)
print listAllbackups('fstab')


I ran it in the terminal and I got:

generator object at 0x81ed58c

Why does it do that and not just print out all the values of (date,
time)
Regards,
Shriphani Palakodety

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


Re: Simple threading example freezes IDLE?

2007-09-27 Thread 7stud
On Sep 26, 5:01 pm, Sergio Correia [EMAIL PROTECTED] wrote:

 I'm using IDLE 1.2.1, Python 2.5.1, and Tk 8.4. Does anyone has any
 idea of why is this happening?


Two mainloops == bad.  IDLE == 1 mainloop.  your program == 1
mainloop.

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


Re: No backend servers available using httplib

2007-09-27 Thread Henrik Lied
On Sep 27, 11:56 am, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] wrote:
 Henrik Lied a écrit :

  Hi there!

  I'm using a recipe found on ASPN [1] to upload some data to an
  external server.

  The request fails, and all I get in response is No backend servers
  available.

  So I'm wondering: Is this a known exception-message in httplib,

 If it was, you should have a full traceback then.

  or
  could it be an error in the requested external resource?
  [1]:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306

  From the recipe's code and the message, looks like you're connecting to
 (or via) a proxy which fails to relay to the real server.

Hello Bruno,

The actual reason was quite a bit simpler: The receiving server
required a certain keyword to be first in the request - which I was
not aware of. So now it works - but it's not perfect:

Is there a way to stream the file content over the connection? The way
it works now, the whole file is loaded into memory, right?

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

mod_python preprocess/filter before proxy

2007-09-27 Thread David Sánchez Martín

Hi!

  I've seen the message below in this python list, that seems to be
unanswered.

  I'm trying to do the pretty same thing.

  There's a way to preprocess the request with a mod_python handler and then
proxying it with mod_proxy?

  Thank you very much in advance, and sorry for trying to revive such an old
message.

Cheers.



whale whale at mycameo.com
Tue Mar 25 05:49:42 CET 2003

I use Apache2.0.44 and mod_python3.0.1.
I add ProxyPass and PythonHandler directives in httpd.conf
## httpd.conf
ProxyPass  /test/  http://www.test.com
ProxyPassReverse  /test/   http://www.test.com
Location /
AddHandler python-program .htm .html
PythonHandler mptest
/Location


And mptest.py:
from mod_python import apache
def handler(req):
req.write('Hello!!')
return apache.OK

ex. My apache server is www.server.com.
When I browsed the local server request(ex.
http://www.server.com/1.html),
I received 'Hello!!' response, the python handler worked well.
But when I browse the proxy request(ex.
http://www.server.com/test/1.html),
the response I received is the original content of
http://www.test.com/1.html, not 'Hello!!'.
The proxy requests didn't seem to be processed by mod_python handler.
How could I pre-process the proxy request before mod_proxy module?
Thanks a lot!!




---
David Sanchez Martin
Administrador de Sistemas
[EMAIL PROTECTED]
GPG Key ID: 0x37E7AC1F

E2000 Nuevas Tecnologías
Tel : +34 902 19 61 77
BEGIN:VCARD
VERSION:2.1
N:Sánchez Martín;David
FN:David Sánchez Martín
ORG:E2000 Financial Investments, S.A.;Centro de Nuevas Tecnologías
TITLE:Administrador de Sistemas
TEL;WORK;VOICE:902196177
ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;Agust=EDn Bravo 17 2=BA B=0D=0A33120 PRAVIA
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:Agust=EDn Bravo 17 2=BA B=0D=0A33120 PRAVIA
KEY;X509;ENCODING=BASE64:
MIICfzCCAeigAwIBAgIQfDrYs+9nGg6LM+khzj6E1zANBgkqhkiG9w0BAQUFADBiMQswCQYD
VQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UE
AxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0EwHhcNMDcwMzI4MTI1NTM5
WhcNMDgwMzI3MTI1NTM5WjBqMRcwFQYDVQQEEw5TYW5jaGV6IE1hcnRpbjEOMAwGA1UEKhMF
RGF2aWQxHTAbBgNVBAMTFERhdmlkIFNhbmNoZXogTWFydGluMSAwHgYJKoZIhvcNAQkBFhFk
c2FuY2hlekBlMjAwMC5lczCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA6MRBLoMUDWpD
XBtkywilANAeIF+P9gh2FwtPdMAp/+2qWjDBAov+1jvyA8YZXeh3a9l4ZM0FZBjbkC7P9N7h
P+WMr4Apy98OXzH3qqDfYLFVmQo9vR54TZ4vznr9lunjJ/1NerbhYUsoWdzULd4xkTJnmJe0
W9HxlXn5oOdSpnUCAwEAAaMuMCwwHAYDVR0RBBUwE4ERZHNhbmNoZXpAZTIwMDAuZXMwDAYD
VR0TAQH/BAIwADANBgkqhkiG9w0BAQUFAAOBgQCeO2Yj6VRnski7dUJOH3n5I+ASe0zSUl31
RRmjgE39a0sUbC6o5PuIj05cb1klUnuiyIyzVF4FfF8prSORpBVjsMIy7vift/xwB6GBZLWz
JUc+JV5vvgMY2+SC+m+bWLJ575AOvpm8fjMQxdvMfMicElru94/k59b7Fm2Q5dMwqj==


EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20070924T113755Z
END:VCARD


smime.p7s
Description: S/MIME cryptographic signature
-- 
http://mail.python.org/mailman/listinfo/python-list

ANN: RuPy 2008 Python Ruby Conference

2007-09-27 Thread Jakub P. Nowak
RuPy 2008
Python  Ruby Conference

Poznan, Poland
April 12-13, 2008

-- Call for speakers

RuPy is a Ruby and Python conference. Held for the first time
in April 2007 it gathered enthusiasts from Poland and other
countries. The idea behind the conference was to liven up the
Ruby and Python community and make these technologies
more popular in Europe.

The first conference was a middle-sized one but came out as
a huge success. We believe it was a great experience for both
attendees and speakers.

RuPy 2008 committee is looking for speakers willing to present
a Ruby/Python related subject. If you have an interesting talk
in mind go ahead and submit a talk proposal. The talk proposal
should include a talk title, brief introduction and your short
resume/biography.

To our invited speakers we offer free accommodation, full
board and possibility to interact with a very lively IT community.
You are also free to participate in all the extra events -
last year's 'Geek party' turned out great!

You can also support us by linking to this site and informing
all your friends about the event and the possibility to submit
a talk proposal.

Potential presenters should submit an abstract to:

[EMAIL PROTECTED]

by December, 31th 2007 for consideration.

If you have any special presentation needs, let us know.

For more details check our site:
http://www.rupy.eu

Best regards,
--
Jakub P. Nowak
RuPy Committee

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


Re: Cross-platform time out decorator

2007-09-27 Thread Tim Golden
Joel wrote:
 I've been using this nice timing out decorator :
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307871 . The
 problem is that since it relies on sigalarm, it doesn't work under
 windows. Would anyone know how to do a cross-platform version?

I don't think you're going to find anything straightforward. AFAIK,
there's nothing on the Windows side of things which is directly
equivalent to the signals business in *nix. Sure, you can mess around
with timers and threads and events and so on. But it's far from being
the built-in tool which the signal module gives you.

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


Re: No backend servers available using httplib

2007-09-27 Thread Diez B. Roggisch
Henrik Lied wrote:

 On Sep 27, 11:56 am, Bruno Desthuilliers bruno.
 [EMAIL PROTECTED] wrote:
 Henrik Lied a écrit :

  Hi there!

  I'm using a recipe found on ASPN [1] to upload some data to an
  external server.

  The request fails, and all I get in response is No backend servers
  available.

  So I'm wondering: Is this a known exception-message in httplib,

 If it was, you should have a full traceback then.

  or
  could it be an error in the requested external resource?
  [1]:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306

  From the recipe's code and the message, looks like you're connecting to
 (or via) a proxy which fails to relay to the real server.
 
 Hello Bruno,
 
 The actual reason was quite a bit simpler: The receiving server
 required a certain keyword to be first in the request - which I was
 not aware of. So now it works - but it's not perfect:
 
 Is there a way to stream the file content over the connection? The way
 it works now, the whole file is loaded into memory, right?

It appears not, as the httplib uses sendall on the underlying socket.

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

Re: URGENT REQUIREMENT FOR PYTHON DEVELOPERS

2007-09-27 Thread Steve Holden
Krishna:

You might want to consider reading

   http://www.python.org/community/jobs/howto/

and submitting these jobs to the Job Board. It's free.

regards
  Steve

[EMAIL PROTECTED] wrote:
 HI
 
  
 
 THIS IS KRISHNA KISHORE FROM MindRiver. We have an Urgent requirement 
 for Python Developers who have 5-7 YRS of EXP.
 
  
 
  SKILLS  :PYTHON AND C/C++
 
  
 
WORK LOCATION:  BANGALROE
 
  
 
  PLEASE REVERT US WITH YOUR UPDATED PROFILES.
 
  
 
 Thanks  Regards,
 
 Kishore Seethanraju |Senior Associate-People Consulting| MindRiver 
 Information Technologies Pvt. Ltd.
 Suite# 512, 4th Floor and Suite # 104, Ground Floor ,Oxford Towers, 139, 
 Airport Road, Bangalore 560 008| Tel: +91.80.3052.1600 |Direct: 
 +91.80.3057.5799| Mobile: + 91.9901 96 1696 | Fax: +91.80.3057.5797| 
 Email: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] | Web 
 www.mindriver-it.com http://www.mindriver-it.com/
 
 Information transmitted by this-mail is proprietary to MindRiver and / 
 or its Customers and is intended for use only by the individual or 
 entity to which it is addressed, and may contain information that is 
 privileged, confidential or exempt from disclosure under applicable law. 
 If you are not the intended recipient or it appears that this mail has 
 been forwarded to you without proper authority, you are notified that 
 any use or dissemination of this information in any manner is strictly 
 prohibited. In such cases, please notify us immediately at the above 
 mentioned telephone number or email to [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] and delete this mail from your 
 records. We believe this email to be virus free but do not warrant that 
 this is the case and we will not accept liability for any losses arising 
 from any virus being transmitted unintentionally by us'
 
  
 


-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comparing elements of a list with a string

2007-09-27 Thread Steve Holden
Shriphani wrote:
 Hello,
 Would that mean that if I wanted to append all the (date, time) tuples
 to a list, I should do something like:
 
 for file in list_of_backup_files:
 some_list.append(file)

That would be one way to do it (assuming you started with some_list as 
an empty list). But a faster way would be to use a list comprehension 
and say

some_list = [f for f in list_of_backup_files]

 By the way I did this:
 
 def listAllbackups(filename):
   list_of_backups = glob(home+'/Desktop/backupdir/*%s*'%filename)
   for element in list_of_back:
   if element.find(file) != -1:
   date_components = element.split('-')[-4:-1]
   date = str(date_components[0]) + : + 
 str(date_components[1]) +
 : + str(date_components[2])
   time = element.split('-')[-1]
   yield (date, time)
 print listAllbackups('fstab')
 
 
 I ran it in the terminal and I got:
 
 generator object at 0x81ed58c
 
 Why does it do that and not just print out all the values of (date,
 time)

Because the generator object returned by the function has to be used in 
an iterative context to produce its values. Which is why the list 
comprehension produces a list!

If you don't really want a generator then you could just rewrite the 
function to return a list in the first place. You did specifically ask 
how do I use the yield statement  If you are going to iterate o 
ver the list then a generator is typically more memory-efficient 
(because it only produces one element at a time), and can do things that 
a list can't (like deal with a potentially infinite sequence of results).

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Re: sorteddict [was a PEP proposal, but isn't anymore!]

2007-09-27 Thread gatti
I don't see a focused discussion of computational complexity of a
sorted dict; its API cannot be simpler than sorting a dictionary and
it has issues and complications that have already been discussed
without completely satisfactory solutions, so the only possible reason
to adopt a sorted dict is that some important use case for mapping
types becomes significantly cheaper.

With n entries, the size of a non-sorted hashtable, of a hashtable
plus lists or sets of keys, and of reasonable sorted dict
implementations with trees are all O(n). No substantial space
advantage can be obtained by sorting dictionaries.

Iterating through all n entries of a mapping, once, in sorted order,
is O(n) time and O(1) space with an unsorted hash table, a hash table
with a sorted list of the keys and all  types of tree that I know of.
If there is a performance gain, it must come from amortizing
insertions, deletions and index-building. (The other operation, value
updates for an existing key, doesn't matter: updates cause no
structural changes and they must not invalidate any iterator.)

Let's consider a very simple use case: n insertions followed by x
iterations through all entries and n*y lookups by key.

Cost for a hashtable and an ad hoc sorted list of the keys,
fundamentally equivalent to sorting a Python dict:

O(n) for insertions
O(n log n) for indexing
O(nx) for iterations
O(ny) for lookups

Cost for a tree:

O(n log n) for insertions
no indexing
O(nx) for iterations
O(ny log n) for lookups

The hashtable comes out ahead because of cheaper lookups, for any x
and y; note that without lookups there is no reason to use a mapping
instead of a list of (key,value) tuples.

With an equal number k of insertions and deletions between the
iterations, the hashtable must be reindexed x times:

O(n) for insertions
O(kx) for updates and deletions
O(nx log n) for indexing and reindexing
O(nx) for iterations
O(ny) for lookups

The tree might be cheaper:

O(n log n) for insertions
O(kx log n) for updates and deletions
no indexing and reindexing
O(nx) for iterations
O(ny log n) for lookups

For a fixed small k, or with k proportional to n, reindexing the
hashtable and lookups in the tree are equally mediocre.

Maybe we could make k changes in the middle of each iteration. For a
naively reindexed hashtable:

O(n) for insertions
O(kx) for updates and deletions
O(knx log n) for indexing and reindexing
O(nx) for iterations
O(ny) for lookups

For a tree, the costs remain as above: the new factor of n for the
hashtable is fatal. Clever updates of the existing index or use of a
heap would lower the cost, but they would need to be encapsulated as a
sorteddict implementation.

Is this a practical use case? When are sequential visits of all
elements in order frequently suspended to make insertions and
deletions, with a need for efficient lookup by key?
- Priority queues; but given the peculiar pattern of insertions and
deletions there are more suitable specialized data structures.
- A* and similar best-first algorithms.
It's a small but important niche; maybe it isn't important enough for
the standard library. Other absent datatypes like heaps, an immutable
mapping type similar to frozenset and tuple, or disjoint sets with
would be more fundamental and general, and a mapping that remembers
the order of insertion regardless of keys would be equally useful.
In the Java collections framework all these kinds of mapping and
others coexist peacefully, but Python doesn't have the same kitchen
sink approach to basic libraries.

Regarding the API, a sorted dict should not expose random access by an
entry's position in the sequence: it is a gratuitous difficulty for
the implementor and, more importantly, a perversion of the mapping
data type. For that purpose there are lists and tuples, or explicit
indices like those of the Boost multi-index containers (http://
www.boost.org/libs/multi_index).
The only differences with dict should be the constraint that items(),
keys(), values(), iteritems(), iterkeys(), itervalues() return entries
sorted by key.

Regards,

Lorenzo Gatti

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


Confusion regarding constructor as default value

2007-09-27 Thread aine_canby
Why are the following different?

def AddRow(self, rowName, tableRow=TableRow(ReleaseDate(),
ExpiryDate())):
# check to see if the row already exists, if not add it to the
container

if not self.dict.has_key(rowName):
self.dict[rowName] = tableRow

def AddRow(self, rowName, tableRow):
# check to see if the row already exists, if not add it to the
container

if not self.dict.has_key(rowName):
self.dict[rowName] = TableRow(ReleaseDate(), 
ExpiryDate())

It seems that when I use the first function that I'm getting duplicate
objects in self.dict

Thanks for your help,

Aine.

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


Mysqldb stderr

2007-09-27 Thread mastro . francesco
developing a daemon (using python 2.4 and mysqldb 1.2.1_p2) we notes
that mysqldb class write on stderr some warnings and error
asyncronously (uhmmm it's good written? ;P ).
If stderr is closed these function raise up an I/O error (obviously).
We spent a lot of time to understand
for now we redirected stderr on /dev/null, but.. it's a workaround.

Someone knows how stop write on stderr (and stdout) on mysqldb?


Thanks.

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


Launching command on windows

2007-09-27 Thread Alexandre Badez
Hy,

I'm working on windows and I try to do something like:

import os
APP = os.path.abspath(C:\\Program Files\\Notepad++\\notepad++.exe)
FILE1 = os.path.abspath(D:\\Documents and settings\\test1.py)
FILE2 = os.path.abspath(D:\\Documents and settings\\test2.py)
command = '%(app)s %(file1)s %(file2)s' % {
'app' : APP,
'file1' : FILE1,
'file2' : FILE2}
# === FOR 'DEBUG' ===
print APP
print FILE1
print FILE2
print command
print repr(command)
# === END FOR 'DEBUG' ===
os.system(command)


This code give in output:
C:\Program Files\Notepad++\notepad++.exe
D:\Documents and settings\test1.py
D:\Documents and settings\test2.py
C:\Program Files\Notepad++\notepad++.exe D:\Documents and settings
\test1.py D:\Documents and settings\test2.py
'C:\\Program Files\\Notepad++\\notepad++.exe D:\\Documents and
settings\\test1.py D:\\Documents and settings\\test2.py'

'C:\Program' n'est pas reconnu en tant que commande interne
ou externe, un programme ex,cutable ou un fichier de commandes.
# = My windows is a french one
# This error message could be translated as:
# 'c:\Program' is not an internal nor external command, an executable
program nor a command file

But if I copy the command in the output, an paste it in a console, it
work very well.
Does any of you know what I can do ?

PS: I think I'm oblige to add  neer every path for spaces in path,
but if you know an other way, it could be cool :)

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


Re: What is a good way of having several versions of a python module installed in parallell?

2007-09-27 Thread Neil Cerutti
On 2007-09-25, Joel Hedlund [EMAIL PROTECTED] wrote:
 First of all, thanks for all the input - it's appreciated.

 Otherwise, three words:
 
   test driven development

 Do you also do this for all the little stuff, the small hacks
 you just whip together to get a particular task done? My
 impression is that doing proper unittests adds a lot of time to
 development, and I'm thinking that this may be a low return
 investment for the small programs.

For documentating and testing small hacks, try the doctest
module. It integrates with Python's unit testing modules, so if
you need to graduate, it is simple to do so.

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


Re: Cross-platform time out decorator

2007-09-27 Thread kyosohma
On Sep 26, 5:21 am, Joel [EMAIL PROTECTED] wrote:
 I've been using this nice timing out decorator 
 :http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307871. The
 problem is that since it relies on sigalarm, it doesn't work under
 windows. Would anyone know how to do a cross-platform version?

 Thanks a lot!

 joel

You might be able to use the timeit module.

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

Some people like to use hotshot:

http://www.onlamp.com/pub/a/python/2005/12/15/profiling.html

I doubt this is what you're looking for, but maybe it'll give you a
push in the right direction.

Mike

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


Re: Cross-platform time out decorator

2007-09-27 Thread Joel
On Sep 26, 12:21 pm, Joel [EMAIL PROTECTED] wrote:
 I've been using this nice timing out decorator 
 :http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307871. The
 problem is that since it relies on sigalarm, it doesn't work under
 windows. Would anyone know how to do a cross-platform version?

 Thanks a lot!

 joel

I found the solution : 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440569
describes a solution based on threads. I tested it and it works
perfectly.

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


Re: Confusion regarding constructor as default value

2007-09-27 Thread Diez B. Roggisch
 [EMAIL PROTECTED] wrote:

 Why are the following different?
 
 def AddRow(self, rowName, tableRow=TableRow(ReleaseDate(),
 ExpiryDate())):
 # check to see if the row already exists, if not add it to the
 container
 
 if not self.dict.has_key(rowName):
 self.dict[rowName] = tableRow
 
 def AddRow(self, rowName, tableRow):
 # check to see if the row already exists, if not add it to the
 container
 
 if not self.dict.has_key(rowName):
 self.dict[rowName] = TableRow(ReleaseDate(), ExpiryDate())
 
 It seems that when I use the first function that I'm getting duplicate
 objects in self.dict
 
 Thanks for your help,

It's a FAQ. 

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

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


Re: Confusion regarding constructor as default value

2007-09-27 Thread aine_canby
On 27 Sep, 15:03, [EMAIL PROTECTED] wrote:
 Why are the following different?

 def AddRow(self, rowName, tableRow=TableRow(ReleaseDate(),
 ExpiryDate())):
 # check to see if the row already exists, if not add it to the
 container

 if not self.dict.has_key(rowName):
 self.dict[rowName] = tableRow

 def AddRow(self, rowName, tableRow):
 # check to see if the row already exists, if not add it to the
 container

 if not self.dict.has_key(rowName):
 self.dict[rowName] = TableRow(ReleaseDate(), 
 ExpiryDate())

 It seems that when I use the first function that I'm getting duplicate
 objects in self.dict

 Thanks for your help,

 Aine.

I've just tried the following:

Function A:

def AddRow(self, rowName, tableRow=TableRow(ReleaseDate(),
ExpiryDate())):

print tableRow
if not self.dict.has_key(rowName):
self.dict[rowName] = tableRow

Function B:

def AddRow(self, rowName, tableRow=None):

if tableRow==None:
tableRow = TableRow(ReleaseDate(), ExpiryDate())
# check to see if the row already exists, if not add it to the
container
print tableRow
if not self.dict.has_key(rowName):
self.dict[rowName] = tableRow

Function A is giving:

DatabaseExamination.TableRow instance at 0x011D4468
DatabaseExamination.TableRow instance at 0x011D42B0 same!
DatabaseExamination.TableRow instance at 0x011D42B0 same!
DatabaseExamination.TableRow instance at 0x011D42B0 same!
DatabaseExamination.TableRow instance at 0x011D42B0 same!

Function B is giving:

DatabaseExamination.TableRow instance at 0x011D0670
DatabaseExamination.TableRow instance at 0x011D0760
DatabaseExamination.TableRow instance at 0x011D07D8
DatabaseExamination.TableRow instance at 0x011D0850


So at least I know know what is causing the problem. But I'm still not
understanding why I can't use TableRow() as the default value in order
to geterate new instances.

How would you implement this?

Thanks,

Aine.

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


Re: Confusion regarding constructor as default value

2007-09-27 Thread aine_canby
On 27 Sep, 15:34, Diez B. Roggisch [EMAIL PROTECTED] wrote:
  [EMAIL PROTECTED] wrote:
  Why are the following different?

  def AddRow(self, rowName, tableRow=TableRow(ReleaseDate(),
  ExpiryDate())):
  # check to see if the row already exists, if not add it to the
  container

  if not self.dict.has_key(rowName):
  self.dict[rowName] = tableRow

  def AddRow(self, rowName, tableRow):
  # check to see if the row already exists, if not add it to the
  container

  if not self.dict.has_key(rowName):
  self.dict[rowName] = TableRow(ReleaseDate(), ExpiryDate())

  It seems that when I use the first function that I'm getting duplicate
  objects in self.dict

  Thanks for your help,

 It's a FAQ.

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

 Diez- Dölj citerad text -

 - Visa citerad text -

Cool, I understand now. It was my understanding of how Python works
that was at fault.

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

Translating Event.time from pyhook

2007-09-27 Thread randy . tucker7
I use pyhook to monitor user usage of keyboard and mouse. According to
pyhook specs, event.time hold the number of seconds since the epoch.
However, when I use the example source code I get numbers like
358054093, which translates to 07 May 1981..

Can anyone explain to me what am I doing wrong?

Thanks.

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


PyObject_CallObject: difference between functions and class methods

2007-09-27 Thread mauro
Hi all!

I am trying to call within a C extension a Python function provided as
an argument by the user with: PyObject_Call(). The C extension should
work also if the user supplies a class method, but in this case I am
getting an error. Do I need to explicitly pass 'self' as an argument
to PyObject_Call()? If so, how can I do that?

Now, I am using:

if ((tmp_args = PyTuple_New(1)) == NULL)
PyErr_SetString( PyExc_ReferenceError, attempt to access a 
null-
pointer );
PyTuple_SetItem(tmp_args, 0, paramlist);

to create the tuple required by PyObject_Call(), but I have no idea on
how to add a reference to 'self'.

Here is what I would like to obtain:

##
import mymodule

def myfunc(x):
# Do something
return [z]

class MyClass:
def mymethod(self, x):
# Do something
return z
def runme(self):
mymodule.main(myfunc) # This will work
mymodule.main(self.mymethod) # This will not work (Segmentation
fault)

x = MyClass()
x.runme()
##

Thanks in advance.

Mauro

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


Emailing the attachment created with the Quick Screenshots Script (Python + PIL)

2007-09-27 Thread Mark Bratcher
The Quick Screenshots Script (Python + PIL) is a dream come true, and yet
so simple to use reliably.  Does anyone have a suggestion or know how to
include in the script, the ability to email the attachment?  This would make
the dream perfect!  Thanks!

 

Mark Bratcher

Consolidated Citrus, LP

4210-250 Metro, Parkway

Fort Myers, FL  33916

239-275-4060 ext 219

 

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

making run time changes..

2007-09-27 Thread Piyush Jain
Hi,

I am new(almost) to python. I wish to making a server in which I can make
changes at run time. For example , add a method to a class/attribute to
object etc. by sending it messages. 

Can anyone help me with what features to look into and how to go about it.
Are there any similar projects?

 

Regards,

Piyush

 

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

Re: Launching command on windows

2007-09-27 Thread mauro
On 27 Set, 15:17, Alexandre Badez [EMAIL PROTECTED] wrote:
 Hy,

 I'm working on windows and I try to do something like:

 import os
 APP = os.path.abspath(C:\\Program Files\\Notepad++\\notepad++.exe)
 FILE1 = os.path.abspath(D:\\Documents and settings\\test1.py)
 FILE2 = os.path.abspath(D:\\Documents and settings\\test2.py)
 command = '%(app)s %(file1)s %(file2)s' % {
 'app' : APP,
 'file1' : FILE1,
 'file2' : FILE2}
 # === FOR 'DEBUG' ===
 print APP
 print FILE1
 print FILE2
 print command
 print repr(command)
 # === END FOR 'DEBUG' ===
 os.system(command)

 This code give in output:
 C:\Program Files\Notepad++\notepad++.exe
 D:\Documents and settings\test1.py
 D:\Documents and settings\test2.py
 C:\Program Files\Notepad++\notepad++.exe D:\Documents and settings
 \test1.py D:\Documents and settings\test2.py
 'C:\\Program Files\\Notepad++\\notepad++.exe D:\\Documents and
 settings\\test1.py D:\\Documents and settings\\test2.py'

 'C:\Program' n'est pas reconnu en tant que commande interne
 ou externe, un programme ex,cutable ou un fichier de commandes.
 # = My windows is a french one
 # This error message could be translated as:
 # 'c:\Program' is not an internal nor external command, an executable
 program nor a command file

 But if I copy the command in the output, an paste it in a console, it
 work very well.
 Does any of you know what I can do ?

 PS: I think I'm oblige to add  neer every path for spaces in path,
 but if you know an other way, it could be cool :)

If you don't mind using spawnl instead of system, this should work
even with spaces:
os.spawnl(os.P_NOWAITO, command)
I hope it helps.

Mauro

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


Re: Launching command on windows

2007-09-27 Thread kyosohma
On Sep 27, 8:17 am, Alexandre Badez [EMAIL PROTECTED] wrote:
 Hy,

 I'm working on windows and I try to do something like:

 import os
 APP = os.path.abspath(C:\\Program Files\\Notepad++\\notepad++.exe)
 FILE1 = os.path.abspath(D:\\Documents and settings\\test1.py)
 FILE2 = os.path.abspath(D:\\Documents and settings\\test2.py)
 command = '%(app)s %(file1)s %(file2)s' % {
 'app' : APP,
 'file1' : FILE1,
 'file2' : FILE2}
 # === FOR 'DEBUG' ===
 print APP
 print FILE1
 print FILE2
 print command
 print repr(command)
 # === END FOR 'DEBUG' ===
 os.system(command)

 This code give in output:
 C:\Program Files\Notepad++\notepad++.exe
 D:\Documents and settings\test1.py
 D:\Documents and settings\test2.py
 C:\Program Files\Notepad++\notepad++.exe D:\Documents and settings
 \test1.py D:\Documents and settings\test2.py
 'C:\\Program Files\\Notepad++\\notepad++.exe D:\\Documents and
 settings\\test1.py D:\\Documents and settings\\test2.py'

 'C:\Program' n'est pas reconnu en tant que commande interne
 ou externe, un programme ex,cutable ou un fichier de commandes.
 # = My windows is a french one
 # This error message could be translated as:
 # 'c:\Program' is not an internal nor external command, an executable
 program nor a command file

 But if I copy the command in the output, an paste it in a console, it
 work very well.
 Does any of you know what I can do ?

 PS: I think I'm oblige to add  neer every path for spaces in path,
 but if you know an other way, it could be cool :)



I got it to work using subprocess.Popen

Not sure why it doesn't work with os.system though.

Mike

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


Re: Tkinter / Tk 8.5

2007-09-27 Thread Kevin Walzer
Michal Bozon wrote:
 Today has been released a first beta of Tk 8.5, including a Ttk
 (tile) style engine, which makes possible the native look
 of widgets on MS
 platform, without having to install any extension.
 
 http://wiki.tcl.tk/11075
 http://sourceforge.net/mailarchive/message.php?msg_name=1190813039.46fa5d6f6a06b%40webmail.nist.gov
 
 Is there a chance it will be included in 2.5.x, 2.6 or 3.0 ?
 
  -m.

Did you know that a wrapper for use with Tk 8.4.x is located here?

http://tkinter.unpythonic.net/wiki/TileWrapper

This does require a separate installation of the Tile libraries, but 
those can be obtained from ActiveState.

I use this wrapper myself on OS X with a commercial application I 
develop, and Tile makes a big difference.

(I maintain and update this wrapper at the wiki, but am not the original 
author.)

--Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter / Tk 8.5

2007-09-27 Thread Kevin Walzer
Eric Brunel wrote:
 On Thu, 27 Sep 2007 04:41:48 +0200, Scott David Daniels 
 [EMAIL PROTECTED] wrote:
 
 Michal Bozon wrote:
 Today has been released a first beta of Tk 8.5, including a Ttk
 (tile) style engine, which makes possible the native look
 of widgets on MS platform, without having to install any extension.
  Is there a chance it will be included in 2.5.x, 2.6 or 3.0 ?

 This is just a guess, but:
 The beta: no way for anything.
 2.5.x: also very unlikely
 2.6: unlikely unless release is _soon_ (first alpha of 2.6 is out)
 
 It won't be: tcl/tk development is quite slow. There have been several 
 months between each 5 or 6 alpha release and between the last alpha and 
 the beta. So don't expect the official release to come soon...
 
 3.0: much more likely, 3.0 won't be out for some time.
 
 This would be my guess too...

I'd say that Tk 8.5 will be out before Python 3.0: the beta phase should 
be fairly efficient on Tk.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyObject_CallObject: difference between functions and class methods

2007-09-27 Thread Hrvoje Niksic
[ Note that there is now a mailing list dedicated to the C API:
http://mail.python.org/mailman/listinfo/capi-sig ]

mauro [EMAIL PROTECTED] writes:

 I am trying to call within a C extension a Python function provided as
 an argument by the user with: PyObject_Call(). The C extension should
 work also if the user supplies a class method, but in this case I am
 getting an error. Do I need to explicitly pass 'self' as an argument
 to PyObject_Call()?

You don't.  The reference to self will be added automatically when
invoking the function you receive as object.method.

 if ((tmp_args = PyTuple_New(1)) == NULL)
   PyErr_SetString( PyExc_ReferenceError, attempt to access a 
 null-
 pointer );
 PyTuple_SetItem(tmp_args, 0, paramlist);

Maybe you are mismanaging the reference count -- PyTuple_SetItem
steals the refcount of its argument.  Anyway, why not use
PyObject_CallFunction or PyObject_CallFunctionObjArgs?  For example:

PyObject *
mymodule_main(PyObject *ignored, PyObject *func)
{
  PyObject *result, *my_param;
  /* ... do something, e.g. create my_param ... */

  /* call func */
  result = PyObject_CallFunction(received_func, O, my_param);
  Py_DECREF(my_param);  /* assuming you no longer need it */
  if (!result)
return NULL;

  /* ... do something with result ... */

  Py_DECREF(result);
  Py_INCREF(Py_None);
  return Py_None;  /* or whatever */
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setuptools without unexpected downloads

2007-09-27 Thread kyosohma
On Sep 26, 5:52 pm, Steve Holden [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  On Sep 26, 8:30 am, Steve Holden [EMAIL PROTECTED] wrote:
  Fredrik Lundh wrote:
  Paul Boddie wrote:
  P.S. Of course, the package maintainer problem manifests itself most
  prominently on Windows where you often see people asking for pre-built
  packages or installers.
  for the record, I'd love to see a group of volunteers doing stuff like
  this for Windows.  there are plenty of volunteers that cover all major
  Linux/*BSD distributions (tons of thanks to everyone involved in this!),
  but as far as I can remember, nobody has ever volunteered to do the same
  for Windows.
  I'd like to see something like this happen, too, and if a group of
  volunteers emerges I'll do what I can through the PSF to provide
  resources. Activities that benefit the whole community (or a large part
  of it) are, IMHO, well worth supporting.

  What would it entail to do this? Using py2exe + some installer (like
  Inno Setup) to create an installer that basically copies/installs the
  files into the site-packages folder or wherever the user chooses? If
  that's all it is, I would think it would be fairly easy to create
  these. Maybe I'm over-simplifying it though.

  What are a some examples of packages that need this?

 MySQLdb and psycopg are two obvious examples I have had to grub around
 or produce my own installers for. There's generally some configuration
 work to do for packages that have been produced without considering
 Windows requirements, and ideally this will be fed back to the developers.

 I think you may be oversimplifying a little. Pure Python packages aren't
 too problematic, it's mostly the extension modules. Unless a copy of
 Visual Studio is available (and we *might* get some cooperation from
 Microsoft there) that means resorting to MingW, which isn't an easy
 environment to play with (in my occasional experience, anyway).

 There's going to be increasing demand for 64-bit implementations too.

 regards
   Steve
 --
 Steve Holden+1 571 484 6266   +1 800 494 3119
 Holden Web LLC/Ltd  http://www.holdenweb.com
 Skype: holdenweb  http://del.icio.us/steve.holden

 Sorry, the dog ate my .sigline

Steve,

We have Visual Studio 2005 at work and my boss is a Python nut, so I
could probably use it. I also have academic versions of VS 6 and 2003
(maybe 2005 too...I forget, it might be 2004) at home as well...I
think I can use those for open source development, although knowing
Microsoft, there's probably something draconian hiding in the EULA
somewhere.

If someone is willing to give me some guidance, I'll give it a try.

Mike

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


Re: Confusion regarding constructor as default value

2007-09-27 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 On 27 Sep, 15:03, [EMAIL PROTECTED] wrote:
 Why are the following different?

 def AddRow(self, rowName, tableRow=TableRow(ReleaseDate(),
 ExpiryDate())):
 # check to see if the row already exists, if not add it to 
 the
 container

 if not self.dict.has_key(rowName):
 self.dict[rowName] = tableRow

 def AddRow(self, rowName, tableRow):
 # check to see if the row already exists, if not add it to 
 the
 container

 if not self.dict.has_key(rowName):
 self.dict[rowName] = TableRow(ReleaseDate(), 
 ExpiryDate())

 It seems that when I use the first function that I'm getting duplicate
 objects in self.dict

 Thanks for your help,

 Aine.
 
 I've just tried the following:
 
 Function A:
 
 def AddRow(self, rowName, tableRow=TableRow(ReleaseDate(),
 ExpiryDate())):
 
 print tableRow
 if not self.dict.has_key(rowName):
 self.dict[rowName] = tableRow
 
 Function B:
 
 def AddRow(self, rowName, tableRow=None):
 
 if tableRow==None:
   tableRow = TableRow(ReleaseDate(), ExpiryDate())
 # check to see if the row already exists, if not add it to the
 container
 print tableRow
 if not self.dict.has_key(rowName):
 self.dict[rowName] = tableRow
 
 Function A is giving:
 
 DatabaseExamination.TableRow instance at 0x011D4468
 DatabaseExamination.TableRow instance at 0x011D42B0 same!
 DatabaseExamination.TableRow instance at 0x011D42B0 same!
 DatabaseExamination.TableRow instance at 0x011D42B0 same!
 DatabaseExamination.TableRow instance at 0x011D42B0 same!
 
 Function B is giving:
 
 DatabaseExamination.TableRow instance at 0x011D0670
 DatabaseExamination.TableRow instance at 0x011D0760
 DatabaseExamination.TableRow instance at 0x011D07D8
 DatabaseExamination.TableRow instance at 0x011D0850
 
 
 So at least I know know what is causing the problem. But I'm still not
 understanding why I can't use TableRow() as the default value in order
 to geterate new instances.
 
Because the value of the default is computed as the funciton declaration 
is processed, whereas you seem to expect to see a new call to ExpiryDate 
each time the function is called.

 How would you implement this?
 
 Thanks,
 
 Aine.
 
Function B is the canonical solution to this problem.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Getting web page throught a proxy (squid)

2007-09-27 Thread Vincent Sabard
salut jean-paul,

comment vas-tu ?

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

Re: Cross-platform time out decorator

2007-09-27 Thread Hrvoje Niksic
Joel [EMAIL PROTECTED] writes:

 I found the solution :
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440569
 describes a solution based on threads. I tested it and it works
 perfectly.

Note that, unlike the original alarm code, it doesn't really interrupt
the timed-out method, it just returns the control back to the caller,
using an exception to mark that a timeout occurred.  The timed out
code is still merrily running in the background.  I don't know if it's
a problem in your case, but it's an important drawback.
-- 
http://mail.python.org/mailman/listinfo/python-list


os.removedirs - How to force this delete?

2007-09-27 Thread cstewart913
I've been searching to find a way to force this delete to work even if
the directory isn't empty.  I've had no luck thus far.  Anyone know
what that would be?

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


Re: Google and Python

2007-09-27 Thread asdfjehqwjerhqjwljekrh
On Sep 24, 10:40 am, [EMAIL PROTECTED] (Alex Martelli) wrote:
  Good motto. So is most of Google's code base now in
  Python? About what is the ratio of Python code to C++
  code? Of course lines of code is kine of a bogus measure.
  Of all those cycles Google executes, about what portion
  are executed by a Python interpreter?

 I don't have those numbers at hand, and if I did they would be
 confidential

I would be curious to know whether they code much mixed model
coding.  By that I mean (a) code your application in Python, and then
(b) optimize it as necessary by moving some functionality into Python
C/C++ modules.  (Some of (b) may happen during design, of course.)

I think of this as the state of the art in programming practice, and I
wonder whether Google's doing this, or has a superior alternative.

Mike

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


Re: How do I get the value out of a DOM Element

2007-09-27 Thread kj7ny
Forgot to mention I'm using Python 2.4.3.

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


Pb with an AttributeError

2007-09-27 Thread Eric BOUVIER

Hello,

First, sorry for my english.

I've just been assigned a project written in Python which contains
bug(s).
I've never programmed in Python, but I've read the code  
and understood basically what the different source codes do.

I've traced the code and found where the problem is but I don't 
know how to solve the problem.

Here it is :

I've got a string issued from a CSV file : 
   string1 = eval(line[4])
   print  * string1 = (, string1 ,) \n  
=  * string1 = ( {'header': 'X-Score', 'param': {'key':
'SP136=', 'value': ['SD:0 ']} )

Then, there is a split with the equal : 
   TheParts = string.split(string1[param], =)
   print  * TheParts = (, TheParts ,) \n

But, running the program returns : 

Traceback (most recent call last):
  File C:\test\helper.py, line 136, in Action_handler
Score_eval(line, OutputFile_SP, This_Host)
  File C:\test\helper.py, line 66, in Score_eval
TheParts = string.split(string1[param], =)
  File C:\ActiveState\Python25\lib\string.py, line 290, in split
return s.split(sep, maxsplit)
AttributeError: 'dict' object has no attribute 'split'  !?!

I've found that it works when I put directly the string in the split
expression : 

   TheParts = string.split( {'key': 'ESP136=', 'value': ['SHA:0 ']}
, =)
  = * TheParts =   [{'key': 'ESP136, ', 'value': ['SHA:0
']}]

  But the code isn't dynamic anymore !
I think it's a problem with the type, but the different syntax I've
tried didn't work.
Is somebody could help me ?

 Thank you

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

Re: Cross-platform time out decorator

2007-09-27 Thread Joel
On Sep 27, 4:36 pm, Hrvoje Niksic [EMAIL PROTECTED] wrote:
 Joel [EMAIL PROTECTED] writes:
  I found the solution :
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440569
  describes a solution based on threads. I tested it and it works
  perfectly.

 Note that, unlike the original alarm code, it doesn't really interrupt
 the timed-out method, it just returns the control back to the caller,
 using an exception to mark that a timeout occurred.  The timed out
 code is still merrily running in the background.  I don't know if it's
 a problem in your case, but it's an important drawback.

There should be a method to stop the thread though? I've never
programmed thread stuff in python and wasn't able to find how to do
it, would you happen to know how to kill the timed out thread?

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


Re: making run time changes..

2007-09-27 Thread Steve Holden
Piyush Jain wrote:
 Hi,
 
 I am new(almost) to python. I wish to making a server in which I can 
 make changes at run time. For example , add a method to a 
 class/attribute to object etc. by sending it messages.
 
 Can anyone help me with what features to look into and how to go about 
 it. Are there any similar projects?
 
Take a look at Pyro (Python remote objects). It can almost certainly do 
what you want.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Traveling Europe

2007-09-27 Thread freeaircon
World's most popular traveling destinations

http://world-traveling-destinations.blogspot.com/

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


Re: setuptools without unexpected downloads

2007-09-27 Thread Istvan Albert
On Sep 26, 2:09 am, Ben Finney [EMAIL PROTECTED] wrote:

 behaviour with a specific invocation of 'setup.py'. But how can I
 disallow this from within the 'setup.py' program, so my users don't
 have to be aware of this unexpected default behaviour?

I don't have the answer for this, but I can tell you that I myself
dislike the auto-download behavior and I wish it worked differently.

I've given up on setuptools/easy-install altogether. It is most
annoying to end up with half a dozen unexpected packages.

The default behavior should be to pop a question with a list of
packages that will be downloaded (and have a flag that bypasses this).
And of course being able to turn off this feature from setup.py.

i.










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


Re: Launching command on windows

2007-09-27 Thread Alexandre Badez
On Sep 27, 4:20 pm, [EMAIL PROTECTED] wrote:

 I got it to work using subprocess.Popen

 Not sure why it doesn't work with os.system though.

 Mike

Thanks Mike and Mauro,

Mauro, your solution do not seems to work (or I made a mistake..)
Mike your solution work great, thanks.
But, I steel think it's a bug (python or window ??).
I will try to take a look about it, when I have time.

Alex

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


Re: setuptools without unexpected downloads

2007-09-27 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 On Sep 26, 5:52 pm, Steve Holden [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
 On Sep 26, 8:30 am, Steve Holden [EMAIL PROTECTED] wrote:
 Fredrik Lundh wrote:
 Paul Boddie wrote:
 P.S. Of course, the package maintainer problem manifests itself most
 prominently on Windows where you often see people asking for pre-built
 packages or installers.
 for the record, I'd love to see a group of volunteers doing stuff like
 this for Windows.  there are plenty of volunteers that cover all major
 Linux/*BSD distributions (tons of thanks to everyone involved in this!),
 but as far as I can remember, nobody has ever volunteered to do the same
 for Windows.
 I'd like to see something like this happen, too, and if a group of
 volunteers emerges I'll do what I can through the PSF to provide
 resources. Activities that benefit the whole community (or a large part
 of it) are, IMHO, well worth supporting.
 What would it entail to do this? Using py2exe + some installer (like
 Inno Setup) to create an installer that basically copies/installs the
 files into the site-packages folder or wherever the user chooses? If
 that's all it is, I would think it would be fairly easy to create
 these. Maybe I'm over-simplifying it though.
 What are a some examples of packages that need this?
 MySQLdb and psycopg are two obvious examples I have had to grub around
 or produce my own installers for. There's generally some configuration
 work to do for packages that have been produced without considering
 Windows requirements, and ideally this will be fed back to the developers.

 I think you may be oversimplifying a little. Pure Python packages aren't
 too problematic, it's mostly the extension modules. Unless a copy of
 Visual Studio is available (and we *might* get some cooperation from
 Microsoft there) that means resorting to MingW, which isn't an easy
 environment to play with (in my occasional experience, anyway).

 There's going to be increasing demand for 64-bit implementations too.

 regards
   Steve
 --
 Steve Holden+1 571 484 6266   +1 800 494 3119
 Holden Web LLC/Ltd  http://www.holdenweb.com
 Skype: holdenweb  http://del.icio.us/steve.holden

 Sorry, the dog ate my .sigline
 
 Steve,
 
 We have Visual Studio 2005 at work and my boss is a Python nut, so I
 could probably use it. I also have academic versions of VS 6 and 2003
 (maybe 2005 too...I forget, it might be 2004) at home as well...I
 think I can use those for open source development, although knowing
 Microsoft, there's probably something draconian hiding in the EULA
 somewhere.
 
 If someone is willing to give me some guidance, I'll give it a try.
 
Mike:

The existing Python Windows installation is, IIRC, produced with VS 
2003. Though much work has been done on making a VS2005 version, I do 
not believe it has yet been completed. But I don't believe there's 
anything horrendous in the EULA waiting to bite us in the ass.

I think I could probably get Microsoft to make low-cost software 
available for individuals who were helping the Python community out in 
this way (and if not then I might persuade the PSF to apply some funding 
if individuals were seen to be committed to the task).

At least as important as individual volunteers to do the packaging work 
(and feed back changes to non-Windows implementation teams) is the need 
for someone to coordinate all the work done on different packages. 
Without someone who has an overall grasp of what's going on such work 
might tend to founder. Are you interested in that side of things at all?

I'm happy to give you what guidance I can [off line would probably be 
best], but my version of Visual Studio hasn't been used in two months ...

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Re: setuptools without unexpected downloads

2007-09-27 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 What would it entail to do this? Using py2exe + some installer (like
 Inno Setup) to create an installer that basically copies/installs the
 files into the site-packages folder or wherever the user chooses?

if the setup.py file is properly built, python setup.py bdist_wininst
builds an installer that does exactly that.

ideally, someone doing this would:

1) build EXE installers and EGG:s for a reasonable number of Python 
versions (e.g. 2.3 and newer) for selected releases.  if possible, using 
the same compilers as used for the python.org core distribution.

2) test the installers in some way (at least some kind of sanity
checking is necessary; i.e. installing the kit and checking that the 
core modules can at least be imported).

3) if necessary, work with upstream providers to fix/improve setup.py 
and test code.

/F

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


Re: Cross-platform time out decorator

2007-09-27 Thread Steve Holden
Joel wrote:
 On Sep 27, 4:36 pm, Hrvoje Niksic [EMAIL PROTECTED] wrote:
 Joel [EMAIL PROTECTED] writes:
 I found the solution :
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440569
 describes a solution based on threads. I tested it and it works
 perfectly.
 Note that, unlike the original alarm code, it doesn't really interrupt
 the timed-out method, it just returns the control back to the caller,
 using an exception to mark that a timeout occurred.  The timed out
 code is still merrily running in the background.  I don't know if it's
 a problem in your case, but it's an important drawback.
 
 There should be a method to stop the thread though? I've never
 programmed thread stuff in python and wasn't able to find how to do
 it, would you happen to know how to kill the timed out thread?
 
There is no way to kill a thread, other than set a flag and have the 
thread read it to realise the main thread wants it to stop.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Re: Cross-platform time out decorator

2007-09-27 Thread Tim Golden
Steve Holden wrote:
 Joel wrote:
 On Sep 27, 4:36 pm, Hrvoje Niksic [EMAIL PROTECTED] wrote:
 Joel [EMAIL PROTECTED] writes:
 I found the solution :
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440569
 describes a solution based on threads. I tested it and it works
 perfectly.
 Note that, unlike the original alarm code, it doesn't really interrupt
 the timed-out method, it just returns the control back to the caller,
 using an exception to mark that a timeout occurred.  The timed out
 code is still merrily running in the background.  I don't know if it's
 a problem in your case, but it's an important drawback.
 There should be a method to stop the thread though? I've never
 programmed thread stuff in python and wasn't able to find how to do
 it, would you happen to know how to kill the timed out thread?

 There is no way to kill a thread, other than set a flag and have the 
 thread read it to realise the main thread wants it to stop.

This is more-or-less why I suggested earlier that you wouldn't
find anything straightforward. The signal mechanism, as far as
I know, is pretty much unique in terms of the support it gets
from the OS and the language combined. Any other solution will
end up papering over cracks.

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


Re: os.removedirs - How to force this delete?

2007-09-27 Thread Marc Christiansen
[EMAIL PROTECTED] wrote:
 I've been searching to find a way to force this delete to work even if
 the directory isn't empty.  I've had no luck thus far.  Anyone know
 what that would be?

Answering your immediate question: you can't force os.removedirs to
delete non-empty dirs.
But shutil.rmtree(path, ignore_errors=True) does what you want.

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


Re: Pb with an AttributeError

2007-09-27 Thread Nathan Harmston
Hi,

I m not sure what your trying to do, but this is where your problem is:

string1 is not a string it is actually a dict because of your eval.
When you call
string1[param] inside the string.split()

it is returning a dictionary and not a string
'param': {'key': 'SP136=', 'value': ['SD:0 ']}

since {'key': 'SP136=', 'value': ['SD:0 ']} is inside curly
brackets it is a dictionary.

I still dont get what your trying to have as your final result, but
hope this helps.

Thanks

Nathan

On 27/09/2007, Eric BOUVIER [EMAIL PROTECTED] wrote:



 Hello,

 First, sorry for my english.

 I've just been assigned a project written in Python which contains bug(s).
 I've never programmed in Python, but I've read the code
 and understood basically what the different source codes do.

 I've traced the code and found where the problem is but I don't
 know how to solve the problem.

 Here it is :

 I've got a string issued from a CSV file :
string1 = eval(line[4])
print  * string1 = (, string1 ,) \n
 =  * string1 = ( {'header': 'X-Score', 'param': {'key': 'SP136=',
 'value': ['SD:0 ']} )

 Then, there is a split with the equal :
TheParts = string.split(string1[param], =)
print  * TheParts = (, TheParts ,) \n

 But, running the program returns :

 Traceback (most recent call last):
   File C:\test\helper.py, line 136, in Action_handler
 Score_eval(line, OutputFile_SP, This_Host)
   File C:\test\helper.py, line 66, in Score_eval
 TheParts = string.split(string1[param], =)
   File C:\ActiveState\Python25\lib\string.py, line 290,
 in split
 return s.split(sep, maxsplit)
 AttributeError: 'dict' object has no attribute 'split'  !?!

 I've found that it works when I put directly the string in the split
 expression :

TheParts = string.split( {'key': 'ESP136=', 'value': ['SHA:0 ']} ,
 =)
   = * TheParts =   [{'key': 'ESP136, ', 'value': ['SHA:0 ']}]

   But the code isn't dynamic anymore !
 I think it's a problem with the type, but the different syntax I've tried
 didn't work.
 Is somebody could help me ?

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

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


Re: Pb with an AttributeError

2007-09-27 Thread Nathan Harmston
Did I just help someone with their homework? Hope not :S

On 27/09/2007, Nathan Harmston [EMAIL PROTECTED] wrote:
 Hi,

 I m not sure what your trying to do, but this is where your problem is:

 string1 is not a string it is actually a dict because of your eval.
 When you call
 string1[param] inside the string.split()

 it is returning a dictionary and not a string
 'param': {'key': 'SP136=', 'value': ['SD:0 ']}

 since {'key': 'SP136=', 'value': ['SD:0 ']} is inside curly
 brackets it is a dictionary.

 I still dont get what your trying to have as your final result, but
 hope this helps.

 Thanks

 Nathan

 On 27/09/2007, Eric BOUVIER [EMAIL PROTECTED] wrote:
 
 
 
  Hello,
 
  First, sorry for my english.
 
  I've just been assigned a project written in Python which contains bug(s).
  I've never programmed in Python, but I've read the code
  and understood basically what the different source codes do.
 
  I've traced the code and found where the problem is but I don't
  know how to solve the problem.
 
  Here it is :
 
  I've got a string issued from a CSV file :
 string1 = eval(line[4])
 print  * string1 = (, string1 ,) \n
  =  * string1 = ( {'header': 'X-Score', 'param': {'key': 'SP136=',
  'value': ['SD:0 ']} )
 
  Then, there is a split with the equal :
 TheParts = string.split(string1[param], =)
 print  * TheParts = (, TheParts ,) \n
 
  But, running the program returns :
 
  Traceback (most recent call last):
File C:\test\helper.py, line 136, in Action_handler
  Score_eval(line, OutputFile_SP, This_Host)
File C:\test\helper.py, line 66, in Score_eval
  TheParts = string.split(string1[param], =)
File C:\ActiveState\Python25\lib\string.py, line 290,
  in split
  return s.split(sep, maxsplit)
  AttributeError: 'dict' object has no attribute 'split'  !?!
 
  I've found that it works when I put directly the string in the split
  expression :
 
 TheParts = string.split( {'key': 'ESP136=', 'value': ['SHA:0 ']} ,
  =)
= * TheParts =   [{'key': 'ESP136, ', 'value': ['SHA:0 ']}]
 
But the code isn't dynamic anymore !
  I think it's a problem with the type, but the different syntax I've tried
  didn't work.
  Is somebody could help me ?
 
   Thank you
  --
  http://mail.python.org/mailman/listinfo/python-list
 

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


Implement file download using python

2007-09-27 Thread skulka3
Hello,

I want to implement file downloads inside an authenticated web page,
such that when a user clicks a link, the server side python code
connects to a ftp server, downloads a relevant file and then streams
the file to the browser for the user to open it with the appropriate
application. In this case it will either be a pdf or a tiff file.

This function is quite similar to something like writing raw bytes to
a ServletOutputStream in java to be rendered directly to the user.

It would be nice if someone can provide guidance, examples on how such
a task may be accomplished using python.

Thanks,
Salil .

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


True of False

2007-09-27 Thread koutoo
I tried writing a true and false If statement and didn't get
anything?  I read some previous posts, but I must be missing
something.  I just tried something easy:

a = [a, b, c, d, e, f]

if c in a == True:
 Print Yes

When I run this, it runs, but nothing prints.  What am I doing wrong?
Thanks.

Kou

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


ValueError: too many values to unpack,

2007-09-27 Thread Shawn Minisall
I am trying to read a few lines of a file with multiple values, the rest 
are single and are reading in fine.

With the multiple value lines, python says this ValueError: too many 
values to unpack

I've googled it and it says that happens when you have too few or too 
many strings that don't match with the variables in number your trying 
to assign them too.  Below are the lines in reading in:

line 3 - 19.1829.1578.75212.10
line 4 - 10020410.29   

And this is the code I'm using:

#read withdrawls from file on line3
line = infile.readline()
   
#split withdrawls up
withdraw1, withdraw2, withdraw3, withdraw4 = string.split(line, \t)

#read deposits from file on line4
line = infile.readline()
#split deposits up
deposit1, deposit2, deposit3 = string.split(line, \t)

I have 4 strings to match line 3 and 3 to match the 3 on line 4...any 
thoughts?

thx

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


RE: Pb with an AttributeError

2007-09-27 Thread Eric BOUVIER
 Thanks, 

I find the type function and effectively the type is a dict. 
I didn't know this type before !  :-}

The program normally try to get the value of SP between the  
in the string1. Here, it's 136. 
The string1 is normally longer and had a lot of value but only one 
with value=.

I find str() and applied it to tranform the type 'dict' in a sting type.
Thus, I arrived to get 136 with regular expression.

   Thanks


 -Message d'origine-
 De : Nathan Harmston [mailto:[EMAIL PROTECTED] 
 Envoyé : jeudi 27 septembre 2007 18:16
 À : Eric BOUVIER
 Cc : python-list@python.org
 Objet : Re: Pb with an AttributeError
 
 Hi,
 
 I m not sure what your trying to do, but this is where your 
 problem is:
 
 string1 is not a string it is actually a dict because of your eval.
 When you call
 string1[param] inside the string.split()
 
 it is returning a dictionary and not a string
 'param': {'key': 'SP136=', 'value': ['SD:0 ']}
 
 since {'key': 'SP136=', 'value': ['SD:0 ']} is inside curly
 brackets it is a dictionary.
 
 I still dont get what your trying to have as your final result, but
 hope this helps.
 
 Thanks
 
 Nathan
 
 On 27/09/2007, Eric BOUVIER [EMAIL PROTECTED] wrote:
 
 
 
  Hello,
 
  First, sorry for my english.
 
  I've just been assigned a project written in Python which 
 contains bug(s).
  I've never programmed in Python, but I've read the code
  and understood basically what the different source codes do.
 
  I've traced the code and found where the problem is but I don't
  know how to solve the problem.
 
  Here it is :
 
  I've got a string issued from a CSV file :
 string1 = eval(line[4])
 print  * string1 = (, string1 ,) \n
  =  * string1 = ( {'header': 'X-Score', 'param': 
 {'key': 'SP136=',
  'value': ['SD:0 ']} )
 
  Then, there is a split with the equal :
 TheParts = string.split(string1[param], =)
 print  * TheParts = (, TheParts ,) \n
 
  But, running the program returns :
 
  Traceback (most recent call last):
File C:\test\helper.py, line 136, in Action_handler
  Score_eval(line, OutputFile_SP, This_Host)
File C:\test\helper.py, line 66, in Score_eval
  TheParts = string.split(string1[param], =)
File C:\ActiveState\Python25\lib\string.py, line 290,
  in split
  return s.split(sep, maxsplit)
  AttributeError: 'dict' object has no attribute 'split'  !?!
 
  I've found that it works when I put directly the string in the split
  expression :
 
 TheParts = string.split( {'key': 'ESP136=', 'value': 
 ['SHA:0 ']} ,
  =)
= * TheParts =   [{'key': 'ESP136, ', 'value': 
 ['SHA:0 ']}]
 
But the code isn't dynamic anymore !
  I think it's a problem with the type, but the different 
 syntax I've tried
  didn't work.
  Is somebody could help me ?
 
   Thank you
  --
  http://mail.python.org/mailman/listinfo/python-list
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implement file download using python

2007-09-27 Thread Diez B. Roggisch
 [EMAIL PROTECTED] wrote:

 Hello,
 
 I want to implement file downloads inside an authenticated web page,
 such that when a user clicks a link, the server side python code
 connects to a ftp server, downloads a relevant file and then streams
 the file to the browser for the user to open it with the appropriate
 application. In this case it will either be a pdf or a tiff file.
 
 This function is quite similar to something like writing raw bytes to
 a ServletOutputStream in java to be rendered directly to the user.
 
 It would be nice if someone can provide guidance, examples on how such
 a task may be accomplished using python.

Fetching using ftplib is easy. But serving depends on what
HTTP-server-environment you use. Please elaborate on that.

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


RE: making run time changes..

2007-09-27 Thread Piyush Jain
Hi,
It seems that pyro provides remote access to object acting as middleware. My
requirement is a bit different. It need not be remote. But I need to make
run time changes at the running program, say changing it's functionality.
More in lines of dynamic modules, but triggered by messages from outside.

Regards,
Piyush

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Steve Holden
Sent: Thursday, September 27, 2007 9:05 PM
To: python-list@python.org
Subject: Re: making run time changes..

Piyush Jain wrote:
 Hi,
 
 I am new(almost) to python. I wish to making a server in which I can 
 make changes at run time. For example , add a method to a 
 class/attribute to object etc. by sending it messages.
 
 Can anyone help me with what features to look into and how to go about 
 it. Are there any similar projects?
 
Take a look at Pyro (Python remote objects). It can almost certainly do 
what you want.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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

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


Re: ValueError: too many values to unpack,

2007-09-27 Thread Marc 'BlackJack' Rintsch
On Thu, 27 Sep 2007 12:36:58 -0400, Shawn Minisall wrote:

 With the multiple value lines, python says this ValueError: too many 
 values to unpack
 
 I've googled it and it says that happens when you have too few or too 
 many strings that don't match with the variables in number your trying 
 to assign them too.  Below are the lines in reading in:
 
 line 3 - 19.1829.1578.75212.10
 line 4 - 10020410.29   
 
 And this is the code I'm using:
 
 #read withdrawls from file on line3
 line = infile.readline()

 #split withdrawls up
 withdraw1, withdraw2, withdraw3, withdraw4 = string.split(line, \t)
 
 #read deposits from file on line4
 line = infile.readline()
 #split deposits up
 deposit1, deposit2, deposit3 = string.split(line, \t)
 
 I have 4 strings to match line 3 and 3 to match the 3 on line 4...any 
 thoughts?

First thought is to find out which of the two lines triggers the
exception.  This information is part of the full traceback.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


ValueError: too many values to unpack

2007-09-27 Thread Shawn Minisall
I am trying to read a few lines of a file with multiple values, the rest 
are single and are reading in fine.

With the multiple value lines, python says this ValueError: too many 
values to unpack

I've googled it and it says that happens when you have too few or too 
many strings that don't match with the variables in number your trying 
to assign them too.  Below are the lines in reading in:

line 3 - 19.1829.1578.75212.10
line 4 - 10020410.29  
And this is the code I'm using:

   #read withdrawls from file on line3
   line = infile.readline()
 #split withdrawls up
   withdraw1, withdraw2, withdraw3, withdraw4 = string.split(line, \t)

   #read deposits from file on line4
   line = infile.readline()
   #split deposits up
   deposit1, deposit2, deposit3 = string.split(line, \t)

I have 4 strings to match line 3 and 3 to match the 3 on line 4...any 
thoughts?

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


Re: True of False

2007-09-27 Thread Simon Brunning
On 9/27/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 I tried writing a true and false If statement and didn't get
 anything?  I read some previous posts, but I must be missing
 something.  I just tried something easy:

 a = [a, b, c, d, e, f]

 if c in a == True:
  Print Yes

 When I run this, it runs, but nothing prints.  What am I doing wrong?

Just use

if c in a:

and all will be well. The True object isn't the only truthy value in
Python - see http://docs.python.org/lib/truth.html.

-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: True of False

2007-09-27 Thread skulka3
On Sep 27, 11:33 am, [EMAIL PROTECTED] wrote:
 I tried writing a true and false If statement and didn't get
 anything?  I read some previous posts, but I must be missing
 something.  I just tried something easy:

 a = [a, b, c, d, e, f]

 if c in a == True:
  Print Yes

 When I run this, it runs, but nothing prints.  What am I doing wrong?
 Thanks.

 Kou

,
You may want to include paren around (c in a) and a lower case p for
Print, i.e. print, and  it should work

so eg:
a = [a, b, c, d, e, f]

 if (c in a) == True:
  print Yes

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


Re: True of False

2007-09-27 Thread Marc 'BlackJack' Rintsch
On Thu, 27 Sep 2007 09:33:34 -0700, koutoo wrote:

 I tried writing a true and false If statement and didn't get
 anything?  I read some previous posts, but I must be missing
 something.  I just tried something easy:
 
 a = [a, b, c, d, e, f]
 
 if c in a == True:
  Print Yes
 
 When I run this, it runs, but nothing prints.  What am I doing wrong?

Wow that's odd:

In [265]: a = list('abcdef')

In [266]: a
Out[266]: ['a', 'b', 'c', 'd', 'e', 'f']

In [267]: 'c' in a
Out[267]: True

In [268]: 'c' in a == True
Out[268]: False

In [269]: ('c' in a) == True
Out[269]: True

In [270]: 'c' in (a == True)
---
type 'exceptions.TypeError' Traceback (most recent call last)

/home/bj/ipython console in module()

type 'exceptions.TypeError': argument of type 'bool' is not iterable


What's going on there?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: True of False

2007-09-27 Thread Shriphani

[EMAIL PROTECTED] wrote:
 I tried writing a true and false If statement and didn't get
 anything?  I read some previous posts, but I must be missing
 something.  I just tried something easy:

 a = [a, b, c, d, e, f]

 if c in a == True:
  Print Yes

 When I run this, it runs, but nothing prints.  What am I doing wrong?
 Thanks.

 Kou

Hello,
Just try :

a = [a,b,c,d,e,f]
if c in a:
print yes

That is going to work as the statement 'c in a' itself is true. You
could try that by typing c in a at the interpreter.

regards,
Shriphani Palakodety

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


Re: comparing elements of a list with a string

2007-09-27 Thread Marc 'BlackJack' Rintsch
On Thu, 27 Sep 2007 08:16:59 -0400, Steve Holden wrote:

 Shriphani wrote:
 Hello,
 Would that mean that if I wanted to append all the (date, time) tuples
 to a list, I should do something like:
 
 for file in list_of_backup_files:
 some_list.append(file)
 
 That would be one way to do it (assuming you started with some_list as 
 an empty list). But a faster way would be to use a list comprehension 
 and say
 
 some_list = [f for f in list_of_backup_files]

Or:

some_list = list(list_of_backup_files)

If `some_list` is not empty:

some_list.extend(list_of_backup_files)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implement file download using python

2007-09-27 Thread skulka3
On Sep 27, 11:39 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
  [EMAIL PROTECTED] wrote:
  Hello,

  I want to implement file downloads inside an authenticated web page,
  such that when a user clicks a link, the server side python code
  connects to a ftp server, downloads a relevant file and then streams
  the file to the browser for the user to open it with the appropriate
  application. In this case it will either be a pdf or a tiff file.

  This function is quite similar to something like writing raw bytes to
  a ServletOutputStream in java to be rendered directly to the user.

  It would be nice if someone can provide guidance, examples on how such
  a task may be accomplished using python.

 Fetching using ftplib is easy. But serving depends on what
 HTTP-server-environment you use. Please elaborate on that.

 Diez

Thanks Diez for your reply.
I am comfortable with using ftplib to fetch the file. As for the HTTP-
server environment,
I am using Apache 1.3 web server and python 2.1.3.

Salil.

Salil.

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


Re: True of False

2007-09-27 Thread Casey
On Sep 27, 12:48 pm, Simon Brunning [EMAIL PROTECTED]
wrote:
 On 9/27/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

  I tried writing a true and false If statement and didn't get
  anything?  I read some previous posts, but I must be missing
  something.  I just tried something easy:

  a = [a, b, c, d, e, f]

  if c in a == True:
   Print Yes

  When I run this, it runs, but nothing prints.  What am I doing wrong?

 Just use

 if c in a:

 and all will be well. The True object isn't the only truthy value in
 Python - see http://docs.python.org/lib/truth.html.

I would recommend the OP try this:

run the (I)python shell and try the following:

 a = [x for x in abcdefg]
 a
['a','b','c','d','e','f','g']
 c in a
True
 c in a == True
False
 (c in a) == True
True

The reason your conditional failed is that it was interpreted as c
in (a == True) which is False.
the == operator binds at a higher precedence level than the in
operator, just as multiplication
binds higher than addition


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


Re: True of False

2007-09-27 Thread Duncan Booth
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:

 In [268]: 'c' in a == True
 Out[268]: False
 
 In [269]: ('c' in a) == True
 Out[269]: True
 
 In [270]: 'c' in (a == True)
 ---
  
type 'exceptions.TypeError' Traceback (most recent call
last) 
 
 /home/bj/ipython console in module()
 
type 'exceptions.TypeError': argument of type 'bool' is not iterable
 
 
 What's going on there?

See http://docs.python.org/ref/comparisons.html

 Comparisons can be chained arbitrarily, e.g., x  y = z is equivalent
 to x  y and y = z, except that y is evaluated only once (but in both
 cases z is not evaluated at all when x  y is found to be false). 

In exactly the same way:

   'c' in a == True

is equivalent to:

   'c' in a and a == True

which is False.


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


Re: True of False

2007-09-27 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 I tried writing a true and false If statement and didn't get
 anything?  I read some previous posts, but I must be missing
 something.  I just tried something easy:
 
 a = [a, b, c, d, e, f]
 
 if c in a == True:
  Print Yes
 
 When I run this, it runs, but nothing prints.  What am I doing wrong?
 Thanks.

You are unnecessarily adding a comparison with True. The correct way to 
write that is

if c in a:
   print yes

Bu of course you haven't actually told us what you really did, because 
the code you represent has syntax errors.

  a = [a, b, c, d, e, f]
  c in a
True
  if c in a == True:
...print found it
...
  if (c in a) == True:
... print At last!
...
At last!
 
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

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


Re: True of False

2007-09-27 Thread Richard Thomas
On 27/09/2007, Casey [EMAIL PROTECTED] wrote:
 On Sep 27, 12:48 pm, Simon Brunning [EMAIL PROTECTED]
 wrote:
  On 9/27/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 
   I tried writing a true and false If statement and didn't get
   anything?  I read some previous posts, but I must be missing
   something.  I just tried something easy:
 
   a = [a, b, c, d, e, f]
 
   if c in a == True:
Print Yes
 
   When I run this, it runs, but nothing prints.  What am I doing wrong?
 
  Just use
 
  if c in a:
 
  and all will be well. The True object isn't the only truthy value in
  Python - see http://docs.python.org/lib/truth.html.

 I would recommend the OP try this:

 run the (I)python shell and try the following:

  a = [x for x in abcdefg]
  a
 ['a','b','c','d','e','f','g']
  c in a
 True
  c in a == True
 False
  (c in a) == True
 True

 The reason your conditional failed is that it was interpreted as c
 in (a == True) which is False.
 the == operator binds at a higher precedence level than the in
 operator, just as multiplication
 binds higher than addition


Actually it evaluates '(c in a) and (a == True)'. You can check like so:

import dis
a = list(abcdef)
dis.dis(lambda: c in a == True)

And just follow the bytecode operations.

-- Richard.

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

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


Re: True of False

2007-09-27 Thread Casey
On Sep 27, 1:12 pm, Richard Thomas [EMAIL PROTECTED] wrote:
 On 27/09/2007, Casey [EMAIL PROTECTED] wrote:



  On Sep 27, 12:48 pm, Simon Brunning [EMAIL PROTECTED]
  wrote:
   On 9/27/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

I tried writing a true and false If statement and didn't get
anything?  I read some previous posts, but I must be missing
something.  I just tried something easy:

a = [a, b, c, d, e, f]

if c in a == True:
 Print Yes

When I run this, it runs, but nothing prints.  What am I doing wrong?

   Just use

   if c in a:

   and all will be well. The True object isn't the only truthy value in
   Python - see http://docs.python.org/lib/truth.html.

  I would recommend the OP try this:

  run the (I)python shell and try the following:

   a = [x for x in abcdefg]
   a
  ['a','b','c','d','e','f','g']
   c in a
  True
   c in a == True
  False
   (c in a) == True
  True

  The reason your conditional failed is that it was interpreted as c
  in (a == True) which is False.
  the == operator binds at a higher precedence level than the in
  operator, just as multiplication
  binds higher than addition

 Actually it evaluates '(c in a) and (a == True)'. You can check like so:

 import dis
 a = list(abcdef)
 dis.dis(lambda: c in a == True)

 And just follow the bytecode operations.

 -- Richard.

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

Doh, I forgot about operator chaining here.  I'm so used to just
seeing a  b  c that I forget about arbitrary operator chaining and
think like a C++ programmer!

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


Re: True of False

2007-09-27 Thread Carsten Haese
On Thu, 2007-09-27 at 16:47 +, Marc 'BlackJack' Rintsch wrote:
 On Thu, 27 Sep 2007 09:33:34 -0700, koutoo wrote:
 
  I tried writing a true and false If statement and didn't get
  anything?  I read some previous posts, but I must be missing
  something.  I just tried something easy:
  
  a = [a, b, c, d, e, f]
  
  if c in a == True:
   Print Yes
  
  When I run this, it runs, but nothing prints.  What am I doing wrong?
 
 Wow that's odd:
 
 In [265]: a = list('abcdef')
 
 In [266]: a
 Out[266]: ['a', 'b', 'c', 'd', 'e', 'f']
 
 In [267]: 'c' in a
 Out[267]: True
 
 In [268]: 'c' in a == True
 Out[268]: False
 
 In [269]: ('c' in a) == True
 Out[269]: True
 
 In [270]: 'c' in (a == True)
 ---
 type 'exceptions.TypeError' Traceback (most recent call last)
 
 /home/bj/ipython console in module()
 
 type 'exceptions.TypeError': argument of type 'bool' is not iterable
 
 
 What's going on there?

What's going on here is that both 'in' and '==' are comparison
operations, and Python allows you to chain comparisons. Just like a  x
 b is evaluated as a  x and x  b, 'c' in a == True is evaluated
as 'c' in a and a == True. Obviously, since a==True is false, the
chained comparison is False.

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


getopt with negative numbers?

2007-09-27 Thread Casey
Is there an easy way to use getopt and still allow negative numbers as
args?  I can easily write a workaround (pre-process the tail end of
the arguments, stripping off any non-options including negative
numbers into a separate sequence and ignore the (now empty) args list
returned by getopt, but it would seem this is such a common
requirement that there would be an option to treat a negative value as
an argument.  Note that this is only a problem if the first non-option
is a negative value, since getopt stops processing options as soon as
it identifies the first argument value.

Alternatively, does optparse handle this?  I haven't used optparse (I
know it is more powerful and OO, but you tend to stick with what you
know, especially when it is part of my normal python programming
template), but if it handles negative numbers I'm willing to learn it.

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


Re: True of False

2007-09-27 Thread Erik Jones

On Sep 27, 2007, at 11:47 AM, Marc 'BlackJack' Rintsch wrote:

 On Thu, 27 Sep 2007 09:33:34 -0700, koutoo wrote:

 I tried writing a true and false If statement and didn't get
 anything?  I read some previous posts, but I must be missing
 something.  I just tried something easy:

 a = [a, b, c, d, e, f]

 if c in a == True:
  Print Yes

 When I run this, it runs, but nothing prints.  What am I doing wrong?

 Wow that's odd:

 In [265]: a = list('abcdef')

 In [266]: a
 Out[266]: ['a', 'b', 'c', 'd', 'e', 'f']

 In [267]: 'c' in a
 Out[267]: True

 In [268]: 'c' in a == True
 Out[268]: False

 In [269]: ('c' in a) == True
 Out[269]: True

 In [270]: 'c' in (a == True)
 -- 
 -
 type 'exceptions.TypeError' Traceback (most recent  
 call last)

 /home/bj/ipython console in module()

 type 'exceptions.TypeError': argument of type 'bool' is not iterable


 What's going on there?

That is weird.  Given 270, what's happening in 268.

Erik Jones

Software Developer | Emma®
[EMAIL PROTECTED]
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate  market in style.
Visit us online at http://www.myemma.com


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


Re: True of False

2007-09-27 Thread Gary Herron
Richard Thomas wrote:
 On 27/09/2007, Casey [EMAIL PROTECTED] wrote:
   
 On Sep 27, 12:48 pm, Simon Brunning [EMAIL PROTECTED]
 wrote:
 
 On 9/27/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

   
 I tried writing a true and false If statement and didn't get
 anything?  I read some previous posts, but I must be missing
 something.  I just tried something easy:
 
 a = [a, b, c, d, e, f]
 
 if c in a == True:
  Print Yes
 
 When I run this, it runs, but nothing prints.  What am I doing wrong?
 
 Just use

 if c in a:

 and all will be well. The True object isn't the only truthy value in
 Python - see http://docs.python.org/lib/truth.html.
   
 I would recommend the OP try this:

 run the (I)python shell and try the following:

 
 a = [x for x in abcdefg]
 a
   
 ['a','b','c','d','e','f','g']
 
 c in a
   
 True
 
 c in a == True
   
 False
 
 (c in a) == True
   
 True

 The reason your conditional failed is that it was interpreted as c
 in (a == True) which is False.
 the == operator binds at a higher precedence level than the in
 operator, just as multiplication
 binds higher than addition

 

 Actually it evaluates '(c in a) and (a == True)'. You can check like so:

 import dis
 a = list(abcdef)
 dis.dis(lambda: c in a == True)

 And just follow the bytecode operations.
   
Yikes.  So I did that and you're correct.   I've always looked at
chained comparisons with mild suspicion.  Now I guess that suspicion is
justified.  Interpreting
abc
as
ab and bc
make perfect sense to me, but interpreting
c in a == True
as
(c in a) and (a == True)
is not at all natural.

Gary Herron

 -- Richard.

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

 

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


Re: getopt with negative numbers?

2007-09-27 Thread Peter Otten
Casey wrote:

 Is there an easy way to use getopt and still allow negative numbers as
 args?  I can easily write a workaround (pre-process the tail end of
 the arguments, stripping off any non-options including negative
 numbers into a separate sequence and ignore the (now empty) args list
 returned by getopt, but it would seem this is such a common
 requirement that there would be an option to treat a negative value as
 an argument.  Note that this is only a problem if the first non-option
 is a negative value, since getopt stops processing options as soon as
 it identifies the first argument value.
 
 Alternatively, does optparse handle this?  I haven't used optparse (I
 know it is more powerful and OO, but you tend to stick with what you
 know, especially when it is part of my normal python programming
 template), but if it handles negative numbers I'm willing to learn it.

optparse can handle options with a negative int value; -- can be used to
signal that no more options will follow:

 import optparse
 parser = optparse.OptionParser()
 parser.add_option(-a, type=int)
Option at 0xb7d6fd8c: -a
 options, args = parser.parse_args([-a, -42, --, -123])
 options.a
-42
 args
['-123']

Without the -- arg you will get an error:

 parser.parse_args([-123])
Usage:  [options]

: error: no such option: -1
$

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


Re: getopt with negative numbers?

2007-09-27 Thread Casey
On Sep 27, 1:34 pm, Peter Otten [EMAIL PROTECTED] wrote:
 optparse can handle options with a negative int value; -- can be used to
 signal that no more options will follow:

Thanks, Peter.  getopt supports the POSIX -- end of options
indicator as well, but that seems a little less elegant than being
able to simply set a value that tells the parser I don't use any
numeric values as options, and I want to allow negative values as
arguments.  At the parser level implemening this would be trivial and
I frankly was hoping it had been implemented and it just wasn't
mentioned in the spares Python getopt library reference.

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


Re: How do I get the value out of a DOM Element

2007-09-27 Thread Stefan Behnel
kj7ny wrote:
 Forgot to mention I'm using Python 2.4.3.

You can install both lxml and ET on Python 2.4 (and 2.3). It's just that ET
went into the stdlib from 2.5 on.

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


  1   2   3   >