Re: i am new to python-Please somebody help

2007-08-03 Thread Hendrik van Rooyen

 "gregarican"  wrote:

> Maybe it's just me but the word "grovelling" just doesn't ring of
> newbie friendliness. To each their own I guess. Kind of like the
> Smalltalk list where a few respondents are really dry. Someone will
> post asking something like "Can I use Smalltalk to do X so that it
> talks to Y?" One guy (without pointing to a link or offering a
> snippet) just posts "Yes." I guess literally they have contributed. Or
> someone calls your house and asks, "Is so-and-so there?" You just say
> "Yes" and hang up on them :-)

Or at table  - "Can you pass the salt?"

"Yes"

< a brief hiatus, laden with unfulfilled expectations and no action >

"Please pass me the salt"

"Certainly - there you are."

On the subject of "grovelling" - this refusal to tug, and to condone
tugging at forelocks, may be a Southern Hemisphere affliction.

Don't like it myself.

- Hendrik

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


Re: Memory Leak with Tkinter Canvas (Python 2.5 Win32)

2007-08-03 Thread Hendrik van Rooyen

"frikk"  wrote:

>   1.  ... Am I somehow leaving
> objects laying around that aren't being deleted? Is create_rectangle
> not the appropriate function to use?)

Try calling the canvas's delete method with the old rectangle before
making a new one.

- Hendrik

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


Re: i am new to python-Please somebody help

2007-08-03 Thread Hendrik van Rooyen
"Bruno Desthuilliers"  wrote:

>Now if you want some examples of definitively "rude" newsgroups, I 
>suggest you take your chance on other newsgroups in the comp.* 
>hierarchy...

I know someone who derisively refers to anybody that is associated 
with computers in any way as a "Pencil Neck".

This leads me to wonder whether or not the rudeness stems from 
the physically deficient's urge to kick sand in the bully's face.

- Hendrik

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


File Handling & TRY/EXCEPT

2007-08-03 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm looking for some advice on how best to handle file read/write errors
with try/except as i'm a little vague on this, I have a small memory leak in
my app and I'm starting to think its generated by my log file write. For an
example of the function look below.

 

   def addAppLog(self, event):

  try:

 logfile = open('/pblue/new/Logs/Application.csv','a')

 

 now = datetime.datetime.now()

 

 logstring = '%s,%s \n' % (event, str(now))

 

 logfile.write(logstring)

  except:

 self.addAppLog(event)

  else:

 logfile.close()

 

Now I'm looking for some help to sort this out as I'm sure it's pretty
untidy, I want to make it as air tight as possible. The basic concept was
that if it tries writing to the log file and it fails, then it needs to
reattempt it, right?

 

What's the best way to handle this to ensure that there are not any memory
leaks caused when the file is open() but not followed by a close(). I'm
running 2.4 and I know some of these newer versions don't need you to
explicitly close() the file objects, but I would certainly feel a lot
better.

 

Any advice?

 

Thanks guys,

 

Rob

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

Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Bruno Desthuilliers
Skip Montanaro a écrit :
>>> In this case there was a bug.  Depending on inputs, sometimes obj
>>> initialized to a class, sometimes an instance of that class.  (I fixed
>>> that too while I was at it.)  The problem was that the use of __call__
>>> obscured the underlying bug by making the instance as well as the class
>>> callable.
> 
>> I don't quite get the point here. A concrete example would be welcome.
> 
> The bug went something like this:
> 
> obj = some.default_class
> ...
> if some_other_rare_condition_met:
> ... several lines ...
> obj = some.other_class()
> ...
> 
> Later,
> 
> x = obj()
> x(...)

Ok, I see. A nasty one, indeed.

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


Re: (no) fast boolean evaluation ?

2007-08-03 Thread Laurent Pointal
Stef Mientki a écrit :
> hello,
> 
> I discovered that boolean evaluation in Python is done "fast"
> (as soon as the condition is ok, the rest of the expression is ignored).
> 
> Is this standard behavior or is there a compiler switch to turn it on/off ?

As it was replied, its standard behavior and cannot be modified.

IMHO, if you really need all your expressions to be evaluated, the clean 
(most readable) way may be:

a = 
b = 
if a and b :
 ...

A+

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


Re: (no) fast boolean evaluation ? missing NOT

2007-08-03 Thread Laurent Pointal
Stef Mientki a écrit :
> 
> def Some_Function (const):
> print 'Ive been here', const
> return True
> 
> A = True
> 
> if A and Some_Function (4 ):
> print 'I knew it was True'
> else:
> print 'I''ll never print this'
> 
> 
> 
> Ive been here 4
> I knew it was True
>  
> I was expected that the function would not be called,
> because A is True.

When using the *and* operator, the short-circuit evaluation is done if A 
is False (no need to know the other operand, the result cannot be True). 
But if A is True, the compiler must evaluate the second parameter to 
know the expression result.

[note: for the or operator, the short circuit is done if first operand 
is True]

A+

Laurent.

PS. See http://en.wikipedia.org/wiki/Truth_table or google for boolean 
logic tables.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (no) fast boolean evaluation ? missing NOT

2007-08-03 Thread Stef Mientki
John Machin wrote:
> On Aug 3, 8:55 am, Ian Clark <[EMAIL PROTECTED]> wrote:
>> Stef Mientki wrote:
>>> hello,
>>> I discovered that boolean evaluation in Python is done "fast"
>>> (as soon as the condition is ok, the rest of the expression is ignored).
>>> Is this standard behavior or is there a compiler switch to turn it on/off ?
>>> thanks,
>>> Stef Mientki
>> It's called short circuit evaluation and as far as I know it's standard
>> in most all languages. This only occurs if a conditional evaluates to
>> True and the only other operators that still need to be evaluated are
>> 'or's or the condition evaluates to False and all the other operators
>> are 'and's. The reason is those other operators will never change the
>> outcome: True or'd with any number of False's will still be True and
>> False and'ed to any number of Trues will still be False.
>>
>> My question would be why would you *not* want this?
>>
>>
> 
> Why? Perhaps under some compound condition like this:
> 
> (you_are_confused and/or
> function_returns_bool_but_has__side_effects())
> 

Thanks guys,
Yes this is exactly what's going wrong ...

Sorry, my question missed the essential "NOT",
here is an example, that behaves different in Delphi,
(so I guess Delphi is not a real language ;-)


def Some_Function (const):
 print 'Ive been here', const
 return True

A = True

if A and Some_Function (4 ):
 print 'I knew it was True'
else:
 print 'I''ll never print this'



Ive been here 4
I knew it was True
http://docs.python.org/ref/Booleans.html>


or_test ::= and_test | or_test "or" and_test
>> A = 4
 >>> B = 5
 >>> A and B
5
 >>> A & B
4
 >>> A or B
4
 >>> A | B
5

So if I use the bitwise operation on integers,
   "and" changes into (bitwise) "or" and vise versa.

Is there some way to prevent / detect these kind of errors
( as I'm building a micro-controller simulator in Python,
I need both logical and bitwise operators very frequently).

cheers,
Stef Mientki


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


Re: Error with Tkinter and tkMessageBox

2007-08-03 Thread Fabio Z Tessitore
Il Fri, 03 Aug 2007 12:38:09 +1000, John McMonagle ha scritto:

> Fabio Z Tessitore wrote:
>> I've tried to use Twm and SURPRISE! it works!!!
>> 
>> Can you say why? How can I fix the prob with Gnome?
>> 
>> Thanks
> 
> I don't know why it doesn't work correctly on the version of gnome which
> you are running (I run KDE).  Perhaps the question needs to be posed to
> a gnome group ?

Thank you, very much, John.
Best wishes.

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


Re: How to read information from tables in HTML?

2007-08-03 Thread Stefan Behnel
ZelluX wrote:
> I'm confronted with some trouble when dealing with html files.
> 
> The html files contain javascript and some information stored in tables.
> And it seems that they're not well-formed, when parsed with minidom, it
> will say "mismatched tag".

minidom deals with XML. You're trying to read something that's (similar to)
HTML. HTML is much less strict.


> Then how can i get information from those files? Is there any useful
> library for me?

BeautifulSoup or lxml.html (which supports the BeautifulSoup parser, btw).

Both can deal with broken HTML, but lxml.html has better support for cleaning
up HTML (e.g. removing Javascript or embedded content, etc.) or handling forms.

http://codespeak.net/lxml/

The lxml.html package is not currently in an official lxml release, but you
can install it from SVN sources:

http://codespeak.net/svn/lxml/branch/html/

A release is expected soon.

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


How to read information from tables in HTML?

2007-08-03 Thread ZelluX
Hi, all

I'm confronted with some trouble when dealing with html files.

The html files contain javascript and some information stored in tables.
And it seems that they're not well-formed, when parsed with minidom, it
will say "mismatched tag".
Then how can i get information from those files? Is there any useful
library for me?

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


Re: How to create python script which can create csv we file with relationship

2007-08-03 Thread André Martins
http://docs.python.org/lib/module-csv.html

2007/8/3, Sonu <[EMAIL PROTECTED]>:
>
> hello,
> i need to create script
> that can create a csv file as i want
> for example i have two table in database that are person ,country
> if i want to create csv file to person,then wht to do ,,
> how to connect database,how to create csv of interrelated field
> eg :in person table :country_id (which is primary key of country table)
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
[]'s
André Martins
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: File Handling & TRY/EXCEPT

2007-08-03 Thread Alex Popescu
"Robert Rawlins - Think Blue" <[EMAIL PROTECTED]>
wrote in news:[EMAIL PROTECTED]: 

> This is a multipart message in MIME format.
> 
> --=_NextPart_000_00B0_01C7D5B0.02EB8BA0
> Hello Guys,
> 
>  
> 
> I'm looking for some advice on how best to handle file read/write
> errors with try/except as i'm a little vague on this, I have a small
> memory leak in my app and I'm starting to think its generated by my
> log file write. For an example of the function look below.
> 
>  
> 
>def addAppLog(self, event):
> 
>   try:
> 
>  logfile =
>  open('/pblue/new/Logs/Application.csv','a') 
> 
>  
> 
>  now = datetime.datetime.now()
> 
>  
> 
>  logstring = '%s,%s \n' % (event, str(now))
> 
>  
> 
>  logfile.write(logstring)
> 
>   except:
> 
>  self.addAppLog(event)
> 
>   else:
> 
>  logfile.close()
>

Shouldn't you always close the file? So, a finally block with

if logfile:
  logfile.close()

./alex
--
.w( the_mindstorm )p.

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


Re: Emacs + python

2007-08-03 Thread hg
Greg Donald wrote:

> On 8/1/07, hg <[EMAIL PROTECTED]> wrote:
>> Are there any cscope & ECB equivalent for Python ?
> 
> ECB is not language specific.  It works the same for browsing Python
> code as any other language.
> 
> 
> --
> Greg Donald
> http://destiney.com/

Thanks, I realized my mistake soon after I posted ... how about a cscope
equivalent ?

hg


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


Replacing _xmlplus.dom.minidom with xml.dom.minidom

2007-08-03 Thread aine_canby
Hi,

I'm working with a number of scripts which were written years ago for
my company for Python 2.2, and I'd like to update for Python 2.5. I
have written a script to add # -*- coding: cp1252 -*- to the beginning
of all my scripts, and that has fixed the encoding issues.

Another issue was the use of -

from _xmlplus.dom import minidom

http://sourceforge.net/project/showfiles.php?group_id=6473

I couldn't get a version of this module for  2.5, so I changed the
above to -

from xml.dom import minidom

The scripts I work with are all working now correctly for 2.5. But I
haven't been able to test the whole system as not all of it concerns
me. Anyway, my colleges are interested in updating also if it will be
reasonably hassle free.

So my main concern now is the use of  _xmlplus.dom.minidom. Why was it
used and what differences should  I look out for with regard to
xml.dom.mididom

Thanks very much for your help,

Barry.

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


RE: File Handling & TRY/EXCEPT

2007-08-03 Thread Robert Rawlins - Think Blue
Thanks for your ideas guys,

I'm unfortunately tied to 2.4 so don't have the full try except status, but
I'm now working with the following code:

def addApp(self, event):
try:
logfile =
open('/pblue/new/Logs/Application.csv','a')

now = datetime.datetime.now()
logstring = '%s,%s \n' % (event, str(now))

try:
logfile.write(logstring)
finally:
logfile.close()
except:
self.addApp(event)

I'm trying to slowly debug my app and get rid of all the memory leaks, but
its pain staking work, any help you can offer on that stuff would be a god
send, I'm a little reluctant about posting all my app code on the lists as
I'd like to keep some of it private.

How does that new version look? A little tidier?

Thanks guys,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Steve Holden
Sent: 03 August 2007 14:20
To: python-list@python.org
Subject: Re: File Handling & TRY/EXCEPT

Robert Rawlins - Think Blue wrote:
> Hello Guys,
> 
>  
> 
> I'm looking for some advice on how best to handle file read/write errors 
> with try/except as i'm a little vague on this, I have a small memory 
> leak in my app and I'm starting to think its generated by my log file 
> write. For an example of the function look below.
> 
>  
> 
>def addAppLog(self, event):
>   try:
>  logfile = open('/pblue/new/Logs/Application.csv','a')
>  now = datetime.datetime.now()
>  logstring = '%s,%s \n' % (event, str(now))
>  logfile.write(logstring)
>   except:
>  self.addAppLog(event)
> 
It seems somewhat perverse, when the logging code raises an exception, 
to recursively log - presumably the same exception will be raised again?

>   else:
> 
>  logfile.close()
> 
Remember that in 2.5 you can use try ... except ... finally

> 
> Now I'm looking for some help to sort this out as I'm sure it's pretty 
> untidy, I want to make it as air tight as possible. The basic concept 
> was that if it tries writing to the log file and it fails, then it needs 
> to reattempt it, right?
> 
Wrong. The one thing you can't log is a logging attempt error!
>  
> 
> What's the best way to handle this to ensure that there are not any 
> memory leaks caused when the file is open() but not followed by a 
> close(). I'm running 2.4 and I know some of these newer versions don't 
> need you to explicitly close() the file objects, but I would certainly 
> feel a lot better.
> 
>  
> 
> Any advice?
> 
This is just a quick on-the-fly look at what you did, I am sure you will 
receive other,  probably more helpful, comments.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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

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


Re: Help: GIS

2007-08-03 Thread kyosohma
On Aug 2, 10:46 pm, zxo102 <[EMAIL PROTECTED]> wrote:
> Hi,
> I am new in GIS area and need your suggestions for where I can
> start from.  I have a python based web application with a database.
> Now I would like to add a GIS map into my application. When a user
> clicks a certain area in the GIS map, it can grab the data from the
> database via my python based application. Do I have to use MapServer
> or Grass or some other  backends for this purpose?
>Thanks  a lot.
>
> Ouyang

While I am not a part of our GIS department, they use ArcGIS which has
Python support built in. If that's what you're using, you should be
able to use the examples given on ESRI's website:
http://www.spatialvision.com.au/html/tips-python-arc9.htm

Hmmm...not much there. Here are some other links I found:

http://nrm.salrm.uaf.edu/~dverbyla/arcgis_python/index.html
http://www.ollivier.co.nz/publication/uc2004/python_workshop/sld008.htm
http://www.3dartist.com/WP/python/pycode.htm

I don't know if these will be much help. You really need to just dig
in and start coding. I would recommend "Programming Python 3rd Ed." by
Lutz if you want something in hard copy. "Dive Into Python" is a free
book that's online that I'm told is very good. Both have good
examples, some of which are involved. All the web oriented Python
books are a few years old, but the code in them still works, for the
most part.

Mike

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


Re: File Handling & TRY/EXCEPT

2007-08-03 Thread Steve Holden
Robert Rawlins - Think Blue wrote:
> Hello Guys,
> 
>  
> 
> I’m looking for some advice on how best to handle file read/write errors 
> with try/except as i’m a little vague on this, I have a small memory 
> leak in my app and I’m starting to think its generated by my log file 
> write. For an example of the function look below.
> 
>  
> 
>def addAppLog(self, event):
>   try:
>  logfile = open('/pblue/new/Logs/Application.csv','a')
>  now = datetime.datetime.now()
>  logstring = '%s,%s \n' % (event, str(now))
>  logfile.write(logstring)
>   except:
>  self.addAppLog(event)
> 
It seems somewhat perverse, when the logging code raises an exception, 
to recursively log - presumably the same exception will be raised again?

>   else:
> 
>  logfile.close()
> 
Remember that in 2.5 you can use try ... except ... finally

> 
> Now I’m looking for some help to sort this out as I’m sure it’s pretty 
> untidy, I want to make it as air tight as possible. The basic concept 
> was that if it tries writing to the log file and it fails, then it needs 
> to reattempt it, right?
> 
Wrong. The one thing you can't log is a logging attempt error!
>  
> 
> What’s the best way to handle this to ensure that there are not any 
> memory leaks caused when the file is open() but not followed by a 
> close(). I’m running 2.4 and I know some of these newer versions don’t 
> need you to explicitly close() the file objects, but I would certainly 
> feel a lot better.
> 
>  
> 
> Any advice?
> 
This is just a quick on-the-fly look at what you did, I am sure you will 
receive other,  probably more helpful, comments.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: How to create python script which can create csv we file with relationship

2007-08-03 Thread kyosohma
On Aug 3, 6:45 am, Sonu <[EMAIL PROTECTED]> wrote:
> hello,
> i need to create script
> that can create a csv file as i want
> for example i have two table in database that are person ,country
> if i want to create csv file to person,then wht to do ,,
> how to connect database,how to create csv of interrelated field
> eg :in person table :country_id (which is primary key of country table)

Did you try google? Python has a csv module: 
http://docs.python.org/lib/module-csv.html

Mike

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


Re: wxpython TreeCtrl with os.listdir

2007-08-03 Thread kyosohma
On Aug 3, 6:56 am, [EMAIL PROTECTED] wrote:
> Hello,
>
> Does anybody know how can I "insert" os.listdir items in wx python
> TreeCtrl and every item assign adequately
> icon on this example
> import wx
>
> class TestFrame(wx.Frame):
> def __init__(self):
> wx.Frame.__init__(self, None, title="simple tree with icons",
> size=(400,500))
>
> il = wx.ImageList(16,16)
>
> # adequately icons
> self.fldridx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER,
> wx.ART_OTHER, (16,16))) # icon for os.listdir folder
> self.fldropenidx =
> il.Add(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN,wx.ART_OTHER,
> (16,16)))
> # icon for os.listdir file
> self.fileidx =
> il.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER,
> (16,16)))
> # icon for os.listdir open folder
>
> self.tree = wx.TreeCtrl(self)
>
> self.tree.AssignImageList(il)
> root = self.tree.AddRoot("wx.Object")
> self.tree.SetItemImage(root,
> self.fldridx,wx.TreeItemIcon_Normal)
> self.tree.SetItemImage(root,
> self.fldropenidx,wx.TreeItemIcon_Expanded)
>
> self.AddTreeNodes(root, data.tree)  # There must be os.listdir
> items
> self.tree.Expand(root)
>
> def AddTreeNodes(self, parentItem, items):
> for item in items:
> if type(item) == str:
> newItem = self.tree.AppendItem(parentItem, item)
> self.tree.SetItemImage(newItem,
> self.fileidx,wx.TreeItemIcon_Normal)
> else:
> newItem = self.tree.AppendItem(parentItem, item[0])
> self.tree.SetItemImage(newItem,
> self.fldridx,wx.TreeItemIcon_Normal)
> self.tree.SetItemImage(newItem,
> self.fldropenidx,wx.TreeItemIcon_Expanded)
>
> self.AddTreeNodes(newItem, item[1])
>
> def GetItemText(self, item):
> if item:
> return self.tree.GetItemText(item)
> else:
> return ""
>
> app = wx.PySimpleApp(redirect=True)
> frame = TestFrame()
> frame.Show()
> app.MainLoop()
>
> Regards,
> Vedran

This looks like something to post to the wxPython user's group, found
here: http://www.wxpython.org/maillist.php

The treectrl is one of the more complicated widgets of the wxPython
set.

Mike

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


distutils and development workflow

2007-08-03 Thread Brian Blais

Hello,

I was wondering how people organize their projects while they are  
developing, and packaging with distutils.  For example, so many  
python packages let me download, then do "sudo python setup.py  
install" and they are put in the right place.  The developers of  
those packages, however, probably don't have their working copies in  
their /usr/lib/python25/lib/site-packages directory, so where do they  
put them so that they work during development, and they also work  
when packaged with distutils?


So far, I've been hacking the python path (just for me), but it isn't  
portable, so I'd like to learn how I am supposed to do it.



thanks,

Brian Blais

--
Brian Blais
[EMAIL PROTECTED]
http://web.bryant.edu/~bblais



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

Re: Memory Leak with Tkinter Canvas (Python 2.5 Win32)

2007-08-03 Thread frikk
On Aug 3, 2:26 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote:
> "frikk"  wrote:
> >   1.  ... Am I somehow leaving
> > objects laying around that aren't being deleted? Is create_rectangle
> > not the appropriate function to use?)
>
> Try calling the canvas's delete method with the old rectangle before
> making a new one.
>
> - Hendrik

Hey guys-

  Both of your suggestions were perfect - I was just unaware I was
actually creating new *object* instead of drawing on the canvas.  noob
mistake.  Thanks again!

-Blaine

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


Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> In this particular case it was clearly unnecessary and just obfuscated
> the code.  I'm wondering, are there some general cases where __call__
> methods of a user-defined class are simply indispensable?

I don't know that you couldn't live without __call__, but it would make 
some code harder to write and understand. The time you need __call__ is 
when you need an object which is callable and which also has methods. e.g. 
look at xmlrpclib:

server = ServerProxy('http://some.server.com/path')

server.method(x=5) retrieves the url http://some.server.com/path/method?x=5
server.method.submethod(x=5) retrieves the url 
http://some.server.com/path/method/submethod?x=5


There is no need here to distinguish between a callable object and an 
object used for traversal. I think without __call__, code to access web 
servers would be less clean.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Replacing _xmlplus.dom.minidom with xml.dom.minidom

2007-08-03 Thread Robert Rawlins - Think Blue
Just as a heads up, minidom is pretty inefficient and difficult to work with
too.

On someone else's advice I switched over to ElementTree and have been really
pleased with the results, its much simpler to work with and more efficient
too.

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: 03 August 2007 14:39
To: python-list@python.org
Subject: Replacing _xmlplus.dom.minidom with xml.dom.minidom

Hi,

I'm working with a number of scripts which were written years ago for
my company for Python 2.2, and I'd like to update for Python 2.5. I
have written a script to add # -*- coding: cp1252 -*- to the beginning
of all my scripts, and that has fixed the encoding issues.

Another issue was the use of -

from _xmlplus.dom import minidom

http://sourceforge.net/project/showfiles.php?group_id=6473

I couldn't get a version of this module for  2.5, so I changed the
above to -

from xml.dom import minidom

The scripts I work with are all working now correctly for 2.5. But I
haven't been able to test the whole system as not all of it concerns
me. Anyway, my colleges are interested in updating also if it will be
reasonably hassle free.

So my main concern now is the use of  _xmlplus.dom.minidom. Why was it
used and what differences should  I look out for with regard to
xml.dom.mididom

Thanks very much for your help,

Barry.

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

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


Re: (no) fast boolean evaluation ? missing NOT

2007-08-03 Thread Bruno Desthuilliers
Stef Mientki a écrit :
(snip)
> Gabriel: you pointed me to this page:
> The exact behavior is defined in the Language Reference 
> 
> 
> 
> or_test  ::=  and_test | or_test "or" and_test
>  
> Can you imagine, while I'm not a programmer, just a human,
> that I don't understand one bit of this line.

This is a variant[2] of the BNF notation[1] for languages grammar. 
You'll find such notation in almost any programming language.

[1] http://en.wikipedia.org/wiki/Backus-Naur_form
[2] http://docs.python.org/ref/notation.html

> So now I'm left with just one question:
> for bitwise operations I should use &, |, ^

yes.

> for boolean operations I should use and, or, xor

yes.

> but after doing some test I find strange effects:
>  >>> A = 4
>  >>> B = 5
>  >>> A and B
> 5
>  >>> A & B
> 4
>  >>> A or B
> 4
>  >>> A | B
> 5


Nothing strange here. You now know how boolean operators works. Bitwise 
operators are something different (while still related). Represent 
yourself ints as bit fields, ie (restricting ourselves to 4-bits words 
for the example):

0 => 
1 => 0001
2 => 0010
3 => 0011
4 => 0100
5 => 0101
6 => 0110
7 => 0111
8 => 1000

(etc)

The bitwise operators works this way:

1/ the & operator compares each bit of it's operands, and for each 
returns '1' if both bits are '1', else '0'. So you have:

A & B => 4 & 5 => 0100 & 0101 => 0100 => 4

   0100
& 0101
   
   0100

2/ the | operator compares each bit of it's operands, and for each 
returns '1' if one of the bits is '1', else '0'. So you have:

A | B => 4 | 5 => 0100 | 0101 => 0101 => 5

   0100
| 0101
   
   0101


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


How to log python Shell results

2007-08-03 Thread Colly
How do I output the IDLE 1.2.1 Python Shell results to a log file.

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


Re: Eclipse/PyDev question.

2007-08-03 Thread André Martins
I think you can download the eclipse plataform e get pydev through eclipse
update.
Eclipse Europa distro is a group of 21 projects  like jdt and cdt not
correlate to python.

[]'s
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Efficient Rank Ordering of Nested Lists

2007-08-03 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> A naive approach to rank ordering (handling ties as well) of nested
> lists may be accomplished via:
> 
>def rankLists(nestedList):
>   def rankList(singleList):
>   sortedList = list(singleList)
>   sortedList.sort()
>   return map(sortedList.index, singleList)
>   return map(rankList, nestedList)
> 
>>>> unranked = [ [ 1, 2, 3, 4, 5 ], [ 3, 1, 5, 2, 4 ], [ -1.1, 2.2,
> 0, -1.1, 13 ] ]
>>>> print rankLists(unranked)
> 
>[[0, 1, 2, 3, 4], [2, 0, 4, 1, 3], [0, 3, 2, 0, 4]]
> 
> This works nicely when the dimensions of the nested list are small.
> It is slow when they are big.  Can someone suggest a clever way to
> speed it up?

Each use of sortedList.index is O(N) [where N is len(singleList)], and
you have N such uses in the map in the inner function, so this approach
is O(N squared).  Neil's suggestion to use bisect replaces the O(N)
.index with an O(log N) search, so the overall performance is O(N log N)
[[and you can't do better than that, big-O wise, because the sort step
is also O(N log N)]].

"beginner"'s advice to use a dictionary is also good and may turn out to
be faster, just because dicts are SO fast in Python -- but you need to
try and measure both alternatives.  One way to use a dict (warning,
untested code):

  def rankList(singleList):
  d = {}
  for i, item in reversed(enumerate(sorted(singleList))):
  d[item] = i
  return [d[item] for item in singleList]

If you find the for-clause too rich in functionality, you can of course
split it up a bit; but note that you do need the 'reversed' to deal with
the corner case of duplicate items (without it, you'd end up with 1s
instead of 0s for the third one of the sublists in your example).  If
speed is of the essence you might try to measure what happens if you
replace the returned expression with map(d.__getitem__, singleList), but
I suspect the list comprehension is faster as well as clearer.  

Another potential small speedup is to replace the first 3 statements
with just one:

d = dict((item,i) for i,item in reversed(enumerate(sorted(singleList

but THIS density of functionality is a bit above my personal threshold
of comfort ("sparse is better than dense":-).


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


Re: Eclipse/PyDev question.

2007-08-03 Thread Danyelle Gragsone
I wonder how long before they come out with a python version of
eclipse.  I know there is a C/C++ now.

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


Re: How to log python Shell results

2007-08-03 Thread kyosohma
On Aug 3, 10:14 am, Colly <[EMAIL PROTECTED]> wrote:
> How do I output the IDLE 1.2.1 Python Shell results to a log file.

Redirect stdout to the log file.




out = sys.stdout  # save stdout for restoration later
f = open(r'c:\test\test.log', 'w')
sys.stdout = f  # now stdout is redirected
# do some stuff that prints output
f.close() # when done, close the file
sys.stdout = out  # restore stdout



Or you could just copy and paste it yourself.

Mike

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


Re: Best way to capture output from an exec'ed (or such) script?

2007-08-03 Thread [EMAIL PROTECTED]
On Aug 2, 7:32 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> If your web server is multithreaded (or you use some other way to process
> many simultaneous requests) you have to be more careful - remember that
> sys.stdout is global, you must find a way to distinguish between output
>  from different processes all going into the same collector.
>
Any ideas on how to do this?  Is it even possible?

-Greg

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


Re: Eclipse/PyDev question.

2007-08-03 Thread gregarican
On Aug 3, 10:58 am, king kikapu <[EMAIL PROTECTED]> wrote:
> Hi,
> this is actually a question to those of us who use Eclipse and Pydev
> as their main Python developing environment. As i use Eclipse (3.3
> Europa) only for Python and i have nothing to do with Java, is there a
> way to disable/uninstall some Java-specific stuff and make the
> environment actually more snappy ??
>
> thanks for any help

I've used Eclipse for Java, Python, and Ruby development and can say
that AFAIK "Eclipse" and "snappy" are contradictions. Like "jumbo"
"shrimp" :-/

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


Re: Eclipse/PyDev question.

2007-08-03 Thread king kikapu
On Aug 3, 5:00 pm, gregarican <[EMAIL PROTECTED]> wrote:
> On Aug 3, 10:58 am, king kikapu <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > this is actually a question to those of us who use Eclipse and Pydev
> > as their main Python developing environment. As i use Eclipse (3.3
> > Europa) only for Python and i have nothing to do with Java, is there a
> > way to disable/uninstall some Java-specific stuff and make the
> > environment actually more snappy ??
>
> > thanks for any help
>
> I've used Eclipse for Java, Python, and Ruby development and can say
> that AFAIK "Eclipse" and "snappy" are contradictions. Like "jumbo"
> "shrimp" :-/

xexexe...I am sure about that :) I was wondering if we can throw away
some java-stuff and make our life easier (or, snappier)...

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


xlrd question

2007-08-03 Thread JYOUNG79
When running 'python setup.py install' to install items for xlrd to work, does 
anybody know 
what items are 
installed and where items are installed at on a Mac (OS 10.4)?  I'm assuming it 
mainly uses 
things out of the xlrd 
folder, but was curious if it copies files to other locations.

Thanks.

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


Re: Replacing _xmlplus.dom.minidom with xml.dom.minidom

2007-08-03 Thread Stefan Behnel
Robert Rawlins - Think Blue wrote:
> Just as a heads up, minidom is pretty inefficient and difficult to work with
> too.
> 
> On someone else's advice I switched over to ElementTree and have been really
> pleased with the results, its much simpler to work with and more efficient
> too.

/and/ lxml.etree is compatible to ElementTree, so once you have written your
code for ElementTree, you can switch to lxml.etree if ever you need things
like XPath, XSLT or validation.

However, as I understand the OP, the question deals with old code, so porting
it to ET (i.e. reimplementing it) might not be that easy...

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


Re: (no) fast boolean evaluation ? missing NOT

2007-08-03 Thread Roel Schroeven
Paul Boddie schreef:
> On 3 Aug, 11:45, Stef Mientki <[EMAIL PROTECTED]> wrote:
>> Sorry, my question missed the essential "NOT",
>> here is an example, that behaves different in Delphi,
>> (so I guess Delphi is not a real language ;-)
> 
> Delphi is based on Pascal, and from what I can recall from my
> university textbook, there isn't any mandatory short-circuit
> evaluation in Pascal: it's an implementation-dependent feature.
> Consequently, an expression involving boolean operators in such
> languages may well evaluate each term (potentially causing side-
> effects) before determining the final result.

I even thought Pascal never uses short-circuit evaluation, and always 
evaluates all terms. I might be wrong about that though; it's been quite 
a long time since I've used Pascal.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: (no) fast boolean evaluation ? missing NOT

2007-08-03 Thread Paul Boddie
On 3 Aug, 11:45, Stef Mientki <[EMAIL PROTECTED]> wrote:
>
> Sorry, my question missed the essential "NOT",
> here is an example, that behaves different in Delphi,
> (so I guess Delphi is not a real language ;-)

Delphi is based on Pascal, and from what I can recall from my
university textbook, there isn't any mandatory short-circuit
evaluation in Pascal: it's an implementation-dependent feature.
Consequently, an expression involving boolean operators in such
languages may well evaluate each term (potentially causing side-
effects) before determining the final result.

Paul

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


Eclipse/PyDev question.

2007-08-03 Thread king kikapu
Hi,
this is actually a question to those of us who use Eclipse and Pydev
as their main Python developing environment. As i use Eclipse (3.3
Europa) only for Python and i have nothing to do with Java, is there a
way to disable/uninstall some Java-specific stuff and make the
environment actually more snappy ??

thanks for any help

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


Re: (no) fast boolean evaluation ?

2007-08-03 Thread Bruno Desthuilliers
Steven D'Aprano a écrit :
> On Fri, 03 Aug 2007 10:20:59 +0200, Bruno Desthuilliers wrote:
> 
>> Joshua J. Kugler a écrit :
>>> On Thursday 02 August 2007 15:19, Evan Klitzke wrote:
> I discovered that boolean evaluation in Python is done "fast"
> (as soon as the condition is ok, the rest of the expression is ignored).
 This is standard behavior in every language I've ever encountered.
>>> Then you've never programmed in VB (at least 6, don't know if .net still
>>> does this).  Nested IF statements. CK! 
>> I do remember an even brain-deadiest language that not only didn't 
>> short-circuit boolean operators but also didn't have an "elif" statement...
> 
> 
> Is it a secret?
> 
> I'm a little perplexed at why you say a language without "elif" is a good
> sign of brain-death in a programming language. I understand that, given
> the parsing rules of Python, it is better to use elif than the equivalent:
> 
> if condition:
> pass
> else:
> if another_condition:
> pass
> 
> 
> But that's specific to the syntax of the language. You could, if you
> choose, design a language where elif was unnecessary:
> 
> if condition:
> pass
> else if another_condition:
> pass
> 
> What advantage is there to "elif", apart from it needing three fewer
> characters to type?
> 

Sorry, I forgot to mention the language did not allow to have else & if 
in the same statement. IOW :

if some_condition then
   do_sometehing
else
   if some_other_condition then
 do_something_else
   else
 if yet_another_condition then
   do_yet_another_thing
 else
   if your_still_here then
  give_up('this language is definitively brain dead')
   end if
 end if
   end if
end if

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


Eclipse and Python

2007-08-03 Thread Danyelle Gragsone
Does anyone have any suggested websites for learning Eclipse the python way?

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


Re: Eclipse/PyDev question.

2007-08-03 Thread Danyelle Gragsone
I just found this: http://www.easyeclipse.org/site/distributions/python.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient Rank Ordering of Nested Lists

2007-08-03 Thread Neil Cerutti
On 2007-08-03, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> A naive approach to rank ordering (handling ties as well) of nested
> lists may be accomplished via:
>
>def rankLists(nestedList):
>   def rankList(singleList):
>   sortedList = list(singleList)
>   sortedList.sort()
>   return map(sortedList.index, singleList)
>   return map(rankList, nestedList)
>
>>>> unranked = [ [ 1, 2, 3, 4, 5 ], [ 3, 1, 5, 2, 4 ], [ -1.1, 2.2,
> 0, -1.1, 13 ] ]
>>>> print rankLists(unranked)
>
>[[0, 1, 2, 3, 4], [2, 0, 4, 1, 3], [0, 3, 2, 0, 4]]
>
> This works nicely when the dimensions of the nested list are
> small. It is slow when they are big.  Can someone suggest a
> clever way to speed it up?

Use binary search instead of linear.

 import bisect
 import functools

 def rankLists(nestedList):
   def rankList(singleList):
 sortedList = list(sorted(singleList))
 return map(functools.partial(bisect.bisect_left, sortedList), singleList)
   return map(rankList, nestedList)

-- 
Neil Cerutti
Facts are stupid things. --Ronald Reagan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML Processing

2007-08-03 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>On Aug 2, 2:09 pm, Jay Loden <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] wrote:
>> > On Aug 2, 1:45 pm, Roman <[EMAIL PROTECTED]> wrote:
>> >> Is there a package that converts a string that contains special
>> >> characters in xml to to literal value.  For instance, converts
>stringhttp://myhome/¶mtohttp://myhome/¶m.
>>
>> >> Thanks in advance
>>
>> > I've seen examples using the HTMLgen module. But here's another script
>> > I just found:
>>
>> >http://mail.python.org/pipermail/python-list/1999-November/016814.html
>>
>> > I would think that you could use regular expressions too.
>>
>> > Mike
>>
>> I would reccommend against using the example above or using regular
>expressions, since both are likely to miss corner cases, and the stdlib
>has an encode function that's already designed for this task
>>
>> http://docs.python.org/lib/module-xml.sax.saxutils.html
>>
>> The encode() function in xml.sax.saxutils also is extensible, should
>you run into any entities that it fails to escape in the current
>implementation.
>>
>> -Jay
>
>Yes, I am an idiot.
>

!  Unproved, as Scotsmen are wont to say.

This and similar questions arise frequently enough that I recommend
http://wiki.python.org/moin/EscapingXml > for those who want
to pursue the subject.
-- 
http://mail.python.org/mailman/listinfo/python-list


Idlelib TreeWidget (UNCLASSIFIED)

2007-08-03 Thread Vines, John (Civ, ARL/CISD)
Classification:  UNCLASSIFIED 
Caveats: NONE
 
Does anyone have any experience using the idlelib TreeWidget module?  I
am using it to display XML files and would like to include some editing
capabilities.  Does anyone have any examples I could take a look at?

Thanks,
John

 
Classification:  UNCLASSIFIED 
Caveats: NONE
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: replacement for execfile

2007-08-03 Thread Stefan Bellon
On Sun, 29 Jul, Steven D'Aprano wrote:

> (1) Don't use eval, exec or execfile.

Ok, then I would really like to ask a question about how to solve my
problem without execfile ... ;-)

I am embedding Python on Windows using MinGW. In order to execute a
Python script file, calling any of the PyRun_File functions does not
work but crashes (I assume this is because the Python DLL was built
using Microsoft tools and those tools and MinGW have different FILE
structures, so a FILE *fp cannot be passed from my MinGW C code to
the Python DLL).

Therefore my current solution is to call PyRun_String functions and
execute a string with the content "execfile('filename')".

Is there a way to solve this problem with PyRun_File?

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


Devloper Wanted For Debugging / Optimizing

2007-08-03 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I've been writing (with your help) a small application over the past couple
of months but I'm really struggling to iron out all of the creases and its
seems to spring a few memory leaks that I'm unable to find and plug. It's
only a small app, around 500 lines of code I would guess, aside from the
usual python type things it deals with dbus and XML parsing using element
tree, But it's for an embedded Linux platform so keeping it lightweight and
memory leak free is an absolute must.

 

Is anyone interested to take this small project on to have a look at my
code? Perhaps give me a little bit of advice on where I'm going wrong?

 

I would be willing to pay someone for their much needed time to get the
final few creases ironed out, this isn't really stuff we can deal with on
the boards so something private is a must, hence I'm exploring the idea of a
paid contract.

 

If anyone is interested then please feel free to contact me off list.

 

Thanks again guys,

 

Rob

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

Using cursor.callproc with zxJDBC

2007-08-03 Thread Vaughan V Ashe
Hi 

We would like to use the store proc. We are using a postgreql database. what we 
have working so far is:

params = [4,4,2]

curs.callproc("update_job_status",params)

db.commit()


#print db

#print curs.description

result = curs.fetchall()

if result == 1:

print "good one"

else:

print "shite"



we are using the beta version of jython. Would be very happy to get a response 
from you



Regards



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

Re: Email

2007-08-03 Thread Rohan
On Aug 2, 1:06 pm, Laurent Pointal <[EMAIL PROTECTED]> wrote:
> Rohan wrote:
> > I was wondering if there could be an arrangement where a file could be
> > attached and send as an email.
> > For ex
> > f = open(add.txt,w)
> > f.write('python')
> > f.close()
>
> > Now I would like to send an email with add.txt as an attachment, is it
> > possible ?
> > some one give me a pointer towards this.
>
> You can use iMailer as an example script to get parts:
>
> http://nojhan.free.fr/article.php3?id_article=22
>
> A+
>
> Laurent.


Laurent the link you gave me is in a language unknown to me if you
have anything that expalains in english, then let me know.
thanks

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


Re: (no) fast boolean evaluation ?

2007-08-03 Thread Bruno Desthuilliers
Joshua J. Kugler a écrit :
> On Thursday 02 August 2007 15:19, Evan Klitzke wrote:
>>> I discovered that boolean evaluation in Python is done "fast"
>>> (as soon as the condition is ok, the rest of the expression is ignored).
>> This is standard behavior in every language I've ever encountered.
> 
> Then you've never programmed in VB (at least 6, don't know if .net still
> does this).  Nested IF statements. CK! 

I do remember an even brain-deadiest language that not only didn't 
short-circuit boolean operators but also didn't have an "elif" statement...

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

Re: (no) fast boolean evaluation ?

2007-08-03 Thread Neil Cerutti
On 2007-08-03, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> But that's specific to the syntax of the language. You could,
> if you choose, design a language where elif was unnecessary:
>
> if condition:
> pass
> else if another_condition:
> pass
>
> What advantage is there to "elif", apart from it needing three
> fewer characters to type?

It's a great boon to the authors of auto-indenting text editors.

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


Re: Bug in execfile?

2007-08-03 Thread Peter Otten
Fernando Perez wrote:

> I'm finding the following behavior truly puzzling, but before I post a bug
> report on the site, I'd rather be corrected if I'm just missing somethin
> obvious.
> 
> Consider the following trivial script:
> 
> from math import sin, pi
> wav = lambda k,x: sin(2*pi*k*x)
> print wav(1,0.25)

> The above runs just fine from a prompt, or even interactively via
> execfile(). Now, consider calling it by using this instead:
> 
> #!/usr/bin/env python
> def runscript(fname):
> """Run a file by calling execfile()."""
> execfile(fname)
> runscript('execfilebugscript.py')

> If I run the above, calling the first script 'execfilebugscript.py' and
> the second 'execfilebug.py', I get this:

> NameError: global name 'sin' is not defined

> I'm really, really puzzled by this.  From reading the execfile() docs, I
> had the hunch to change the call to:
> 
> execfile(fname,{})
> 
> and now the problem disappears, so I can keep on working.


If you execfile() a script names not known in the context of a function are
looked up in the global namespace, but assignments set names in the local
namespace.

Consider execfile(filename) for a file

x = 42
def f():
print x
f()

x and f are put into the local namespace, but x is not local to the function
f and therefore looked up in f's globals.

Now if you call execfile() in the global namespace of the client script the
global and local namespace are identical

>>> globals() is locals()
True

so x although put into the local namespace will still be found when looked
up in the global namespace. That is the same situation as in your
workaround execfile(filename, {}).

This however is not the case if you call execfile() inside a function. Here
global and local namespace differ.

In your example, when you put another execfile() into the global namespace
of the client script the sin() imported there is the only one that your
wav() function sees. You can verify that by putting

def sin(phi): return "I'm not math.sin()"

instead of 

if 1:  

into execfilebug.py.

Can the current behaviour of execfile() be changed into a more intuitive
one? Not with only two namespaces. You'd probably need something similar to
closures, and I don't think the necessary work would be worth the effort.

Peter

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


Re: Best way to capture output from an exec'ed (or such) script?

2007-08-03 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>En Thu, 02 Aug 2007 16:48:06 -0300, <[EMAIL PROTECTED]> escribió:
>
>> In any case. I've added some minor scripting support, so that you can
>> write dynamic pages in Python. To do this, I use execfile(), and pass
>> the script a dictionary with some basic variables. The script then
>> sets a "ret" variable that's sent back to the browser. That's some
>> major ugliness right there! If I do a "print" inside the script, then
>> it'll end up on the server console. I want it to end up in the web
>> browser.
>
>If `print` were a function, this would be easy: just provide a replacement  
>into the dictionary you pass to the script. But print is a statement, and  
>this becomes a bit harder.
>
>If your web server only processes a single request at a time, you can  
>replace sys.stdout (and perhaps sys.stderr) with a suitable object having  
>a write() function: a true open file, or a StringIO instance, or even a  
>custom object that collects "printed" lines into a list.
>
>If your web server is multithreaded (or you use some other way to process  
>many simultaneous requests) you have to be more careful - remember that  
>sys.stdout is global, you must find a way to distinguish between output  
> from different processes all going into the same collector.
.
.
.
While we're on the subject of Web servers so small
as to be educational, I'll recommend http://www.ibm.com/developerworks/web/library/wa-ltwebserv/ >.
-- 
http://mail.python.org/mailman/listinfo/python-list

Global package variable, is it possible?

2007-08-03 Thread Chris Allen
Hello fellow pythoneers.  I'm stumped on something, and I was hoping
maybe someone in here would have an elegant solution to my problem.
This is the first time I've played around with packages, so I'm
probably misunderstanding something here...

Here's what I'd like to do in my package.  I want my package to use a
configuration file, and what I'd like is for the config file to appear
magically in each module so I can just grab values from it without
having to load and parse the config file in each package module.  Not
quite understanding how the __init__.py file works, I expected it to
be as easy as just setting up the ConfigParser object and then I
figured (since a package is a module) that it would now be global to
my package and I could access it in my modules, but I was wrong...  I
don't want to have to pass it in to each module upon init, or anything
lame like that.  A main reason for this is that I'd like to be able to
reload the config file dynamically and have all my modules
automatically receive the new config.  There must be a way to do this,
but seeing how __init__.py's namespace is not available within the
package modules, I don't see a simple and elegant way to do this.
Does anybody have any suggestions?  Thanks!

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


wxpython TreeCtrl with os.listdir

2007-08-03 Thread vedrandekovic
Hello,

Does anybody know how can I "insert" os.listdir items in wx python
TreeCtrl and every item assign adequately
icon on this example
import wx


class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="simple tree with icons",
size=(400,500))


il = wx.ImageList(16,16)

# adequately icons
self.fldridx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER,
wx.ART_OTHER, (16,16))) # icon for os.listdir folder
self.fldropenidx =
il.Add(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN,wx.ART_OTHER,
(16,16)))
# icon for os.listdir file
self.fileidx =
il.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER,
(16,16)))
# icon for os.listdir open folder



self.tree = wx.TreeCtrl(self)

self.tree.AssignImageList(il)
root = self.tree.AddRoot("wx.Object")
self.tree.SetItemImage(root,
self.fldridx,wx.TreeItemIcon_Normal)
self.tree.SetItemImage(root,
self.fldropenidx,wx.TreeItemIcon_Expanded)

self.AddTreeNodes(root, data.tree)  # There must be os.listdir
items
self.tree.Expand(root)


def AddTreeNodes(self, parentItem, items):
for item in items:
if type(item) == str:
newItem = self.tree.AppendItem(parentItem, item)
self.tree.SetItemImage(newItem,
self.fileidx,wx.TreeItemIcon_Normal)
else:
newItem = self.tree.AppendItem(parentItem, item[0])
self.tree.SetItemImage(newItem,
self.fldridx,wx.TreeItemIcon_Normal)
self.tree.SetItemImage(newItem,
self.fldropenidx,wx.TreeItemIcon_Expanded)

self.AddTreeNodes(newItem, item[1])


def GetItemText(self, item):
if item:
return self.tree.GetItemText(item)
else:
return ""

app = wx.PySimpleApp(redirect=True)
frame = TestFrame()
frame.Show()
app.MainLoop()



Regards,
Vedran

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


How to create python script which can create csv we file with relationship

2007-08-03 Thread Sonu
hello,
i need to create script
that can create a csv file as i want
for example i have two table in database that are person ,country
if i want to create csv file to person,then wht to do ,,
how to connect database,how to create csv of interrelated field
eg :in person table :country_id (which is primary key of country table)

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


Re: (no) fast boolean evaluation ? missing NOT

2007-08-03 Thread Stef Mientki
Laurent Pointal wrote:
> Stef Mientki a écrit :
>> 
>> def Some_Function (const):
>> print 'Ive been here', const
>> return True
>>
>> A = True
>>
>> if A and Some_Function (4 ):
>> print 'I knew it was True'
>> else:
>> print 'I''ll never print this'
>> 
>>
>> 
>> Ive been here 4
>> I knew it was True
>> >
>> I was expected that the function would not be called,
>> because A is True.
> 
> When using the *and* operator, the short-circuit evaluation is done if A 
> is False (no need to know the other operand, the result cannot be True). 
> But if A is True, the compiler must evaluate the second parameter to 
> know the expression result.
Sorry you're completely right,
and indeed I must have something very stupid !!

thanks very much
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


suppress pop up windwo

2007-08-03 Thread diego
I'm automating the generation of PDF out of Excel sheets through
win32com.

I nearly accomplished everything I wanted, but one problem is still
left:
when I calling the print job through following code:

xl.Selection.PrintOut(Copies=1,Collate=True)

then a window pops up, where I have to input the name of the pdf I
want to generate.
Is there way to pass this filename to this window?



(I'm using 'Jaws PDF Creator" as printer.)

Thanks in advance for your help!

Diego

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


Re: (no) fast boolean evaluation ? missing NOT

2007-08-03 Thread Diez B. Roggisch
Stef Mientki schrieb:
> John Machin wrote:
>> On Aug 3, 8:55 am, Ian Clark <[EMAIL PROTECTED]> wrote:
>>> Stef Mientki wrote:
 hello,
 I discovered that boolean evaluation in Python is done "fast"
 (as soon as the condition is ok, the rest of the expression is 
 ignored).
 Is this standard behavior or is there a compiler switch to turn it 
 on/off ?
 thanks,
 Stef Mientki
>>> It's called short circuit evaluation and as far as I know it's standard
>>> in most all languages. This only occurs if a conditional evaluates to
>>> True and the only other operators that still need to be evaluated are
>>> 'or's or the condition evaluates to False and all the other operators
>>> are 'and's. The reason is those other operators will never change the
>>> outcome: True or'd with any number of False's will still be True and
>>> False and'ed to any number of Trues will still be False.
>>>
>>> My question would be why would you *not* want this?
>>>
>>>
>>
>> Why? Perhaps under some compound condition like this:
>>
>> (you_are_confused and/or
>> function_returns_bool_but_has__side_effects())
>>
> 
> Thanks guys,
> Yes this is exactly what's going wrong ...
> 
> Sorry, my question missed the essential "NOT",
> here is an example, that behaves different in Delphi,
> (so I guess Delphi is not a real language ;-)
> 
> 
> def Some_Function (const):
> print 'Ive been here', const
> return True
> 
> A = True
> 
> if A and Some_Function (4 ):
> print 'I knew it was True'
> else:
> print 'I''ll never print this'
> 
> 
> 
> Ive been here 4
> I knew it was True
>  
> I was expected that the function would not be called,
> because A is True.
> 
> And I agree with Laurent that it should be better to write a clean code,
> so it doesn't matter whether you write in Python or in Delphi.
> 
> Gabriel: you pointed me to this page:
> The exact behavior is defined in the Language Reference 
> 
> 
> 
> or_test  ::=  and_test | or_test "or" and_test
>  
> Can you imagine, while I'm not a programmer, just a human,
> that I don't understand one bit of this line.
> 
> So now I'm left with just one question:
> for bitwise operations I should use &, |, ^
> for boolean operations I should use and, or, xor
> but after doing some test I find strange effects:
>  >>> A = 4
>  >>> B = 5
>  >>> A and B
> 5
>  >>> A & B
> 4
>  >>> A or B
> 4
>  >>> A | B
> 5
> 
> So if I use the bitwise operation on integers,
>   "and" changes into (bitwise) "or" and vise versa.

No!!! Don't think that!

Choose different numbers, and you will see that.

The semantics for the and/or operators are spelled out like this 
(extra-verbose):


def and(a, b):
 if bool(a) == True:
if bool(b) == True
   return b # because it holds True == bool(b)
 return a # because it holds Fals == bool(a)

def or(a, b):
 if bool(a) == True:
return a
 return b


This could be considered unfortunate because it relies on the implicit 
boolean nature of certain values like "", 0, 1, {} and so forth - but 
it's the way it is.

However, this has _nothing_ to do with the bitwise operations! The work 
on the bits of integers, and because 5 and 4 are bitwise 0b101 and 
0x100, the

5 & 4 -> 4 == 0b100

and

5 | 4 -> 5 == 0x101

That's all!

If you need non-circuiting and/or, write functions and and or:

def and_(a, b):
 return a and b

def or_(a, b):
 return a or b

That will ensure argument evaluation.

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


Re: (no) fast boolean evaluation ?

2007-08-03 Thread Ed Leafe
On Aug 3, 2007, at 11:57 AM, Bruno Desthuilliers wrote:

> Sorry, I forgot to mention the language did not allow to have else  
> & if
> in the same statement. IOW :
>
> if some_condition then
>do_sometehing
> else
>if some_other_condition then
>  do_something_else
>else
>  if yet_another_condition then
>do_yet_another_thing
>  else
>if your_still_here then
>   give_up('this language is definitively brain dead')
>end if
>  end if
>end if
> end if

Usually that's because the language provides a switch/case statement  
construct. If it does and you try to write the above code, it isn't  
the language that's brain-dead!  ;-)

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com


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


Re: (no) fast boolean evaluation ?

2007-08-03 Thread Steven D'Aprano
On Fri, 03 Aug 2007 10:20:59 +0200, Bruno Desthuilliers wrote:

> Joshua J. Kugler a écrit :
>> On Thursday 02 August 2007 15:19, Evan Klitzke wrote:
 I discovered that boolean evaluation in Python is done "fast"
 (as soon as the condition is ok, the rest of the expression is ignored).
>>> This is standard behavior in every language I've ever encountered.
>> 
>> Then you've never programmed in VB (at least 6, don't know if .net still
>> does this).  Nested IF statements. CK! 
> 
> I do remember an even brain-deadiest language that not only didn't 
> short-circuit boolean operators but also didn't have an "elif" statement...


Is it a secret?

I'm a little perplexed at why you say a language without "elif" is a good
sign of brain-death in a programming language. I understand that, given
the parsing rules of Python, it is better to use elif than the equivalent:

if condition:
pass
else:
if another_condition:
pass


But that's specific to the syntax of the language. You could, if you
choose, design a language where elif was unnecessary:

if condition:
pass
else if another_condition:
pass

What advantage is there to "elif", apart from it needing three fewer
characters to type?



-- 
Steven.

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


Re: (no) fast boolean evaluation ?

2007-08-03 Thread Irmen de Jong
John Machin wrote:

> 
> (you_are_confused and/or
> function_returns_bool_but_has__side_effects())
> 

That above expression should be written more explicitly like:

function_result = function_returning_bool_but_with_side_effects()

if you_are_confused or function_result:
   do_something_nice()


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


Coroutine API

2007-08-03 Thread Calvin Spealman
I was talking to some other people, who all were working on different
schedulers and such for coroutines. We decided to work out a common
API to give coroutines, and common rules to passing data between them,
etc. I am wondering now if there is already work on this, or some
schedulers I'm not aware of that have any deployment and a good,
simple design.

We also setup a group to discuss this and iron out our details and
some common coroutines. [EMAIL PROTECTED]

We came up with this basic rule set:
1) A coroutine can be any iterable
2) A coroutine yielding None is suspending to allow others to run
3) A coroutine yielding something else is yielding another coroutine
and needs to stay suspended until that coroutine has a value to pass
to the send() method of the coroutine.
4) In the above case, if the yielded coroutine raises an exception, it
is passed to the waiting coroutine's throw() method.
5) A coroutine raising StopIteration(arg), where arg is its final
result, expects arg to be passed to the send() method of any coroutine
which is waiting for its completion.

The idea is that we don't rely on defining any new types or functions
and we keep it extremely simple. I'd like to consider it WSGI for
coroutines.

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient Rank Ordering of Nested Lists

2007-08-03 Thread pyscottishguy
On Aug 2, 10:20 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> A naive approach to rank ordering (handling ties as well) of nested
> lists may be accomplished via:
>
>def rankLists(nestedList):
>   def rankList(singleList):
>   sortedList = list(singleList)
>   sortedList.sort()
>   return map(sortedList.index, singleList)
>   return map(rankList, nestedList)
>
>>>> unranked = [ [ 1, 2, 3, 4, 5 ], [ 3, 1, 5, 2, 4 ], [ -1.1, 2.2,
> 0, -1.1, 13 ] ]
>>>> print rankLists(unranked)
>
>[[0, 1, 2, 3, 4], [2, 0, 4, 1, 3], [0, 3, 2, 0, 4]]
>
> This works nicely when the dimensions of the nested list are small.
> It is slow when they are big.  Can someone suggest a clever way to
> speed it up?

Isn't there something wrong with the ordering?

Pablo's answers are:
[ 1, 2, 3, 4, 5 ] == [0, 1, 2, 3, 4]  correct

[ 3, 1, 5, 2, 4 ] == [2, 0, 4, 1, 3] wrong?

[ -1.1, 2.2, 0, -1.1, 13 ] == [0, 3, 2, 0, 4] wrong?

Doing it in my head I get:
[ 3, 1, 5, 2, 4 ] == [ 1, 3, 0, 4, 2 ]

[ -1.1, 2.2, 0, -1.1, 13 ] == [0, 3, 2, 1, 4]

What gives?

Did I misunderstand what "rank ordering (handling ties as well)" means?

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


Trying to find zip codes/rest example

2007-08-03 Thread VanL
Hello,

A couple months ago there was an example posted in a blog of a rest 
interface for validating zip codes.  If I recall correctly, the backend 
validator was written in python.

The validator demo page had a single text input; next to the text input 
would appear either a green check or a red X depending on whether the 
zip code was valid.

On the backend, the explanation of the demo included a discussion of 
using HTTP status codes (200 for a valid zip, 406? for invalid) so that 
the service could be used from a console as well.

I now cannot find this demo and the associated discussion.  Does anybody 
remember this demo and where I might be able to find it?

Thanks,

VanL

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


Re: Using cursor.callproc with zxJDBC

2007-08-03 Thread Carsten Haese
On Fri, 2007-08-03 at 17:31 +0100, Vaughan V Ashe wrote:
> Hi 
>  
> We would like to use the store proc. We are using a postgreql
> database. what we have working so far is:
>  
> params = [4,4,2]
> 
> curs.callproc("update_job_status",params)
> 
> db.commit()
> 
> #print db
> 
> #print curs.description
> 
> result = curs.fetchall()
> 
> if result == 1:
> 
> print "good one"
> 
> else:
> 
> print "shite"
> 
>  
> 
> we are using the beta version of jython. Would be very happy to get a
> response from you

You haven't asked a question, and you're not describing what your
problem is.

I'm going to guess what your problem is: You're always getting the
result "shite" regardless of whether the procedure worked or not.
curs.fetchall() returns a list, which is never going to be equal to 1.

If this doesn't help you, please describe what exactly your problem is.

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


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


Re: (no) fast boolean evaluation ?

2007-08-03 Thread Neil Cerutti
On 2007-08-03, Ed Leafe <[EMAIL PROTECTED]> wrote:
> On Aug 3, 2007, at 11:57 AM, Bruno Desthuilliers wrote:
>
>> Sorry, I forgot to mention the language did not allow to have else  
>> & if
>> in the same statement. IOW :
>>
>> if some_condition then
>>do_sometehing
>> else
>>if some_other_condition then
>>  do_something_else
>>else
>>  if yet_another_condition then
>>do_yet_another_thing
>>  else
>>if your_still_here then
>>   give_up('this language is definitively brain dead')
>>end if
>>  end if
>>end if
>> end if
>
> Usually that's because the language provides a switch/case
> statement  construct. If it does and you try to write the above
> code, it isn't  the language that's brain-dead!  ;-)

The switch statements I'm aware of are less generally applicable
than a tower of "if { else if }* else". For example, with a
switch statement you have to dispatch on the one value for every
case.

In some languages, it's even of more limited, e.g., C, which can
switch on only integers.

-- 
Neil Cerutti
Next Sunday Mrs. Vinson will be soloist for the morning service. The pastor
will then speak on "It's a Terrible Experience." --Church Bulletin Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global package variable, is it possible?

2007-08-03 Thread Fabio Z Tessitore

Heve you tried to do something like:

# module configure.py
value1 = 10
value2 = 20
...


# other module
from configure import *

# now I'm able to use value1 value2 etc.
var = value1 * value2

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


Re: i am new to python-Please somebody help

2007-08-03 Thread Zentrader
On the discussion of rudeness, we have to include the OP.  He/She/it
did not even attempt a Google before posting, and posted with a
meaningless subject.  We'll chalk that up to newness, but some sort of
retort was called for IMHO.  How else do we learn the conventions that
govern rudeness.  Personally, there is only one form of rudeness that
can not be overlooked and that is the prima donna that says "My Way Is
The Only Way", or posts some nonsense like "that is not correct" with
no other explanation.  Any attempt to sincerely help, I can live with.

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


Strange set of errors

2007-08-03 Thread Stephen Webb
Greetings all,

I've recently begun using Python to do scientific computation, and I wrote
the following script to find approximate eigenvalues for a semi-infinite
matrix:


from pylab import *
from numpy import *
from scipy import *

def bandstructure(N,s):

b = s/4.0

jmax = 10 + N**2

spectrum1 = [0]*2*N
spectrum2 = [0]*2*N
spectrum3 = [0]*2*N


for k in arange(1, 2*N+1, 1):

A = zeros( (jmax,jmax) )

i = 0
while i <= jmax-1:
if i <= jmax-2:
A[i,i+1] = b
A[i+1,i] = b
A[i,i] = ((k + 2.0*i*N)/N)**2
i = i+1
else:
A[i,i] = ((k + 2.0*i*N)/N)**2
i = i+1

#This portion of the code builds a matrix twice as large to check
against

B = zeros( (2*jmax,2*jmax) )

i = 0
while i <= 2*jmax-1:
if i <= 2*jmax-2:
B[i,i+1] = b
B[i+1,i] = b
B[i,i] = ((k + 2.0*i*N)/N)**2
i = i+1
else:
B[i,i] = ((k + 2.0*i*N)/N)**2
i = i+1

x = linalg.eigvals(A)
y = linalg.eigvals(B)

j = 1
while j<=3:
if abs(y[j]-x[j]) <= 10.0**(-5):
j = j + 1
else:
print 'jmax not large enough to obtain accurate results'

spectrum1[k-1] = x[0] + 0.5*s
spectrum2[k-1] = x[1] + 0.5*s
spectrum3[k-1] = x[2] + 0.5*s

plot (k, spectrum1, k, spectrum2, k, spectrum3)

xlabel('k (energy level)')
ylabel('E/E_r')
title('Finite Size Band Structure, N = %d, s = %f' % (N, s))
grid(true)


When I run this script, I get the following message, which I can't figure
out:

Traceback (most recent call last):
  File "", line 1, in 
  File "bandstruc.py", line 61, in bandstructure
plot (k, spectrum1, k, spectrum2, k, spectrum3)
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pylab.py",
line 2028, in plot
ret =  gca().plot(*args, **kwargs)
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py",
line 2535, in plot
for line in self._get_lines(*args, **kwargs):
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py",
line 437, in _grab_next_args
for seg in self._plot_2_args(remaining[:2], **kwargs):
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py",
line 337, in _plot_2_args
x, y, multicol = self._xy_from_xy(x, y)
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py",
line 266, in _xy_from_xy
nrx, ncx = x.shape
ValueError: need more than 0 values to unpack

Also, I've been having trouble with the plot function in matplotlib. For
example, I enter the following in the terminal:

>>> from pylab import *
>>> plot([1,2,3])
[]

I'm reasonably sure that the issue in the first big error message is just an
indexing error on my part, but I have no idea what the second thing means.
Every time I run the plot([1,2,3]) I get a different ending number that
seems to vary randomly.

Could anybody please help me out with these problems?

Thanks,

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

Re: i am new to python-Please somebody help

2007-08-03 Thread Zentrader
BTW - on the subject of polite discussions, how about this one as an
example of opinions politely expressed.
Oh, and does anyone know how to use zip in Python.  Yes+1.

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


Re: Global package variable, is it possible?

2007-08-03 Thread Carsten Haese
On Fri, 2007-08-03 at 17:51 +, Fabio Z Tessitore wrote:
> Heve you tried to do something like:
> 
> # module configure.py
> value1 = 10
> value2 = 20
> ...
> 
> 
> # other module
> from configure import *
> 
> # now I'm able to use value1 value2 etc.
> var = value1 * value2

Right idea, wrong execution. Note that the OP said "I'd like to be able
to reload the config file dynamically and have all my modules
automatically receive the new config."

"from configure import *" will import the settings into the current
namespace, and subsequent changes in the original namespace will, in
general, not have any effect in the current namespace.

This should do the trick:

# module configure.py
value1 = 10
value2 = 20
...

# other module
import configure

var = configure.value1 * configure.value2

HTH,

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


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


►►►Get FREE Satellite TV on your PC ◄◄◄

2007-08-03 Thread Ana James
Watch Satellite TV On Your Computer Without Paying Monthly Fees... FOR
FREE?

Watch all your favorite shows on your Computer from anywhere in the
World!

Save 1000's of $$$ over many years on cable and satellite bills.

INSTANT DOWNLOAD

Plus Free Unlimited Downloads Movies, MP3s Music, etc !!!

More Details: http://tvonpc.us.to/

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


RE: File Handling & TRY/EXCEPT

2007-08-03 Thread Alex Popescu
"Robert Rawlins - Think Blue" <[EMAIL PROTECTED]>
wrote in news:[EMAIL PROTECTED]: 

> Thanks for your ideas guys,
> 
> I'm unfortunately tied to 2.4 so don't have the full try except
> status, but I'm now working with the following code:
> 
>  def addApp(self, event):
>   try:
>logfile =
> open('/pblue/new/Logs/Application.csv','a')
> 
>now = datetime.datetime.now()
>logstring = '%s,%s \n' % (event, str(now))
>
>try:
> logfile.write(logstring)
>finally:
> logfile.close()
>   except:
>self.addApp(event)
> 
> I'm trying to slowly debug my app and get rid of all the memory leaks,
> but its pain staking work, any help you can offer on that stuff would
> be a god send, I'm a little reluctant about posting all my app code on
> the lists as I'd like to keep some of it private.
> 
> How does that new version look? A little tidier?
> 
> Thanks guys,
> 

Now, you are sure the file is always close. What I don't think is 
correct is to retry to re-write the event (cause if opening the file 
crashed ones there are very good chances that it will throw the 2nd 
time).

./alex
--
.w( the_mindstorm )p.

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


Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Terry Reedy

Skip Montanaro a écrit :
>>> In this case there was a bug.  Depending on inputs, sometimes obj
>>> initialized to a class, sometimes an instance of that class.  (I fixed
>>> that too while I was at it.)  The problem was that the use of __call__
>>> obscured the underlying bug by making the instance as well as the class
>>> callable.
>
>> I don't quite get the point here. A concrete example would be welcome.
>
> The bug went something like this:
>
> obj = some.default_class
> ...
> if some_other_rare_condition_met:
> ... several lines ...
> obj = some.other_class()

Should that have been some.other_class (without the ()s?).  It is in the 
nature of Python's dynamic typing that mis-typing errors sometimes show up 
later than one would wish.  Hence the need for unit testing.  Consider

i = condition and 1 or '2' # whoops, should have been 2, without the 's
...
k = j * i # j an int; whoops, bad i value passes silently
...
use of k as string raises exception

I do not think __call__ should be specifically blamed for this general 
downside of Python's design.

Terry Jan Reedy



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

downloading files

2007-08-03 Thread Ehsan
I foundd this code in ASPN  Python Cookbook for downloading files in
python but when it finished downloading files the files became
corrupted and didn't open, the files in internet havn't any problem:


def download(url,fileName):
"""Copy the contents of a file from a given URL
to a local file.
"""
import urllib
webFile = urllib.urlopen(url)
localFile = open(fileName, 'w')
localFile.write(webFile.read())
webFile.close()
localFile.close()
download('http://www.2shared.com/download/1839752/cd520048/
xpersia14.3gp?tsid=20070803-143313-49566ea2', 'xpersia4.3gp' )

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


Re: Global package variable, is it possible?

2007-08-03 Thread Chris Allen
> Hmm. So maybe something like this makes sense:
>
> __init__py:
> ###
> _default_cfg_file = 'config.conf'
>
> import configure
> def loadcfg(filename):
> configure.cfgfile = filename
> try:
> reload(pkg_module1)
> reload(pkg_module2)
> except NameError:
> pass
> cfg = loadcfg(_default_cfg_file)
>
> import pkg_module1
> import pkg_module2
> # EOF
>
> confgure.py:
> ###
> cfgfile = None
> def loadcfg()
> global cfgfile
> if not cfgfile:
> return None
> file = open(cfgfile)
> cfg = SafeConfigParser()
> cfg.readfp(file)
> return cfg
> # EOF
>
> pkg_module1:
> ###
> import configure
> cfg = configure.loadcfg()
> # EOF
>
> It's a little bit convoluted, but I think it solves most of my
> gripes.  Anybody have a better idea of how to do this?  Thanks again
> Fabio.

Ugh... I wasn't thinking... Of course this won't work either for the
same reasons above.  changing configure.cfgfile from __init__.py will
have no effect on the separate configure instances loaded in other
modules.  I still don't understand why python's __init__.py namespace
isn't global to all modules in the package.  Is this a feature, to
prevent sloppy code?  I think there are certain instances when it
would make sense.

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


Re: Global package variable, is it possible?

2007-08-03 Thread Chris Allen
On Aug 3, 11:16 am, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Fri, 2007-08-03 at 17:51 +, Fabio Z Tessitore wrote:
> > Heve you tried to do something like:
>
> > # module configure.py
> > value1 = 10
> > value2 = 20
> > ...
>
> > # other module
> > from configure import *
>
> > # now I'm able to use value1 value2 etc.
> > var = value1 * value2
>
> Right idea, wrong execution. Note that the OP said "I'd like to be able
> to reload the config file dynamically and have all my modules
> automatically receive the new config."
>
> "from configure import *" will import the settings into the current
> namespace, and subsequent changes in the original namespace will, in
> general, not have any effect in the current namespace.
>
> This should do the trick:
>
> # module configure.py
> value1 = 10
> value2 = 20
> ...
>
> # other module
> import configure
>
> var = configure.value1 * configure.value2
>
> HTH,
>
> --
> Carsten Haesehttp://informixdb.sourceforge.net

It does help thanks.  Okay now after reading your post I really need
to do some experimenting.  I was under the impression when I wrote my
last post that changing an attribute in one modules instance in
__init__.py would not effect other modules.  Sorry, I'm relatively new
to python, and things like this are still sometimes "gotchas!" for me.

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


Re: downloading files

2007-08-03 Thread Steve Holden
Ehsan wrote:
> I foundd this code in ASPN  Python Cookbook for downloading files in
> python but when it finished downloading files the files became
> corrupted and didn't open, the files in internet havn't any problem:
> 
> 
> def download(url,fileName):
>   """Copy the contents of a file from a given URL
>   to a local file.
>   """
>   import urllib
>   webFile = urllib.urlopen(url)
>   localFile = open(fileName, 'w')
>   localFile.write(webFile.read())
>   webFile.close()
>   localFile.close()
> download('http://www.2shared.com/download/1839752/cd520048/
> xpersia14.3gp?tsid=20070803-143313-49566ea2', 'xpersia4.3gp' )
> 
I'm guessing there are binary files and you are running on Windows, 
which is inserting a carriage return before ebery newline. Try

localFile = open(fileName, 'wb')

to avoid thus behavior.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: downloading files

2007-08-03 Thread Carsten Haese
On Fri, 2007-08-03 at 11:48 -0700, Ehsan wrote:
> I foundd this code in ASPN  Python Cookbook for downloading files in
> python but when it finished downloading files the files became
> corrupted and didn't open, the files in internet havn't any problem:
> 
> 
> def download(url,fileName):
>   """Copy the contents of a file from a given URL
>   to a local file.
>   """
>   import urllib
>   webFile = urllib.urlopen(url)
>   localFile = open(fileName, 'w')
> [...]

Try 'wb' instead of 'w'.

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


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


Re: (no) fast boolean evaluation ? missing NOT

2007-08-03 Thread Terry Reedy

"Stef Mientki" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| John Machin wrote:
| So now I'm left with just one question:
| for bitwise operations I should use &, |, ^
| for boolean operations I should use and, or, xor
| but after doing some test I find strange effects:
| >>> A = 4
| >>> B = 5
| >>> A and B
| 5

>>> B and A
4

| >>> A & B
| 4
| >>> A or B
| 4

>>> B or A
5

| >>> A | B
| 5
|
| So if I use the bitwise operation on integers,
|   "and" changes into (bitwise) "or" and vise versa.

No, you hypnotised yourself by generalizing from insufficient data.
Repeat experiment with, for instance, 3 and 4 instead of 4 and 5.  Then 3&4 
= 0, 3|4 = 7.

tjr



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


Re: Global package variable, is it possible?

2007-08-03 Thread Chris Allen
On Aug 3, 10:51 am, Fabio Z Tessitore <[EMAIL PROTECTED]>
wrote:
> Heve you tried to do something like:
>
> # module configure.py
> value1 = 10
> value2 = 20
> ...
>
> # other module
> from configure import *
>
> # now I'm able to use value1 value2 etc.
> var = value1 * value2
>
> bye


Thanks for the response Fabio.  I thought about this, but I don't
think this will work well in my situation either.  Take a look at the
following:

__init__py:
###
_default_cfgfile = 'config.conf'
from configure import *
cfg = loadcfg(_default_cfgfile)

import pkg_module1
import pkg_module2
# EOF


configure.py:

from ConfigParser import SafeConfigParser

def loadcfg(filename):
file = open(filename)
cfg = SafeConfigParser()
cfg.readfp(file)
return cfg
# EOF

pkg_module1:

_default_cfgfile = 'config.conf'
from configure import *
cfg = loadcfg(_default_cfgfile)
# EOF


One problem I see with this approach is that we must define the
configuration file in every module.  Alternatively a better approach
would be to only define the configuration file within configure.py,
however this also seems less than ideal.  I don't like it because I
believe something as important as the location of the package
configuration file, used by all modules, should defined in __init__
not tucked away in one of it's modules.

Another problem is that after the package is loaded and we want to
load in a new config file, what will happen?  With this approach we'll
have to reload every module the package uses for them to read the new
config.  And even then, how do we tell each module what the new config
file is?  If I did define the configuration file in configure.py then
I suppose what I could do is set a cfgfile variable in configure.py to
the new file location and reload all the modules.  If there is no
global package variables, then maybe this isn't so bad...

Hmm. So maybe something like this makes sense:

__init__py:
###
_default_cfg_file = 'config.conf'

import configure
def loadcfg(filename):
configure.cfgfile = filename
try:
reload(pkg_module1)
reload(pkg_module2)
except NameError:
pass
cfg = loadcfg(_default_cfg_file)

import pkg_module1
import pkg_module2
# EOF

confgure.py:
###
cfgfile = None
def loadcfg()
global cfgfile
if not cfgfile:
return None
file = open(cfgfile)
cfg = SafeConfigParser()
cfg.readfp(file)
return cfg
# EOF

pkg_module1:
###
import configure
cfg = configure.loadcfg()
# EOF

It's a little bit convoluted, but I think it solves most of my
gripes.  Anybody have a better idea of how to do this?  Thanks again
Fabio.

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


Re: Trying to find zip codes/rest example

2007-08-03 Thread Terry Reedy

"VanL" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
|
| I now cannot find this demo and the associated discussion.  Does anybody
| remember this demo and where I might be able to find it?

No, but does the localflavor entry on
http://code.djangoproject.com/browser/django/trunk/docs/add_ons.txt?rev=5118
help? (found with Google) 



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


Announcing Wing IDE 101 for teaching intro programming courses

2007-08-03 Thread Wingware
Hi,

We're pleased to announce the first public beta release of Wing IDE 101,
a free scaled back edition of Wing IDE that was designed for teaching
introductory programming courses.

We are releasing Wing IDE 101 to the general public in the hopes
that it may help others teach with or learn Python.  Wingware also
offers educational pricing for Wing IDE Professional, including steep
discounts for class room use.  If you are interested in teaching
Python with Wing IDE, please email [EMAIL PROTECTED] for more
information.

Key features of Wing IDE 101 include:

   * Powerful Editor -- Syntax highlighting, goto-definition, navigation
 menus, error indicators, auto-indent, and keyboard emulation for
 Visual Studio, VI/Vim, Emacs, and Brief.
   * Python Shell -- Evaluate files and selections in the integrated Python 
shell.
   * Graphical Debugger -- Set breakpoints and view stack and program data.

Note that Wing IDE 101 omits auto-completion and most other code intelligence
features found in the other Wing IDE products. This was by design, so that
students are more conscious of the details of the language and the modules
that they are learning about.

Wing IDE 101 is available on Windows, Linux, and Mac OS X. It is free for all
non-commercial uses and does not require a license code to run.  Wing 101
is not, however, open source.

The current release is 3.0 beta1 and is available here:

http://wingware.com/downloads/wingide-101

General information for beta testers is here:

http://wingware.com/wingide/beta

More details on Wing 101's features are here:

http://wingware.com/wingide-101
http://wingware.com/wingide/features

Please direct bug reports and suggestions to [EMAIL PROTECTED]

Thanks!

The Wingware Team
Wingware | Python IDE
Advancing Software Development

www.wingware.com

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


Re: downloading files

2007-08-03 Thread kyosohma
On Aug 3, 1:48 pm, Ehsan <[EMAIL PROTECTED]> wrote:
> I foundd this code in ASPN  Python Cookbook for downloading files in
> python but when it finished downloading files the files became
> corrupted and didn't open, the files in internet havn't any problem:
>
> def download(url,fileName):
> """Copy the contents of a file from a given URL
> to a local file.
> """
> import urllib
> webFile = urllib.urlopen(url)
> localFile = open(fileName, 'w')
> localFile.write(webFile.read())
> webFile.close()
> localFile.close()
> download('http://www.2shared.com/download/1839752/cd520048/
> xpersia14.3gp?tsid=20070803-143313-49566ea2', 'xpersia4.3gp' )

Uhhh...you probably need to change the open() command to binary mode.
Replace that line with this:

localFile = open(fileName, mode='wb')

I tried it on my PC to download a photo from one of my sites and it
worked great.

Mike

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


Re: Eclipse and Python

2007-08-03 Thread kyosohma
On Aug 3, 11:22 am, "Danyelle Gragsone" <[EMAIL PROTECTED]> wrote:
> Does anyone have any suggested websites for learning Eclipse the python way?
>
> thanks,
> Danyelle

This article is a little old, but it might be helpful to you:

http://www.ibm.com/developerworks/library/os-ecant/

I found this too. It looks a little better:

http://pydev.sourceforge.net/

Have fun!

Mike

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


draggable Tkinter.Text widget

2007-08-03 Thread infidel
Inspired by effbot's recent Vroom! editor, I have been toying with my
own version.  I'd like to make the Text widget "draggable", kind of
like how you can drag a PDF document up and down in Adobe Reader.

Here's what I have so far:

from Tkinter import *

class Draggable(Text, object):

def __init__(self, parent, **options):
Text.__init__(self, parent, **options)
self.config(
borderwidth=0,
font="{Lucida Console} 10",
foreground="green",
background="black",
insertbackground="white", # cursor
selectforeground="green", # selection
selectbackground="#008000",
wrap=WORD, # use word wrapping
undo=True,
width=80,
)
self.bind('', self.handle_mousedown3)
self.bind('', self.handle_drag3)

def handle_mousedown3(self, event=None):
self._y = event.y

def handle_drag3(self, event=None):
self.yview_scroll(self._y - event.y, UNITS)
self._y = event.y

if __name__ == '__main__':
root = Tk()
root.protocol("WM_DELETE_WINDOW", root.quit)
root.config(background='black')
root.wm_state("zoomed")
text = Draggable(root)
text.delete(1.0, END)
text.insert(END, '\n'.join(str(x) for x in xrange(1, 1001)))
text.pack(fill=Y, expand=True)
root.mainloop()

This works fine, but because the mouse movements are in pixels and
scroll actions are in lines, the 'magnitude' of the scrolling is much
larger than the mouse movements causing them.  This isn't all bad, it
makes scanning a long document quickly easier, but I was wondering if
there was a simple way to add some "friction" to the scrolling so a
tiny mouse movement doesn't cause the text to go zipping by in a
flash.

Thanks,
infidel

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


os.listdir path error

2007-08-03 Thread vedrandekovic
Hello

Here is my simple listdir example:

>>> import os
>>> os.listdir("C:\Python24\") # This directory relly exists

Here is my error:

WindowsError: [Errno 3] The system cannot find the path specified: 'l/
*.*'

Regards,
Vedran

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


Re: Strange set of errors

2007-08-03 Thread Kurt Smith
Sorry, forgot to "Reply to all."

On 8/3/07, Stephen Webb <[EMAIL PROTECTED]> wrote:
> Greetings all,

<>

> Also, I've been having trouble with the plot function in matplotlib. For
> example, I enter the following in the terminal:
>
>  >>> from pylab import *
> >>> plot([1,2,3])
> []
>

I can help you with your second problem: matplotlib is doing what it
should, all you need to do is tell it to show() the figure you created
(with the plot on it.)  Note -- if you call the show() function, you
will turn control over to the backend (in my case, TkAgg), and lose
the ability to issue interactive commands afterwards.  A solution is
to use the ion() (stands for "interactive-on") function call before
issuing plotting commands:

>>> from pylab import *
>>> ion()
>>> plot([1,2,3])
[]
>>> # image is shown here

See http://matplotlib.sourceforge.net/interactive.html for an
exhaustive explanation.

> Every time I run the plot([1,2,3]) I get a different ending number that
> seems to vary randomly.

The "[]" is what the
plot() function returns -- a list of instances of the Line2D class,
and it tells you their locations in memory (hence the hex number
starting with 0x).  The hex number can be used to uniquely identify
this object, as in the id(object) call.

Hope this helps,

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


Re: os.listdir path error

2007-08-03 Thread Jerry Hill
On 8/3/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello
>
> Here is my simple listdir example:
>
> >>> import os
> >>> os.listdir("C:\Python24\") # This directory relly exists
>
> Here is my error:
>
> WindowsError: [Errno 3] The system cannot find the path specified: 'l/
> *.*'


That's a somewhat surprising error.  Under 2.5, I get a more helpful
error message:

>>> import os
>>> os.listdir("C:\Python25\")

SyntaxError: EOL while scanning single-quoted string

That's because I've escaped the closing quote of the string with \".
Use this instead:

>>> os.listdir("C:\\Python25\\")
or
>>> os.listdir("C:/Python25/")

since windows is usually happy to use forward slashes instead of
backslashes in directory names.

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


Re: os.listdir path error

2007-08-03 Thread kyosohma
On Aug 3, 2:50 pm, [EMAIL PROTECTED] wrote:
> Hello
>
> Here is my simple listdir example:
>
> >>> import os
> >>> os.listdir("C:\Python24\") # This directory relly exists
>
> Here is my error:
>
> WindowsError: [Errno 3] The system cannot find the path specified: 'l/
> *.*'
>
> Regards,
> Vedran

I get "SyntaxError: EOL while scanning single-quoted string", which is
what should happen when you escape the double-quotes at the end. Not
sure how you're getting that WindowsErrors.

If I do  os.listdir('c:\python24')  instead, it works fine.

Mike

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


Re: Trying to find zip codes/rest example

2007-08-03 Thread VanL
Terry Reedy wrote:
> No, but does the localflavor entry on
> http://code.djangoproject.com/browser/django/trunk/docs/add_ons.txt?rev=5118
> help? (found with Google) 

Thanks, but no.  A friend asked for advice about implementing a 
password-checking interface; I remembered that the method described in 
the article seemed particularly slick.  I wanted to refer it to him as a 
sample "best practices" link.


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


Re: Strange set of errors

2007-08-03 Thread Kurt Smith
On 8/3/07, Stephen Webb <[EMAIL PROTECTED]> wrote:
> Greetings all,
>
> I've recently begun using Python to do scientific computation, and I wrote
> the following script to find approximate eigenvalues for a semi-infinite
> matrix:
>
>
>  from pylab import *
> from numpy import *
> from scipy import *
>
> def bandstructure(N,s):
>
> b = s/4.0
>
> jmax = 10 + N**2
>
> spectrum1 = [0]*2*N
> spectrum2 = [0]*2*N
> spectrum3 = [0]*2*N
>
>
> for k in arange(1, 2*N+1, 1):
>
> A = zeros( (jmax,jmax) )
>
> i = 0
> while i <= jmax-1:
> if i <= jmax-2:
> A[i,i+1] = b
> A[i+1,i] = b
> A[i,i] = ((k + 2.0*i*N)/N)**2
> i = i+1
> else:
> A[i,i] = ((k + 2.0*i*N)/N)**2
> i = i+1
>
> #This portion of the code builds a matrix twice as large to check
> against
>
> B = zeros( (2*jmax,2*jmax) )
>
> i = 0
> while i <= 2*jmax-1:
> if i <= 2*jmax-2:
> B[i,i+1] = b
> B[i+1,i] = b
> B[i,i] = ((k + 2.0*i*N)/N)**2
> i = i+1
> else:
> B[i,i] = ((k + 2.0*i*N)/N)**2
> i = i+1
>
> x = linalg.eigvals(A)
> y = linalg.eigvals(B)
>
> j = 1
> while j<=3:
> if abs(y[j]-x[j]) <= 10.0**(-5):
> j = j + 1
> else:
> print 'jmax not large enough to obtain accurate results'
>
> spectrum1[k-1] = x[0] + 0.5*s
> spectrum2[k-1] = x[1] + 0.5*s
> spectrum3[k-1] = x[2] + 0.5*s
>
> plot (k, spectrum1, k, spectrum2, k, spectrum3)
>
> xlabel('k (energy level)')
> ylabel('E/E_r')
> title('Finite Size Band Structure, N = %d, s = %f' % (N, s))
> grid(true)
>
>
> When I run this script, I get the following message, which I can't figure
> out:
>
>  Traceback (most recent call last):
>   File "", line 1, in 
>   File "bandstruc.py", line 61, in bandstructure
> plot (k, spectrum1, k, spectrum2, k, spectrum3)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pylab.py",
> line 2028, in plot
> ret =  gca().plot(*args, **kwargs)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py",
> line 2535, in plot
> for line in self._get_lines(*args, **kwargs):
>   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py",
> line 437, in _grab_next_args
> for seg in self._plot_2_args(remaining[:2], **kwargs):
>   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py",
> line 337, in _plot_2_args
> x, y, multicol = self._xy_from_xy(x, y)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py",
> line 266, in _xy_from_xy
> nrx, ncx = x.shape
>  ValueError: need more than 0 values to unpack
>


Basically, you're trying to plot spectrum[123] vs. k: the spectra are
lists, but k is an integer.  I made some modifications to get things
working more smoothly.  Note the ion() function call at the beginning,
and the use of "indx = arange(1,2*N+1)" instead of plotting vs. k.

There's probably some other things that could be cleaned up, but I'm
short on time right now; this will get your code working at least.

Hope this helps,
(From a fellow physicist)
Kurt

##

from pylab import *
from numpy import *

ion()

def bandstructure(N,s):

b = s/4.0

jmax = 10 + N**2

spectrum1 = [0]*2*N
spectrum2 = [0]*2*N
spectrum3 = [0]*2*N


for k in arange(1, 2*N+1, 1):

A = zeros( (jmax,jmax) )

i = 0
while i <= jmax-1:
if i <= jmax-2:
A[i,i+1] = b
A[i+1,i] = b
A[i,i] = ((k + 2.0*i*N)/N)**2
i = i+1
else:
A[i,i] = ((k + 2.0*i*N)/N)**2
i = i+1

#This portion of the code builds a matrix twice as large to
check against

B = zeros( (2*jmax,2*jmax) )

i = 0
while i <= 2*jmax-1:
if i <= 2*jmax-2:
B[i,i+1] = b
B[i+1,i] = b
B[i,i] = ((k + 2.0*i*N)/N)**2
i = i+1
else:
B[i,i] = ((k + 2.0*i*N)/N)**2
i = i+1

x = linalg.eigvals(A)
y = linalg.eigvals(B)

j = 1
while j<=3:
if abs(y[j]-x[j]) <= 10.0**(-5):
j = j + 1
else:
print 'jmax not large enough to obtain accurate results'

spectrum1[k-1] = x[0] + 0.5*s
spectrum2[k-1] = x[1] + 0.5*s
spectrum3[k-1] = x[2] + 0.5*s

indx = arange(1,2*N+1, 1)
plot (indx, spectr

libpq.dll for pgdb

2007-08-03 Thread ekzept
the module PGDB which gives Python access to PostgreSql currently
wants for a copy of a properly located or proper libpq.dll library, on
Windows.

anyone know what the current story on this is?

thanks,

 -- jt

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


ANNOUNCE: Spiff Workflow 0.0.1 (Initial Release)

2007-08-03 Thread Samuel
Introduction

Spiff Workflow is a library implementing a framework for workflows. It
is based on http://www.workflowpatterns.com and implemented in pure
Python. Supported workflow patterns include (at least) the following:

 1. Sequence
 2. Parallel Split
 3. Synchronization
 4. Exclusive Choice
 5. Simple Merge
 6. Multi-Choice
 7. Structured Synchronizing Merge
 8. Multi-Merge
 9. Structured Discriminator
10. Arbitrary Cycles

Spiff Workflow is part of the Spiff platform, which aims to produce a
number of generic libraries generally needed in enterprise
applications. This release is the initial release and SHOULD NOT BE
USED IN PRODUCTION ENVIRONMENTS - this release is meant for
development only.

Spiff Workflow is free software and distributed under the GNU
LGPLv2.1.

Dependencies
-
Python >= 2.4

Download
-
The release page is here:
http://pypi.python.org/pypi/Spiff%20Workflow/0.0.1

You can also check the code out of SVN:
svn checkout http://spiff.googlecode.com/svn/trunk/libs/Workflow/

Links:
---
Spiff project page: http://code.google.com/p/spiff/
Mailing list: http://groups.google.com/group/spiff-devel
Bug tracker: http://code.google.com/p/spiff/issues/list
Documentation: http://spiff.googlecode.com/svn/trunk/libs/Workflow/README
Browse the source: http://spiff.googlecode.com/svn/trunk/libs/Workflow/

If you have any questions, please do not hesitate to ask.

-Samuel

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


Re: Global package variable, is it possible?

2007-08-03 Thread Fabio Z Tessitore
Il Fri, 03 Aug 2007 14:16:59 -0400, Carsten Haese ha scritto:

> Right idea, wrong execution. Note that the OP said "I'd like to be able
> to reload the config file dynamically and have all my modules
> automatically receive the new config."

You are obviously right ... I haven't read all the post, sorry!

Only for knowing more about modules: is there a way to dinamically reload 
an already imported module?

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


Re: Global package variable, is it possible?

2007-08-03 Thread Chris Allen
> Only for knowing more about modules: is there a way to dinamically reload
> an already imported module?
>
> bye
> Fabio

Yeah you can reload modules with the reload builtin function.

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


Re: downloading files

2007-08-03 Thread Ehsan
On Aug 3, 10:10 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> Ehsan wrote:
> > I foundd this code in ASPN  Python Cookbook for downloading files in
> > python but when it finished downloading files the files became
> > corrupted and didn't open, the files in internet havn't any problem:
>
> > def download(url,fileName):
> >"""Copy the contents of a file from a given URL
> >to a local file.
> >"""
> >import urllib
> >webFile = urllib.urlopen(url)
> >localFile = open(fileName, 'w')
> >localFile.write(webFile.read())
> >webFile.close()
> >localFile.close()
> > download('http://www.2shared.com/download/1839752/cd520048/
> > xpersia14.3gp?tsid=20070803-143313-49566ea2', 'xpersia4.3gp' )
>
> I'm guessing there are binary files and you are running on Windows,
> which is inserting a carriage return before ebery newline. Try
>
> localFile = open(fileName, 'wb')
>
> to avoid thus behavior.
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb  http://del.icio.us/steve.holden
> --- Asciimercial --
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> --- Thank You for Reading -- Hide quoted text -
>
> - Show quoted text -

thanx Steve
It works but could you explain more what's wrong with just 'w'?

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


regexp problem in Python

2007-08-03 Thread Ehsan
I want to find "http://www.2shared.com/download/1716611/e2000f22/
Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11"  or 3gp instead of
wmv in the text file like this :

""some code""
function reportAbuse() {
var windowname="abuse";
var url="/abuse.jsp?link=" + "http://www.2shared.com/file/1716611/
e2000f22/Jadeed_Mlak14.html";
OpenWindow =
window.open(url,windowname,'toolbar=no,scrollbars=no,resizable=no,width=500,height=500,left=50,top=50');
OpenWindow.focus();
  }
  function startDownload(){
window.location = "http://www.2shared.com/download/1716611/
e2000f22/Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11";
//document.downloadForm.submit();
  }
  

http://www.2shared.com/download/1716611/e2000f22/
Jadeed_Mlak14.3gp?tsid=20070803-164051-9d637d11"sfgsfgsfgv




I use this pattern :
"http.*?\.(wmv|3gp).*""

but it returns only 'wmv' and '3gp' instead of "http://www.2shared.com/
download/1716611/e2000f22/Jadeed_Mlak14.wmv?
tsid=20070803-164051-9d637d11"

what can I do? what's wrong whit this pattern? thanx for your comments

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


Re: Eclipse/PyDev question.

2007-08-03 Thread Fabio Zadrozny
On 8/3/07, king kikapu <[EMAIL PROTECTED]> wrote:
>
> Hi,
> this is actually a question to those of us who use Eclipse and Pydev
> as their main Python developing environment. As i use Eclipse (3.3
> Europa) only for Python and i have nothing to do with Java, is there a
> way to disable/uninstall some Java-specific stuff and make the
> environment actually more snappy ??
>
> thanks for any help
>
>
You can actually just get the Eclipse 'runtime' distribution (without java
stuff) and install pydev with it (latest version -- previous versions had a
dependency on some java stuff). Reference:
http://pydev.blogspot.com/2007/06/pydev-and-jdt-sdk-not-required-anymore.html

Cheers,

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

amra and py2exe

2007-08-03 Thread vinod
Hi i am having trouble creating exe using py2exe for amara package
i saw some posts related to this talking about amara cat file but i
dont have any cat file for amara on my machine.
the standalone script runs fine. i am using python on windows
here is the error i am getting while creating the exe
The following modules appear to be missing
['amara', 'ext.IsDOMString', 'ext.SplitQName']

can anybody please help me with this?

Thanks,
Vinod

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


  1   2   >