Extending Python with C++

2005-12-29 Thread jeremito
I am learning how to extend Pythong with C++.  I have will be writing
some code in C++ and want/need Python to interact with it.  I am not
having success following the online documentation from
http://docs.python.org/ext/ext.html.  I have also looked briefly at
some of the demos in the source code distribution.  Can anyone help me?
 I am using the MacPython (version 2.4) distribution.

I have one specific question.  The documentation online states:

"If the main program (the Python interpreter) is compiled and linked by
the C compiler, global or static objects with constructors cannot be
used. This is not a problem if the main program is linked by the C++
compiler."

Thanks,
Jeremy

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


Re: Extending Python with C++

2005-12-29 Thread jeremito
Oops, sorry.  My question is, how can I know if my Python interpreter
was lined by C++?  The non-specific questions are, of course, does
anyone have any hints or suggestions?  Good websites to visit?
Thanks,
Jeremy

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


Re: Extending Python with C++

2005-12-29 Thread jeremito
Unfortunately, I need to know a bit more than just the concept 'extern
"C"'.  I am really slow at this.  Can anyone point me towards some
examples or a tutorial (other than the one from python.org, I didn't
understand that one)?
Thanks,
Jeremy

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


Why doesn't this work--Extending Python--?

2006-01-04 Thread jeremito
I have written a simple C++ program in my efforts to learn how to
extend Python.  It is shown below.  Everything compiles and installs
correctly, but I get strange answers.  I know the function "Pi" is
correct because when I call it from a C++ code it gives the correct
answers.  This is what I get when I run it in Python:

Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Pie
>>> Pie.Pi(100)
4.244022824665725e-314
>>> Pie.Pi(10)
6.3659915186006512e-314
>>> Pie.Pi(100)
6.3659881268399925e-314

Thanks for the help,
Jeremy

  1 /* PiPython.cpp*/

  2 #include

  3
  4 using namespace  std;

  5
  6 double Pi(int Particles)

  7 {

  8 double PiEst = 0.0;

  9 double x,y;

 10 int CircleArea = 0;
 11 for ( int i = 0; i <= Particles; i++)

 12 {
 13 x = (double) rand()/RAND_MAX;

 14 y = (double) rand()/RAND_MAX;

 15

 16 if (sqrt(pow(x,2)+pow(y,2)) <= 1.0)

 17 {

 18 CircleArea++;
 19 }
 20 }

 21 return 4.0*(double(CircleArea)/double(Particles));

 22 }

 23
 24
 25 PyObject *wrap_Pi(PyObject *self, PyObject *args)

 26 {

 27 int Particles;
 28 int Pie;
 29 if (!PyArg_ParseTuple(args, "i", &Particles))

 30 return NULL;

 31 Pie = Pi(Particles);

 32 return Py_BuildValue("d", Pie);
 33 }
 34

 35 /* List of all functions in the module */
 36 static PyMethodDef PieMethods[] =
 37 {
 38 {"Pi", wrap_Pi, METH_VARARGS},
 39 {NULL, NULL}
 40 };
 41
 42 /* Module Initialization function */
 43 PyMODINIT_FUNC initPie(void)
 44 {
 45 Py_InitModule("Pie", PieMethods);
 46 }

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


Re: Why doesn't this work--Extending Python--?

2006-01-04 Thread jeremito
Well what do you know, that worked!  It's one of those errors that you
can't see yourself, but someone else can see it instantly.
Thanks,
Jeremy

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


Convert string to mathematical function

2006-08-01 Thread jeremito
I am extending python with C++ and need some help.  I would like to
convert a string to a mathematical function and then make this a C++
function.  My C++ code would then refer to this function to calculate
what it needs.  For example I want to tell my function to calculate
"x^2 + 3x +2", but later on I may want: "x + 3".  Does anybody know how
I can get an arbitrary string in Python (but proper mathematical
function) turned into a C++ function?  My one idea (although I don't
know how to implement it, I'm still new at this) is to pass to C++ a
pointer to a (Python) function.  Will this work?
Thanks,
Jeremy

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


Re: Convert string to mathematical function

2006-08-02 Thread jeremito
I was unaware of the exec and eval functions in Python.  Without trying
them, they seem to be what I want to do.  I'll play around with it and
see if I can figure it out.  Thanks for the suggestions everyone.
Jeremy

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


Extending/Embedding Confusion

2006-08-04 Thread jeremito
I am trying to learn how to extend and/or embed Python.  I have looked
at the document "Extending and Embedding the Python Interpreter" and
also "Python/C API Reference Manual.  In the examples shown in
"Extending..." there are some things I ma not familiar with so I turn
to the index in the Reference Manual, but they are not listed.  For
example, PyEval_CallObject and PyDict_GetAttrString.  My question is
this: Is the documentation out of date or is the index not complete?
Where can I get information about these things?

Secondly, I am really struggling with understanding how to Extend/Embed
Python.  The examples given in the documentation are not as helpful as
I would hope.  Does anyone know of additional examples on the web that
will shed some light on this issue?  I have tried Google, but haven't
yet been successful in finding additional examples that help.
Thanks,
Jeremy

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


string formatter for tuple

2006-11-02 Thread jeremito
I have the following in my code

a = (1,2,3)
print "a = %s" %a

But when I run this, I get:

TypeError: not all arguments converted during string formatting

Now I realize why this happens, a is actually 3 elements when the print
statement is only expecting to print one value.  I tried

print "a = %s" %(a)

but I got the same error.

How can I print a tuple with a single string format?
Thanks,
Jeremy

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


Re: string formatter for tuple

2006-11-02 Thread jeremito

[EMAIL PROTECTED] wrote:
> > "Tim" == Tim Chase <[EMAIL PROTECTED]> writes:
>
> >> How can I print a tuple with a single string format?
>
> Tim>print "a = %s" % str(a)
> Tim> or
> Tim>print "a = %s" % repr(a)
>
> Or wrap the tuple in a tuple:
>
> print "a = %s" % (a,)
> 
> Skip

Thank you all very much for your help.
Jeremy

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


What is proper way to require a method to be overridden?

2007-01-04 Thread jeremito
I am writing a class that is intended to be subclassed.  What is the
proper way to indicate that a sub class must override a method?

Thanks,
Jeremy

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


Re: What is proper way to require a method to be overridden?

2007-01-04 Thread jeremito

Gabriel Genellina wrote:
> At Thursday 4/1/2007 23:52, jeremito wrote:
>
> >I am writing a class that is intended to be subclassed.  What is the
> >proper way to indicate that a sub class must override a method?
>
> If any subclass *must* override a method, raise NotImplementedError
> in the base class (apart from documenting how your class is supposed
> to be used).
>
>
> --
> Gabriel Genellina
> Softlab SRL
>

Thanks, that's what I needed.  Since I am a complete novice at
Exceptions, I'll have to learn about it.
Jeremy

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


Python module for making Quicktime or mpeg movies from images

2007-10-11 Thread jeremito
My Python script makes a bunch of images that I want to use as frames
in a movie.  I've tried searching for a module that will take these
images and put them together in a Quicktime or mpeg movie, but haven't
found anything.  My images are currently pdfs, but I could make them
into just about anything if needed.

Is there a module, or example of how to do this?
Thanks,
Jeremy

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


Re: Python module for making Quicktime or mpeg movies from images

2007-10-11 Thread jeremito
On Oct 11, 10:43 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> jeremito wrote:
> > My Python script makes a bunch of images that I want to use as frames
> > in a movie.  I've tried searching for a module that will take these
> > images and put them together in a Quicktime or mpeg movie, but haven't
> > found anything.  My images are currently pdfs, but I could make them
> > into just about anything if needed.
>
> > Is there a module, or example of how to do this?
>
> http://pymedia.org/
>
> Diez

That initially looked promising, but it looks like nobody is working
on it anymore and it doesn't compile on Mac.  (I should have mentioned
I am using a Mac.)  Any other suggestions?

Thanks,
Jeremy

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


Re: Python module for making Quicktime or mpeg movies from images

2007-10-12 Thread jeremito
On Oct 12, 10:37 am, TYR <[EMAIL PROTECTED]> wrote:
> On Oct 11, 4:17 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
>
>
>
> > jeremito wrote:
> > > On Oct 11, 10:43 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > >> jeremito wrote:
> > >>> My Python script makes a bunch of images that I want to use as frames
> > >>> in a movie.  I've tried searching for a module that will take these
> > >>> images and put them together in a Quicktime or mpeg movie, but haven't
> > >>> found anything.  My images are currently pdfs, but I could make them
> > >>> into just about anything if needed.
> > >>> Is there a module, or example of how to do this?
> > >>http://pymedia.org/
>
> > >> Diez
>
> > > That initially looked promising, but it looks like nobody is working
> > > on it anymore and it doesn't compile on Mac.  (I should have mentioned
> > > I am using a Mac.)  Any other suggestions?
>
> > Not really a Python module but... run them
> > through mencoder? (Haven't tried it but it
> > seems to be saying it's possible).
>
> >http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.html#EXAMPLES%20OF%20ME...
>
> > TJG
>
> NodeBox; nodebox.org
>
> GUI application that creates either PDFs or Quicktime vids from python
> code. Unix/Linux/MacOS.

I actually found NodeBox in my googling.  This seems to be a stand
alone application.  I need to be able to convert my images to a movie
from my code I wrote myself.

Thanks,
Jeremy

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


Re: Python module for making Quicktime or mpeg movies from images

2007-10-15 Thread jeremito
On Oct 13, 5:30 am, has <[EMAIL PROTECTED]> wrote:
> On 12 Oct, 20:53, jeremito <[EMAIL PROTECTED]> wrote:
>
> > I actually found NodeBox in my googling.  This seems to be a stand
> > alone application.  I need to be able to convert my images to a movie
> > from my code I wrote myself.
>
> Some Mac-specific options:
>
> -QuickTimePlayer is standard on OS X and its scripting interface
> (which you can access from Python via appscript, and is fully usable
> even in unpaid mode) includes an 'open image sequence' command. This
> would be the simplest solution as long as you don't mind launching
> another application to do the work.

I have used this, but I want to automate this so I wanted something I
could call from my Python script.
>
> - The Cocoa API's QTKit class (accessible via PyObjC) includes a -
> addImage:forDuration:withAttributes: method that you could use to
> build up a movie yourself.
>

This sounds like a good option.  I have downloaded and installed
PyObjC and am currently looking for the QTKit class but have been
unsuccessful so far.  A cursory glance at the documentation hasn't
produced any help, yet.  I'll keep looking unless you can point to it
directly.

Thanks again,
Jeremy

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


Help me override append function of list object

2007-01-30 Thread jeremito
I have created a class that inherits from the list object.  I want to 
override the append function to allow my class to append several 
copies at the same time with one function call.  I want to do 
something like:

import copy

class MyList(list):
  __init__(self):
pass

  def append(self, object, n=1):
for i in xrange(n):
self.append(copy.copy(object))

Now I know this doesn't work because I overwrite append, but want the 
original functionality of the list object.  Can someone help me?

Thanks,
Jeremy

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


Re: Help me override append function of list object

2007-01-30 Thread jeremito


On Jan 30, 10:47 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> jeremito wrote:
> > I have created a class that inherits from the list object.  I want to
> > override the append function to allow my class to append several
> > copies at the same time with one function call.  I want to do
> > something like:
>
> > import copy
>
> > class MyList(list):
> >   __init__(self):
> > pass
>
> >   def append(self, object, n=1):
> > for i in xrange(n):
> > self.append(copy.copy(object))
>
> > Now I know this doesn't work because I overwrite append, but want the
> > original functionality of the list object.  Can someone help me?Use 
> > list.append(self, obj) or super(MyList, self).append(obj), e. g.:
>
> >>> import copy
> >>> class List(list):... def append(self, obj, n=1):
> ... for i in xrange(n):
> ... super(List, self).append(copy.copy(obj))
> ...>>> items = List()
> >>> items.append(42, 3)
> >>> items[42, 42, 42]
>
> Peter

Thank you so much.  I'm glad it is so easy.
Jeremy

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


how to add class attributes in __new__

2007-02-01 Thread jeremito
I am subclassing the array class and have __new__ to initialize and
create my class.  In that class I create not only do I create an array
object, but I also create some other data in __new__ I want to have
access to outside of __new__.  I tried

self.mydata = mydata

but that didn't work.

Can someone point me in the right direction?
Thanks,
Jeremy

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


How can I use __setitem__ method of dict object?

2007-02-06 Thread jeremito
Please excuse me if this is obvious to others, but I can't figure it
out.  I am subclassing dict, but want to prevent direct changing of
some key/value pairs.  For this I thought I should override the
__setitem__ method as such:


class xs(dict):
"""
XS is a container object to hold information about cross sections.
"""

def __new__(cls, xS=1.0, xF=1.0, xG=1.0, nu=1.0, debug=0):
"""
"""
x = {}
x['xS'] = xS
x['xF'] = xF
x['nu'] = nu
x['xG'] = xG
x['xA'] = x['xG'] + x['xF']
x['xT'] = x['xA'] + x['xS']

return x

def __setitem__(self, key, value):
"""
I have overridden this method to prevent setting xT or xA
outside the
class.
"""
print "I am in __setitem__"
if key == 'xT':
raise AttributeError("""Can't change xT.  Please change,
xF, xS, or xG""")


But I can't even get __setitem__ to run.  Example:
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xs
>>> cs = xs.xs()
>>> cs
{'xA': 2.0, 'xF': 1.0, 'xG': 1.0, 'xS': 1.0, 'nu': 1.0, 'xT': 3.0}
>>> cs['xT'] = 3.1415
>>> cs
{'xA': 2.0, 'xF': 1.0, 'xG': 1.0, 'xS': 1.0, 'nu': 1.0, 'xT':
3.14150002}


Is this what the __setitem__ method is for?  If not, how can I do what
I want to do?
Thanks in advance,
Jeremy

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


Re: How can I use __setitem__ method of dict object?

2007-02-06 Thread jeremito
On Feb 6, 10:59 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> On 6 fév, 16:23, "jeremito" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Please excuse me if this is obvious to others, but I can't figure it
> > out.  I am subclassing dict, but want to prevent direct changing of
> > some key/value pairs.  For this I thought I should override the
> > __setitem__ method as such:
>
> > class xs(dict):
> > """
> > XS is a container object to hold information about cross sections.
> > """
>
> > def __new__(cls, xS=1.0, xF=1.0, xG=1.0, nu=1.0, debug=0):
> > """
> > """
> > x = {}
> > x['xS'] = xS
> > x['xF'] = xF
> > x['nu'] = nu
> > x['xG'] = xG
> > x['xA'] = x['xG'] + x['xF']
> > x['xT'] = x['xA'] + x['xS']
>
> > return x
>
> replace this with:
> def __init__(self,  xS=1.0, xF=1.0, xG=1.0, nu=1.0, debug=0):
>dict.__init__(
>self,
>xS=xS,
>xF=xF,
>xG=xG,
>   nu=nu,
>   xA=xG + xF,
>   xT=xG + xF + xS
>  )
>
> > def __setitem__(self, key, value):
> > """
> > I have overridden this method to prevent setting xT or xA
> > outside the
> > class.
> > """
> > print "I am in __setitem__"
> > if key == 'xT':
> > raise AttributeError(
>
>   "Can't change xT.  Please change, xF, xS, or xG"
>)
>dict.__setitem__(self, key, value)
>
> > But I can't even get __setitem__ to run.
>
> of course, since your __new__ method returns a dict instance, not a xs
> instance...
> There are very few cases where you really need to override the __new__
> method.

The reason I create my object with __new__ instead of __init__ is
because when I use __init__ when a value is set it calls __setitem__.
This is what I want to happen, but not inside of __init__.  Does this
make sense?  I'm sure there is a better/more pythonic way to do this,
but I'm unsure of what it is.  Can someone show me an example of how
this should work?


>
> > Example:
> > Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
> > [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> > Type "help", "copyright", "credits" or "license" for more information.>>> 
> > import xs
> > >>> cs = xs.xs()
> > >>> cs
>
> > {'xA': 2.0, 'xF': 1.0, 'xG': 1.0, 'xS': 1.0, 'nu': 1.0, 'xT': 3.0}>>> 
> > cs['xT'] = 3.1415
> > >>> cs
>
> > {'xA': 2.0, 'xF': 1.0, 'xG': 1.0, 'xS': 1.0, 'nu': 1.0, 'xT':
> > 3.14150002}
>
> > Is this what the __setitem__ method is for?
>
> Yes. But note that you you need to manually call the superclass's
> overriden method  - unless you
> really want to replace it with your own, which is obviously not the
> case here...
>
> Note that if someone manually changes the values of xG, xF, or xS, the
> computed values of xA and/or xT
> won't reflect this change. Is that what you want ?
>

Eventually (when I figure out how to use __setitem__) I will change
what happens when xG, xF, or xS are changed so that it also changes xA
and xT.

> Finally, and if I may ask, what is your use-case for subclassing
> dict ? You don't need this to implement a dict-like object,
> and it might be simpler in your case to write an ordinary class, then
> add support for the required subset of the dict interface.

Eventually I am going to add other features to my class (as I have
mentioned) so I can't simply use a dict object.

>
> My 2 cents...

Thanks again,
Jeremy

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


Re: How can I use __setitem__ method of dict object?

2007-02-06 Thread jeremito
On Feb 6, 2:36 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> jeremito a écrit :
>
>
>
> > On Feb 6, 10:59 am, "[EMAIL PROTECTED]"
> > <[EMAIL PROTECTED]> wrote:
>
> >>On 6 fév, 16:23, "jeremito" <[EMAIL PROTECTED]> wrote:
>
> (snip)
> >>>But I can't even get __setitem__ to run.
>
> >>of course, since your __new__ method returns a dict instance, not a xs
> >>instance...
> >>There are very few cases where you really need to override the __new__
> >>method.
>
> > The reason I create my object with __new__ instead of __init__ is
> > because when I use __init__ when a value is set it calls __setitem__.
> > This is what I want to happen, but not inside of __init__.   Does this
> > make sense?
>
> It would make sens - if you couldn't call dict.__setitem__ directly.
>
>
>
>
>
> > I'm sure there is a better/more pythonic way to do this,
> > but I'm unsure of what it is.  Can someone show me an example of how
> > this should work?
>
> (snip)
> >>>Is this what the __setitem__ method is for?
>
> >>Yes. But note that you you need to manually call the superclass's
> >>overriden method  - unless you
> >>really want to replace it with your own, which is obviously not the
> >>case here...
>
> >>Note that if someone manually changes the values of xG, xF, or xS, the
> >>computed values of xA and/or xT
> >>won't reflect this change. Is that what you want ?
>
> > Eventually (when I figure out how to use __setitem__) I will change
> > what happens when xG, xF, or xS are changed so that it also changes xA
> > and xT.
>
> Which is not the best way to go IMHO. Unless the computation is very
> intensive (which doesn't seem to be the case here) or it's heavily used
> in big loops *and* the perfs are not good enough, it's better to
> recompute on the fly at read time. And if one of the above cases arises,
> then it will be time to use memoization (ie: cache the result of
> computation, invalidating the cache when needed).
>
>
>
> >>Finally, and if I may ask, what is your use-case for subclassing
> >>dict ? You don't need this to implement a dict-like object,
> >>and it might be simpler in your case to write an ordinary class, then
> >>add support for the required subset of the dict interface.
>
> > Eventually I am going to add other features to my class (as I have
> > mentioned) so I can't simply use a dict object.
>
> I already understood this. My question is : why do you want to
> *subclass* dict. In Python, inheritence is only about implementation,
> it's *not* needed for polymorphism to work. So you don't have to
> subclass dict to have an object behaving (more or less, that's up to
> you) like a dict.
>
> Here's an alternative implementation, so you get the idea. Note that it
> behaves mostly like a dict (well, not totally, but since we don't know
> which subset of the dict interface you need...), but also like a
> 'standard' object, so you can use either cs.['xT'] or cs.xT with the
> same result.
>
> class Xs(dict):
>  """
>  Xs is a container object to hold information about cross sections.
>  """
>  _computedkeys = 'xA', 'xT'
>
>  def __init__(self, xS=1.0, xF=1.0, xG=1.0, nu=1.0, debug=0):
>  self.xS = xS
>  self.xF = xF
>  self.xG = xG
>  self.nu = nu
>
>  # xA and xT as properties (AKA computed attributes)
>  def _get_xA(self):
>  return self.xG + self.xF
>  def _set_xA(self, dummy):
>  raise AttributeError(
>  "%s.xA is read-only" % self.__class__.__name__
>  )
>  xA = property(fset=_set_xA, fget=_get_xA)
>
>  def _get_xT(self):
>  return self.xA + self.xS
>  def _set_xT(self, dummy):
>  raise AttributeError(
>  "%s.xT is read-only" % self.__class__.__name__
>  )
>  xT = property(fset=_set_xT, fget=_get_xT)
>
>  # dict interface support, to be extended if needed
>  def __setitem__(self, key, value):
>  setattr(self, key, value)
>
>  def __getitem__(self, key):
>  return getattr(self, key)
>
>  def keys(self):
>  return self.__dict__.keys() + list(self._computedkeys)
>
>  def values(self):
>  return self.__dict__.values() \
> + [getattr(self, key) for key in self._computedkeys]
>
>  def items(self):
>  return zip(self.keys(), self.values())
>
>  def __iter__(self):
>  for k in self.keys():
>  yield k
>  raise StopIteration
>
>  def __contains__(self, key):
>  return key in self.keys()
>
>  def __repr__(self):
>  return repr(dict(self.items()))

Thanks a lot for your help.  I think what you have written is much
better than what I could have come up with on my own.  I guess I just
need more experience.
Thanks,
Jeremy

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


Re: How can I use __setitem__ method of dict object?

2007-02-07 Thread jeremito
On Feb 6, 5:10 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> jeremito a écrit :
>  > On Feb 6, 2:36 pm, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote:
>
>  >
> (snip)
>
>  >>Here's an alternative implementation, so you get the idea.
>  >>
>  >>class Xs(dict):
>
> oops ! I meant:
>   class Xs(object):
>
> of course...
>
> (snip)
>
> > I guess I just
> > need more experience.
>
> Possibly - but not only. You may want to have a look at the
> FineManual(tm) for all this kind of "magic", starting with 
> :http://docs.python.org/ref/specialnames.htmlhttp://docs.python.org/ref/sequence-types.html
>
> HTH

Thanks again!  Sometimes the problem is simply not knowing where to
find the documentation, or finding the right portion of the
documentation.  Your help has been invaluable.

Jeremy

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


Re: How can I use __setitem__ method of dict object?

2007-02-07 Thread jeremito
On Feb 7, 8:28 am, "jeremito" <[EMAIL PROTECTED]> wrote:
> On Feb 6, 5:10 pm, Bruno Desthuilliers
>
>
>
> <[EMAIL PROTECTED]> wrote:
> > jeremito a écrit :
> >  > On Feb 6, 2:36 pm, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote:
>
> > (snip)
>
> >  >>Here's an alternative implementation, so you get the idea.
>
> >  >>class Xs(dict):
>
> > oops ! I meant:
> >   class Xs(object):
>
> > of course...
>
> > (snip)
>
> > > I guess I just
> > > need more experience.
>
> > Possibly - but not only. You may want to have a look at the
> > FineManual(tm) for all this kind of "magic", starting with 
> > :http://docs.python.org/ref/specialnames.htmlhttp://docs.python.org/re...
>
> > HTH
>
> Thanks again!  Sometimes the problem is simply not knowing where to
> find the documentation, or finding the right portion of the
> documentation.  Your help has been invaluable.
>
> Jeremy

One more question.  I will be asking for the value of cs.xT *many*
(~millions) times.  Therefore I don't want it's value to be calculated
on the fly.  How can I set the value of xT whenever xS, xF, or xG are
changed, but not allow it to be set directly?  From the example given
previously, it seems like it can't be done this way.

Thans,
Jeremy

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


Re: How can I use __setitem__ method of dict object?

2007-02-07 Thread jeremito
On Feb 7, 12:48 pm, Jussi Salmela <[EMAIL PROTECTED]> wrote:
> jeremito kirjoitti:
>
> > On Feb 7, 8:28 am, "jeremito" <[EMAIL PROTECTED]> wrote:
> >> On Feb 6, 5:10 pm, Bruno Desthuilliers
>
> >> <[EMAIL PROTECTED]> wrote:
> >>> jeremito a écrit :
> >>>  > On Feb 6, 2:36 pm, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote:
> >>> (snip)
> >>>  >>Here's an alternative implementation, so you get the idea.
> >>>  >>class Xs(dict):
> >>> oops ! I meant:
> >>>   class Xs(object):
> >>> of course...
> >>> (snip)
> >>>> I guess I just
> >>>> need more experience.
> >>> Possibly - but not only. You may want to have a look at the
> >>> FineManual(tm) for all this kind of "magic", starting with 
> >>> :http://docs.python.org/ref/specialnames.htmlhttp://docs.python.org/re...
> >>> HTH
> >> Thanks again!  Sometimes the problem is simply not knowing where to
> >> find the documentation, or finding the right portion of the
> >> documentation.  Your help has been invaluable.
>
> >> Jeremy
>
> > One more question.  I will be asking for the value of cs.xT *many*
> > (~millions) times.  Therefore I don't want it's value to be calculated
> > on the fly.  How can I set the value of xT whenever xS, xF, or xG are
> > changed, but not allow it to be set directly?  From the example given
> > previously, it seems like it can't be done this way.
>
> > Thans,
> > Jeremy
>
> I'm certainly no wizard in timing, but here goes:
>
> Using the class definition given to you by Bruno, adding the following
> to the end (and 'import timeit' at the start):
>
> #
> lst = timeit.Timer('for i in xrange(10): xx=xs.xT', \
> 'from __main__ import Xs;xs = Xs()').repeat(100,1000)
> lst.sort()
> print lst
> print 'Average:', sum(lst)/100
> #
>
> I get the output:
> [0.017246605364648282, 0.01727426251101738, 0.017275659336591698,
> 0.017290745052793044, 0.01733264982001903, 0.017347735536220377,
>
>   and so on ...
>
> 0.029063749722380933, 0.029163762433493667, 0.029422733894950315,
> 0.029790378386079785]
> Average: 0.0182474979362
>
> Thus: A 1000 assignments take a little over 18 milliseconds. The largest
> values in the list are probably caused bu GC occurring. But even 30 ms /
> 1000 iterations i.e. 30 microseconds per fetch seems to be fast enough.
>
> All this depends of course on the computer used. Mine is on the fast
> side, you might test it on your PC.
>
> The correct way of programming is to find a good simple algorithm and
> the data structures needed, to program a clean solution with them and
> then when you've got a correctly operating application and THEN IF you
> need speed try to do something about it.
>
> "Premature optimization is the worst evil" or something like that is how
> the saying goes.
>
> Hopefully I'm not leading you astray by being a novice in using the
> timeit module.
>
> HTH,
> Jussi

Thank you.  Once again this mailing list has proven most helpful.  I
realize it probably isn't worth my time (or stress) to figure out how
to avoid calculating xT on the fly-at least not yet.

Jeremy

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


Distutils -- specifying compiled output name

2006-05-25 Thread jeremito
I am using distutils to comiple/install a c extension created with
SWIG.  However I need to be able to specify the output filename from
gcc.  I tried doing this with the "extra_compile_args" and
"extra_link_args" by setting them equal to "-o MyOutputName.so" but
that didn't work.  Can someone show me how to specify the output name?
Thanks,
Jeremy

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


Removing compile option in distutils

2007-12-27 Thread jeremito
Hello all,

I am using distutils for building/compiling my Python extensions.  The
default configuration tells the compiler to generate debug information
with the "-g" flag.  I don't want this, but I can't seem to figure out
how to get rid of it.  Does anyone now how?

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