On Sep 14, 4:38 pm, de...@web.de (Diez B. Roggisch) wrote:
> lallous writes:
> > How can I keep the class private and have the following work:
>
> > [code]
> > class __internal_class(object):
> > @staticmethod
> > def meth1(s):
> >
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')
On Jun 22, 4:49 pm, James Mills wrote:
> On Wed, Jun 23, 2010 at 12:27 AM, lallous 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 to the sou
asier.
:)
On Jun 22, 4:24 pm, James Mills wrote:
> On Wed, Jun 23, 2010 at 12:14 AM, lallous 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 the sourc
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
Hello,
I wonder if anyone read this:
http://www.amazon.com/PYTHON-2-6-Extending-Embedding-documentation/dp/1441419608/ref=sr_1_7?ie=UTF8&s=books&qid=1277214352&sr=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
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):
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 wrote:
> Hello
>
> I am still learning Python, and have a question, perhaps I can shorten
> the code:
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 the_res
On Feb 22, 12:42 am, Gregory Ewing
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 the cb.
>
> I would
On Feb 21, 11:21 am, Lie Ryan wrote:
> On 02/21/10 19:27,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 t
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 it
On Feb 20, 6:08 pm, "Martin v. Loewis" wrote:
> >> class C1:
>
> >> # Pure virtual
> >> def cb(self, param1, param2):
> >> """
> >> This is a callback
>
> >> �...@param param1: ...
> >> �...@param param2: ...
> >> """
> >> raise NotImpl
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 NotImplementedErro
On Feb 18, 1:56 pm, "D'Arcy J.M. Cain" wrote:
> On Thu, 18 Feb 2010 04:28:00 -0800 (PST)
>
> lallous wrote:
> > def make_power(n):
> > return lambda x: x ** n
>
> Hint: type(make_power(2))
>
> Did you expect that to return "int"?
>
Yes it should be listed somewhere, now I get it. Thanks Arnaud.
--
Elias
On Feb 18, 1:47 pm, Arnaud Delobelle wrote:
> lallous writes:
> > Hello,
>
> > I am still fairly new to Python. Can someone explain to me why there
> > is a difference in f and g:
>
> >
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), f[
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
@Ulrich:
On Feb 4, 1:09 pm, Ulrich Eckhardt 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 lines"
I did not
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
"l
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&
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
);
if (sz == -1 || PyErr_Occurred() != NULL)
{
PyErr_Clear();
return false;
}
return true;
}
I don't like it, any other suggestions?
--
Elias
"lallous" wrote in message news:hdr80a$vs...@aioe.org...
Hello
I have an a class defined as:
class __object(object):
pa
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:
passed
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", a
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 t
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 prot
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 s
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?
A
Thanks for your help Carl as usual.
Will go with the getattr override method which is cleaner as you explained.
Regards,
Elias
"Carl Banks" wrote in message
news:f02c069c-e536-4c6b-b114-2215aa611...@k17g2000yqh.googlegroups.com...
On Nov 2, 7:16 am, "lallous" wrote:
H
Hello,
Is there is a way, using the Python C api, to install an exception handler
that:
- will be triggered when an exception occurs
- analyze the reason of the exception
- correct the situation and try again (something like exception handling on
windows where the exception handler can retriev
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 un
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
wrote in message
news:mailman.968.1254922056.2807.python-l...@python.org...
Good morning all!
I am tryin
Hello Shay,
"Shay Telfer" 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 something?
Eg
cat blah.py | py
Hello Shay,
"Shay Telfer" 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 something?
Eg
cat blah.py | py
Hello Shay,
"Shay Telfer" 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 something?
Eg
cat blah.py | py
"Carl Banks" wrote in message
news:d50bba1e-b272-4e39-8a58-377531278...@z4g2000prh.googlegroups.com...
On Sep 30, 5:24 am, "lallous" wrote:
Hello
After using the PyCObject, I cannot pickle the class anymore.
Any simple solution to this problem? (or resorting to __r
Hello
What is faster when clearing a list?
del L[:]
or
L = []
--
Elias
--
http://mail.python.org/mailman/listinfo/python-list
Hello Timothy,
"Timothy W. Grove" 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 to found in the
p 29, 2:27 am, "lallous" 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 it
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
Thanks everyone.
Finally, I used Falcolas suggestion and took into consideration
sturlamolden's comments.
Regards,
Elias
"lallous" 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 w
"chad" wrote in message
news:4e260ef3-8b0e-4613-a4f8-1c267e875...@u16g2000pru.googlegroups.com...
On Sep 29, 7:20 pm, Tim Chase wrote:
> What's the sanest way to print out all the files in the directory that
> start with the underscore? Ie, I just want to list _1, _2, _3, _4.
I'd use a string
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())
Thanks Carl, that does it!
--
Elias
"Carl Banks" wrote in message
news:48ce343a-36ef-406f-bea3-851444785...@b18g2000vbl.googlegroups.com...
On Sep 28, 8:19 am, "lallous" wrote:
Hello
How to programmatically create a class instance of a given Python class?
For example
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
--
http://ma
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
--
ht
le, I will play with 8
spaces indentation, it would naturally make it clearer ;)
--
Elias
On Sep 3, 11:43 am, Chris Rebert wrote:
> On Thu, Sep 3, 2009 at 2:38 AM, lallous wrote:
> > Hello
>
> > In C/C++ you use the braces where as in Python you use the indentation
> > lev
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 wi
50 matches
Mail list logo