Re: linux

2012-05-02 Thread Chris Angelico
On Wed, May 2, 2012 at 4:25 PM, Debashish Saha  wrote:
> can anyone say me how to subscribe linux mailing list like 'python
> mailing list'. Actually i want to post question there.

Search the web, you'll find something.

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


Re: linux

2012-05-02 Thread Temia Eszteri
>can anyone say me how to subscribe linux mailing list like 'python
>mailing list'. Actually i want to post question there.

It'd probably be best to visit the mailing list (if any) for the
distribution that you're using in particular. Odds are any such
mailing list would be available on the distro's site.

~Temia
--
When on earth, do as the earthlings do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread Paul Rubin
"Russ P."  writes:
> The SVD can be thought of as factoring any linear transformation into
> a rotation, then a scaling, followed by another rotation. 

Ah yes, my description was backwards, sorry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread Paul Rubin
someone  writes:
>> You will probably get better advice if you are able to describe what
>> problem (ill-posed or otherwise) you are actually trying to solve.  SVD
> I don't understand what else I should write. I gave the singular
> matrix and that's it. Nothing more is to say about this problem,

You could write what your application is.  What do the numbers in that
matrix actually represent?  

> except it would be nice to learn some things for future use (for
> instance understanding SVD more 

The Wikipedia article about SVD is pretty good.  

> Still, I dont think I completely understand SVD. SVD (at least in
> Matlab) returns 3 matrices, one is a diagonal matrix I think. 

Yes.  Two diagonal matrices and a unitary matrix.  The diagonal matrices
have the singular values which are the magnitudes of the matrix's
eigenvalues.  A matrix (for simplicity consider it to have nonzero
determinant) represents a linear transformation in space.  Think of a
bunch of vectors as arrows sticking out of the origin in different
directions, and consider what happens to them if you use the matrix to
act on all of them at once.  You could break the transformation into 3
steps: 1) scale the axes by suitable amounts, so all the vectors stretch
or shrink depending on their directions.  2) Rotate all the vectors
without changing their lengths, through some combination of angles; 3)
undo the scaling transformation so that the vectors get their original
lengths back.  Each of these 3 steps can be described by a matrix and
the 3 matrices are what SVD calculates.

I still don't have any idea whether this info is going to do you any
good.  There are some quite knowledgeable numerics folks here (I'm not
one) who can probably be of more help, but frankly your questions don't
make a whole lot of sense.  

You might get the book "Numerical Recipes" which is old but instructive.
Maybe someone else here has other recommendations.
-- 
http://mail.python.org/mailman/listinfo/python-list


How would I go about building an API converter?

2012-05-02 Thread Alec Taylor
I have multiple different APIs with different schemas serialised in XML or
JSON which I need to output as a standardised schema.

Main features needed:

   - *Serialisation to XML and JSON*
   - *Authentication*
  - I.e.: can't get/set data unless you have the correct user+pass
   - *Role/Scope limitation*
  - I.e.: you can't access everything in our database, only what your
  role allows for
   - *Get/set (conversion) between different schemas*
  - I.e.: No matter the input API, you can get it formatted in
  whichever output API you request

Is this the sort of problem Slumber  with
TastyPiewould be best for?

Or are there a different libraries you'd recommend?

Thanks for all suggestions,

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


The amazing disappearing stderr

2012-05-02 Thread Peter Faulks

G'day All,


Following on from my earlier query on overloading print()

I've come up with this:


/* < stdcallbk.pyd > */

/*---stdcallbk.h-*/
#ifndef STDCALLBK_MODULE_H
#include 
#define STDCALLBK_MODULE_H


// Type definition for the callback function.
typedef void __stdcall(CALLBK_FUNC_T)(const char* p);


#ifdef __cplusplus
extern "C" {
#endif
  void register_callback(CALLBK_FUNC_T* callback);
  void import_stdcallbk(void);
#ifdef __cplusplus
}
#endif


#endif/* #define STDCALLBK_MODULE_H */


/*---stdcallbk.c-*/
#include "stdcallbk_module.h"

static CALLBK_FUNC_T *callback_write_func = NULL;
static FILE *fp;/*for debugging*/
static PyObject* g_stdout;

typedef struct
{
PyObject_HEAD
CALLBK_FUNC_T *write;
} Stdout;


static PyObject* write2(PyObject* self, PyObject* args)
{
const char* p;

if (!PyArg_ParseTuple(args, "s", &p))
return NULL;

fputs(p, fp);fflush(fp);
if(callback_write_func)
callback_write_func(p);
else
printf("%s", p);

return PyLong_FromLong(strlen(p));
}

static PyObject* flush2(PyObject* self, PyObject* args)
{
// no-op
return Py_BuildValue("");
}


static PyMethodDef Stdout_methods[] =
{
{"write", write2, METH_VARARGS, "sys-stdout-write"},
{"flush", flush2, METH_VARARGS, "sys-stdout-write"},
{NULL, NULL, 0, NULL}
};



static PyTypeObject StdoutType =
{
PyVarObject_HEAD_INIT(0, 0)
"stdcallbk.StdoutType", /* tp_name */
sizeof(Stdout), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"stdcallbk.Stdout objects", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
Stdout_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};


static struct PyModuleDef stdcallbkmodule = {
PyModuleDef_HEAD_INIT,
"stdcallbk",   /* name of module */
NULL, /* module documentation, may be NULL */
-1,   /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
NULL,
NULL,
NULL,
NULL,
NULL
};


PyMODINIT_FUNC PyInit_stdcallbk(void)
{
PyObject* m;

fp = fopen("debuggered.txt", "wt");
fputs("got to here Vers 12\n", fp);  fflush(fp);

StdoutType.tp_new = PyType_GenericNew;
if (PyType_Ready(&StdoutType) < 0)
return 0;

m = PyModule_Create(&stdcallbkmodule);
if (m)
{
Py_INCREF(&StdoutType);
PyModule_AddObject(m, "Stdout", (PyObject*) &StdoutType);
fputs("PyModule_AddObject() Called\n", fp); fflush(fp);
}
g_stdout = StdoutType.tp_new(&StdoutType, 0, 0);

/*PySys_SetObject("stdout", g_stdout)*/
fprintf(fp, "PySys_SetObject(stdout) returned %d\n", 
PySys_SetObject("stdout", g_stdout));

fflush(fp);

/*PySys_SetObject("stderr", g_stdout)*/
fprintf(fp, "PySys_SetObject(stderr) returned %d\n", 
PySys_SetObject("stderr", g_stdout));

fflush(fp);

return m;
}




/* called by cpp exe _after_ Py_Initialize(); */
void __declspec(dllexport) import_stdcallbk(void)
{
PyImport_ImportModule("stdcallbk");
}



/* called by cpp exe _before_ Py_Initialize(); */
void __declspec(dllexport) register_callback(CALLBK_FUNC_T* callback)
{
PyImport_AppendInittab("stdcallbk", &PyInit_stdcallbk);
callback_write_func = callback;
}

/* < /stdcallbk.pyd > */




/*- Embarcadero C++ Builder exe -*/
#include "/py_module/stdcallbk_module.h"



void __stdcall callback_write_func(const char* p)
{
ShowMessage(p);
}
//---
void __fastcall TForm1::Button1Click(TObject *Sender)
{
PyObject *pName, *pModule;

register_callback(callback_write_func);

Py_Initialize();
import_stdcallbk();
//PyRun_SimpleString("import stdcallbk\n");

pName = PyUnicode_FromString("hello_emb.py");
pModule = PyImport_Import(pName);
Py_Finalize();

}
//---



-- python script - hello_emb.py 
#import stdcallbk

print("HELLO FRED !")


assert 1==2






When run from the cpp exe, I get a messagebox "HE

reading data file into a list

2012-05-02 Thread ArifulHossain tuhin
I have this data file which contains raw data in newline terminated for like 
below: 

10.6626
11.2683
11.9244
12.5758
14.1402
15.1636

Now i want to read that file and import this data into a numpy array. how 
should i go about it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading data file into a list

2012-05-02 Thread Peter Otten
ArifulHossain tuhin wrote:

> I have this data file which contains raw data in newline terminated for
> like below:
> 
> 10.6626
> 11.2683
> 11.9244
> 12.5758
> 14.1402
> 15.1636
> 
> Now i want to read that file and import this data into a numpy array. how
> should i go about it?

myarray = numpy.loadtxt(filename)

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


Re: syntax for code blocks

2012-05-02 Thread Kiuhnm

On 5/2/2012 4:43, alex23 wrote:

[Apologies in advance if this comes through twice]

On May 2, 12:18 am, Kiuhnm  wrote:

"Most Pythonic" doesn't mean better, unfortunately.


Nor does it mean "Kiuhnm prefers it".


That goes without saying.


For instance, assume that you want to write a function that accepts a
dictionary of callbacks:
func(some_args, callbacks)

Pythonic way


def when_odd(n):
  pass

def when_prime(n):
  pass

def before_check():
  pass

def after_check():
  pass

func(some_args, {'when_odd' : when_odd,
   'when_prime' : when_prime,
   'before_check' : before_check,
   'after_check' : after_check})


When would you _ever_ define a function like this? Why are you passing
in _named_ callbacks? Are you calling them by name? Then declare them
in the function signature and rely on scoping. Does func() branch on
existent keys? Then don't write code like that.

At the very _least_, you could change the function call to:

 func(some_args, locals())


I think that's very bad. It wouldn't be safe either. What about name 
clashing and how would you pass only some selected functions?

A second call would also need some cleaning up leading to some serious bugs.


But as you're _passing them in by name_ why not just make it
func(some_args) and pick them up out of the scope.


Because that's not clean and maintainable. It's not different from using 
global variables.



_No one_ writes Python code like this. Presenting bad code as
"pythonic" is a bit of a straw man.


How can I present good code where there's no good way of doing that 
without my module or something equivalent?

That was my point.


My way
--

with func(some_args)<<  ':dict':
  with when_odd as 'n':
  pass
  with when_prime as 'n':
  pass
  with before_check as '':
  pass
  with after_check as '':
  pass


This is unintuitive, to say the least. You're effectively replacing
the common form of function definition with "with when_odd as 'n'",
then using the surrounding context manager to limit the scope.


What's so unintuitive about it? It's just "different".


More importantly, _you're naming your "anonymous" code blocks_, I'm
guessing so that func() can choose which ones to use. But if you're
naming them, why not just use a function?


I'm creating a dictionary, not naming my blocks just for the sake of it.
If you use a function, you end up with the solution that you called 
'bad' and non-pythonic.



I'm not entirely sure what your 'solution' offers over something like:

class FOO(object):
 def __init__(self, fn):
 self.fn = fn

 def __enter__(self):
 return self.fn

 def __exit__(self, exc_type, exc_value, traceback):
 pass

def func(x, before_check=None, after_check=None, when_odd=None,
when_prime=None):
 pass

with FOO(func) as f:
 def before_check(x):
 pass
 def after_check(x):
 pass
 def when_odd(x):
 pass
 def when_prime(x):
 pass

 f(1)


The problem is always the same. Those functions are defined at the 
module level so name clashing and many other problems are possible.


I remember a post on this ng when one would create a list of commands 
and then use that list as a switch table. My module let you do that very 
easily. The syntax is:


with func() << ':list':
with 'arg':
cmd_code
with 'arg':
cmd_code
with '':
cmd_code

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


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Miguel Guedes

On 27/04/12 03:11, Xah Lee wrote:

John Carmack glorifying functional programing in 3k words

http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/

where was he ten years ago?

O, and btw, i heard that Common Lispers don't do functional
programing, is that right?

Fuck Common Lispers. Yeah, fuck them. One bunch of Fuckfaces. (and
Fuck Pythoners. Python fucking idiots.)

O, don't forget,

〈Programing: What are OOP's Jargons and Complexities (Object Oriented
Program as Functional Program)〉
http://xahlee.org/Periodic_dosage_dir/t2/oop.html

please you peruse of it.


I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or 
personally affected by your retarded and offensive comment. However, who 
the fuck do you think you are to post stuff of this nature? (I believe) 
I'll understand if you've got some sort of psychological issue affecting 
your behaviour.

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


Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread Kiuhnm

On 5/2/2012 8:00, someone wrote:

Still, I dont think I completely understand SVD. SVD (at least in
Matlab) returns 3 matrices, one is a diagonal matrix I think. I think I
would better understand it with geometric examples, if one would be so
kind to maybe write something about that... I can plot 3D vectors in
matlab, very easily so maybe I better understand SVD if I hear/read the
geometric explanation (references to textbook/similar is also appreciated).


Russ's post is a very good starting point. I hope you read it.

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


How can I read streaming output of a subprocess

2012-05-02 Thread Damjan Georgievski
I want to read the stream of an external process that I start with 
Python. From what I've seen that's not possible with the subprocess module?


I want to read the output of "ip monitor neigh" which will show changes 
in the ARP table on my Linux computer. Each change is a new line printed 
by "ip" and the process continues to run forever.




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


Re: reading data file into a list

2012-05-02 Thread Kiuhnm

On 5/2/2012 11:59, ArifulHossain tuhin wrote:

I have this data file which contains raw data in newline terminated for like 
below:

10.6626
11.2683
11.9244
12.5758
14.1402
15.1636

Now i want to read that file and import this data into a numpy array. how 
should i go about it?


http://docs.scipy.org/doc/numpy/reference/routines.io.html

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


Re: syntax for code blocks

2012-05-02 Thread Mark Lawrence

On 02/05/2012 11:52, Kiuhnm wrote:

I remember a post on this ng when one would create a list of commands
and then use that list as a switch table. My module let you do that very
easily.

Kiuhnm


I'll believe that when I see a reference to your code repository and the 
working example that others have already asked you to provide.


--
Cheers.

Mark Lawrence.

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


Re: How can I read streaming output of a subprocess

2012-05-02 Thread Kushal Kumaran
On Wed, May 2, 2012 at 4:38 PM, Damjan Georgievski  wrote:
> I want to read the stream of an external process that I start with Python.
> From what I've seen that's not possible with the subprocess module?
>
> I want to read the output of "ip monitor neigh" which will show changes in
> the ARP table on my Linux computer. Each change is a new line printed by
> "ip" and the process continues to run forever.
>

You can use subprocess for this.  If you don't call wait() or
communicate() on the Popen object, the process will happily continue
running.  You can call readline on the stdout pipe, which will block
until the command you are running outputs (and flushes) a line.

Something like this should work:

p = subprocess.Popen(['ip', 'monitor', 'neigh'], stdout=subprocess.PIPE)
first_line = p.stdout.readline()

Buffering done by "ip" can ruin your day.  It seems reasonable to
expect, though, that something that is printing state changes on
stdout will be careful to flush its output when appropriate.

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


Re: reading data file into a list

2012-05-02 Thread Steven D'Aprano
On Wed, 02 May 2012 02:59:55 -0700, ArifulHossain tuhin wrote:

> I have this data file which contains raw data in newline terminated for
> like below:
> 
> 10.6626
> 11.2683
> 11.9244
> 12.5758
> 14.1402
> 15.1636
> 
> Now i want to read that file and import this data into a numpy array.
> how should i go about it?

That depends. How big is the file? Could it include extraneous whitespace 
and possibly even comments? How do you expect to deal with bad data? What 
version of Python are you using? Who will be maintaining this, a Python 
expert or somebody who doesn't know Python very well?

Here's one way (untested but should work):


import numpy
f = open("my data file.txt", "r")
contents = numpy.array([float(line) for line in f])
f.close()


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


Re: How can I read streaming output of a subprocess

2012-05-02 Thread Kiuhnm
On 5/2/2012 13:08, Damjan Georgievski wrote:
> I want to read the stream of an external process that I start with 
> Python. From what I've seen that's not possible with the subprocess module?

Try with
cmd = 'your command here'
stdout = Popen(cmd, shell = True, stdout = PIPE, stderr = STDOUT).stdout
print(stdout.read())
just to see if it works.
You can also use
for line in stdout:
print(line)
or similar.

Then you should add some error checking, etc...

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


Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread Steven D'Aprano
On Wed, 02 May 2012 08:00:44 +0200, someone wrote:

> On 05/02/2012 01:05 AM, Paul Rubin wrote:
>> someone  writes:
>>> Actually I know some... I just didn't think so much about, before
>>> writing the question this as I should, I know theres also something
>>> like singular value decomposition that I think can help solve
>>> otherwise illposed problems,
>>
>> You will probably get better advice if you are able to describe what
>> problem (ill-posed or otherwise) you are actually trying to solve.  SVD
> 
> I don't understand what else I should write. I gave the singular matrix
> and that's it.

You can't judge what an acceptable condition number is unless you know 
what your data is.

http://mathworld.wolfram.com/ConditionNumber.html
http://en.wikipedia.org/wiki/Condition_number

If your condition number is ten, then you should expect to lose one digit 
of accuracy in your solution, over and above whatever loss of accuracy 
comes from the numeric algorithm. A condition number of 64 will lose six 
bits, or about 1.8 decimal digits, of accuracy.

If your data starts off with only 1 or 2 digits of accuracy, as in your 
example, then the result is meaningless -- the accuracy will be 2-2 
digits, or 0 -- *no* digits in the answer can be trusted to be accurate.



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


Code help for understand

2012-05-02 Thread viral shah
Hi

in every .py file I found this same code line on the below side

*def main():
application = webapp.WSGIApplication([('/', MainHandler)],
 debug=True)
run_wsgi_app(application)


if __name__ == '__main__':
main()
*
can anyone explain me what's the all this thing suggest?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code help for understand

2012-05-02 Thread J. Mwebaze
if you are referring to the line
*
*
*if __name__ == '__main__':*
*
*
Find a good explanation here
*
*
http://stackoverflow.com/questions/419163/what-does-if-name-main-do



On Wed, May 2, 2012 at 2:30 PM, viral shah  wrote:

> Hi
>
> in every .py file I found this same code line on the below side
>
> *def main():
> application = webapp.WSGIApplication([('/', MainHandler)],
>  debug=True)
> run_wsgi_app(application)
>
>
> if __name__ == '__main__':
> main()
> *
> can anyone explain me what's the all this thing suggest?
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I read streaming output of a subprocess

2012-05-02 Thread Adam Skutt
On May 2, 7:46 am, Kiuhnm  wrote:
> On 5/2/2012 13:08, Damjan Georgievski wrote:
>
> > I want to read the stream of an external process that I start with
> > Python. From what I've seen that's not possible with the subprocess module?
>
> Try with
>     cmd = 'your command here'
>     stdout = Popen(cmd, shell = True, stdout = PIPE, stderr = STDOUT).stdout

One should never, ever start a process with shell=True unless it's
absolutely necessary.   It is a waste of resources and an a security
issue waiting to happen.  Just say no.  Also, stderr shouldn't be
combined with stdout unless there is a need to mix the two streams,
which usually is not the case.

Also, one needs to hold on to the POpen object so the process can be
properly reaped later or use a with block.  This is where things get
tricky for most applications.  It gets a little extra tricky for 'ip
monitor'.

Assuming the intention is to write a command-line application, the
right thing to do _most likely_ is:
with Popen(['ip', 'monitor', 'neigh'], stdout=PIPE) as proc:
try:
   for line in proc.stdout:
   # Do your processing here, it need not be line-by-line.
finally:
   process.terminate()

Calling process.terminate() explicitly is necessary since "ip monitor"
writes output forever.  This is not the right thing to do in all
situations, and the right thing to do depends on your application and
the command being executed as a subprocess.  It's not really possible
to generalize fully.

As such, your error-handling / cleanup code may end up being
completely different.Don't use my code if it's not applicable to
your situation.  In any case, you need to cleanup after yourself,
which means waiting until the subprocess terminates.  It may also
include cleaning up the file objects for the pipes.  Using POpen
objects in a with block does both, so do that where you can.

The official Python documentation for the subprocess module is pretty
clear and worth reading.  I encourage you to look through it
carefully.  It does, unfortunately, gloss over which resources need to
be cleaned up and when.

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


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread jaialai . technology

I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or
personally affected by your retarded and offensive comment. However, who
the fuck do you think you are to post stuff of this nature? (I believe)
I'll understand if you've got some sort of psychological issue affecting
your behaviour.

OP lives out of his car and his main source of income seems to be ad
revenue from his website.
He may be nuts be he is pretty smart and some of the articles he has up
there are worth reading. Still, he has to promote it in some way and by
constantly posting these sorts of things he brings people to his site.
I'm honestly impressed he can survive this way so I am willing to
ignore or maybe killfile his postings and leave him be.
--
http://mail.python.org/mailman/listinfo/python-list


DateTime objectFormatting

2012-05-02 Thread Nikhil Verma
Hi

I am using  a  DateTimeField in my class and want to do some tweaking with
its object.

class ClinicVisitDateSettings(models.Model):
name = models.CharField(max_length=80,blank=True,null=True)
date_created = models.DateTimeField(blank=True,null=True)

def __unicode__(self):
return "%s %s" % (self.name, self.date_created.strftime("%A %B %d"))


The user fills Gen GI in name and date along with time.

What i am able to achieve with this class object to return is :-

Gen GI Monday  May 7

I want that the this class should return object like this :-

Gen GI Monday AM, May 7
Pancreas Tuesday PM, May 8

How can achieve AM and PM also ? with this datetime object

Thanks in advance

-- 
Regards
Nikhil Verma
+91-958-273-3156
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread Steven_Lord



"Russ P."  wrote in message 
news:[email protected]...

On May 1, 11:52 am, someone  wrote:

On 04/30/2012 03:35 AM, Nasser M. Abbasi wrote:

> On 04/29/2012 07:59 PM, someone wrote:
> I do not use python much myself, but a quick google showed that pyhton
> scipy has API for linalg, so use, which is from the documentation, the
> following code example

> X = scipy.linalg.solve(A, B)

> But you still need to check the cond(). If it is too large, not good.
> How large and all that, depends on the problem itself. But the rule of
> thumb, the lower the better. Less than 100 can be good in general, but 
> I

> really can't give you a fixed number to use, as I am not an expert in
> this subjects, others who know more about it might have better
> recommendations.

Ok, that's a number...

Anyone wants to participate and do I hear something better than "less
than 100 can be good in general" ?

If I don't hear anything better, the limit is now 100...

What's the limit in matlab (on the condition number of the matrices), by
the way, before it comes up with a warning ???


I'm not going to answer, and the reason why is that saying "the limit is X" 
may lead you to believe that "as long as my condition number is less than X, 
I'm safe." That's not the case. The threshold above which MATLAB warns is 
the fence that separates the tourists from the edge of the cliff of 
singularity -- just because you haven't crossed the fence doesn't mean 
you're not in danger of tripping and falling into the ravine.



The threshold of acceptability really depends on the problem you are
trying to solve.


I agree with this statement, although you generally don't want it to be too 
big. The definition of "too big" is somewhat fluid, though.



 I haven't solved linear equations for a long time,
but off hand, I would say that a condition number over 10 is
questionable.


That seems pretty low as a general bound IMO.


A high condition number suggests that the selection of independent
variables for the linear function you are trying to fit is not quite
right. For a poorly conditioned matrix, your modeling function will be
very sensitive to measurement noise and other sources of error, if
applicable. If the condition number is 100, then any input on one
particular axis gets magnified 100 times more than other inputs.
Unless your inputs are very precise, that is probably not what you
want.

Or something like that.


Russ, you and the OP (and others) may be interested in one of the books that 
Cleve Moler has written and made freely available on the MathWorks website:


http://www.mathworks.com/moler/

The chapter Linear Equations in "Numerical Computing with MATLAB" includes a 
section (section 2.9, starting on page 14 if I remember correctly) that 
discusses norm and condition number and gives a more formal statement of 
what you described. The code included in the book is written in MATLAB, but 
even if you don't use MATLAB (since I know this has been cross-posted to 
comp.lang.python) there's plenty of good, crunchy mathematics in that 
section.


--
Steve Lord
[email protected]
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com 


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


Re: DateTime objectFormatting

2012-05-02 Thread Jerry Hill
On Wed, May 2, 2012 at 10:49 AM, Nikhil Verma  wrote:
> What i am able to achieve with this class object to return is :-
>
> Gen GI Monday  May 7
>
> I want that the this class should return object like this :-
>
> Gen GI Monday AM, May 7
> Pancreas Tuesday PM, May 8

Check the documentation for the strftime method:
http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior
 That has a list of the various formatting directives that can be used
to lay out your date and time as you wish.

In this case, instead of "%A %B %d", you probably want "%A %p, %B %d".
 That is, Full Weekday Name, followed by the AM/PM marker, then a
comma, then the Full Month Name and the day of month.

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


Re: DateTime objectFormatting

2012-05-02 Thread Chris Rebert
On Wed, May 2, 2012 at 7:49 AM, Nikhil Verma  wrote:

>     def __unicode__(self):
>     return "%s %s" % (self.name, self.date_created.strftime("%A %B %d"))
>
>
> The user fills Gen GI in name and date along with time.
>
> What i am able to achieve with this class object to return is :-
>
> Gen GI Monday  May 7
>
> I want that the this class should return object like this :-
>
> Gen GI Monday AM, May 7
> Pancreas Tuesday PM, May 8
>
> How can achieve AM and PM also ? with this datetime object

Consult the docs.
http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior :
"%p -- Locale’s equivalent of either AM or PM."

So, strftime("%A %p, %B %d").

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


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Tim Bradshaw

On 2012-05-02 14:44:36 +, [email protected] said:


He may be nuts


But he's right: programmers are pretty much fuckwits[*]: if you think 
that's not true you are not old enough.


[*] including me, especially.

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


Re: DateTime objectFormatting

2012-05-02 Thread Nikhil Verma
Thanks

On Wed, May 2, 2012 at 8:27 PM, Chris Rebert  wrote:

> On Wed, May 2, 2012 at 7:49 AM, Nikhil Verma 
> wrote:
> 
> > def __unicode__(self):
> > return "%s %s" % (self.name, self.date_created.strftime("%A %B
> %d"))
> >
> >
> > The user fills Gen GI in name and date along with time.
> >
> > What i am able to achieve with this class object to return is :-
> >
> > Gen GI Monday  May 7
> >
> > I want that the this class should return object like this :-
> >
> > Gen GI Monday AM, May 7
> > Pancreas Tuesday PM, May 8
> >
> > How can achieve AM and PM also ? with this datetime object
>
> Consult the docs.
> http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior:
> "%p -- Locale’s equivalent of either AM or PM."
>
> So, strftime("%A %p, %B %d").
>
> Regards,
> Chris
>



-- 
Regards
Nikhil Verma
+91-958-273-3156
-- 
http://mail.python.org/mailman/listinfo/python-list


Python SOAP library

2012-05-02 Thread Alec Taylor
What's the best SOAP library for Python?

I am creating an API converter which will be serialising to/from a variety of 
sources, including REST and SOAP.

Relevant parsing is XML [incl. SOAP] and JSON.

Would you recommend: http://code.google.com/p/soapbox/

Or suggest another?

Thanks for all information,

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


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Tomasz Rola
On Wed, 2 May 2012, [email protected] wrote:

> > I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or
> > personally affected by your retarded and offensive comment. However, who
> > the fuck do you think you are to post stuff of this nature? (I believe)
> > I'll understand if you've got some sort of psychological issue affecting
> > your behaviour.
> OP lives out of his car and his main source of income seems to be ad
> revenue from his website.
> He may be nuts be he is pretty smart and some of the articles he has up
> there are worth reading. Still, he has to promote it in some way and by
> constantly posting these sorts of things he brings people to his site.
> I'm honestly impressed he can survive this way so I am willing to
> ignore or maybe killfile his postings and leave him be.

He may be smart but obviously hasn't figured out this yet: positive aura 
drives more people and more permamently towards you. Perhaps he should 
develop an alter ego that could stand side by side with Dalai Lama and see 
which one gets more attention.

Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:[email protected] **
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: DateTime objectFormatting

2012-05-02 Thread Terry Reedy

On 5/2/2012 10:49 AM, Nikhil Verma wrote:

This was posted as html (with text copy). Please send messages to the 
list and newsgroup as text (only). Html sometimes does strange things, 
especially if you post code.


--
Terry Jan Reedy

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


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Tim Wintle
On Wed, 2012-05-02 at 17:31 +0200, Tomasz Rola wrote: 
> positive aura drives more people and more permamently towards you. Perhaps he 
> should 
> develop an alter ego that could stand side by side with Dalai Lama and see 
> which one gets more attention.

Really?



If all you want is attention then "being nice" doesn't seem to be the
best option.

(of course if you want any respect...)

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


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Chris Angelico
On Thu, May 3, 2012 at 1:31 AM, Tomasz Rola  wrote:
> He may be smart but obviously hasn't figured out this yet: positive aura
> drives more people and more permamently towards you.

You catch more flies with honey than with vinegar, but who wants to catch flies?

I don't see much value in Xah Lee's posts, myself; if he wants to use
LISP and hate Python then he's free to, but why ramble about it on
this list?

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


Re: How can I read streaming output of a subprocess

2012-05-02 Thread Damjan Georgievski

I want to read the stream of an external process that I start with Python.
 From what I've seen that's not possible with the subprocess module?

I want to read the output of "ip monitor neigh" which will show changes in
the ARP table on my Linux computer. Each change is a new line printed by
"ip" and the process continues to run forever.



You can use subprocess for this.  If you don't call wait() or
communicate() on the Popen object, the process will happily continue
running.  You can call readline on the stdout pipe, which will block
until the command you are running outputs (and flushes) a line.

Something like this should work:

p = subprocess.Popen(['ip', 'monitor', 'neigh'], stdout=subprocess.PIPE)
first_line = p.stdout.readline()

Buffering done by "ip" can ruin your day.  It seems reasonable to
expect, though, that something that is printing state changes on
stdout will be careful to flush its output when appropriate.



thanks,

With your confirmation, I've rechecked again and now I see that the 
problem I experienced before was with some strange ssh interaction.


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


Re: [GENERAL] Uppercase to lowercase trigger?

2012-05-02 Thread Chris Angelico
On Wed, May 2, 2012 at 10:33 PM, Chrishelring
 wrote:
> Hi,
>
> I´ve got some tables with column names in lowercase. Before updatering these
> tables I want to add a trigger that can convert these lowercase to
> uppercase, and when the tables are updates convert them back to lowercase..

Not entirely sure what you're looking for here, but in Postgres, if
you don't quote your column names, they are lowercased by default.

UPDATE some_table SET ColumnName = 'foo', COLUMNNAME2 = 'bar';

This will work if the table has "columnname" and "columnname2".

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


Re: [GENERAL] Uppercase to lowercase trigger?

2012-05-02 Thread Chris Angelico
On Thu, May 3, 2012 at 2:29 AM, Chris Angelico  wrote:
> On Wed, May 2, 2012 at 10:33 PM, Chrishelring
>  wrote:
>> Hi,
>>
>> I´ve got some tables with column names in lowercase. Before updatering these
>> tables I want to add a trigger that can convert these lowercase to
>> uppercase, and when the tables are updates convert them back to lowercase..
>
> Not entirely sure what you're looking for here, but in Postgres, if
> you don't quote your column names, they are lowercased by default.
>
> UPDATE some_table SET ColumnName = 'foo', COLUMNNAME2 = 'bar';
>
> This will work if the table has "columnname" and "columnname2".
>
> ChrisA

Take no notice of me... 'py'thon and 'pg'-sql are apparently too close
on my keyboard and brain...

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


RE: syntax for code blocks

2012-05-02 Thread Prasad, Ramit
Steven D'Aprano wrote: 
> >> Have you actually tried to use these code blocks of yours? I asked you
> >> for a *working* example earlier, and you replied with examples that
> >> failed with multiple NameErrors and no hint as to how to fix them. And
> >> now you give an example that fails with SyntaxError.
> >
> > The examples I gave you work perfectly.
> 
> Except they don't.
> 
> Look, this isn't difficult. I asked for *working* examples, you gave
> examples that give NameError. Some of those errors are easy to fix, e.g.
> by importing the random and re modules. Some of them aren't. 

[snip] 

> 
> > It's clear that you don't even
> > have the vaguest idea of how my module works or, otherwise, you'd know
> > what you're doing wrong.
> 
> Well duh. What module? Where do I find it? 

[snip part deux]

> Whatever man. It's no skin off my nose. I've tried really hard to give
> your proposal a fair go, but my care factor is rapidly running out if you
> can't even be bothered to ensure your examples use legal Python syntax.


I think the crucial link that was provided in another thread (and
should have been included in a new thread on the same project) is
http://mtomassoli.wordpress.com/2012/04/20/code-blocks-in-python/

The only example I see on that page (for running from module) that 
looks fully complete is:

import codeblocks
codeblocks.rewrite()
def each(iterable, block):
for e in iterable:
block(e)# step into -> 6:
with each(range(0, 10)) << 'x':
print('element ' + str(x))
codeblocks.end_of_module()



I have not tried this (or any) example. To me it seems like an 
overly complicated way to avoid creating a function def. Especially
since it creates a function anyway (whether anonymous or named).


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Temia Eszteri
>On 27/04/12 03:11, Xah Lee wrote:
>> John Carmack glorifying functional programing in 3k words
>>
>> http://www.altdevblogaday.com/2012/04/26/functional-programming-in-c/
>>
>> where was he ten years ago?
>>
>> O, and btw, i heard that Common Lispers don't do functional
>> programing, is that right?
>>
>> Fuck Common Lispers. Yeah, fuck them. One bunch of Fuckfaces. (and
>> Fuck Pythoners. Python fucking idiots.)
>>
>> O, don't forget,
>>
>> 〈Programing: What are OOP's Jargons and Complexities (Object Oriented
>> Program as Functional Program)〉
>> http://xahlee.org/Periodic_dosage_dir/t2/oop.html
>>
>> please you peruse of it.
>
>I'm not a 'Common Lisper' or a 'Pythoner' so I'm not directly or 
>personally affected by your retarded and offensive comment. However, who 
>the fuck do you think you are to post stuff of this nature? (I believe) 
>I'll understand if you've got some sort of psychological issue affecting 
>your behaviour.

And another one gets trolled.

~Temia
--
When on earth, do as the earthlings do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Tomasz Rola
On Thu, 3 May 2012, Chris Angelico wrote:

> On Thu, May 3, 2012 at 1:31 AM, Tomasz Rola  wrote:
> > He may be smart but obviously hasn't figured out this yet: positive aura
> > drives more people and more permamently towards you.
> 
> You catch more flies with honey than with vinegar, but who wants to 
> catch flies?

Nah. Who invents such distorted examples only to prove himself right :-).

I think you can catch more girls with honey and I'm not sure if I'd like 
to catch those who prefer vinegar. I think we can make it into some kind 
of law, say Angelico-Rola Law (of girlscatching), ok?

"One cannot catch a girl on honey without catching some flies in the 
process."

Or is it a hypothesis?

> I don't see much value in Xah Lee's posts, myself; if he wants to use
> LISP and hate Python then he's free to, but why ramble about it on
> this list?

Well, it is strange because about half of his every post are filled up 
with f and sh words. Even I feel a bit dirty after reading them (and I 
swear without giving it much of second thought). Myself, I think I 
shouldn't try too hard to understand his motives - because one can easily 
become what one understands. Especially that he doesn't seem to be 
interested in getting feedback, so chances are there is some force of 
chaos behind all this. Or his feelings have been hurt by 
Lisp/Python/Emacs/Perl community (but I couldn't care less, really).

Either way, I greet Xah for taking my mind off a subject of writing some 
piece of code that should have been written a while ago :-).

Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:[email protected] **
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Tomasz Rola
On Wed, 2 May 2012, Tim Wintle wrote:

> On Wed, 2012-05-02 at 17:31 +0200, Tomasz Rola wrote: 
> > positive aura drives more people and more permamently towards you. Perhaps 
> > he should 
> > develop an alter ego that could stand side by side with Dalai Lama and see 
> > which one gets more attention.
> 
> Really?
> 
>  +lama&ctab=0&geo=all&date=all&sort=0>
> 
> If all you want is attention then "being nice" doesn't seem to be the
> best option.
> 
> (of course if you want any respect...)

Okay, I should have given the idea a second thought. OTOH, see for 
yourself:

http://www.google.com/trends/?q=xah+lee,dalai+lama&ctab=0&geo=all&date=all&sort=0

Esp. "xah lee does not have enough search volume for ranking"...

For me, the conclusion is simple. If he wants to achieve anything, he 
should mimic Dalai Lama first and only after becoming comparable to the 
guy, if he's still dissatisfied, only then he should follow OBL. But by 
all means he should stop being himself. If becoming DL-like is too hard (I 
believe it is), he might find something even easier, like Miyamoto 
Musashi, a sword/Zen master.

http://www.google.com/trends/?q=miyamoto+musashi,+dalai+lama&ctab=0&geo=all&date=all&sort=0

Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:[email protected] **
-- 
http://mail.python.org/mailman/listinfo/python-list


mmap and bit wise twiddling - Raspberry Pi

2012-05-02 Thread Petr Jakes
Hi,
I am trying to work with HW peripherals on Raspberry Pi
To achieve this, it is necessary read/write some values from/to the
memory directly.

I am looking for some wise way how to organize the bit twiddling.

To set some specific bit, for example, it is necessary:
- read 4 bytes string representation (I am using mmap)
- transform it to the corresponding integer (I am using numpy)
- do some bit masking over this integer
- transport integer to the string representation (numpy again)
- write it back to the memory

In other words I mean: is there wise way to create an instrument/
machinery to define Class and then simply define all necessary objects
and set the bit values over object attributes so the whole bit-
twiddling remains under the hood.

say:
LED01 = GPIO(4)  # gpio PIN number 4 is assigned to the LED01 name
(attribute)
LED01.on()
LED01.off()
 or

gpio = GPIO()
LED01 = gpio.pin04
LED01 = 1 # led diode is shining (or gpio pin 4 is set)
LED01 = 0 # led diode is off

General suggestions, how to organise this work are more then welcome.

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


Re: Some posts do not show up in Google Groups

2012-05-02 Thread Michael Torrie
On 05/01/2012 12:12 AM, Frank Millman wrote:
> I have had a look at this before, but there is one thing that Google
> Groups does that no other reader seems to do, and that is that
> messages are sorted according to thread-activity, not original posting
> date. This makes it easy to see what has changed since the last time I
> checked.

Any good threaded e-mail reader will do this.  I use Thunderbird, for
example, and all incoming python messages to the list come in, sorting
the threads by most recent activity.  Also coming from google groups I
think you would enjoy the capabilities that a true threaded e-mail
reader brings.  Google's "conversations" view of things just does not
preserve the structure of the more complicated and long-running threads.

If you want to stick with NNTP, thunderbird works with nntp just fine,
and in fact works very well, unlike what Dennis Lee Bieber claims on his
post.  And as far as nntp goes, I don't see any difference between
reading the list in Thunderbird via nntp or a dedicated e-mail feed
(which I filter into its own IMAP folder).

Avoid using gmail for reading and posting to mailing lists (yes I know I
post from gmail).  Google helpfully tosses out your own posts to the
list so you never see them, which is a real problem for mailing lists.
Google certainly knows about this bug but claims its a feature.  What a
crock.  In the gmail web interface, google puts messages from your sent
folder into the "conversation" stream, so they toss the duplicate
message coming from the list.  When using IMAP, this leads to dropped
messages as no IMAP client will presume to know enough to put sent
messages into a thread.  The workwaround, which is what I use, is to
send your messages to the list through a non-Gmail SMTP server.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a string to list for submission to easygui multenterb​ox

2012-05-02 Thread Laurent Pointal
ksals wrote:

> On May 1, 5:29 pm, John Gordon  wrote:
>> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com>
>> ksals  writes:
>>
>> > The original choice looks like this when I print it:
>> > print(choice)
>> > ('ksals', '', 'alsdkfj', '3', '')
>> > I need to submit these as defaults to a multenterbox. Each entry above
>> > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box.
>> > I tried your suggestion so you must be right it is a tuple of 5
>> > strings.  But I need them to work in an instruction like
>> > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice)
>> > fieldNames has 5 fields.
>>
>> If you just need to convert a tuple to a list, that's easy.  Call the
>> built-in function list() and pass the tuple as an intializer:
>>
>> >>> choice = ('ksals', '', 'alsdkfj', '3', '')
>> >>> print choice
>>
>> ('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice)
>> >>> print choice_list
>>
>> ['ksals', '', 'alsdkfj', '3', '']
>>
>> --
>> John Gordon   A is for Amy, who fell down the stairs
>> [email protected]  B is for Basil, assaulted by bears
>> -- Edward Gorey, "The Gashlycrumb Tinies"
>>
>>
> This is a small excert to show you what I get
> 
> for choice in easygui.multchoicebox(msg1, title,qstack):
> if choice[0] == None:
> print ("No entries made")
> break
> 
> 
> print("CHOICE IS: ",choice). CHOICE IS:
> ('', 'ksals', '', '', '')
> c=list(choice)
> print("C IS: ",c)  .  C IS:  ['(',
> "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'",
> "'", ',', ' ', "'", "'", ',', ' ', "'", "'",
> ')']

Looks like you have your tuple expression
('ksals', '', 'alsdkfj', '3', '')
not as a tuple, but as a string. Do you convert it somewhere ? 

If you have it as a string, you can use eval() (not safe!) on the string to 
retrieve the tuple, then list() on the tuple to get a list.


-- 
Laurent POINTAL - [email protected]
3 allée des Orangers - 91940 Les Ulis - France
Tél. 01 69 29 06 59

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


try/except in a loop

2012-05-02 Thread J. Mwebaze
I have multiple objects, where any of them can serve my purpose.. However
some objects might not have some dependencies. I can not tell before hand
if the all the dependencies exsit. What i want to is begin processing from
the 1st object, if no exception is raised, i am done.. if an exception is
raised, the next object is tried, etc  Something like

objs = [... ]
try:
  obj = objs[0]
  obj.make()
except Exception, e:
  try:
  obj = objs[1]
  obj.make()
  except Exception, e:
 try:
obj = objs[2]
obj.make()
 except Exception, e:
   continue

The problem is the length of the list of objs is variable... How can i do
this?



-- 
*Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze

/* Life runs on code */*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: try/except in a loop

2012-05-02 Thread Chris Kaynor
On Wed, May 2, 2012 at 12:51 PM, J. Mwebaze  wrote:
> I have multiple objects, where any of them can serve my purpose.. However
> some objects might not have some dependencies. I can not tell before hand if
> the all the dependencies exsit. What i want to is begin processing from the
> 1st object, if no exception is raised, i am done.. if an exception is
> raised, the next object is tried, etc  Something like
>
> objs = [... ]
> try:
>   obj = objs[0]
>   obj.make()
> except Exception, e:
>   try:
>       obj = objs[1]
>       obj.make()
>   except Exception, e:
>      try:
>         obj = objs[2]
>         obj.make()
>      except Exception, e:
>        continue
>
> The problem is the length of the list of objs is variable... How can i do
> this?


for obj in objs:
try:
obj.make()
except Exception:
continue
else:
break
else:
raise RuntimeError('No object worked')

>
>
>
> --
> Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze |
> skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze
>
> /* Life runs on code */
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: try/except in a loop

2012-05-02 Thread Andrew Berg
Why wouldn't a for loop work? If something works, you can break out,
otherwise continue.

working_obj = None
for obj in iterable:
try:
obj.do_something()
working_obj = obj
break
except:
continue

-- 
CPython 3.3.0a3 | Windows NT 6.1.7601.17790
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mmap and bit wise twiddling - Raspberry Pi

2012-05-02 Thread Thomas Heller

Am 02.05.2012 19:40, schrieb Petr Jakes:

Hi,
I am trying to work with HW peripherals on Raspberry Pi
To achieve this, it is necessary read/write some values from/to the
memory directly.

I am looking for some wise way how to organize the bit twiddling.

To set some specific bit, for example, it is necessary:
 - read 4 bytes string representation (I am using mmap)
 - transform it to the corresponding integer (I am using numpy)
 - do some bit masking over this integer
 - transport integer to the string representation (numpy again)
 - write it back to the memory

In other words I mean: is there wise way to create an instrument/
machinery to define Class and then simply define all necessary objects
and set the bit values over object attributes so the whole bit-
twiddling remains under the hood.

say:
LED01 = GPIO(4)  # gpio PIN number 4 is assigned to the LED01 name
(attribute)
LED01.on()
LED01.off()
  or

gpio = GPIO()
LED01 = gpio.pin04
LED01 = 1 # led diode is shining (or gpio pin 4 is set)
LED01 = 0 # led diode is off


I have an abstract BitVector base-class that allows to get/set single
bits or several bits in a convenient way.  You must define concrete
subclasses which define a _value get/set property that actually
updates the byte or word in the hardware.  I use it to access bits
or groups of bits of I2C devices.

You would basically code like this, assuming an 8-bit GPIO port:

class GPIO(BitVector):
def __init__(self, address, value=0xFF, nbits=8):
self.address = address
super(GPIO, self).__init__(value, nbits)
def _get_value(self):
"read an 8-bit value from the hardware as 8-bit integer"
...
def _set_value(self, v):
"write the 8-bit value 'v' to the hardware"
...

then you can do:

gpio = GPIO(0x12345678)

led0 = gpio[4] # bit 4
led0.value = 1 # switch led on
print led0.value # get led status

For multiple bits use this (note that different from standard Python
practices, indexing works inclusive and uses [high_bitnum:low_bitnum]:

port = GPIO(0x12345678)
high_nibble = port[7:4]
print high_nibble.value
low_nibble = port[3:0]
low_nibble.value = 0xF

Thomas
class BitVector(object):
"""BitVector class, represents mutable integers
constricted to a certain range.

Single bits can be get/set by indexing with integers.

Slices can be used to get/set the bits in this range, as an
integer constricted to this range also.

Slices must use [MSB:LSB], and are inclusive.

>>> [x for x in BitVector(0xAA)]
[0, 1, 0, 1, 0, 1, 0, 1]
>>> [x for x in BitVector(0xFF)]
[1, 1, 1, 1, 1, 1, 1, 1]
>>>
>>> bv = BitVector(0)
>>> bv[6:3] = 0xf
>>> [x for x in bv]
[0, 0, 0, 1, 1, 1, 1, 0]
>>> bv[6:3] = -1
Traceback (most recent call last):
  ...
ValueError: value out of allowed range
>>> bv[6:3] = 16
Traceback (most recent call last):
  ...
ValueError: value out of allowed range
>>> hex(bv)
'0x78'
>>> bin(bv)
'0b000'
>>> 
"""
def __init__(self, value=0, nbits=8):
self._nbits = nbits
self._value = value

def __index__(self):
return self._value

def __hex__(self):
return hex(self._value)

def __getitem__(self, index):
if isinstance(index, slice):
return self._getslice(index)
if not 0 <= index < self._nbits:
raise IndexError("invalid index")
return int(bool(self._value & (1 << index)))

@property
def bits(self):
"""
Return some bits as an object that has a .value property.  The
.value property represents the current value of the specied
bits.

b = BitVector().bits[7:0]
b.value = ...
print b.value
"""
class Bits(object):
def __init__(self, bv):
self.bv = bv
def __getitem__(self, index):
class GetSet(object):
def __init__(self, bv):
self.bv = bv
def _get(self):
return self.bv[index]
def _set(self, value):
self.bv[index] = value
value = property(_get, _set)
return GetSet(self.bv)
return Bits(self)

def _getslice(self, index):
if index.step is not None:
raise ValueError("extended slicing not supported")
stop, start = index.stop, index.start
if start <= stop or start < 0 or stop >= self._nbits:
print "START, STOP", start, stop
raise ValueError("invalid slice range")
mask = (1 << (start+1)) - 1
return (self._value & mask) >> stop

def _setslice(self, index, value):
if index.step is not None:
raise ValueError("extended slicing not supported")
stop, start = index.stop, index.start
if start <= stop or start < 0 or stop >= se

Re: mmap and bit wise twiddling - Raspberry Pi

2012-05-02 Thread Thomas Heller

Am 02.05.2012 22:05, schrieb Thomas Heller:

class GPIO(BitVector):
def __init__(self, address, value=0xFF, nbits=8):
self.address = address
super(GPIO, self).__init__(value, nbits)
def _get_value(self):
"read an 8-bit value from the hardware as 8-bit integer"
...
def _set_value(self, v):
"write the 8-bit value 'v' to the hardware"
...


Sorry, forgot to create the property; so please add this
to the class definition:

_value = property(_get_value, _set_value)


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


Re: try/except in a loop

2012-05-02 Thread Andrew Berg
Forgot to add that all this is covered in the tutorial in the official docs:
http://docs.python.org/tutorial/controlflow.html#for-statements

-- 
CPython 3.3.0a3 | Windows NT 6.1.7601.17790
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: try/except in a loop

2012-05-02 Thread Prasad, Ramit
> > I have multiple objects, where any of them can serve my purpose..
> However
> > some objects might not have some dependencies. I can not tell before
> hand if
> > the all the dependencies exsit. What i want to is begin processing from
> the
> > 1st object, if no exception is raised, i am done.. if an exception is
> > raised, the next object is tried, etc  Something like
> >
> > objs = [... ]
> > try:
> >   obj = objs[0]
> >   obj.make()
> > except Exception, e:
> >   try:
> >   obj = objs[1]
> >   obj.make()
> >   except Exception, e:
> >  try:
> > obj = objs[2]
> > obj.make()
> >  except Exception, e:
> >continue
> >
> > The problem is the length of the list of objs is variable... How can i
> do
> > this?
> 
> 
> for obj in objs:
> try:
> obj.make()
> except Exception:
> continue
> else:
> break
> else:
> raise RuntimeError('No object worked')


I think you misunderstand the else clauses.

>>> for obj in [ 1,2,3,4 ]:
... try:
... print obj
... except Exception:
... print 'EXCEPTION'
... else:
... print 'NO EXCEPTION'
... else:
... print 'NO OBJECTS'
... 
1
NO EXCEPTION
2
NO EXCEPTION
3
NO EXCEPTION
4
NO EXCEPTION
NO OBJECTS


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: try/except in a loop

2012-05-02 Thread Chris Kaynor
On Wed, May 2, 2012 at 1:12 PM, Prasad, Ramit  wrote:
>> > I have multiple objects, where any of them can serve my purpose..
>> However
>> > some objects might not have some dependencies. I can not tell before
>> hand if
>> > the all the dependencies exsit. What i want to is begin processing from
>> the
>> > 1st object, if no exception is raised, i am done.. if an exception is
>> > raised, the next object is tried, etc  Something like
>> >
>> > objs = [... ]
>> > try:
>> >   obj = objs[0]
>> >   obj.make()
>> > except Exception, e:
>> >   try:
>> >       obj = objs[1]
>> >       obj.make()
>> >   except Exception, e:
>> >      try:
>> >         obj = objs[2]
>> >         obj.make()
>> >      except Exception, e:
>> >        continue
>> >
>> > The problem is the length of the list of objs is variable... How can i
>> do
>> > this?
>>
>>
>> for obj in objs:
>>     try:
>>         obj.make()
>>     except Exception:
>>         continue
>>     else:
>>         break
>> else:
>>     raise RuntimeError('No object worked')
>
>
> I think you misunderstand the else clauses.
>
 for obj in [ 1,2,3,4 ]:
> ...     try:
> ...         print obj
> ...     except Exception:
> ...         print 'EXCEPTION'
> ...     else:
> ...         print 'NO EXCEPTION'
> ... else:
> ...     print 'NO OBJECTS'
> ...
> 1
> NO EXCEPTION
> 2
> NO EXCEPTION
> 3
> NO EXCEPTION
> 4
> NO EXCEPTION
> NO OBJECTS

You left out the break in the try clause's else that I had. That break
statement causes the for loop to exit early if there is no exception,
and thus the for loop's else clause does not run:

>>> for obj in [ 1,2,3,4 ]:
... try:
... print obj
... except Exception:
... print 'EXCEPTION'
... else:
... print 'NO EXCEPTION'
... break
... else:
... print 'NO OBJECTS'
...
1
NO EXCEPTION

>
>
> Ramit
>
>
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
>
> --
>
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread someone

On 05/02/2012 01:03 PM, Kiuhnm wrote:

On 5/2/2012 8:00, someone wrote:

Still, I dont think I completely understand SVD. SVD (at least in
Matlab) returns 3 matrices, one is a diagonal matrix I think. I think I
would better understand it with geometric examples, if one would be so
kind to maybe write something about that... I can plot 3D vectors in
matlab, very easily so maybe I better understand SVD if I hear/read the
geometric explanation (references to textbook/similar is also
appreciated).


Russ's post is a very good starting point. I hope you read it.


Ofcourse I do.


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


Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread someone

On 05/02/2012 08:36 AM, Russ P. wrote:

On May 1, 11:03 pm, someone  wrote:

On 05/02/2012 01:38 AM, Russ P. wrote:

..

On May 1, 4:05 pm, Paul Rubinwrote:

It would really appreciate if anyone could maybe post a simple SVD
example and tell what the vectors from the SVD represents geometrically
/ visually, because I don't understand it good enough and I'm sure it's
very important, when it comes to solving matrix systems...


SVD is perhaps the ultimate matrix decomposition and the ultimate tool
for linear analysis. Google it and take a look at the excellent
Wikipedia page on it. I would be wasting my time if I tried to compete
with that.


Ok.


To really appreciate the SVD, you need some background in linear
algebra. In particular, you need to understand orthogonal
transformations. Think about a standard 3D Cartesian coordinate frame.
A rotation of the coordinate frame is an orthogonal transformation of
coordinates. The original frame and the new frame are both orthogonal.


Yep.


A vector in one frame is converted to the other frame by multiplying
by an orthogonal matrix. The main feature of an orthogonal matrix is
that its transpose is its inverse (hence the inverse is trivial to
compute).


As far as i know, you have to replace orthogonal with: orthonormal. That 
much I at least think I know without even going to wikipedia first...



The SVD can be thought of as factoring any linear transformation into
a rotation, then a scaling, followed by another rotation. The scaling
is represented by the middle matrix of the transformation, which is a
diagonal matrix of the same dimensions as the original matrix. The
singular values can be read off of the diagonal. If any of them are
zero, then the original matrix is singular. If the ratio of the
largest to smallest singular value is large, then the original matrix
is said to be poorly conditioned.


Aah, thank you very much. I can easily recognize some of this...


Standard Cartesian coordinate frames are orthogonal. Imagine an x-y
coordinate frame in which the axes are not orthogonal. Such a
coordinate frame is possible, but they are rarely used. If the axes
are parallel, the coordinate frame will be singular and will basically
reduce to one-dimensional. If the x and y axes are nearly parallel,
the coordinate frame could still be used in theory, but it will be
poorly conditioned. You will need large numbers to represent points
fairly close to the origin, and small deviations will translate into
large changes in coordinate values. That can lead to problems due to
numerical roundoff errors and other kinds of errors.


Thank you very much for your time. It always helps to get the same 
explanation from different people with slightly different ways of 
explaining it. Thanks!

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


RE: Overlayong PDF Files

2012-05-02 Thread Sells, Fred
Assuming your form has actual PDF data entry fields.  I export the form to a 
.fdf file, run a little script to replace fieldnames with %(fieldname)s  and 
save this as a staic template.  At run time I'll merge the template with a 
python dictionary using the % operator and shell down to pdftk to merge the two 
files and create a filled in PDF.  This way you don't have to worry about exact 
placement of data.

I have been looking for an api that would let me do this without the .fdf step, 
but to no avail.


-Original Message-
From: [email protected] 
[mailto:[email protected]] On Behalf Of 
Adam Tauno Williams
Sent: Thursday, April 26, 2012 8:25 AM
To: [email protected]
Subject: Re: Overlayong PDF Files

On Wed, 2012-04-25 at 13:36 -0500, Greg Lindstrom wrote:
> I would like to take an existing pdf file which has the image of a 
> health care claim and overlay the image with claim data (insured name, 
> address, procedures, etc.).  I'm pretty good with reportlab -- in 
> fact, I've created a form close to the CMS 1500 (with NPI), but it's 
> not close enough for scanning.  I'd like to read in the "official"
> form and add my data.  Is this possible?

I 'overlay' PDF documents  using pypdf.

Example


--
Adam Tauno Williams 
System Administrator, OpenGroupware Developer, LPI / CNA Fingerprint 8C08 209A 
FBE3 C41A DD2F A270 2D17 8FA4 D95E D383
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread someone

On 05/02/2012 01:52 PM, Steven D'Aprano wrote:

On Wed, 02 May 2012 08:00:44 +0200, someone wrote:


On 05/02/2012 01:05 AM, Paul Rubin wrote:

someone   writes:

Actually I know some... I just didn't think so much about, before
writing the question this as I should, I know theres also something
like singular value decomposition that I think can help solve
otherwise illposed problems,


You will probably get better advice if you are able to describe what
problem (ill-posed or otherwise) you are actually trying to solve.  SVD


I don't understand what else I should write. I gave the singular matrix
and that's it.


You can't judge what an acceptable condition number is unless you know
what your data is.

http://mathworld.wolfram.com/ConditionNumber.html
http://en.wikipedia.org/wiki/Condition_number

If your condition number is ten, then you should expect to lose one digit
of accuracy in your solution, over and above whatever loss of accuracy
comes from the numeric algorithm. A condition number of 64 will lose six
bits, or about 1.8 decimal digits, of accuracy.

If your data starts off with only 1 or 2 digits of accuracy, as in your
example, then the result is meaningless -- the accuracy will be 2-2
digits, or 0 -- *no* digits in the answer can be trusted to be accurate.


I just solved a FEM eigenvalue problem where the condition number of the 
mass and stiffness matrices was something like 1e6... Result looked good 
to me... So I don't understand what you're saying about 10 = 1 or 2 
digits. I think my problem was accurate enough, though I don't know what 
error with 1e6 in condition number, I should expect. How did you arrive 
at 1 or 2 digits for cond(A)=10, if I may ask ?




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


Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread someone

On 05/02/2012 04:47 PM, Steven_Lord wrote:


Russ, you and the OP (and others) may be interested in one of the books
that Cleve Moler has written and made freely available on the MathWorks
website:

http://www.mathworks.com/moler/

The chapter Linear Equations in "Numerical Computing with MATLAB"
includes a section (section 2.9, starting on page 14 if I remember
correctly) that discusses norm and condition number and gives a more
formal statement of what you described. The code included in the book is
written in MATLAB, but even if you don't use MATLAB (since I know this
has been cross-posted to comp.lang.python) there's plenty of good,
crunchy mathematics in that section.


I use matlab more than python. I just want to learn python, which seems 
extremely powerful and easy but yet, I'm a python beginner.


Thank you very much for the reference, Mr. Lord. I'll look closely at 
that Moler-book, in about 1/2 hour or so Looking forward to learning 
more about this...

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


Re: Converting a string to list for submission to easygui multenterb​ox

2012-05-02 Thread ksals
On May 2, 1:57 pm, Laurent Pointal  wrote:
> ksals wrote:
> > On May 1, 5:29 pm, John Gordon  wrote:
> >> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com>
> >> ksals  writes:
>
> >> > The original choice looks like this when I print it:
> >> > print(choice)
> >> > ('ksals', '', 'alsdkfj', '3', '')
> >> > I need to submit these as defaults to a multenterbox. Each entry above
> >> > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box.
> >> > I tried your suggestion so you must be right it is a tuple of 5
> >> > strings.  But I need them to work in an instruction like
> >> > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice)
> >> > fieldNames has 5 fields.
>
> >> If you just need to convert a tuple to a list, that's easy.  Call the
> >> built-in function list() and pass the tuple as an intializer:
>
> >> >>> choice = ('ksals', '', 'alsdkfj', '3', '')
> >> >>> print choice
>
> >> ('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice)
> >> >>> print choice_list
>
> >> ['ksals', '', 'alsdkfj', '3', '']
>
> >> --
> >> John Gordon                   A is for Amy, who fell down the stairs
> >> [email protected]              B is for Basil, assaulted by bears
> >> -- Edward Gorey, "The Gashlycrumb Tinies"
>
> > This is a small excert to show you what I get
>
> > for choice in easygui.multchoicebox(msg1, title,qstack):
> >             if choice[0] == None:
> >                 print ("No entries made")
> >                 break
>
> >             print("CHOICE IS: ",choice)    .         CHOICE IS:
> > ('', 'ksals', '', '', '')
> >             c=list(choice)
> >             print("C IS: ",c)              .      C IS:  ['(',
> > "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'",
> > "'", ',', ' ', "'", "'", ',', ' ', "'", "'",
> > ')']
>
> Looks like you have your tuple expression
>         ('ksals', '', 'alsdkfj', '3', '')
> not as a tuple, but as a string. Do you convert it somewhere ?
>
> If you have it as a string, you can use eval() (not safe!) on the string to
> retrieve the tuple, then list() on the tuple to get a list.
>
> --
> Laurent POINTAL - [email protected]
> 3 allée des Orangers - 91940 Les Ulis - France
> Tél. 01 69 29 06 59
>
>

Thank you and everyone that helped me.  I did finally figure it out
this morning. I am now converting for my use. I just didn't understand
what I was looking at
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: try/except in a loop

2012-05-02 Thread Prasad, Ramit
> >> for obj in objs:
> >> try:
> >> obj.make()
> >> except Exception:
> >> continue
> >> else:
> >> break
> >> else:
> >> raise RuntimeError('No object worked')
> >
> >
> > I think you misunderstand the else clauses.
> >
>  for obj in [ 1,2,3,4 ]:
> > ... try:
> > ... print obj
> > ... except Exception:
> > ... print 'EXCEPTION'
> > ... else:
> > ... print 'NO EXCEPTION'
> > ... else:
> > ... print 'NO OBJECTS'
> > ...
> > 1
> > NO EXCEPTION
> > 2
> > NO EXCEPTION
> > 3
> > NO EXCEPTION
> > 4
> > NO EXCEPTION
> > NO OBJECTS
> 
> You left out the break in the try clause's else that I had. That break
> statement causes the for loop to exit early if there is no exception,
> and thus the for loop's else clause does not run:
> 
> >>> for obj in [ 1,2,3,4 ]:
> ... try:
> ... print obj
> ... except Exception:
> ... print 'EXCEPTION'
> ... else:
> ... print 'NO EXCEPTION'
> ... break
> ... else:
> ... print 'NO OBJECTS'
> ...
> 1
> NO EXCEPTION

Whoops, you are right. My apologies Chris!

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python SOAP library

2012-05-02 Thread John Nagle

On 5/2/2012 8:35 AM, Alec Taylor wrote:

What's the best SOAP library for Python?
I am creating an API converter which will be serialising to/from a variety of 
sources, including REST and SOAP.
Relevant parsing is XML [incl. SOAP] and JSON.
Would you recommend: http://code.google.com/p/soapbox/

Or suggest another?
Thanks for all information,


   Are you implementing the client or the server?

   Python "Suds" is a good client-side library. It's strict SOAP;
you must have a WSDL file, and the XML queries and replies must
verify against the WSDL file.

https://fedorahosted.org/suds/

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


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Michael Torrie
On 05/02/2012 09:31 AM, Tomasz Rola wrote:
> On Wed, 2 May 2012, [email protected] wrote:
>> OP lives out of his car and his main source of income seems to be ad
>> revenue from his website.

I'm always curious about this sort of thing.  Do you know this for a
fact, jaialai.technology?

>> He may be nuts be he is pretty smart and some of the articles he has up
>> there are worth reading. Still, he has to promote it in some way and by
>> constantly posting these sorts of things he brings people to his site.
>> I'm honestly impressed he can survive this way so I am willing to
>> ignore or maybe killfile his postings and leave him be.
> 
> He may be smart but obviously hasn't figured out this yet: positive aura 
> drives more people and more permamently towards you. Perhaps he should 
> develop an alter ego that could stand side by side with Dalai Lama and see 
> which one gets more attention.

He appears to have some degree of the Aspergers/autism spectrum
disorder.  He quite literally cannot understand how people see him and
why other people don't recognize his genius (both real and imagined).
At least this is one possibility.

Others who have crossed this list appear to have aspergers or autism
too, such as Ranting Rick.  He pops up occasionally, posts quite
normally and even helpfully, and then lapses back into periods of
ranting about how he can fix python and we all should be doing
something.  He refuses to write code to put his ideas into practice, and
berates the list readers for being lazy and unwilling to code this
ideas.  Then eventually he disappears for months even years at a time
before resurfacing.  I've always been curious to know more about Rick.
Where does he work?  How does he live, and what does he do outside of
the python list (he appears to only use his e-mail address on this list).

Then other times I just worry about coding something cool in python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy (matrix solver) - python vs. matlab

2012-05-02 Thread Russ P.
On May 2, 1:29 pm, someone  wrote:

> > If your data starts off with only 1 or 2 digits of accuracy, as in your
> > example, then the result is meaningless -- the accuracy will be 2-2
> > digits, or 0 -- *no* digits in the answer can be trusted to be accurate.
>
> I just solved a FEM eigenvalue problem where the condition number of the
> mass and stiffness matrices was something like 1e6... Result looked good
> to me... So I don't understand what you're saying about 10 = 1 or 2
> digits. I think my problem was accurate enough, though I don't know what
> error with 1e6 in condition number, I should expect. How did you arrive
> at 1 or 2 digits for cond(A)=10, if I may ask ?

As Steven pointed out earlier, it all depends on the precision you are
dealing with. If you are just doing pure mathematical or numerical
work with no real-world measurement error, then a condition number of
1e6 may be fine. But you had better be using "double precision" (64-
bit) floating point numbers (which are the default in Python, of
course). Those have approximately 12 digits of precision, so you are
in good shape. Single-precision floats only have 6 or 7 digits of
precision, so you'd be in trouble there.

For any practical engineering or scientific work, I'd say that a
condition number of 1e6 is very likely to be completely unacceptable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Tomasz Rola
On Wed, 2 May 2012, Michael Torrie wrote:

> On 05/02/2012 09:31 AM, Tomasz Rola wrote:
> > On Wed, 2 May 2012, [email protected] wrote:
> >> OP lives out of his car and his main source of income seems to be ad
> >> revenue from his website.
> 
> I'm always curious about this sort of thing.  Do you know this for a
> fact, jaialai.technology?

I guess everything we can tell about Xah comes from his own website's 
"about me" pages :-).

> >> He may be nuts be he is pretty smart and some of the articles he has up
> >> there are worth reading. Still, he has to promote it in some way and by
> >> constantly posting these sorts of things he brings people to his site.
> >> I'm honestly impressed he can survive this way so I am willing to
> >> ignore or maybe killfile his postings and leave him be.
> > 
> > He may be smart but obviously hasn't figured out this yet: positive aura 
> > drives more people and more permamently towards you. Perhaps he should 
> > develop an alter ego that could stand side by side with Dalai Lama and see 
> > which one gets more attention.
> 
> He appears to have some degree of the Aspergers/autism spectrum
> disorder.  He quite literally cannot understand how people see him and
> why other people don't recognize his genius (both real and imagined).
> At least this is one possibility.

>From what I have learned, Aspergers know there is a "language" that other 
people speak that makes them comfortable with each other, but are unable 
to reproduce it (in a manner similar to, say, Englishman living in France 
for years, with Frenchmen not very content about his broken accent). OTOH 
people with autism, even so called Highly Functioning Autism, neither 
understand there is such a language, nor give a damn (abovementioned 
Englishman lives in France without realizing guys around him speak 
differently).

About geniuses - I have heard they stand up and deliver, do not rant. Xah 
has his strong points - they come up on his website, but interaction is 
probably not one of them.

Perhaps Xah (and other guys) have particularly hard time with being 
attacked by depression and react by ranting? This, or some kind of 
narcistic delirium.

Of course, all of those are just my somewhat-semi-educated guesses.

> Others who have crossed this list appear to have aspergers or autism
> too, such as Ranting Rick.  He pops up occasionally, posts quite
> normally and even helpfully, and then lapses back into periods of
> ranting about how he can fix python and we all should be doing
> something.  He refuses to write code to put his ideas into practice, and
> berates the list readers for being lazy and unwilling to code this
> ideas.  Then eventually he disappears for months even years at a time

Well? I thought there were some languages similar in form to Python, that 
could satisfy anybody looking for such form "only with few features 
different". I don't remember their names - but just staying here and doing 
like you describe does not look rational.

> before resurfacing.  I've always been curious to know more about Rick.
> Where does he work?  How does he live, and what does he do outside of
> the python list (he appears to only use his e-mail address on this list).

Yep. It is always interesting, in a way.

I think if they do not have constant income, they probably live a 
miserable lifes in some shack, working on hardware in a pre-death state, 
reanimated and resuscitated and breaking again...

Or maybe not. Afterall, ability to resuscitate computer can be sold, too.

> Then other times I just worry about coding something cool in python.

Or some other language :-)

Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:[email protected] **
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: syntax for code blocks

2012-05-02 Thread alex23
On May 2, 8:52 pm, Kiuhnm  wrote:
>>  func(some_args, locals())
>
> I think that's very bad. It wouldn't be safe either. What about name
> clashing

locals() is a dict. It's not injecting anything into func's scope
other than a dict so there's not going to be any name clashes. If you
don't want any of its content in your function's scope, just don't use
that content.

> and how would you pass only some selected functions?

You wouldn't. You would just refer to the required functions in the
dict _in the same way you would in both your "bad python" and code
block versions.

> > But as you're _passing them in by name_ why not just make it
> > func(some_args) and pick them up out of the scope.
>
> Because that's not clean and maintainable. It's not different from using
> global variables.

...I'm beginning to suspect we're not engaging in the same
conversation.

This is very common in Python:

from module1 import func1

def func2(args): pass

def main():
# do something with func1 and func2

And I've never had problems maintaining code like this. I know
_exactly_ the scope that the functions exist within because I added
them to it. They're not _global_ because they're restricted to that
specific scope.

> > _No one_ writes Python code like this. Presenting bad code as
> > "pythonic" is a bit of a straw man.
>
> How can I present good code where there's no good way of doing that
> without my module or something equivalent?
> That was my point.

You haven't presented *any* good code or use cases.

> > This is unintuitive, to say the least. You're effectively replacing
> > the common form of function definition with "with when_odd as 'n'",
> > then using the surrounding context manager to limit the scope.
>
> What's so unintuitive about it? It's just "different".

Because under no circumstance does "with function_name as
string_signature" _read_ in an understandable way. It's tortuous
grammar that makes no sense as a context manager. You're asking people
to be constantly aware that there are two completely separate meanings
to 'with x as y'.

> > More importantly, _you're naming your "anonymous" code blocks_, I'm
> > guessing so that func() can choose which ones to use. But if you're
> > naming them, why not just use a function?
>
> I'm creating a dictionary, not naming my blocks just for the sake of it.
> If you use a function, you end up with the solution that you called
> 'bad' and non-pythonic.

What I considered 'bad' was having a _single_ function that takes
_multiple differing collections_ of named functions. Now you've moved
the onus onto the caller to ensure that the function is provided what
it needs in a specific context to do its thing. Rather than overload
one single function and push the complexity out to the caller, why not
have multiple functions with obvious names about what they do that
only take the data they need to act on?

Then again, it's _really difficult_ to tell if something named
'func()' could have a real use like this.

> The problem is always the same. Those functions are defined at the
> module level so name clashing and many other problems are possible.

So define & use a different scope! Thankfully module level isn't the
only one to play with.

> I remember a post on this ng when one would create a list of commands
> and then use that list as a switch table. My module let you do that very
> easily. The syntax is:
>
>      with func() << ':list':
>          with 'arg':
>              cmd_code
>          with 'arg':
>              cmd_code
>          with '':
>              cmd_code

I'm sorry but it is still clear-as-mud what you're trying to show
here. Can you show _one_ practical, real-world, non-toy example that
solves a real problem in a way that Python cannot?
-- 
http://mail.python.org/mailman/listinfo/python-list


Why variable used in list comprehension available outside?

2012-05-02 Thread Peng Yu
Hi,

The following example demonstrates the variable 'v' used in the list
comprehension is accessible out site the list comprehension.

I think that 'v' should be strictly local. Does anybody know where
this behavior is documented and why it is designed this way?

~/linux/test/python/man/library/__buildin__/class/{/iteritems$ cat main1.py
#!/usr/bin/env python

d = {'one': 10, 'two': 20}

for k, v in d.iteritems():
  print k, v
  x=[2*v for v in [1, 2, 3]]
  print x
  print k, v
~/linux/test/python/man/library/__buildin__/class/{/iteritems$ ./main1.py
two 20
[2, 4, 6]
two 3
one 10
[2, 4, 6]
one 3


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


Re: Why variable used in list comprehension available outside?

2012-05-02 Thread Tim Chase
On 05/02/12 19:52, Peng Yu wrote:
> The following example demonstrates the variable 'v' used in the
> list comprehension is accessible out site the list
> comprehension.

It did in Python 2.x but has been fixed in 3.x:

tim@bigbox:~$ python3
Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 42
>>> [x for x in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> x
42
>>>

tim@bigbox:~$ python2.6
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 42
>>> [x for x in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> x
9
>>>


-tkc



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


key/value store optimized for disk storage

2012-05-02 Thread Steve Howell
This is slightly off topic, but I'm hoping folks can point me in the
right direction.

I'm looking for a fairly lightweight key/value store that works for
this type of problem:

  ideally plays nice with the Python ecosystem
  the data set is static, and written infrequently enough that I
definitely want *read* performance to trump all
  there is too much data to keep it all in memory (so no memcache)
  users will access keys with fairly uniform, random probability
  the key/value pairs are fairly homogenous in nature:
keys are <= 16 chars
values are between 1k and 4k bytes generally
  approx 3 million key/value pairs
  total amount of data == 6Gb
  needs to work on relatively recent versions of FreeBSD and Linux

My current solution works like this:

  keys are file paths
  directories are 2 levels deep (30 dirs w/100k files each)
  values are file contents

The current solution isn't horrible, but I'm try to squeeze a little
performance/robustness out of it.  A minor nuisance is that I waste a
fair amount of disk space, since the values are generally less than 4k
in size.  A larger concern is that I'm not convinced that file systems
are optimized for dealing with lots of little files in a shallow
directory structure.

To deal with the latter issue, a minor refinement would be to deepen
the directory structure, but I want to do due diligence on other
options first.

I'm looking for something a little lighter than a full-on database
(either SQL or no-SQL), although I'm not completely ruling out any
alternatives yet.

As I mention up top, I'm mostly hoping folks can point me toward
sources they trust, whether it be other mailing lists, good tools,
etc.  To the extent that this is on topic and folks don't mind
discussing this here, I'm happy to follow up on any questions.

Thanks,

Steve

P.S. I've already found some good information via Google, but there's
a lot of noise out there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: key/value store optimized for disk storage

2012-05-02 Thread Paul Rubin
Steve Howell  writes:
>   keys are file paths
>   directories are 2 levels deep (30 dirs w/100k files each)
>   values are file contents

> The current solution isn't horrible, 

Yes it is ;-)

> As I mention up top, I'm mostly hoping folks can point me toward
> sources they trust, whether it be other mailing lists, good tools,

cdb sounds reasonable for your purposes.  I'm sure there are python
bindings for it.

http://cr.yp.to/cdb.html mentions a 4gb limit (2**32) but I
half-remember something about a 64 bit version.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: key/value store optimized for disk storage

2012-05-02 Thread Terry Reedy

On 5/2/2012 10:14 PM, Steve Howell wrote:

This is slightly off topic, but I'm hoping folks can point me in the
right direction.

I'm looking for a fairly lightweight key/value store that works for
this type of problem:

   ideally plays nice with the Python ecosystem
   the data set is static, and written infrequently enough that I
definitely want *read* performance to trump all
   there is too much data to keep it all in memory (so no memcache)
   users will access keys with fairly uniform, random probability
   the key/value pairs are fairly homogenous in nature:
 keys are<= 16 chars
 values are between 1k and 4k bytes generally
   approx 3 million key/value pairs
   total amount of data == 6Gb
   needs to work on relatively recent versions of FreeBSD and Linux


On my 64bit machine with 64 bit Python, I would consider putting all the 
values in one data file and creating a key:file-offset dict. Each value 
would start with length(value) so that is not needed in memory. The 
dict, once created, could be pickled and unpickled for each run.


--
Terry Jan Reedy

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


Re: key/value store optimized for disk storage

2012-05-02 Thread Tim Chase
On 05/02/12 21:14, Steve Howell wrote:
> I'm looking for a fairly lightweight key/value store that works for
> this type of problem:
> 
>   ideally plays nice with the Python ecosystem
>   the data set is static, and written infrequently enough that I
> definitely want *read* performance to trump all
>   there is too much data to keep it all in memory (so no memcache)
>   users will access keys with fairly uniform, random probability
>   the key/value pairs are fairly homogenous in nature:
> keys are <= 16 chars
> values are between 1k and 4k bytes generally
>   approx 3 million key/value pairs
>   total amount of data == 6Gb
>   needs to work on relatively recent versions of FreeBSD and Linux
[snip]
> I'm looking for something a little lighter than a full-on database
> (either SQL or no-SQL), although I'm not completely ruling out any
> alternatives yet.

This sounds suspiciously like the standard library's anydbm
module[1] which should handle everything you list (though I can't be
positive about the 6Gb bit, though I expect it should be fine; I
can't find any documentation on the limits).

-tkc

[1]
http://docs.python.org/library/anydbm.html



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


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Chris Angelico
On Thu, May 3, 2012 at 3:22 AM, Tomasz Rola  wrote:
> I think you can catch more girls with honey and I'm not sure if I'd like
> to catch those who prefer vinegar. I think we can make it into some kind
> of law, say Angelico-Rola Law (of girlscatching), ok?
>
> "One cannot catch a girl on honey without catching some flies in the
> process."
>
> Or is it a hypothesis?

This has the makings of a publication in a respected scientific
journal, I think. We should totally pursue that... next time we're
bored and have no interesting problems to solve by writing code.

Also, I lolled. :)

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


Re: key/value store optimized for disk storage

2012-05-02 Thread Steve Howell
On May 2, 7:46 pm, Paul Rubin  wrote:
> Steve Howell  writes:
> >   keys are file paths
> >   directories are 2 levels deep (30 dirs w/100k files each)
> >   values are file contents
> > The current solution isn't horrible,
>
> Yes it is ;-)
> > As I mention up top, I'm mostly hoping folks can point me toward
> > sources they trust, whether it be other mailing lists, good tools,
>
> cdb sounds reasonable for your purposes.  I'm sure there are python
> bindings for it.
>
> http://cr.yp.to/cdb.htmlmentions a 4gb limit (2**32) but I
> half-remember something about a 64 bit version.

Thanks.  That's definitely in the spirit of what I'm looking for,
although the non-64 bit version is obviously geared toward a slightly
smaller data set.  My reading of cdb is that it has essentially 64k
hash buckets, so for 3 million keys, you're still scanning through an
average of 45 records per read, which is about 90k of data for my
record size.  That seems actually inferior to a btree-based file
system, unless I'm missing something.

I did find this as follow up to your lead:

http://thomas.mangin.com/data/source/cdb.py

Unfortunately, it looks like you have to first build the whole thing
in memory.




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


Re: key/value store optimized for disk storage

2012-05-02 Thread Paul Rubin
Steve Howell  writes:
> Thanks.  That's definitely in the spirit of what I'm looking for,
> although the non-64 bit version is obviously geared toward a slightly
> smaller data set.  My reading of cdb is that it has essentially 64k
> hash buckets, so for 3 million keys, you're still scanning through an
> average of 45 records per read, which is about 90k of data for my
> record size.  That seems actually inferior to a btree-based file
> system, unless I'm missing something.

1) presumably you can use more buckets in a 64 bit version; 2) scanning
90k probably still takes far less time than a disk seek, even a "seek"
(several microseconds in practice) with a solid state disk.

> http://thomas.mangin.com/data/source/cdb.py
> Unfortunately, it looks like you have to first build the whole thing
> in memory.

It's probably fixable, but I'd guess you could just use Bernstein's
cdbdump program instead.

Alternatively maybe you could use one of the *dbm libraries,
which burn a little more disk space, but support online update.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: John Carmack glorifying functional programing in 3k words

2012-05-02 Thread Chris Angelico
On Thu, May 3, 2012 at 8:04 AM, Michael Torrie  wrote:
> Others who have crossed this list appear to have aspergers or autism
> too, such as Ranting Rick.  He pops up occasionally, posts quite
> normally and even helpfully, and then lapses back into periods of
> ranting about how he can fix python and we all should be doing
> something.  He refuses to write code to put his ideas into practice, and
> berates the list readers for being lazy and unwilling to code this
> ideas.  Then eventually he disappears for months even years at a time
> before resurfacing.  I've always been curious to know more about Rick.
> Where does he work?  How does he live, and what does he do outside of
> the python list (he appears to only use his e-mail address on this list).

My first thought was that he was the alt of some regular poster - that
he's the email account used for trolling, keeping it separate from the
regular address. But that theory hasn't really gained credence.

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


Re: key/value store optimized for disk storage

2012-05-02 Thread William R. Wing (Bill Wing)
On May 2, 2012, at 10:14 PM, Steve Howell wrote:

> This is slightly off topic, but I'm hoping folks can point me in the
> right direction.
> 
> I'm looking for a fairly lightweight key/value store that works for
> this type of problem:
> 
>  ideally plays nice with the Python ecosystem
>  the data set is static, and written infrequently enough that I
> definitely want *read* performance to trump all
>  there is too much data to keep it all in memory (so no memcache)
>  users will access keys with fairly uniform, random probability
>  the key/value pairs are fairly homogenous in nature:
>keys are <= 16 chars
>values are between 1k and 4k bytes generally
>  approx 3 million key/value pairs
>  total amount of data == 6Gb
>  needs to work on relatively recent versions of FreeBSD and Linux
> 


I don't understand that statement, I don't think I agree with it.  I'm writing 
this e-mail on a system with 16 GB of memory.  It is just under 3 years old, 
and if it were purchased today, it would have 32 GB of memory at essentially 
the same price.

I think you might want to re-examine your thinking about the limits of a 
memory-based system.  It could probably be completely written in python and 
still have acceptable performance.

-Bill

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


Re: key/value store optimized for disk storage

2012-05-02 Thread Steve Howell
On May 2, 8:29 pm, Paul Rubin  wrote:
> Steve Howell  writes:
> > Thanks.  That's definitely in the spirit of what I'm looking for,
> > although the non-64 bit version is obviously geared toward a slightly
> > smaller data set.  My reading of cdb is that it has essentially 64k
> > hash buckets, so for 3 million keys, you're still scanning through an
> > average of 45 records per read, which is about 90k of data for my
> > record size.  That seems actually inferior to a btree-based file
> > system, unless I'm missing something.
>
> 1) presumably you can use more buckets in a 64 bit version; 2) scanning
> 90k probably still takes far less time than a disk seek, even a "seek"
> (several microseconds in practice) with a solid state disk.
>

Doesn't cdb do at least one disk seek as well?  In the diagram on this
page, it seems you would need to do a seek based on the value of the
initial pointer (from the 256 possible values):

http://cr.yp.to/cdb/cdb.txt

> >http://thomas.mangin.com/data/source/cdb.py
> > Unfortunately, it looks like you have to first build the whole thing
> > in memory.
>
> It's probably fixable, but I'd guess you could just use Bernstein's
> cdbdump program instead.
>
> Alternatively maybe you could use one of the *dbm libraries,
> which burn a little more disk space, but support online update.

Yup, I don't think I want to incur the extra overhead.  Do you have
any first hand experience pushing dbm to the scale of 6Gb or so?  My
take on dbm is that its niche is more in the 10,000-record range.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python SOAP library

2012-05-02 Thread Alec Taylor
Client and server (unfortunately)

I need to support serialisation between formats

On Thu, May 3, 2012 at 7:24 AM, John Nagle  wrote:
> On 5/2/2012 8:35 AM, Alec Taylor wrote:
>>
>> What's the best SOAP library for Python?
>> I am creating an API converter which will be serialising to/from a variety
>> of sources, including REST and SOAP.
>> Relevant parsing is XML [incl. SOAP] and JSON.
>> Would you recommend: http://code.google.com/p/soapbox/
>>
>> Or suggest another?
>> Thanks for all information,
>
>
>   Are you implementing the client or the server?
>
>   Python "Suds" is a good client-side library. It's strict SOAP;
> you must have a WSDL file, and the XML queries and replies must
> verify against the WSDL file.
>
>    https://fedorahosted.org/suds/
>
>                                                John Nagle
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: syntax for code blocks

2012-05-02 Thread Michael Torrie
On 05/02/2012 04:52 AM, Kiuhnm wrote:
> The problem is always the same. Those functions are defined at the 
> module level so name clashing and many other problems are possible.

Only functions defined at the module level are in fact in the module's
namespace.  For example, this works fine, and the definitions for one
and two are only within their respective scopes:

def other_part():
def one():
pass
def two():
pass

# do something with one and two


def main():
def one():
pass
def two():
pass

# do something with one and two

other_part()

If you are experiencing name clashes you need to start dividing your
code up logically instead of keeping everything in the global namespace
of your module.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a string to list for submission to easygui multenterb​ox

2012-05-02 Thread Chris Angelico
On Thu, May 3, 2012 at 3:57 AM, Laurent Pointal  wrote:
> If you have it as a string, you can use eval() (not safe!) on the string to
> retrieve the tuple, then list() on the tuple to get a list.

Are you saying that eval is not safe (which it isn't), or that it has
to be eval() and not safe_eval() to do this job? There's also
ast.literal_eval which ought to be safe for this situation (I think).

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


Re: syntax for code blocks

2012-05-02 Thread Michael Torrie
On 05/02/2012 10:26 PM, Michael Torrie wrote:
> If you are experiencing name clashes you need to start dividing your
> code up logically instead of keeping everything in the global namespace
> of your module.

I shouldn't have used the word "global" here as it's not actually global.

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


Re: key/value store optimized for disk storage

2012-05-02 Thread Paul Rubin
Steve Howell  writes:
> Doesn't cdb do at least one disk seek as well?  In the diagram on this
> page, it seems you would need to do a seek based on the value of the
> initial pointer (from the 256 possible values):

Yes, of course it has to seek if there is too much data to fit in
memory.  All I'm saying is that if you're spending milliseconds on the
seek, that may dominate the lookup time even if you scan the 90k.

Actually, looking at the spec more closely, there are 256 hash tables in
the file, but each table can be of any size.  So there can be far more
than 2**16 hash slots.  Uncharacteristically for Bernstein, the document
is pretty unclear, so maybe you have to look at the code to be sure of
the layout.  Note also that empty hash buckets have just 2 words of
overhead.  So with 3M keys and 75% load factor, you get 4M buckets and
relatively few collisions.  The extra 1M buckets in a 64 bit
implementation is just 16MB in the file, which isn't much at all even
considering that you want it to stay resident in memory to avoid some
seeks, assuming you're on a PC and not some smaller device like a phone.
(A phone will have a solid state disk eliminating most seek time, so
you're ok in that situation too).

> Yup, I don't think I want to incur the extra overhead.  Do you have
> any first hand experience pushing dbm to the scale of 6Gb or so?  My
> take on dbm is that its niche is more in the 10,000-record range.

There are a bunch of different variants.  I'm trying to remember what
I've personally done with it and I'm sure I've used much more than 10k
records, but maybe not millions.  Unix dbm was originally designed to
handle millions of records back when that was a lot.  I'd expect gdbm,
bsddb and so forth can handle it easily.  The naive Python dbm module
might not be able to.  

The amount of data you're talking about (a few million keys, a few gb of
data) is fairly modest by today's standards, so I would think fancy
methods aren't really needed.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: key/value store optimized for disk storage

2012-05-02 Thread Paul Rubin
Paul Rubin  writes:
>looking at the spec more closely, there are 256 hash tables.. ...

You know, there is a much simpler way to do this, if you can afford to
use a few hundred MB of memory and you don't mind some load time when
the program first starts.  Just dump all the data sequentially into a
file.  Then scan through the file, building up a Python dictionary
mapping data keys to byte offsets in the file (this is a few hundred MB
if you have 3M keys).  Then dump the dictionary as a Python pickle and
read it back in when you start the program.

You may want to turn off the cyclic garbage collector when building or
loading the dictionary, as it badly can slow down the construction of
big lists and maybe dicts (I'm not sure of the latter).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bus errors when the network interface is reset?

2012-05-02 Thread Kushal Kumaran
On Tue, May 1, 2012 at 7:31 PM, David M Chess  wrote:
>
> We have a system running Python 2.6.6 under RHEL 6.1.  A bunch of processes
> spend most of their time sitting in a BaseHTTPServer.HTTPServer waiting for
> requests.
>
> Last night an update pushed out via xcat whimsically restarted all of the
> network interfaces, and at least some of our processes died with bus errors
> (i.e. no errors or exceptions reflected up to the Python level, just a
> crash).
>
> This is just my initial looking into this.  Seeking opinions of the form,
> say:
>
> Yeah, that happens, don't reset the network interfaces.
> Yeah, that happens, and you can prevent the crash by doing X in your OS.
> Yeah, that happens, and you can prevent the crash by doing X in your Python
> code.
> That wouldn't happen if you upgraded S to version V.
> That sounds like a new bug and/or more information is needed; please provide
> copious details including at least X, Y, and Z.
>
> Any thoughts or advice greatly appreciated.
>

Never seen this happen.  Does it matter if your listening socket is
bound to all interfaces v/s bound to a specific interface?  From a
cursory look at the source, SocketServer.TCPServer (which
BaseHTTPServer is derived from) simply does a select, followed by an
accept.  Do any other server applications crash as well?

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