On Sep 14, 4:38 pm, de...@web.de (Diez B. Roggisch) wrote:
lallouslall...@lgwm.org writes:
How can I keep the class private and have the following work:
[code]
class __internal_class(object):
@staticmethod
def meth1(s):
print meth1:, s
@staticmethod
def
How can I keep the class private and have the following work:
[code]
class __internal_class(object):
@staticmethod
def meth1(s):
print meth1:, s
@staticmethod
def meth2(s):
print meth2:,
__internal_class.meth1(s)
x = __internal_class()
x.meth2('sdf')
Hello,
I wonder if anyone read this:
http://www.amazon.com/PYTHON-2-6-Extending-Embedding-documentation/dp/1441419608/ref=sr_1_7?ie=UTF8s=booksqid=1277214352sr=1-7
or this:
http://www.amazon.com/Python-Extending-Embedding-Documentation-Manual/dp/1441412743/ref=pd_sim_b_3
Are these books just a
Hi again,
Well, it seems the printed version of the manual. Can anyone suggest a
nice book to learn more about the Python C Api?
Thanks,
Elias
--
http://mail.python.org/mailman/listinfo/python-list
.
:)
On Jun 22, 4:24 pm, James Mills prolo...@shortcircuit.net.au wrote:
On Wed, Jun 23, 2010 at 12:14 AM, lallous lall...@lgwm.org wrote:
Well, it seems the printed version of the manual. Can anyone suggest a
nice book to learn more about the Python C Api?
It's not really a book, but how about
On Jun 22, 4:49 pm, James Mills prolo...@shortcircuit.net.au wrote:
On Wed, Jun 23, 2010 at 12:27 AM, lallous lall...@lgwm.org wrote:
For me it is not a matter of competency to seek a book: organized,
structured and uniform way of presenting information.
Nonetheless, I always refer
Hello,
Learning Python from the help file and online resources can leave one
with many gaps. Can someone comment on the following:
# -
class X:
T = 1
def f1(self, arg):
print f1, arg=%d % arg
def f2(self, arg):
print f2, arg=%d % arg
def f3(self, arg):
On Feb 21, 11:21 am, Lie Ryan lie.1...@gmail.com wrote:
On 02/21/10 19:27,lallouswrote:
snip
If the base defines the method and it was empty, then my C++ code
would still call the function. This is not optimal because I don't
want to go from C++ to Python if the _derived_ class does not
On Feb 22, 12:42 am, Gregory Ewing greg.ew...@canterbury.ac.nz
wrote:
lallouswrote:
If the base defines the method and it was empty, then my C++ code
would still call the function. This is not optimal because I don't
want to go from C++ to Python if the _derived_ class does not
implement
Hello
I am still learning Python, and have a question, perhaps I can shorten
the code:
L = (
(1, 2, 3),
(4,),
(5,),
(6, 7)
)
for x in L:
print x
What I want, is to write the for loop, something like this:
for (first_element, the_rest) in L:
print first_element
for x in
Thank you all for the replies.
The solution using Python 3's syntax look very intuitive.
Thanks Tim, Arnaud for the idea (I am using 2.x)
--
Elias
On Feb 25, 1:28 pm, lallous elias.bachaal...@gmail.com wrote:
Hello
I am still learning Python, and have a question, perhaps I can shorten
On Feb 20, 6:08 pm, Martin v. Loewis mar...@v.loewis.de wrote:
class C1:
# Pure virtual
def cb(self, param1, param2):
This is a callback
�...@param param1: ...
�...@param param2: ...
raise NotImplementedError,
Thanks everyone for the answers.
The dispatcher() is actually sits in C++ code.
So my code receives an object that is an instance of the base class,
it PyObject_GetAttrString(py_obj, 'funcname'). If the attribute exists
I will call PyObject_CallMethod on it.
If the base defines the method and
Hello
How can I do something similar to pure virtual functions in C++ ?
Let us consider this:
class C1:
# Pure virtual
def cb(self, param1, param2):
This is a callback
@param param1: ...
@param param2: ...
raise NotImplementedError,
Hello
Is there is any Python library that allow such things:
Given a string expression as: x + 5 + x * (y + 2), any library that
can develop the equation for example.
Or if we say factor with x then it renders the expression with x *
( rest of expression ).
There could be a functionality where
Hello,
I am still fairly new to Python. Can someone explain to me why there
is a difference in f and g:
def make_power(n):
return lambda x: x ** n
# Create a set of exponential functions
f = [lambda x: x ** n for n in xrange(2, 5)]
g = [make_power(n) for n in xrange(2, 5)]
print f[0](3),
Yes it should be listed somewhere, now I get it. Thanks Arnaud.
--
Elias
On Feb 18, 1:47 pm, Arnaud Delobelle arno...@googlemail.com wrote:
lallous elias.bachaal...@gmail.com writes:
Hello,
I am still fairly new to Python. Can someone explain to me why there
is a difference in f and g
On Feb 18, 1:56 pm, D'Arcy J.M. Cain da...@druid.net wrote:
On Thu, 18 Feb 2010 04:28:00 -0800 (PST)
lallous elias.bachaal...@gmail.com wrote:
def make_power(n):
return lambda x: x ** n
Hint: type(make_power(2))
Did you expect that to return int?
No, I expect to see a specialized
@Ulrich:
On Feb 4, 1:09 pm, Ulrich Eckhardt eckha...@satorlaser.com wrote:
Just for the record: Neither of the below methods actually produce a
multiline string. They only spread a string containing one line over
multiple lines of source code.
I meant:
Note - Note: I don't want to use new
Hello
Maybe that's already documented, but it seems the parser accepts to
build a long string w/o really using the first method:
# Method1
x = line1 + \ # cannot use comments!
line2+ \
line3
and instead using a list with one element like this:
# Method2
x = [
line1 # can use comments
line2
Hello
PyObject* PyImport_ImportModule( const char *name)
How to specify a full file path instead and a module name?
Like PyImport_SomeFunction(const char *path_to_script, const char *name)
Thanks,
Elias
--
http://mail.python.org/mailman/listinfo/python-list
Looks like one way to do that is to use something like:
s.sprintf(
import imp\n
imp.load_source('%s', r'%s'), modname, script_path);
PyRun_SimpleString(s.c_str());
Unless someone has a better suggestion.
Regards,
Elias
lallous lall...@lgwm.org wrote in message news:heir4g$oh
Hello
I have an a class defined as:
class __object(object):
pass
Now, I call a C function that takes a PyObject* and checks its type:
if (PyString_Check(obj)) ...
if (PySequence_Check(obj))
Before doing the check, I print the passed object with PyObject_Str() and
get:
);
if (sz == -1 || PyErr_Occurred() != NULL)
{
PyErr_Clear();
return false;
}
return true;
}
I don't like it, any other suggestions?
--
Elias
lallous lall...@lgwm.org wrote in message news:hdr80a$vs...@aioe.org...
Hello
I have an a class defined as:
class __object(object
Hello
class __object(object):
def __getitem__(self, idx):
return getattr(self, idx)
class __dobject(object): pass
x = __object()
setattr(x, 0, hello)
print x[0]
y = __dobject(a=1,b=2)
setattr(y, 0, world)
#print y[0]
How can I, given an object of instance __dobject, add to that
Hello,
Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I don't
need the reference to py_val I should decrement the reference after this
call?
So for example:
PyObject *py_val = PyInt_FromLong(5)
PyObject_SetAttrString(py_obj, val, py_val);
Py_DECREF(py_val)
Right?
If
Hello,
I am a little confused on how to check if a python variable is an integer or
not.
Sometimes PyInt_Check() fails and PyLong_Check() succeeds.
How to properly check for integer values?
OTOH, I tried PyNumber_Check() and:
(1) The doc says: Returns 1 if the object o provides numeric
Hello Daniel,
Thanks for the reply.
Everytime I use PyObject_SetAttrString(obj, attr_name, py_val) and I
don't
need the reference to py_val I should decrement the reference after this
call?
It really depends on /how/ the object is created. If the
method used to create *py_val* increases
Hello
I have 3 questions, hope someone can help:
1)
How can I create an instance class in Python, currently I do:
class empty:
pass
Then anytime I want that class (which I treat like a dictionary):
o = empty()
o.myattr = 1
etc
Is there is a one line syntax to instantiate an instance?
Thanks for your help Carl as usual.
Will go with the getattr override method which is cleaner as you explained.
Regards,
Elias
Carl Banks pavlovevide...@gmail.com wrote in message
news:f02c069c-e536-4c6b-b114-2215aa611...@k17g2000yqh.googlegroups.com...
On Nov 2, 7:16 am, lallous lall
Hello Group,
If a reference to an imported module reaches zero will Python cleanup
everything related to that module and unload the compiled code, etc, etc...?
For example:
import sys
m = [__import__(str(x)) for x in xrange(1,4)]
del sys.modules['1']
del m[0]
print m
Is module['1'] really
Hello Shay,
Shay Telfer shaypyt...@earthyself.com wrote in message
news:mailman.1021.1254988413.2807.python-l...@python.org...
Hi...
It seems that python will accept a .py file piped from stdin, but not a
.pyc file (and there don't seem to be any flags to allow this). Am I
missing
Hello Shay,
Shay Telfer shaypyt...@earthyself.com wrote in message
news:mailman.1021.1254988413.2807.python-l...@python.org...
Hi...
It seems that python will accept a .py file piped from stdin, but not a
.pyc file (and there don't seem to be any flags to allow this). Am I
missing
Hello Shay,
Shay Telfer shaypyt...@earthyself.com wrote in message
news:mailman.1021.1254988413.2807.python-l...@python.org...
Hi...
It seems that python will accept a .py file piped from stdin, but not a
.pyc file (and there don't seem to be any flags to allow this). Am I
missing
Hello
Try re-asking your question in a more general way so that users w/o
background information (about those classes and modules you're using) can
help you with your problem.
--
Elias
bbarb...@inescporto.pt wrote in message
news:mailman.968.1254922056.2807.python-l...@python.org...
Good
Carl Banks pavlovevide...@gmail.com wrote in message
news:d50bba1e-b272-4e39-8a58-377531278...@z4g2000prh.googlegroups.com...
On Sep 30, 5:24 am, lallous lall...@lgwm.org wrote:
Hello
After using the PyCObject, I cannot pickle the class anymore.
Any simple solution to this problem
Hello Timothy,
Timothy W. Grove tim_gr...@sil.org wrote in message
news:mailman.726.1254378947.2807.python-l...@python.org...
Recently I purchased some software to recover some files which I had lost.
(A python project, incidentally! Yes, I should have kept better backups!)
They were nowhere
Hello
What is faster when clearing a list?
del L[:]
or
L = []
--
Elias
--
http://mail.python.org/mailman/listinfo/python-list
chad cdal...@gmail.com wrote in message
news:4e260ef3-8b0e-4613-a4f8-1c267e875...@u16g2000pru.googlegroups.com...
On Sep 29, 7:20 pm, Tim Chase python.l...@tim.thechases.com wrote:
What's the sanest way to print out all the files in the directory that
start with the underscore? Ie, I just
Thanks everyone.
Finally, I used Falcolas suggestion and took into consideration
sturlamolden's comments.
Regards,
Elias
lallous lall...@lgwm.org wrote in message news:h9sgcn$iv...@aioe.org...
Hello
From my C extension module I want to store a C pointer in a given
PyObject.
The only way
Hello
Can anyone suggest a good book Python book for advancing from beginner
level?
(I started with Learning Python 3rd ed)
Regards,
Elias
--
http://mail.python.org/mailman/listinfo/python-list
...
On Sep 29, 2:27 am, lallous lall...@lgwm.org wrote:
Hello
From my C extension module I want to store a C pointer in a given
PyObject.
The only way I figure how to do it is to use Py_BuildValues and store the
poiner casted to Py_ssize_t, thus:
Py_BuildValues(n, (Py_ssize_t)my_ptr)
Can
Hello
From my C extension module I want to store a C pointer in a given PyObject.
The only way I figure how to do it is to use Py_BuildValues and store the
poiner casted to Py_ssize_t, thus:
Py_BuildValues(n, (Py_ssize_t)my_ptr)
Can it be done differently?
Regards,
Elias
--
Thanks Carl, that does it!
--
Elias
Carl Banks pavlovevide...@gmail.com wrote in message
news:48ce343a-36ef-406f-bea3-851444785...@b18g2000vbl.googlegroups.com...
On Sep 28, 8:19 am, lallous lall...@lgwm.org wrote:
Hello
How to programmatically create a class instance of a given Python
Hello
Suppose I have this code:
class X:
def __init__(self, n):
self.L = [x for x in xrange(0, n+1)]
class Y:
def __init__(self, n):
self.M = [X(x) for x in xrange(0, n)]
t = Y(5)
How can I easily print t and all its nested attributes? (Something like
PHP's print_r())
Hello
How to programmatically create a class instance of a given Python class?
For example to create a new list there is the PyObject *PyList_New() but
suppose the user already defined a class:
class X: pass
How to create an instance of it from my C extension module?
Regards,
Elias
--
Hello,
Thank you all for your replies.
A simple suggestion as Chris' actually might help.
I am used to two spaces indentation since years, and apparently two
spaces won't make it clear if no visuals were present (braces, or
begin/end, ...)
Though it is not comfortable to change a style, I will
Hello
In C/C++ you use the braces where as in Python you use the indentation
levels.
Most editors offer a Ctrl+[ to match the braces so that you can easily
identify the scopes (more correctly statements blocks).
I am finding it difficult to see blocks and/or jump from end to start
with some IDE
Hello
I am new to python and have some questions.
How to copy objects using another method than this:
class op:
def __init__(self, op):
for x in dir(op):
if x[:2] == __:
continue
setattr(self, x, getattr(op, x))
o = op(src)
I tried to copy
49 matches
Mail list logo