Re: UnicodeDecodeError having fetch web page

2010-05-26 Thread John Machin
Rob Williscroft  rtw.me.uk> writes:

> 
> Barry wrote in news:83dc485a-5a20-403b-99ee-c8c627bdbab3
> @m21g2000vbr.googlegroups.com in gmane.comp.python.general:
> 

> > UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1:
> > unexpected code byte
> 
> It may not be you, en.wiktionary.org is sending gzip 
> encoded content back,

It sure is; here's where the offending 0x8b comes from:

"""ID1 (IDentification 1)
   ID2 (IDentification 2)
These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139
(0x8b, \213), to identify the file as being in gzip format."""

(from http://www.faqs.org/rfcs/rfc1952.html)


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


Re: function that counts...

2010-05-26 Thread Bryan
I wrote:
> My prttn() calls ndsums() once for each
> digit, so the whole thing is polynomial in the number of digits.

Correction: my prttn() function calls ndsums() at most 9 times per
digit of n. That still provides run time polynomial in the length of
the input.


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


Re: asyncore loop and cmdloop problem

2010-05-26 Thread [email protected]
On May 26, 2:03 am, [email protected] wrote:
> On 04:31 pm, [email protected] wrote:
>
>
>
> >On May 25, 5:47 pm, "[email protected]"  wrote:
> >>On May 25, 5:23 pm, Michele Simionato 
> >>wrote:
>
> >> > On May 25, 2:56 pm, "[email protected]"  wrote:
>
> >> > > Could you please provide me with a simple example how to do this
> >>with
> >> > > threads.
> >> > > I don't know where to put the cmdloop().
> >> > > Please help, i' m so confused!
> >> > > Thank you
>
> >> > What are you trying to do? Do you really need to use the standard
> >> > library? Likely what you want to accomplish is already implemented
> >>in
> >> > Twisted; I remember there was something like that in their examples
> >> > directory.
>
> >>Thank you,
> >>and sorry for the mistake i did before with my post.
>
> >>Antonis
>
> >hi again. i installed twisted, but since i m not familiar with it, do
> >you remember which example you have in mind?
> >What i want to accomplish is something like "asterisk". while you send
> >commands from the asterisk cli, at the same time
> >the underlying protocol sends you notifications to the console.
> >without exiting the application.
> >thanks
>
> You can find a couple simple examples here:
>
>  http://twistedmatrix.com/documents/current/core/examples/
>
> Search for "stdin" and "stdio".
>
> Jean-Paul

Thank you so much, i'll check them!!!
Antonis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function that counts...

2010-05-26 Thread Bryan
I wrote:
> > I came up with a recursive memo-izing algorithm that
> > handles 100-digit n's.

Oops. I missed Richard Thomas's post. He posted the same algorithm a
couple days before.


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


Kohonen neural network

2010-05-26 Thread Lex Lebedeff
Hello!

Has anyone tried to build an implementation of subject in Python?
Any help is appreciated!

--- news://freenews.netfront.net/ - complaints: [email protected] ---
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQLDB - server has gone on blob insertion...

2010-05-26 Thread Durumdara
Hi!

I want to test my program that coded into PGSQL, and PySQLite. With these
DBs I have problem on many blob deletion (2 hours) and compact/vacuum (1
hours)...

So I'm trying to port my program, and before that making a test to check,
which time needs to delete 1 GB of blobs.

I installed MySQLDb from the exe (Py2.6, from stackoverflow version), set
all parameters, etc.

import MySQLdb

conn = MySQLdb.connect (host = "localhost",
user = "root",
  passwd = "",
  db = "db")
cursor = conn.cursor ()
cursor.execute ("SELECT VERSION()")

cursor.execute('delete from blobs;')

s = time.time()
for i in range(200):
   k = str(i)
   xbuffer = chr(65 + (i % 26))
   xbuffer = xbuffer * 1024 * 1024
   b = MySQLdb.escape_string(xbuffer)
   print len(b)
   cursor.execute('''insert into blobs
(blob_id, file_id, size, ext, data)
values
(%s, %s, %s, %s, %s)''', (i, i, -1, 'org', b))
   conn.commit()
e = time.time()
t = e - s
print t

sys.exit()

When I tried to start this, I got error:

_mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')

I read that server have some parameter, that limit the Query length.

Then I decreased the blob size to 1M, and then it is working.

But: I can insert 800k-1,9 MB blobs.

I tried to set this parameter, but nothing changed.
My.ini:

# SERVER SECTION
# --
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]

max_allowed_packet = 16M

# The TCP/IP Port the MySQL Server will listen on
port=3306

What is the problem? What I do wrong?

Thanks for your help:
   dd
-- 
http://mail.python.org/mailman/listinfo/python-list


TypeError: _new_() takes exactly 3 arguments (2 given) - what does it mean?

2010-05-26 Thread Jesse McDonnell


I'm attempting to install Powerline http://code.google.com/p/powerline/, a computer reservation software based on CherryPy/Python using a MYSql database, at my local library and I've run up against an error that I cannot google my way out of!   The google groups for the application is inactive so I'm posting on here in the hope that I can get some pointers to get me beyond this issue. Any suggestions/pointers will be greatly appreciated.
 
 
The error message is
File "/usr/lib/python2.5/site-packages/powerline-0.2.4-py2.5.egg/powerline/main.py", line 38, in index   settings = settings_model(database)TypeError: __new__() takes exactly 3 arguments (2 given)
The full text/context is below - I've been working with Linux for about 15 years but I'm not a programmer, don't know anything about python so I'm totally stuck. (From googling, I believe that the missing Application config error returned by CherryPy Checker below is informational and not a show stopper. Powerline is the only python-based application running on the server)
The output below is the terminal output when the Links text-based browser running locally attempts to the Powerline application at localhost:8080. I've attached the main.py and database.py files (I'm guessing that these are the two files involved) from the powerline directory and the ls output for the directory also. I'll be happy to post any other files needed.
Thanks!
je...@ubuntu:~$ sudo python -m powerline.main /etc/powerline.conf[22/May/2010:19:48:56] ENGINE Listening for SIGHUP.[22/May/2010:19:48:56] ENGINE Listening for SIGTERM.[22/May/2010:19:48:56] ENGINE Listening for SIGUSR1.[22/May/2010:19:48:56] ENGINE Bus STARTINGCherryPy Checker:The Application mounted at '' has an empty config.
[22/May/2010:19:48:56] ENGINE Started monitor thread '_TimeoutMonitor'.[22/May/2010:19:48:56] ENGINE Started monitor thread 'Autoreloader'.[22/May/2010:19:48:56] ENGINE Serving on 127.0.0.1:8080[22/May/2010:19:48:56] ENGINE Bus STARTED[22/May/2010:19:50:09] HTTPRequest Headers: HOST: localhost:8080 ACCEPT: */* ACCEPT-CHARSET: us-ascii, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-10, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16, windows-1250, windows-1251, windows-1252, windows-1256, windows-1257, cp437, cp737, cp850, cp852, cp866, x-cp866-u, x-mac, x-mac-ce, x-kam-cs, koi8-r, koi8-u, koi8-ru, TCVN-5712, VISCII, utf-8 USER-AGENT: Links (2.1pre32; Linux 2.6.24-23-server i686; 176x45) CONNECTION: Keep-Alive Remote-Addr: 127.0.0.1 ACCEPT-LANGUAGE: en, *;q=0.1 ACCEPT-ENCODING: gzip, deflate[22/May/2010:19:50:09] HTTP Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/CherryPy-3.1.2-py2.5.egg/cherrypy/_cprequest.py", line 606, in respond   cherrypy.response.body = self.handler() File "/usr/lib/python2.5/site-packages/CherryPy-3.1.2-py2.5.egg/cherrypy/_cpdispatch.py", line 25, in __call__   return self.callable(*self.args, **self.kwargs) File "/usr/lib/python2.5/site-packages/powerline-0.2.4-py2.5.egg/powerline/web.py", line 62, in default   return handler_func(**kwargs) File "/usr/lib/python2.5/site-packages/powerline-0.2.4-py2.5.egg/powerline/web.py", line 99, in wrapper   body.update(result) File "/usr/lib/python2.5/site-packages/powerline-0.2.4-py2.5.egg/powerline/main.py", line 38, in index   settings = settings_model(database)TypeError: __new__() takes exactly 3 arguments (2 given)
XXX
XXXje...@ubuntu:/usr/lib/python2.5/site-packages/powerline-0.2.4-py2.5.egg/powerline$ more main.py# powerline.main - Main controllers and entry point# (c) 2008 Pianohacker, licensed under the GPLv3
import cherrypyfrom powerline import output, web, database, json, manager, xmlrpc, location, user_errorfrom powerline.lib import pluginfrom powerline.database import user_model, system_model, session_model, settings_model, connectimport timefrom sys import argvfrom os import path
class root(web.controller):   js = cherrypy.tools.staticdir.handler(section = '/js', dir = 'templates/js')   data = "" = '/data', dir = 'templates/data')   js._cp_config, data._cp_config = [{'tools.caching.on': True}] * 2
   def __init__(self):   self.XMLRPC = xmlrpc.api()   self.manager = manager.interface()
   cherrypy.config.update({   'tools.sessions.on': True,   'tools.decode.on': True,   'tools.encode.on': True,   'tools.encode.encoding': 'utf-8',   'tools.staticdir.root': location,   })
   plugin.load(path.join(location, 'plugins'))
   super(root, self).__init__()
   @web.accessible_by('/', method = 'GET')   @web.expose(template = 'index.html')   def index(self):   """/ - The main page. Also where reservation requests are POSTed to."""   database = connect()   setting

Vote to Add Python Package "pubsub" to the Python Standard Library

2010-05-26 Thread Tom
I vote for adding the Python package "pubsub" to the Python standard
library.  It has recently been added to wxpython (replacing the old
wx.lib.pubsub package), but it has application to non-gui programs as
well.

For more information see: .

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


[WxPython] Advice on Temperature Application Method & Structure

2010-05-26 Thread Jimbo
Hello

I have made a simple application using WxPython that is a temperature
converter. This is my first application made in WxPython, the only
other apps I have made were in Win32 c++ so I am new to widgets in
general.


I am looking for advice & criticism on when you should use classes in
GUI widget apps (& where) & other general advice:
- Structure of a wxPython script/code
- Should every window be in its own class?
- whats the best way to refer to a control (by window name or ID)
- Should a group of controls that are related be in a class
For example should I make a Celsius class that handles the
celsius editbox, static & button & the button action
function(convert_to_fahrenheit())?
- Errors, bad things I have done in my code
- When & why use a Validator??


Temperature Converter Application:
"""
Temperature Application

Description: This application uses WxPython to create a simple
windows app to convert temperature from celsius
to fahrenheit & visa versa.

Looking for advice on everything to do with wxPython:
For example:
- Structure of a wxPython script/code
- Should every window be in its own class?
- whats the best way to refer to a control (by window name or ID)
- Should a ground of controls that are related be in a class
For example should I make a Celsius class that handles the
celsius editbox, static & button?
- Errors, bad things I have done in my code
- When & why use a Validator??
"""


import wx


## Constants ##
ID_FAHREN = 1
ID_CELSIUS = 2


class Controller(wx.Frame):


def __init__(self, parent, id):

wx.Frame.__init__(self,parent,id,"Temperature Converter",
size=(247,186))

# Create Controls
panel = wx.Panel(self)
self.create_controls( panel, wx.Validator() )

self.fah_edit.SetValue(str(32))
self.cel_edit.SetValue(str(0))

# Define actions
self.Bind_Events()


def create_controls(self, panel, val):
""" Create all the controls we will need for the temperature
conversion """

self.bmp_static = wx.StaticText(panel, -1, "Bitmap pic will be here",
(10,5), (150,40))

self.fah_static = wx.StaticText(panel, -1, "Fahrenheit: ",
(10,70), (-1,-1))

self.cel_static = wx.StaticText(panel, -1,"Celsius: ",
(140,70), (-1,-1))

self.fah_edit = wx.TextCtrl(panel,ID_FAHREN, pos=(70,65),
size=(40,25), style=0, validator=val,
name='a')

self.cel_edit = wx.TextCtrl(panel,ID_CELSIUS, pos=(180,65),
size=(40,25), style=0, validator=val,
name='b')

self.to_fah_button = wx.Button(panel,label="To Fahrenheit",
pos=(145,95),size=(80,25))

self.to_cel_button = wx.Button(panel,label="To Celsius",
pos=(35,95),size=(80,25))

self.exit_button = wx.Button(panel,label="Exit",pos=(157,123),
size=(70,25))



def Bind_Events(self):
""" Bind application events to class functions """

self.Bind(wx.EVT_BUTTON,self.close_button,
self.exit_button)

self.Bind(wx.EVT_CLOSE,self.close_window)

self.Bind(wx.EVT_BUTTON,self.convert_to_celsius,
self.to_fah_button)

self.Bind(wx.EVT_BUTTON,self.convert_to_fahrenheit,
self.to_cel_button)


def close_button(self, event):

self.Close(True)


def close_window(self, event):

self.Destroy()


def error_check(self, string):
""" Check for valid input in editboxes. Valid input
includes float & integer values only """

if string.isalpha() or len(string) <= 0:

return False

return True


def convert_to_fahrenheit(self, event):
""" Convert the value in fahrenheit window to celsius &
display in our window/edit box """

# Algorithm
# - Get number from fahrenheit editbox
# - convert fahrenheit value to celsius
# - change value in Celsius Window to

# Step 1:
fahren_value = self.fah_edit.GetValue()

if not self.error_check( fahren_value ):

self.fah_edit.SetValue( "NA" )
return

# Step 2:
value = (float(fahren_value) - 32) * 5/9

# Step 3:
self.cel_edit.SetValue( str(value) )


def convert_to_celsius(self, event):
""" Convert the value in celcius window/editbox to
fahrenheit & display in our window/editbox """

# Algorithm
# - Get number from celsius editbox
# - convert celsius value to fahrenheit
# - change value in fahrenheit Window

# Step 1:
celsius_value = self.cel_edit.GetValue()

if not self.error_check( celsius_value ):

self.cel_edit.SetValue( "NA" )
return

# Step 2:
value = (float( celsius_value ) * 9/5) + 32

# Step 3:
self.fah_edit.SetValue( str(value) )



if __name__ == "__main__":

app = wx.PySimpleApp()

frame = Controller(parent=None,id=-1)
frame.Show()
app.MainLoop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed up a numpy code with huge array

2010-05-26 Thread Alexzive
thank you all for the tips.
I 'll try them soon.

I also notice another bottleneck, when python tries to access some
array data stored in the odb files (---> in text below), even before
starting the algoritm:

###
EPS_nodes = range(len(frames))
for f in frames:
... sum = 0
--->UN = F[f].fieldOutputs['U'].getSubset(region=TOP).values <---
... EPS_nodes[f] = UN[10].data[Scomp-1]/L3

###

unfortunately I don't have time to learn cython. Using dictionaries
sounds promising.
Thanks!
Alex

On May 26, 8:14 am, Stefan Behnel  wrote:
> Alexzive, 25.05.2010 21:05:
>
> > is there a way to improve the performance of the attached code ? it
> > takes about 5 h on a dual-core (using only one core) when len(V)
> > ~1MIL. V is an array which is supposed to store all the volumes of
> > tetrahedral elements of a grid whose coord. are stored in NN (accessed
> > trough the list of tetraelements -->  EL)
>
> Consider using Cython for your algorithm. It has direct support for NumPy
> arrays and translates to fast C code.
>
> Stefan

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


Re: speed up a numpy code with huge array

2010-05-26 Thread Alexzive

sorry it was just bullshit what I wrote about the second bottleneck,
it seemed to hang up but it was just me forgetting to double-enter
during debugging after "for cycle".

On May 26, 1:43 pm, Alexzive  wrote:
> thank you all for the tips.
> I 'll try them soon.
>
> I also notice another bottleneck, when python tries to access some
> array data stored in the odb files (---> in text below), even before
> starting the algoritm:
>
> ###
> EPS_nodes = range(len(frames))
> for f in frames:
> ...     sum = 0
> --->    UN = F[f].fieldOutputs['U'].getSubset(region=TOP).values <---
> ...     EPS_nodes[f] = UN[10].data[Scomp-1]/L3
>
> ###
>
> unfortunately I don't have time to learn cython. Using dictionaries
> sounds promising.
> Thanks!
> Alex
>
> On May 26, 8:14 am, Stefan Behnel  wrote:
>
>
>
> > Alexzive, 25.05.2010 21:05:
>
> > > is there a way to improve the performance of the attached code ? it
> > > takes about 5 h on a dual-core (using only one core) when len(V)
> > > ~1MIL. V is an array which is supposed to store all the volumes of
> > > tetrahedral elements of a grid whose coord. are stored in NN (accessed
> > > trough the list of tetraelements -->  EL)
>
> > Consider using Cython for your algorithm. It has direct support for NumPy
> > arrays and translates to fast C code.
>
> > Stefan

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


Re: A Quick MySQL Question

2010-05-26 Thread Victor Subervi
On Wed, May 26, 2010 at 2:42 AM, Dennis Lee Bieber wrote:

> I was, for that example, assuming that the user input "values" was
> being used in a select query and hence wrapped it with wildcard markers
> so that the phrase would match anywhere in the data field.
>

In said thread you wrote the following:

clauses = []
for nm in nameList:
   clauses.append(nm + " like %s")
where = " and ".join(clauses)   #could be " or "
valueList = ["%%s%" % vl for vl in valueList]
SQL = "select * from table where " + where
cur.execute(SQL, valueList)

Ok, so let's assume we have a name list of:

["name1", "name2", "name3"]

and a value list of:

["value1", "value2", "value3"]

Therefore:

clauses = ["name1 like %s", "name2 like %s", "name3 like %s"]
where = "name1 like %s and name2 like %s and name3 like %s"
SQL = "select * from table where name1 like %s and name2 like %s and name3
like %s"
valueList = ("%value1", "%value2", "%value3")
cur.execute("select * from table where name1 like %s and name2 like %s and
name3 like %s", ("%value1", "%value2", "%value3"))

Why do the values have that extra "%"?
TIA,
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kohonen neural network

2010-05-26 Thread alex23
On May 26, 7:21 pm, Lex Lebedeff  wrote:
> Has anyone tried to build an implementation of subject in Python?
> Any help is appreciated!

http://www.dia.fi.upm.es/~jamartin/download.htm

Seriously, though, any reason why you couldn't just type "kohonen
neural network python" into Google? You would've found it a lot easier
to wade through the results before your question & it's many mirrors.
It would've been the 2nd entry, immediately after the wikipedia
article on Kohonen SOMs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [WxPython] Advice on Temperature Application Method & Structure

2010-05-26 Thread Philip Semanchuk


On May 26, 2010, at 7:36 AM, Jimbo wrote:


Hello

I have made a simple application using WxPython that is a temperature
converter. This is my first application made in WxPython, the only
other apps I have made were in Win32 c++ so I am new to widgets in
general.


I am looking for advice & criticism on when you should use classes in
GUI widget apps (& where) & other general advice:


Hi Jimbo,
The first piece of advice I have is to post on the wxPython mailing  
list where you'll reach a more focused audience.



- Should every window be in its own class?


That works for me.


- whats the best way to refer to a control (by window name or ID)


ID. Uniqueness is not enforced among window names.


- Should a group of controls that are related be in a class
For example should I make a Celsius class that handles the
celsius editbox, static & button & the button action
function(convert_to_fahrenheit())?


When and where to use a class is not wxPython-specific, and is partly  
a matter of taste. For instance, I would not put a  
convert_to_fahrenheit() function inside a class, because it doesn't  
need any class-related info. Make it a module-level function and it  
will be easier to re-use. I wouldn't do what you suggested (grouping  
controls into a class) because it doesn't seem to serve any purpose  
other than documentation, which can be accomplished just as well with  
a comment. Ask yourself this -- what problem would grouping them into  
a class solve?




- When & why use a Validator??


I'm ambivalent about Validators. Before I used them I had all of my  
init code in one place, and in the on_ok_clicked() event I had all of  
my teardown code and it was easy to see what control got assigned to  
which variable. Now that information is scattered through a bunch of  
classes which are fairly verbose.


Also, Validators are great for validating individual controls, but not  
so great with groups. E.g. when control A can only be blank if B is  
too. A & B have to know about one another and the Validator starts to  
get messy.


OTOH it's nice to group the code that knows everything that needs to  
be know about the relationship between a control and the variable to  
which is assigned. We call the validator when the control loses focus  
(to let users know if they've entered something invalid) and when OK  
is clicked. It's nice to be able to simply call the validators in that  
case.


Good luck with your app
Philip



Temperature Converter Application:
"""
Temperature Application

Description: This application uses WxPython to create a simple
windows app to convert temperature from celsius
to fahrenheit & visa versa.

Looking for advice on everything to do with wxPython:
For example:
- Structure of a wxPython script/code
- Should every window be in its own class?
- whats the best way to refer to a control (by window name or ID)
- Should a ground of controls that are related be in a class
For example should I make a Celsius class that handles the
celsius editbox, static & button?
- Errors, bad things I have done in my code
- When & why use a Validator??
"""


import wx


## Constants ##
ID_FAHREN = 1
ID_CELSIUS = 2


class Controller(wx.Frame):


def __init__(self, parent, id):

wx.Frame.__init__(self,parent,id,"Temperature Converter",
size=(247,186))

# Create Controls
panel = wx.Panel(self)
self.create_controls( panel, wx.Validator() )

self.fah_edit.SetValue(str(32))
self.cel_edit.SetValue(str(0))

# Define actions
self.Bind_Events()


def create_controls(self, panel, val):
""" Create all the controls we will need for the temperature
conversion """

self.bmp_static = wx.StaticText(panel, -1, "Bitmap pic will be here",
(10,5), (150,40))

self.fah_static = wx.StaticText(panel, -1, "Fahrenheit: ",
(10,70), (-1,-1))

self.cel_static = wx.StaticText(panel, -1,"Celsius: ",
(140,70), (-1,-1))

self.fah_edit = wx.TextCtrl(panel,ID_FAHREN, pos=(70,65),
size=(40,25), style=0, validator=val,
name='a')

self.cel_edit = wx.TextCtrl(panel,ID_CELSIUS, pos=(180,65),
size=(40,25), style=0, validator=val,
name='b')

self.to_fah_button = wx.Button(panel,label="To Fahrenheit",
pos=(145,95),size=(80,25))

self.to_cel_button = wx.Button(panel,label="To Celsius",
pos=(35,95),size=(80,25))

self.exit_button = wx.Button(panel,label="Exit",pos=(157,123),
size=(70,25))



def Bind_Events(self):
""" Bind application events to class functions """

self.Bind(wx.EVT_BUTTON,self.close_button,
self.exit_button)

self.Bind(wx.EVT_CLOSE,self.close_window)

self.Bind(wx.EVT_BUTTON,self.convert_to_celsius,
self.to_fah_button)

self.Bind(wx.EVT_BUTTON,self.convert_to_fahrenheit,
self.to_cel_button)


def close_button(self, event):

self.Close(True)


def close_window(self, event):

self.Destroy()


def error_check(self, string):
""" Check for valid input in editboxes. Valid input
includes float & integer values only """

if string.isalpha() or len(string) <= 0:

return False

return True


def convert_to_fahrenheit(self, event):
""" Co

Inheritable Slots Metaclass

2010-05-26 Thread Rebel Lion
I made a metaclass to inherit __slots__ automatically.

I think this feature should be included in builtin object's metaclass.

You can now write:

class Foo(object):
__metaclass__ = SlotMetaclass

@slot
def foo():
pass


class Bar(Foo):

@slot
def bar():
pass

foo = Foo()
foo.foo = 1
bar = Bar()
bar.bar = 1
bar.foo = 1
try:
bar.baz = 1 # this should fall
except AttributeError, e:
print 'yeah', e


Instead of

class Foo(object):
  __slots__ = ['foo']
class Bar(Foo)
  __slots__ = ['foo', 'bar']


Please discuss the pros & cons for this feature.


Here is the metaclass:

class slot(object):
"""Slot Decorator"""

def __init__(self, func):
pass


class SlotMetaclass(type):
"""Inheritable Slots Metaclass"""

def __new__(cls, name, bases, attrs):
# make a normal class, and get its attributes to decide which
ones are slots
tmpcls = type.__new__(cls, name, bases, attrs)
slots = []
for k in dir(tmpcls):
v = getattr(tmpcls, k)
if isinstance(v, slot):
slots.append(k)
# clean up
del tmpcls
for x in slots:
del attrs[x]
# create the real class with __slots__
attrs['__slots__'] = slots
return type.__new__(cls, name, bases, attrs)




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


Looking for matlab to python converter.

2010-05-26 Thread Steven W. Orr
I found something on sourceforge called mat2py, but there's nothing there. (It 
seems to be just a placeholder.) I figure that if anyone would know of something 
useful, this would be the place to try.


TIA

--
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
--
http://mail.python.org/mailman/listinfo/python-list


LJ.com top article

2010-05-26 Thread Aahz
I'm finally getting around to reading my copy of Linux Journal 8/2009
(picked up at OSCON last year), and on page 17, they list the most
popular articles from linuxjournal.com.  Given that I'm posting here,
I'm sure all long-time readers already know what that article is: Eric
Raymond's "Why Python?", now ten years old.

http://www.linuxjournal.com/article/3882
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for matlab to python converter.

2010-05-26 Thread alex23
On May 26, 10:52 pm, "Steven W. Orr"  wrote:
> I found something on sourceforge called mat2py, but there's nothing there. (It
> seems to be just a placeholder.) I figure that if anyone would know of 
> something
> useful, this would be the place to try.

http://sourceforge.net/projects/libermate/

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


Does pickled objects work fine between different OS?

2010-05-26 Thread Oltmans
If I dump a Python dictionary into a file named "data.pkl" using
Pickle module on a Linux operating system, will the data contained in
"data.pkl" load fine in a Windows OS? I mean will I be able to load
the dictionary data contained in "data.pkl" just fine on Windows XP?

I could have tested it but don't have immediate access to a *nix based
system so please enlighten me. All help will be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python command line manual

2010-05-26 Thread Aahz
In article ,
Chris Rebert   wrote:
>On Mon, May 24, 2010 at 3:52 PM, Peng Yu  wrote:
>>
>> I mainly check online python manual. But I feel that it would be nice
>> if there is command line manual available (just like perl command line
>> manual). Could you please let me know if such command line manual
>> available?
>
>98% sure that there isn't. You could instead use a text-based console
>web browser such as lynx to view the online docs to much the same
>effect though.

...after downloading them locally so that you're not dependent on an
Internet connection.  At least, that's what I've been doing for about a
decade...
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python command line manual

2010-05-26 Thread Tim Golden

On 26/05/2010 14:50, Aahz wrote:

In article,
Chris Rebert  wrote:

On Mon, May 24, 2010 at 3:52 PM, Peng Yu  wrote:


I mainly check online python manual. But I feel that it would be nice
if there is command line manual available (just like perl command line
manual). Could you please let me know if such command line manual
available?


98% sure that there isn't. You could instead use a text-based console
web browser such as lynx to view the online docs to much the same
effect though.


...after downloading them locally so that you're not dependent on an
Internet connection.  At least, that's what I've been doing for about a
decade...


Wow. That's a slow internet connection you've got there...

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


Python-URL! archives

2010-05-26 Thread Mark Lawrence
According to http://www.python.org/community/lists/ these are archived 
here http://www.equi4.com/wikis/urls/82.  As the latter hasn't been 
updated since 2000-07-20 isn't it time to change the former :)


Regards.

Mark Lawrence

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


Re: python command line manual

2010-05-26 Thread Mark Lawrence

On 26/05/2010 14:59, Tim Golden wrote:

On 26/05/2010 14:50, Aahz wrote:

In article,
Chris Rebert wrote:

On Mon, May 24, 2010 at 3:52 PM, Peng Yu wrote:


I mainly check online python manual. But I feel that it would be nice
if there is command line manual available (just like perl command line
manual). Could you please let me know if such command line manual
available?


98% sure that there isn't. You could instead use a text-based console
web browser such as lynx to view the online docs to much the same
effect though.


...after downloading them locally so that you're not dependent on an
Internet connection. At least, that's what I've been doing for about a
decade...


Wow. That's a slow internet connection you've got there...

TJG


+1 LOTW

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


Re: function that counts...

2010-05-26 Thread Albert van der Horst
In article <[email protected]>,
superpollo   wrote:
>... how many positive integers less than n have digits that sum up to m:
>
>In [197]: def prttn(m, n):
> tot = 0
> for i in range(n):
> s = str(i)
> sum = 0
> for j in range(len(s)):
> sum += int(s[j])
> if sum == m:
> tot += 1
> return tot
>.:
>
>In [207]: prttn(25, 1)
>Out[207]: 348
>
>any suggestion for pythonizin' it?

I don't like the excursion to string and back.

def x(i) : return  x(i/10)+i%10 if i else 0

or if you can't stand recursion:

def x(i):
   s= 0
   while i:
  s += i%10
  i /= 10
   return s

(All untested but you get the idea.)

>
>bye


--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
alb...@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: speed up a numpy code with huge array

2010-05-26 Thread bobicanprogram
On May 26, 7:43 am, Alexzive  wrote:
> thank you all for the tips.
> I 'll try them soon.
>
> I also notice another bottleneck, when python tries to access some
> array data stored in the odb files (---> in text below), even before
> starting the algoritm:
>
> ###
> EPS_nodes = range(len(frames))
> for f in frames:
> ... sum = 0
> --->UN = F[f].fieldOutputs['U'].getSubset(region=TOP).values <---
> ... EPS_nodes[f] = UN[10].data[Scomp-1]/L3
>
> ###
>
> unfortunately I don't have time to learn cython. Using dictionaries
> sounds promising.
> Thanks!
> Alex
>
> On May 26, 8:14 am, Stefan Behnel  wrote:
>
> > Alexzive, 25.05.2010 21:05:
>
> > > is there a way to improve the performance of the attached code ? it
> > > takes about 5 h on a dual-core (using only one core) when len(V)
> > > ~1MIL. V is an array which is supposed to store all the volumes of
> > > tetrahedral elements of a grid whose coord. are stored in NN (accessed
> > > trough the list of tetraelements -->  EL)
>
> > Consider using Cython for your algorithm. It has direct support for NumPy
> > arrays and translates to fast C code.
>
> > Stefan


The SIMPL toolkit (http://www.icanprogram.com/06py/lesson1/
lesson1.html) might be a simpler way to offload some processing to
faster C code.

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


Re: Another Little MySQL Problem

2010-05-26 Thread Kushal Kumaran
On Tue, 2010-05-25 at 14:45 -0400, Victor Subervi wrote:
> Hi;
> I have this code:
> 
> clientCursor.execute('select ID from %s' % (personalDataTable))
> upds = [itm[0] for itm in clientCursor]
> print "" % upds
> 
> The problem is that the values passed are 1L, 2L When I retrieve
> them on the other end and try to convert them to integers, guess what
> happens? So how do I get rid of that "L"?

You could build a list of ints instead of a list of longs, like this:

upds = [int(itm[0]) for itm in clientCursor]

I'm not sure if the result of applying str() on lists is guaranteed not
to change, though.

-- 
regards,
kushal



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


Re: UnicodeDecodeError having fetch web page

2010-05-26 Thread Kushal Kumaran
On Tue, 2010-05-25 at 20:12 +, Rob Williscroft wrote:
> Barry wrote in news:83dc485a-5a20-403b-99ee-c8c627bdbab3
> @m21g2000vbr.googlegroups.com in gmane.comp.python.general:
> 
> > Hi,
> > 
> > The code below is giving me the error:
> > 
> > Traceback (most recent call last):
> >   File "C:\Users\Administratör\Desktop\test.py", line 4, in 
> > UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1:
> > unexpected code byte
> > 
> > 
> > What am i doing wrong?
> 
> It may not be you, en.wiktionary.org is sending gzip 
> encoded content back, it seems to do this even if you set
> the Accept header as in:
> 
> request.add_header( "Accept", "text/html" )
> 
> But maybe I'm not doing it correctly.
> 

You need the Accept-Encoding: identity header.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html



-- 
regards,
kushal


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


Re: Does pickled objects work fine between different OS?

2010-05-26 Thread Daniel Fetchinson
> If I dump a Python dictionary into a file named "data.pkl" using
> Pickle module on a Linux operating system, will the data contained in
> "data.pkl" load fine in a Windows OS?

Yes.

> I mean will I be able to load the dictionary data contained in "data.pkl"
> just fine on Windows XP?

Yes.

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does pickled objects work fine between different OS?

2010-05-26 Thread Ross Ridge
Oltmans   wrote:
>If I dump a Python dictionary into a file named "data.pkl" using
>Pickle module on a Linux operating system, will the data contained in
>"data.pkl" load fine in a Windows OS? I mean will I be able to load
>the dictionary data contained in "data.pkl" just fine on Windows XP?

That will work just fine.  The only thing that may be a problem is that
if you choose to use the newer pickle format, it won't work with versions
of Python before 2.3.

Ross Ridge

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


Re: Does pickled objects work fine between different OS?

2010-05-26 Thread Grant Edwards
On 2010-05-26, Oltmans  wrote:

> If I dump a Python dictionary into a file named "data.pkl" using
> Pickle module on a Linux operating system, will the data contained in
> "data.pkl" load fine in a Windows OS?

That depends on the data and the version of Python.  Older versions
didn't handle some floating point values (NAN, INF) in a portable
manner, and loading the pickled data would fail when such a value was
encountered.

-- 
Grant Edwards   grant.b.edwardsYow! It's the RINSE CYCLE!!
  at   They've ALL IGNORED the
  gmail.comRINSE CYCLE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


question

2010-05-26 Thread Kent Tenney
In a docutils svn checkout.

[docutils/trunk/docutils]$ python setup.py install --root /tmp
OK

[docutils/trunk/docutils]$ python setup.py install_data --root /tmp

distutils.errors.DistutilsFileError:
could not delete
'/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/include/README.txt':
Permission denied

Am I missing something?

If it works for you, I suppose it's somewhere in my versioning.
I have bull in a china shop tendencies when it comes to installing stuff.

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


Re: Troubles with python internationalization

2010-05-26 Thread Dan Stromberg
On May 25, 10:46 am, Pascal Chambon  wrote:

> * code safety : it seems default python string formatting technics (%
> operator, .format() method) are normally used when one needs to
> substitute placeholders in translated strings. But the thing is : I DONT
> want my view to raise an exception simply because one of the
> translations has forgotten a damn "%(myvar)s" placeholder. The only
> quick fix I can think of, is to always use substitution through
> defaultdicts instances (and still, exceptions could occur if abnormal
> "%s" placeholders are found in the translated string).
> Are there some utilities in python, or frameworks like django,
>   to allow a safe string substitution (which might,
> for example, simply log an error if a buggy string si found)  ? Python's
> template strings' "safe_substitute()" won't fit, because it swallows
> errors without any notice...

For this one, you might check into pylint.  I've just recently started
using it, but I'm loving it.  I pretty much don't check things in
without first running them through pylint (and some unit tests) first
now.

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


uk girls

2010-05-26 Thread devi
we are write here
uk girls body language
uk girls clture
and that feature what
about this last man
visit in earth.

visit www.ukgirlsbody.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


uk girls

2010-05-26 Thread devi
we are write here
uk girls body language
uk girls clture
and that feature what
about this last man
visit in earth.

visit  www.onlineairlinesjobs.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Yet Another Configuration Parser Module

2010-05-26 Thread christian schulze
Hey folks,
I've written a small configuration parser for a recent project. I
think it's pretty usefull and not that "fat" or "complex" as the
regular python configuration modules like ConfigParser. The file
contains everything you need to know.

http://crac.pcriot.com/dl/config.py

If you have any suggestions I'd be glad if you'd contact me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another Little MySQL Problem

2010-05-26 Thread Victor Subervi
On Wed, May 26, 2010 at 11:25 AM, Kushal Kumaran
wrote:

> On Tue, 2010-05-25 at 14:45 -0400, Victor Subervi wrote:
> > Hi;
> > I have this code:
> >
> > clientCursor.execute('select ID from %s' % (personalDataTable))
> > upds = [itm[0] for itm in clientCursor]
> > print "" % upds
> >
> > The problem is that the values passed are 1L, 2L When I retrieve
> > them on the other end and try to convert them to integers, guess what
> > happens? So how do I get rid of that "L"?
>
> You could build a list of ints instead of a list of longs, like this:
>
> upds = [int(itm[0]) for itm in clientCursor]
>

Oh, geez. That should have been obvious to me! Thanks!
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Error

2010-05-26 Thread William Miner
I¹m relative new to python and I puzzled by the following strange (to me)
behavior. I was taking pieces from two old scripts to build a new one. When
I began to debug it I got the following error message:

Traceback (most recent call last):
  File 
"/Users/williamminer/ex2gen/ex2gen-3.0.5/src/ScriptDev/run_ex2gen_scan.py",
line 38, in 
if re.search('varm',line):
AttributeError: 'function' object has no attribute 'search'

This had worked in the previous script but not the new one. I noticed that
the new script had an additional line at the beginning (line 3)

#!/usr/bin/env python
import sys, math, os, shutil, commands, re, mpmath
from mpmath import *

When I deleted this line, the script ran. Why did the line

from mpmath import *

Trash the search function fro the regular expression module?

I¹m running Python 2.6.2 on  Mac running OS 10.6.3.

Thanks!

Buff Miner
-- 
Enig Associates, Inc.
Suite 500, Bethesda Crescent Bldg.
4600 East West Hwy
Bethesda, Maryland 20814
Tel:(301)680-8600
Fax:(301)680-8100

This message is intended only for the use of the intended recipient(s), and
it may be privileged and confidential. If you are not the intended
recipient, you are hereby notified that any review, retransmission,
conversion to hard copy, copying, circulation or other use of this message
is strictly prohibited and may be illegal. If you are not the intended
recipient, please notify the sender immediately by return e-mail, and delete
this message from your system. Thank you.


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


Re: Ugly modification of a class, can it be done better ?

2010-05-26 Thread Stef Mientki
On 21-05-2010 03:27, Steven D'Aprano wrote:
> Sorry for breaking threading, but Stef's original post has not come 
> through to me.
>
>   
>> On Thu, May 20, 2010 at 8:13 PM, Stef Mientki 
>> wrote:
>> 
>   
>>> So I want to change the behavior of the class dynamically. I've done it
>>> by adding a global variable (Base_Grid_Double_Click) in the module,
>>> initial set to None,
>>> but can be changed by the main program to some callback function. (see
>>> the code below)
>>>   
> How is this supposed to work? If you have *one* global, then *every* 
> instance will see the same setting.
But that's exactly what I need ;-)
The problem is a little more complicated,
I've several "frame-works",
that searches for specific modules (applications) in a specific directory.
The frame work should determine what should happen (e.g. on a
doubleclick of a grid cell) in these modules (application),
but the frame work has no idea what kind of instances are in these modules.
The same module can be used in different frame-works (or even
stand-alone) and the behavior of e.g. a doubleclick,
can differ, depending on the frame work.
Describing the situation above, I realize that the concept is already
spaghetti in itself ;-)
but for a modular system this works like a charm.
So for the moment I'll stick to the orginal solution.

thank you all for the responses.
cheers,
Stef Mientki

>  To change it dynamically, you enter a 
> nightmare world of having to save the global, modify it, then restore it, 
> every single time. Trust me, I've been there, this is the *worst* way of 
> programming. This is why object oriented inheritance was invented, to 
> escape this nonsense!
>
> The first thing is to make the callback specific to the class, not 
> global. Why does your printing code need access to the callback that 
> handles double-clicking on a grid? It doesn't! So don't give it that 
> access (at least, not easy access). Put the callback in the class.
>
> class MyClass:
> callback = None
> def method(self, *args):
> if self.callback is None:
> behaviour_with_no_callback()
> else:
> behaviour_with_callback()
> 
>
> Now if you want to apply a callback to some instances, and not others, it 
> is totally simple:
>
>
> red = MyClass()
> blue = MyClass()
> red.callback = my_callback_function
>
> and you're done.
>
>
> If you have lots of instances that use the same callback? Make a subclass.
>
> class MyDottedClass(MyClass):
> pass
>
> red = MyClass()
> blue = MyClass()
> red_with_green_dots = MyDottedClass()
> blue_with_green_dots = MyDottedClass()
>
> MyDottedClass.callback = dotted_callback
>
> And now all the dot instances will use the same callback without 
> effecting the undotted instances. What to change them all to use a 
> different behaviour?
>
> MyDottedClass.callback = something_different
>
> and now they all change, again without effecting the undotted instances.
>
>
>
>
>   
>>> Is this a valid construction ( sorry I'm not a programmer), or are
>>> there better ways to accomplish similar dynamic behavior ?
>>>   
> Of course you're a programmer! You're writing programs, aren't you?
>
>
>
>
>   

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


Re: Error

2010-05-26 Thread Chris Rebert
On Wed, May 26, 2010 at 10:48 AM, William Miner  wrote:
> I’m relative new to python and I puzzled by the following strange (to me)
> behavior. I was taking pieces from two old scripts to build a new one. When
> I began to debug it I got the following error message:
>
> Traceback (most recent call last):
>   File
> "/Users/williamminer/ex2gen/ex2gen-3.0.5/src/ScriptDev/run_ex2gen_scan.py",
> line 38, in 
> if re.search('varm',line):
> AttributeError: 'function' object has no attribute 'search'
>
> This had worked in the previous script but not the new one. I noticed that
> the new script had an additional line at the beginning (line 3)
>
> #!/usr/bin/env python
> import sys, math, os, shutil, commands, re, mpmath
> from mpmath import *
>
> When I deleted this line, the script ran. Why did the line
>
> from mpmath import *
>
> Trash the search function fro the regular expression module?

mpmath defines a function named re() which returns the real part of a
complex number. Because you used "import *", the existing value of the
global variable "re", which was the regular expression module, gets
clobbered with mpmath's re() function. Thus, you get that error when
you try to call the "search" method on what is now a function object.

This is precisely why using the `from foo import *` syntax is discouraged.

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


Re: UnicodeDecodeError having fetch web page

2010-05-26 Thread Rob Williscroft
Kushal Kumaran wrote in news:1274889564.2339.16.ca...@nitrogen in
gmane.comp.python.general: 

> On Tue, 2010-05-25 at 20:12 +, Rob Williscroft wrote:
>> Barry wrote in news:83dc485a-5a20-403b-99ee-c8c627bdbab3
>> @m21g2000vbr.googlegroups.com in gmane.comp.python.general:
>> 
>> > Hi,
>> > 
>> > The code below is giving me the error:
>> > 
>> > Traceback (most recent call last):
>> >   File "C:\Users\Administratör\Desktop\test.py", line 4, in
>> >
>> > UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position
>> > 1: unexpected code byte
>> > 
>> > 
>> > What am i doing wrong?
>> 
>> It may not be you, en.wiktionary.org is sending gzip 
>> encoded content back, it seems to do this even if you set
>> the Accept header as in:
>> 
>> request.add_header( "Accept", "text/html" )
>> 
>> But maybe I'm not doing it correctly.
>> 
> You need the Accept-Encoding: identity header.
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html

Thanks, following this I did change the line to be:

request.add_header( "Accept-Encoding", "identity" )

but it made no difference to en.wiktionary.org it just sent the
back a gzip encoded response.

Rob.

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


Re: Error

2010-05-26 Thread MRAB

William Miner wrote:
I’m relative new to python and I puzzled by the following strange (to 
me) behavior. I was taking pieces from two old scripts to build a new 
one. When I began to debug it I got the following error message:


Traceback (most recent call last):
  File 
"/Users/williamminer/ex2gen/ex2gen-3.0.5/src/ScriptDev/run_ex2gen_scan.py", 
line 38, in 

if re.search('varm',line):
AttributeError: 'function' object has no attribute 'search'

This had worked in the previous script but not the new one. I noticed 
that the new script had an additional line at the beginning (line 3)


#!/usr/bin/env python
import sys, math, os, shutil, commands, re, mpmath
from mpmath import *

When I deleted this line, the script ran. Why did the line

from mpmath import *

Trash the search function fro the regular expression module?

I’m running Python 2.6.2 on  Mac running OS 10.6.3.


When you write:

from mpmath import *

you're importing all the 'public' names (by which I mean those not
starting with '_') from the mpmath module.

The mpmath module happens to contain a function called 're', so 're'
will now refer to that function instead of the re module.

That's why using "import *" is usually a bad idea.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error

2010-05-26 Thread D'Arcy J.M. Cain
On Wed, 26 May 2010 13:48:42 -0400
William Miner  wrote:
> #!/usr/bin/env python
> import sys, math, os, shutil, commands, re, mpmath
> from mpmath import *
> 
> When I deleted this line, the script ran. Why did the line
> 
> from mpmath import *
> 
> Trash the search function fro the regular expression module?

What is mpmath?  It isn't in the standard distribution.  My guess is
that it has an object called "re" that is overwriting the re module.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: _new_() takes exactly 3 arguments (2 given) - what does it mean?

2010-05-26 Thread Terry Reedy

On 5/24/2010 2:52 PM, Jesse McDonnell wrote:

I'm attempting to install Powerline http://code.google.com/p/powerline/,
a computer reservation software based on CherryPy/Python using a MYSql
database, at my local library and I've run up against an error that I
cannot google my way out of! The google groups for the application is
inactive so I'm posting on here in the hope that I can get some pointers
to get me beyond this issue. Any suggestions/pointers will be greatly
appreciated.


Honestly, unless you find a Python+Powerline expert who will help, I 
suggest that you delete Powerline and look for something else. The most 
recent release is an alpha release over 2 years old. Except for the Feb 
2010 wiki updates, the project appears to be dead. Even if someone 
helped you past this, there is no evidence that the fix would applied 
back to the codebase. And what about the next bug or problem?


Otherwise, sign in and submit a new issue on the project tracker, with 
just your command line, empty config response, and traceback  (if 
allowed, I do not know) and see if you get a response.


Terry Jan Reedy


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


Re: Error

2010-05-26 Thread Gary Herron

On 05/26/2010 10:48 AM, William Miner wrote:
I'm relative new to python and I puzzled by the following strange (to 
me) behavior. I was taking pieces from two old scripts to build a new 
one. When I began to debug it I got the following error message:


Traceback (most recent call last):
  File 
"/Users/williamminer/ex2gen/ex2gen-3.0.5/src/ScriptDev/run_ex2gen_scan.py", 
line 38, in 

if re.search('varm',line):
AttributeError: 'function' object has no attribute 'search'

This had worked in the previous script but not the new one. I noticed 
that the new script had an additional line at the beginning (line 3)


#!/usr/bin/env python
import sys, math, os, shutil, commands, re, mpmath
from mpmath import *

When I deleted this line, the script ran. Why did the line

from mpmath import *


Just a guess, (since I don;t have mpmath on hand), but if mpmath has a 
definition for something named re, it would overwrite any previous 
definition of re.


So general advice says don't use the "from xxx import *" unless you 
really *know* what is in the module, and need *all* of it imported.


Either:
  from mpmath import x,y,z,whatever

or
  import re
  import mpmath
  ... re.search ...
  ... mpmath.whatever ...



Gary Herron






Trash the search function fro the regular expression module?

I'm running Python 2.6.2 on  Mac running OS 10.6.3.

Thanks!

Buff Miner
--
Enig Associates, Inc.
Suite 500, Bethesda Crescent Bldg.
4600 East West Hwy
Bethesda, Maryland 20814
Tel:(301)680-8600
Fax:(301)680-8100

This message is intended only for the use of the intended 
recipient(s), and

it may be privileged and confidential. If you are not the intended
recipient, you are hereby notified that any review, retransmission,
conversion to hard copy, copying, circulation or other use of this message
is strictly prohibited and may be illegal. If you are not the intended
recipient, please notify the sender immediately by return e-mail, and 
delete

this message from your system. Thank you.



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


multiprocessing and accessing server's stdout

2010-05-26 Thread Tim Arnold
Hi,
I'm using multiprocessing's BaseManager to create a server on one
machine and a client on another. The client fires a request and the
server does some work, the result of which ends up on a shared file
system that both the client and server can see.

However, I need the client machine to see the stdout of the process
running on the server. Not sure this is doable--I've been unable to
google anything useful on this one.

thanks,
--Tim Arnold

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


Re: TypeError: _new_() takes exactly 3 arguments (2 given) - what does it mean?

2010-05-26 Thread Carl Banks
[Again, can't see the original, sorry]

On May 26, 11:30 am, Terry Reedy  wrote:
> On 5/24/2010 2:52 PM, Jesse McDonnell wrote:
>
> > I'm attempting to install Powerlinehttp://code.google.com/p/powerline/,
> > a computer reservation software based on CherryPy/Python using a MYSql
> > database, at my local library and I've run up against an error that I
> > cannot google my way out of! The google groups for the application is
> > inactive so I'm posting on here in the hope that I can get some pointers
> > to get me beyond this issue. Any suggestions/pointers will be greatly
> > appreciated.


The most common reason for this message is trying to subclass a
module.  (Very easy mistake when a module has the same name as a
class, which is part of why I don't like the practice, though the
modern PEP 8 reduces the issue.)

IOW, someone did something like this:

import foo
class bar(foo): pass

when they should have done this:

from foo import foo
class bar(foo): pass


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


Fetching a gzipped webpage

2010-05-26 Thread Barry
Hi,

Here's my attempt at petching a webpage which is gzip encoded -

import urllib.request
import gzip
import io

request = urllib.request.Request(url='http://en.wiktionary.org/wiki/
baby',headers={'Accept': 'text/html','User-Agent':'Mozilla/5.0
(iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1
(KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3'} )
response = urllib.request.urlopen(request)
data = response.read()

compressedstream = io.StringIO(data)

gzipper = gzip.GzipFile(fileobj=compressedstream)
data = gzipper.read()
print(data)


However it gives the error:

Traceback (most recent call last):
  File "test.py", line 9, in 
TypeError: initial_value must be str or None, not bytes

How should I be doing this for Python 3?

Thanks

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


Re: Another Little MySQL Problem

2010-05-26 Thread John Nagle

Kushal Kumaran wrote:

On Tue, 2010-05-25 at 14:45 -0400, Victor Subervi wrote:

Hi;
I have this code:

clientCursor.execute('select ID from %s' % (personalDataTable))
upds = [itm[0] for itm in clientCursor]
print "" % upds

The problem is that the values passed are 1L, 2L When I retrieve
them on the other end and try to convert them to integers, guess what
happens? So how do I get rid of that "L"?


What's the table definition?

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


Re: MySQL, Python, NumPy and formatted read

2010-05-26 Thread John Nagle

Ian Hoffman wrote:

Hello,

I'm having significant Python difficulties (and I'm new to Python).
I'm trying to read BLOB ASCII (numerical) data from a MySQL database
using MySQLdb in a formatted fashion.  The BLOB data is a sequence of
numbers separated by newlines (\n), like this:
5
6
10
45
etc.


   Note that a BLOB is not ASCII.  If you're storing ASCII text, use type
TEXT in SQL, not type BLOB.  Don't lie to the database.  It doesn't like that.
And if you're going to store numbers, store numbers, not text.  SQL has
the usual integer and floating point types.

   When you read a BLOB from MySQLdb, you do not get a string.  You get
an object of type "bytes".  This is not a Python string.  Python strings
can be ASCII or Unicode in Python 2.x, and in 3.x, are always Unicode.

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


Re: Fetching a gzipped webpage

2010-05-26 Thread Peter Otten
Barry wrote:

> Here's my attempt at petching a webpage which is gzip encoded -
> 
> import urllib.request
> import gzip
> import io
> 
> request = urllib.request.Request(url='http://en.wiktionary.org/wiki/
> baby',headers={'Accept': 'text/html','User-Agent':'Mozilla/5.0
> (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1
> (KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3'} )
> response = urllib.request.urlopen(request)
> data = response.read()
> 
> compressedstream = io.StringIO(data)
> 
> gzipper = gzip.GzipFile(fileobj=compressedstream)
> data = gzipper.read()
> print(data)
> 
> 
> However it gives the error:
> 
> Traceback (most recent call last):
>   File "test.py", line 9, in 
> TypeError: initial_value must be str or None, not bytes
> 
> How should I be doing this for Python 3?

Use io.BytesIO instead of io.StringIO, as Rob Williscroft showed you 
yesterday.

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


Fastest way to apply a function to an iterable

2010-05-26 Thread Shashank Singh
What is the most efficient way of applying a function to all the elements of
an iterable while discarding the
result (i.e. operations are done only for side-effects).

For example if I want to save all elements in a list of items (and am not
interested in what save() returns), the
simplest way is:

itemlist = [i1, i2, i3]
for item in itemlist: item.save()

It might be squeezing too much but is it possible to do it more efficiently
by pushing the looping inside the C code
and achieve some gains as is done by using map in place of a for loop when
the return values need to be saved?

Any suggestions will be appreciated.

TIA

-- 
Regards
Shashank Singh
Senior Undergraduate, Department of Computer Science and Engineering
Indian Institute of Technology Bombay
[email protected]
http://www.cse.iitb.ac.in/~shashanksingh
-- 
http://mail.python.org/mailman/listinfo/python-list


Indentation

2010-05-26 Thread William Miner
I have a script which I would now put inside a loop. Is there any way to
³automatically² indent the old script so it can be put inside the new loop.
Doing it by hand seems so inelegant and time consuming.

By the way, thanks for the answer to my previous question.

Thanks!

Buff Miner
-- 
Enig Associates, Inc.
Suite 500, Bethesda Crescent Bldg.
4600 East West Hwy
Bethesda, Maryland 20814
Tel:(301)680-8600
Fax:(301)680-8100

This message is intended only for the use of the intended recipient(s), and
it may be privileged and confidential. If you are not the intended
recipient, you are hereby notified that any review, retransmission,
conversion to hard copy, copying, circulation or other use of this message
is strictly prohibited and may be illegal. If you are not the intended
recipient, please notify the sender immediately by return e-mail, and delete
this message from your system. Thank you.


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


Re: Indentation

2010-05-26 Thread Adam Tauno Williams
On Wed, 2010-05-26 at 16:13 -0400, William Miner wrote:
> I have a script which I would now put inside a loop. Is there any way
> to “automatically” indent the old script so it can be put inside the
> new loop. Doing it by hand seems so inelegant and time consuming.

Open script in MonoDevelop
Highlight text, 
right-click, 
click "Indent Selection" in context menu.

Or any decent IDE should provide the same kind of thing.



-- 
Adam Tauno Williams  LPIC-1, Novell CLA

OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Re: Error

2010-05-26 Thread Alister
On Wed, 26 May 2010 11:09:58 -0700, Chris Rebert wrote:

> On Wed, May 26, 2010 at 10:48 AM, William Miner 
> wrote:
>> I’m relative new to python and I puzzled by the following strange (to
>> me) behavior. I was taking pieces from two old scripts to build a new
>> one. When I began to debug it I got the following error message:
>>
>> Traceback (most recent call last):
>>   File
>> "/Users/williamminer/ex2gen/ex2gen-3.0.5/src/ScriptDev/
run_ex2gen_scan.py",
>> line 38, in 
>> if re.search('varm',line):
>> AttributeError: 'function' object has no attribute 'search'
>>
>> This had worked in the previous script but not the new one. I noticed
>> that the new script had an additional line at the beginning (line 3)
>>
>> #!/usr/bin/env python
>> import sys, math, os, shutil, commands, re, mpmath from mpmath import *
>>
>> When I deleted this line, the script ran. Why did the line
>>
>> from mpmath import *
>>
>> Trash the search function fro the regular expression module?
> 
> mpmath defines a function named re() which returns the real part of a
> complex number. Because you used "import *", the existing value of the
> global variable "re", which was the regular expression module, gets
> clobbered with mpmath's re() function. Thus, you get that error when you
> try to call the "search" method on what is now a function object.
> 
> This is precisely why using the `from foo import *` syntax is
> discouraged.
> 
> Cheers,
> Chris
I am fairly new to Python but had already decided to opt a style that  
would always use import XXX rather than the from XXX import * syntax.

It is nice to know that at least one of my decisions on best practice is 
good
 

as an old programmer (8 bit assembler for micro controller applications) 
picking up the baton again for fun I have to say Python is great
(I find C to be so low level I might just as well go back to assembler!).



-- 
"Linux doesn't support any sub-32-bit computers, and despite the 
occasional
 deranged people interested in retro-computing (ie Alan Cox) I doubt it
 seriously will.."

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


Re: Another Little MySQL Problem

2010-05-26 Thread Alister
On Wed, 26 May 2010 12:43:29 -0700, John Nagle wrote:

> Kushal Kumaran wrote:
>> On Tue, 2010-05-25 at 14:45 -0400, Victor Subervi wrote:
>>> Hi;
>>> I have this code:
>>>
>>> clientCursor.execute('select ID from %s' % (personalDataTable))
>>> upds = [itm[0] for itm in clientCursor] print ">> type='hidden' name='upds' value='%s' />" % upds
>>>
>>> The problem is that the values passed are 1L, 2L When I retrieve
>>> them on the other end and try to convert them to integers, guess what
>>> happens? So how do I get rid of that "L"?
> 
> What's the table definition?
> 
>   John Nagle

I think you should probably also write your execuete diferently:

>>> clientCursor.execute('select ID from %s' , (personalDataTable,))

this ensures the parameters are correctly escaped to prevent mysql 
injection attacks,the "," after personalDataTable is necessary to ensure 
the parameter is passed as a tupple

However I am fairly new so could be mistaken on exactly what your code 
does.
-- 
If you analyse anything, you destroy it.
-- Arthur Miller
-- 
http://mail.python.org/mailman/listinfo/python-list


atexit/signal for non-interactive jobs

2010-05-26 Thread kj




I want to implement clean-up functions for scripts to be run on a
Linux cluster (through LSF).  The goal is to make sure that a
minimal wrap-up sequence (print diagnostic info, flush buffers,
etc.) gets executed if the job is terminated for some reason.  (The
most common reason for premature termination is a SIGUSR2 signal,
sent to the process by LSF when the job has taken longer than the
time limit for the job's LSF queue.)

No matter what I try, I can't get this wrap-up sequence to work
when the script runs non-interactively.

The latest I have looks something like this:

import signal
import atexit

def set_handlers(handler):
atexit.register(handler)
for sig in dir(signal):
if sig.startswith('SIG') and not '_' in sig:
signal(getattr(signal, sig), handler)

def wrapup(*args):
# etc, etc

def main():
# ... 
set_handlers(wrapup)
run()

main()


If I start the script interactively and after a few seconds (i.e.
before it terminates) I hit Ctrl-C (which sends a TERM signal to
the process), the wrapup function gets called as desired (although
this action appears to be triggered by atexit, and not by the
handler for SIGTERM, which apparently never gets called).

But if instead I background the script after starting it, and then
use kill to explicitly send a TERM signal to its process, the script
terminates, but the wrapup code does not execute.

It makes no sense to me.  If someone cares to explain it, I'd be
very grateful.  (Is my code doing something wrong?)

But more to the point, what must I do to get this to work in the
non-interactive case?

TIA!

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


Using Babel: How to protect translator comments (and old translations) in GNU gettext PO files?

2010-05-26 Thread python
We're using the Python based Babel gettext utilities. Is there
any technique we can use to make sure that translator comments
and old ("obsolete") translations (marked with #~) in PO files
are preserved across PO file updates?

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


Re: Kohonen neural network

2010-05-26 Thread Lex Lebedeff
On Wed, 26 May 2010 05:26:56 -0700, alex23 wrote:

> On May 26, 7:21 pm, Lex Lebedeff  wrote:
>> Has anyone tried to build an implementation of subject in Python? Any
>> help is appreciated!
> 
> http://www.dia.fi.upm.es/~jamartin/download.htm
> 
> Seriously, though, any reason why you couldn't just type "kohonen neural
> network python" into Google? You would've found it a lot easier to wade
> through the results before your question & it's many mirrors. It
> would've been the 2nd entry, immediately after the wikipedia article on
> Kohonen SOMs.

Thanx, I've already googled this stuff. Rather unreadable and freaky code.

--- news://freenews.netfront.net/ - complaints: [email protected] ---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to apply a function to an iterable

2010-05-26 Thread Stefan Behnel

Shashank Singh, 26.05.2010 21:48:

What is the most efficient way of applying a function to all the elements of
an iterable while discarding the
result (i.e. operations are done only for side-effects).

For example if I want to save all elements in a list of items (and am not
interested in what save() returns), the
simplest way is:

itemlist = [i1, i2, i3]
for item in itemlist: item.save()

It might be squeezing too much but is it possible to do it more efficiently
by pushing the looping inside the C code
and achieve some gains as is done by using map in place of a for loop when
the return values need to be saved?


If all items have the exact same type, you can get away with an unbound method:

class MyType(object):
...
def safe(self):
...

itemlist = [ MyType() for i in range(20) ]

# this is what you want:

from itertools import imap
for _ in imap(MyType.save, itemlist): pass


But some people may consider this too ugly to actually use in real code.

Stefan

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


Re: multiprocessing and accessing server's stdout

2010-05-26 Thread Adam Tauno Williams
On Wed, 2010-05-26 at 11:47 -0700, Tim Arnold wrote:
> Hi,
> I'm using multiprocessing's BaseManager to create a server on one
> machine and a client on another. The client fires a request and the
> server does some work, the result of which ends up on a shared file
> system that both the client and server can see.
> However, I need the client machine to see the stdout of the process
> running on the server. Not sure this is doable--I've been unable to
> google anything useful on this one.

Nope, it isn't.  Don't use stdout, use an IPC mechanism to communicate
between the client and the server if you need feedback.
-- 
Adam Tauno Williams  LPIC-1, Novell CLA

OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Re: Indentation

2010-05-26 Thread Tim Chase

On 05/26/2010 03:13 PM, William Miner wrote:

I have a script which I would now put inside a loop. Is there
any way to ³automatically² indent the old script so it can be
put inside the new loop. Doing it by hand seems so inelegant
and time consuming.


It's usually a function of your editor -- most good editors allow 
you to indent/exdent a block of code.  In vim (my editor of 
choice), you can use the ">" and "<" operators with a motion or 
visual block to indent one 'shiftwidth' (which uses spaces or 
tabs based on your 'expandtab' setting, and can mix-and-match if 
your 'tabstop' isn't the same as your 'shiftwidth').


Adam already demonstrated how to do it in MonoDevelop, and I 
think in Visual Studio (a long time since I've had to touch that 
beast) you can just highlight a block and press  or 
 to indent/exdent.  Likely an emacs user will chime in 
on this thread with how to do it there too.


If you're stuck with a bogus editor but are on a *nix platform, 
you can indent with sed:


  sed 's/^//' original.py > out.py

(that's 4 spaces after the 2nd slash; adjust accordingly to your 
tastes) and then just copy the contents of out.py into your script.


If you're on Win32 without a good editor, go get a good editor ;-)

-tkc






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


Re: Inheritable Slots Metaclass

2010-05-26 Thread Carl Banks
On May 26, 5:49 am, Rebel Lion  wrote:
> I made a metaclass to inherit __slots__ automatically.
>
> I think this feature should be included in builtin object's metaclass.

I'd be ok with a metatype in the standard library that makes slots
more transparent, but since slots are intended as an optimization, it
doesn't really need (and might be detrimental to have) transparency
for ordinary objects.

However, Aahz will be by shortly to tell you never to use slots.

> You can now write:
>
>     class Foo(object):
>         __metaclass__ = SlotMetaclass
>
>         @slot
>         def foo():
>             pass
>
>     class Bar(Foo):
>
>         @slot
>         def bar():
>             pass
>
>     foo = Foo()
>     foo.foo = 1
>     bar = Bar()
>     bar.bar = 1
>     bar.foo = 1
>     try:
>         bar.baz = 1 # this should fall
>     except AttributeError, e:
>         print 'yeah', e
>
> Instead of
>
>     class Foo(object):
>           __slots__ = ['foo']
>     class Bar(Foo)
>           __slots__ = ['foo', 'bar']
>
> Please discuss the pros & cons for this feature.

It seems like a good approach, but the use of decorators to define
slots is hideous.  I'd recommend creating slots with simple assignment
instead:

slot = object()

class Foo():
__metaclass__ = SlotsMetaclass
foo = slot

class Bar():
bar = slot

Then replace

"isinstance(v,slot)" with "v is slot"

in the metaclass.



> Here is the metaclass:
>
> class slot(object):
>     """Slot Decorator"""
>
>     def __init__(self, func):
>         pass
>
> class SlotMetaclass(type):
>     """Inheritable Slots Metaclass"""
>
>     def __new__(cls, name, bases, attrs):
>         # make a normal class, and get its attributes to decide which
> ones are slots
>         tmpcls = type.__new__(cls, name, bases, attrs)
>         slots = []
>         for k in dir(tmpcls):
>             v = getattr(tmpcls, k)
>             if isinstance(v, slot):
>                 slots.append(k)
>         # clean up
>         del tmpcls
>         for x in slots:
>             del attrs[x]
>         # create the real class with __slots__
>         attrs['__slots__'] = slots
>         return type.__new__(cls, name, bases, attrs)

You don't need to create a temporary class here; you should loop
through the base classes and inspect their slots.  Also, you don't
need to recreate slots that exist in base classes, so you could just
get all the new slots from the class dict.

You should consider corner cases if you think it should be standard.
For instance, what if a derived class defined the same slot as a a
base class--it'll create a new slot in yours but it shouldn't.  What
if you want to create a subclass that does have a dict?  Can't do it
in your version.  You need to consider stuff like that.


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


Re: Fastest way to apply a function to an iterable

2010-05-26 Thread Peter Otten
Stefan Behnel wrote:

> Shashank Singh, 26.05.2010 21:48:
>> What is the most efficient way of applying a function to all the elements
>> of an iterable while discarding the
>> result (i.e. operations are done only for side-effects).
>>
>> For example if I want to save all elements in a list of items (and am not
>> interested in what save() returns), the
>> simplest way is:
>>
>> itemlist = [i1, i2, i3]
>> for item in itemlist: item.save()
>>
>> It might be squeezing too much but is it possible to do it more
>> efficiently by pushing the looping inside the C code
>> and achieve some gains as is done by using map in place of a for loop
>> when the return values need to be saved?
> 
> If all items have the exact same type, you can get away with an unbound
> method:
> 
>  class MyType(object):
>  ...
>  def safe(self):
>  ...
> 
>  itemlist = [ MyType() for i in range(20) ]
> 
>  # this is what you want:
> 
>  from itertools import imap
>  for _ in imap(MyType.save, itemlist): pass
> 
> 
> But some people may consider this too ugly to actually use in real code.
 
Which doesn't mean it can't get worse:

>>> from sys import maxint
>>> from operator import attrgetter
>>> from itertools import imap, islice
>>> class I:
... def __init__(self, i):
... self.i = i
... def save(self):
... print "saving", self.i
...
>>> items = [I(i) for i in range(5)]
>>> next(islice(imap(apply, imap(attrgetter("save"), items)), maxint, 
maxint), None)
saving 0
saving 1
saving 2
saving 3
saving 4


See also the following thread:

http://mail.python.org/pipermail/python-list/2010-January/1233307.html

Most real-world applications should spend significantly more time inside the 
save() methods than in the enclosing loop, so I'd expect the effect of this 
kind of optimization on the speed of your program to be negligable.

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


Re: Fastest way to apply a function to an iterable

2010-05-26 Thread Shashank Singh
On Thu, May 27, 2010 at 1:56 AM, Stefan Behnel  wrote:

> If all items have the exact same type, you can get away with an unbound
> method:
>
>class MyType(object):
>...
>def safe(self):
>...
>
>itemlist = [ MyType() for i in range(20) ]
>
># this is what you want:
>

   from itertools import imap
>for _ in imap(MyType.save, itemlist): pass
>

Thanks Stefan,

I probably didn't state the problem properly. I was assuming the
availability of  a static method that could be passed on to map based
solution (or imap for that matter).

The question was, if one wants to apply a function on each member of list
and discard the return value, is it possible to do it more efficiently than
having a for loop in python and applying the function of each of the
members?

Take this run:

from itertools import imap
from timeit import Timer


def save(x): 2 * x

from itertools import imap
from timeit import Timer


def save(x): 2 * x

def f1(): map(save, range(1000)) #simple map

def f2():
  for _ in imap(save, range(1000)): pass #imap

def f3():
  for x in range(1000):save(x) #simple iteration

t1 = Timer("f1()", "from __main__ import f1")
print "f1", t1.timeit(number=1000)

t2 = Timer("f2()", "from __main__ import f2")
print "f2", t2.timeit(number=1000)

t3 = Timer("f3()", "from __main__ import f3")
print "f3", t3.timeit(number=1000)

The output for one run was:

f1 0.393015034034
f2 0.476230638252
f3 0.376324923978

=> simple for loop performs better than map/imap. Another problem with
map/imap is that the memory cost is dependent on the length of the list
(because of the intermediate mapped list stored) which is not the case for
simple for loop.

I hope I have explained it better this time.

-- 
Regards
Shashank Singh
Senior Undergraduate, Department of Computer Science and Engineering
Indian Institute of Technology Bombay
[email protected]
http://www.cse.iitb.ac.in/~shashanksingh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest way to apply a function to an iterable

2010-05-26 Thread Stefan Behnel

Shashank Singh, 26.05.2010 23:16:
> I probably didn't state the problem properly. I was assuming the
> availability of  a static method that could be passed on to map based
> solution (or imap for that matter).
>
> The question was, if one wants to apply a function on each member of list
> and discard the return value, is it possible to do it more efficiently than
> having a for loop in python and applying the function of each of the
> members?
>
> Take this run:
>
> from itertools import imap
> from timeit import Timer
>
>
> def save(x): 2 * x
>
> from itertools import imap
> from timeit import Timer
>
>
> def save(x): 2 * x
>
> def f1(): map(save, range(1000)) #simple map
>
> def f2():
>for _ in imap(save, range(1000)): pass #imap
>
> def f3():
>for x in range(1000):save(x) #simple iteration
>
> t1 = Timer("f1()", "from __main__ import f1")
> print "f1", t1.timeit(number=1000)
>
> t2 = Timer("f2()", "from __main__ import f2")
> print "f2", t2.timeit(number=1000)
>
> t3 = Timer("f3()", "from __main__ import f3")
> print "f3", t3.timeit(number=1000)
>
> The output for one run was:
>
> f1 0.393015034034
> f2 0.476230638252
> f3 0.376324923978
>
> =>  simple for loop performs better than map/imap.

Interesting. So you've found the fastest solution already. If a simple for 
loop is both the most readable and the fastest way to do it, it sounds to 
me like you have solved your problem yourself.



> Another problem with
> map/imap is that the memory cost is dependent on the length of the list
> (because of the intermediate mapped list stored) which is not the case for
> simple for loop.

... neither is it the case for the imap() solution - but that still proves 
to be slower in your timings.


BTW, assuming that you are using Python 2, you'd better use xrange() in 
benchmarks. The list creation of range() can easily spoil your timings.


Stefan

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


Re: Inheritable Slots Metaclass

2010-05-26 Thread geremy condra
On Wed, May 26, 2010 at 1:50 PM, Carl Banks  wrote:
> On May 26, 5:49 am, Rebel Lion  wrote:
>> I made a metaclass to inherit __slots__ automatically.
>>
>> I think this feature should be included in builtin object's metaclass.
>
> I'd be ok with a metatype in the standard library that makes slots
> more transparent, but since slots are intended as an optimization, it
> doesn't really need (and might be detrimental to have) transparency
> for ordinary objects.
>
> However, Aahz will be by shortly to tell you never to use slots.

Ok, I'll bite: why?

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


Re: Another Little MySQL Problem

2010-05-26 Thread John Nagle

Alister wrote:

I think you should probably also write your execute differently:


clientCursor.execute('select ID from %s' , (personalDataTable,))


this ensures the parameters are correctly escaped to prevent mysql 
injection attacks,the "," after personalDataTable is necessary to ensure 
the parameter is passed as a tuple


   Actually, no.  The names of tables are not quoted in SQL.
One writes

SELECT ID FROM mytable;

not

SELECT ID FROM "mytable";

so you don't want to run table names through the quoting and escaping function.
If the table name is a variable, you need to be very careful about where it
comes from.

On the other hand, if you're specifying a data value, a field that's normally
quoted, as in

SELECT ID from mytable WHERE mykey="foo";

you write

cursor.execute("SELECT ID FROM mytable WHERE mykey=%s", (mykeyval,))

to get proper escaping.  Don't put quote marks around the %s; MySQLdb does that.

   Also, if you're selecting every entry in a database, without a
WHERE or ORDER BY clause, you will get the entries in more or less random
order.

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


Re: Another Little MySQL Problem

2010-05-26 Thread Christian Heimes

 Actually, no.  The names of tables are not quoted in SQL.
One writes

SELECT ID FROM mytable;

not

SELECT ID FROM "mytable";


nit picking mode:

Some RDBMS support case sensitive table names. You have to quote the 
table name if you using the feature. Yeah I know, it's pretty bad idea 
but it's possible.


Christian

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


Re: atexit/signal for non-interactive jobs

2010-05-26 Thread Cameron Simpson
On 26May2010 20:19, kj  wrote:
| If I start the script interactively and after a few seconds (i.e.
| before it terminates) I hit Ctrl-C (which sends a TERM signal to
| the process), the wrapup function gets called as desired (although
| this action appears to be triggered by atexit, and not by the
| handler for SIGTERM, which apparently never gets called).

I hate to tell you this, but ^C sends SIGINT, not SIGTERM.
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

To have no errors
Would be life without meaning
No struggle, no joy
- Haiku Error Messages 
http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheritable Slots Metaclass

2010-05-26 Thread Carl Banks
On May 26, 2:51 pm, geremy condra  wrote:
> On Wed, May 26, 2010 at 1:50 PM, Carl Banks  wrote:
> > On May 26, 5:49 am, Rebel Lion  wrote:
> >> I made a metaclass to inherit __slots__ automatically.
>
> >> I think this feature should be included in builtin object's metaclass.
>
> > I'd be ok with a metatype in the standard library that makes slots
> > more transparent, but since slots are intended as an optimization, it
> > doesn't really need (and might be detrimental to have) transparency
> > for ordinary objects.
>
> > However, Aahz will be by shortly to tell you never to use slots.
>
> Ok, I'll bite: why?

I was just razzing him a bit.


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


confusing error with nntplib

2010-05-26 Thread Eduardo Alvarez
When trying to use nntplib to connect to the news server nntp.aioe.org,
a bizarre sequence of events occurs:

1) I import the module, and create an instance, as follows:

s = nntplib.NNTP('nntp.aioe.org')

I get no errors, which leads me to believe all went well. The I try
fetching info on a newsgroup (in this case, comp.lang.python):

s.group('comp.lang.python')

I then get the following error:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/nntplib.py", line 345, in group
resp = self.shortcmd('GROUP ' + name)
  File "/usr/lib/python2.6/nntplib.py", line 259, in shortcmd
return self.getresp()
  File "/usr/lib/python2.6/nntplib.py", line 214, in getresp
resp = self.getline()
  File "/usr/lib/python2.6/nntplib.py", line 206, in getline
if not line: raise EOFError
EOFError

Running this a *second* time, gives me the following, different error:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/nntplib.py", line 345, in group
resp = self.shortcmd('GROUP ' + name)
  File "/usr/lib/python2.6/nntplib.py", line 258, in shortcmd
self.putcmd(line)
  File "/usr/lib/python2.6/nntplib.py", line 198, in putcmd
self.putline(line)
  File "/usr/lib/python2.6/nntplib.py", line 193, in putline
self.sock.sendall(line)
  File "", line 1, in sendall
socket.error: [Errno 32] Broken pipe

As this is a broken pipe, I reconnect to the server, the same way as
before. When I *then* retrieving the newsgroup's info, I get no errors.

I'm pretty baffled by this. It might be an issue with the server itself,
but still, any input would be very appreciated.

yours,

-- 
Eduardo Alvarez

"Stercus, Stercus, Stercus, moriturus sum"
  -- Rincewind The Wizzard
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheritable Slots Metaclass

2010-05-26 Thread Rebel Lion

> I'd be ok with a metatype in the standard library that makes slots
> more transparent, but since slots are intended as an optimization, it
> doesn't really need (and might be detrimental to have) transparency
> for ordinary objects.
>

But why there is __slots__ if it's not indeed needed. we should make
it more usable instead of a hack, which it now looks like.

> However, Aahz will be by shortly to tell you never to use slots.

Obviously he didn't work on graphs, at least huge graphs.

> It seems like a good approach, but the use of decorators to define
> slots is hideous.  I'd recommend creating slots with simple assignment
> instead:
>
> slot = object()
>
> class Foo():
>     __metaclass__ = SlotsMetaclass
>     foo = slot
>
> class Bar():
>     bar = slot
>
> Then replace
>
> "isinstance(v,slot)" with "v is slot"
>
> in the metaclass.
>

This is a style not a problem. My way intents to keep the consistency
with @property

> You don't need to create a temporary class here; you should loop
> through the base classes and inspect their slots.  

As you can see, I'm very lazy. If we got some decision here, we can
surely make a better implementation that this hack.

> Also, you don't
> need to recreate slots that exist in base classes, so you could just
> get all the new slots from the class dict.
>
> You should consider corner cases if you think it should be standard.
> For instance, what if a derived class defined the same slot as a a
> base class--it'll create a new slot in yours but it shouldn't.  What
> if you want to create a subclass that does have a dict?  Can't do it
> in your version.  You need to consider stuff like that.
>

The most arguable point here. I raise this post inorder to make slot
inheritable.
In most cases, if a class uses slots, it is designed to be heavily
used.
Ans subclass of it should be heavily used too, but in this case you
want to create __slots__,
you have to manually lookup __slots__ of bases.

But your corner is considerable. We can offer a __no_slots__ to
disable slots.

In conclusion, my point is:

If you don't want to use slots in common days, you can subclass a
class which doesn't use slots(in most cases)
If you want to use slots, you need inherit parent classes' slots(in a
few cases)
If you don't want to use slots when you are subclassing a class which
uses slots(in few cases):
  use a __noslots__ magic



Regards,

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


Re: Inheritable Slots Metaclass

2010-05-26 Thread John Nagle

Rebel Lion wrote:

I'd be ok with a metatype in the standard library that makes slots
more transparent, but since slots are intended as an optimization, it
doesn't really need (and might be detrimental to have) transparency
for ordinary objects.



But why there is __slots__ if it's not indeed needed. we should make
it more usable instead of a hack, which it now looks like.


However, Aahz will be by shortly to tell you never to use slots.


I'd argue that "slotting" of classes should be automatic, unless a class
1) defines "__setattr__" or 2) performs an operation which visibly
creates a class attribute, like "self[foo] = ...".  This would handle
the common use cases.  Only classes to which attributes are added from
outside the class would be affected.  And really, if you're going to do
that, you should subclass.

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


Re: Another Little MySQL Problem

2010-05-26 Thread Alister
On Wed, 26 May 2010 15:30:16 -0700, John Nagle wrote:

> Alister wrote:
>> I think you should probably also write your execute differently:
>> 
> clientCursor.execute('select ID from %s' , (personalDataTable,))
>> 
>> this ensures the parameters are correctly escaped to prevent mysql
>> injection attacks,the "," after personalDataTable is necessary to
>> ensure the parameter is passed as a tuple
> 
> Actually, no.  The names of tables are not quoted in SQL.
> One writes
> 
>   SELECT ID FROM mytable;
> 
> not
> 
>   SELECT ID FROM "mytable";
> 
> so you don't want to run table names through the quoting and escaping
> function. If the table name is a variable, you need to be very careful
> about where it comes from.
> 
> On the other hand, if you're specifying a data value, a field that's
> normally quoted, as in
> 
>   SELECT ID from mytable WHERE mykey="foo";
> 
> you write
> 
>   cursor.execute("SELECT ID FROM mytable WHERE mykey=%s", 
(mykeyval,))
> 
> to get proper escaping.  Don't put quote marks around the %s; MySQLdb
> does that.
> 
> Also, if you're selecting every entry in a database, without a
> WHERE or ORDER BY clause, you will get the entries in more or less
> random order.
> 
>   John Nagle

Thanks i hadn't read the search string fully.
in this case if personalDataTable is generated by user input it should be 
carefully checked as it will still be a possible source of attack.

The golden rule with user input is trust nothing.
 



-- 
QOTD:
"I won't say he's untruthful, but his wife has to call the
dog for dinner."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheritable Slots Metaclass

2010-05-26 Thread Carl Banks
On May 26, 8:33 pm, Rebel Lion  wrote:
> > I'd be ok with a metatype in the standard library that makes slots
> > more transparent, but since slots are intended as an optimization, it
> > doesn't really need (and might be detrimental to have) transparency
> > for ordinary objects.
>
> But why there is __slots__ if it's not indeed needed. we should make
> it more usable instead of a hack, which it now looks like.

It is needed--for optimization.  The thinking is that for most uses it
is not a good idea to defeat Python's dynamicsm, therefore making it
too easy to add slots would be detrimental to the community because it
would encourage people to use slots even when not needed.

I more or less agree with this, and would be very -1 on any attempt to
mske slots the "default", so to speak; however I don't think it would
make slots dangerously accessible to have a user import a module and
explicitly set the metaclass, for the benefit of getting rid of their
weirdness.


> > However, Aahz will be by shortly to tell you never to use slots.
>
> Obviously he didn't work on graphs, at least huge graphs.

There's no need to be presumptuous.  You can state your use case with
accusing him of anything.


> > It seems like a good approach, but the use of decorators to define
> > slots is hideous.  I'd recommend creating slots with simple assignment
> > instead:
>
> > slot = object()
>
> > class Foo():
> >     __metaclass__ = SlotsMetaclass
> >     foo = slot
>
> > class Bar():
> >     bar = slot
>
> > Then replace
>
> > "isinstance(v,slot)" with "v is slot"
>
> > in the metaclass.
>
> This is a style not a problem. My way intents to keep the consistency
> with @property

It's a problem if you think this metaclass ought to be in the standard
library.  This "style" will never, ever make it to the standard
library, ever.  I guarantee you.

Frankly, you're observing a pattern where there is none.  You see
decorator syntax and you think "Ah, that's the standard way to define
attributes that affect the behavior of a class".  It's not.

Descriptor syntax is syntax sugar to make it less unwieldy to apply a
function to a function or class.  That's it, that's all it is.  If you
don't have a function, there is no reason for a decorator.

You're entitled to your own preferred style, of course, but I'm just
telling you it'll never fly with most people.


> > You don't need to create a temporary class here; you should loop
> > through the base classes and inspect their slots.  
>
> As you can see, I'm very lazy. If we got some decision here, we can
> surely make a better implementation that this hack.

No, sorry, it doesn't work that way.  Unless you're a known genius and/
or a long time contributor, you better have some pretty worked out
code and some persuasive use cases if you want any consideration.
Ideas are cheap.

(If you want some inspiration, go read PEP 389.)


> > Also, you don't
> > need to recreate slots that exist in base classes, so you could just
> > get all the new slots from the class dict.
>
> > You should consider corner cases if you think it should be standard.
> > For instance, what if a derived class defined the same slot as a a
> > base class--it'll create a new slot in yours but it shouldn't.  What
> > if you want to create a subclass that does have a dict?  Can't do it
> > in your version.  You need to consider stuff like that.
>
> The most arguable point here. I raise this post inorder to make slot
> inheritable.

Slots already are inheritable, as I pointed out.  It's just weird and
complicated how they affect things.

class A(object): __slots__ = ['a']
class B(A): __slots__ = ['b']
B().a = 1  # this will work


> In most cases, if a class uses slots, it is designed to be heavily
> used.
> Ans subclass of it should be heavily used too, but in this case you
> want to create __slots__,
> you have to manually lookup __slots__ of bases.

You don't have to, unless you want to work around some of those other
corner cases I spoke of.


> But your corner is considerable. We can offer a __no_slots__ to
> disable slots.
>
> In conclusion, my point is:
>
> If you don't want to use slots in common days, you can subclass a
> class which doesn't use slots(in most cases)
> If you want to use slots, you need inherit parent classes' slots(in a
> few cases)
> If you don't want to use slots when you are subclassing a class which
> uses slots(in few cases):
>   use a __noslots__ magic

That seems like a reasonable way to handle it.

I don't want to sound to pessimistic about it, I really wouldn't mind
a metaclass that makes slots more normal; but you have work to do.


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


Re: UnicodeDecodeError having fetch web page

2010-05-26 Thread Kushal Kumaran
On Wed, May 26, 2010 at 11:40 PM, Rob Williscroft  wrote:
> Kushal Kumaran wrote in news:1274889564.2339.16.ca...@nitrogen in
> gmane.comp.python.general:
>
>> On Tue, 2010-05-25 at 20:12 +, Rob Williscroft wrote:
>>> Barry wrote in news:83dc485a-5a20-403b-99ee-c8c627bdbab3
>>> @m21g2000vbr.googlegroups.com in gmane.comp.python.general:
>>>
>>> > Hi,
>>> >
>>> > The code below is giving me the error:
>>> >
>>> > Traceback (most recent call last):
>>> >   File "C:\Users\Administratör\Desktop\test.py", line 4, in
>>> >   
>>> > UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position
>>> > 1: unexpected code byte
>>> >
>>> >
>>> > What am i doing wrong?
>>>
>>> It may not be you, en.wiktionary.org is sending gzip
>>> encoded content back, it seems to do this even if you set
>>> the Accept header as in:
>>>
>>> request.add_header( "Accept", "text/html" )
>>>
>>> But maybe I'm not doing it correctly.
>>>
>> You need the Accept-Encoding: identity header.
>> http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html
>
> Thanks, following this I did change the line to be:
>
> request.add_header( "Accept-Encoding", "identity" )
>
> but it made no difference to en.wiktionary.org it just sent the
> back a gzip encoded response.
>

A known problem, I guess... https://bugzilla.wikimedia.org/show_bug.cgi?id=7098

You'll just have to handle the gzipped data.

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheritable Slots Metaclass

2010-05-26 Thread Carl Banks
On May 26, 9:55 pm, Carl Banks  wrote:
> I don't want to sound to pessimistic about it, I really wouldn't mind
> a metaclass that makes slots more normal; but you have work to do.


Just as a minor followup, I'll mention that slots and inheritance have
some issues that aren't going to be resolvable to everyone's
satisfaction, and that's another reason why I don't think slots should
be accessible by default.

For instance, some might assume that deriving from a class with slots
automatically grants the derived class the same optimization that the
base class has.  Others will not even consider that the base class has
slots and will assume that their derived class has dynamic attributes
like most other Python classes.  Who's right?

I'd go with the former, for the same reason you gave, but the latter
is not unreasonable.  type does the latter.

The best answer might be to always insist on an explicit declaration
one way or another, but that makes it prone to other problems like
forward compatibility issues.  Point is, it's not a simple thing.


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


Re: Kohonen neural network

2010-05-26 Thread alex23
Lex Lebedeff  wrote:
> Thanx, I've already googled this stuff. Rather unreadable and freaky code.

Then please remember to mention what you've already seen & tried when
asking in the future, it saves us all from wasting each others time.
-- 
http://mail.python.org/mailman/listinfo/python-list


"AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 - 2011" on http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html "SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PA

2010-05-26 Thread Naeem
"AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 - 2011"
on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scholarships-education.blogspot.com/2010/05/australian-leadership-awards.html
"SCHOLARSHIPS IN AUSTRALIA, UK, CANADA, PAKISTAN, AMERICA, EUROPEAN
UNION""AUSTRALIAN LEADERSHIP AWARDS SCHOLARSHIPS FOR THE YEAR 2010 -
2011"  on  
http://scho