Re: unable to print Unicode characters in Python 3

2009-01-28 Thread John Machin

On 28/01/2009 6:32 PM, Martin v. Löwis wrote:

Next step?


You need to use the Visual Studio debugger to find out where
precisely the IOError comes from.


Big step. I don't have Visual Studio and have never used it before. 
Which version of VS do I need to debug which released version of Python 
2.X and where do I get that VS from? Or do I need to build Python from 
source to be able to debug it?

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


Re: Python-list Digest, Vol 64, Issue 617

2009-01-28 Thread Ferdinand Sousa

 Secondly, it has no way to display the image drawn on. Is it possible, or
 do
 I have to pass the image off to another module's methods?

 im.show() this will display the image (and any modification(s) made to
it)


 Example: Draw a Grey Cross Over an Image
 import Image, ImageDraw
 im = Image.open(lena.pgm)
 draw = ImageDraw.Draw(im)
 draw.line((0, 0) + im.size, fill=128)
 draw.line((0, im.size[1], im.size[0], 0), fill=128)
 del draw
 # write to stdout
 im.save(sys.stdout, PNG)

 Hope that helps

 That's pretty much the code I used. In fact, I borrowed it from the pdf. I
 just tried it, and it output %PNG.

 im.save(picture1.png)
OR
im.save(picture1 png) # not sure if it has to be PNG

What was happening earlier was that the binary data was being directed to
the standard output, which is where all your text is printed by a print
statement (print func in Py 3000). If you open a png in notepad, you will
notice that the 1st four characters are indeed %PNG, which is the magic
number for a PNG file.
For further info, see:
http://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_fileshttp://en.wikipedia.org/wiki/Magic_number_%28programming%29#Magic_numbers_in_files
http://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header

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


Re: Receiving data from USB

2009-01-28 Thread Diez B. Roggisch

barithegr...@gmail.com schrieb:

Hi
Can any body tell me how can i receive data from usb(usrp) in python.


http://letmegooglethatforyou.com/?q=python+usb

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


need help

2009-01-28 Thread juvy j
Hi guys,

need help on how to read file from other server(linux).

thanks a lot.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best/better way? (histogram)

2009-01-28 Thread Peter Otten
Bernard Rankin wrote:

 I've got several versions of code to here to generate a histogram-esque
 structure from rows in a CSV file.
 
 The basic approach is to use a Dict as a bucket collection to count
 instances of data items.
 
 Other than the try/except(KeyError) idiom for dealing with new bucket
 names, which I don't like as it desribes the initial state of a KeyValue
 _after_ you've just described what to do with the existing value, I've
 come up with a few other methods.
 
 What seems like to most resonable approuch?

The simplest. That would be #3, cleaned up a bit:

from collections import defaultdict
from csv import DictReader
from pprint import pprint
from operator import itemgetter

def rows(filename):
infile = open(filename, rb)
for row in DictReader(infile):
yield row[CATEGORIES]

def stats(values):
histo = defaultdict(int)
for v in values:
histo[v] += 1
return sorted(histo.iteritems(), key=itemgetter(1), reverse=True)

Should you need the inner dict (which doesn't seem to offer any additional
information) you can always add another step:

def format(items):
result = []
for raw, count in items:
leaf = raw.rpartition(|)[2]
result.append((raw, dict(count=count, leaf=leaf)))
return result

pprint(format(stats(rows(sampledata.csv))), indent=4, width=60)

By the way, if you had broken the problem in steps like above you could have
offered four different stats() functions which would would have been a bit
easier to read...

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


Re: errno 22 instead of errno 2

2009-01-28 Thread Tim Golden

Glenn Linderman wrote:

open(c:\abc,rb)

This simple one-line script, produces errno 22 on Python 2.6, but errno 
2 on Python 2.5.2


Is this an unintentional regression?  Or is this an intentional bug fix?

The file doesn't exist (errno 2) but I guess on Windows it is also 
somewhat an invalid file name (errno 22).


Yes, I'm aware that \a is ASCII 007.  Using a valid, non-existent file 
name produces errno 2 on both versions.





Just glancing quickly at the svn logs, there certainly were some
changes around that area in 2008:

http://svn.python.org/view/python/trunk/Objects/fileobject.c?view=log

Have a look at r61468, for example. Don't know if that's caused
what you're seeing but it might well be. (Don't have time just
at the mo to check out the revision and rebuild).

http://svn.python.org/view/python/trunk/Objects/fileobject.c?rev=61468r1=60984r2=61468


I'd question whether it's strictly a regression, unintentional or
otherwise, since I doubt the code makes any particular commitment as
to which error code is raised, but I'd certainly be looking askance
if I had code which relied on a particular error number which then
changed!  Still, that's what unit tests are for, I suppose.

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


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread Aaron Brady
On Jan 27, 3:16 pm, Reckoner recko...@gmail.com wrote:
 I'm not sure this is possible, but I would like to have
 a list of  objects

 A=[a,b,c,d,...,z]

 where,  in the midst of a lot of processing I might do something like,

 A[0].do_something_which_changes_the_properties()

 which alter the properties of the object 'a'.

 The trick is that I would like A to be mysteriously aware that
 something about the  object 'a' has changed so that when I revisit A,
 I will know that the other items in the list need to be refreshed to
 reflect the changes in A as a result of changing 'a'.

 Even better would be to automatically percolate the subsequent changes
 that resulted from altering 'a' for the rest of the items in the list.
 Naturally, all of these items are related in some parent-child
 fashion.

 that might be a lot to ask, however.

 Any advice appreciated.

What you could do is specialize '__getitem__' (or '__getslice__') so
that whenever one of its items is accessed, the item is marked as
dirty or the entire list is refreshed.  (Unproduced.)

def taintlist(list):
  def __getitem__( self, key ):
x= super(taintlist, self).__getitem__( self, key )
self._dirty= True
self.refresh()  #too early, unfortunately
return x
  ...

However, what you are probably after is something like this
(unproduced):

def taintlist(list):
  def __getitem__( self, key ):
x= super(taintlist, self).__getitem__( self, key )
y= delegate( self, key, x )
return y

The 'delegate' class, also unproduced, automatically delegates
function calls (including member lookups) to the target.  After the
delegated call returns, the list is notified-- hence the three
arguments to its constructor.  (Unproduced.)

class delegate:
  def __getattr__( self, key ):
attr= super( delegate, self ).__getattr__( self, key )
deleg= delegate( self.owner, self.ownerkey, attr )
return deleg
  def __call__( self, *ar, **kw ):
res= self.attr( *ar, **kw )
self.owner.markdirty( )
return res

I'm not convinced it's possible, but there's a possibility... or
something like it.  When you call a[0].meth(), three things happen:

x= '0' looked up on 'a'
y= 'meth' looked up on 'x'
z= 'y' called

You want control over the last of these parts, so you can call a
custom function instead.  It becomes increasingly risky as the depth
increases, such as if the target class implements custom access, I
guess.  In the 'delegate' shown, for example, it assumes that the
result is callable.  You might need:

class delegate:
  def __getattr__( self, key ):
attr= super( delegate, self ).__getattr__( self, key )
if not iscallable( attr ):
  return attr
... #return delegate

Further, if the result is callable, that doesn't mean it will
necessarily be called.  You should be able to tolerate this sequence:

x= '0' looked up on 'a'
y= 'meth' looked up on 'x'
z= attribute looked up on 'y' (instead of 'y' called)

Mind if we inquire after your progress?
--
http://mail.python.org/mailman/listinfo/python-list


ORM recommendation when using live/predefined DB?

2009-01-28 Thread Phillip B Oldham
We're trying to move to Python for a few parts of our application. We
have a live database, which has been modeled for a specific use, and
has other code connecting to and working with it.

We'd like to reduce the amount of work we have to do in terms of
keeping our python code up-to-date with schema changes, and we don't
want python objects to dictate how the database should be structured.

Can you recommend an ORM (or similar) package to look into?
--
http://mail.python.org/mailman/listinfo/python-list


Re: How many followers of comp.lang.python

2009-01-28 Thread Bruno Desthuilliers

Grant Edwards a écrit :

On 2009-01-27, Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid 
wrote:


Please visit comp.databases or comp.lang.javascript for really
unfriendly and unhelpful places where few happens except
bickering and name-calling.


I've always found comp.lang.c to be a rather dangerous place as
well.


Really ? I remember having learned quite a lot there too - but it was 
several years ago, and things may have changed.

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


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread John O'Hagan
On Tue, 27 Jan 2009, Reckoner wrote:
 I'm not sure this is possible, but I would like to have
 a list of  objects

 A=[a,b,c,d,...,z]

 where,  in the midst of a lot of processing I might do something like,

 A[0].do_something_which_changes_the_properties()

 which alter the properties of the object 'a'.

 The trick is that I would like A to be mysteriously aware that
 something about the  object 'a' has changed so that when I revisit A,
 I will know that the other items in the list need to be refreshed to
 reflect the changes in A as a result of changing 'a'.

 Even better would be to automatically percolate the subsequent changes
 that resulted from altering 'a' for the rest of the items in the list.
[...]

Interesting question.

Maybe this is too simple for your purpose (or maybe just wrong!), but could 
you subclass list and give it an update method which keeps a dictionary of 
the state of its members and/or calls another method that makes the 
appropriate changes in the other members when a change occurs, something 
like:

class SelfAwareList(list):

state_dict = {}

def update(self):
for i in self:
if i.state == 'some_condition':
self.do_stuff_to_other_members()
self.state_dict[i] = i.state

def do_stuff_to_other_members(self):
print 'doing stuff...'

?

You could manually call update() on the SelfAwareList instance after calling a 
method on a SelfAwareList member, or even build it into the members' methods 
so that it was automatic.

HTH,

John


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


Re: How many followers of comp.lang.python

2009-01-28 Thread Bruno Desthuilliers

rantingrick a écrit :

On Jan 27, 10:12 am, Bruno Desthuilliers bruno.
42.desthuilli...@websiteburo.invalid wrote:


All you can say is that he didn't *post* here (at least under his real
identity...) for the 9 past years - this doesn't mean he never *reads*
(and this, you just have no way to know).


Ah, this is a good point. You have to wonder, Guido could be one of
the regulars here.


if you mean one of the regular posters, I have serious doubts about 
it. It was mostly a theoretical refutation of your conclusions. The 
important point is that you just *can not* tell if he's *reading* this 
ng or not...



very interesting. We should have a vote as to who
would be the most likely candidate, now that would be a good thread :)


Waste of time as far as I'm concerned.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute a hyperlink?

2009-01-28 Thread Roel Schroeven
Muddy Coder schreef:
 Hi Folks,
 
 Module os provides a means of running shell commands, such as:
 
 import os
 os.system('dir .')
 
 will execute command dir
 
 I think a hyperlink should also be executed. I tried:
 
 os.system('http://somedomain.com/foo.cgi?name=foopasswd=bar')
 
 but I got kicked out by the Python interpreter. I wonder somebody
 knows the syntax of triggering a hyperlink? Thanks in advance!

As others have said, you can use the webbrowser module for hyperlinks.
Alternatively you can use os.startfile() which works hyperlinks and many
types of files, but only works on Windows (it does the same as
double-clicking in Windows Explorer).

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

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


Re: unable to print Unicode characters in Python 3

2009-01-28 Thread Thorsten Kampe
* John Machin (Tue, 27 Jan 2009 18:03:55 -0800 (PST))
 On Jan 28, 5:56 am, Martin v. Löwis mar...@v.loewis.de wrote:
 The only font choice offered apart from Raster Fonts in the Command
 Prompt window's Properties box is Lucida Console, not Lucida Sans
 Unicode. It will let me print Cyrillic characters from a C program,
 but not Chinese. I'm off looking for how to get a better font.

I have
[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont]
00=DejaVu Sans Mono

Note that you have to /reboot/ (no, I'm not kidding) to make this work.

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


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread Bruno Desthuilliers

excord80 a écrit :

I need to make a small, relatively low-traffic site that users can
create accounts on and log into. Scripts must run as cgi (no
mod_python or FastCGI is available). Can anyone recommend a small and
simple web framework for Python, maybe similar to Perl's
CGI::Application?


What about:
http://thraxil.org/code/cgi_app/

(yes, it is a port of CGI::Application, and FWIW it's mentionned on the 
CGI::Application's wiki).


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


Re: Python Application Server

2009-01-28 Thread Bruno Desthuilliers

Adi Eyal a écrit :

Hi All

Could anyone recommend a python application server? My application
consists mainly of long running background processes that need to
communicate with each other. Features on my wishlist include, process
pooling (each process will in general be stateless), monitoring,
scheduling and a framework for inter-process communication. Ideally, I
would also like to be able to cluster the app server if the need
arises. I have never used Zope or Webware, but my impression is that
these servers are focused on web applications with a short
request-response cycle. My usage will be different since my processes
will be triggered by certain events and then continue running until
they complete, without sending any response at all but possibly
spawning off additional processes in a workflow.

I hope my description has been clear. Does such an application server
exist for python?

Not sure if it would fit your needs, but you may want to have a look at 
Twisted ?

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


Re: ORM recommendation when using live/predefined DB?

2009-01-28 Thread Bruno Desthuilliers

Phillip B Oldham a écrit :

We're trying to move to Python for a few parts of our application. We
have a live database, which has been modeled for a specific use, and
has other code connecting to and working with it.

We'd like to reduce the amount of work we have to do in terms of
keeping our python code up-to-date with schema changes, and we don't
want python objects to dictate how the database should be structured.

Can you recommend an ORM (or similar) package to look into?


AFAICT, SQLAlchemy is the most tolerant (and advanced) Python SQL 
abstraction / ORM package.

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


Re: A Twisted Design Decision

2009-01-28 Thread koranthala
On Jan 27, 9:27 pm, koranthala koranth...@gmail.com wrote:
 On Jan 27, 6:57 pm, Jean-Paul Calderone exar...@divmod.com wrote:



  On Tue, 27 Jan 2009 05:46:25 -0800 (PST), koranthala koranth...@gmail.com 
  wrote:
  Twisted, being twisted in its behavior is causing quite a lot of
  confusion in design decisions.

  I'm not sure I agree with your premise. ;)

  I will put forward a comparison of reactor and non-reactor patterns.
  The code is not exact - whatever is shown is the gist of it.

  For example, a message handler - in a usual scenario:
  class messageHandler:
     def run():
           msg = self.get_next_msg()
           if not msg.send():
               self.handle_failure()

  To handle parallel execution, we will have to use threads, but the
  code flow is similar.

  How do we do the same in a reactor pattern (Twisted)?
  msg.send will cause a deferred to be raised - the failure, if it
  happens will happen much later.
  i.e. other than sending messageHandler object in msg.send(), I cannot
  see any mechanism of running handle_failure.

  In Twisted:
  class messageHandler:
     def run():
           msg = self.get_next_msg()
           msg.send(self):

  class msgClass:
      def send(o):
          d = deferred.addCallBack(success_handler, o).addErrBack
  (failure_handler, o)

      def failure_handler(o):
          o.handle_failure()

  This doesn't look like a correct or faithful translation of the original.
  Here are two possibilities.  First:

      class messageHandler:
          def run():
              msg = self.get_next_msg()
              d = msg.send()
              def cbSendFailed(result):
                  if not result:
                      self.handle_failure()
              d.addErrback(cbSendFailed)
              return d

  Next:

      class messageHandler:
          @inlineCallbacks
          def run():
              msg = self.get_next_msg()
              if not (yield msg.send()):
                  self.handle_failure()

  These are both just straight translations from your version so as to
  be able to handle a Deferred from `msg.send´.

  Basically, what I find is that a lot of functional encapsulation is
  now lost by following reactor pattern. handle_failure is
  messageHandlers code and makes for pretty viewing if called from
  inside messageHandler itself. But, due to the twisted nature of
  reactor pattern, the msg Class - who is functionally a lower class to
  messageHandler invoking messageHandler's code.

  You don't need to lose anything.  I don't know what your motivation was
  for re-arranging the code when you wrote the Twisted version, but it doesn't
  appear to have been necessary.

  Is there a way to solve this in a more beautiful way? Am I missing
  something here?

  Hope this helps,

  Jean-Paul

 Thank you Jean-Paul.
 My code is more complex than what I have mentioned. When I mentioned
 msg.send, the msg object actually gets the data from DB etc to send.
 And there are many other items being done.
 I will try to see whether I can change the code to incorporate what
 you mentioned.

 I rewrote most of my code after learning just raw deferreds - I had
 planned to study inlineCallbacks - but then it slipped my mind  - now
 it has come to bit me. :-(

Hi,
  I tried to update the code as per the suggestion, but to no avail.
  My system uses Python2.4.3 (cannot move to 2.5) - so I tried to
rewrite with deferredGenerators - since I thought inlineCallbacks are
similar to deferredGenerators.

  But I cannot seem to rewrite it in a format where the functional
encapsulation is not broken.
  i.e. as I mentioned in the first example - I have to pass SELF to
child objects for them to modify it.

  The code was not exactly as I mentioned. I will try to explain more
below:
  The code before Twisted was incorporated.

  class MessageHandler:
def send_message():
  if self.execute():  #Lots of checks going inside this
for i in self.msgs: #Sends many messages at the same time
   if msg.send():
 self.success += 1
   else
 self.failure += 1

  class Message:
def send():
  self.update_data() #The data to be sent is updated here
  return self.protocol.send() #Any protocol - for this example
HTTP is used

  class Protocol:
 def send():
HTTP get page
if page received:
  parse page and see parameters
  if parameters:
return True
return False

The code I rewrote after Twisted was incorporated:

  class MessageHandler:
def send_message():
  if self.execute():  #Lots of checks going inside this
for i in self.msgs: #Sends many messages at the same time
   msg.send(self):  #Has to send myself to the childclass

  class Message:
def send(h):
  self.h = h   #The message handler object
  self.update_data() #The data to be sent is updated here
  return self.protocol.send(self) #Again, sending myself to child
class

  

Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread Jeroen Ruigrok van der Werven
-On [20090127 22:21], excord80 (excor...@gmail.com) wrote:
I need to make a small, relatively low-traffic site that users can
create accounts on and log into. Scripts must run as cgi (no
mod_python or FastCGI is available). Can anyone recommend a small and
simple web framework for Python, maybe similar to Perl's
CGI::Application?

Werkzeug[1] should be in your line, I think.

[1] http://werkzeug.pocoo.org/

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Earth to earth, ashes to ashes, dust to dust...
--
http://mail.python.org/mailman/listinfo/python-list


Re: optparse question

2009-01-28 Thread Thorsten Kampe
* Pat (Tue, 27 Jan 2009 14:04:28 -0500)
  I had no idea people were going to get so upset that I used a
  Windows example and go off on a tear.
  
  Nobody is upset, and nobody has gone off on a tear. The point
  about the Windows example is that the docs say in a
  close-to-screamingly- obvious manner that /options are not
  supported, no matter what religion uses them. It was not, and still
  is not, apparent what you really wanted. We're all patiently waiting
  for you to rephrase the question(s).
 
 Sigh. I used an incorrect example (I sincerely apologize to the world
 for that egregious error on my part).
 
 I''m totally cognizant that the documentation states '-'' or '--' need
 to be used for flags.
 
 The question was it possible to add a simple flag like 'd-' to optparse 
 with no other parameters?   I'm guessing from the vitriolic diatribes 
 here that the answer is no.
 [...]
 If you don't want to answer the question or don't have any meaningful
 to add, please don't pollute the forum with further vacuous responses.
 I didn't ask, or expect, you to write the code for me.
 
 christ on a stick, so many of you behave like prima donnas.

You have a problem. The problem is not a Python or a technical one. It's 
described here -
http://en.wikipedia.org/wiki/Attention_Deficit_Syndrome

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


Re: errno 22 instead of errno 2

2009-01-28 Thread Mark Hammond

On 28/01/2009 6:52 PM, Glenn Linderman wrote:

open(c:\abc,rb)

This simple one-line script, produces errno 22 on Python 2.6, but errno
2 on Python 2.5.2

Is this an unintentional regression? Or is this an intentional bug fix?

The file doesn't exist (errno 2) but I guess on Windows it is also
somewhat an invalid file name (errno 22).

Yes, I'm aware that \a is ASCII 007. Using a valid, non-existent file
name produces errno 2 on both versions.



I think you will find that in Python 2.6, the exception object has both 
'errno' and 'winerror' attributes, which more accurately reflect the 
source of the 2 different error numbers, where Python 2.5 would often 
store the windows error number in the errno field, leading to what you see.


I tend to use something like winerror = getattr(e, 'winerror', 
e.errno) to handle both cases...


Cheers,

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


Re: Python Package Managment

2009-01-28 Thread David Cournapeau
On Wed, Jan 28, 2009 at 3:16 PM, Bernard Rankin beranki...@yahoo.com wrote:
 [extracted from pylons-discuss]


  I hate to pass the buck, but this is Python's fault for not having
  reliable package management built in.  There's nothing Pylons can do
  about it except switch to another programming language.
  [SNIP]

 Without Setuptools,
 Pylons and TurboGears couldn't exist, and Zope and Twisted
 would not have been able to split themselves into several packages.
 People coming to Python from Perl and Ruby expect to be able to just
 run a command to download and install a package.  That problem was
 solved ten years ago, so why does Python still not have it standard?

 If Setuptools and Virtualenv or the equivalent were built into Python,
 you could trust that every computer that has successfully installed
 Python can install packages and make virtual environments the same
 way..

 That would eliminate 2/3 of the problems users have when
 installing Pylons, and the subsequent need to explain the problems and
 workarounds in the installation docs.  At
 work people say, Half the trouble of Pylons is installing it, and I
 often have to help them install it in person because otherwise they
 get stuck at some error message and have no idea what to do.


 Agreed.  I would even move ipython (or something like it) to core.

 Of course, even Setuptools has a long way to go in some areas. (Installation 
 Rollback, for one.)

 Python is about batteries included, and these are major batteries in most 
 modern environments.

 A CPAN like in-house hosted archive would nice, too.  This way, modules 
 have a better chance of outliving the original author's interest/commitment 
 in paying for, possibly non-trivial, web hosting.

 I'm sure these issues has been discussed to death, but I wonder what the 
 larger Python community thinks.

You may be interested in the following:

http://mail.python.org/pipermail/python-dev/2006-April/063952.html

The thread is two years and a half old, but my impression is that the
situation has not changeed much since. Few if any people are against
improving the situation, but more people are against the currently
available solutions (setuptools, virtualenv, etc...).

cheers,

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


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread Brian Blais

On Jan 27, 2009, at 16:19 , excord80 wrote:


I need to make a small, relatively low-traffic site that users can
create accounts on and log into. Scripts must run as cgi (no
mod_python or FastCGI is available). Can anyone recommend a small and
simple web framework for Python, maybe similar to Perl's
CGI::Application?

Or would it just be better to roll my own?



I'd strongly suggest webpy (http://webpy.org/).  It is easy, works  
with CGI, FastCGI, etc... or you can run its own built-in server.   
It's very nice!



bb

--
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais



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


Re: ORM recommendation when using live/predefined DB?

2009-01-28 Thread Marco Mariani

Phillip B Oldham wrote:


Can you recommend an ORM (or similar) package to look into?


SQLAlchemy with reflected tables. You can use straight SQL, generate it 
dynamically via python expressions, go with the ORM, or everything 
together (in a bucket :)
It really pays due respect to the RDBMS, and does not try to avoid the 
OO-SQL gap.

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


Re: Drawing and Displaying an Image with PIL

2009-01-28 Thread W. eWatson

r wrote:

Change this line:
draw.line((0,0),(20,140), fill=128)

To This:
draw.line((0,0, 20,140), fill=128)

And you should be good to go. Like you said, if you need to combine 2
tuples you can do:
(1,2)+(3,4)
Yes, that's true, but the big question is how to see the final image? 
Either one employees another module or writes the file into a folder, then 
displays it with a paint program?


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

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


Re: New to python, open source Mac OS X IDE?

2009-01-28 Thread Cameron Laird
In article 33d59aa0-e73b-45f8-bdfe-4c78717c6...@v5g2000prm.googlegroups.com,
joseph.a.mar...@gmail.com joseph.a.mar...@gmail.com wrote:
On Jan 27, 6:47 pm, André andre.robe...@gmail.com wrote:
 On Jan 27, 7:06 pm, joseph.a.mar...@gmail.com

 joseph.a.mar...@gmail.com wrote:
  Greetings! I've heard enough raving about Python, I'm going to see for
  myself what all the praise is for!

  I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you
  even use an IDE for Python?

 If you already use netbeans, what
abouthttp://www.netbeans.org/features/python/
 ?


Wow, you guys are fast... yes, I was having trouble deciding between
that (Netbeans), Smultron, or TextWrangler. Thanks!

As already mentioned, both Netbeans and Komodo are good choices.
A few more comments about these two appear in URL:
http://ldn.linuxfoundation.org/column/debuggers-and-debugging .
--
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, open source Mac OS X IDE?

2009-01-28 Thread Patrick Steiger
I would recommend Netbeans with Python plugin, Eric4 and Komodo Edit, with
descending order of preference

2009/1/27 joseph.a.mar...@gmail.com joseph.a.mar...@gmail.com

 Greetings! I've heard enough raving about Python, I'm going to see for
 myself what all the praise is for!

 I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you
 even use an IDE for Python?

 Any recommendations on open source Python environments?

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




-- 
I May Be the Walrus.
--
http://mail.python.org/mailman/listinfo/python-list


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread koranthala
On Jan 28, 2:16 am, Reckoner recko...@gmail.com wrote:
 I'm not sure this is possible, but I would like to have
 a list of  objects

 A=[a,b,c,d,...,z]

 where,  in the midst of a lot of processing I might do something like,

 A[0].do_something_which_changes_the_properties()

 which alter the properties of the object 'a'.

 The trick is that I would like A to be mysteriously aware that
 something about the  object 'a' has changed so that when I revisit A,
 I will know that the other items in the list need to be refreshed to
 reflect the changes in A as a result of changing 'a'.

 Even better would be to automatically percolate the subsequent changes
 that resulted from altering 'a' for the rest of the items in the list.
 Naturally, all of these items are related in some parent-child
 fashion.

 that might be a lot to ask, however.

 Any advice appreciated.

I think Python Cookbook has a recipe which deals with this.
- 6.12 Checking an Instance for Any State Change.
--
http://mail.python.org/mailman/listinfo/python-list


bigint to timestamp

2009-01-28 Thread Shah Sultan Alam
Hi Group,
I have file with contents retrieved from mysql DB.
which has a time field with type defined bigint(20)
I want to parse that field into timestamp format(-MM-DD HH:MM:SS
GMT) using python code.
The value I found for that field is 212099016004150509
Give me sample code that does the conversion.

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


Re: Drawing and Displaying an Image with PIL

2009-01-28 Thread Peter Otten
W. eWatson wrote:

 r wrote:
 Change this line:
 draw.line((0,0),(20,140), fill=128)
 
 To This:
 draw.line((0,0, 20,140), fill=128)
 
 And you should be good to go. Like you said, if you need to combine 2
 tuples you can do:
 (1,2)+(3,4)
 Yes, that's true, but the big question is how to see the final image?
 Either one employees another module or writes the file into a folder, then
 displays it with a paint program?

For debugging purposes you can just invoke the show() method

im = Image.open(...)
# modify image
im.show() 

If you want to integrate the image into your own Tkinter program -- that is
explained here:

http://effbot.org/tkinterbook/photoimage.htm

Following these instruction you code might become

import Tkinter as tk
import Image
import ImageTk
import ImageDraw
import sys

filename = sys.argv[1]
im = Image.open(filename)

draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line(((0,0),(20,140)), fill=128)


root = tk.Tk()
pi = ImageTk.PhotoImage(im)
label = tk.Label(root, image=pi)
label.pack()
root.mainloop()

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


Re: Python Application Server

2009-01-28 Thread Cameron Laird
In article mailman.8176.1233117922.3487.python-l...@python.org,
James Mills  prolo...@shortcircuit.net.au wrote:
On Wed, Jan 28, 2009 at 2:42 PM, James Mills
prolo...@shortcircuit.net.au wrote:
(...)

 Might I recommend circuits (1) as a general purpose
 framework that you can build your application on top of.

 circuits will allow you to communicate with long-running
 background processes, communicate between processes
 (by way of a Bridge). All communication in circuits is
 asyncroneous. circuits has also recently seen the integration
 of the multiprocessing package from python 2.6/3.0 so you
 can create processes and have inter-process communication
 seamlessly. In fact, parts of your system can even run on other
 nodes (you mentioned clustering).

I should probably mention some of the components available (features);
 * TCPServer, TCPClient
 * UDPServer, UDPClient
 * HTTP, IRC and SMTP protocols
 * Web Server (with limited WSGI support) (depends on parts of CherryPy)
 * Timers, Timer
 * Logger, Debugger
 * ... there are many more components ... :)

Building new components is fairly easy as well.
.
.
.
The big question will be whether circuits qualifies for
the original poster as an application server.  I agree,
though, that, by the definition as it appeared at the
beginning of this thread, circuits seems to be the best
candidate.
--
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, open source Mac OS X IDE?

2009-01-28 Thread 7stud
On Jan 27, 6:07 pm, Burukena buruk...@gmail.com wrote:
 On 1/27/09 8:44 PM, James Stroud wrote:

  joseph.a.mar...@gmail.com wrote:
  Greetings! I've heard enough raving about Python, I'm going to see for
  myself what all the praise is for!

  I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you
  even use an IDE for Python?

  Any recommendations on open source Python environments?

  Thanks!

  Try open komodo. I haven't used it because vim is my IDE, but it looks
  pretty good.

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

 Vim and a terminal works for me, specifically with screen.

What does 'with screen' mean?

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


Re: Drawing and Displaying an Image with PIL

2009-01-28 Thread Bill McClain
On 2009-01-28, W. eWatson notval...@sbcglobal.net wrote:
 Yes, that's true, but the big question is how to see the final image? 
 Either one employees another module or writes the file into a folder, then 
 displays it with a paint program?

Does im.show() not work?

-Bill
-- 
Sattre Press  Tales of War
http://sattre-press.com/   by Lord Dunsany
i...@sattre-press.com http://sattre-press.com/tow.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Addition of multiprocessing ill-advised? (was: Python 3.0.1)

2009-01-28 Thread Jesse Noller
On Tue, Jan 27, 2009 at 11:36 PM, James Mills
prolo...@shortcircuit.net.au wrote:
 On Wed, Jan 28, 2009 at 1:49 PM, Ben Finney b...@benfinney.id.au wrote:
 Steve Holden st...@holdenweb.com writes:
 I think that [Python 2.6 was a rushed release]. 2.6 showed it in the
 inclusion (later recognizable as somewhat ill-advised so late in the
 day) of multiprocessing […]

 Steve: It's just a new package - it used to be available
 as a 3rd-party package. I dare say it most definitely was
 -not- ill-advised. It happens to be a great addition to the
 standard library.

 What was ill-advised about the addition of the 'multiprocessing'
 module to Python 2.6? I ask because I haven't yet used it in anger,
 and am not sure what problems have been found in it.

 I have found no problems with it - I've recently integrated it with my
 event/component framework (1). In my library I use Process, Pipe
 and Value.

 cheers
 James


Awesome James, I'll be adding this to both the multiprocessing talk,
and the distributed talk. Let me know if you have any issues.

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


Re: New to python, open source Mac OS X IDE?

2009-01-28 Thread aspersieman

7stud wrote:

On Jan 27, 6:07 pm, Burukena buruk...@gmail.com wrote:
  

On 1/27/09 8:44 PM, James Stroud wrote:



joseph.a.mar...@gmail.com wrote:
  

Greetings! I've heard enough raving about Python, I'm going to see for
myself what all the praise is for!

I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you

even use an IDE for Python?

Any recommendations on open source Python environments?

Thanks!


Try open komodo. I haven't used it because vim is my IDE, but it looks
pretty good.
  
James

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

Vim and a terminal works for me, specifically with screen.



What does 'with screen' mean?
  

http://www.gnu.org/software/screen/

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

  


--
Vince Noir: Howard... Howard... Howard... Howard... Howard... Howard... 
Howard... Howard... Howard... Howard... Howard... Howard?
Howard Moon: This better be good.
Vince Noir: You know the black bits in bananas, are they tarantulas' eggs?
Howard Moon: Please don't speak to me ever again in your life. 

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


Re: Addition of multiprocessing ill-advised?

2009-01-28 Thread Steve Holden
James Mills wrote:
 On Wed, Jan 28, 2009 at 1:49 PM, Ben Finney b...@benfinney.id.au wrote:
 Steve Holden st...@holdenweb.com writes:
 I think that [Python 2.6 was a rushed release]. 2.6 showed it in the
 inclusion (later recognizable as somewhat ill-advised so late in the
 day) of multiprocessing […]
 
 Steve: It's just a new package - it used to be available
 as a 3rd-party package. I dare say it most definitely was
 -not- ill-advised. It happens to be a great addition to the
 standard library.
 
 What was ill-advised about the addition of the 'multiprocessing'
 module to Python 2.6? I ask because I haven't yet used it in anger,
 and am not sure what problems have been found in it.
 
 I have found no problems with it - I've recently integrated it with my
 event/component framework (1). In my library I use Process, Pipe
 and Value.
 
It will be a great library in time, but the code was immature and
insufficiently tested before the 2.6 release. The decision to include it
late in the release cycle

There are 32 outstanding issues on multiprocessing, two of them critical
and four high. Many of them are platform-specific, so if they don't hit
your platform you won't mind.

Jesse did a great job in the time available. It would have been more
sensible to wait until 2.7 to include it in the library, IMHO, or make
the decision to include it in 2.6 in a more timely fashion. The one
advantage of the inclusion is that the issues have been raised now, so
as long as maintenance continues the next round will be better.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: bigint to timestamp

2009-01-28 Thread Ulrich Eckhardt
Shah Sultan Alam wrote:
 I have file with contents retrieved from mysql DB.
 which has a time field with type defined bigint(20)
 I want to parse that field into timestamp format(-MM-DD HH:MM:SS
 GMT) using python code.

Try time.strftime.

 The value I found for that field is 212099016004150509

That looks like a bit big for digestion by strftime, so I'd suggest you
first find out what the unit and offset of the value in your DB actually
is.
 
Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: need help

2009-01-28 Thread Steve Holden
juvy j wrote:
 Hi guys,
  
 need help on how to read file from other server(linux).
  
Which service do you plan to use: FTP, HTTP and NFS are three
possibilities that immediately come to mind, all well handled by {ython
standard library modules. A little more background might help.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Addition of multiprocessing ill-advised? (was: Python 3.0.1)

2009-01-28 Thread Jesse Noller
On Tue, Jan 27, 2009 at 10:49 PM, Ben Finney b...@benfinney.id.au wrote:
 (Continuing a side topic of a different discussion)

 Steve Holden st...@holdenweb.com writes:

 I think that [Python 2.6 was a rushed release]. 2.6 showed it in the
 inclusion (later recognizable as somewhat ill-advised so late in the
 day) of multiprocessing […]

 What was ill-advised about the addition of the 'multiprocessing'
 module to Python 2.6? I ask because I haven't yet used it in anger,
 and am not sure what problems have been found in it.

 --
  \  Holy bouncing boiler-plated fits, Batman! —Robin |
  `\   |
 _o__)  |
 Ben Finney
 --
 http://mail.python.org/mailman/listinfo/python-list


I might write a longer blog post about this later, but I can see
Steve's point of view. The fact is, pyprocessing/multiprocessing was a
late addition to Python 2.6. Personally, I was game to put it into
either 2.7 or 2.6, but I felt inclusion into 2.6 wasn't completely out
of question - and others agreed with me.

See these mail threads:

http://mail.python.org/pipermail/python-dev/2008-May/079417.html
http://mail.python.org/pipermail/python-dev/2008-June/080011.html

And so on.

All of that being said; the initial conversion and merging of the code
into core exposed a lot of bugs I and others didn't realize were there
in the first place. I take full responsibility for that - however some
of those bugs were in python-core itself (deadlock after fork
anyone?).

So, the road to inclusion was a bit rougher than I initially thought -
I relied heavily on the skills of people who had more experience in
the core than I did, and it was disruptive to the release schedule of
python 2.6 due to both the bugs and instability.

I however; disagree that this was ultimately a bad decision, or that
it was some how indicative of a poorly managed or rushed 2.6 release.
All releases have bugs, and towards the end of the 2.6 cycle,
multiprocessing *was not* the release blocker.

After 2.6 went out, I had a small wave of bugs filed against
multiprocessing that I've been working through bit by bit (I still
need to work on BSD/Solaris issues) and some of the bugs have exposed
issues I simply wish weren't there but I think this is true of any
package, especially one as complex as multiprocessing is.

I know of plenty of people using the package now, and I know of
several groups switching to 2.6 as quickly as possible due to its new
features, bug fixes/etc. Multiprocessing as a package is not bug free
- I'm the first to admit that - however it is useful, and being used
and frankly, I maintain that it is just one step in a larger project
to bring additional concurrency and distributed stuff into
python-core over time.

So yes, I see Steve's point - multiprocessing *was* disruptive, and it
inclusion late in the game siphoned off resources that could have been
used elsewhere. Again, I'll take the responsibility for soiling the
pool this way. I do however think, that python 2.6 is overall a
*fantastic* release both feature wise, quality wise and is quite
useful for people who want to get things done (tm).

Now I'm going to go back to fixing bugs.

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


Re: Addition of multiprocessing ill-advised?

2009-01-28 Thread Jesse Noller
On Wed, Jan 28, 2009 at 8:32 AM, Steve Holden st...@holdenweb.com wrote:
...snip...
 I have found no problems with it - I've recently integrated it with my
 event/component framework (1). In my library I use Process, Pipe
 and Value.

 It will be a great library in time, but the code was immature and
 insufficiently tested before the 2.6 release. The decision to include it
 late in the release cycle

 There are 32 outstanding issues on multiprocessing, two of them critical
 and four high. Many of them are platform-specific, so if they don't hit
 your platform you won't mind.


See my reply to the thread I just sent out; I don't disagree with you.
However, there are not 32 open bugs:

http://bugs.python.org/issue?%40search_text=title=%40columns=titleid=%40columns=idcreation=creator=activity=%40columns=activity%40sort=activityactor=nosy=type=components=versions=dependencies=assignee=jnollerkeywords=priority=%40group=prioritystatus=1%40columns=statusresolution=%40pagesize=50%40startwith=0%40queryname=%40old-queryname=%40action=search

Man, I hope that url comes through. As of this writing, there are 18
open bugs assigned to me for resolution. Of those, 2 are critical, but
should not be - one is an enhancement I am on the fence about, and one
is for platforms which have issues with semaphore support.

However, I agree that there are bugs, and there will continue to be
bugs. I think the quality has greatly increased since the port to core
started, and we did find bugs in core as well. I also think it is more
than ready for use now.

 Jesse did a great job in the time available. It would have been more
 sensible to wait until 2.7 to include it in the library, IMHO, or make
 the decision to include it in 2.6 in a more timely fashion. The one
 advantage of the inclusion is that the issues have been raised now, so
 as long as maintenance continues the next round will be better.

Again, I don't disagree. Alas, the PEP resolution and proposal was
greatly delayed due to, well, someone paying me money to do something
else ;) - that being said, yes, the decision was made late in the
game, and was disruptive.

Maintenance is going to continue as long as I continue to have an
internet connection. Heck, there are enhancements to it I really want
to add, but I swore off those until the bugs are closed/resolved and
my pycon talks are in the can.

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


Re: bigint to timestamp

2009-01-28 Thread Steve Holden
Shah Sultan Alam wrote:
 Hi Group,
 I have file with contents retrieved from mysql DB.
 which has a time field with type defined bigint(20)
 I want to parse that field into timestamp format(-MM-DD HH:MM:SS
 GMT) using python code.
 The value I found for that field is 212099016004150509
 Give me sample code that does the conversion.
 
Please?

Perhaps you could tell us what date and time 212099016004150509 is
supposed to represent? The classic format is seconds since the Unix
epoch but that isn't what this is:

 time.localtime(212099016004150509)
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: timestamp out of range for platform time_t

Neither does it appear to be a MySQL TIME field, since the maximum value
for that would appear to be

 ((838*60)+59)*60+59
3020399

So, just what is this field? What do the values mean?

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: need help

2009-01-28 Thread Tim Chase

need help on how to read file from other server(linux).
 

Which service do you plan to use: FTP, HTTP and NFS are three
possibilities that immediately come to mind,


Or scp, or sftp, or rsync, or SMB, or AFS, or IMAP, or POP3, or 
instant-message, or VCS sync (svn/hg/git/bzr/cvs/darcs/whatever) 
or ...


and via push or pull?


A little more background might help.


indeed, for the OP:

http://catb.org/~esr/faqs/smart-questions.html

-tkc



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


Re: Python Application Server

2009-01-28 Thread Adi Eyal
Hi All

Thanks for the responses - I'll look into Circuits and Twisted, the
both seem to be relevant.

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


Re: Addition of multiprocessing ill-advised?

2009-01-28 Thread Steve Holden
Jesse Noller wrote:
[...]
 So yes, I see Steve's point - multiprocessing *was* disruptive, and it
 inclusion late in the game siphoned off resources that could have been
 used elsewhere. Again, I'll take the responsibility for soiling the
 pool this way. I do however think, that python 2.6 is overall a
 *fantastic* release both feature wise, quality wise and is quite
 useful for people who want to get things done (tm).
 
Overall I completely agree. And I don't think the decision to include it
was down to you anyway, though you were certainly urging it. It was a
release management issue. And 2.6 *is* a good release.

 Now I'm going to go back to fixing bugs.
 
Don't forget those PyCon talks!

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Best/better way? (histogram)

2009-01-28 Thread Bernard Rankin


 
 The simplest. That would be #3, cleaned up a bit:
 
 from collections import defaultdict
 from csv import DictReader
 from pprint import pprint
 from operator import itemgetter
 
 def rows(filename):
 infile = open(filename, rb)
 for row in DictReader(infile):
 yield row[CATEGORIES]
 
 def stats(values):
 histo = defaultdict(int)
 for v in values:
 histo[v] += 1
 return sorted(histo.iteritems(), key=itemgetter(1), reverse=True)
 
 Should you need the inner dict (which doesn't seem to offer any additional
 information) you can always add another step:
 
 def format(items):
 result = []
 for raw, count in items:
 leaf = raw.rpartition(|)[2]
 result.append((raw, dict(count=count, leaf=leaf)))
 return result
 
 pprint(format(stats(rows(sampledata.csv))), indent=4, width=60)
 
 By the way, if you had broken the problem in steps like above you could have
 offered four different stats() functions which would would have been a bit
 easier to read...
 


Thank you.  The code reorganization does make make it easer to read.

I'll have to look up the docs on itemgetter()

:)


  

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


Re: bigint to timestamp

2009-01-28 Thread Jon Clements
On Jan 28, 1:50 pm, Steve Holden st...@holdenweb.com wrote:
 Shah Sultan Alam wrote:
  Hi Group,
  I have file with contents retrieved from mysql DB.
  which has a time field with type defined bigint(20)
  I want to parse that field into timestamp format(-MM-DD HH:MM:SS
  GMT) using python code.
  The value I found for that field is 212099016004150509
  Give me sample code that does the conversion.

 Please?

 Perhaps you could tell us what date and time 212099016004150509 is
 supposed to represent? The classic format is seconds since the Unix
 epoch but that isn't what this is:

  time.localtime(212099016004150509)

 Traceback (most recent call last):
   File stdin, line 1, in module
 ValueError: timestamp out of range for platform time_t

 Neither does it appear to be a MySQL TIME field, since the maximum value
 for that would appear to be

  ((838*60)+59)*60+59

 3020399

 So, just what is this field? What do the values mean?

 regards
  Steve
 --
 Steve Holden        +1 571 484 6266   +1 800 494 3119
 Holden Web LLC              http://www.holdenweb.com/

Bit hard to guess without the actual date to compare to... and I'm a
bit busy, but thought I'd throw this in the pool: I'm guessing it's a
MySQL database that's had data put into it via a .NET application
using the .NET DateTime (so a 20 byte int sounds about right IIRC),
which is based on the number of ticks since Jan 1, 1 I think that
should end up around 2[18ish digits here...]...

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


Re: A Twisted Design Decision

2009-01-28 Thread Jean-Paul Calderone

On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala koranth...@gmail.com 
wrote:

On Jan 27, 9:27 pm, koranthala koranth...@gmail.com wrote:

On Jan 27, 6:57 pm, Jean-Paul Calderone exar...@divmod.com wrote:

[snip]


Thank you Jean-Paul.
My code is more complex than what I have mentioned. When I mentioned
msg.send, the msg object actually gets the data from DB etc to send.
And there are many other items being done.
I will try to see whether I can change the code to incorporate what
you mentioned.

I rewrote most of my code after learning just raw deferreds - I had
planned to study inlineCallbacks - but then it slipped my mind  - now
it has come to bit me. :-(


Hi,
 I tried to update the code as per the suggestion, but to no avail.
 My system uses Python2.4.3 (cannot move to 2.5) - so I tried to
rewrite with deferredGenerators - since I thought inlineCallbacks are
similar to deferredGenerators.

 But I cannot seem to rewrite it in a format where the functional
encapsulation is not broken.
 i.e. as I mentioned in the first example - I have to pass SELF to
child objects for them to modify it.


Why?  You don't do this in the original version of your code.  Why do
it after switching to Twisted (particularly since you seem to want *not*
to)?

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


Re: Python Application Server

2009-01-28 Thread bobicanprogram
On Jan 27, 11:23 pm, Adi Eyal a...@digitaltrowel.com wrote:
 Hi All

 Could anyone recommend a python application server? My application
 consists mainly of long running background processes that need to
 communicate with each other. Features on my wishlist include, process
 pooling (each process will in general be stateless), monitoring,
 scheduling and a framework for inter-process communication. Ideally, I
 would also like to be able to cluster the app server if the need
 arises. I have never used Zope or Webware, but my impression is that
 these servers are focused on web applications with a short
 request-response cycle. My usage will be different since my processes
 will be triggered by certain events and then continue running until
 they complete, without sending any response at all but possibly
 spawning off additional processes in a workflow.

 I hope my description has been clear. Does such an application server
 exist for python?

 Thanks in advance
 Adi


You might want to look into the SIMPL project stuff (http://
www.icanprogram.com/simpl).   In particular there is a framework
(SIMPL calls them softwareICs) called a proxy which sounds like
exactly what you might want.

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


Re: Calling Python-tk code from C/C++

2009-01-28 Thread bobicanprogram
On Jan 27, 12:29 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:
 En Tue, 27 Jan 2009 07:42:01 -0200, Rajorshi Biswas rajor...@in.com
 escribió:

  Hello all, This is my first post to this mailing list. Our requirement
  is to invoke a Tkinter python panel from a C++ GUI app where both GUI
  windows would run in 2 separate threads. We have written a sample PyQt
  application which calls this Tk panel using something like this:class
  TkPanel(threading.Thread):def run(self): # call showPaneldef
  showPanel():# create window = Tk.Tk() window.mainloop()def start():t =
  TkPanel()t.start()Now we call this from our main python code:def
  startPanel(self): import tkPanel tkPanel.start() # this calls
  tkwindow.mainloop() in a separate thread.This works absolutely fine when
  the invoking app is Python.

  From the above description I don't see where PyQt is involved. Do you
 really want to mix Qt and Tk in the same application? I don't think they
 could coexist...
 --
 Gabriel Genellina


Check out the SIMPL project (http://www.icanprogram.com/simpl).
Using that toolkit you should be able to have your C++ module exchange
a message with a separate Python/Tk/SIMPL module.This might do
what you are after.

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


how to optimize object creation/reading from file?

2009-01-28 Thread perfreem
hi,

i am doing a series of very simple string operations on lines i am
reading from a large file (~15 million lines). i store the result of
these operations in a simple instance of a class, and then put it
inside of a hash table. i found that this is unusually slow... for
example:

class myclass(object):
__slots__ = (a, b, c, d)
def __init__(self, a, b, c, d):
self.a = a
self.b = b
self.c = c
self.d = d
def __str__(self):
return %s_%s_%s_%s %(self.a, self.b, self.c, self.d)
def __hash__(self):
return hash((self.a, self.b, self.c, self.d))
def __eq__(self, other):
return (self.a == other.a and \
self.b == other.b and \
self.c == other.c and \
self.d == other.d)
__repr__ = __str__

n = 1500
table = defaultdict(int)
t1 = time.time()
for k in range(1, n):
myobj = myclass('a' + str(k), 'b', 'c', 'd')
table[myobj] = 1
t2 = time.time()
print time: , float((t2-t1)/60.0)

this takes a very long time to run: 11 minutes!. for the sake of the
example i am not reading anything from file here but in my real code i
do. also, i do 'a' + str(k) but in my real code this is some simple
string operation on the line i read from the file. however, i found
that the above code shows the real bottle neck, since reading my file
into memory (using readlines()) takes only about 4 seconds. i then
have to iterate over these lines, but i still think that is more
efficient than the 'for line in file' approach which is even slower.

in the above code is there a way to optimize the creation of the class
instances ? i am using defaultdicts instead of ordinary ones so i dont
know how else to optimize that part of the code. is there a way to
perhaps optimize the way the class is written? if takes only 3 seconds
to read in 15 million lines into memory it doesnt make sense to me
that making them into simple objects while at it would take that much
more...
--
http://mail.python.org/mailman/listinfo/python-list


Re: A Twisted Design Decision

2009-01-28 Thread koranthala
On Jan 28, 7:10 pm, Jean-Paul Calderone exar...@divmod.com wrote:
 On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala koranth...@gmail.com 
 wrote:
 On Jan 27, 9:27 pm, koranthala koranth...@gmail.com wrote:
  On Jan 27, 6:57 pm, Jean-Paul Calderone exar...@divmod.com wrote:
  [snip]

  Thank you Jean-Paul.
  My code is more complex than what I have mentioned. When I mentioned
  msg.send, the msg object actually gets the data from DB etc to send.
  And there are many other items being done.
  I will try to see whether I can change the code to incorporate what
  you mentioned.

  I rewrote most of my code after learning just raw deferreds - I had
  planned to study inlineCallbacks - but then it slipped my mind  - now
  it has come to bit me. :-(

 Hi,
   I tried to update the code as per the suggestion, but to no avail.
   My system uses Python2.4.3 (cannot move to 2.5) - so I tried to
 rewrite with deferredGenerators - since I thought inlineCallbacks are
 similar to deferredGenerators.

   But I cannot seem to rewrite it in a format where the functional
 encapsulation is not broken.
   i.e. as I mentioned in the first example - I have to pass SELF to
 child objects for them to modify it.

 Why?  You don't do this in the original version of your code.  Why do
 it after switching to Twisted (particularly since you seem to want *not*
 to)?

 Jean-Paul

Without that, I am unable to increment success and failure counters
which are part of the message handler object.
In the original version, if send fails the return value of
protocol.send is propogated back to msg.send and to msg handler.send.
But in twisted, it is not so. So, I have to pass in SELF through to
increment success and failure counter.
Is it possible otherwise in twisted?
--
http://mail.python.org/mailman/listinfo/python-list


Python 3.0, 'Hello' 42

2009-01-28 Thread towitowi
Hello,

In the 3.0 changes list there is mentioned that -compares are not
supported anymore if the compared types are different (except
numbers). Like
  42  Hello
did return True of False depending on the implementation but is now a
TypeError.

But the document also mentions that the result is not strictly
undefined but reproducable undetermined. Meaning, that on a given
machine with a given python implementation result will always be the
same. But on another machine, or with another python implementation,
it might give a different result.

My question now is, why this is? E.g, Is there an integer large enough
so that the result changes? What circumstances influence the result?

Thanks in advance.

tschau, towi.
--
http://mail.python.org/mailman/listinfo/python-list


RE: How to execute a hyperlink?

2009-01-28 Thread Barak, Ron
Hi Muddy,

http://docs.python.org/library/urllib2.html may help.

Bye,
Ron.

-Original Message-
From: Muddy Coder [mailto:cosmo_gene...@yahoo.com]
Sent: Wednesday, January 28, 2009 03:00
To: python-list@python.org
Subject: How to execute a hyperlink?

Hi Folks,

Module os provides a means of running shell commands, such as:

import os
os.system('dir .')

will execute command dir

I think a hyperlink should also be executed. I tried:

os.system('http://somedomain.com/foo.cgi?name=foopasswd=bar')

but I got kicked out by the Python interpreter. I wonder somebody knows the 
syntax of triggering a hyperlink? Thanks in advance!


Muddy Coder

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


Re: how to optimize object creation/reading from file?

2009-01-28 Thread Bruno Desthuilliers

perfr...@gmail.com a écrit :

hi,

i am doing a series of very simple string operations on lines i am
reading from a large file (~15 million lines). i store the result of
these operations in a simple instance of a class, and then put it
inside of a hash table. i found that this is unusually slow... for
example:

class myclass(object):
__slots__ = (a, b, c, d)
def __init__(self, a, b, c, d):
self.a = a
self.b = b
self.c = c
self.d = d
def __str__(self):
return %s_%s_%s_%s %(self.a, self.b, self.c, self.d)
def __hash__(self):
return hash((self.a, self.b, self.c, self.d))
def __eq__(self, other):
return (self.a == other.a and \
self.b == other.b and \
self.c == other.c and \
self.d == other.d)
__repr__ = __str__



If your class really looks like that, a tuple would be enough.


n = 1500
table = defaultdict(int)
t1 = time.time()
for k in range(1, n):


hint : use xrange instead.


myobj = myclass('a' + str(k), 'b', 'c', 'd')
table[myobj] = 1


hint : if all you want is to ensure unicity, use a set instead.


t2 = time.time()
print time: , float((t2-t1)/60.0)


hint : use timeit instead.


this takes a very long time to run: 11 minutes!. for the sake of the
example i am not reading anything from file here but in my real code i
do. also, i do 'a' + str(k) but in my real code this is some simple
string operation on the line i read from the file. however, i found
that the above code shows the real bottle neck, since reading my file
into memory (using readlines()) takes only about 4 seconds. i then
have to iterate over these lines, but i still think that is more
efficient than the 'for line in file' approach which is even slower.


iterating over the file, while indeed a bit slower on a per-line basis, 
avoid useless memory comsuption which can lead to disk swapping - so for 
 huge files, it might still be better wrt/ overall performances.



in the above code is there a way to optimize the creation of the class
instances ? i am using defaultdicts instead of ordinary ones so i dont
know how else to optimize that part of the code. is there a way to
perhaps optimize the way the class is written? if takes only 3 seconds
to read in 15 million lines into memory it doesnt make sense to me
that making them into simple objects while at it would take that much
more...


Did you bench the creation of a 15.000.000 ints list ?-)

But anyway, creating 15.000.000 instances (which is not a small number) 
of your class takes many seconds - 23.466073989868164 seconds on my 
(already heavily loaded) machine. Building the same number of tuples 
only takes about 2.5 seconds - that is, almost 10 times less. FWIW, 
tuples have all the useful characteristics of your above class (wrt/ 
hashing and comparison).


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


Re: New to python, open source Mac OS X IDE?

2009-01-28 Thread Cameron Laird
In article bb128b21-43c4-4cf2-b3db-ede8f9079...@v18g2000pro.googlegroups.com,
7stud  bbxx789_0...@yahoo.com wrote:
.
.
.
 Vim and a terminal works for me, specifically with screen.

What does 'with screen' mean?


URL: http://www.gnu.org/software/screen/ 
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute a hyperlink?

2009-01-28 Thread Jeff McNeil
On Jan 27, 7:59 pm, Muddy Coder cosmo_gene...@yahoo.com wrote:
 Hi Folks,

 Module os provides a means of running shell commands, such as:

 import os
 os.system('dir .')

 will execute command dir

 I think a hyperlink should also be executed. I tried:

 os.system('http://somedomain.com/foo.cgi?name=foopasswd=bar')

 but I got kicked out by the Python interpreter. I wonder somebody
 knows the syntax of triggering a hyperlink? Thanks in advance!

 Muddy Coder

Like others have said, if you want a browser window, use the
'webbrowser' module. If you're looking to simply trigger a GET/POST
without the UI aspect, then you'll probably want urllib or urllib2.

Thanks,

Jeff
mcjeff.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


file date/time on windows

2009-01-28 Thread m.banaouas

hi,

I noticed recently that the value of file date/time I get with python:
time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime))
is forwarding by one hour the real file date/time.

Example:
file A.txt: 2009-01-18 16:13
returned valeur:  2009-01-28 15:13

Is there a simple way to get it work correctely  (other than adding always 1
hour ...) ?

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


win32com.client / Trendlines

2009-01-28 Thread mathieu
Hi there,

  I am trying to use win32com.client, but I do not think I fully grasp
the concept. So far I copied chunk of code from the net to write my
script. It worked well until I could not find any example on
Trendlines. According to doc it should be as simple as:

wc.Chart.SeriesCollection(1).Trendlines.Add( type=constants.xlLinear,
name=Linear Trend)

But I get an error:

Traceback (most recent call last):
  File addchart.py, line 65, in ?
wc2.Chart.SeriesCollection(1).Trendlines.Add
( type=constants.xlLinear, name=Linear Trend)
AttributeError: 'function' object has no attribute 'Add'

It looks like Trendlines indeed does not have such member function. Am
I missing something, do I need to generate something particular (eg.
using makepy.py)

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


Re: A Twisted Design Decision

2009-01-28 Thread Jean-Paul Calderone

On Wed, 28 Jan 2009 06:30:32 -0800 (PST), koranthala koranth...@gmail.com 
wrote:

On Jan 28, 7:10 pm, Jean-Paul Calderone exar...@divmod.com wrote:

On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala koranth...@gmail.com 
wrote:
On Jan 27, 9:27 pm, koranthala koranth...@gmail.com wrote:
 On Jan 27, 6:57 pm, Jean-Paul Calderone exar...@divmod.com wrote:
 [snip]

 Thank you Jean-Paul.
 My code is more complex than what I have mentioned. When I mentioned
 msg.send, the msg object actually gets the data from DB etc to send.
 And there are many other items being done.
 I will try to see whether I can change the code to incorporate what
 you mentioned.

 I rewrote most of my code after learning just raw deferreds - I had
 planned to study inlineCallbacks - but then it slipped my mind  - now
 it has come to bit me. :-(

Hi,
  I tried to update the code as per the suggestion, but to no avail.
  My system uses Python2.4.3 (cannot move to 2.5) - so I tried to
rewrite with deferredGenerators - since I thought inlineCallbacks are
similar to deferredGenerators.

  But I cannot seem to rewrite it in a format where the functional
encapsulation is not broken.
  i.e. as I mentioned in the first example - I have to pass SELF to
child objects for them to modify it.

Why?  You don't do this in the original version of your code.  Why do
it after switching to Twisted (particularly since you seem to want *not*
to)?

Jean-Paul


Without that, I am unable to increment success and failure counters
which are part of the message handler object.
In the original version, if send fails the return value of
protocol.send is propogated back to msg.send and to msg handler.send.
But in twisted, it is not so. So, I have to pass in SELF through to
increment success and failure counter.
Is it possible otherwise in twisted?


Why isn't the return value of protocol.send propagated back to msg.send?
It sounds like it should be.

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


Re: Why doesn't eval of generator expression work with locals?

2009-01-28 Thread Gabriel Genellina
En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden st...@holdenweb.com  
escribió:

Gabriel Genellina wrote:

En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern robert.k...@gmail.com
escribió:



I *thought* I did understand this until I came to this example:

1)

id(globals()), id(locals())

(11239760, 11239760)

# ok, globals and locals are the same at the module level

2)

s = (id(n) for n in [globals(),locals()])
list(eval(s))

[11239760, 11239760]  # still the same results

3)

s = (id(n()) for n in [globals,locals])
list(eval(s))

[11239760, 12583248]  # locals() is different


No, locals is different, not locals(). You are looking at two different
functions that return the same object when called in the given context,
that's all.


Perhaps you didn't notice that I shifted the () from right to left. I'm  
always printing the result of *calling* globals and locals -- the only  
change is *where* I do call them.



[id(n) for n in [globals(),locals()]]

[11239760, 11239760]

[id(n()) for n in [globals,locals]]

[11239760, 12583248]

Seems that it is important *when* those functions are evaluated, but I
don't understand *why*...


--
Gabriel Genellina

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


Re: win32com.client / Trendlines

2009-01-28 Thread mathieu
On Jan 28, 4:21 pm, mathieu mathieu.malate...@gmail.com wrote:
 Hi there,

   I am trying to use win32com.client, but I do not think I fully grasp
 the concept. So far I copied chunk of code from the net to write my
 script. It worked well until I could not find any example on
 Trendlines. According to doc it should be as simple as:

 wc.Chart.SeriesCollection(1).Trendlines.Add( type=constants.xlLinear,
 name=Linear Trend)

 But I get an error:

 Traceback (most recent call last):
   File addchart.py, line 65, in ?
     wc2.Chart.SeriesCollection(1).Trendlines.Add
 ( type=constants.xlLinear, name=Linear Trend)
 AttributeError: 'function' object has no attribute 'Add'

 It looks like Trendlines indeed does not have such member function. Am
 I missing something, do I need to generate something particular (eg.
 using makepy.py)


Ok found it.

trend = wc2.Chart.SeriesCollection(1).Trendlines().Add
(Type=constants.xlLinear, Name=Linear Trend)
trend.DisplayRSquared = True
trend.DisplayEquation = True

Trendlines is a function...

Sorry for the noise, win32com really rocks !

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


Re: New to python, open source Mac OS X IDE?

2009-01-28 Thread Kevin Walzer

joseph.a.mar...@gmail.com wrote:

Greetings! I've heard enough raving about Python, I'm going to see for
myself what all the praise is for!

I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you
even use an IDE for Python?

Any recommendations on open source Python environments?

Thanks!


I use IDLE + Terminal myself. IDLE has improved a lot on the Mac in 
recent years.


Another good tool is Aquamacs, a Mac-optimized version of Emacs: 
http://aquamacs.org



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


Re: file date/time on windows

2009-01-28 Thread MRAB

m.banaouas wrote:

hi,

I noticed recently that the value of file date/time I get with python:
time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime))
is forwarding by one hour the real file date/time.

Example:
file A.txt: 2009-01-18 16:13
returned valeur:  2009-01-28 15:13

Is there a simple way to get it work correctely  (other than adding always 1
hour ...) ?


time.gmtime(), as the name suggests, returns GMT (UTC).

From your email address I presume you're in France, which is GMT+1.

Windows Explorer shows the file time in local time, which for you is 
currently GMT+1, but when the clocks go forward (DST) it'll be GMT+2.

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


Re: how to optimize object creation/reading from file?

2009-01-28 Thread perfreem
On Jan 28, 10:06 am, Bruno Desthuilliers bruno.
42.desthuilli...@websiteburo.invalid wrote:
 perfr...@gmail.com a écrit :



  hi,

  i am doing a series of very simple string operations on lines i am
  reading from a large file (~15 million lines). i store the result of
  these operations in a simple instance of a class, and then put it
  inside of a hash table. i found that this is unusually slow... for
  example:

  class myclass(object):
      __slots__ = (a, b, c, d)
      def __init__(self, a, b, c, d):
          self.a = a
          self.b = b
          self.c = c
          self.d = d
      def __str__(self):
          return %s_%s_%s_%s %(self.a, self.b, self.c, self.d)
      def __hash__(self):
          return hash((self.a, self.b, self.c, self.d))
      def __eq__(self, other):
          return (self.a == other.a and \
                  self.b == other.b and \
                  self.c == other.c and \
                  self.d == other.d)
      __repr__ = __str__

 If your class really looks like that, a tuple would be enough.

  n = 1500
  table = defaultdict(int)
  t1 = time.time()
  for k in range(1, n):

 hint : use xrange instead.

      myobj = myclass('a' + str(k), 'b', 'c', 'd')
      table[myobj] = 1

 hint : if all you want is to ensure unicity, use a set instead.

  t2 = time.time()
  print time: , float((t2-t1)/60.0)

 hint : use timeit instead.

  this takes a very long time to run: 11 minutes!. for the sake of the
  example i am not reading anything from file here but in my real code i
  do. also, i do 'a' + str(k) but in my real code this is some simple
  string operation on the line i read from the file. however, i found
  that the above code shows the real bottle neck, since reading my file
  into memory (using readlines()) takes only about 4 seconds. i then
  have to iterate over these lines, but i still think that is more
  efficient than the 'for line in file' approach which is even slower.

 iterating over the file, while indeed a bit slower on a per-line basis,
 avoid useless memory comsuption which can lead to disk swapping - so for
   huge files, it might still be better wrt/ overall performances.

  in the above code is there a way to optimize the creation of the class
  instances ? i am using defaultdicts instead of ordinary ones so i dont
  know how else to optimize that part of the code. is there a way to
  perhaps optimize the way the class is written? if takes only 3 seconds
  to read in 15 million lines into memory it doesnt make sense to me
  that making them into simple objects while at it would take that much
  more...

 Did you bench the creation of a 15.000.000 ints list ?-)

 But anyway, creating 15.000.000 instances (which is not a small number)
 of your class takes many seconds - 23.466073989868164 seconds on my
 (already heavily loaded) machine. Building the same number of tuples
 only takes about 2.5 seconds - that is, almost 10 times less. FWIW,
 tuples have all the useful characteristics of your above class (wrt/
 hashing and comparison).

 My 2 cents...

thanks for your insight ful reply - changing to tuples made a big
change!
--
http://mail.python.org/mailman/listinfo/python-list


Re: A Twisted Design Decision

2009-01-28 Thread koranthala
On Jan 28, 8:36 pm, Jean-Paul Calderone exar...@divmod.com wrote:
 On Wed, 28 Jan 2009 06:30:32 -0800 (PST), koranthala koranth...@gmail.com 
 wrote:
 On Jan 28, 7:10 pm, Jean-Paul Calderone exar...@divmod.com wrote:
  On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala 
  koranth...@gmail.com wrote:
  On Jan 27, 9:27 pm, koranthala koranth...@gmail.com wrote:
   On Jan 27, 6:57 pm, Jean-Paul Calderone exar...@divmod.com wrote:
   [snip]

   Thank you Jean-Paul.
   My code is more complex than what I have mentioned. When I mentioned
   msg.send, the msg object actually gets the data from DB etc to send.
   And there are many other items being done.
   I will try to see whether I can change the code to incorporate what
   you mentioned.

   I rewrote most of my code after learning just raw deferreds - I had
   planned to study inlineCallbacks - but then it slipped my mind  - now
   it has come to bit me. :-(

  Hi,
    I tried to update the code as per the suggestion, but to no avail.
    My system uses Python2.4.3 (cannot move to 2.5) - so I tried to
  rewrite with deferredGenerators - since I thought inlineCallbacks are
  similar to deferredGenerators.

    But I cannot seem to rewrite it in a format where the functional
  encapsulation is not broken.
    i.e. as I mentioned in the first example - I have to pass SELF to
  child objects for them to modify it.

  Why?  You don't do this in the original version of your code.  Why do
  it after switching to Twisted (particularly since you seem to want *not*
  to)?

  Jean-Paul

 Without that, I am unable to increment success and failure counters
 which are part of the message handler object.
 In the original version, if send fails the return value of
 protocol.send is propogated back to msg.send and to msg handler.send.
 But in twisted, it is not so. So, I have to pass in SELF through to
 increment success and failure counter.
 Is it possible otherwise in twisted?

 Why isn't the return value of protocol.send propagated back to msg.send?
 It sounds like it should be.

 Jean-Paul

Thank you very much again Jean-Paul for helping me out.
I am unable to understand how I will be able to propogate the return
value of protocol.send to msg.send.
Maybe I am being foolish - but my understanding is as follows.

In a non-reactor pattern scenario:
msg_handler.send_message calls msg.send which inturn calls
protocol.send.
So, the reply to protocol.send actually goes up the stack till
msg_handler.send_message wherein I can increment/decrement success/
failure counter.

In reactor pattern:
msg_handler.send_message calls msg.send which call protocol.send which
causes a deferred to be created.
Now, when the deferred finishes its work, reactor calls the callback
associated - but the original context (stack etc) is lost.
Now, the only mechanism of interaction is via the parameters passed in
the callback.
This means that msg_handler has to pass in its object to msg.send
which inturn has to send either msg_handler or self to protocol.send
so that it is stored in the parameter to the callback.
When callback is hit, I use this parameter to call methods in each
object.

This is what I was trying to say in my first mail that - Twisted,
being twisted in its behavior is causing quite a lot of
confusion in design decisions - because now I have to break functional
encapsulation - by asking lower layer objects to handler upper layer
objects behaviors.

As I said earlier, maybe I am being completely stupid -  there might
be a very easy and obvious solution. But I cannot seem to get it at
all.

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


Re: How to execute a hyperlink?

2009-01-28 Thread Cameron Laird
In article 8uvfl.45$n_6...@newsfe22.ams2,
Roel Schroeven  rschroev_nospam...@fastmail.fm wrote:
Muddy Coder schreef:
 Hi Folks,
 
 Module os provides a means of running shell commands, such as:
 
 import os
 os.system('dir .')
 
 will execute command dir
 
 I think a hyperlink should also be executed. I tried:
 
 os.system('http://somedomain.com/foo.cgi?name=foopasswd=bar')
 
 but I got kicked out by the Python interpreter. I wonder somebody
 knows the syntax of triggering a hyperlink? Thanks in advance!

As others have said, you can use the webbrowser module for hyperlinks.
Alternatively you can use os.startfile() which works hyperlinks and many
types of files, but only works on Windows (it does the same as
double-clicking in Windows Explorer).
.
.
.
I suspect that os.startfile() will indeed give Muddy Coder
the most immediate satisfaction.  It might interest him,
though, also to experiment with 

  os.system(start %s % URL)

Again, recognize this only gives happy results, in general,
under Win*.
--
http://mail.python.org/mailman/listinfo/python-list


writing large dictionaries to file using cPickle

2009-01-28 Thread perfreem
hello all,

i have a large dictionary which contains about 10 keys, each key has a
value which is a list containing about 1 to 5 million (small)
dictionaries. for example,

mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f':
'world'}, ...],
key2: [...]}

in total there are about 10 to 15 million lists if we concatenate
together all the values of every key in 'mydict'. mydict is a
structure that represents data in a very large file (about 800
megabytes).

what is the fastest way to pickle 'mydict' into a file? right now i am
experiencing a lot of difficulties with cPickle when using it like
this:

from cPickle import pickle
pfile = open(my_file, 'w')
pickle.dump(mydict, pfile)
pfile.close()

this creates extremely large files (~ 300 MB) though it does so
*extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and
it gets slower and slower. it takes almost an hour if not more to
write this pickle object to file.

is there any way to speed this up? i dont mind the large file... after
all the text file with the data used to make the dictionary was larger
(~ 800 MB) than the file it eventually creates, which is 300 MB.  but
i do care about speed...

i have tried optimizing this by using this:

s = pickle.dumps(mydict, 2)
pfile.write(s)

but this takes just as long... any ideas ? is there a different module
i could use that's more suitable for large dictionaries ?
thank you very much.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A Twisted Design Decision

2009-01-28 Thread Chris Mellon
On Wed, Jan 28, 2009 at 10:05 AM, koranthala koranth...@gmail.com wrote:
 On Jan 28, 8:36 pm, Jean-Paul Calderone exar...@divmod.com wrote:
 On Wed, 28 Jan 2009 06:30:32 -0800 (PST), koranthala koranth...@gmail.com 
 wrote:
 On Jan 28, 7:10 pm, Jean-Paul Calderone exar...@divmod.com wrote:
  On Wed, 28 Jan 2009 02:02:57 -0800 (PST), koranthala 
  koranth...@gmail.com wrote:
  On Jan 27, 9:27 pm, koranthala koranth...@gmail.com wrote:
   On Jan 27, 6:57 pm, Jean-Paul Calderone exar...@divmod.com wrote:
   [snip]

   Thank you Jean-Paul.
   My code is more complex than what I have mentioned. When I mentioned
   msg.send, the msg object actually gets the data from DB etc to send.
   And there are many other items being done.
   I will try to see whether I can change the code to incorporate what
   you mentioned.

   I rewrote most of my code after learning just raw deferreds - I had
   planned to study inlineCallbacks - but then it slipped my mind  - now
   it has come to bit me. :-(

  Hi,
I tried to update the code as per the suggestion, but to no avail.
My system uses Python2.4.3 (cannot move to 2.5) - so I tried to
  rewrite with deferredGenerators - since I thought inlineCallbacks are
  similar to deferredGenerators.

But I cannot seem to rewrite it in a format where the functional
  encapsulation is not broken.
i.e. as I mentioned in the first example - I have to pass SELF to
  child objects for them to modify it.

  Why?  You don't do this in the original version of your code.  Why do
  it after switching to Twisted (particularly since you seem to want *not*
  to)?

  Jean-Paul

 Without that, I am unable to increment success and failure counters
 which are part of the message handler object.
 In the original version, if send fails the return value of
 protocol.send is propogated back to msg.send and to msg handler.send.
 But in twisted, it is not so. So, I have to pass in SELF through to
 increment success and failure counter.
 Is it possible otherwise in twisted?

 Why isn't the return value of protocol.send propagated back to msg.send?
 It sounds like it should be.

 Jean-Paul

 Thank you very much again Jean-Paul for helping me out.
 I am unable to understand how I will be able to propogate the return
 value of protocol.send to msg.send.
 Maybe I am being foolish - but my understanding is as follows.

 In a non-reactor pattern scenario:
 msg_handler.send_message calls msg.send which inturn calls
 protocol.send.
 So, the reply to protocol.send actually goes up the stack till
 msg_handler.send_message wherein I can increment/decrement success/
 failure counter.

 In reactor pattern:
 msg_handler.send_message calls msg.send which call protocol.send which
 causes a deferred to be created.
 Now, when the deferred finishes its work, reactor calls the callback
 associated - but the original context (stack etc) is lost.
 Now, the only mechanism of interaction is via the parameters passed in
 the callback.
 This means that msg_handler has to pass in its object to msg.send
 which inturn has to send either msg_handler or self to protocol.send
 so that it is stored in the parameter to the callback.
 When callback is hit, I use this parameter to call methods in each
 object.

 This is what I was trying to say in my first mail that - Twisted,
 being twisted in its behavior is causing quite a lot of
 confusion in design decisions - because now I have to break functional
 encapsulation - by asking lower layer objects to handler upper layer
 objects behaviors.

 As I said earlier, maybe I am being completely stupid -  there might
 be a very easy and obvious solution. But I cannot seem to get it at
 all.


I'm sure you're not completely stupid, but there is an easy and
obvious solution - you should be returning the *deferred* up the
callstack. That will allow the MessageHandler to attach
callbacks/errbacks to it, without needing to pass self all the way
down the call stack and have a proxy object manage it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: writing large dictionaries to file using cPickle

2009-01-28 Thread python
Hi,

Change:

pickle.dump(mydict, pfile)

to:

pickle.dump(mydict, pfile, -1 )

I think you will see a big difference in performance and also a much
smaller file on disk.

BTW: What type of application are you developing that creates so many
dictionaries? Sounds interesting.

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


Re: unable to print Unicode characters in Python 3

2009-01-28 Thread jefm
this is alink explaining how to add new fonts to the command line
(e.g. Lucida Sans Unicode)
http://phatness.com/node/1643
--
http://mail.python.org/mailman/listinfo/python-list


Re: A Twisted Design Decision

2009-01-28 Thread Jean-Paul Calderone

On Wed, 28 Jan 2009 08:05:13 -0800 (PST), koranthala koranth...@gmail.com 
wrote:

On Jan 28, 8:36 pm, Jean-Paul Calderone exar...@divmod.com wrote:

[snip]
Why isn't the return value of protocol.send propagated back to msg.send?
It sounds like it should be.

Jean-Paul


Thank you very much again Jean-Paul for helping me out.
I am unable to understand how I will be able to propogate the return
value of protocol.send to msg.send.
Maybe I am being foolish - but my understanding is as follows.

In a non-reactor pattern scenario:
msg_handler.send_message calls msg.send which inturn calls
protocol.send.
So, the reply to protocol.send actually goes up the stack till
msg_handler.send_message wherein I can increment/decrement success/
failure counter.

In reactor pattern:
msg_handler.send_message calls msg.send which call protocol.send which
causes a deferred to be created.
Now, when the deferred finishes its work, reactor calls the callback
associated - but the original context (stack etc) is lost.
Now, the only mechanism of interaction is via the parameters passed in
the callback.


You can still interact via return values.  You should be thinking about
a Deferred in the same way as you think about a function which returns
a result synchronously.  The Deferred represents the result, even though
it isn't the result itself (since the result doesn't exist yet).  Anything
you would have done by calling a function and then using its return value
you can do by calling a function and then using the Deferred it returns.

I'll try to update the Twisted version of the code you gave previously to
demonstrate this:


   class MessageHandler:
   def send_message(self):
   def handleResult(result):
   if result:
  self.success += 1
   else:
  self.failure += 1 
   if self.execute():

   for i in self.msgs:
   msg.send().addCallback(handleResult)

   class Message:
   def send(self):
   self.h = h   #The message handler object
   self.update_data() #The data to be sent is updated here
   return self.protocol.send()


   class Protocol:
   @deferredGenerator
   def send(self):
   d = waitForDeferred(getPage(url, method, data))
   yield d
   if page received:
   parse page and see parameters
   if parameters:
   yield True
   return
   yield False

See how neither the handler nor the message is passed into the protocol.
The result of the Deferred returned by Protocol.send is instead used by
the handler to do something that the handler knows about.  The encapsulation
is the same as it was in your original example.  The only significant change
is from synchronous return values to Deferred return values.

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


Re: writing large dictionaries to file using cPickle

2009-01-28 Thread perfreem
On Jan 28, 11:32 am, pyt...@bdurham.com wrote:
 Hi,

 Change:

 pickle.dump(mydict, pfile)

 to:

 pickle.dump(mydict, pfile, -1 )

 I think you will see a big difference in performance and also a much
 smaller file on disk.

 BTW: What type of application are you developing that creates so many
 dictionaries? Sounds interesting.

 Malcolm

hi!

thank you for your reply. unfortunately i tried this but it doesn't
change the speed. it's still writing the file extremely slowly.  i'm
not sure why?

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


Re: How many followers of comp.lang.python

2009-01-28 Thread Grant Edwards
On 2009-01-28, Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid 
wrote:

 very interesting. We should have a vote as to who would be the
 most likely candidate, now that would be a good thread :)

 Waste of time as far as I'm concerned.

Usenet?  Wasting time?   Never!

-- 
Grant Edwards   grante Yow! I feel ... JUGULAR ...
  at   
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: writing large dictionaries to file using cPickle

2009-01-28 Thread Christian Heimes
perfr...@gmail.com schrieb:
 but this takes just as long... any ideas ? is there a different module
 i could use that's more suitable for large dictionaries ?
 thank you very much.

Have a look at ZODB.

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


Re: How many followers of comp.lang.python

2009-01-28 Thread Jeremiah Dodds
On Tue, Jan 27, 2009 at 10:07 AM, rantingrick rantingr...@gmail.com wrote:

 I curious of how many are really out there. I have been watching the
 list for some time but basically see the same 10 or so people
 answering questions.

 Reply to this message so we can see how many exists here

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


I'm sure there are a lot more people lurking than actually posting.

I personally do a lot more lurking than posting - plus I post through google
groups at the moment, which means that at least some of the regular posters
won't see what I post.

I've learned an awful lot by lurking the mailing lists, hopefully I'll be
able to contribute more in the future.
--
http://mail.python.org/mailman/listinfo/python-list


Windows PIL installer question

2009-01-28 Thread cjl
Is there any way to run the PIL installer from the command line on
Windows in 'silent' mode, without displaying the install screens or
requiring user interaction?
--
http://mail.python.org/mailman/listinfo/python-list


Re: A Twisted Design Decision

2009-01-28 Thread koranthala
 You can still interact via return values.  You should be thinking about
 a Deferred in the same way as you think about a function which returns
 a result synchronously.  The Deferred represents the result, even though
 it isn't the result itself (since the result doesn't exist yet).  Anything
 you would have done by calling a function and then using its return value
 you can do by calling a function and then using the Deferred it returns.


Oh! This makes it very clear.

Thank you very much Jean-Paul and Chris Mellon.
My view of deferred was very different from this. That was the reason
behind these persistent questions.
My view of deferred was that of it being a mechanism to provide
asynchronous behavior and nothing more.

The twisted documentation explicitly mentions this - 'Twisted’s
Deferred abstraction, which symbolises a ’promised’ result and which
can pass an eventual result to handler functions.' But with my earlier
view I understood it completely differently.

Thank you once more, Jean-Paul  Chris for taking your valuable time
out to help me out.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Process crash with no reason

2009-01-28 Thread gil . shinar
On Jan 27, 5:59 pm, Philip Semanchuk phi...@semanchuk.com wrote:
 On Jan 27, 2009, at 10:34 AM, gil.shi...@gmail.com wrote:



  On Jan 27, 2:10 pm, Tim Golden m...@timgolden.me.uk wrote:
  gil.shi...@gmail.com wrote:
  On Jan 26, 8:40 pm, Philip Semanchuk phi...@semanchuk.com wrote:
  On Jan 26, 2009, at 1:13 PM, gil.shi...@gmail.com wrote:

  Hi All,
  I'm running a program that is acting as a nice interface to  
  sybase'
  replication server. The program is using the cherrypy web  
  service for
  the GUI. The process is crashing every few days with no reason.  
  In the
  log I can see INFO and DEBUG (No ERROR) log lines and I do not  
  get any
  TraceBack python's message. This program is running on solaris 9
  machine.
  Where can I see or what can I do in order to find out what  
  causes the
  process to crash?
  I have tried simulating a traceBack message and I could see this
  traceback message in one of the log files I'm using. When the  
  process
  crashes without my help, I don't have a clue.
  Let me know if you need any other info
  Although Python isn't immune to fatal errors like you describe, I'd
  immediately suspect a 3rd-party module instead, esp. one written  
  in C
  or C++. Are you using anything like that?

  No I do not.

  Then how are you interacting with Sybase?

  I'm using python's functions to run sybase sql commands.

 Can you give a short code sample? I'm unaware of how one would use the  
 standard Python library to talk to Sybase, unless Sybase has a raw  
 socket interface or some such.

First of all I have found the following python's import:

import Sybase


To connect the sybase server we are using the following function:

def _getConnection (self):
db = Sybase.connect(self.dbs, self.login[0], self.login
[1], datetime='auto')
return db


To execute a DBS query, we are using the following function:

def _executeQuery(self, cursor, query, expected_result=None):
try:
self.logger.debug('Executing query:' + query +
', expected:' + str(expected_result))
cursor.execute(query)
except Sybase.DatabaseError, e:
if ((expected_result != None) and (Msg  +
expected_result in str(e))):
return (DBStatus.SUCCESS,
self._getDBMsg(str(e)))
raise Sybase.DatabaseError, self._getDBMsg(str
(e))

return (DBStatus.SUCCESS, )

Do you need anything else?

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


small python-cgi wiki?

2009-01-28 Thread Bernard Rankin
Hello,

I'm looking to set up a small private wiki, and am looking for recommendations.

Some sort of CGI based package that I could just untar somewhere web accessable 
via Apache would be great.

Any ideas?

Thanks,
:)


  

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


Re: Python Package Managment

2009-01-28 Thread Bernard Rankin



  [extracted from pylons-discuss]
 
 
   I hate to pass the buck, but this is Python's fault for not having
   reliable package management built in.  There's nothing Pylons can do
   about it except switch to another programming language.
   [SNIP]
 
  Without Setuptools,
  Pylons and TurboGears couldn't exist, and Zope and Twisted
  would not have been able to split themselves into several packages.
  People coming to Python from Perl and Ruby expect to be able to just
  run a command to download and install a package.  That problem was
  solved ten years ago, so why does Python still not have it standard?
 
  If Setuptools and Virtualenv or the equivalent were built into Python,
  you could trust that every computer that has successfully installed
  Python can install packages and make virtual environments the same
  way..
 
  That would eliminate 2/3 of the problems users have when
  installing Pylons, and the subsequent need to explain the problems and
  workarounds in the installation docs.  At
  work people say, Half the trouble of Pylons is installing it, and I
  often have to help them install it in person because otherwise they
  get stuck at some error message and have no idea what to do.
 
 
  Agreed.  I would even move ipython (or something like it) to core.
 
  Of course, even Setuptools has a long way to go in some areas. 
  (Installation 
 Rollback, for one.)
 
  Python is about batteries included, and these are major batteries in 
  most 
 modern environments.
 
  A CPAN like in-house hosted archive would nice, too.  This way, modules 
  have 
 a better chance of outliving the original author's interest/commitment in 
 paying 
 for, possibly non-trivial, web hosting.
 
  I'm sure these issues has been discussed to death, but I wonder what the 
 larger Python community thinks.
 
 You may be interested in the following:
 
 http://mail.python.org/pipermail/python-dev/2006-April/063952.html
 
 The thread is two years and a half old, but my impression is that the
 situation has not changeed much since. Few if any people are against
 improving the situation, but more people are against the currently
 available solutions (setuptools, virtualenv, etc...).
 

Thank you, I'll have a look.



  

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


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread koranthala
On Jan 28, 5:42 pm, koranthala koranth...@gmail.com wrote:
 On Jan 28, 2:16 am, Reckoner recko...@gmail.com wrote:



  I'm not sure this is possible, but I would like to have
  a list of  objects

  A=[a,b,c,d,...,z]

  where,  in the midst of a lot of processing I might do something like,

  A[0].do_something_which_changes_the_properties()

  which alter the properties of the object 'a'.

  The trick is that I would like A to be mysteriously aware that
  something about the  object 'a' has changed so that when I revisit A,
  I will know that the other items in the list need to be refreshed to
  reflect the changes in A as a result of changing 'a'.

  Even better would be to automatically percolate the subsequent changes
  that resulted from altering 'a' for the rest of the items in the list.
  Naturally, all of these items are related in some parent-child
  fashion.

  that might be a lot to ask, however.

  Any advice appreciated.

 I think Python Cookbook has a recipe which deals with this.
 - 6.12 Checking an Instance for Any State Change.

Were you able to get this? If not, let me know. I will try to type it
in here - (it is a big recipe, so not doing it now)
--
http://mail.python.org/mailman/listinfo/python-list


Reuse of DB-API 2.0 cursors for multiple queries?

2009-01-28 Thread moreati
Today, I used the adodbapi module against an SQL Server Express
database. I was surprised to get an exception, when I attempted to
submit a second query with my cursor object. The full session is
below.

With cx_Oracle I've become used to reusing a cursor for subsequent
queries. The PEP doesn't specify either way, that I can see. Is this
behaviour left to the implementation, or should I be able to expect a
cursor is reusable?

With thanks, Alex

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
(Intel)] on win32
Type help, copyright, credits or license for more information.
 import adodbapi
 conn = adodbapi.connect('Provider=SQLOLEDB.1;Data 
 Source=.\\SQLEXPRESS;Initial Catalog=MYDATABBASE;Integrated 
 Security=SSPI;User Instance=False;')
 curs = conn.cursor()
 curs.execute('select * from localview_roles')
 curs.execute('select * from localview_roles')
Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Python25\Lib\site-packages\adodbapi\adodbapi.py, line 713,
in execut
e
self._executeHelper(operation,False,parameters)
  File C:\Python25\Lib\site-packages\adodbapi\adodbapi.py, line 664,
in _execu
teHelper
self._raiseCursorError(DatabaseError,tracebackhistory)
  File C:\Python25\Lib\site-packages\adodbapi\adodbapi.py, line 474,
in _raise
CursorError
eh(self.conn,self,errorclass,errorvalue)
  File C:\Python25\Lib\site-packages\adodbapi\adodbapi.py, line 60,
in standar
dErrorHandler
raise errorclass(errorvalue)
adodbapi.adodbapi.DatabaseError:
--ADODBAPI
Traceback (most recent call last):
   File C:\Python25\Lib\site-packages\adodbapi\adodbapi.py, line
650, in _exec
uteHelper
adoRetVal=self.cmd.Execute()
   File COMObject ADODB.Command, line 3, in Execute
   File C:\Python25\lib\site-packages\win32com\client\dynamic.py,
line 258, in
 _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
retType, argTypes
) + args)
 com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft OLE
DB Provider
 for SQL Server', u'Cannot create new connection because in manual or
distribute
d transaction mode.', None, 0, -2147467259), None)
-- on command: select * from localview_roles
-- with parameters: None
--
http://mail.python.org/mailman/listinfo/python-list


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread Paul McGuire
On Jan 27, 3:16 pm, Reckoner recko...@gmail.com wrote:
 The trick is that I would like A to be mysteriously aware that
 something about the  object 'a' has changed so that when I revisit A,
 I will know that the other items in the list need to be refreshed to
 reflect the changes in A as a result of changing 'a'.


Check out the Enthought Traits package.

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


Re: Process crash with no reason

2009-01-28 Thread Philip Semanchuk


On Jan 28, 2009, at 12:12 PM, gil.shi...@gmail.com wrote:


On Jan 27, 5:59 pm, Philip Semanchuk phi...@semanchuk.com wrote:

On Jan 27, 2009, at 10:34 AM, gil.shi...@gmail.com wrote:

On Jan 27, 2:10 pm, Tim Golden m...@timgolden.me.uk wrote:

Then how are you interacting with Sybase?



I'm using python's functions to run sybase sql commands.


Can you give a short code sample? I'm unaware of how one would use  
the

standard Python library to talk to Sybase, unless Sybase has a raw
socket interface or some such.


First of all I have found the following python's import:

import Sybase


This isn't part of the Python standard library. It's a 3rd party  
module -- exactly what we were looking for.


Personally, I think this (or another C++ or C-based 3rd party module  
that you use heavily) is your prime suspect for the origin of the  
crashes you're having. That's not because I think the people who wrote  
or maintain it are bad or lazy coders. In fact, it's no reflection on  
their skill at all. It's just that a lot more people have used and  
exercised the Python standard library modules. A 3rd party module like  
this one will be less well-used and therefore less well-tested and  
therefore more likely to contain a bug that causes a crash.


That said, I don't know how to advise you to proceed from here. You  
could perhaps turn on logging at the database level. I know Postgres,  
for instance, can write very detailed logs and so if you get a crash  
at 9:33:22 you can look in the log and see what was happening at that  
time. If you get several crashes and they all happen when a certain  
SQL statement is being executed, that's probably the culprit.


You could also alter the Sybase module to add logging using Python's  
logging module. Who knows, it might already be there, waiting to be  
turned on with a switch.


But I'm jumping the gun a little. As I said, it could be this module  
or another that's causing your problem. It's a lot easier to cause a  
hard crash using C or C++ than it is using pure Python, so pure Python  
modules would be lower on my list of suspects. Enumerate all of the  
modules you're using and find out where they come from. Any of them  
that are not in the standard library and are not written in pure  
Python should top your list of suspects.


Good luck
Philip



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


Re: unable to print Unicode characters in Python 3

2009-01-28 Thread Martin v. Löwis
 Big step. I don't have Visual Studio and have never used it before.
 Which version of VS do I need to debug which released version of Python
 2.X and where do I get that VS from? Or do I need to build Python from
 source to be able to debug it?

You need Visual Studio 2008 (Professional, not sure about Standard), or
Visual C++ 2008 (which is free). You need to build Python from source in
debug mode; the released version is in release mode, and with no debug
information.

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


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread Reckoner
On Jan 28, 9:16 am, koranthala koranth...@gmail.com wrote:
 On Jan 28, 5:42 pm, koranthala koranth...@gmail.com wrote:



  On Jan 28, 2:16 am, Reckoner recko...@gmail.com wrote:

   I'm not sure this is possible, but I would like to have
   a list of  objects

   A=[a,b,c,d,...,z]

   where,  in the midst of a lot of processing I might do something like,

   A[0].do_something_which_changes_the_properties()

   which alter the properties of the object 'a'.

   The trick is that I would like A to be mysteriously aware that
   something about the  object 'a' has changed so that when I revisit A,
   I will know that the other items in the list need to be refreshed to
   reflect the changes in A as a result of changing 'a'.

   Even better would be to automatically percolate the subsequent changes
   that resulted from altering 'a' for the rest of the items in the list.
   Naturally, all of these items are related in some parent-child
   fashion.

   that might be a lot to ask, however.

   Any advice appreciated.

  I think Python Cookbook has a recipe which deals with this.
  - 6.12 Checking an Instance for Any State Change.

 Were you able to get this? If not, let me know. I will try to type it
 in here - (it is a big recipe, so not doing it now)

Actually, I have the python cookbook, but cannot find the recipe you
mention. maybe I have an older version?

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


Re: New to python, open source Mac OS X IDE?

2009-01-28 Thread Pierre-Alain Dorange
joseph.a.mar...@gmail.com joseph.a.mar...@gmail.com wrote:

 Greetings! I've heard enough raving about Python, I'm going to see for
 myself what all the praise is for!
 
 I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you
 even use an IDE for Python?
 
 Any recommendations on open source Python environments?

I'm new to python, i began with IDLE, but then switch to
TextWrangler+Terminal i prefer.

Now i also try XCode (not opensource, but free from Apple) just as a
text editor and still terminal, fine. Xcode editor is good for me.

I try to use Python directly from Xcode but i do not understand the
right way to do this. There is project for PyObjC but a can't make
working directly simple script project, so i continue to use terminal...

-- 
Pierre-Alain Dorangehttp://microwar.sourceforge.net/

Ce message est sous licence Creative Commons by-nc-sa-2.0
http://creativecommons.org/licenses/by-nc-sa/2.0/fr/
--
http://mail.python.org/mailman/listinfo/python-list


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread koranthala
On Jan 28, 10:39 pm, Reckoner recko...@gmail.com wrote:
 On Jan 28, 9:16 am, koranthala koranth...@gmail.com wrote:



  On Jan 28, 5:42 pm, koranthala koranth...@gmail.com wrote:

   On Jan 28, 2:16 am, Reckoner recko...@gmail.com wrote:

I'm not sure this is possible, but I would like to have
a list of  objects

A=[a,b,c,d,...,z]

where,  in the midst of a lot of processing I might do something like,

A[0].do_something_which_changes_the_properties()

which alter the properties of the object 'a'.

The trick is that I would like A to be mysteriously aware that
something about the  object 'a' has changed so that when I revisit A,
I will know that the other items in the list need to be refreshed to
reflect the changes in A as a result of changing 'a'.

Even better would be to automatically percolate the subsequent changes
that resulted from altering 'a' for the rest of the items in the list.
Naturally, all of these items are related in some parent-child
fashion.

that might be a lot to ask, however.

Any advice appreciated.

   I think Python Cookbook has a recipe which deals with this.
   - 6.12 Checking an Instance for Any State Change.

  Were you able to get this? If not, let me know. I will try to type it
  in here - (it is a big recipe, so not doing it now)

 Actually, I have the python cookbook, but cannot find the recipe you
 mention. maybe I have an older version?

 thanks.

Mine is 2nd Edition.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread excord80
On Jan 28, 4:57 am, Bruno Desthuilliers bruno.
42.desthuilli...@websiteburo.invalid wrote:


 What about:http://thraxil.org/code/cgi_app/

 (yes, it is a port of CGI::Application, and FWIW it's mentionned on the
 CGI::Application's wiki).


Nice find. Thank you. Interesting project. It seems to be only one
fairly short file (perhaps that's all it takes), and its most recent
release was in 2004. No mailing list.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't eval of generator expression work with locals?

2009-01-28 Thread Steve Holden
Gabriel Genellina wrote:
 En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden st...@holdenweb.com
 escribió:
 Gabriel Genellina wrote:
 En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern robert.k...@gmail.com
 escribió:
 
 I *thought* I did understand this until I came to this example:

 1)
 id(globals()), id(locals())
 (11239760, 11239760)

 # ok, globals and locals are the same at the module level

 2)
 s = (id(n) for n in [globals(),locals()])
 list(eval(s))
 [11239760, 11239760]  # still the same results

 3)
 s = (id(n()) for n in [globals,locals])
 list(eval(s))
 [11239760, 12583248]  # locals() is different

 No, locals is different, not locals(). You are looking at two different
 functions that return the same object when called in the given context,
 that's all.
 
 Perhaps you didn't notice that I shifted the () from right to left. I'm
 always printing the result of *calling* globals and locals -- the only
 change is *where* I do call them.
 
Ah, right. As you were ...

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread excord80
On Jan 28, 5:05 am, Jeroen Ruigrok van der Werven asmo...@in-
nomine.org wrote:


 Werkzeug[1] should be in your line, I think.

 [1]http://werkzeug.pocoo.org/


Again, the solution must work for plain vanilla CGI. I don't have WSGI
available. But thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: small python-cgi wiki?

2009-01-28 Thread excord80
On Jan 28, 12:02 pm, Bernard Rankin beranki...@yahoo.com wrote:

 I'm looking to set up a small private wiki, and am looking for 
 recommendations.

 Some sort of CGI based package that I could just untar somewhere web 
 accessable via Apache would be great.

There are a number of them listed at 
http://wiki.python.org/moin/PythonWikiEngines
. You might have a look at PikiPiki.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't eval of generator expression work with locals?

2009-01-28 Thread Scott David Daniels

Gabriel Genellina wrote:
En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden st...@holdenweb.com 
escribió:

Gabriel Genellina wrote:

En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern robert.k...@gmail.com
escribió:



I *thought* I did understand this until I came to this example:

1)

id(globals()), id(locals())

(11239760, 11239760)

This is a bad test.  We know distinct objects are distinct, but:
 print id(object()), id(object())
10598120 10598120

 a = object(); b = object()
 print id(a), id(b)
10598120 10598128

The reason is that once your created object has its id taken, you
must keep a handle on it, otherwise it may get recycled and reused.

That is,  id(var1) == id(var2)  implies   var1 is var2,
but  id(expr1) == id(expr2)  does not even imply  expr1 == expr2

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


Re: ctypes with Compaq Visual Fortran 6.6B *.dll (Windows XP), passing of integer and real values

2009-01-28 Thread alex
Jon
Thank you for your answer. I tried it with no success.

However I tried with
tst=cdll.LoadLibrary(f:\\scratch\\test2\\footst.dll) instead of
tst=windll.LoadLibrary(f:\\scratch\\test2\\footst.dll)

and it runs now with no error message, I can't figure for now why, but
it's great! This is motivating for going ahead.

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


Re: Dynamic methods and lambda functions

2009-01-28 Thread coutinhoti...@gmail.com
Hi!

  I had the same problem myself.
  Mark's detailed explanation really helped me understand.

  I ended up doing something like:

  class A:
def __init__(self):
  names = 'n1', 'n2'
  for n in names:
setattr(self, get%s % n, self._createGetter(n))

def _createGetter(self, n):
  def f(): return n
  return f

  Thanks a lot

  Cheers,
Tiago
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0, 'Hello' 42

2009-01-28 Thread Martin v. Löwis
 But the document also mentions that the result is not strictly
 undefined but reproducable undetermined.

What specific document are you looking at, and where specifically
does it say that? I can't believe that the quotation marks indicate
an actual quote, in particular because reproducible is misspelled.

In any case, I can't find anything like that in the 3.0 changes
document, and, given that the comparison *does* give an exception,
any statement that the result is undetermined would be false.

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


Quickbooks

2009-01-28 Thread Stephen Chapman
Has anyone Implemented the Quickbooks  COM object in Python.  If so can 
you give me

an Idea of where to begin.
Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread Jeroen Ruigrok van der Werven
-On [20090128 19:01], excord80 (excor...@gmail.com) wrote:
Again, the solution must work for plain vanilla CGI. I don't have WSGI
available. But thank you.

It works for plain CGI. I myself use it for FCGI.

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Earth to earth, ashes to ashes, dust to dust...
--
http://mail.python.org/mailman/listinfo/python-list


Re: unable to print Unicode characters in Python 3

2009-01-28 Thread Ross Ridge
John Machin writes:
 The only font choice offered apart from Raster Fonts in the Command
 Prompt window's Properties box is Lucida Console, not Lucida Sans
 Unicode. It will let me print Cyrillic characters from a C program,
 but not Chinese. I'm off looking for how to get a better font.

Thorsten Kampe  thors...@thorstenkampe.de wrote:
I have
[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont]
00=DejaVu Sans Mono

As near as I can tell the DejaVu Sans Mono font doesn't include Chinese
characters.  If you want to display Chinese characters in a console window
on Windows you'll probably have change the (global) system locale to an
appropriate Chinese locale and reboot.

Note that a complete Unicode console font is essentially an impossibility,
so don't bother looking for one.  There are many characters in Unicode
that can't be reasonably mappped to a single fixed-width console glyph.
There are also characters in Unicode that should be represented as
single-width gylphs in Western contexts, but as double-width glyphs in
Far-Eastern contexts.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  rri...@csclub.uwaterloo.ca
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0, 'Hello' 42

2009-01-28 Thread Scott David Daniels

towit...@gmail.com wrote:

Hello,

In the 3.0 changes list there is mentioned that -compares are not
supported anymore if the compared types are different (except
numbers). Like
  42  Hello
did return True of False depending on the implementation but is now a
TypeError.

But the document also mentions that the result is not strictly
undefined but reproducable undetermined. Meaning, that on a given
machine with a given python implementation result will always be the
same. But on another machine, or with another python implementation,
it might give a different result.

My question now is, why this is? E.g, Is there an integer large enough
so that the result changes? What circumstances influence the result?


The ordering of ints and strings may vary between python builds, but
_any_ strings will have the same relationship to _any_ integers.
That is, (str(x)  int(y)) == (str(y)  int(x))  for any x and y that
don't cause exceptions.  The types are compared before the values for
sufficiently disparate types without accomodation in the comparison
methods.  This means the 2.X python series can sort more lists, but
the sort order is not a particularly useful one (except for the fact
that there is an order).

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


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread Reckoner
On Jan 27, 9:46 pm, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 On Tue, 27 Jan 2009 13:16:36 -0800, Reckoner wrote:
  I'm not sure this is possible, but I would like to have a list of
  objects

  A=[a,b,c,d,...,z]

  where,  in the midst of a lot of processing I might do something like,

  A[0].do_something_which_changes_the_properties()

  which alter the properties of the object 'a'.

  The trick is that I would like A to be mysteriously aware that something
  about the  object 'a' has changed so that when I revisit A, I will know
  that the other items in the list need to be refreshed to reflect the
  changes in A as a result of changing 'a'.

 Can't be done if A is a built-in list, probably can't be done entirely
 generically, but you can probably do it in a cooperative manner.

 class TaintList(list):
 tainted = False
 def taint(self):
 self.tainted = True
 def untaint(self):
 self.tainted = False

 A = TaintList()

 import functools
 def taint(parent):
 def decorator(func):
 @functools.wraps(func)
 def f(*args, **kwargs):
 parent.taint()
 return func(*args, **kwargs)
 return f
 return decorator

 class TaintAwareThing(object):
 def __init__(self):
 self.attr = 0
 @taint(A)
 def change_attribute(self, x):
 self.attr = x

  x = TaintAwareThing()
  y = TaintAwareThing()
  z = TaintAwareThing()

  A.extend([x, y, z])
  A.tainted
 False
  x.change_attribute(5)
  A.tainted

 True

 Here is a second approach: create a proxy class TaintThing that wraps
 whatever object you want, using delegation:

 class TaintThing(object):
 parent = A
 def __init__(self, obj):
 self.__dict__['_proxy'] = obj
 def __getattr__(self, attr):
 return getattr(self._proxy, attr)
 def __setattr__(self, attr, value):
 setattr(self._proxy, attr, value)
 self.parent.taint()

 Now change TaintList to automatically wrap anything stored in it:

 # untested
 class TaintList(list):
 def append(self, obj):
 list.append(self, TaintThing(obj))
 # similar for __setitem__, extend, insert

 --
 Steven

thanks for your reply.

For the second case where

 class TaintThing(object):
 parent = A
 def __init__(self, obj):
 self.__dict__['_proxy'] = obj
 def __getattr__(self, attr):
 return getattr(self._proxy, attr)
 def __setattr__(self, attr, value):
 setattr(self._proxy, attr, value)
 self.parent.taint()

you have told it that parent is 'A'. Shouldn't that be passed to it
somehow in the following:

 # untested
 class TaintList(list):
 def append(self, obj):
 list.append(self, TaintThing(obj))
 # similar for __setitem__, extend, insert

I apologize.  I am probably missing something.  This is getting pretty
advanced for me.

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


  1   2   3   >