Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
I've produced a 4 page document that provides a very concise summary
of Python 2-3 differences plus the most commonly used new Python 3
features. It is aimed at existing Python 2 programmers who want to
start writing Python 3 programs and want to use Python 3 idioms rather
than those from Python 2 where the idioms differ.

It uses Python 3.1 syntax since that looks like being the standard for
a few years in view of the language moratorium.

The document is U.S. Letter size but will also print fine on A4
printers.

It is available as a free PDF download (no registration or anything)
from InformIT's website. Here's the direct link:
http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/python/python2python3.pdf

And of course, if you want more on Python 3, there's always the
documentation---or my book:-)
Programming in Python 3 (Second Edition) ISBN-10: 0321680561.
--
Mark Summerfield, www.qtrac.eu
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


PyLinkedIn 0.02

2009-12-02 Thread Max Lynch
Hi,
I wrote a small library to interact with the newly opened LinkedIn OAuth
API.  Right now you can get the status of the current user and his/her
connections.  More will be added as needed in my own software.

At least one person found it useful so far, so I hope some other people do
as well.

http://code.google.com/p/pylinkedin/

Thanks,
Max Lynch
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[ANN] doit 0.5

2009-12-02 Thread Eduardo Schettino
doit - Automation Tool

doit comes from the idea of bringing the power of build-tools to
execute any kind of task. It will keep track of dependencies between
tasks and execute them only when necessary. It was designed to be
easy to use and get out of your way.

doit can be used as:

    * a build tool (generic and flexible)
    * home of your management scripts (it helps you organize and
combine shell scripts and python scripts)
     * a functional tests runner (combine together different tools)

homepage: http://python-doit.sourceforge.net/
PyPi: http://pypi.python.org/pypi/doit
license: MIT
contact: https://launchpad.net/~schettino72

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


ANN: Twisted 9.0.0

2009-12-02 Thread Christopher Armstrong
= Twisted 9.0.0 =

I'm happy to announce Twisted 9, the first (and last) release of
Twisted in 2009. The previous release was Twisted 8.2 in December of
2008. Given that, a lot has changed!

This release supports Python 2.3 through Python 2.6, though it is the
last one that will support Python 2.3. The next release will support
only Python 2.4 and above. Twisted: the framework of the future!

You can download the new release at our web site,

http://twistedmatrix.com/

There were around 285 tickets resolved in this release. The full list
of changes is available here:


http://twistedmatrix.com/trac/browser/tags/releases/twisted-9.0.0/NEWS?format=raw

It's quite a huge list of changes spanning almost all of the Twisted
projects, so here are some of the more exciting changes:

In the core:
- The Windows IOCP reactor now supports SSL.
- The memcache protocol implementation got some nice new features.

In Twisted Web:
- There's a new HTTP client API and protocol implementation, starting
at twisted.web.client.Agent. It's still pretty low-level, but much
more flexible than the old API.
- There were many improvements to the WSGI support.

In Twisted Conch:
- PyASN1 is now used to parse SSH keys (which means you now need to
install it to use Conch).
- SFTP servers (especially on Windows) now behave a lot better.

In Twisted Mail:
- The IMAP server and client protocol implementations had many fixes.
For example, SASL PLAIN credentials now work.

In Twisted Words:
- XMPP clients now support the ANONYMOUS SASL authentication type.
- The IRC protocol implementations had many fixes.

And a lot more.


= What is Twisted? =

From the web site:

Twisted is an event-driven networking engine written in Python and
licensed under the MIT license.

See the FAQ for commonly asked questions about Twisted.

http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions

If you want to get started with Twisted, the first thing you should do
is read the Twisted Core Documentation.

http://twistedmatrix.com/projects/core/documentation/howto/index.html

Twisted projects variously support TCP, UDP, SSL/TLS, multicast, Unix
sockets, a large number of protocols (including HTTP, NNTP, IMAP, SSH,
IRC, FTP, and others), and much more.

Enjoy!

-- 
Christopher Armstrong
http://radix.twistedmatrix.com/
http://planet-if.com/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
On 1 Dec, 17:50, Mark Dickinson dicki...@gmail.com wrote:
 On Dec 1, 2:03 pm, Mark Summerfield l...@qtrac.plus.com wrote:

  I've produced a 4 page document that provides a very concise summary
  of Python 2-3 differences plus the most commonly used new Python 3
  features.

 Very nice indeed!

 My only quibble is with the statement on the first page that
 the 'String % operator is deprecated'.  I'm not sure that's
 true, for all values of 'deprecated'.  There don't appear
 to be any definite plans for getting rid of it just yet.

 Mark

I didn't make this up:-)

According to http://docs.python.org/dev/3.0/whatsnew/3.0.html
The plan is to eventually make this the only API for string
formatting, and to start deprecating the % operator in Python 3.1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
On 1 Dec, 18:30, Lie Ryan lie.1...@gmail.com wrote:
 On 12/2/2009 1:03 AM, Mark Summerfield wrote:



  I've produced a 4 page document that provides a very concise summary
  of Python 2-3 differences plus the most commonly used new Python 3
  features. It is aimed at existing Python 2 programmers who want to
  start writing Python 3 programs and want to use Python 3 idioms rather
  than those from Python 2 where the idioms differ.

  It uses Python 3.1 syntax since that looks like being the standard for
  a few years in view of the language moratorium.

  The document is U.S. Letter size but will also print fine on A4
  printers.

  It is available as a free PDF download (no registration or anything)
  from InformIT's website. Here's the direct link:
 http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/...

  And of course, if you want more on Python 3, there's always the
  documentation---or my book:-)
  Programming in Python 3 (Second Edition) ISBN-10: 0321680561.

 Nice.

Thanks!

 I suggest changing the lambda example a bit, the current example says:
 Python 2                      Python 3
 lambda (a,b): a + b           lambda t: t[0] + t[1]
                                lambda a, b: a + b

 into something like:

 Python 2                      Python 3
 lambda (a,b),c: a + b + c     lambda t, c: t[0] + t[1] + c
                                lambda a, b, c: a + b + c

 it is unclear at first sight that it refers to tuple argument unpacking.

Your proposed example is clearer in some respects, but mine is more
minimal. And I think that anyone who _thinks_ about mine will get the
point. (The document is short, but I never claimed it was a quick
read;-)

 There should also some mention that tuple argument unpacking for regular
 function (def) is also gone.

I probably should have, but it is hard to fit any more in... esp.
since I don't want to take anything out.

 Also, I'm not sure what this change is referring to:
 Python 2                 Python 3
 L = list(seq)            L = sorted(seq)
 L.sort()

 L.sort is still available in python, and sorted() have been available
 since python 2. Both list.sort() and sorted() are for different purpose,
 and neither will be deprecated. What's the change here?

The document is about idioms as well as changes. In this case both
approaches work in both versions, but it seems that there are still a
lot of people who don't know about sorted(), so I put it in to show it
as an idiom.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
On 1 Dec, 21:55, Terry Reedy tjre...@udel.edu wrote:
 Mark Summerfield wrote:
  I've produced a 4 page document that provides a very concise summary
  of Python 2-3 differences plus the most commonly used new Python 3
  features. It is aimed at existing Python 2 programmers who want to
  start writing Python 3 programs and want to use Python 3 idioms rather
  than those from Python 2 where the idioms differ.

  It uses Python 3.1 syntax since that looks like being the standard for
  a few years in view of the language moratorium.

  The document is U.S. Letter size but will also print fine on A4
  printers.

  It is available as a free PDF download (no registration or anything)
  from InformIT's website. Here's the direct link:
 http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/...

  And of course, if you want more on Python 3, there's always the
  documentation---or my book:-)
  Programming in Python 3 (Second Edition) ISBN-10: 0321680561.

 What might be even *more* helpful, with contributions from others
 perhaps, would be an indication of which changes are handled
 automatically by 2to3.py and which must be done by hand.

 tjr

No, that's exactly what I did not want to cover and the document says
so up front. It is aimed at people who want Python 3 to come from
their own brains and fingers!

Also, the kind of info you're talking about is covered elsewhere, for
example:
http://diveintopython3.org/porting-code-to-python-3-with-2to3.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
On 1 Dec, 23:52, John Bokma j...@castleamber.com wrote:
 Mark Summerfield l...@qtrac.plus.com writes:
  It is available as a free PDF download (no registration or anything)
  from InformIT's website. Here's the direct link:
 http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/...

 Thanks!

  And of course, if you want more on Python 3, there's always the
  documentation---or my book:-)
  Programming in Python 3 (Second Edition) ISBN-10: 0321680561.

 Meh, second edition already? Haven't read the entire first edition
 yet. Which is IMO a good book (I also gave it to my brother as a
 present).

If it is any consolation, the second edition should have a much longer
life, now that we have the language moratorium. (I _really_ wanted to
cover 3.1.)

 Only negative point (to me) so far is that in the beginning (p8-9) the
 book mentions placing Python programs in C:\py3eg which gives me the
 unpleasant feeling that someone is coding on Windows XP with
 Administrator rights...

OK, you got me there, I only use Windows for testing purposes and my
personal logon account does have Administrator rights, which I assumed
was standard for personal machines? Also, the path is short. It is
only a suggestion, it really doesn't matter where you unpack the
examples.

 Anyway, will add the 2nd edition to my wish list and donate the current
 one to the library in Xalapa (USBI)  if they want it :-)

 John

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


Help in wxpython

2009-12-02 Thread madhura vadvalkar
Hi

I am trying to write an  PAINT like application where on the mouse
click a circle is drawn on canvas. I am new to python and using
wxpython to create this.

here is the code:

import wx

class SketchWindow(wx.Window):

def __init__ (self, parent,ID):

wx.Window.__init__(self, parent, ID)

self.panel =wx.Panel(self, size= (350,350))
self.pen=wx.Pen( 'blue',4)
self.pos=(0,0)
self.InitBuffer()
self.Bind(wx.EVT_LEFT_DOWN,self.OnLeftDown)

def InitBuffer(self):

size=self.GetClientSize()
self.Buffer=wx.EmptyBitmap(size.width,size.height)
dc=wx.BufferedDC(None,self.buffer)
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
self.Drawcircle(dc)
self.reInitBuffer=False

def OnLeftDown(self,event):
self.pos=event.GetPositionTuple()
self.CaptureMouse()

def Drawcircle(self,dc):
pen=wx.Pen(colour,thickness,wx.SOLID)
dc.SetPen(pen)
dc.DrawCircle(self.pos.x,self.pos.y,r)

class SketchFrame(wx.Frame):
def __init__(self, parent):

wx.Frame.__init__(self, parent, -1, Sketch Frame,size=(800,600))
self.sketch = SketchWindow(self, -1)

if __name__=='__main__':
app=wx.PySimpleApp()
frame=SketchFrame(None)
frame.Show(True)
app.MainLoop()

I am getting the following error:

Traceback (most recent call last):
  File C:/Python26/circle.py, line 42, in module
frame=SketchFrame(None)
  File C:/Python26/circle.py, line 38, in __init__
self.sketch = SketchWindow(self, -1)
  File C:/Python26/circle.py, line 12, in __init__
self.InitBuffer()
  File C:/Python26/circle.py, line 19, in InitBuffer
dc=wx.BufferedDC(None,self.buffer)
AttributeError: 'SketchWindow' object has no attribute 'buffer'

Please tell me what I am doing wrong.

Thanks









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


Re: getattr problem

2009-12-02 Thread Bruno Desthuilliers

Victor Subervi wrote:


(NB : answering to the OP - the post didn't show up on clpy)


Hi;
I have the following code that execute without a problem:


Fine. But it fails to execute here - ImportError on the 3rd line 
(options), NameErrors on the 4th line (addStore) and 5th line 
(optionTables).



import sys,os
sys.path.append(os.getcwd())
import options
storesTables = []


OT, but the official naming convention in Python is 
all_lower_with_underscores.



junkStores = string.join(addStore(), ', ')


junkStores = , .join(addStore())


for table in optionsTables():


OT again, but a general (not python-specific) naming rule is to use 
nouns for variables and verbs for functions. I almost failed to spot the 
parens after optionsTables. getOptionsTables or something like this 
would make your intent more obvious IM(NS)HO.



  if table not in ('particulars', junkStores):


I dont know for sure what junkStores looks like at this point, but given 
the call to string.join, chances are this test doesn't work as expected 
- cf the following snippet:



 foo = (bar, baaz, back)
 bar in foo
True
 baaz in foo
False




storesTables.append(table)
for table in storesTables:



You don't need two loops here - you could as well proceed as you go, ie:


for table in optionsTables():
   if pass_some_test(table):
   proceed_with(table)



  try:
fn = getattr(options, table)
print fn()
  except:
pass


RRRGHHH ! NO ! DONT ! EVER ! DO ! THAT !

You have to either *properly* handle and exception OR let it propagate. 
For the record, even sys.exit is implemented as an exception.



I need to change the obvious line to this or something similar (that 
actually works):


fn = getattr(options, '%s(names)' % table)

That is, I need to pass the variable names to each table as it is 
called.


How does this relate to the above line of code ???

It really looks like you're programming by accident (IOW : try anything 
until it seems to work, but without any understanding of what your 
code is *really* doing)



How do I do this?


If the question is how do I pass a variable to a function, then you 
probably didn't write the above code and shouldn't even touch it before 
you learn CS101. Else, please explain more exactly what you're trying to 
do - would be better with an executable, self-contained example.


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


Re: High-performance Python websites

2009-12-02 Thread Bruno Desthuilliers

Rami Chowdhury a écrit :

On Monday 30 November 2009 10:55:55 inhahe wrote:
On Wed, Nov 25, 2009 at 7:33 PM, ShoqulKutlu kursat.ku...@gmail.com 

wrote:

Hi,

Managing load of high volume of visitors is a common issue for all
kind of web technologies. I mean this is not the python issue. This
issue is mostly about server level designs. You need to supply load
balancing for both web servers and databases to make your web site
able to respond to several concurrent visitors. Of course a good
programmed website is a key performance issue but for your mention
I would also suggest considering how many hardwares, how many
webservers, how many database cluster and which database server
should be used or will be used in the future..

I don't know a lot about this issue, but take apache + php.  every
time a page is loaded a new instance of php  is loaded to run the
page, 


AFAIK that's only the case for PHP-CGI, and Python as a CGI scripting 
language is used the same way.


Yeps.

Apache is very often run with mod_php, 
though, which embeds the PHP interpreter; mod_python does something 
similar for Python.


Indeed.

And FWIW, this has very few impact wrt/ load balancing issues.

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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Dickinson
On Dec 2, 8:01 am, Mark Summerfield l...@qtrac.plus.com wrote:
 On 1 Dec, 17:50, Mark Dickinson dicki...@gmail.com wrote:
  My only quibble is with the statement on the first page that
  the 'String % operator is deprecated'.  I'm not sure that's
  true, for all values of 'deprecated'.  There don't appear
  to be any definite plans for getting rid of it just yet.

 I didn't make this up:-)

No, I didn't imagine for a second that you had!

 According to http://docs.python.org/dev/3.0/whatsnew/3.0.html
 The plan is to eventually make this the only API for string
 formatting, and to start deprecating the % operator in Python 3.1.

I think that's a doc bug.  The plan is to ... should read: The plan
was
originally to   (Well, at least in the 3.1 version of the
what's new in 3.0 documentation;  the 3.0 version that you linked to
isn't even autogenerated any more, AFAIK, so fixes to the ReST source
for that file never make it to the web site.)

I'm a little confused myself about what's actually happening with
% formatting, but here's a fairly recent python-dev posting from
the BDFL:

http://mail.python.org/pipermail/python-dev/2009-September/092399.html

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


Re: Recursion head scratcher

2009-12-02 Thread Dave Angel

Joel Madigan wrote:

Hi everyone!
Sorry this isn't strictly a Python question but my algorithms professor
contends that given the standard recursive-backtracking maze solving
algorithm:

width=6
height=4
maze=[[1,0,1,1,0,1],
  [0,0,1,0,0,0],
  [1,0,1,0,1,0],
  [0,0,0,0,1,1]]
visited = [[False for x in range(width)] for y in range(height)]

sx=1
sy=2
ex=4
ey=0

def findPath(x,y):
if (x  0 or x = width or y  0 or y = height):
return False
elif maze[y][x] == 1:
return False
elif visited[y][x]:
return False
elif (x == ex and y == ey):
print (%d,%d)%(x,y),
return True
else:
visited[y][x] = True

if findPath(x-1,y) or \
   findPath(x+1,y) or \
   findPath(x,y-1) or \
   findPath(x,y+1):
print (%d,%d)%(x,y),
return True
else:
return False

print findPath(sx,sy)

that it is possible to make it print the path to the finish in the order the
steps were taken.  That is, the algorithm as written produces:
(4,0) (4,1) (3,1) (3,2) (3,3) (2,3) (1,3) (1,2) True

Rather than
(1,2) (1,3) (2,3) (3,3) (3,2) (3,1) (4,1) (4,0) True

Furthermore, he claims it's a one line change without using a stack or any
other extra data structure.  But I can't figure it out to save my life.
 This isn't homework, there isn't credit on the line.  I think he said it
just to mess with us.  Can anyone point me in the right direction?  It's
driving me crazy.  The output it gives makes perfect sense, since it just
prints out each step as the stack unwinds.  Normally you would print the
output BEFORE recursing, but in this case you only want to print the step if
it is actually part of the path.  And you don't know that until after the
recursion.

Can anyone shed some light on this?

Thanks,
Joel

  
How about swapping sx,sy with ex,ey ?  That's one line (one statement).  
And the rest of the algorithm appears to be symmetric.  Basically, 
you're reversing time, and starting with the end point, descending till 
you find the start point.


DaveA

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


Re: Help in wxpython

2009-12-02 Thread Dave Angel



madhura vadvalkar wrote:

Hi

I am trying to write an  PAINT like application where on the mouse
click a circle is drawn on canvas. I am new to python and using
wxpython to create this.

here is the code:

import wx

class SketchWindow(wx.Window):

def __init__ (self, parent,ID):

wx.Window.__init__(self, parent, ID)

self.panel =wx.Panel(self, size= (350,350))
self.pen=wx.Pen( 'blue',4)
self.pos=(0,0)
self.InitBuffer()
self.Bind(wx.EVT_LEFT_DOWN,self.OnLeftDown)

def InitBuffer(self):

size=self.GetClientSize()
self.Buffer=wx.EmptyBitmap(size.width,size.height)
dc=wx.BufferedDC(None,self.buffer)
  


You spelled the instance attribute differently.  You initialized it as 
Buffer but reference it as buffer   Lowercase would be more standard.

snip
I am getting the following error:

Traceback (most recent call last):
  File C:/Python26/circle.py, line 42, in module
frame=SketchFrame(None)
  File C:/Python26/circle.py, line 38, in __init__
self.sketch = SketchWindow(self, -1)
  File C:/Python26/circle.py, line 12, in __init__
self.InitBuffer()
  File C:/Python26/circle.py, line 19, in InitBuffer
dc=wx.BufferedDC(None,self.buffer)
AttributeError: 'SketchWindow' object has no attribute 'buffer'

Please tell me what I am doing wrong.

Thanks


  

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


Re: Recursion head scratcher

2009-12-02 Thread Tim Wintle
On Wed, 2009-12-02 at 02:07 -0500, Joel Madigan wrote:
 
 that it is possible to make it print the path to the finish in the
 order the steps were taken.  That is, the algorithm as written
 produces: (4,0) (4,1) (3,1) (3,2) (3,3) (2,3) (1,3) (1,2) True 
 
 Rather than (1,2) (1,3) (2,3) (3,3) (3,2) (3,1) (4,1) (4,0) True 
 
 Furthermore, he claims it's a one line change without using a stack
 or any other extra data structure

The way I see immediately is a three line change (if you include
modifying/removing the existing print statements). It will be one line
shorter to print the other order.

As a hint - think of what the python interpreter's stack looks like when
it's running your code at the moment - that's the stack you're currently
using (and need to use) to store the results you print.

Tim

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


Don't Understand This Error

2009-12-02 Thread Victor Subervi
I get the following error:

 /var/www/html/angrynates.com/cart/chooseOptions.py
8 from login import login
9 import string
   10 import options
   11 from particulars import optionsTables, addStore
   12
options undefined

SyntaxError: invalid syntax (options.py, line 140)
  args = ('invalid syntax', ('/var/www/html/
angrynates.com/cart/options.py', 140, 85,  colorsTables, colorsNames =
colors('products', 'specificTables', specificTables):\n))
  filename = '/var/www/html/angrynates.com/cart/options.py'
  lineno = 140
  msg = 'invalid syntax'
  offset = 85
  print_file_and_line = None
  text =  colorsTables, colorsNames = colors('products',
'specificTables', specificTables):\n

I don't understand the 'text = ... part of the last line. Here's the line
from the code:

colorsTables, colorsNames = colors('products', 'specificTables',
specificTables):

No text. I'm just calling a function and getting the results. Here's the
pared-down function:

def colors(callingTable, which='', specificTables=[]):
  code = []
  names = []
  meanings = []
  code.append({'black': 'FF', 'gray': '465945', 'silver': '708090',
'white': '0F4D92', 'maroon': 'B03060', 'red': 'FE2712', 'purple': '50404D',
'fuchsia': 'FF77FF', 'green': '00A550', 'lime': '32CD32', 'olive': '6B8E23',
'yellow': '9ACD32', 'navy blue': 'CC7722', 'blue': '99', 'teal':
'E2725B', 'aqua': '7FFFD4'})
  meanings.append('These are the standard Web colors.')
  names.append('standardWebColors')
  if which == 'specificTables':
whichTablesToReturn = []
i = 0
while i  len(names): # We utilize the name of the table to determine
where it is in the code tuple
  for table in specificTables:
if names[i] == table:
  whichTablesToReturn.append(i)
  i += 1
returnTheseTables = []
for table in whichTablesToReturn:
  returnTheseTables.append(whichTablesToReturn)
returnTheseNames = []
for table in whichTablesToReturn:
  returnTheseNames.append(whichTablesToReturn)
return returnTheseTables, returnTheseNames
  else:
return optionsDict(which)

Please help me understand what this error is trying to show me.
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't Understand This Error

2009-12-02 Thread Chris Rebert
On Wed, Dec 2, 2009 at 2:33 AM, Victor Subervi victorsube...@gmail.com wrote:
 I get the following error:

  /var/www/html/angrynates.com/cart/chooseOptions.py
     8 from login import login
     9 import string
    10 import options
    11 from particulars import optionsTables, addStore
    12
 options undefined

 SyntaxError: invalid syntax (options.py, line 140)
   args = ('invalid syntax',
 ('/var/www/html/angrynates.com/cart/options.py', 140, 85,  colorsTables,
 colorsNames = colors('products', 'specificTables', specificTables):\n))
   filename = '/var/www/html/angrynates.com/cart/options.py'
   lineno = 140
   msg = 'invalid syntax'
   offset = 85
   print_file_and_line = None
   text =  colorsTables, colorsNames = colors('products',
 'specificTables', specificTables):\n

 I don't understand the 'text = ... part of the last line.

It's the text of the specific line of code that caused the error, I think.

 Here's the line from the code:

     colorsTables, colorsNames = colors('products', 'specificTables',
 specificTables):

The syntax error is that you have an illegal colon at the end of that
line. Remove that colon.

 No text. I'm just calling a function and getting the results. Here's the
 pared-down function:

 def colors(callingTable, which='', specificTables=[]):

The error lies in the caller of colors().

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


Multiprocessing recycle worker if max request reached

2009-12-02 Thread Maris Ruskulis

Hello!
Currently I'm writing little xmlrpc server, because of one c library 
used there is memory leak, which couldn't be fixed. So I decide to use 
multiprocessing, spawn pool of workers and recycle worker if it reaches 
max request count. I managed to set counter for worker, but I could not 
figure out how to recycle worker if counter reaches some value. Is there 
some well known  solution to solve this? Such functionality seems is not 
part of multiprocessing package.

Thank You!
attachment: maris.vcf-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and vc numbers

2009-12-02 Thread Daniel Dalton
 Can you make do with the tempfile module? Or you'd need to identify
 from an external process which console is locked?

Perhaps, I wrote a small hack: 
- Manually set environment variable TTYNUMBER in .bash_profile
- Then use this in the script, to establish what tty I'm working with.

Thanks

-- 
Cheers,
Dan

http://members.iinet.net.au/~ddalton/



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


Delaunay triangulation

2009-12-02 Thread Vincent Davis
Anyone know of a python implementation of Delaunay triangulation?

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xmlrpc idea for getting around the GIL

2009-12-02 Thread alex23
Patrick Stinson patrickstinson.li...@gmail.com wrote:
 Not true. We sell the industry leading sampler engine, and it has been
 paying my salary for three years. It's high performance - every cycle
 counts. Our sampled instruments is loaded as a plugin from third-party
 applications and has been used to make movies you have seen. Our
 customers love it and have never complained about problems with the
 scripting engine.

As an occasional bedroom producer I have to ask if you are talking
about EastWest's Play?

When was Python support added? I'm surprised I missed this at the
time...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bored.

2009-12-02 Thread Necronymouse
Thanks for reaction, I will prohably choose some project as you
said...



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


Re: Can't print Chinese to HTTP

2009-12-02 Thread Gnarlodious
On Nov 30, 5:53 am, Martin v. Löwis wrote:

 #!/usr/bin/python
 print(Content-type:text/plain;charset=utf-8\n\n)
 sys.stdout.buffer.write('晉\n'.encode(utf-8))

Does this work for anyone? Because all I get is a blank page. Nothing.
If I can establish what SHOULD work, maybe I can diagnose this
problem.

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


Re: Don't Understand This Error

2009-12-02 Thread Bruno Desthuilliers

On Wed, Dec 2, 2009 at 2:33 AM, Victor Subervi victorsube...@gmail.com wrote:


def colors(callingTable, which='', specificTables=[]):


Warning : default arguments are eval'd only once, at function creation 
time. This is a well known gotcha that can lead to unexpected behaviours 
like:



def foo(x, bar=[])
   bar.append(gotcha %s % x)
   print bar

for i in range(5):
   bar(i)


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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Wolodja Wentland
On Wed, Dec 02, 2009 at 00:10 -0800, Mark Summerfield wrote:
 On 1 Dec, 18:30, Lie Ryan lie.1...@gmail.com wrote:

  Also, I'm not sure what this change is referring to:
  Python 2                 Python 3
  L = list(seq)            L = sorted(seq)
  L.sort()
 
  L.sort is still available in python, and sorted() have been available
  since python 2. Both list.sort() and sorted() are for different purpose,
  and neither will be deprecated. What's the change here?
 
 The document is about idioms as well as changes. In this case both
 approaches work in both versions, but it seems that there are still a
 lot of people who don't know about sorted(), so I put it in to show it
 as an idiom.

It would be quite nice if you could mark all the Python 3 idioms that
work in Python 2.X as well. This would allow readers that are still using
Python 2.X and are used to the 'old way' to adapt their coding style
accordingly. You could just add a little (2.X) after the idiom for
example.

And thanks for the nice cheat sheet! :-D

-- 
  .''`. Wolodja Wentlandwentl...@cl.uni-heidelberg.de 
 : :'  :
 `. `'` 4096R/CAF14EFC 
   `-   081C B7CD FF04 2BA9 94EA  36B2 8B7F 7D30 CAF1 4EFC


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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Martin P. Hellwig

Mark Summerfield wrote:
cut

It is available as a free PDF download (no registration or anything)
from InformIT's website. Here's the direct link:
http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/python/python2python3.pdf

cut
Very handy! Am I wrong in assuming that you forgot to include that 
file() is gone in favour of open()?


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: Don't Understand This Error

2009-12-02 Thread Victor Subervi
To those who caught the colon at the end of what I thought was going to be
def but turned out to be something else, thank.

On Wed, Dec 2, 2009 at 5:55 AM, Bruno Desthuilliers
bruno.42.desthuilli...@websiteburo.invalid wrote:

 On Wed, Dec 2, 2009 at 2:33 AM, Victor Subervi victorsube...@gmail.com
 wrote:


 def colors(callingTable, which='', specificTables=[]):


 Warning : default arguments are eval'd only once, at function creation
 time. This is a well known gotcha that can lead to unexpected behaviours
 like:


 def foo(x, bar=[])
   bar.append(gotcha %s % x)
   print bar

 for i in range(5):
   bar(i)


Thanks for this instructive example.
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recursion head scratcher

2009-12-02 Thread Joel Madigan
On 12/2/09, Dave Angel da...@ieee.org wrote:
 Joel Madigan wrote:
 Hi everyone!
 Sorry this isn't strictly a Python question but my algorithms professor
 contends that given the standard recursive-backtracking maze solving
 algorithm:

 width=6
 height=4
 maze=[[1,0,1,1,0,1],
   [0,0,1,0,0,0],
   [1,0,1,0,1,0],
   [0,0,0,0,1,1]]
 visited = [[False for x in range(width)] for y in range(height)]

 sx=1
 sy=2
 ex=4
 ey=0

 def findPath(x,y):
 if (x  0 or x = width or y  0 or y = height):
 return False
 elif maze[y][x] == 1:
 return False
 elif visited[y][x]:
 return False
 elif (x == ex and y == ey):
 print (%d,%d)%(x,y),
 return True
 else:
 visited[y][x] = True

 if findPath(x-1,y) or \
findPath(x+1,y) or \
findPath(x,y-1) or \
findPath(x,y+1):
 print (%d,%d)%(x,y),
 return True
 else:
 return False

 print findPath(sx,sy)

 that it is possible to make it print the path to the finish in the order
 the
 steps were taken.  That is, the algorithm as written produces:
 (4,0) (4,1) (3,1) (3,2) (3,3) (2,3) (1,3) (1,2) True

 Rather than
 (1,2) (1,3) (2,3) (3,3) (3,2) (3,1) (4,1) (4,0) True

 Furthermore, he claims it's a one line change without using a stack or
 any
 other extra data structure.  But I can't figure it out to save my life.
  This isn't homework, there isn't credit on the line.  I think he said it
 just to mess with us.  Can anyone point me in the right direction?  It's
 driving me crazy.  The output it gives makes perfect sense, since it just
 prints out each step as the stack unwinds.  Normally you would print the
 output BEFORE recursing, but in this case you only want to print the step
 if
 it is actually part of the path.  And you don't know that until after the
 recursion.

 Can anyone shed some light on this?

 Thanks,
 Joel


 How about swapping sx,sy with ex,ey ?  That's one line (one statement).
 And the rest of the algorithm appears to be symmetric.  Basically,
 you're reversing time, and starting with the end point, descending till
 you find the start point.

 DaveA


Wow... that's devilishy clever.  I can see  that I still have a long
way to travel on my path.  Thanks for your insight.
-- 
http://mail.python.org/mailman/listinfo/python-list


Question about file objects...

2009-12-02 Thread J
Something that came up in class...

when you are pulling data from a file using f.next(), the file is read
one line at a time.

What was explained to us is that Python iterates the file based on a
carriage return as the delimiter.
But what if you have a file that has one line of text, but that one
line has 16,000 items that are comma delimited?

Is there a way to read the file, one item at a time, delimited by
commas WITHOUT having to read all 16,000 items from that one line,
then split them out into a list or dictionary??

Cheers
Jeff

-- 

Ogden Nash  - The trouble with a kitten is that when it grows up,
it's always a cat. -
http://www.brainyquote.com/quotes/authors/o/ogden_nash.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Delaunay triangulation

2009-12-02 Thread David Robinow
On Tue, Dec 1, 2009 at 8:31 PM, Vincent Davis vinc...@vincentdavis.net wrote:
 Anyone know of a python implementation of Delaunay triangulation?

Matplotlib has one.
There's also Delny  @pypi

It's been several years since I needed this. I can't remember the pros/cons.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about file objects...

2009-12-02 Thread nn
On Dec 2, 9:14 am, J dreadpiratej...@gmail.com wrote:
 Something that came up in class...

 when you are pulling data from a file using f.next(), the file is read
 one line at a time.

 What was explained to us is that Python iterates the file based on a
 carriage return as the delimiter.
 But what if you have a file that has one line of text, but that one
 line has 16,000 items that are comma delimited?

 Is there a way to read the file, one item at a time, delimited by
 commas WITHOUT having to read all 16,000 items from that one line,
 then split them out into a list or dictionary??

 Cheers
 Jeff

 --

 Ogden Nash  - The trouble with a kitten is that when it grows up,
 it's always a cat. 
 -http://www.brainyquote.com/quotes/authors/o/ogden_nash.html

File iteration is a convenience since it is the most common case. If
everything is on one line, you will have to handle record separators
manually by using the .read(number_of_bytes) method on the file
object and searching for the comma. If everything fits in memory the
straightforward way would be to read the whole file with .read() and
use .split(,) on the returned string. That should give you a nice
list of everything.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about file objects...

2009-12-02 Thread Andre Engels
On Wed, Dec 2, 2009 at 3:14 PM, J dreadpiratej...@gmail.com wrote:
 Something that came up in class...

 when you are pulling data from a file using f.next(), the file is read
 one line at a time.

 What was explained to us is that Python iterates the file based on a
 carriage return as the delimiter.
 But what if you have a file that has one line of text, but that one
 line has 16,000 items that are comma delimited?

 Is there a way to read the file, one item at a time, delimited by
 commas WITHOUT having to read all 16,000 items from that one line,
 then split them out into a list or dictionary??

If f is a file object, f.read(1) will get the next byte of the file.
Get single-character strings that way until you arrive at a ,, then
concatenate what you have received before that.

-- 
André Engels, andreeng...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


pbs scripts

2009-12-02 Thread aoife
Hi,very new.hoping to incorporate python into my postgrad.

Basically I have 2,000 files.I want to write a script that says:

open each file in turn
for each file:
   open this pbs script and run MUSCLE (a sequence alignment tool)
on each file
   close this file
   move on to next file.

any help would be great.
Aoife
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Delaunay triangulation

2009-12-02 Thread km
check CGAL (cgal.org)
it has python bindings
Krishna

On Wed, Dec 2, 2009 at 11:28 PM, David Robinow drobi...@gmail.com wrote:

 On Tue, Dec 1, 2009 at 8:31 PM, Vincent Davis vinc...@vincentdavis.net
 wrote:
  Anyone know of a python implementation of Delaunay triangulation?

 Matplotlib has one.
 There's also Delny  @pypi

 It's been several years since I needed this. I can't remember the
 pros/cons.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


can python do this?

2009-12-02 Thread Rounak
I am a complete newbie. I want to know if the following can be done 
using python or should I learn some other language:
(Basically, these are applescripts that I wrote while I used Mac OS)
1.Web Page Image to Wallpaper:
A script that takes the current image in a browser and sets it as a
wallpaper. 
http://forums.obdev.at/viewtopic.php?f=24t=3462

2.Screenshot with name, format, Dropbox upload and public URL
I used to run this script,type the name for screenshot and press return.
The screenshot would be uploaded to Dropbox and public url would be
copied to clipboard.
http://forums.obdev.at/viewtopic.php?f=24t=3448

3.Play, pause, set rating to track in iTunes (a music player) with
keyboard shortcuts without activating iTunes. I know there is no iTunes
for Linux but is there a scriptable player. See hundreds of scripts
for iTunes here: http://dougscripts.com/

Thanks.



I am a complete newbie. I want to know if the following can be done 
using python or should I learn some other language:
(Basically, these are applescripts that I wrote while I used Mac OS)
1.Web Page Image to Wallpaper:
A script that takes the current image in a browser and sets it as a
wallpaper. 
http://forums.obdev.at/viewtopic.php?f=24t=3462

2.Screenshot with name, format, Dropbox upload and public URL
I used to run this script,type the name for screenshot and press return.
The screenshot would be uploaded to Dropbox and public url would be
copied to clipboard.
http://forums.obdev.at/viewtopic.php?f=24t=3448

3.Play, pause, set rating to track in iTunes (a music player) with
keyboard shortcuts without activating iTunes. I know there is no iTunes
for Linux but is there a scriptable player. See hundreds of scripts
for iTunes here: http://dougscripts.com/

Thanks.






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


Re: xmlrpc idea for getting around the GIL

2009-12-02 Thread sturlamolden
On 2 Des, 02:47, Patrick Stinson patrickstinson.li...@gmail.com
wrote:

 We don't need extension modules, and all we need to do is run some
 fairly basic scripts that make callbacks and use some sip-wrapped
 types.

Sure, you use SIP but not extension modules...


 - Python is not suitable for real-time work.

 Not true. We have been running python callback code using
 PyObject_CallObject from within our audio thread for some time without
 a problem, and it's *extremely* fast.

It seems you are confusing real-time with real-fast. The fact that
something runs fast does not make it real-time.

Python is not suitable for real-time applications, nor are the OSes
commonly used to run Python.



 We
 need just a ltle push to get our code to work at low latencies,
 and the only thing that is standing in our way is that all threads
 9usually around 20 have to block on the Gil, and this causes small
 gaps in the sound at low latencies (around 5ms, or 64 sample period).

 ...almost perfect.

Python is not programmed with real-time applications in mind: You have
no guarrantees on maximum time-lag when a thread is blocked on the
GIL.

Priority requests (i.e. pre-emptive multitasking) was removed from
Antoine's newgil branch, but that is the kind of mechanism you would
need. Even with priority requests, Python would not be suitable for
real-time apps, as extension modules (e.g. C++ wrapped with SIP) can
hold the GIL forever.

You will also need an OS with a real-time scheduler and a real-time C
library, such as QNX or VxWorks.

I find thea idea of a true real-time Python very interesting, but it
would take a completely reworked interpreter.






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


Re: can python do this?

2009-12-02 Thread Simon Brunning
2009/12/2 Rounak irounakj...@gmail.com:
 I am a complete newbie. I want to know if the following can be done
 using python or should I learn some other language:
 (Basically, these are applescripts that I wrote while I used Mac OS)

Python can do anything Applescript can do with the appscript module -
see http://appscript.sourceforge.net/py-appscript/index.html. And,
naturally, very much more.

I have some driving iTunes examples I'd be happy to send you off-list
if you're interested.

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


Re: can python do this?

2009-12-02 Thread Diez B. Roggisch
Rounak wrote:

 I am a complete newbie. I want to know if the following can be done
 using python or should I learn some other language:
 (Basically, these are applescripts that I wrote while I used Mac OS)
 1.Web Page Image to Wallpaper:
 A script that takes the current image in a browser and sets it as a
 wallpaper.
 http://forums.obdev.at/viewtopic.php?f=24t=3462
 
 2.Screenshot with name, format, Dropbox upload and public URL
 I used to run this script,type the name for screenshot and press return.
 The screenshot would be uploaded to Dropbox and public url would be
 copied to clipboard.
 http://forums.obdev.at/viewtopic.php?f=24t=3448
 
 3.Play, pause, set rating to track in iTunes (a music player) with
 keyboard shortcuts without activating iTunes. I know there is no iTunes
 for Linux but is there a scriptable player. See hundreds of scripts
 for iTunes here: http://dougscripts.com/

As python has an apple-script binding, yes, it's possible, should even be a
rather smooth transition.

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


Re: pbs scripts

2009-12-02 Thread Simon Brunning
2009/12/2 aoife aoife...@hotmail.com:
 Hi,very new.hoping to incorporate python into my postgrad.

 Basically I have 2,000 files.I want to write a script that says:

 open each file in turn

If they are in one directory, look at the glob module. If they are in
a bunch of sub-directories, see os.walk(), or http://bit.ly/5Q5Qiv.

For looping through the files, see http://bit.ly/4zvi9P.

 for each file:
       open this pbs script and run MUSCLE (a sequence alignment tool)
 on each file

Is MUSCLE a command-line tool? If so, see the subprocess module.

       close this file

Do you actually need to open the file, or just run a command on it?
Sounds like the latter to me.

       move on to next file.

Give it a go. Any problems, I'm sure we'd be happy to help.

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


Re: can python do this?

2009-12-02 Thread Rounak

 Python can do anything Applescript can do with the appscript module -
 see http://appscript.sourceforge.net/py-appscript/index.html. And,
 naturally, very much more.

wait, sorry, i forgot to mention. I am now on Linux. I want to know what python 
can do in Linux. On Mac, I am glad to use applescript.


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


Re: can python do this?

2009-12-02 Thread Diez B. Roggisch
Rounak wrote:

 
 Python can do anything Applescript can do with the appscript module -
 see http://appscript.sourceforge.net/py-appscript/index.html. And,
 naturally, very much more.
 
 wait, sorry, i forgot to mention. I am now on Linux. I want to know what
 python can do in Linux. On Mac, I am glad to use applescript.

This question is not so easy to answer. Because such functionality heavily
depends on your actual desktop environment - KDE, Gnome, or something
entirely different. 

However, I'd say that using python you have a good chance of exploiting the
services that are actually available to you.

For example, taking a screenshot:

 
http://stackoverflow.com/questions/69645/take-a-screenshot-via-a-python-script-linux


Uploading that to dropbox is simple python urllib stuff.

And  there seem to be ways to insert things into the clipboard as well:

  http://arminstraub.com/bits-and-bytes/kde-clipboard-on-the-command-line

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


Re: can python do this?

2009-12-02 Thread Rounak

  
 http://stackoverflow.com/questions/69645/take-a-screenshot-via-a-python-script-linux
 
the first solution in this thread requires python imaging library which
I did find here: http://www.pythonware.com/products/pil/faq.htm
But i would like to know if there are easier ways to install this
instead of compiling it from the source.

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


Re: can python do this?

2009-12-02 Thread Grant Edwards
On 2009-12-02, Rounak irounakj...@gmail.com wrote:

 Python can do anything Applescript can do with the appscript module -
 see http://appscript.sourceforge.net/py-appscript/index.html. And,
 naturally, very much more.

 wait, sorry, i forgot to mention. I am now on Linux. I want to
 know what python can do in Linux.

Python can do pretty much anything except kernel modules.

-- 
Grant Edwards   grante Yow! I want you to MEMORIZE
  at   the collected poems of
   visi.comEDNA ST VINCENT MILLAY
   ... BACKWARDS!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can python do this?

2009-12-02 Thread Allan Davis
Try your distribution of linux package management tool.  You will find PIL
there

--
Allan Davis
Member of NetBeans Dream Team
http://wiki.netbeans.org/NetBeansDreamTeam
Lead Developer, nbPython
http://wiki.netbeans.org/Python
http://codesnakes.blogspot.com (my blog)
Co-Chair, CajunJUG
http://www.cajunjug.org


On Wed, Dec 2, 2009 at 9:34 AM, Rounak irounakj...@gmail.com wrote:


 
 
 http://stackoverflow.com/questions/69645/take-a-screenshot-via-a-python-script-linux
 
 the first solution in this thread requires python imaging library which
 I did find here: http://www.pythonware.com/products/pil/faq.htm
 But i would like to know if there are easier ways to install this
 instead of compiling it from the source.

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

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


Re: can python do this?

2009-12-02 Thread Diez B. Roggisch
Rounak wrote:

 
  

http://stackoverflow.com/questions/69645/take-a-screenshot-via-a-python-script-linux
 
 the first solution in this thread requires python imaging library which
 I did find here: http://www.pythonware.com/products/pil/faq.htm
 But i would like to know if there are easier ways to install this
 instead of compiling it from the source.

Did you bother checking your distributions package management?

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


Re: can python do this?

2009-12-02 Thread Bruno Desthuilliers

Rounak a écrit :
 
http://stackoverflow.com/questions/69645/take-a-screenshot-via-a-python-script-linux



the first solution in this thread requires python imaging library which
I did find here: http://www.pythonware.com/products/pil/faq.htm
But i would like to know if there are easier ways to install this
instead of compiling it from the source.



Depends on your linux distro - but PIL is a fairly stable and widely 
used lib, so I fail to imagine any modern distro not having a packaged 
PIL install (rpm, ebuild, whatever).

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


Re: can python do this?

2009-12-02 Thread Rounak
Thanks Allan, I did find PIL in Synaptic Package Manager and installed
it successfully. However, I cannot use it. The reason is:
1. I had installed python3 using sudo apt-get install python3 but python
2 still remains. And it seems Scite (my python editor) is looking for
python 2.

Terminal Output:
$ python -V
Python 2.6.4
$ python3 -V
Python 3.1.1+

Output from Scite:
python -u sshot.py
Traceback (most recent call last):
  File sshot.py, line 1, in module
import ImageGrab
  File /usr/lib/python2.6/dist-packages/PIL/ImageGrab.py, line 34, in
module
import _grabscreen
ImportError: No module named _grabscreen
Exit code: 1

How to make Scite use python3 where it will hopefully find the just
installed PIL.




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


Python without wrapper script

2009-12-02 Thread eric.frederich
Is there a way to set up environment variables in python itself
without having a wrapper script.

The wrapper script is now something like

#!/bin/bash

export LD_LIBRARY_PATH=/some/thing/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/another/thing/lib:$LD_LIBRARY_PATH

export PATH=/some/thing/bin:$PATH
export PATH=/another/thing/bin:$PATH

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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
On Dec 1, 2:03 pm, Mark Summerfield l...@qtrac.plus.com wrote:
 I've produced a 4 page document that provides a very concise summary
 of Python 2-3 differences plus the most commonly used new Python 3
 features. It is aimed at existing Python 2 programmers who want to
 start writing Python 3 programs and want to use Python 3 idioms rather
 than those from Python 2 where the idioms differ.

 It uses Python 3.1 syntax since that looks like being the standard for
 a few years in view of the language moratorium.

 The document is U.S. Letter size but will also print fine on A4
 printers.

 It is available as a free PDF download (no registration or anything)
 from InformIT's website. Here's the direct 
 link:http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/...

 And of course, if you want more on Python 3, there's always the
 documentation---or my book:-)
 Programming in Python 3 (Second Edition) ISBN-10: 0321680561.


I only just found out that I was supposed to give a different URL:
http://www.informit.com/promotions/promotion.aspx?promo=137519
This leads to a web page where you can download the document (just by
clicking the Download Now button), but if you _choose_ you can also
enter your name and email to win some sort of prize.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
On Dec 2, 8:53 am, Mark Dickinson dicki...@gmail.com wrote:
 On Dec 2, 8:01 am, MarkSummerfieldl...@qtrac.plus.com wrote:

  On 1 Dec, 17:50, Mark Dickinson dicki...@gmail.com wrote:
   My only quibble is with the statement on the first page that
   the 'String % operator is deprecated'.  I'm not sure that's
   true, for all values of 'deprecated'.  There don't appear
   to be any definite plans for getting rid of it just yet.

  I didn't make this up:-)

 No, I didn't imagine for a second that you had!

  According tohttp://docs.python.org/dev/3.0/whatsnew/3.0.html
  The plan is to eventually make this the only API for string
  formatting, and to start deprecating the % operator in Python 3.1.

 I think that's a doc bug.  The plan is to ... should read: The plan
 was
 originally to   (Well, at least in the 3.1 version of the
 what's new in 3.0 documentation;  the 3.0 version that you linked to
 isn't even autogenerated any more, AFAIK, so fixes to the ReST source
 for that file never make it to the web site.)

 I'm a little confused myself about what's actually happening with
 % formatting, but here's a fairly recent python-dev posting from
 the BDFL:

 http://mail.python.org/pipermail/python-dev/2009-September/092399.html

Well it seems clear to me that the BDFL wants to kill of % formatting,
but wasn't able to for Python 3... So I still think it is reasonable
(1) to describe it as deprecated and (2) to only teach and use
str.format().
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
On Dec 2, 11:20 am, Wolodja Wentland wentl...@cl.uni-heidelberg.de
wrote:
 On Wed, Dec 02, 2009 at 00:10 -0800, Mark Summerfield wrote:
  On 1 Dec, 18:30, Lie Ryan lie.1...@gmail.com wrote:
   Also, I'm not sure what this change is referring to:
   Python 2                 Python 3
   L = list(seq)            L = sorted(seq)
   L.sort()

   L.sort is still available in python, and sorted() have been available
   since python 2. Both list.sort() and sorted() are for different purpose,
   and neither will be deprecated. What's the change here?

  The document is about idioms as well as changes. In this case both
  approaches work in both versions, but it seems that there are still a
  lot of people who don't know about sorted(), so I put it in to show it
  as an idiom.

 It would be quite nice if you could mark all the Python 3 idioms that
 work in Python 2.X as well. This would allow readers that are still using
 Python 2.X and are used to the 'old way' to adapt their coding style
 accordingly. You could just add a little (2.X) after the idiom for
 example.

Yes it would be nice, but it isn't quite so simple. To take sorted()
as just one example, it was introduced in 2.4 so arguably using it
isn't valid/idiomatic for Python 2.x programs where you care about
backwards compatibility for the Python 2.x series... But my main
reason for not wanting to do this is that the document is aimed at
people who want to write Python 3, not to encourage people to stick
with 2:-)


 And thanks for the nice cheat sheet! :-D

Thanks!

 --
   .''`.     Wolodja Wentland    wentl...@cl.uni-heidelberg.de
  : :'  :    
  `. `'`     4096R/CAF14EFC
    `-       081C B7CD FF04 2BA9 94EA  36B2 8B7F 7D30 CAF1 4EFC

  signature.asc
  1KViewDownload

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


Re: Question about file objects...

2009-12-02 Thread J
On Wed, Dec 2, 2009 at 09:27, nn prueba...@latinmail.com wrote:
 Is there a way to read the file, one item at a time, delimited by
 commas WITHOUT having to read all 16,000 items from that one line,
 then split them out into a list or dictionary??

 File iteration is a convenience since it is the most common case. If
 everything is on one line, you will have to handle record separators
 manually by using the .read(number_of_bytes) method on the file
 object and searching for the comma. If everything fits in memory the
 straightforward way would be to read the whole file with .read() and
 use .split(,) on the returned string. That should give you a nice
 list of everything.

Agreed. The confusion came because the guy teaching said that
iterating the file is delimited by a carriage return character...
which to me sounds like it's an arbitrary thing that can be changed...

I was already thinking that I'd have to read it in small chunks and
search for the delimiter i want...  and reading the whole file into a
string and then splitting that would would be nice, until the file is
so large that it starts taking up significant amounts of memory.

Anyway, thanks both of you for the explanations... I appreciate the help!

Cheers
Jeff



-- 

Charles de Gaulle  - The better I get to know men, the more I find
myself loving dogs. -
http://www.brainyquote.com/quotes/authors/c/charles_de_gaulle.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python without wrapper script

2009-12-02 Thread Ulrich Eckhardt
eric.frederich wrote:
 Is there a way to set up environment variables in python itself
 without having a wrapper script.

Yes, sure, you can set environment variables...

 The wrapper script is now something like
 
 #!/bin/bash
 
 export LD_LIBRARY_PATH=/some/thing/lib:$LD_LIBRARY_PATH
 export LD_LIBRARY_PATH=/another/thing/lib:$LD_LIBRARY_PATH
 
 export PATH=/some/thing/bin:$PATH
 export PATH=/another/thing/bin:$PATH
 
 python ./someScript.py

...but this won't work, I'm afraid.

LD_LIBRARY_PATH is for the program loader / dynamic linker under Linux. This
thing is what is invoked _before_ the program is started, any later
modifications to the environment are ignored.

Similarly PATH, which tells the shell (e.g. bash) where to find executables.
If you need that to e.g. find 'python' itself, you're out of luck.
Otherwise, I believe Python itself doesn't use PATH, so you could set it
inside and any shells started from Python should pick it up.

Uli

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

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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
On Dec 2, 11:31 am, Martin P. Hellwig martin.hell...@dcuktec.org
wrote:
 MarkSummerfieldwrote:

 cut It is available as a free PDF download (no registration or anything)
  from InformIT's website. Here's the direct link:
 http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/...

 cut
 Very handy! Am I wrong in assuming that you forgot to include that
 file() is gone in favour of open()?

No you are not wrong in assuming that I forgot that:-(

My lame excuse is that file() was introduced for isinstance() testing
and similar, and never really as a replacement for open().

Anyway, I have now added:

fh = file(fname, mode) | fh = open(fname, mode)

I've sent a new PDF with this change to InformIT, so hopefully it'll
become available soon from
http://www.informit.com/promotions/promotion.aspx?promo=13751
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
On Dec 2, 4:22 pm, Mark Summerfield l...@qtrac.plus.com wrote:
 On Dec 2, 11:31 am, Martin P. Hellwig martin.hell...@dcuktec.org
 wrote:

  MarkSummerfieldwrote:

  cut It is available as a free PDF download (no registration or anything)
   from InformIT's website. Here's the direct link:
  http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/...

  cut
  Very handy! Am I wrong in assuming that you forgot to include that
  file() is gone in favour of open()?

 No you are not wrong in assuming that I forgot that:-(

 My lame excuse is that file() was introduced for isinstance() testing
 and similar, and never really as a replacement for open().

 Anyway, I have now added:

     fh = file(fname, mode) | fh = open(fname, mode)

 I've sent a new PDF with this change to InformIT, so hopefully it'll
 become available soon 
 fromhttp://www.informit.com/promotions/promotion.aspx?promo=13751

Oops wrong URL again, should have been:
http://www.informit.com/promotions/promotion.aspx?promo=137519
... time to go offline and sleep ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python without wrapper script

2009-12-02 Thread Jean-Michel Pichavant

eric.frederich wrote:

Is there a way to set up environment variables in python itself
without having a wrapper script.

The wrapper script is now something like

#!/bin/bash

export LD_LIBRARY_PATH=/some/thing/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/another/thing/lib:$LD_LIBRARY_PATH

export PATH=/some/thing/bin:$PATH
export PATH=/another/thing/bin:$PATH

python ./someScript.py
  

try in someScript.py

os.environ['PATH'] = /some/thing/bin:+ os.environ['PATH']

example:

import subprocess
import os
p = subprocess.Popen('/bin/echo $TEST', shell=True, stdout=subprocess.PIPE )
p.communicate()[0]
 '\n'

os.environ['TEST'] = 'hello'
p = subprocess.Popen('/bin/echo $TEST', shell=True, stdout=subprocess.PIPE )
p.communicate()[0]
 'hello\n'

JM


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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread John Posner
On Wed, 02 Dec 2009 10:55:23 -0500, Mark Summerfield l...@qtrac.plus.com  
wrote:



On Dec 1, 2:03 pm, Mark Summerfield l...@qtrac.plus.com wrote:

I've produced a 4 page document that provides a very concise summary
of Python 2-3 differences plus the most commonly used new Python 3
features. It is aimed at existing Python 2 programmers who want to
start writing Python 3 programs and want to use Python 3 idioms rather
than those from Python 2 where the idioms differ.


Mark, I add my thanks to those of the other responders. If you find space,  
you might consider adding another str.format() feature:


 Goal: place integer 456 flush-right in a field of width 8

  Py2: %%%dd % 8 % 456
  Py3: {0:{1}d}.format(456, 8)

With str.format(), you don't need to nest one formatting operation within  
another. A little less mind-bending, and every little bit helps!


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


Re: Delaunay triangulation

2009-12-02 Thread sturlamolden
On 2 Des, 15:28, David Robinow drobi...@gmail.com wrote:
 On Tue, Dec 1, 2009 at 8:31 PM, Vincent Davis vinc...@vincentdavis.net 
 wrote:
  Anyone know of a python implementation of Delaunay triangulation?

 Matplotlib has one.
 There's also Delny �...@pypi

 It's been several years since I needed this. I can't remember the pros/cons.

There is also a skikit add-on to NumPy/SciPy.

http://scikits.appspot.com/delaunay
-- 
http://mail.python.org/mailman/listinfo/python-list


Coding Cross Correlation Function in Python

2009-12-02 Thread DarthXander
I have two data sets which I wish to perform the discrete correlation
function on and then plot the results for many values of t to see what
if any time lag exists between the data.
Thus far my code is;

import csv
import pylab
from pylab import *
from numpy import *
from numpy import array

HSBC=csv.reader(open(HSBC data.csv))
Barclays=csv.reader(open(Barclays data.csv))

x=[]
a=[]
y=[]
b=[]
g=[]
h=[]
d=[]

for Date, Close in HSBC:
x.append(Date)
a.append(float(Close))

for Date, Close in Barclays:
y.append(Date)
b.append(float(Close))

for index in range(len(a)):
g.append(a[index]-mean(a))

for index in range(len(b)):
h.append(b[index]-mean(b))

r=std(a)
s=std(b)

So I have all the necessary components for the DCF.

However I'm not faced with the challenge of performing the DCF for t
in the range of potentially 0-700 or so.
Currently I could do it individually for each value of tau ie;

t1=[]
for index in range(len(g)-1):
j=(g[index]*h[index+1])/(r*s)
t1.append(j)

d.append(mean(t1))

However to do this 700 times seems ridiculous. How would I get python
to perform this for me for t in a range of roughly 0-700?

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


Re: can python do this?

2009-12-02 Thread Anssi Saari
Rounak irounakj...@gmail.com writes:

 I am a complete newbie. I want to know if the following can be done 
 using python or should I learn some other language:
 (Basically, these are applescripts that I wrote while I used Mac OS)
 1.Web Page Image to Wallpaper:
 A script that takes the current image in a browser and sets it as a
 wallpaper. 
 http://forums.obdev.at/viewtopic.php?f=24t=3462

I don't know if any Linux web browsers are particularly scriptable. 
Firefox at least is pretty much limited to opening URLs and some other
windows. OTOH, you can do that specific thing by just right clicking
on the image in question and selecting set as desktop background...

 2.Screenshot with name, format, Dropbox upload and public URL
 I used to run this script,type the name for screenshot and press return.
 The screenshot would be uploaded to Dropbox and public url would be
 copied to clipboard.
 http://forums.obdev.at/viewtopic.php?f=24t=3448

I think this should be easily doable with Python, at least the
screenshot and clipboard parts. You can write your own Python code or
use it as glue for utils like xwd, convert, xsel, xclip, xmessage...

No idea if there's any way to talk to Dropbox from Python again since
I know nothing about it.

 3.Play, pause, set rating to track in iTunes (a music player) with
 keyboard shortcuts without activating iTunes. I know there is no iTunes
 for Linux but is there a scriptable player. See hundreds of scripts
 for iTunes here: http://dougscripts.com/

Don't really know again, I've found iTunes handy for managing
podcasts, but that use doesn't need scripting. In Linux, at least
Amarok is scriptable via Javascript. mplayer is generally scriptable
in its slave mode, but it's more a video player than music. mpd is a
music server which even has a Python client to control it (Sonata). 

But really, global hot key mapping is more of a windowing system thing
than a scripting thing. I'm sure you can map your keys to do anything
you want, in whatever environment you use in Linux.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Carsten Haese
John Posner wrote:
  Goal: place integer 456 flush-right in a field of width 8
 
   Py2: %%%dd % 8 % 456
   Py3: {0:{1}d}.format(456, 8)
 
 With str.format(), you don't need to nest one formatting operation
 within another.

With string interpolation, you don't need to do that, either.
 '%*d' % (8,456)
' 456'

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

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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Dickinson
On Dec 2, 4:41 pm, John Posner jjpos...@optimum.net wrote:
   Goal: place integer 456 flush-right in a field of width 8

    Py2: %%%dd % 8 % 456
    Py3: {0:{1}d}.format(456, 8)

 With str.format(), you don't need to nest one formatting operation within  
 another. A little less mind-bending, and every little bit helps!

Or even {:{}d}.format(456, 8), in 3.1 and 2.7 (when it appears).
But you can do this with % formatting, too.  In either 2.x or 3.x:

 %*d % (8, 456)
' 456'

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


Re: Coding Cross Correlation Function in Python

2009-12-02 Thread sturlamolden
On 2 Des, 18:50, DarthXander darthxan...@hotmail.co.uk wrote:

 However to do this 700 times seems ridiculous. How would I get python
 to perform this for me for t in a range of roughly 0-700?

For two 1D ndarrays, the cross-correlation is

from numpy.fft import rfft, irfft
from numpy import fliplr

xcorr = lambda x,y : irfft(rfft(x)*rfft(fliplr(y)))

Normalize as you wish, and preferably pad with zeros before invoking
xcorr.





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


Re: Coding Cross Correlation Function in Python

2009-12-02 Thread DarthXander
On Dec 2, 7:12 pm, sturlamolden sturlamol...@yahoo.no wrote:
 For two 1D ndarrays, the cross-correlation is

 from numpy.fft import rfft, irfft
 from numpy import fliplr

 xcorr = lambda x,y : irfft(rfft(x)*rfft(fliplr(y)))

 Normalize as you wish, and preferably pad with zeros before invoking
 xcorr.

Thanks, though I'd like to do this longer hand than the built in
functions! Great to approximate it though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Noob thread lock question

2009-12-02 Thread Astley Le Jasper
I have a number of threads that write to a database. I have created a
thread lock, but my question is this:

- If one thread hits a lock, do a) all the other threads stop, or b)
just the ones that come to the same lock?
- I presume that the answer is b. In which case do the threads stop
only if they come to the same instance of a lock. For example, you
could have a lock instance for one database and another instance for
another database (first_db_thread_lock = threading.RLock() 
second_db_thread_lock = threading.RLock()).

I appreciate this is a bit of a noob question, but I didn't want to
assume anything.

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


Re: Noob thread lock question

2009-12-02 Thread Diez B. Roggisch

Astley Le Jasper schrieb:

I have a number of threads that write to a database. I have created a
thread lock, but my question is this:

- If one thread hits a lock, do a) all the other threads stop, or b)
just the ones that come to the same lock?


Only the ones coming the the same lock.


- I presume that the answer is b. In which case do the threads stop
only if they come to the same instance of a lock. For example, you
could have a lock instance for one database and another instance for
another database (first_db_thread_lock = threading.RLock() 
second_db_thread_lock = threading.RLock()).



There is nothing like not an instance of a lock. So it's essentially 
the same question as the first, and thus the answer is also: yes, only 
for the *same* lock, which is an instance.


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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread David H Wild
In article
351fcb4c-4e88-41b0-a0aa-b3d63832d...@e23g2000yqd.googlegroups.com,
   Mark Summerfield l...@qtrac.plus.com wrote:
 I only just found out that I was supposed to give a different URL:
 http://www.informit.com/promotions/promotion.aspx?promo=137519
 This leads to a web page where you can download the document (just by
 clicking the Download Now button), but if you _choose_ you can also
 enter your name and email to win some sort of prize.

There is a typographical fault on page 4 of this pdf file. The letter P
is missing from the word Python at the head of the comparison columns.

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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread John Bokma
Mark Summerfield l...@qtrac.plus.com writes:

 On 1 Dec, 23:52, John Bokma j...@castleamber.com wrote:
 Mark Summerfield l...@qtrac.plus.com writes:
  It is available as a free PDF download (no registration or anything)
  from InformIT's website. Here's the direct link:
 http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/...

 Thanks!

  And of course, if you want more on Python 3, there's always the
  documentation---or my book:-)
  Programming in Python 3 (Second Edition) ISBN-10: 0321680561.

 Meh, second edition already? Haven't read the entire first edition
 yet. Which is IMO a good book (I also gave it to my brother as a
 present).

 If it is any consolation, the second edition should have a much longer
 life, now that we have the language moratorium. (I _really_ wanted to
 cover 3.1.)

Nah, I wasn't really complaining. Moreover, I am glad I didn't finish
the first edition, so I have less of a problem starting in the 2nd
edition from the beginning. From what I've read in the 1st edition it's
an excellent book.

 Only negative point (to me) so far is that in the beginning (p8-9) the
 book mentions placing Python programs in C:\py3eg which gives me the
 unpleasant feeling that someone is coding on Windows XP with
 Administrator rights...

 OK, you got me there,

I knew it ;-) Should've emailed you months ago and maybe it would have
changed in the 2nd edition :-(

 I only use Windows for testing purposes and my
 personal logon account does have Administrator rights, which I assumed
 was standard for personal machines?

I use XP Professional and the first thing I do after installation is
creating a limited user account for my day to day work. As far as I know
this can also be done in XP Home, but I've no experience with home.

 Also, the path is short. It is
 only a suggestion, it really doesn't matter where you unpack the
 examples.

My issue with it is that it somewhat promotes working with Administrator
rights, which is as dangerous as working with root rights on other OSes
if the machine is not connected to the Internet. If it's connected to
the Internet it's way more dangerous, sadly.

Anyway, thanks for writing IMO a very good book, and I *am* happy with a
second edition.

-- 
John Bokma

Read my blog: http://johnbokma.com/
Hire me (Perl/Python): http://castleamber.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set object parameters nicely?

2009-12-02 Thread allen.fowler
  Is there a better way to do this?
  class MyOb(object):
       def __init__(self, **kwargs):
           self.__dict__.update(kwargs)

  ob1 = MyOb(p1=Tom, p3=New York)
  ob2 = MyOb(p1=Joe, p2=j...@host, p3=New Jersey)

  I've tried this, but have found two issues:

  1) I can't set default values.
  2) I can't set required values.

  In both of the above cases, if theobjectis created without the
  exact dict() I expect, all the assumption my methods make about what
  is available in self fall apart.

  Perhaps, as Diez mentioned, my approach is wrong.   What would be the
  right thing to do in this situation?

 There is no general answer to this. It depends on your actual problem.

 Diez

What are some of the patterns that tend to be used?

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


Insane Problem

2009-12-02 Thread Victor Subervi
Hi;
I have spent 2-3 hours trying to track this bug. Here's the code snippet:

  form = cgi.FieldStorage()
  fn = getattr(options, 'products')
  ourOptionsNames = []
  optionsNames, doNotUse  = fn('names')
  for name in optionsNames:
test = table + '-' + name
print test
check = form.getfirst(test, '')
print check
if check != '':
  ourOptionsNames.append(name)

Now, when it looks through with test=='products', it doesn't report that any
of the values from the form are checked. However, when I explicitly write
out something like:
print form.getfirst('products-sizes', '')
which I checked on the form from the referring page, it does in fact print
out! My test prints show that 'products-sizes' is being passed to check
and should therefore be appended to ourOptionsNames. But it isn't! What am
I missing here??
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Mark Summerfield
On 2 Dec, 19:28, David H Wild dhw...@talktalk.net wrote:
 In article
 351fcb4c-4e88-41b0-a0aa-b3d63832d...@e23g2000yqd.googlegroups.com,
    Mark Summerfield l...@qtrac.plus.com wrote:

  I only just found out that I was supposed to give a different URL:
 http://www.informit.com/promotions/promotion.aspx?promo=137519
  This leads to a web page where you can download the document (just by
  clicking the Download Now button), but if you _choose_ you can also
  enter your name and email to win some sort of prize.

 There is a typographical fault on page 4 of this pdf file. The letter P
 is missing from the word Python at the head of the comparison columns.

I can't see that problem---I've tried the PDF with evince, gv,
acroread, and okular, and no missing P on page 4. I don't have a
machine with RISC OS on it so I can't test on that environment!

 --
 David Wild using RISC OS on broadbandwww.davidhwild.me.uk

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


ANN: Twisted 9.0.0

2009-12-02 Thread Christopher Armstrong
= Twisted 9.0.0 =

I'm happy to announce Twisted 9, the first (and last) release of
Twisted in 2009. The previous release was Twisted 8.2 in December of
2008. Given that, a lot has changed!

This release supports Python 2.3 through Python 2.6, though it is the
last one that will support Python 2.3. The next release will support
only Python 2.4 and above. Twisted: the framework of the future!

You can download the new release at our web site,

http://twistedmatrix.com/

There were around 285 tickets resolved in this release. The full list
of changes is available here:


http://twistedmatrix.com/trac/browser/tags/releases/twisted-9.0.0/NEWS?format=raw

It's quite a huge list of changes spanning almost all of the Twisted
projects, so here are some of the more exciting changes:

In the core:
- The Windows IOCP reactor now supports SSL.
- The memcache protocol implementation got some nice new features.

In Twisted Web:
- There's a new HTTP client API and protocol implementation, starting
at twisted.web.client.Agent. It's still pretty low-level, but much
more flexible than the old API.
- There were many improvements to the WSGI support.

In Twisted Conch:
- PyASN1 is now used to parse SSH keys (which means you now need to
install it to use Conch).
- SFTP servers (especially on Windows) now behave a lot better.

In Twisted Mail:
- The IMAP server and client protocol implementations had many fixes.
For example, SASL PLAIN credentials now work.

In Twisted Words:
- XMPP clients now support the ANONYMOUS SASL authentication type.
- The IRC protocol implementations had many fixes.

And a lot more.


= What is Twisted? =

From the web site:

Twisted is an event-driven networking engine written in Python and
licensed under the MIT license.

See the FAQ for commonly asked questions about Twisted.

http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions

If you want to get started with Twisted, the first thing you should do
is read the Twisted Core Documentation.

http://twistedmatrix.com/projects/core/documentation/howto/index.html

Twisted projects variously support TCP, UDP, SSL/TLS, multicast, Unix
sockets, a large number of protocols (including HTTP, NNTP, IMAP, SSH,
IRC, FTP, and others), and much more.

Enjoy!

-- 
Christopher Armstrong
http://radix.twistedmatrix.com/
http://planet-if.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python without wrapper script

2009-12-02 Thread Hans Mulder

Ulrich Eckhardt wrote:

eric.frederich wrote:

Is there a way to set up environment variables in python itself
without having a wrapper script.


Yes, sure, you can set environment variables...


The wrapper script is now something like

#!/bin/bash

export LD_LIBRARY_PATH=/some/thing/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/another/thing/lib:$LD_LIBRARY_PATH

export PATH=/some/thing/bin:$PATH
export PATH=/another/thing/bin:$PATH

python ./someScript.py


...but this won't work, I'm afraid.

LD_LIBRARY_PATH is for the program loader / dynamic linker under Linux. This
thing is what is invoked _before_ the program is started, any later
modifications to the environment are ignored.


In cases like yours I have sometimes written Python scripts that acted as
their own wrapper:

#!/usr/bin/env python

import os, sys

if 'LD_LIBRARY_PATH' in os.environ:
lib_path = os.environ['LD_LIBRARY_PATH']
if '/some/thing/lib' in lib_path and '/another/thing/lib' in lib_path:
pass
else:
os.environ['LD_LIBRARY_PATH'] += ':/some/thing/lib:/another/thing/lib'
os.execve(sys.argv[0], sys.argv, os.environ)
else:
os.environ['LD_LIBRARY_PATH'] = '/some/thing/lib:/another/thing/lib'
os.execve(sys.argv[0], sys.argv, os.environ)

os.environ['PATH'] = '/some/thing/bin:/another/thing/bin:' + os.environ['PATH']

# At this point, you can import a module that depends
# on LD_LIBRARY_PATH including /some/thing/lib
#
# Alternatively (and more clearly), you can replace the 'pass' above
# by that import statement


This code restarts Python if it has to modify os.environ['LD_LIBRARY_PATH'].

If you try to single-step this code under pdb, you'll get as far as the
os.execve() call.  That call starts Python afresh, without a debugger.
In other words, if you need to use pdb, you'll have to set the environment
variables in the shell.


Similarly PATH, which tells the shell (e.g. bash) where to find executables.
If you need that to e.g. find 'python' itself, you're out of luck.
Otherwise, I believe Python itself doesn't use PATH, so you could set it
inside and any shells started from Python should pick it up.


You don't have to restart Python if you modify to os.environ['PATH'],
so that bit is easy.



Hope this helps,

-- HansM


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


Re: Noob thread lock question

2009-12-02 Thread John Nagle

Diez B. Roggisch wrote:

Astley Le Jasper schrieb:

I have a number of threads that write to a database. I have created a
thread lock, but my question is this:

- If one thread hits a lock, do a) all the other threads stop, or b)
just the ones that come to the same lock?


Only the ones coming the the same lock.


- I presume that the answer is b. In which case do the threads stop
only if they come to the same instance of a lock. For example, you
could have a lock instance for one database and another instance for
another database (first_db_thread_lock = threading.RLock() 
second_db_thread_lock = threading.RLock()).



There is nothing like not an instance of a lock. So it's essentially 
the same question as the first, and thus the answer is also: yes, only 
for the *same* lock, which is an instance.


Diez


   Note that if you're using MySQLdb, there are some restrictions on threading.
Only one thread at a time can use each connection to the database.  But you
can create multiple connections to the same database at the same time from
a single program, and run them concurrently.

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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread MRAB

Mark Summerfield wrote:

On 2 Dec, 19:28, David H Wild dhw...@talktalk.net wrote:

In article
351fcb4c-4e88-41b0-a0aa-b3d63832d...@e23g2000yqd.googlegroups.com,
   Mark Summerfield l...@qtrac.plus.com wrote:


I only just found out that I was supposed to give a different URL:
http://www.informit.com/promotions/promotion.aspx?promo=137519
This leads to a web page where you can download the document (just by
clicking the Download Now button), but if you _choose_ you can also
enter your name and email to win some sort of prize.

There is a typographical fault on page 4 of this pdf file. The letter P
is missing from the word Python at the head of the comparison columns.



Which is page 4? The page numbers are missing! (But the column titles
look OK.) :-)


I can't see that problem---I've tried the PDF with evince, gv,
acroread, and okular, and no missing P on page 4. I don't have a
machine with RISC OS on it so I can't test on that environment!


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


Re: Insane Problem

2009-12-02 Thread MRAB

Victor Subervi wrote:

Hi;
I have spent 2-3 hours trying to track this bug. Here's the code snippet:

  form = cgi.FieldStorage()
  fn = getattr(options, 'products')
  ourOptionsNames = []
  optionsNames, doNotUse  = fn('names')
  for name in optionsNames:
test = table + '-' + name
print test
check = form.getfirst(test, '')
print check
if check != '':
  ourOptionsNames.append(name)
 
Now, when it looks through with test=='products', it doesn't report that 
any of the values from the form are checked. However, when I explicitly 
write out something like:

print form.getfirst('products-sizes', '')
which I checked on the form from the referring page, it does in fact 
print out! My test prints show that 'products-sizes' is being passed to 
check and should therefore be appended to ourOptionsNames. But it 
isn't! What am I missing here??



What do the print statements actually print? Please copy and paste their
output.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread John Posner
On Wed, 02 Dec 2009 13:34:11 -0500, Carsten Haese  
carsten.ha...@gmail.com wrote:




With string interpolation, you don't need to do that, either.

'%*d' % (8,456)

' 456'



Thanks, Carsten and Mark D. -- I'd forgotten about the use of * in  
minimum-field-width specs and precision specs (doh). How about this:


  pi={1:.{0}f} e={2:.{0}f}.format(5, math.pi, math.e)

  (result: 'pi=3.14159 e=2.71828')

Can the Python2 %-formating facility handle this without repeating the 5  
argument?


Even if it can, I stand by my original suggestion: include an example to  
show that the arguments to str.format() can be used on both the left and  
the right of a : in a replacement field.


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


Cron Job Output

2009-12-02 Thread baytes
I have cron checking services every 5-10 minutes, and if a service
goes up or down it writes to a file, Im trying to write a script that
will check that file for updates and print the results. this will tie
into a module for phenny where the bot will be able to print the
contents of the updated file to the channel.

Im extremely new to python and any point in the right direction or
tutorials on the subject would be greatly appreicated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python bijection

2009-12-02 Thread Joshua Bronson
On Dec 1, 8:17 pm, a...@pythoncraft.com (Aahz) wrote:
 In article 
 85100df7-a8b0-47e9-a854-ba8a8a2f3...@r31g2000vbi.googlegroups.com,
 Joshua Bronson  jabron...@gmail.com wrote:
 I noticed the phonebook example in your ActiveState recipe and thought
 you might consider changing it to something like husbands to wives,
 since the names-to-phone-numbers relation is many-to-many.

 What makes you think husbands to wives is one-to-one?  ;-)  (Even
 assuming monogamy, you have husbands-to-husbands and wives-to-wives.)

Hah! I knew this was coming and even put assuming monogamy in the
source!
http://bitbucket.org/jab/bidict/src/712da6e2dd26/bidict.py#cl-65  ;P

As for husbands-to-husbands and wives-to-wives, those are just
separate one-to-one mappings! Doesn't mean husbands-to-wives ain't one-
to-one!

At any rate, apologies to the community for my heteronormative
example. It was merely pedagogical and reflects nothing about my
personal views! If you have any further concerns, please send them to
my lawyer, /dev/null.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set object parameters nicely?

2009-12-02 Thread Carl Banks
On Dec 2, 12:13 pm, allen.fowler allen.fow...@yahoo.com wrote:
   Is there a better way to do this?
   class MyOb(object):
        def __init__(self, **kwargs):
            self.__dict__.update(kwargs)

   ob1 = MyOb(p1=Tom, p3=New York)
   ob2 = MyOb(p1=Joe, p2=j...@host, p3=New Jersey)

   I've tried this, but have found two issues:

   1) I can't set default values.
   2) I can't set required values.

   In both of the above cases, if theobjectis created without the
   exact dict() I expect, all the assumption my methods make about what
   is available in self fall apart.

   Perhaps, as Diez mentioned, my approach is wrong.   What would be the
   right thing to do in this situation?

  There is no general answer to this. It depends on your actual problem.

 What are some of the patterns that tend to be used?

For the record, I don't really agree that a lot of parameters is code
smell.  It's maybe a red flag that you are doing too much in one
function and/or class, but nothing inherently shady.

One thing to ask yourself: are there a lot of combinations of
parameters that don't make sense?  For example, do you have a lot of
cases where, say, if one parameter is set to x, then parameters a, b,
c, and d do nothing?  That would indicate that you should break your
function/class up into smaller, more targeted parts.

However, if all your parameters are orthogonal, that is, if all or
most combinations make sense, then there's no reason ten or twenty
parameters isn't perfectly reasonable.

Whenever I have ten parameters in an __init__, I ususally just write
out the assignments, although more often than not the object's
attributes don't correspond to the parameters one-to-one, so I'd have
to write them out anyway.


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


Re: python bijection

2009-12-02 Thread Joshua Bronson
On Dec 1, 9:03 pm, Chris Rebert c...@rebertia.com wrote:
 Reminds me of this quite funny blog post:
 Gay marriage: the database engineering perspective
 http://qntm.org/?gay

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


Re: Question about file objects...

2009-12-02 Thread Terry Reedy

J wrote:

On Wed, Dec 2, 2009 at 09:27, nn prueba...@latinmail.com wrote:

Is there a way to read the file, one item at a time, delimited by
commas WITHOUT having to read all 16,000 items from that one line,
then split them out into a list or dictionary??



File iteration is a convenience since it is the most common case. If
everything is on one line, you will have to handle record separators
manually by using the .read(number_of_bytes) method on the file
object and searching for the comma. If everything fits in memory the
straightforward way would be to read the whole file with .read() and
use .split(,) on the returned string. That should give you a nice
list of everything.


Agreed. The confusion came because the guy teaching said that
iterating the file is delimited by a carriage return character...


If he said exactly that, he is not exactly correct. File iteration looks 
for line ending character(s), which depends on the system or universal 
newline setting.



which to me sounds like it's an arbitrary thing that can be changed...

I was already thinking that I'd have to read it in small chunks and
search for the delimiter i want...  and reading the whole file into a
string and then splitting that would would be nice, until the file is
so large that it starts taking up significant amounts of memory.

Anyway, thanks both of you for the explanations... I appreciate the help!


I would not be surprised if a generic file chunk generator were posted 
somewhere. It would be a good entry for the Python Cookbook, if not 
there already.


tjr

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


Re: Cron Job Output

2009-12-02 Thread LoD MoD
You might try something like this http://code.activestate.com/recipes/157035/


On Wed, Dec 2, 2009 at 3:05 PM, baytes brad.ay...@gmail.com wrote:
 I have cron checking services every 5-10 minutes, and if a service
 goes up or down it writes to a file, Im trying to write a script that
 will check that file for updates and print the results. this will tie
 into a module for phenny where the bot will be able to print the
 contents of the updated file to the channel.

 Im extremely new to python and any point in the right direction or
 tutorials on the subject would be greatly appreicated.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Terry Reedy

Mark Summerfield wrote:


Well it seems clear to me that the BDFL wants to kill of % formatting,
but wasn't able to for Python 3...


Definitely. I thought of adding autonumbering of fields (in 3.1) in 
response to his inquiry about the barriers to moving to .format. That 
solved 'simplicity of defaults'. The other, 'Autoconversion of installed 
base' still awaits.



So I still think it is reasonable
(1) to describe it as deprecated and (2) to only teach and use
str.format().


At the moment (3.1) there are, unfortunately, library packages that 
require % for formatting (logging, I believe, for one). There has been 
discussion on adding a new option for 3.2, but I do not know what will 
happen. Depends on whether you want to be absolutely complete. I 
strictly use .format when I can, which so far is always.


Terry Jan Reedy

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


Re: ANN: Twisted 9.0.0

2009-12-02 Thread Terry Reedy

Christopher Armstrong wrote:

= Twisted 9.0.0 =

I'm happy to announce Twisted 9, the first (and last) release of
Twisted in 2009. The previous release was Twisted 8.2 in December of
2008. Given that, a lot has changed!

This release supports Python 2.3 through Python 2.6, though it is the
last one that will support Python 2.3. The next release will support
only Python 2.4 and above. Twisted: the framework of the future!


Not unless it supports 3.1+. Is that in the cards (tickets)?

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


Re: python bijection

2009-12-02 Thread Aahz
In article 9a6902a1-327e-435e-8c9a-b69028994...@u20g2000vbq.googlegroups.com,
Joshua Bronson  jabron...@gmail.com wrote:

At any rate, apologies to the community for my heteronormative
example. It was merely pedagogical and reflects nothing about my
personal views! If you have any further concerns, please send them to
my lawyer, /dev/null.

Apology accepted.  ;-)
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set object parameters nicely?

2009-12-02 Thread allen.fowler
On Dec 2, 6:36 pm, Carl Banks pavlovevide...@gmail.com wrote:

 For the record, I don't really agree that a lot of parameters is code
 smell.  It's maybe a red flag that you are doing too much in one
 function and/or class, but nothing inherently shady.

 One thing to ask yourself: are there a lot of combinations of
 parameters that don't make sense?  For example, do you have a lot of
 cases where, say, if one parameter is set to x, then parameters a, b,
 c, and d do nothing?  That would indicate that you should break your
 function/class up into smaller, more targeted parts.

 However, if all your parameters are orthogonal, that is, if all or
 most combinations make sense, then there's no reason ten or twenty
 parameters isn't perfectly reasonable.

 Whenever I have ten parameters in an __init__, I ususally just write
 out the assignments, although more often than not the object's
 attributes don't correspond to the parameters one-to-one, so I'd have
 to write them out anyway.


Thank you for the thoughtful insight.

In this case, and I am trying to create a number of ORM-like objects.
(Though, there is no database involved.)

So, instances of these classes are acting as records that are shuttled
around in the system, and the object's properties are acting as
values.  The parameters are (mostly) orthogonal, but do need defaults,
and some must be required.


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


Re: Moving from Python 2 to Python 3: A 4 page cheat sheet

2009-12-02 Thread Antoine Pitrou

Le Tue, 01 Dec 2009 06:03:36 -0800, Mark Summerfield a écrit :
 I've produced a 4 page document that provides a very concise summary of
 Python 2-3 differences plus the most commonly used new Python 3
 features. It is aimed at existing Python 2 programmers who want to start
 writing Python 3 programs and want to use Python 3 idioms rather than
 those from Python 2 where the idioms differ.
[...]
 
 It is available as a free PDF download (no registration or anything)
 from InformIT's website. Here's the direct link:

This is great!

Just one thing:

« Copyright © Qtrac Ltd. 2009. All rights reserved »

Might I suggest that you release it under a free license instead?
(such as the CC by, CC by-sa, or the Free Art License)

Regards

Antoine.

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


How to implement Varient/Tagged Unions/Pattern Matching in Python?

2009-12-02 Thread metal
I want to get pattern matching like OCaml in python(ref:http://
en.wikipedia.org/wiki/Tagged_union)

I consider the syntax:

def decl():
def Plus(expr, expr): pass
def Minus(expr, expr): pass
def Times(expr, expr): pass
def Divide(expr, expr): pass
def Value(str): pass
@enum
def expr(Plus, Minus, Times, Divide, Value): pass
declare_types(locals())

def f(e):
def _Plus(l, r):
return '(%s+%s)' % (l, r)
def _Minus(l, r):
return '(%s-%s)' % (l, r)
def _Times(l, r):
return '(%s*%s)' % (l, r)
def _Divide(l, r):
return '(%s/%s)' % (l, r)
def _Value(x):
return x
try:
match(e, locals()) # visitor pattern
except NoMatchedError:
pass

 print f(Times(Value(n), Plus(Value(x, Value(y
(n*(x+y))


But it's hard to do with nested matching. Any suggestions would be
appreciated


BTW, Please don't ask Why do you want to do like this
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Twisted 9.0.0

2009-12-02 Thread exarkun

On 12:18 am, tjre...@udel.edu wrote:

Christopher Armstrong wrote:

= Twisted 9.0.0 =

I'm happy to announce Twisted 9, the first (and last) release of
Twisted in 2009. The previous release was Twisted 8.2 in December of
2008. Given that, a lot has changed!

This release supports Python 2.3 through Python 2.6, though it is the
last one that will support Python 2.3. The next release will support
only Python 2.4 and above. Twisted: the framework of the future!


Not unless it supports 3.1+. Is that in the cards (tickets)?


Somewhat.

A description of the plan on stackoverflow: http://bit.ly/6hWqYU

A message with some ticket links from a thread on the twisted-python 
mailing list: http://bit.ly/8csFSa


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


prolog with python

2009-12-02 Thread William Heath
Hi All,

I have the following prolog program that I would really like to be able to
run in python in some elegant way:

q00(X01, R):-  write('Are you over 80?'), read(INPUT), write(''), q11(INPUT,
R).
q11(X11, R):-  X11=y, write(' You are passed the hardest year'), !.
q00(X01, R):-  write('You are not over 80'),

Most of the implementations I have seen use assert's and don't appear to
handle backtracking or negation.  I somehow need to provide input to the
rules as well as you can see above.  Anyone know how to do this well using a
python library?  I would love a 100% python solution if I could find one.
Anyway, thanks!

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


Re: prolog with python

2009-12-02 Thread Chris Rebert
On Wed, Dec 2, 2009 at 6:47 PM, William Heath wghe...@gmail.com wrote:
 Hi All,

 I have the following prolog program that I would really like to be able to
 run in python in some elegant way:

From googling:

http://pyke.sourceforge.net/
http://code.activestate.com/recipes/303057/

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


Re: [Twisted-Python] ANN: Twisted 9.0.0

2009-12-02 Thread Tim Allen
exar...@twistedmatrix.com wrote:
 A message with some ticket links from a thread on the twisted-python 
 mailing list: http://bit.ly/8csFSa

Some of those tickets seem out of date; a better plan would be to query
for tickets with the py3k keyword:

http://twistedmatrix.com/trac/search?q=py3knoquickjump=1ticket=on

I believe #2484 is the master ticket:

http://twistedmatrix.com/trac/ticket/2484


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


Re: Question on Python as career

2009-12-02 Thread Roy Smith
joy99 subhakolkata1...@gmail.com wrote:

 Dear Group,
 
 I am a researcher in India's one of the premier institutes.(Indian
 Institute of Science,Bangalore).
 [...]
 I have developed them either in Python2.5 and Python2.6.
 
 After I complete my Post Doctoral which may be only 2-3 months away,
 with this knowledge can I join IT?
 Or Do I have to learn anything new?

The short answer is, you will always need to keep learning new things.  
Whatever set of technologies are popular today (check out 
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html, for 
example), will change over time.

When I started out, I knew C and Fortran.  I'm amazed that C is still the 
#2 language, and Fortran isn't even on the TIOBE top 20 list any more.  17 
of the 20 didn't even exist when I started out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Beginner Q. interrogate html object OR file search?

2009-12-02 Thread Mark G
Hi all,

I am new to python and don't yet know the libraries well. What would
be the best way to approach this problem: I have a html file parsing
script - the file sits on my harddrive. I want to extract the date
modified from the meta-data. Should I read through lines of the file
doing a string.find to look for the character patterns of the meta-
tag, or should I use a DOM type library to retrieve the html element I
want? Which is best practice? which occupies least code?

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


Re: Help in wxpython

2009-12-02 Thread Krishnakant
On Wed, 2009-12-02 at 00:20 -0800, madhura vadvalkar wrote:
 Hi
 
 I am trying to write an  PAINT like application where on the mouse
 click a circle is drawn on canvas. I am new to python and using
 wxpython to create this.
 
 here is the code:
 
 import wx
 
 class SketchWindow(wx.Window):
 
 def __init__ (self, parent,ID):
 
 wx.Window.__init__(self, parent, ID)
 
 self.panel =wx.Panel(self, size= (350,350))
 self.pen=wx.Pen( 'blue',4)
 self.pos=(0,0)
 self.InitBuffer()
 self.Bind(wx.EVT_LEFT_DOWN,self.OnLeftDown)
 
 def InitBuffer(self):
 
 size=self.GetClientSize()
 self.Buffer=wx.EmptyBitmap(size.width,size.height)
 dc=wx.BufferedDC(None,self.buffer)
 dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
 dc.Clear()
 self.Drawcircle(dc)
 self.reInitBuffer=False
 
 def OnLeftDown(self,event):
 self.pos=event.GetPositionTuple()
 self.CaptureMouse()
 
 def Drawcircle(self,dc):
 pen=wx.Pen(colour,thickness,wx.SOLID)
 dc.SetPen(pen)
 dc.DrawCircle(self.pos.x,self.pos.y,r)
 
 class SketchFrame(wx.Frame):
 def __init__(self, parent):
 
 wx.Frame.__init__(self, parent, -1, Sketch Frame,size=(800,600))
 self.sketch = SketchWindow(self, -1)
 
 if __name__=='__main__':
 app=wx.PySimpleApp()
 frame=SketchFrame(None)
 frame.Show(True)
 app.MainLoop()
 
 I am getting the following error:
 
 Traceback (most recent call last):
   File C:/Python26/circle.py, line 42, in module
 frame=SketchFrame(None)
   File C:/Python26/circle.py, line 38, in __init__
 self.sketch = SketchWindow(self, -1)
   File C:/Python26/circle.py, line 12, in __init__
 self.InitBuffer()
   File C:/Python26/circle.py, line 19, in InitBuffer
 dc=wx.BufferedDC(None,self.buffer)
 AttributeError: 'SketchWindow' object has no attribute 'buffer'
 
 Please tell me what I am doing wrong.
 
 Thanks
Madhura, Sorry to be a bit off-topic, but, I would really recommend you
to use pygtk instead of wx.
For one thing, the developers at pygtk are very active (they have their
mailing list as well ) and it comes by default with python on almost all
linux distros.  You can also easily install it on windows.

Most important, the api for pygtk is closely similar to wx.
Not to mention the quick responses you will get with pygtk related
problems.

Happy hacking.
Krishnakant.

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


Re: Delaunay triangulation

2009-12-02 Thread Vincent Davis
Thanks for all the replies I will look at each.

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis


On Wed, Dec 2, 2009 at 10:20 AM, sturlamolden sturlamol...@yahoo.no wrote:

 On 2 Des, 15:28, David Robinow drobi...@gmail.com wrote:
  On Tue, Dec 1, 2009 at 8:31 PM, Vincent Davis vinc...@vincentdavis.net
 wrote:
   Anyone know of a python implementation of Delaunay triangulation?
 
  Matplotlib has one.
  There's also Delny  @pypi
 
  It's been several years since I needed this. I can't remember the
 pros/cons.

 There is also a skikit add-on to NumPy/SciPy.

 http://scikits.appspot.com/delaunay
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Declaring a class level nested class?

2009-12-02 Thread cmckenzie
Hi.

I'm new to Python, but I've managed to make some nice progress up to
this point. After some code refactoring, I ran into a class design
problem and I was wondering what the experts thought. It goes
something like this:

class module:
   nestedClass

   def __init__():
  self.nestedClass = nested()
  print self.nestedClass.nestedVar

   class nested():
  nestedVar = 1
  def __init__(self):
 print Initialized...

I can't figure out what the correct way to construct the nested
class so it can belong to module.

I want a class level construct of nested to belong to module, but
I keep getting nestedClass isn't defined.

My example isn't great or 100% accurate, but I hope you get the idea.

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


Re: Declaring a class level nested class?

2009-12-02 Thread Chris Rebert
On Wed, Dec 2, 2009 at 8:55 PM, cmckenzie mckenzi...@gmail.com wrote:
 Hi.

 I'm new to Python, but I've managed to make some nice progress up to
 this point. After some code refactoring, I ran into a class design
 problem and I was wondering what the experts thought. It goes
 something like this:

 class module:
   nestedClass

   def __init__():
      self.nestedClass = nested()
      print self.nestedClass.nestedVar

   class nested():
      nestedVar = 1
      def __init__(self):
         print Initialized...

 I can't figure out what the correct way to construct the nested
 class so it can belong to module.

 I want a class level construct of nested to belong to module, but
 I keep getting nestedClass isn't defined.

Here's the scoping reason why it fails (remember that the nested class
is a class variable of the containing class):

BEGIN PENDING FAQ SUBMISSION

Why do I get errors when accessing class variables (a.k.a. static variables)?
-
If you try something like the following::

class Foo(object):
class_variable = 42

def method(self, x):
return x + class_variable


Foo().method(7)

You'll get an error about Python being unable to find the class variable::

Traceback (most recent call last):
 ...
NameError: global name 'class_variable' is not defined

This is because class-level scope is not consulted when looking up
plain names in methods.  When looking up a name, the following scopes
are consulted, in order: Local variables, Variables in nested
functions, Global variables, and finally, Built-ins.

To refer to class variables, you must be more explicit. There are several
ways to go about it:

* Refer to the class by name::

def method1(self, x):
return x + Foo.class_variable

* Refer to the class of the object dynamically. If you class is
subclassed, this will allow the subclasses to override the value of
the class variable. ::

def method2(self, x):
return x + self.__class__.class_variable

* Exploit the fact that attribute lookups on an object fall back to
its class. Be warned that if you have both instance and class variables
with the same name, the instance variable will shadow
the class variable. ::

def method3(self, x):
return x + self.class_variable

* If your method is not truly an instance method
(i.e. does not utilize ``self``), make it a class method ::

@classmethod
def method4(cls, x):
return x + cls.class_variable

END FAQ EXCERPT

However, there's pretty much no reason to nest classes anyway in
Python (it's not Java!). Just make them both top-level in the file. If
one class is only used internally in the module, just use the normal
private naming convention of starting its name with an underscore.

Also note that class names should generally use StudlyCaps, and that
naming a class module is rather confusing.

Cheers,
Chris
--
If the Python.org webmasters are listening, add the FAQ entry already!
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Declaring a class level nested class?

2009-12-02 Thread inhahe
it seems to me like it should work just fine if you just take out the
second line where it just says nestedClass

On Wed, Dec 2, 2009 at 11:55 PM, cmckenzie mckenzi...@gmail.com wrote:
 Hi.

 I'm new to Python, but I've managed to make some nice progress up to
 this point. After some code refactoring, I ran into a class design
 problem and I was wondering what the experts thought. It goes
 something like this:

 class module:
   nestedClass

   def __init__():
      self.nestedClass = nested()
      print self.nestedClass.nestedVar

   class nested():
      nestedVar = 1
      def __init__(self):
         print Initialized...

 I can't figure out what the correct way to construct the nested
 class so it can belong to module.

 I want a class level construct of nested to belong to module, but
 I keep getting nestedClass isn't defined.

 My example isn't great or 100% accurate, but I hope you get the idea.

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

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


  1   2   >