when "normal" parallel computations in CPython will be implemented at last?

2012-07-01 Thread dmitrey
hi all,
are there any information about upcoming availability of parallel
computations in CPython without modules like  multiprocessing? I mean
something like parallel "for" loops, or, at least, something without
forking with copying huge amounts of RAM each time and possibility to
involve unpiclable data (vfork would be ok, but AFAIK it doesn't work
with CPython due to GIL).

AFAIK in PyPy some progress have been done (
http://morepypy.blogspot.com/2012/06/stm-with-threads.html )

Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


why () is () and [] is [] work in other way?

2012-04-20 Thread dmitrey
I have spent some time searching for a bug in my code, it was due to
different work of "is" with () and []:
>>> () is ()
True
>>> [] is []
False

(Python 2.7.2+ (default, Oct  4 2011, 20:03:08)
[GCC 4.6.1] )

Is this what it should be or maybe yielding unified result is better?
D.
-- 
http://mail.python.org/mailman/listinfo/python-list


can I overload operators like "=>", "->" or something like that?

2012-04-19 Thread dmitrey
hi all,
can I somehow overload operators like "=>", "->" or something like
that? (I'm searching for appropriate overload for logical implication
"if a then b")
Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


new release 0.38 of OpenOpt, FuncDesigner, SpaceFuncs, DerApproximator

2012-03-16 Thread dmitrey
Hi all,
I'm glad to inform you about new release 0.38 (2012-March-15):

OpenOpt:

interalg can handle discrete variables
interalg can handle multiobjective problems (MOP)
interalg can handle problems with parameters fixedVars/freeVars
Many interalg improvements and some bugfixes
Add another EIG solver: numpy.linalg.eig
New LLSP solver pymls with box bounds handling

FuncDesigner:

Some improvements for sum()
Add funcs tanh, arctanh, arcsinh, arccosh
Can solve EIG built from derivatives of several functions,
obtained by automatic differentiation by FuncDesigner

SpaceFuncs:

Add method point.symmetry(Point|Line|Plane)
Add method LineSegment.middle
Add method Point.rotate(Center, angle)

DerApproximator:

Minor changes

See http://openopt.org for more details

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


PEP: add __sum__ method

2012-01-22 Thread dmitrey
hi all,
could you consider adding __sum__ method, e.g. Python sum(a) checks
does a have attribute __sum__ and if it has, then a.__sum__() is
invoked instead of Python sum(a).
(for my soft FuncDesigner it would be very essential, I guess for many
other soft as well, e.g. for PuLP, who has to use lpSum, because
ordinary Python sum slows it very much, as well as my funcs, and for
large-scale problems max recursion depth is exeeded).
Regards, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get id(function) for each function in stack?

2012-01-06 Thread dmitrey
On Jan 6, 8:28 pm, Ian Kelly  wrote:
> On Fri, Jan 6, 2012 at 11:02 AM, dmitrey  wrote:
> > hi all,
> > how to get id(func) for each func in stack? (I mean memory address, to
> > compare it with id(some known funcs))
> > Thank you in advance, D.
>
> The answer hasn't changed since your last thread about this.  The
> stack contains code objects, not functions.  You can get the code
> objects using inspect.stack(), and compare them to the func_code
> attributes of the functions you're interested in.
>
> Also, there's no need to use id() for this.  Just use the "is"
> operator to check identity.
>
> for frame_tuple in inspect.stack():
>     frame = frame_tuple[0]
>     if frame.f_code is some_function.func_code:
>         print("Found it!")
>
> Cheers,
> Ian

Python build-in function sum() has no attribute func_code, what should
I do in the case?
D.
-- 
http://mail.python.org/mailman/listinfo/python-list


how to get id(function) for each function in stack?

2012-01-06 Thread dmitrey
hi all,
how to get id(func) for each func in stack? (I mean memory address, to
compare it with id(some known funcs))
Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get function string name from i-th stack position?

2011-12-31 Thread dmitrey
On Dec 30, 11:48 pm, Ian Kelly  wrote:
> On Fri, Dec 30, 2011 at 11:43 AM, dmitrey  wrote:
> > Thank you. And what should I do to get function by itself instead of
> > its string name, e.g. I want to know does this function is my_func or
> > any other? For example, I would like to check is this function Python
> > sum(), or maybe numpy.sum(), or anything else?
>
> The Python stack only includes Python code objects.  Built-ins like
> sum won't appear in it because they're basically C functions and don't
> have associated code objects.  If you really want to see them, you
> could probably do something with ctypes to inspect the C stack, but I
> don't recommend it.
>
> You can get the Python code objects from the stack by calling
> inspect.stack(), which includes each frame object currently on the
> stack as the first member of each tuple.  E.g.:
>
> frames = map(operator.itemgetter(0), inspect.stack())
>
> Each frame has an f_code attribute that stores the code object
> associated with that frame.  Getting the actual function from the code
> object is tricky, for two reasons.  One, not all code objects
> represent functions.  There are also code objects for modules, class
> definitions, and probably other thing as well.  Two, code objects
> don't have associated functions. The relationship is the reverse:
> functions have associated code objects.  You would have to iterate
> over each function that you're interested in, looking for one with a
> func_code attribute that "is" the frame's f_code attribute.
>
> In any case, testing function identity is a rather large rabbit hole
> that is best avoided.  These are mathematically the same function:
>
> def plus1(value):
>     return value + 1
>
> plus_one = lambda x: x + 1
>
> But they are two distinct function objects, and there is no way
> programmatically to determine that they are the same function except
> by comparing the bytecode (which won't work generally because of the
> halting problem).
>
> What is it that you're trying to do?  Perhaps the helpful folks on the
> list will be able to suggest a better solution if you can provide more
> details.
>
> Cheers,
> Ian

Maybe it is somehow possible to compare function id with my candidates
id, e.g.
PythonSumID = id(sum)
import numpy
NumpySumID = id(numpy.sum)
func = getting_function_from_Nth_stack_level_above
if id(func) == PythonSumID:
 
elif id(func) == NumpySumID:
 
else:
 
I need it due to the following reason: FuncDesigner users often use
Python or numpy sum on FuncDesigner objects, while FuncDesigner.sum()
is optimized for this case, works faster and doesn't lead to "Max
recursion dept exceeded", that sometimes trigger for numpy or Python
sum() when number of summarized elements is more than several
hundreds. I would like to print warning "you'd better use FuncDesigner
sum" if this case has been identified.
Regards, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get function string name from i-th stack position?

2011-12-30 Thread dmitrey
On Dec 30, 8:35 pm, Tim Chase  wrote:
> On 12/30/11 11:51, dmitrey wrote:
>
> > how to get string name of a function that is n levels above
> > the current Python interpreter position?
>
> Use the results of traceback.extract_stack()
>
>    from traceback import extract_stack
>    def one(x):
>      print "one", x
>      stk = extract_stack()
>      for mod, lineno, fun_name, call_code_text in stk:
>        print "[%s:%i] in %s" % (mod, lineno, fun_name)
>    def two(x):
>      print "two", x
>      one(x)
>    def three(x):
>      print "three", x
>      two(x)
>    three("Hi")
>
> -tkc

Thank you. And what should I do to get function by itself instead of
its string name, e.g. I want to know does this function is my_func or
any other? For example, I would like to check is this function Python
sum(), or maybe numpy.sum(), or anything else?
Regards, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Ann: OpenOpt and FuncDesigner 0.37

2011-12-15 Thread dmitrey
Hi all,
I'm glad to inform you about new release 0.37 (2011-Dec-15) of our
free software:

OpenOpt (numerical optimization):

IPOPT initialization time gap (time till first iteration) for
FuncDesigner models has been decreased
Some improvements and bugfixes for interalg, especially for
"search all SNLE solutions" mode (Systems of Non Linear Equations)
Eigenvalue problems (EIG) (in both OpenOpt and FuncDesigner)
Equality constraints for GLP (global) solver de
Some changes for goldenSection ftol stop criterion
GUI func "manage" - now button "Enough" works in Python3, but "Run/
Pause" not yet (probably something with threading and it will be fixed
in Python instead)

FuncDesigner:
Major sparse Automatic differentiation improvements for badly-
vectorized or unvectorized problems with lots of constraints (except
of box bounds); some problems now work many times or orders faster (of
course not faster than vectorized problems with insufficient number of
variable arrays). It is recommended to retest your large-scale
problems with useSparse = 'auto' | True| False

Two new methods for splines to check their quality: plot and
residual
Solving ODE dy/dt = f(t) with specifiable accuracy by interalg
Speedup for solving 1-dimensional IP by  interalg

SpaceFuncs and DerApproximator:

Some code cleanup

You may trace OpenOpt development information in our recently created
entries in Twitter and Facebook, see http://openopt.org for details.

For more information visit http://openopt.org

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


multiprocessing module question

2011-12-12 Thread dmitrey
hi all,
suppose I have a func F, list [args1,args2,args3,...,argsN] and want
to obtain r_i = F(args_i) in parallel mode. My difficulty is: if F
returns not None, than I should break calculations, and I can't dig in
multiprocessing module documentation how to do it. Order doesn't
matter for me (I have to find 1st suitable, where result of F is not
None)
Could anyone scribe me an example?
Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] New free multifactor analysis tool for experiment planning

2011-10-24 Thread dmitrey
Hi all,

you may be interested in new free multifactor analysis tool for
experiment planning (in physics, chemistry, biology etc). It is based
on numerical optimization solver BOBYQA, released in 2009 by Michael
J.D. Powell, and has easy and convenient GUI frontend, written in
Python + tkinter. Maybe other (alternative) engines will be available
in future.

See its webpage for details:
http://openopt.org/MultiFactorAnalysis

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


[ANN} OpenOpt, FuncDesigner, DerApproximator, SpaceFuncs release 0.36 Options

2011-09-15 Thread dmitrey
Hi all,
new release of our free scientific soft (OpenOpt, FuncDesigner,
DerApproximator,
SpaceFuncs) v. 0.36 is out:

OpenOpt:

Now solver interalg can handle all types of constraints and
integration problems
Some minor improvements and code cleanup

FuncDesigner:

Interval analysis now can involve min, max and 1-d monotone
splines R -> R of 1st and 3rd order
Some bugfixes and improvements

SpaceFuncs:

Some minor changes

DerApproximator:

Some improvements for obtaining derivatives in points from R^n
where left or right derivative for a variable is absent, especially
for stencil > 1

See http://openopt.org for more details.

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


blist question

2011-07-07 Thread dmitrey
hi all,
I feel lack of native Python lists operations (e.g. taking N greatest
elements with the involved key function and O(n) speed) and
occasionally found blist
http://pypi.python.org/pypi/blist/
Its entry says it is better than Python list. Did anyone ensure?
Will it ever be merged into Python source code?
D.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] OpenOpt Suite release 0.34

2011-06-16 Thread dmitrey
Hi all,
I'm glad to inform you about new quarterly release 0.34 of the free
(even for commercial purposes, license: BSD) cross-platform OOSuite
package software (OpenOpt, FuncDesigner, SpaceFuncs,
DerApproximator),

Main changes:
* Python 3 compatibility
* Lots of improvements and speedup for interval calculations
* Now interalg can obtain all solutions of nonlinear equation
(example) or systems of them (example) in the involved box lb_i <= x_i
<= ub_i (bounds can be very large), possibly constrained (e.g. sin(x)
+ cos(y+x) > 0.5).
* Many other improvements and speedup for interalg.

See http://forum.openopt.org/viewtopic.php?id=425 for more details.

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


[ANN] OpenOpt Suite release 0.34

2011-06-16 Thread dmitrey
Hi all,
I'm glad to inform you about new quarterly release 0.34 of the OOSuite
package software (OpenOpt, FuncDesigner, SpaceFuncs,
DerApproximator) .

Main changes:
* Python 3 compatibility
* Lots of improvements and speedup for interval calculations
* Now interalg can obtain all solutions of nonlinear equation or
systems of them in the involved box lb_i <= x_i <= ub_i (bounds can be
very large), possibly constrained (e.g. sin(x) + cos(y+x) > 0.5).
* Many other improvements and speedup for interalg.

See http://forum.openopt.org/viewtopic.php?id=425 for more details.

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


Re: seems like a bug in isinstance()

2011-05-07 Thread dmitrey
On May 7, 11:53 am, Gregory Ewing  wrote:
> Chris Rebert wrote:
> > This is because you did `from Point import
> > ...` in file2.py, whereas in file1.py you did `from
> > openopt.kernel.Point import ...`. These 2 different ways of referring
> > to the same module are sufficient to "trick"/"outsmart" (C)Python and
> > cause it to import the same module twice
>
> That can't be the whole story, because those two ways of
> referring to the module *should* have returned the same
> module object, even though one is absolute and the other
> relative.
>
> I suspect what's happened is that somehow sys.path contains
> both the directory containing .../openopt *and* the directory
> .../openopt/kernel, and the second import is picking up
> Point.py a second time as though it were a top-level module.
>
> This could have happened by starting an interactive session
> while cd'ed to .../openopt/kernel, or by launching a .py
> file from there as a main script.
>
> The solution is to make sure that sys.path only contains the
> top level directories of the package hierarchy, and doesn't
> also contain any of their subdirectories.
>
> Always using absolute imports may be a good idea stylistically,
> but in this case it will only mask the symptoms of whatever
> is really wrong, and further problems could result from the
> same cause.
>
> --
> Greg

> I suspect what's happened is that somehow sys.path contains
both the directory containing .../openopt *and* the directory
.../openopt/kernel
Yes, you are right. But I have to do it due to another issue I haven't
solved yet: Python3 imports don't see files from same directory
http://groups.google.com/group/comp.lang.python/browse_thread/thread/9470dbdacc138709#

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


Python3: imports don't see files from same directory?

2011-05-07 Thread dmitrey
hi all,
I try to port my code to Python 3 and somehow files don't see files
from same directory, so I have to add those directories explicitly,
e.g.
import sys
sys.path += [...]

Also, it leads to bugs like this one:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/961a90219a61e19d#

any ideas what's the reason and how to fix it?
I have tried to search google but got nothing yet.

Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 dict question

2011-05-06 Thread dmitrey
On May 6, 10:51 pm, Chris Rebert  wrote:
> On Fri, May 6, 2011 at 12:40 PM, dmitrey  wrote:
> > hi all,
> > suppose I have Python dict myDict and I know it's not empty.
> > I have to get any (key, value) pair from the dict (no matter which
> > one) and perform some operation.
> > In Python 2 I used mere
> > key, val = myDict.items()[0]
> > but in Python 3 myDict.items() return iterator.
> > Of course, I could use
> > for key, val in myDict.items():
> >   do_something
> >   break
> > but maybe there is any better way?
>
> key, val = next(myDict.items())
>
> Cheers,
> Chris

Unfortunately, it doesn't work, it turn out to be dict_items:
>>> next({1:2}.items())
Traceback (most recent call last):
  File "", line 1, in 
TypeError: dict_items object is not an iterator
>>> dir({1:2}.items())
['__and__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__gt__',
'__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__',
'__ne__', '__new__', '__or__', '__rand__', '__reduce__',
'__reduce_ex__', '__repr__', '__ror__', '__rsub__', '__rxor__',
'__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__',
'__xor__', 'isdisjoint']
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 3 dict question

2011-05-06 Thread dmitrey
hi all,
suppose I have Python dict myDict and I know it's not empty.
I have to get any (key, value) pair from the dict (no matter which
one) and perform some operation.
In Python 2 I used mere
key, val = myDict.items()[0]
but in Python 3 myDict.items() return iterator.
Of course, I could use
for key, val in myDict.items():
   do_something
   break
but maybe there is any better way?

Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: seems like a bug in isinstance()

2011-05-06 Thread dmitrey
On May 6, 12:57 pm, Chris Rebert  wrote:
> On Fri, May 6, 2011 at 2:24 AM, dmitrey  wrote:
> > hi all,
>
> > suppose I've created a class Point in file .../openopt/kernel/Point.py
>
> > Consider the code in file .../somewhere/file1.py
> > from openopt.kernel.Point import Point
> > p = Point()
>
> > now let's pass p into a func from .../openopt/kernel/file2.py and
> > check
> > from Point import Point
> > isinstance(p, Point)
>
> > So, it returns False!
>
> > p is , while Point is  > openopt.kernel.Point.Point at 0x2048e20>
>
> > [Subject: seems like a bug in isinstance()]
>
> This is due to a peculiarity of how (C)Python's import machinery
> works; isinstance() is working just fine.
> (And if you ever think you've found a bug in Python's built-ins, odds
> are you haven't. Python has been around too long, someone ought to
> have encountered it earlier, statistically speaking.)
>
> Note how the class is referred to as both Point.Point and
> openopt.kernel.Point.Point. This is because you did `from Point import
> ...` in file2.py, whereas in file1.py you did `from
> openopt.kernel.Point import ...`. These 2 different ways of referring
> to the same module are sufficient to "trick"/"outsmart" (C)Python and
> cause it to import the same module twice as 2 separate instances (i.e.
> it gets re-executed). Why the import machinery isn't smarter in this
> situation, I don't recall.
>
> The output of this should be illuminating:
> print(Point, type(p), type(p) is Point, id(Point), id(type(p)))
> As this demonstrates, you're dealing with 2 separate definitions of
> the same Point class.
>
> Solution: Avoid the implicitly-relative `from Point import ...` style
> of import; always use the absolute `from openopt.kernel.Point import
> ...` style instead. Subsequent imports will thus reference the
> already-previously-imported instance of a module rather than importing
> a copy of it from scratch again.
>
> Cheers,
> Chris
> --http://rebertia.com

Thanks Cris, however, I had understood reason of the bug and mere
informed Python developers of the bug to fix it.

>>> print(Point, type(p), type(p) is Point, id(Point), id(type(p)))
(, ,
False, 44211536, 8585344)

The proposed solution of using `from openopt.kernel.Point import ... '
everywhere is already performed but is not nice for me. I have lots of
places like that in my code; also, when I import something from
openopt it performs recursive import of many files including that one
where Point is defined, thus I have cycled imports (well, it somehow
works, but is unstable and may lead to future bugs). Also, writing
"from Point import Point" is much simpler than using each time the
long string "from name1.name2.Point import Point". I think it's Python
developers who have to fix the issue, not users. I have 5 years of
intensive Python experience yet it took same time to me to locate the
bug, because my algorithm got "False" from isinstance() and went
absolutely different thread from "if isinstance(): ... else: ...".
This bug could be encountered very seldom under rare circumstances and
thus be quite difficult to be located, especially for Python newbies
unawared of this one.

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


seems like a bug in isinstance()

2011-05-06 Thread dmitrey
hi all,

suppose I've created a class Point in file .../openopt/kernel/Point.py

Consider the code in file .../somewhere/file1.py
from openopt.kernel.Point import Point
p = Point()

now let's pass p into a func from .../openopt/kernel/file2.py and
check
from Point import Point
isinstance(p, Point)

So, it returns False!

p is , while Point is 

I have Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
D.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] OpenOpt Suite release 0.33

2011-03-16 Thread dmitrey
Hi all, I'm glad to inform you about new release 0.33 of our
completely free (license: BSD) cross-platform software:

OpenOpt:

* cplex has been connected
* New global solver interalg with guarantied precision, competitor
to LGO, BARON, MATLAB's intsolver and Direct (also can work in inexact
mode)
* New solver amsg2p for unconstrained medium-scaled NLP and NSP

FuncDesigner:

* Essential speedup for automatic differentiation when vector-
variables are involved, for both dense and sparse cases
* Solving MINLP became available
* Add uncertainty analysis
* Add interval analysis
* Now you can solve systems of equations with automatic
determination is the system linear or nonlinear (subjected to given
set of free or fixed variables)
* FD Funcs min and max can work on lists of oofuns
* Bugfix for sparse SLE (system of linear equations), that slowed
down computation time and demanded more memory
* New oofuns angle, cross
* Using OpenOpt result(oovars) is available, also, start points
with oovars() now can be assigned easier

SpaceFuncs (2D, 3D, N-dimensional geometric package with abilities for
parametrized calculations, solving systems of geometric equations and
numerical optimization with automatic differentiation):

* Some bugfixes

DerApproximator:

* Adjusted with some changes in FuncDesigner

For more details visit our site http://openopt.org.

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


[ANN] New package: SpaceFuncs (2D, 3D, ND geometric modeling, optimization, solving)

2011-02-16 Thread dmitrey
Hi all,
I'm glad to inform you about new, 4th OpenOpt Suite module:

SpaceFuncs - a tool for 2D, 3D, N-dimensional geometric modeling with
possibilities of parametrized calculations, numerical optimization and
solving systems of geometrical equations.

For details see its home page
http://openopt.org/SpaceFuncs
and documentation
http://openopt.org/SpaceFuncsDoc

The module is written in Python + NumPy, requires FuncDesigner (and
OpenOpt, DerApproximator for some operations). It has completely free
license: BSD.

Also, you can try it online via our Sage-server
http://sage.openopt.org/welcome

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


Re: PEP: possibility of inline using of a symbol instead of "import"

2011-01-06 Thread dmitrey
On Jan 6, 8:43 pm, Erwin Mueller  wrote:
>
> Why you have several pages of code in the first place? Don't you know that you
> can split your code in files? Just a suggestion.
>
> --
> Erwin Mueller, dev...@deventm.orghttp://www.global-scaling-institute.de/

Erwin, take a look at Python language developers source code and see
how many files have *tens* of pages. Or any other mature soft, e.g.
numpy or scipy.
Also, possibility of splitting *my* files doesn't matter I can split
other files I deal with, e.g. written by other programmers.
D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP: possibility of inline using of a symbol instead of "import"

2011-01-06 Thread dmitrey
Yes, I know, still usually it is placed in file header
On Jan 6, 5:57 pm, Tim Harig  wrote:

> Python doesn't require imports to be at the top of a file.  They can be
> imported at any time.
>
> > import MyModule
> > (...lots of code...)
> > r = MyModule.myFunc(...)
>
> (...lots of code...)
> import MyModule
> r = MyModule.myFunc(...)

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


PEP: possibility of inline using of a symbol instead of "import"

2011-01-06 Thread dmitrey
hi all,
I have th PEP (I'm not sure something like that hadn't been proposed
although):
very often in a Python file header the following lines are present,
like:
from MyModule1 import myFunc1
import MyModule2 as mm2
from MyModule3 import myFunc3 as mf3
etc

and after several pages of code they are using somewhere, maybe only
one time, e.g.
r1 = myFunc1(...)
r2 = mm2.myFunc2(...)
r3 = mf3(...)
It makes programs less clear, you have to scroll several pages of code
in IDE to understand what it refers to.

I propose to add possibility of using a symbol instead (for simplicity
I use @ here, that is already reserved for decorators, thus it should
be other symbol, maybe from Unicode although for simplicity to type it
I would prefer something ordinary like $ or ` or !).

e.g. instead of

import MyModule
(...lots of code...)
r = MyModule.myFunc(...)

someone could just type in the single place

r = @MyModule.myFunc(...)

Also, "import MyModule2 as mm2" could be replaced to mere
mm2 = @MyModule2
and "from MyModule3 import myFunc3 as mf3" could be replaced to mere
"mf3 = @MyModule3.myFunc3".

As for __import__(ModuleTextName), it could be replaced to something
like @(ModuleTextName) or @{ModuleTextName} or @[ModuleTextName].

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


New OpenOpt/FuncDesigner release 0.32

2010-12-15 Thread dmitrey
Hi all,
I'm glad to inform you about new quarterly OpenOpt/FuncDesigner
release (0.32):

OpenOpt:
* New class: LCP (and related solver)
* New QP solver: qlcp
* New NLP solver: sqlcp
* New large-scale NSP (nonsmooth) solver gsubg. Currently it still
requires lots of improvements (especially for constraints - their
handling is very premature yet and often fails), but since the solver
sometimes already works better than ipopt, algencan and other
competitors it was tried with, I decided to include the one into the
release.
* Now SOCP can handle Ax <= b constraints (and bugfix for handling lb
<= x <= ub has been committed)
* Some other fixes and improvements

FuncDesigner:
* Add new function removeAttachedConstraints
* Add new oofuns min and max (their capabilities are quite restricted
yet)
* Systems of nonlinear equations: possibility to assign personal
tolerance for an equation
* Some fixes and improvements

For more details see our forum entry
http://forum.openopt.org/viewtopic.php?id=325

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


Re: namespace issue, Python vs numpy min/max problem

2010-11-13 Thread dmitrey
Well, I think I have found an appropriate solution.
Regards, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


namespace issue, Python vs numpy min/max problem

2010-11-13 Thread dmitrey
hi all,
I have the following problem:
I have overloaded "max" function in my module (FuncDesigner); it works
like following:
if some data in arguments is of type "oofun" then my function works,
elseware numpy.max() is used.

Now the problem:
suppose someone writes
from FuncDesigner import *
...
a = max(0,1)

so it calls FuncDesigner, it calls numpy.max and result is 0 (because
in numpy it means "max of array with single element 0 along 1st
axis").
But if user has not imported numpy then he expected calling ordinary
Python max and thus result to be "1".

Is there any way to get rid of the problem (somehow automatically
determine which func should be used - numpy or Python max)? The same
issue with "min", but they are equivalent, of course.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: OpenOpt 0.31, FuncDesigner 0.21, DerApproximator 0.21

2010-09-15 Thread dmitrey
Hi all,

I'm glad to inform you about new releases of our completely free (BSD
license) cross-platform software, written using Python language and
NumPy:
OpenOpt 0.31 (numerical optimization), FuncDesigner 0.21 (automatic
differentiation, modelling, interpolation, integration),
DerApproximator 0.21 (finite-differences derivatives approximation).

For release details see
http://forum.openopt.org/viewtopic.php?id=299
or visit our homepage
http://openopt.org

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


Re: Create child class of Python dict with modified values

2010-08-09 Thread dmitrey
On Aug 9, 1:38 pm, Peter Otten <__pete...@web.de> wrote:
> dmitrey wrote:
> > hi all,
> > suppose I have defined a child class of Python dict, currently it
> > constructor looks like that:
> >     def __init__(self, *args, **kwargs):
> >         dict.__init__(self, *args, **kwargs)
> >         #(+some more insufficient code)
>
> > Constructor should be capable of calling with either any way Python
> > dict is constructed or with a Python dict instance to be derived from;
> > calculations speed is important.
>
> > So it works well for now, but I want __init__ to set modified values,
> > like this:
> > values_of_the_dict = [some_func(elem) for elem in self.values()]
>
> > How this could be done?
> >>> class D(dict):
>
> ...     def __init__(self, *args, **kw):
> ...             if args:
> ...                     args = ((k, v.upper()) for k, v in args[0]),
> ...             if kw:
> ...                     for k in kw: kw[k] = 10*kw[k]
> ...             dict.__init__(self, *args, **kw)
> ...>>> D(["ab", "cd"], e="f")
>
> {'a': 'B', 'c': 'D', 'e': 'ff'}
>
> Replace v.upper() and 10*kw[k] with the appropriate some_func() calls.

OK, thank you.

> Personally I would apply the function before passing the data to the dict
> subclass.

It's impossible for the situation in hand.

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


Create child class of Python dict with modified values

2010-08-09 Thread dmitrey
hi all,
suppose I have defined a child class of Python dict, currently it
constructor looks like that:
def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)
#(+some more insufficient code)

Constructor should be capable of calling with either any way Python
dict is constructed or with a Python dict instance to be derived from;
calculations speed is important.

So it works well for now, but I want __init__ to set modified values,
like this:
values_of_the_dict = [some_func(elem) for elem in self.values()]

How this could be done?

Thank you in advance,
Dmitrey.

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


Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread dmitrey
On 20 июл, 18:39, Neil Cerutti  wrote:
> On 2010-07-20, dmitrey  wrote:
>
> > This doesn't stack with the following issue: sometimes user can
> > write in code "myObject.size = (some integer value)" and then
> > it will be involved in future calculations as ordinary fixed
> > value; if user doesn't supply it, but myObject.size is involved
> > in calculations, then the oofun is created to behave like
> > similar numpy.array attribute.
>
> Telling them, "Don't do that," is a good solution in Python.
>
> --
> Neil Cerutti

But this is already documented feature, and it works as intended, so
moving it into something like "myObject._size" will bring backward
incompatibility and break all FuncDesigner user API and style, where
no underlines are present, it will seem like a hack that it really
is.

Sometimes apriory knowing size value as fixed integer brings some code
speedup, also, if a user supplies the value, a check for computed
value wrt the provided size is performed each time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread dmitrey
> e.g. one that just looks in the object's dictionary so as to avoid returning 
> true for properties or other such fancy attributes.

So can anyone explain me how to look into object's dict? As I have
wrote, "something in dir(...)" requires O(numOfFields) while I would
like to use o(log(n))

>How about using a property instead of the __getattr__() hook? A property is a 
>computed attribute that (among other things) plays much nicer with hasattr.

Could anyone provide an example of it to be implemented, taking into
account that a user can manually set "myObject.size" to an integer
value?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread dmitrey
On 20 июл, 15:00, Jean-Michel Pichavant 
wrote:
> dmitrey wrote:
> > hi all,
> > I have a class (FuncDesigner oofun) that has no attribute "size", but
> > it is overloaded in __getattr__, so if someone invokes
> > "myObject.size", it is generated (as another oofun) and connected to
> > myObject as attribute.
>
> > So, when I invoke in other code part "hasattr(myObject, 'size')",
> > instead o returning True/False it goes to __getattr__ and starts
> > constructor for another one oofun, that wasn't intended behaviour.
> > Thus "hasattr(myObject, 'size')" always returns True. It prevents me
> > of some bonuses and new features to be done in FuncDesigner.
>
> >>>> 'size' in dir(b)
>
> > False
>
> >>>> hasattr(b,'size')
>
> > True
>
> >>>> 'size' in dir(b)
>
> > True
>
> > Could you fix it?
>
> Quite simple, when calling b.size, return the computed value but do not
> set it as attribute, the value will be computed on each b.size call, and
> hasattr w. If you don't want to compute it each time, cause there no
> reason for it to change, use a private dummy attribute to record the
> value instead of size (__size for instance) and return the value of
> __size when getting the value of size.
>
> class Foo(object):
>     def __init__(self):
>         self.__size = None
>
>     def __getattr__(self, name):
>         if name == "size":
>             if self.__size is None:
>                 self.__size = 5 # compute the value
>             return self.__size
>         raise AttributeError(name)
>
> b = Foo()
> print 'size' in dir(b)
> print hasattr(b, 'size')
> print 'size' in dir(b)
>
> False
> True
> False
>
> JM

This doesn't stack with the following issue: sometimes user can write
in code "myObject.size = (some integer value)" and then it will be
involved in future calculations as ordinary fixed value; if user
doesn't supply it, but myObject.size is involved in calculations, then
the oofun is created to behave like similar numpy.array attribute.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread dmitrey
On Jul 20, 1:37 pm, Chris Rebert  wrote:
> On Tue, Jul 20, 2010 at 3:10 AM, dmitrey  wrote:
> > hi all,
> > I have a class (FuncDesigner oofun) that has no attribute "size", but
> > it is overloaded in __getattr__, so if someone invokes
> > "myObject.size", it is generated (as another oofun) and connected to
> > myObject as attribute.
>
> > So, when I invoke in other code part "hasattr(myObject, 'size')",
> > instead o returning True/False it goes to __getattr__ and starts
> > constructor for another one oofun, that wasn't intended behaviour.
> > Thus "hasattr(myObject, 'size')" always returns True. It prevents me
> > of some bonuses and new features to be done in FuncDesigner.
>
> >>>> 'size' in dir(b)
> > False
> >>>> hasattr(b,'size')
> > True
> >>>> 'size' in dir(b)
> > True
>
> > Could you fix it?
>
> There's probably some hackery you could do to check whether hasattr()
> is in the call stack, and then not dynamically create the attribute in
> __getattr__ if that's the case, but that's obviously quite kludgey.

It's too unreliable solution, hasattr may or may not appear in stack
wrt different cases

> /Slightly/ less hackish: Replace hasattr() in the __builtin__ module
> with your own implementation that treats instances of FuncDesigner
> specially.

It's too unreliable as well

> Least ugly suggestion: Just don't use hasattr(); use your `x in
> dir(y)` trick instead.

something in dir() consumes O(n) operations for lookup, while hasattr
or getattr() require O(log(n)). It matters for me, because it's inside
deeply nested mathematical computations FuncDesigner is made for.

>
> > Subject: [...] I think this is Python bug
>
> Nope, that's just how hasattr() works. 
> Seehttp://docs.python.org/library/functions.html#hasattr(emphasis mine):
> """
> hasattr(object, name)
>     The arguments are an object and a string. The result is True if
> the string is the name of one of the object’s attributes, False if
> not. (***This is implemented by calling getattr(object, name)*** and
> seeing whether it raises an exception or not.)
> """

Thus I believe this is very ugly implementation. Some code implemented
via "__getattr__" can start to execute arbitrary Python code, that is
certainly not desired behaviour "hasattr" was designed for (to perform
a check only), and it's too hard to reveal the situations, that makes
a potential holes for viruses etc.

Moreover, the implementation via "try getattr(object, name)" slowers
code evaluation, I wonder why it is implemented so.

>
> I suppose you could argue for the addition of a __hasattr__ special
> method, but this seems like a really rare use case to justify adding
> such a method (not to mention the language change moratorium is still
> currently in effect).

I think much more easier solution would be to implement an additional
argument to hasattr, e.g. hasattr(obj, field,
onlyLookupInExistingFields = {True/False}). I think by default it's
better set to True, now it behaves like False.

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


hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread dmitrey
hi all,
I have a class (FuncDesigner oofun) that has no attribute "size", but
it is overloaded in __getattr__, so if someone invokes
"myObject.size", it is generated (as another oofun) and connected to
myObject as attribute.

So, when I invoke in other code part "hasattr(myObject, 'size')",
instead o returning True/False it goes to __getattr__ and starts
constructor for another one oofun, that wasn't intended behaviour.
Thus "hasattr(myObject, 'size')" always returns True. It prevents me
of some bonuses and new features to be done in FuncDesigner.

>>> 'size' in dir(b)
False
>>> hasattr(b,'size')
True
>>> 'size' in dir(b)
True

Could you fix it?
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] OpenOpt 0.29, FuncDesigner 0.19, DerApproximator 0.19

2010-06-16 Thread dmitrey
Hi all,
I'm glad to inform you about new release of the free cross-platform
(Linux, Windows, Mac etc) software (numerical optimization, linear/
nonlinear/ODE systems, automatic differentiation, etc), that is
written in Python language and released quarterly since 2007.

For more details see
http://forum.openopt.org/viewtopic.php?id=252

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


Bug in Python set

2010-05-02 Thread dmitrey
Python 2.6.5 r265:79063
>>>set().update(set()) is None
True
while I expect result of update to be set.
Also, result of
set().add(None)
is None while I expect it to be set with element None (or, maybe, it
should be empty set?)

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


[ANN] OpenOpt 0.28, FuncDesigner 0.18, DerApproximator 0.18

2010-03-15 Thread dmitrey
Hi all,
I'm glad to inform you about new release of our free (BSD-licensed)
soft OpenOpt 0.28 (numerical optimization), FuncDesigner 0.18 (CAS
with automatic differentiation), DerApproximator 0.18 (finite-
differeces derivatives approximation).

More details here:
http://forum.openopt.org/viewtopic.php?id=222

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


Re: remote evaluation of Python code typed in html webpage frame

2010-01-15 Thread dmitrey
Thank you for the link, but I meant what is appropriate soft to be
installed on my server to do things like that.
Also, for my purposes it's better to have some text with possibility
of reexecuting after some minor code changes than python interpreter
command prompt.
Regards, D.

On 15 янв, 16:41, "Diez B. Roggisch"  wrote:
> Am 15.01.10 15:16, schrieb dmitrey:
>
> > hi all,
> > what's the simplest way to create a webpage with a frame for Python
> > code to be typed in (as a plain text, or, better, as a highlighted
> > text or something like scite or any other easy python IDE, capable of
> > automatic indentations), and then pressing a button to evaluate it
> > using a remote server?
>
> > Thank you in advance, D.
>
> http://try-python.mired.org/
>
> Diez

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


remote evaluation of Python code typed in html webpage frame

2010-01-15 Thread dmitrey
hi all,
what's the simplest way to create a webpage with a frame for Python
code to be typed in (as a plain text, or, better, as a highlighted
text or something like scite or any other easy python IDE, capable of
automatic indentations), and then pressing a button to evaluate it
using a remote server?

Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] OpenOpt 0.27 (optimization), FuncDesigner 0.17 (auto differentiation)

2009-12-16 Thread dmitrey
Hi all,
I'm glad to inform you about release of OpenOpt 0.27 (numerical
optimization framework), FuncDesigner 0.17 (CAS with automatic
differentiation, convenient modelling of linear/nonlinear functions,
can use convenient modelling for some OpenOpt optimization problems
and systems of linear/nonlinear equations, possibly sparse or
overdetermined), DerApproximator 0.17 (finite-differences derivatives
approximation, get or check user-supplied).

These packages are written in Python language + NumPy; license BSD
allows to use it in both free and closed-code soft

See changelog for details: http://openopt.org/Changelog

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


__mul__ vs __rmul__ (and others) priority for different classes

2009-12-11 Thread dmitrey
hi all,
I have created a class MyClass and defined methods like __add__,
__mul__, __pow__, __radd__, __rmul__ etc.
Also, they are defined to work with numbers, Python lists and
numpy.arrays.

Both Python lists and numpy arrays have their own methods __add__,
__mul__, __pow__, __radd__, __rmul__ etc.
If I involve myPythonList * myClassInstance it returns just result of
my __rmul__; but when I invoke nuumpy_arr*myClassInstance it returns
another numpy array with elements [nuumpy_arr[0]*myClassInstance,
nuumpy_arr[1]*myClassInstance, ...].

Can I somehow prevent numpy array of using it __mul__ etc methods?
(and use only my __rmul__, __radd__, etc instead)?

Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Solving System of Linear Equation (SLE) - FuncDesigner example

2009-10-25 Thread dmitrey
Hi all,
I would like to introduce a couple examples of easy & convenient
modelling and solving System of Linear Equation (SLE) by FuncDesigner
(a python-written tool, BSD license). It doesn't require to construct
matrices A and b (Ax = b) by user, they are created automatically. See
here for details:
http://openopt.org/FuncDesignerDoc#Solving_systems_of_linear_equations
Currently the only one solver available is numpy.linalg.solve (LAPACK
routine dgesv, dense systems only); I intend to add some more solvers,
maybe for sparse matrices as well, in future.
Regards, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: FuncDesigner 0.15 - free Python-written framework with automatic differentiation

2009-09-15 Thread dmitrey
FuncDesigner is cross-platform (Windows, Linux, Mac OS etc) Python-
written framework with automatic differentiation (http://
en.wikipedia.org/wiki/Automatic_differentiation). License BSD allows
to use it in both open- and closed-code soft. It has been extracted
from OpenOpt framework as a stand-alone package, still you can easily
optimize models written in FuncDesigner by OpenOpt (some examples
here: http://openopt.org/NumericalOptimizationForFuncDesignerModels)

For more details see
http://openopt.org/FuncDesigner
http://forum.openopt.org/viewtopic.php?id=141

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


ANN: OpenOpt 0.25 - free Python-written numerical optimization framework with automatic differentiation

2009-09-15 Thread dmitrey
OpenOpt is cross-platform (Windows, Linux, Mac OS etc) Python-written
framework. If you have a model written in FuncDesigner (http://
openopt.org/FuncDesigner), you can get 1st derivatives via automatic
differentiation (http://en.wikipedia.org/wiki/
Automatic_differentiation) (some examples here:
http://openopt.org/NumericalOptimizationForFuncDesignerModels).

License BSD allows to use it in both open- and closed-code soft.

For more details see
http://openopt.org/
http://forum.openopt.org/viewtopic.php?id=141

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


simplest way to visit 3 subdirectories with a command?

2009-08-18 Thread dmitrey
hi all,
could you inform how to compose a py-file (for soft installation),
that will visit 3 subdirectories (eg subdir1, subdir2, subdir3) and
invoke a command "python setup.py install" in each subdirectory?
I know there should be a simple solution available in Python
documentation, but I have an awful lots of other things to be done, so
could someone write these several lines of code?

Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "for" cycle with assigning index

2009-08-15 Thread dmitrey
Thanks all, especially Dennis for your detailed answer.
left_arr_indexes is list of nonnegative integers, eg [0,0,0,1,1,4]
IndDict is a dict like {0: [1,2], 3: [0,1], 10:[0,2,3]}, so that's why
I don't use python list instead.
The code is taken from OpenOpt framework that I develop. Currently I
have implemented another workaround but the solution you proposed can
be used in other parts of code.
Regards, D.

On Aug 16, 4:23 am, Dennis Lee Bieber  wrote:
> On Sat, 15 Aug 2009 13:22:08 -0700, Dennis Lee Bieber
>  declaimed the following in
> gmane.comp.python.general:
>
>         Okay -- my lack of experience with lambda shows... forgot to guard
> the intermediates...
>
> > > for i in xrange(len(Funcs2)):
> > >      Funcs.append(lambda i=i,*args, **kwargs: (Funcs2[i](*args,
> > > **kwargs)[IndDict[left_arr_indexes[i]]]))
>
> > > I get "list indices must be integers, not dict" (and i is equal to
> > > Python dictionary, that is Funcs2)
>
>         So... with the following assumptions (and ignoring all the other
> respondents )...
>
> 1)      Funcs2 IS a dictionary keyed by sequential integers starting at 0
> 2)      Order in Funcs matters; that is, the first element of the list must
> align with the element of the dictionary having key "0"
> 3)      IndDict and left_arr_indexes DO NOT CHANGE CONTENT after the loop
> runs
> 4)      left_arr_indexes is at least as long as Funcs2
>
> assert (min(Funcs2.keys()) == 0
>                         and
>                 max(Funcs2.keys()) == (len(Funcs2) - 1))        #1
> assert len(left_arr_indexes) >= len(Funcs2)          #4
>
> Funcs = [None] * len(Funcs2)                                            #2a
> for ki, fv in Funcs2.items():   #ki->key as index; fv->function value
>         ritmp = IndDict[left_arr_indexes[ki]]                           #3
>         Funcs[ki] = (lambda ri=ritmp, fn=fv, *args, **kwargs:
>                                         (fn(*args, **kwargs)[ri])             
>           #2b
>
> ri and fn used to protect the intermediates, ritmp and fv, from changes
>
> 2a is needed as the order of .items() is undefined, so .append() can not
> be used. This presets the result list size permitting direct indexing
> (2b) to fill slots in order.
>
> #1 can still fail itself if a key is NOT an integer (what is the min()
> of 0 and "a")
>
>         I still don't know if IndDict is really a list or a dictionary, nor
> what left_array_indexes contains (by name, it is a list of values to
> index into another list -- but could be a list of keys to access a
> dictionary)
>
>         And I'll reiterate: if you are using dictionaries in which the keys
> are sequential integers starting at 0... Replace them with simple
> lists...
> --
>         Wulfraed         Dennis Lee Bieber               KD6MOG
>         wlfr...@ix.netcom.com      HTTP://wlfraed.home.netcom.com/

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


"for" cycle with assigning index

2009-08-15 Thread dmitrey
Hi all,
could you inform me how to do it properly?

I have the cycle

for i in xrange(len(Funcs2)): # Funcs2 is Python dict
 Funcs.append(lambda *args, **kwargs: (Funcs2[i](*args, **kwargs)
[IndDict[left_arr_indexes[i]]]))

So, all the Funcs are initialized with i = last index = len(Funcs2)

When I involve

for i in xrange(len(Funcs2)):
 Funcs.append(lambda i=i,*args, **kwargs: (Funcs2[i](*args,
**kwargs)[IndDict[left_arr_indexes[i]]]))

I get "list indices must be integers, not dict" (and i is equal to
Python dictionary, that is Funcs2)

So, how to do it correctly?
Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: for key, value in dict.() - how to get? (which func)

2009-08-11 Thread dmitrey
Yes, thank you, items() is the correct approach, on the other hand I
have already get rid of the cycle.
Regards, D.

On Aug 11, 10:26 pm, "Rami Chowdhury" 
wrote:
> Hi Dmitrey,
>
> I think what you're looking for is myDict.items(), or myDict.iteritems().
>
> Cheers,
> Rami
>
> On Tue, 11 Aug 2009 12:15:13 -0700, dmitrey   
> wrote:
>
>
>
> > hi all,
> > which method should I use to get iterator over (key, value) pairs for
> > Python dict, Python v 2.6 and above?
>
> > Of course I could use
>
> > for key in myDict.keys():
> >     value = myDict.values()
> >     # do something with the pair key, value
>
> > but searching each time for the value take some cputime that is
> > serious for the task involved
>
> > IIRC in python 2.5 I have something like keyvalues(), but I don't see
> > something like that in current dir(myDict).
>
> > Thank you in advance, D.
>
> --
> Rami Chowdhury
> "Never attribute to malice that which can be attributed to stupidity" --  
> Hanlon's Razor
> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

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


for key, value in dict.() - how to get? (which func)

2009-08-11 Thread dmitrey
hi all,
which method should I use to get iterator over (key, value) pairs for
Python dict, Python v 2.6 and above?

Of course I could use

for key in myDict.keys():
value = myDict.values()
# do something with the pair key, value

but searching each time for the value take some cputime that is
serious for the task involved

IIRC in python 2.5 I have something like keyvalues(), but I don't see
something like that in current dir(myDict).

Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is it possible to overload operator "^"?

2009-08-08 Thread dmitrey
> the operator precedence will seem wrong
So, are there any ways to change operator precedence (for my class)?

To Diez:
yes, but I haven't paid attention to xor. BTW the url is currently
unavailable (Network Timeout. The server at docs.python.org is taking
too long to respond.).

On Aug 8, 12:06 pm, "Diez B. Roggisch"  wrote:
> Did you read the link I gave you for your last question?
> It shows __xor__ as special method.
> Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


is it possible to overload operator "^"?

2009-08-08 Thread dmitrey
hi all,
is it possible to overload operator "^"? (AFAIK __pow__ overloads **
instead of ^)
Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


how to overload operator "< <" (a < x < b)?

2009-08-07 Thread dmitrey
hi all,
is it possible to overload operator "<  <"? (And other like this one,
eg "<=  <=", ">  >", ">=  >=")
Any URL/example?
Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: openopt 0.24 - free numerical optimization framework

2009-06-15 Thread dmitrey
Hi all,
OpenOpt 0.24, a free Python-written numerical optimization framework
with some own solvers and connections to tens of 3rd party ones, has
been released.

BSD license allows to use it in both free opensource and commercial
closed-code software.

Currently we have ~80 unique visitors daily, 15% of the ones visit
installation webpage, and some more install it via PYPI, Debian and
Alt Linux repository, mac.softpedia.com, darwinports.com,
pythonxy.com, mloss.org.

Our homepage:
http://openopt.org

Introduction to the framework:
http://openopt.org/Foreword

All release details are here:
http://openopt.org/Changelog
or
http://forum.openopt.org/viewtopic.php?id=110

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


easiest way to check python version?

2009-06-10 Thread dmitrey
hi all,
what is easiest way  to check python version (to obtain values like
2.4, 2.5, 2.6, 3.0 etc) from Python env?
I don't mean "python -V" from command prompt.
Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: OpenOpt 0.23 - free numerical optimization framework

2009-03-15 Thread dmitrey
Hi all,
OpenOpt 0.23, a free numerical optimization framework (license: BSD)
with some own
solvers and connections to tens of 3rd party ones, has been released.

Our new homepage:
http://openopt.org

Introduction to the framework:
http://openopt.org/Foreword

All release details are here:
http://openopt.org/Changelog
or
http://forum.openopt.org/viewtopic.php?id=58

Special thanks to Stepan Hlushak for writing GLP (global) solver
"de" ("differential evolution").

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


multiprocessing module - isn't it a bug?

2009-03-14 Thread dmitrey
# THIS WORKS OK
from multiprocessing import Pool
N = 400
K = 800
processes = 2

def costlyFunction2(z):
r = 0
for k in xrange(1, K+2):
r += z ** (1 / k**1.5)
return r

class ABC:
def __init__(self): pass
def testParallel(self):
po = Pool(processes=processes)
r = po.map(costlyFunction2, xrange(N), chunksize = N/
(10*processes))
A=ABC()
A.testParallel()
print 'done'

# But when I define costlyFunction2 inside of class, it doesn't work:
from multiprocessing import Pool
N = 400
K = 800
processes = 2
class ABC:
def __init__(self): pass
def testParallel(self):
po = Pool(processes=processes)
def costlyFunction2(z):
r = 0
for k in xrange(1, K+2):
r += z ** (1 / k**1.5)
return r
r = po.map(costlyFunction2, xrange(N), chunksize = N/
(10*processes))
A=ABC()
A.testParallel()
print 'done'

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.6/threading.py", line 522, in
__bootstrap_inner
self.run()
  File "/usr/lib/python2.6/threading.py", line 477, in run
self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in
_handle_tasks
put(task)
PicklingError: Can't pickle : attribute lookup
__builtin__.function failed

This doesn't work for
costlyFunction2 = lambda x: 11
as well; and it doesn't work for imap, apply_async as well (same
error).
So, isn't it a bug, or it can be somehow fixed?
Thank you in advance, D.
--
http://mail.python.org/mailman/listinfo/python-list


[numerical optimization] Poll "what do you miss in OpenOpt framework"

2009-02-26 Thread dmitrey
Hi all,
I created a poll "what do you miss in OpenOpt framework", could you
take participation?

http://www.doodle.com/participation.html?pollId=a78g5mk9sf7dnrbe

Let me remember for those ones who is not familiar with OpenOpt - it's
a free Python-written numerical optimization framework:

http://openopt.org

I intend to take you opinions into account till next OpenOpt release
0.23 (2009-03-15)

Thank you in advance,
Dmitrey
--
http://mail.python.org/mailman/listinfo/python-list


OpenOpt 0.21 (free optimization framework)

2008-12-15 Thread dmitrey
Hi all,
OpenOpt 0.21, free optimization framework (license: BSD) with some own
solvers and connections to tens of 3rd party ones, has been released.

All details here:

http://openopt.blogspot.com/2008/12/openopt-release-021.html

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


Tkinter question: howto redirect text output (stdout) to Text widget?

2008-10-14 Thread dmitrey
hi all,
could anyone post an example how to redirect text output (stdout) to
Text widget?

Thank you in advance,
Dmitrey.
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to get a class instance name during creation?

2008-10-04 Thread dmitrey
On Oct 3, 9:46 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> dmitrey a écrit :
>
> > hi all,
> > I have a code
> > z = MyClass(some_args)
> > can I somehow get info in MyClass __init__ function that user uses "z"
> > as name of the variable?
>
> > I.e. to have __init__ function that creates field z.name with value
> > "z".
>
> This has been debated to hell and back. To make a long story short, here
> are two common use cases:
>
> x = MyClass()
> y = x
> del x
>
> objects = [MyClass() for i in range(100)]
>
> If you can come with a meaningfull answer to "what's *the* name of any
> of the MyClass instance(s)" in both cases, then please let us know...

I had seen the examples during google search, still I hoped for an
answer to my exact situation. I know for sure there will be no
renaming and creating like the above objects = [MyClass() for i in
range(100)].
as for the z = MyClass(some, args, 'z') I had it in my mind but I
hoped to have something automatic, w/o the arg 'z'.
Regards, D.
--
http://mail.python.org/mailman/listinfo/python-list


how to get a class instance name during creation?

2008-10-03 Thread dmitrey
hi all,
I have a code
z = MyClass(some_args)
can I somehow get info in MyClass __init__ function that user uses "z"
as name of the variable?

I.e. to have __init__ function that creates field z.name with value
"z".

Thank you in advance, D.
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to keep a window above all other OS windows?

2008-09-23 Thread dmitrey
On Sep 23, 11:21 pm, dmitrey <[EMAIL PROTECTED]> wrote:
> Hi all,
> how to keep a Tkinter window above all other OS windows (i.e.
> including those ones from other programs)?
>
> Thank you in advance,
> Dmitrey

I have put [Tkinter] into topic of my message but somehow it has been
removed.
D.
--
http://mail.python.org/mailman/listinfo/python-list


[Tkinter] how to keep a window above all other OS windows?

2008-09-23 Thread dmitrey
Hi all,
how to keep a Tkinter window above all other OS windows (i.e.
including those ones from other programs)?

Thank you in advance,
Dmitrey
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to kill threading.Thread instance?

2008-09-21 Thread dmitrey
I wonder why something like myThread.exit() or myThread.quit() or
threading.kill(myThread) can't be implemented?
Is something like that present in Python 3000?
Regards, D.
--
http://mail.python.org/mailman/listinfo/python-list


How to kill threading.Thread instance?

2008-09-21 Thread dmitrey
hi all,
Is there a better way to kill threading.Thread (running) instance than
this one
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960
(it's all I have found via google).

BTW, it should be noticed that lots of threading module methods have
no docstrings (in my Python 2.5), for example _Thread__bootstrap,
_Thread__stop.

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


how to do easy_install to source code, not egg?

2008-09-18 Thread dmitrey
Hi all,
how to do easy_install  to source code, not egg?

(I don't mean "develop" option, it shouldn't call compiled egg-file).

Thank you in advance,
Dmitrey.
--
http://mail.python.org/mailman/listinfo/python-list


PYPI, some troubles

2008-09-17 Thread dmitrey
hi all,

1. when I commit a new release to PYPI, I can use stored data (by my
browser: Name, package summary, keywords etc), but in the last line
(classification) I had to chose all those lines from the very
beginning, moreover, if I click at one of them without pressing "CTRL"
all my choices drops & I have to type it from the very beginning (I
use Mozilla Firefox 3.0 but I don't think it's the matter).

2. Another issue: I have attached my source code (openopt0.19.tar.bz2
file), now I can see it in "files for openopt 0.19" section (http://
pypi.python.org/pypi) but easy_install can't find the package:

# easy_install openopt
Searching for openopt
Reading http://pypi.python.org/simple/openopt/
Couldn't find index page for 'openopt' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
Reading http://pypi.python.org/simple/OpenOpt/
Reading http://scipy.org/scipy/scikits/wiki/OpenOpt
No local packages or download links found for openopt
error: Could not find suitable distribution for
Requirement.parse('openopt')

Does anyone know what shoul I do?
Thank you in advance,
Dmitrey
--
http://mail.python.org/mailman/listinfo/python-list


Re: Genetic programming: pygene, pygp, AST, or (gasp) Lisp?

2008-07-21 Thread dmitrey
also, you could look at the simple openopt example provided by GA
"galileo" solver (connected to OO framework)
http://projects.scipy.org/scipy/scikits/browser/trunk/openopt/scikits/openopt/examples/glp_1.py
http://scipy.org/scipy/scikits/wiki/GLP
Regards, D
--
http://mail.python.org/mailman/listinfo/python-list


howto check is function capable of obtaining **kwargs?

2008-07-21 Thread dmitrey
hi all,
howto check is function capable of obtaining **kwargs?

i.e. I have some funcs like
def myfunc(a,b,c,...):...

some like
def myfunc(a,b,c,...,*args):...

some like
def myfunc(a,b,c,...,*args, **kwargs):...

some like
def myfunc(a,b,c,...,zz=zz0):...

So I need to know is the given function capable of handling zz
parameter, for example the call
myfunc(a,b,c,...,zz=4,...)

Thank you in advance, D.
--
http://mail.python.org/mailman/listinfo/python-list


ANN: OpenOpt 0.18 (numerical optimization framework)

2008-06-15 Thread dmitrey
Greetings,
We're pleased to announce:
OpenOpt 0.18 (release), free (license: BSD) optimization framework
(written in Python language) with connections to lots of solvers (some
are C- or Fortran-written)  is available for download.

Changes since previous release 0.17 (March 15, 2008):

* connection to glpk MILP solver (requires cvxopt v >= 1.0)

* connection to NLP solver IPOPT (requires python-ipopt wrapper
installation, that is currently available for Linux only, see openopt
NLP webpage for more details)

* major changes for NLP/NSP solver ralg

* splitting non-linear constraints can benefit for some solvers

* unified text output for NLP solvers

* handling of maximization problems (via p.goal = 'max' or
'maximum')

* some bugfixes, lots of code cleanup

Newsline:
http://openopt.blogspot.com/

Homepage:
http://scipy.org/scipy/scikits/wiki/OpenOpt

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


write Python dict (mb with unicode) to a file

2008-06-14 Thread dmitrey
hi all,
what's the best way to write Python dictionary to a file?

(and then read)

There could be unicode field names and values encountered.
Thank you in advance, D.
--
http://mail.python.org/mailman/listinfo/python-list


howto split string with both comma and semicolon delimiters

2008-06-12 Thread dmitrey
hi all,
howto split string with both comma and semicolon delimiters?

i.e. (for example) get ['a','b','c'] from string "a,b;c"

I have tried s.split(',;') but it don't work
Thx, D.
--
http://mail.python.org/mailman/listinfo/python-list


Re: howto use pylint from Eric IDE?

2008-05-18 Thread dmitrey
Since I have no project (and willing to create the one), just several
py-files, the Project->Check button is disabled.
Are there any other methods in v4.1.1 or more recent?
Thx, D.

On 18 Тра, 16:48, Detlev Offenbach <[EMAIL PROTECTED]> wrote:
> dmitrey wrote:
> > Hi all,
>
> > I have Eric 4.1.1, pylint and Eric pylint plugin installed, but I
> > cannot find how to use pylint from Eric IDE GUI.
> > Does anyone know?
>
> > Thank you in advance, D.
>
> Project->Check->Run PyLint
>
> Regards,
> Detlev
> --
> Detlev Offenbach
> [EMAIL PROTECTED]

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

Re: Using Python for programming algorithms

2008-05-18 Thread dmitrey
Along with numpy & scipy there is some more Python scientific soft
worse to be mentioned:

http://scipy.org/Topical_Software
http://pypi.python.org/pypi?:action=browse&show=all&c=385

On 18 Тра, 06:25, Henrique Dante de Almeida <[EMAIL PROTECTED]> wrote:
> once I
> looked for linear programming toolkits for python and IIRC, I only
> could find a trivial wrapper for glpk (called pulp).

You could be interested in OpenOpt, it has connections to LP solvers
glpk, cvxopt's one and lp_solve (former & latter allows handling MILP
as well)

http://scipy.org/scipy/scikits/wiki/LP
--
http://mail.python.org/mailman/listinfo/python-list

howto use pylint from Eric IDE?

2008-05-18 Thread dmitrey
Hi all,

I have Eric 4.1.1, pylint and Eric pylint plugin installed, but I
cannot find how to use pylint from Eric IDE GUI.
Does anyone know?

Thank you in advance, D.
--
http://mail.python.org/mailman/listinfo/python-list


Re: simple question about Python list

2008-05-09 Thread dmitrey
Hmm... I thought this issue is available from Python2.5 only. I have
no other interpreters in my recently installed KUBUNTU 8.04.

Thanks all,
D.

On 9 Тра, 13:41, Duncan Booth <[EMAIL PROTECTED]> wrote:
> dmitrey <[EMAIL PROTECTED]> wrote:
> > On 9 ôÒÁ, 13:17, Paul Hankin <[EMAIL PROTECTED]> wrote:
> >> On May 9, 11:04šam, dmitrey <[EMAIL PROTECTED]> wrote:
>
> >> > list1 = ['elem0', 'elem1', 'elem2', 'elem3', 'elem4', 'elem5']
> >> > and
> >> > list2 = [0, 2, 4] # integer elements
>
> >> > howto (I mean most simple recipe, of course) form list3 that contains
> >> > elements from list1 with indexes from list2, i.e.
>
> >> list3 = [list1[i] for i in list2]
>
> > Ok, I use Python 2.5 but I try my code to remain Python 2.4 and
> > (preferable) 2.3 compatible.
> > Are there other solutions?
> > D.
>
> Did you try Paul's suggestion?
>
> Python 2.3.5 (#1, Oct 13 2005, 09:17:23)
> [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-52)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> list1 = ['elem0', 'elem1', 'elem2', 'elem3', 'elem4', 'elem5']
> >>> list2 = [0, 2, 4]
> >>> list3 = [list1[i] for i in list2]
> >>> list3
>
> ['elem0', 'elem2', 'elem4']

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

Re: simple question about Python list

2008-05-09 Thread dmitrey
Ok, I use Python 2.5 but I try my code to remain Python 2.4 and
(preferable) 2.3 compatible.
Are there other solutions?
D.

On 9 Тра, 13:17, Paul Hankin <[EMAIL PROTECTED]> wrote:
> On May 9, 11:04 am, dmitrey <[EMAIL PROTECTED]> wrote:
>
> > list1 = ['elem0', 'elem1', 'elem2', 'elem3', 'elem4', 'elem5']
> > and
> > list2 = [0, 2, 4] # integer elements
>
> > howto (I mean most simple recipe, of course) form list3 that contains
> > elements from list1 with indexes from list2, i.e.
>
> list3 = [list1[i] for i in list2]
>
> --
> Paul Hankin

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

Re: How to kill Python interpreter from the command line?

2008-05-09 Thread dmitrey
in addition to killall and kill funcs mentioned above you could be
interested in pkill
see "man pkill" from terminal for more details

pkill python

or

pkill pyt

or

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


simple question about Python list

2008-05-09 Thread dmitrey
hi all,
suppose I have 2 lists
list1 = ['elem0', 'elem1', 'elem2', 'elem3', 'elem4', 'elem5']
and
list2 = [0, 2, 4] # integer elements

howto (I mean most simple recipe, of course) form list3 that contains
elements from list1 with indexes from list2, i.e.

list3 = ['elem0', 'elem2', 'elem4']?

Thank you in advance, D.
--
http://mail.python.org/mailman/listinfo/python-list


howto print binary number

2008-05-07 Thread dmitrey
hi all,
could you inform how to print binary number?
I.e. something like

print '%b' % my_number

it would be nice would it print exactly 8 binary digits (0-1, with
possible start from 0)

Thank you in advance, D
--
http://mail.python.org/mailman/listinfo/python-list


memory allocation for Python list

2008-03-26 Thread dmitrey
hi all,
I have a python list of unknown length, that sequentially grows up via
adding single elements.
Each element has same size in memory (numpy.array of shape 1 x N, N is
known from the very beginning).
As I have mentioned, I don't know final length of the list, but
usually I know a good approximation, for example 400.

So, how can I optimize a code for the sake of calculations speedup?
Currently I just use

myList = []

for i in some_range:
...
myList.append(element)
...

Thank you in advance,
Dmitrey

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


ANN: OpenOpt 0.17 (free numerical optimization framework)

2008-03-16 Thread dmitrey
Greetings,
We're pleased to announce:
OpenOpt 0.17 (release), free (license: BSD) optimization framework for
Python language programmers,  is available for download.

Brief introduction to numerical optimization problems and related
software:
http://scipy.org/scipy/scikits/wiki/OOIntroduction

Changes since previous release (December 15):

* new classes: GLP (global problem), MMP (mini-max problem)
* several new solvers written: goldenSection, nsmm
* some more solvers connected: scipy_slsqp, bvls, galileo
* possibility to change default solver parameters
* user-defined callback functions
* changes in auto derivatives check
* "noise" parameter for noisy functions
* some changes to NLP/NSP solver ralg
* some changes in graphical output: initial estimations xlim, ylim
* scaling
* some bugfixes

Newsline:
http://openopt.blogspot.com/

Homepage:
http://scipy.org/scipy/scikits/wiki/OpenOpt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: future multi-threading for-loops

2008-02-05 Thread dmitrey
On Feb 5, 6:11 pm, Christian Heimes <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Multi-threaded control flow is a worthwhile priority.
>
> It is? That's totally new to me. Given the fact that threads don't scale
> I highly doubt your claim, too.

I would propose "for X IN A" for parallel and remain "for X in A" for
sequential.
BTW for fortress lang I had proposed "for X <- A" and "for X <= A" for
sequential/parallel instead of current "for X <- seq(A)", "for X <-
A", mb they will implement my way instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: future multi-threading for-loops

2008-02-05 Thread dmitrey
On Feb 5, 5:22 am, [EMAIL PROTECTED] wrote:
> Some iterables and control loops can be multithreaded.  Worries that
> it takes a syntax change.
>
> for X in A:
> def f( x ):
> normal suite( x )
> start_new_thread( target= f, args= ( X, ) )
>
> Perhaps a control-flow wrapper, or method on iterable.
>
> @parallel
> for X in A:
> normal suite( X )
>
> for X in parallel( A ):
> normal suite( X )
>
I would propose "for X IN A" for parallel and remain "for X in A" for
sequential.
BTW for fortress lang I had proposed "for X <- A" and "for X <= A" for
sequential/parallel instead of current "for X <- seq(A)", "for X <-
A", mb they will implement my way instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


IronPython vs CPython: faster in 1.6 times?

2008-02-05 Thread dmitrey
Hi all,
the url http://torquedev.blogspot.com/2008/02/changes-in-air.html
(blog of a game developers)
says IronPython is faster than CPython in 1.6 times.
Is it really true?
If yes, what are IronPython drawbacks vs CPython?
And is it possible to use IronPython in Linux?

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


Re: ANN: eric4 4.1.0 released

2008-02-03 Thread dmitrey
Hi all,
I prefer the Eric Python IDE to all other, however, unfortunately,
Eric4.x (as well as the latest snapshot mentioned in the ann) fails to
debug any py-file (while Eric3.9.5 from Kubuntu software channel works
ok):

The debugged program raised the exception unhandled TypeError
"not all arguments converted during string formatting"
File: /usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugBase.py, Line: 515

Could you fix the issue?
Kubuntu 7.10, AMD Athlon, Python 2.5.
Regards, D.

On Feb 3, 5:45 pm, Detlev Offenbach <[EMAIL PROTECTED]> wrote:
> Hi,
>
> eric4 4.1.0 was just released. This is a major feature release. Compared
> to 4.0.4 it contains these features next to bug fixes.
>
> - Added a plugin system for easy extensibility
> - Converted the following interface to plugins available separately
>   -- PyLint checker
>   -- CxFreeze packager
>   -- CharTables tool
>   -- CVS version control system
>   -- BRM refactoring
> - Added new project types
>   -- Eric4 Plugin
>   -- Django
>   -- TurboGears
>   -- wxPython
> - Added source code exporters for
>   -- HTML
>   -- PDF
>   -- RTF
>   -- Latex
> - Added subversion repository and log browsers
> - Included API files for
>   -- eric4
>   -- Django
>   -- TurboGears
>   -- wxPython
>   -- Zope 2
>   -- Zope 3
> - Many enhancements to the functionality already there
>
> What is eric4?
> --
> eric4 is a Python (and Ruby) IDE with all batteries included. Please 
> seehttp://www.die-offenbachs.de/ericfor details and screenshots.
>
> Regards,
> Detlev
> --
> Detlev Offenbach
> [EMAIL PROTECTED]

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


Re: OpenOpt install

2007-12-18 Thread dmitrey
thank you, I'll try to fix the issue when I'll have more time, I'm
short of the one for now because of some other urgent work.
D.

On Dec 18, 10:53 am, Robert Kern <[EMAIL PROTECTED]> wrote:
> dmitrey wrote:
> > When earlier OpenOpt versions had been installed there were no
> > compiled pyc-files (in destination directory). I called to mailing
> > list but no obvious receipt had been achieved. Matthieu had done some
> > changes but it yielded other mistakes (no some py-files detected or
> > kind of), so I had removed those changes and write my own, for to have
> > OO py-files being compiled when installed, because next time when they
> > will be run user may not have root permissions, so he will recompile
> > source files each time OO starts.
>
> Well, the problem there is that you have put code into subdirectories that
> aren't packages. Then you manually add the directories to sys.path when you
> import scikits.openopt.oo . This is a bad thing to do for several reasons; one
> reason is that you don't get the correct .pyc files.
>
> You need to make the directory structure match the package structure. For
> example, you currently have the module scikits.openopt.LP in
> scikits/openopt/Kernel/LP/LP.py . You have two options:
>
>   * you can make the directory structure match the package structure by moving
> the files to the correct location:
>
> $ mv scikits/openopt/Kernel/LP/LP.py scikits/openopt/LP.py
>
>   * you can make the package structure match the directory structure by adding
> __init__.py files to the subdirectories and changing the imports to match:
>
> $ touch scikits/openopt/Kernel/__init__.py
> $ touch scikits/openopt/Kernel/LP/__init__.py
> $ vim scikits/openopt/oo.py
>   # 1. Delete the sys.path munging.
>   # 2. Change "from LP import LP as CLP" to "from Kernel.LP import LP as 
> CLP"
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>  that is made terrible by our own mad attempt to interpret it as though it had
>  an underlying truth."
>   -- Umberto Eco

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


Re: OpenOpt install

2007-12-17 Thread dmitrey
When earlier OpenOpt versions had been installed there were no
compiled pyc-files (in destination directory). I called to mailing
list but no obvious receipt had been achieved. Matthieu had done some
changes but it yielded other mistakes (no some py-files detected or
kind of), so I had removed those changes and write my own, for to have
OO py-files being compiled when installed, because next time when they
will be run user may not have root permissions, so he will recompile
source files each time OO starts.

On Dec 17, 10:27 pm, Robert Kern <[EMAIL PROTECTED]> wrote:
> dmitrey wrote:
> > Use
> > python setup.py install
>
> People should be able to run the distutils commands independently.
>
> What are you trying to achieve with this block of code that follows the 
> setup()
> call?
>
> new_name = 'tmp55'
> os.rename('scikits', new_name)
> newPath = []
> for directory in sys.path:
> if not 'scikits' in directory: newPath.append(directory)# something
> wrong with list.remove()
> sys.path = newPath
> import scikits
> reload(scikits)
> Path = scikits.__path__[0]
> NewPath = os.path.join(Path, 'openopt')
> rmtree(NewPath, True) # True means ignore errors
> copytree(os.path.join(os.path.curdir, new_name, 'openopt'), NewPath)
> NewPath = Path
> compileall.compile_dir(NewPath)
>
> os.rename(new_name, 'scikits')
>
> This just looks like a really bad idea.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>  that is made terrible by our own mad attempt to interpret it as though it had
>  an underlying truth."
>   -- Umberto Eco

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


Re: OpenOpt install

2007-12-17 Thread dmitrey
Use
python setup.py install

Regards, D

On Dec 16, 2:27 pm, Neal Becker <[EMAIL PROTECTED]> wrote:
> What do I need to do?  I have numpy, scipy (Fedora F8)
>
>  cdopenopt/
> [EMAIL PROTECTED] python setup.py build
> running build
> running config_cc
> unifing config_cc, config, build_clib, build_ext, build commands --compiler 
> options
> running config_fc
> unifing config_fc, config, build_clib, build_ext, build commands --fcompiler 
> options
> running build_py
> creating build
> creating build/lib
> creating build/lib/scikits
> copying scikits/__init__.py -> build/lib/scikits
> creating build/lib/scikits/openopt
> copying scikits/openopt/__init__.py -> build/lib/scikits/openopt
> copying scikits/openopt/info.py -> build/lib/scikits/openopt
> copying scikits/openopt/oo.py -> build/lib/scikits/openopt
> Traceback (most recent call last):
>   File "setup.py", line 101, in 
> import scikits
> ImportError: No module named scikits

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


Re: Python strings question (vertical stack)

2007-11-20 Thread dmitrey
Thanks all, I have solved the problem:

a="""
%s
%s
%s
""" % ('asdf', 'asdf2', 'asdf3')

print a

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


Python strings question (vertical stack)

2007-11-20 Thread dmitrey
Hi all,
I have some strings, let it be string1, string2, string3.

So how could String=
"""
string1
string2
string3
"""

be obtained?

Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with Python class creating

2007-10-19 Thread dmitrey
Thanks all for these detailed explanations.
On Oct 18, 10:48 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> dmitrey a écrit :
> Not unless these classes define their own initializers. But that's
> another problem
>
> > and there are lots of
> > those ones)
>
> > class MyClass:
> > def __init__(self):
> > iterfcn = lambda *args: ooIter(self)
>
> The real problem is that you create one anonymous function *per instance*.
No, it's not a problem - it's desired behaviour.
Regards, Dmitrey

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

problem with Python class creating

2007-10-18 Thread dmitrey
Hi all,
I have the code like this one:

from myMisc import ooIter
class MyClass:
def __init__(self): pass
iterfcn = lambda *args: ooIter(self) # i.e pass the class instance
to other func named ooIter
field2 = val2
field3 = val3 # etc

So it yields "global name 'self' is not defined", that is true. How
could I handle the situation?

Currently I do (and it works, but give me some troubles - I should
call MyClass.__init__ for each children class, and there are lots of
those ones)

class MyClass:
def __init__(self):
iterfcn = lambda *args: ooIter(self) # i.e pass the class
instance to other func named ooIter
field2 = val2
field3 = val3 # etc

I suspect it has better solution, is it?
Thank you in advance, Dmitrey

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


lambda-funcs problem

2007-09-19 Thread dmitrey . kroshko
hi all,
I need to create a Python list of lambda-funcs that are dependent on
the number of the ones, for example

F = []
for i in xrange(N):
F.append(lambda x: x + i)

however, the example don't work - since i in end is N-1 it yields x+
(N-1) for any func.

So what's the best way to make it valid?
Evaluation speed is also very important to me.

Thank you in advance, D.

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


howto reload Python module?

2007-09-02 Thread dmitrey
my Python module was changed in HDD (hardware disk drive), moreover,
changed its location (but still present in sys.path).
how can I reload a func "myfunc"  from the module? (or howto reload
whole module)?
Thank you in advance, D.

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


howto compile recursively all *.py files to *.pyc (from a directory my_dir)?

2007-09-01 Thread dmitrey
howto compile recursively all *.py files to *.pyc (from a directory
my_dir)?
Thank you in advance, D.

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


  1   2   >