Re: trying to create simple py script

2012-08-10 Thread Ifthikhan Nazeem
I have been using Flask for a while and it's been a positive experience so
far. It's simplicity helps you to get things done faster.


On Fri, Aug 10, 2012 at 8:35 AM, Lutz Horn  wrote:

> Hi Smaran,
>
> Am Do, 9. Aug 2012, um 23:52, schrieb Smaran Harihar:
> > I am trying to create a simple cgi-script to receive a Ajax
> > call, manipulate the string received and send it back as JSON.
>
> I can recommend bottle. The following example manipulates a JSON request
> body and returns it. That is *much* easier than using CGI.
>
> #!/usr/bin/env python
>
> from bottle import request, post, run
>
> @post('/hello')
> def index():
> if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
> body = request.json
> body["baz"] = "qux"
> return body
> else:
> return 'This is a normal HTTP Post request.'
>
> run(host='localhost', port=8080)
>
> Lutz
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socketserver.BaseRequestHandler and socketserver.StreamRequestServer docs

2012-08-10 Thread lipska the kat

On 09/08/12 20:45, Terry Reedy wrote:

On 8/9/2012 1:39 PM, Dennis Lee Bieber wrote:

On Thu, 09 Aug 2012 16:15:33 +0100, lipska the kat
 declaimed the following in
gmane.comp.python.general:



in the examples in this chapter we see usage examples for
socketserver.BaseRequestHandler


[snip]



I think the doc can be improved a bit and opened an issue to "Improve
socketserver doc"
http://bugs.python.org/issue15608


Thank you for your reasonable responses
I have sent an email to d...@python.org
politely suggesting a couple of improvements to
the socketserver documentation

lipska

--
Lipska the Kat: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
--
http://mail.python.org/mailman/listinfo/python-list


[c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Giacomo Alzetta
I'm trying to implement a c-extension which defines a new class(ModPolynomial 
on the python side, ModPoly on the C-side).
At the moment I'm writing the in-place addition, but I get a *really* strange 
behaviour.

Here's the code for the in-place addition:

#define ModPoly_Check(v) (PyObject_TypeCheck(v, &ModPolyType))
[...]
static PyObject *
ModPoly_InPlaceAdd(PyObject *self, PyObject *other)
{

if (!ModPoly_Check(self)) {
// This should never occur for in-place addition, am I correct?
if (!ModPoly_Check(other)) {
PyErr_SetString(PyExc_TypeError, "Neither argument is a 
ModPolynomial.");
return NULL;
}
return ModPoly_InPlaceAdd(other, self);
} else {
if (!PyInt_Check(other) && !PyLong_Check(other)) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
}

ModPoly *Tself = (ModPoly *)self;
PyObject *tmp, *tmp2;
tmp = PyNumber_Add(Tself->ob_item[0], other);
tmp2 = PyNumber_Remainder(tmp, Tself->n_modulus);

Py_DECREF(tmp);
tmp = Tself->ob_item[0];
Tself->ob_item[0] = tmp2;
Py_DECREF(tmp);

printf("%d\n", (int)ModPoly_Check(self));
return self;

}

And here's an example usage:

>>> from algebra import polynomials
>>> pol = polynomials.ModPolynomial(3,17)
>>> pol += 5
1
>>> pol

>>> 

Now, how come my ModPolynomial suddenly becomes a read-only buffer, even though 
that last printf tells us that the object returned is of the correct type?
If I raise an exception instead of returning self, the ModPolynomial gets 
incremented correctly. If I use the Py_RETURN_NONE macro, the ModPolynomial is 
correctly replaced by None.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: no data exclution and unique combination.

2012-08-10 Thread Hans Mulder
On 9/08/12 23:33:58, Terry Reedy wrote:
> On 8/9/2012 4:06 PM, giuseppe.amatu...@gmail.com wrote:
[...]
>> unique=dict()
>> for row in  array2D :
>>  row = tuple(row)
>>  if row in unique:
>>  unique[row] += 1
>>  else:
>>  unique[row] = 1
> 
> I believe the 4 lines above are equivalent to
>unique[row] = unique.get(row, 0) + 1


I would write that bit as:

from collections import defaultdict

unique = defaultdict(int)
for row in  array2D:
unique[row] += 1


Hope this helps,

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


Re: save dictionary to a file without brackets.

2012-08-10 Thread Steven D'Aprano
On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote:

> On 08/09/12 18:33, Mark Lawrence wrote:
>> On 10/08/2012 00:24, Roy Smith wrote:
 ... you mean, Python lets you make a hash of it?
>>>
>>> Only if you order it with spam, spam, spam, spam, spam, spam, and
>>> spam.
>> 
>> Now now gentlemen we're getting slightly off topic here and wouldn't
>> want to upset the people who insist on staying on topic.  Or would we?
>> :)
> 
> We apologise for the off-topicness in the thread.  Those responsible
> have been sacked...


Sacked? They were beaten to death with a large halibut!


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


[newbie] A question about lists and strings

2012-08-10 Thread Mok-Kong Shen


In an earlier question about lists, I was told about the issue of
creation of local names in a function. However, I still can't
understand why the program below outputs:

[999] sss
[999]

and not two identical lines of output. For both operators "+=" should
anyway work in similar manner in the function xx in my view.

Thanks for your help in advance.

M. K. Shen

--

def xx(list,str):
  list+=[999]
  str+="sss"

lista=[]
stra=""
lista+=[999]
stra+="sss"
print(lista,stra)

listb=[]
strb=""
xx(listb,strb)
print(listb,strb)
--
http://mail.python.org/mailman/listinfo/python-list


Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Hans Mulder
On 10/08/12 10:20:00, Giacomo Alzetta wrote:
> I'm trying to implement a c-extension which defines a new class(ModPolynomial 
> on the python side, ModPoly on the C-side).
> At the moment I'm writing the in-place addition, but I get a *really* strange 
> behaviour.
> 
> Here's the code for the in-place addition:
> 
> #define ModPoly_Check(v) (PyObject_TypeCheck(v, &ModPolyType))
> [...]
> static PyObject *
> ModPoly_InPlaceAdd(PyObject *self, PyObject *other)
> {
> 
> if (!ModPoly_Check(self)) {
> // This should never occur for in-place addition, am I correct?
> if (!ModPoly_Check(other)) {
> PyErr_SetString(PyExc_TypeError, "Neither argument is a 
> ModPolynomial.");
> return NULL;
> }
> return ModPoly_InPlaceAdd(other, self);
> } else {
> if (!PyInt_Check(other) && !PyLong_Check(other)) {
> Py_INCREF(Py_NotImplemented);
> return Py_NotImplemented;
> }
> }
> 
> ModPoly *Tself = (ModPoly *)self;
> PyObject *tmp, *tmp2;
> tmp = PyNumber_Add(Tself->ob_item[0], other);
> tmp2 = PyNumber_Remainder(tmp, Tself->n_modulus);
> 
> Py_DECREF(tmp);
> tmp = Tself->ob_item[0];
> Tself->ob_item[0] = tmp2;
> Py_DECREF(tmp);
> 
> printf("%d\n", (int)ModPoly_Check(self));
> return self;
> 
> }

I have no experience writing extensions in C, but as I see it,
you're returning a new reference to self, so you'd need:

Py_INCREF(self);

If you don't, then a Py_DECREF inside the assignment operator
causes your polynomial to be garbage collected.  Its heap slot
is later used for the unrelated buffer object you're seeing.

Hope this helps,

-- HansM

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Roman Vashkevich
10.08.2012, в 13:19, Mok-Kong Shen написал(а):

> 
> In an earlier question about lists, I was told about the issue of
> creation of local names in a function. However, I still can't
> understand why the program below outputs:
> 
> [999] sss
> [999]
> 
> and not two identical lines of output. For both operators "+=" should
> anyway work in similar manner in the function xx in my view.
> 
> Thanks for your help in advance.
> 
> M. K. Shen
> 
> --
> 
> def xx(list,str):
>  list+=[999]
>  str+="sss"
> 
> lista=[]
> stra=""
> lista+=[999]
> stra+="sss"
> print(lista,stra)
> 
> listb=[]
> strb=""
> xx(listb,strb)
> print(listb,strb)
> -- 
> http://mail.python.org/mailman/listinfo/python-list

It seems like your xx() function doesn't return local str parameter and prints 
the global empty str, whereas it mutates the global list.

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


Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Giacomo Alzetta
Il giorno venerdì 10 agosto 2012 11:22:13 UTC+2, Hans Mulder ha scritto:
> On 10/08/12 10:20:00, Giacomo Alzetta wrote:
> 
> > I'm trying to implement a c-extension which defines a new 
> > class(ModPolynomial on the python side, ModPoly on the C-side).
> 
> > At the moment I'm writing the in-place addition, but I get a *really* 
> > strange behaviour.
> 
> > 
> 
> > Here's the code for the in-place addition:
> 
> > 
> 
> > #define ModPoly_Check(v) (PyObject_TypeCheck(v, &ModPolyType))
> 
> > [...]
> 
> > static PyObject *
> 
> > ModPoly_InPlaceAdd(PyObject *self, PyObject *other)
> 
> > {
> 
> > 
> 
> > if (!ModPoly_Check(self)) {
> 
> > // This should never occur for in-place addition, am I correct?
> 
> > if (!ModPoly_Check(other)) {
> 
> > PyErr_SetString(PyExc_TypeError, "Neither argument is a 
> > ModPolynomial.");
> 
> > return NULL;
> 
> > }
> 
> > return ModPoly_InPlaceAdd(other, self);
> 
> > } else {
> 
> > if (!PyInt_Check(other) && !PyLong_Check(other)) {
> 
> > Py_INCREF(Py_NotImplemented);
> 
> > return Py_NotImplemented;
> 
> > }
> 
> > }
> 
> > 
> 
> > ModPoly *Tself = (ModPoly *)self;
> 
> > PyObject *tmp, *tmp2;
> 
> > tmp = PyNumber_Add(Tself->ob_item[0], other);
> 
> > tmp2 = PyNumber_Remainder(tmp, Tself->n_modulus);
> 
> > 
> 
> > Py_DECREF(tmp);
> 
> > tmp = Tself->ob_item[0];
> 
> > Tself->ob_item[0] = tmp2;
> 
> > Py_DECREF(tmp);
> 
> > 
> 
> > printf("%d\n", (int)ModPoly_Check(self));
> 
> > return self;
> 
> > 
> 
> > }
> 
> 
> 
> I have no experience writing extensions in C, but as I see it,
> 
> you're returning a new reference to self, so you'd need:
> 
> 
> 
> Py_INCREF(self);
> 
> 
> 
> If you don't, then a Py_DECREF inside the assignment operator
> 
> causes your polynomial to be garbage collected.  Its heap slot
> 
> is later used for the unrelated buffer object you're seeing.
> 
> 
> 
> Hope this helps,
> 
> 
> 
> -- HansM

Yes, you're right. I didn't thought the combined operator would do a Py_DECREF 
if the iadd operation was implemented, but it obviosuly makes sense.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: save dictionary to a file without brackets.

2012-08-10 Thread Mark Lawrence

On 10/08/2012 09:54, Steven D'Aprano wrote:

On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote:


On 08/09/12 18:33, Mark Lawrence wrote:

On 10/08/2012 00:24, Roy Smith wrote:

... you mean, Python lets you make a hash of it?


Only if you order it with spam, spam, spam, spam, spam, spam, and
spam.


Now now gentlemen we're getting slightly off topic here and wouldn't
want to upset the people who insist on staying on topic.  Or would we?
:)


We apologise for the off-topicness in the thread.  Those responsible
have been sacked...



Sacked? They were beaten to death with a large halibut!




Well whatever you do *DON'T* mention Cython. I mentioned it just now but 
I think I've got away with it.


--
Cheers.

Mark Lawrence.

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Roman Vashkevich

10.08.2012, в 13:28, Roman Vashkevich написал(а):

> 10.08.2012, в 13:19, Mok-Kong Shen написал(а):
> 
>> 
>> In an earlier question about lists, I was told about the issue of
>> creation of local names in a function. However, I still can't
>> understand why the program below outputs:
>> 
>> [999] sss
>> [999]
>> 
>> and not two identical lines of output. For both operators "+=" should
>> anyway work in similar manner in the function xx in my view.
>> 
>> Thanks for your help in advance.
>> 
>> M. K. Shen
>> 
>> --
>> 
>> def xx(list,str):
>> list+=[999]
>> str+="sss"
>> 
>> lista=[]
>> stra=""
>> lista+=[999]
>> stra+="sss"
>> print(lista,stra)
>> 
>> listb=[]
>> strb=""
>> xx(listb,strb)
>> print(listb,strb)
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
> 
> It seems like your xx() function doesn't return local str parameter and 
> prints the global empty str, whereas it mutates the global list.
> 
> Roman

Excuse me for the mess I just did in my message:)
The function doesn't print anything of cause. It takes list by reference and 
creates a new local str.
When it's called with listb and strb arguments, listb is passed by reference 
and mutated. A string "sss" is concatenated with an empty local str. Nothing 
more happens. Since local str is not returned by xx(), it can not be expected 
to be printed out in the statement that follows. What is printed out in the 
print statement is the mutated listb and the global strb.

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Peter Otten
Mok-Kong Shen wrote:

> 
> In an earlier question about lists, I was told about the issue of
> creation of local names in a function. However, I still can't
> understand why the program below outputs:
> 
> [999] sss
> [999]
> 
> and not two identical lines of output. For both operators "+=" should
> anyway work in similar manner in the function xx in my view.
> 
> Thanks for your help in advance.
> 
> M. K. Shen
> 
> --
> 
> def xx(list,str):
>list+=[999]
>str+="sss"

a += b

is internally translated into to

a = a.__iadd__(b)

If the 'list' class were implemented in Python it would look like

class list:
   def __iadd__(self, other):
   for item in other:
   self.append(item)
   return self

i. e. the original list is modified when you perform += and you'll see the 
modification when you look at any name bound to that original list:

b = a = [1, 2]
a += [3, 4]
print a # [1, 2, 3, 4]
print b # [1, 2, 3, 4]

Strings on the other hand are "immutable" -- they cannot be altered after 
the initial creation. The hypothetical __iadd__() implementation is

class str:
def __iadd__(self, other):
return self + other

So += rebinds a name to a new string:

b = a = "first"
a += "second"
print b # first
print a # firstsecond

Armed with this knowledge

> lista=[]
> stra=""
> lista+=[999]

[999] is appended to lista and lista is rebound to itself.

> stra+="sss"

A new string "" + "sss" is created and stra is bound to that new string.

> print(lista,stra)

 
> listb=[]
> strb=""
> xx(listb,strb)

Inside xx() 

(1) 999 is appended to listb and the local variable list is rebound.
(2) A new string "" + "sss" is created and bound to the local variable str.

> print(listb,strb)

If you have understood the above here's a little brain teaser:

>>> a = ([1,2,3],)
>>> a[0] += [4, 5]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'tuple' object does not support item assignment

>>> a[0]

What are the contents of a[0] now?


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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Dave Angel
On 08/10/2012 05:19 AM, Mok-Kong Shen wrote:
>
> In an earlier question about lists, I was told about the issue of
> creation of local names in a function. However, I still can't
> understand why the program below outputs:
>
> [999] sss
> [999]
>
> and not two identical lines of output. For both operators "+=" should
> anyway work in similar manner in the function xx in my view.
>
> Thanks for your help in advance.
>
> M. K. Shen
>
> --
>
> def xx(list,str):
>   list+=[999]
>   str+="sss"
>
> lista=[]
> stra=""
> lista+=[999]
> stra+="sss"
> print(lista,stra)
>
> listb=[]
> strb=""
> xx(listb,strb)
> print(listb,strb)

I'm rewriting your xx function so it doesn't overwrite reserved words,
list and str.

def xx(mylist, mystring):
mylist += [999]
mystring += "xxx"

There are a couple of effects you need to understand in order to see
what's happening.

First, some terminology.  You don't assign values in Python, you bind a
name or another lvalue to an object.  a=650  builds an object of type
int, and binds it to the name a.  if you then say b=a, you bind b to the
*SAME* object, the previously created int object of value 650.  It can
be useful to print the id() of an object, to convince yourself that
they're actually the same. So if you print id(a) and id(b), you'll get
the same value.  But if you said  c=651 and d=651, you'd have two
objects, and the two names would be bound to different objects, with
different ids.

The += operator is an example of an augmented assignment operator. 
Others that behave the same way include *=  -=  and so on.

The += operator tries to modify the object referred to by the left hand
side, by modifying that object in place. If that fails, perhaps because
the object is immutable, then it builds a new object, and binds the left
side to that new object.

So, if you have a list, and you use += to append to it, you still have
the same list object, but it's longer now.  If you have a string, or an
int, or ... that's immutable, then it builds a new one, and binds it to
the left side.

Now, put those two operations inside a function, and what do we have ? 
Let's go through the function, looking at what happens.

Local parameter mylist gets bound to the list object bound to listb. 
The object is not copied, it's now bound to new names, one in the global
space, one local.  When the mylist +=  statement is executed, it
modifies that object, and instantly the global "variable" listb is modified.

Local parameter mystring gets bound to the string object bound to strb. 
We still only have one (immutable) object.  When the mystring +=
statement is executed, it creates a new string object by concatenating
the old one and the "xxx" string.  At this point, we can print
id(mystring) and see that it changed.  When the function returns, the
local symbols are unbound, and the new string object is discarded since
there are no longer any refs.

At this point, in top-level code, the listb object has been modified,
and the strb one has not;  it still is bound to the old value.



-- 

DaveA

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Mok-Kong Shen

Am 10.08.2012 11:48, schrieb Roman Vashkevich:

[snip]

>The function  It takes list by reference and creates a new local
> str. When it's called with listb and strb arguments, listb is passed
> by reference and mutated. A string "sss" is concatenated with an
> empty local str. Nothing more happens. Since local str is not
> returned by xx(), it can not be expected to be printed out in the
> statement that follows. What is printed out in the print statement is
> the mutated listb and the global strb.

Thanks for the explanation of the output obtained. But this means
nonetheless that parameters of types lists and strings are dealt with
in "inherently" (semantically) different ways by Python, right?

M. K. Shen

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Mok-Kong Shen

Am 10.08.2012 12:07, schrieb Dave Angel:
[snip]

At this point, in top-level code, the listb object has been modified,
and the strb one has not;  it still is bound to the old value.


This means there is no way of modifying a string at the top level
via a function, excepting through returning a new value and assigning
that to the string name at the top level. Please again correct me, if
I am wrong.

M. K. Shen

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Chris Angelico
On Fri, Aug 10, 2012 at 8:12 PM, Mok-Kong Shen
 wrote:
> Thanks for the explanation of the output obtained. But this means
> nonetheless that parameters of types lists and strings are dealt with
> in "inherently" (semantically) different ways by Python, right?

It's nothing to do with parameters, but yes, lists are mutable and
strings are immutable. A tuple will behave the same way a string does:

>>> a
(1, 2, 3, 4)
>>> b=a
>>> a+=5,# note that "5," is a one-element tuple
>>> a
(1, 2, 3, 4, 5)
>>> b
(1, 2, 3, 4)


By the way:

On Fri, Aug 10, 2012 at 8:07 PM, Dave Angel  wrote:
> But if you said  c=651 and d=651, you'd have two
> objects, and the two names would be bound to different objects, with
> different ids.

To be more accurate, you *may* have two different objects. It's
possible for things to be optimized (eg with small numbers, or with
constants compiled at the same time).

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Dave Angel
On 08/10/2012 06:12 AM, Mok-Kong Shen wrote:
> Am 10.08.2012 11:48, schrieb Roman Vashkevich:
>> [snip]
> >The function  It takes list by reference and creates a new local
> > str. When it's called with listb and strb arguments, listb is passed
> > by reference and mutated. A string "sss" is concatenated with an
> > empty local str. Nothing more happens. Since local str is not
> > returned by xx(), it can not be expected to be printed out in the
> > statement that follows. What is printed out in the print statement is
> > the mutated listb and the global strb.
>
> Thanks for the explanation of the output obtained. But this means
> nonetheless that parameters of types lists and strings are dealt with
> in "inherently" (semantically) different ways by Python, right?
>
> M. K. Shen
>

Nothing to do with parameters.  Lists are mutable, and strings are
immutable, so += behaves differently.



-- 

DaveA

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Chris Angelico
On Fri, Aug 10, 2012 at 8:31 PM, Mok-Kong Shen
 wrote:
> This means there is no way of modifying a string at the top level
> via a function, excepting through returning a new value and assigning
> that to the string name at the top level. Please again correct me, if
> I am wrong.

Yes, but you can (ab)use a one-element list as a pointer.

>>> foo=["Hello"]
>>> def mutate(ptr):
ptr[0]="World"

>>> mutate(foo)
>>> print(foo[0])
World

But it's probably worth thinking about exactly why you're wanting to
change that string, and what you're really looking to accomplish.
There may well be a better way.

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Mok-Kong Shen

Am 10.08.2012 12:40, schrieb Chris Angelico:


But it's probably worth thinking about exactly why you're wanting to
change that string, and what you're really looking to accomplish.
There may well be a better way.


My problem is the following: I have at top level 3 lists and 3 strings:
lista, listb, listc and stra, strb, strc. I can with a single function
call change all 3 list values. How could I realize similar changes
of the 3 string values with a single function call?

Thanks in advance.

M. K. Shen


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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Dave Angel
On 08/10/2012 06:31 AM, Mok-Kong Shen wrote:
> Am 10.08.2012 12:07, schrieb Dave Angel:
> [snip]
>> At this point, in top-level code, the listb object has been modified,
>> and the strb one has not;  it still is bound to the old value.
>
> This means there is no way of modifying a string at the top level
> via a function, excepting through returning a new value and assigning
> that to the string name at the top level. Please again correct me, if
> I am wrong.
>
> M. K. Shen
>

You're close.  There are three ways I can think of. The "right" way is
to return a value, which the caller can use any way he wants, including
binding it to a global.

Second is to declare the name as global, rather than taking the object
as a formal parameter.  In this case, you're taking on the
responsibility for managing that particular global, by its correct name.
def yy():
global strb
strb += "whatever"

Third is to hold the string in some more complex structure which is
mutable.  (untested, may contain typos)
def  zz(mydict):
  mydict["key1"] += "text"

called as:
globaldict = {"key1": "initial ", "key2": "init"}




-- 

DaveA

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Roman Vashkevich
10.08.2012, в 14:12, Mok-Kong Shen написал(а):

> Am 10.08.2012 11:48, schrieb Roman Vashkevich:
>> [snip]
> >The function  It takes list by reference and creates a new local
> > str. When it's called with listb and strb arguments, listb is passed
> > by reference and mutated. A string "sss" is concatenated with an
> > empty local str. Nothing more happens. Since local str is not
> > returned by xx(), it can not be expected to be printed out in the
> > statement that follows. What is printed out in the print statement is
> > the mutated listb and the global strb.
> 
> Thanks for the explanation of the output obtained. But this means
> nonetheless that parameters of types lists and strings are dealt with
> in "inherently" (semantically) different ways by Python, right?
> 
> M. K. Shen
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

I am not sure I understand your question. Can you rephrase it or make it more 
explicit?

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Dave Angel
On 08/10/2012 06:37 AM, Chris Angelico wrote:
> On Fri, Aug 10, 2012 at 8:12 PM, Mok-Kong Shen
>  wrote:
>> Thanks for the explanation of the output obtained. But this means
>> nonetheless that parameters of types lists and strings are dealt with
>> in "inherently" (semantically) different ways by Python, right?
> It's nothing to do with parameters, but yes, lists are mutable and
> strings are immutable. A tuple will behave the same way a string does:
>
 a
> (1, 2, 3, 4)
 b=a
 a+=5,# note that "5," is a one-element tuple
 a
> (1, 2, 3, 4, 5)
 b
> (1, 2, 3, 4)
>
>
> By the way:
>
> On Fri, Aug 10, 2012 at 8:07 PM, Dave Angel  wrote:
>> But if you said  c=651 and d=651, you'd have two
>> objects, and the two names would be bound to different objects, with
>> different ids.
> To be more accurate, you *may* have two different objects. It's
> possible for things to be optimized (eg with small numbers, or with
> constants compiled at the same time).
>
> ChrisA

You're right, of course.  But I picked the value of 650+ deliberately,
as I believe CPython doesn't currently optimize ints over 256.



-- 

DaveA

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Dave Angel
On 08/10/2012 06:48 AM, Mok-Kong Shen wrote:
> Am 10.08.2012 12:40, schrieb Chris Angelico:
>
>> But it's probably worth thinking about exactly why you're wanting to
>> change that string, and what you're really looking to accomplish.
>> There may well be a better way.
>
> My problem is the following: I have at top level 3 lists and 3 strings:
> lista, listb, listc and stra, strb, strc. I can with a single function
> call change all 3 list values. How could I realize similar changes
> of the 3 string values with a single function call?
>
> Thanks in advance.
>
> M. K. Shen
>
>
Make sure your function returns the values, rather than just trying to
mutate them in place.

def aa(mystring1, mystring2, mystring3):
mystring1 += "something"
mystring2 += "otherthing"
mystring3 += "nobody"
return mystring1, mystring2, mystring3

str1, str2, str3 = aa(str1, str2, str3)



-- 

DaveA

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Roman Vashkevich
10.08.2012, в 14:12, Mok-Kong Shen написал(а):

> Am 10.08.2012 11:48, schrieb Roman Vashkevich:
>> [snip]
> >The function  It takes list by reference and creates a new local
> > str. When it's called with listb and strb arguments, listb is passed
> > by reference and mutated. A string "sss" is concatenated with an
> > empty local str. Nothing more happens. Since local str is not
> > returned by xx(), it can not be expected to be printed out in the
> > statement that follows. What is printed out in the print statement is
> > the mutated listb and the global strb.
> 
> Thanks for the explanation of the output obtained. But this means
> nonetheless that parameters of types lists and strings are dealt with
> in "inherently" (semantically) different ways by Python, right?
> 
> M. K. Shen
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

DaveA provided a very explicit explanation of how py handles list and string 
objects.
Parameters are handled "inherently" by functions...

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Chris Angelico
On Fri, Aug 10, 2012 at 8:56 PM, Dave Angel  wrote:
>> On Fri, Aug 10, 2012 at 8:07 PM, Dave Angel  wrote:
>>> But if you said  c=651 and d=651, you'd have two
>>> objects, and the two names would be bound to different objects, with
>>> different ids.
>> To be more accurate, you *may* have two different objects. It's
>> possible for things to be optimized (eg with small numbers, or with
>> constants compiled at the same time).
>
> You're right, of course.  But I picked the value of 650+ deliberately,
> as I believe CPython doesn't currently optimize ints over 256.

Yep. Also:

>>> a=651; b=651
>>> a is b
True
>>> a=651
>>> a is b
False

Same thing occurs (or at least, appears to) with constants in the same
module. Could potentially be a fairly hefty optimization, if you use
the same numbers all the time (bit flags, scale factors, modulo
divisors, etc, etc, etc).

Still doesn't alter your fundamental point of course.

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Mok-Kong Shen

Am 10.08.2012 12:56, schrieb Roman Vashkevich:


I am not sure I understand your question. Can you rephrase it or make it more 
explicit?


I have just detailed my problem and Dave Angel has shown how to solve
it properly.

M. K. Shen

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


Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Hans Mulder
On 10/08/12 11:25:36, Giacomo Alzetta wrote:
> Il giorno venerdì 10 agosto 2012 11:22:13 UTC+2, Hans Mulder ha scritto:
[...]
> Yes, you're right. I didn't thought the combined operator would do a Py_DECREF
> if the iadd operation was implemented, but it obviosuly makes sense.

The += operator cannot know if the iadd returns self or a newly created
object.  Mutable types usually do the former; non-mutable types must do
the latter.

Come to think of it: why are your polynomials mutable?

As a mathematician, I would think of polynomials as elements of
some kind of ring, and I'd expect them to be non-mutable.

-- HansM

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


Re: save dictionary to a file without brackets.

2012-08-10 Thread Roy Smith
In article ,
 Mark Lawrence  wrote:

> On 10/08/2012 09:54, Steven D'Aprano wrote:
> > On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote:
> >
> >> On 08/09/12 18:33, Mark Lawrence wrote:
> >>> On 10/08/2012 00:24, Roy Smith wrote:
> > ... you mean, Python lets you make a hash of it?
> 
>  Only if you order it with spam, spam, spam, spam, spam, spam, and
>  spam.
> >>>
> >>> Now now gentlemen we're getting slightly off topic here and wouldn't
> >>> want to upset the people who insist on staying on topic.  Or would we?
> >>> :)
> >>
> >> We apologise for the off-topicness in the thread.  Those responsible
> >> have been sacked...
> >
> >
> > Sacked? They were beaten to death with a large halibut!
> >
> >
> 
> Well whatever you do *DON'T* mention Cython. I mentioned it just now but 
> I think I've got away with it.

What if I spell it Kython?
-- 
http://mail.python.org/mailman/listinfo/python-list


Threads and sockets

2012-08-10 Thread loial
I am writing an application to send data to a printer port(9100) and then 
recieve PJL responses back on that port. Because of the way PJL works I have to 
do both in the same process(script).

At the moment I do not start to read responses until the data has been sent to 
the printer. However it seems I am missing some responses from the printer 
whilst sending the data, so I need to be able to do the 2 things at the same 
time.

Can I open a port once and then use 2 different threads, one to write to the 
post and one to read the responses)?
 

 

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


Re: [GENERAL] Postgres and Upstart

2012-08-10 Thread Chris Angelico
On Fri, Aug 10, 2012 at 11:56 PM, Albe Laurenz  wrote:
> Chris Angelico wrote:
>> I'm looking for a reliable way to be sure that Postgres has finished
>> its initialization and is ready to rumble.
>
> The normal way to test this is a connection attempt.
> You could also look into the server logs for the
> appropriate message, but that seems more fragile and difficult.

Yeah, I can poll it, and that's what I do in a couple of places; but
somewhere in the code, it probably "knows" that it's ready. I can keep
doing what I'm doing, but was hoping for an event-driven approach.

Thanks!

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


dictionary into desired variable....

2012-08-10 Thread Tamer Higazi
Hi!
suppose you have a dictionary that looks like this:

x = [1,3,6,1,1] which should represent a certain other variable.

in reality it would represent:

y[1][3][6][1][1]

Now, how do I write a python routine, that points in this dictionary,
where I should receive or set other values.



Tamer

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


Re: dictionary into desired variable....

2012-08-10 Thread Chris Angelico
On Sat, Aug 11, 2012 at 12:02 AM, Tamer Higazi  wrote:
> Hi!
> suppose you have a dictionary that looks like this:
>
> x = [1,3,6,1,1] which should represent a certain other variable.
>
> in reality it would represent:
>
> y[1][3][6][1][1]
>
> Now, how do I write a python routine, that points in this dictionary,
> where I should receive or set other values.

For a start, that looks like a list, not a dictionary. A dict in
Python is a mapping, eg a hashtable - an unordered pairing of keys and
values. But this might do what you want:

value = y
for idx in x:
   value = value[idx]

At the end of that, 'value' will be the same as 'y[1][3][6][1][1]'.

If that's not what you mean, you may want to clarify your question some.

Hope that helps!

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


Re: dictionary into desired variable....

2012-08-10 Thread Zero Piraeus
:

> suppose you have a dictionary that looks like this:
>
> x = [1,3,6,1,1] which should represent a certain other variable.

That's a list, not a dict.

> in reality it would represent:
>
> y[1][3][6][1][1]
>
> Now, how do I write a python routine, that points in this dictionary,
> where I should receive or set other values.

>>> x = [1, 3, 6, 1, 1]
>>> y = [0, [0, 1, 2, [0, 1, 2, 3, 4, 5, [0, [0, 'bingo!']
>>> def drill(tree, path):
... target = tree
... for step in path:
... target = target[step]
... return target
...
>>> drill(y, x)
'bingo!'
>>>

 -[]z.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: save dictionary to a file without brackets.

2012-08-10 Thread Mark Lawrence

On 10/08/2012 13:29, Roy Smith wrote:

In article ,
  Mark Lawrence  wrote:


On 10/08/2012 09:54, Steven D'Aprano wrote:

On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote:


On 08/09/12 18:33, Mark Lawrence wrote:

On 10/08/2012 00:24, Roy Smith wrote:

... you mean, Python lets you make a hash of it?


Only if you order it with spam, spam, spam, spam, spam, spam, and
spam.


Now now gentlemen we're getting slightly off topic here and wouldn't
want to upset the people who insist on staying on topic.  Or would we?
:)


We apologise for the off-topicness in the thread.  Those responsible
have been sacked...



Sacked? They were beaten to death with a large halibut!




Well whatever you do *DON'T* mention Cython. I mentioned it just now but
I think I've got away with it.


What if I spell it Kython?



What a silly bunt!!!

--
Cheers.

Mark Lawrence.

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


Re: dictionary into desired variable....

2012-08-10 Thread Dave Angel
On 08/10/2012 10:02 AM, Tamer Higazi wrote:
> Hi!
> suppose you have a dictionary that looks like this:
>
> x = [1,3,6,1,1] which should represent a certain other variable.
>
> in reality it would represent:
>
> y[1][3][6][1][1]
>
> Now, how do I write a python routine, that points in this dictionary,
> where I should receive or set other values.
>

Others have pointed out how you could "receive" a value from that. 
Doing a setter would be tricker.

But I'd want to start with the question of just what you're really
looking for.  Is this an assignment, so it doesn't have to actually make
sense?  If so, could we please have the actual wording.   x is not a
dictionary, and Python doesn't have routines nor pointers.  Perhaps it's
a generic programming class, and the student gets to choose the language.

If it's indeed intended to model some kind of useful data, could we know
a bit more about the constraints?  is y supposed to be a nested list, or
a nested dictioary, or something else? How is this nested list/dict
first created?  Do you need to have other parts of the code access the
raw, nested Something.  Are there always going to be 5 subscripts, and
are each constrained to be in a fixed range?  If it's a nested
dictionary, are the keys always integers?

Since a python function or method can't return a pointer, presumably you
mean for a function or method to fetch or store a value.

Sounds like what you want is a class, where the __init__ method takes a
nested something, y and saves it as an attribute _y.  And there are at
least two more methods in that class, fetch() that takes a list of ints,
and returns a value.  And store() that takes a list of ints and a value,
and mutates the _y, returning None.  The store() method is a good bit
trickier to write, depending on the assumptions above.



-- 

DaveA

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


Re: [newbie] A question about lists and strings

2012-08-10 Thread Rotwang

On 10/08/2012 10:59, Peter Otten wrote:

[...]

If you have understood the above here's a little brain teaser:


a = ([1,2,3],)
a[0] += [4, 5]

Traceback (most recent call last):
   File "", line 1, in 
TypeError: 'tuple' object does not support item assignment


a[0]


What are the contents of a[0] now?


Ha, nice.


--
I have made a thing that superficially resembles music:

http://soundcloud.com/eroneity/we-berated-our-own-crapiness
--
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary into desired variable....

2012-08-10 Thread Tamer Higazi
Sorry,
I ment of course list

what I exaclty ment is

that if I assign

value = Number

that I automaticly assign y[1][3][6][1][1] a new number.

more detailled explained:

let us say a would be x = [2,5,4]

y = a[3]

if I change y to []

I want the result to be x = [2,5,[]] and that's automaticly
independently how deep i dig.



Sorry for the inconvenience.


Tamer



Am 10.08.2012 16:31, schrieb Chris Angelico:
> On Sat, Aug 11, 2012 at 12:02 AM, Tamer Higazi  wrote:
>> Hi!
>> suppose you have a dictionary that looks like this:
>>
>> x = [1,3,6,1,1] which should represent a certain other variable.
>>
>> in reality it would represent:
>>
>> y[1][3][6][1][1]
>>
>> Now, how do I write a python routine, that points in this dictionary,
>> where I should receive or set other values.
> 
> For a start, that looks like a list, not a dictionary. A dict in
> Python is a mapping, eg a hashtable - an unordered pairing of keys and
> values. But this might do what you want:
> 
> value = y
> for idx in x:
>value = value[idx]
> 
> At the end of that, 'value' will be the same as 'y[1][3][6][1][1]'.
> 
> If that's not what you mean, you may want to clarify your question some.
> 
> Hope that helps!
> 
> Chris Angelico

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


Re: Threads and sockets

2012-08-10 Thread Dieter Maurer
loial  writes:

> I am writing an application to send data to a printer port(9100) and then 
> recieve PJL responses back on that port. Because of the way PJL works I have 
> to do both in the same process(script).
>
> At the moment I do not start to read responses until the data has been sent 
> to the printer. However it seems I am missing some responses from the printer 
> whilst sending the data, so I need to be able to do the 2 things at the same 
> time.
>
> Can I open a port once and then use 2 different threads, one to write to the 
> post and one to read the responses)?

That should be possible. Alternatively, you could use "asyncore" -- a
mini framework to facilitate asynchronous communication.

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


Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Giacomo Alzetta
Il giorno venerdì 10 agosto 2012 14:21:50 UTC+2, Hans Mulder ha scritto:
> On 10/08/12 11:25:36, Giacomo Alzetta wrote:
> 
> > Il giorno venerdì 10 agosto 2012 11:22:13 UTC+2, Hans Mulder ha scritto:
> 
> [...]
> 
> > Yes, you're right. I didn't thought the combined operator would do a 
> > Py_DECREF
> 
> > if the iadd operation was implemented, but it obviosuly makes sense.
> 
> 
> 
> The += operator cannot know if the iadd returns self or a newly created
> 
> object.  Mutable types usually do the former; non-mutable types must do
> 
> the latter.
> 
> 
> 
> Come to think of it: why are your polynomials mutable?
> 
> 
> 
> As a mathematician, I would think of polynomials as elements of
> 
> some kind of ring, and I'd expect them to be non-mutable.
> 
> 
> 
> -- HansM

Usually non-mutable types simply do not implement the iadd operation, and the 
interpreter tries the simple add after(see intobject.c, longobject.c etc.).

I've decided to make my polynomials mutable for efficiency.
I want to implement the AKS primality tests, and if I want to use it with big 
numbers the number of coefficients of a polynomial can easily go up to 
1k-10k-100k and using non-mutable polynomials would mean to allocate and free 
that much memory for almost every operation.
Like this I have to allocate/free less frequently.

[even though I must admit that this is a premature optimization :s, since I've 
not profile anything, but untill I do not implement them I wont be able to see 
how much time I gain.]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary into desired variable....

2012-08-10 Thread woooee
On Friday, August 10, 2012 8:31:48 AM UTC-7, Tamer Higazi wrote:
> let us say a would be x = [2,5,4]
> 
> y = a[3]
> 
> if I change y to []
 
> 
> I want the result to be x = [2,5,[]] and that's automaticly

There is no such thing as a[3] if a=[2,4,5].  And this is a list not a 
dictionary, so I would suggest a tutorial from the Python wiki page.

You have to use a mutable container.  Integers are not mutable.  Lists, for 
example are.

y=[4]
x = [2,5,y]
print x
y[0]=10
print x
-- 
http://mail.python.org/mailman/listinfo/python-list


lpod-python

2012-08-10 Thread Francesco
I'm trying to use the lpod-python module to programmatically read data from Open Document files. My problem is: i can't download the 
module from its authors' site, http://download.lpod-project.org/lpod-python/lpod-python-0.9.3.tar.gz. It seems the download site is 
unavailable, while the main site is working.

I also tried to install the module with pip (I read on the site that it's now 
available), but again, no luck.
Do somebody know what's happening to download.lpod-project.org ? It doesn't 
even ping...

Please let me know, thank you very much.
Francesco
--
http://mail.python.org/mailman/listinfo/python-list


Re: save dictionary to a file without brackets.

2012-08-10 Thread 88888 Dihedral
Dave Angel於 2012年8月10日星期五UTC+8上午5時47分45秒寫道:
> On 08/09/2012 05:34 PM, Roman Vashkevich wrote:
> 
> > Actually, they are different.
> 
> > Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred 
> > thousand entries, and you will feel the difference.
> 
> > Dict uses hashing to get a value from the dict and this is why it's O(1).
> 
> 
> 
> Sure, that's why
> 
> 
> 
> for key in dict:
> 
>   print key[0], key[1], dict[key]
> 
> 
> 
> is probably slower than
> 
> 
> 
> for (edge1, edge2), cost in d.iteritems(): # or .items()
> 
>   print edge1, edge2, cost
> 
> 
> 
> 
> 
> So, the latter is both faster and easier to read.  Why are you arguing 
> against it?
> 
> 
> 
> Also, please stop top-posting.  It's impolite here, and makes it much harder 
> to figure out who is saying what, in what order.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> 
> 
> DaveA

OK, lets estimate the hash colision rate first.

For those items hashed to the same key, I'll store a sorted list with a
known lenth m to be accessed in O(LOG(M)). 

Of couse another hash can be attatched.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to execute the script

2012-08-10 Thread Dave Angel
On 08/10/2012 01:14 PM, Smaran Harihar wrote:
> Hi,
>
> I have set executable permissions for my py script (cgi-script) but for
> some reason rather than executing it, the browser simply downloads the py
> script.
>
> Here is the 
> link.
> Before it was working on another server. I migrated it to this new domain
> and it is having this issue. Where am I going wrong?
>
>
Lots of possibilities, though I can't think of any relating to Python.  
So I didn't try to read your source file.

Is the location of this script acceptable to your web host?  Some hosts
deliberately restrict scripts to be in certain places (like /cgi-bin) in
order to thwart a certain type of cracker.

Next question, is the python installation actually at the place where
your shebang points?




-- 

DaveA

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


Re: trying to create simple py script

2012-08-10 Thread Dan Stromberg
CGI's old stuff.  Sure it's easy to find doc about it - it's been around
longer.

I'd recommend either CherryPy or Bottle - because these are the two (that I
know of) that support Python 3 today.

Here's a nice comparison of Python REST frameworks:

http://www.youtube.com/watch?v=AYjPIMe0BhA

I'm using CherryPy on Python 2.7 with the ruby-on-rails-like "Routes"
dispatcher.

Bottle does sound pretty nice.

On Thu, Aug 9, 2012 at 9:52 PM, Smaran Harihar wrote:

> Hi Guys,
>
> I am trying to create a simple cgi-script to receive a Ajax
> call, manipulate the string received and send it back as JSON.
> Most of the people I have spoken to, seemed to be against using the cgi
> script, but most of the documentation and tutorials seem to point to cgi
> for AJAX calls. They said, it makes more sense to use django or bottle
> which are python web framework.
>
> So I am confused and wanted some guidance as to which should I chose?
> Should I go with cgi or django/bottle?
>
> --
> Thanks & Regards
> Smaran Harihar
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threads and sockets

2012-08-10 Thread Dan Stromberg
A select() loop should work.

On Fri, Aug 10, 2012 at 1:01 PM, loial  wrote:

> I am writing an application to send data to a printer port(9100) and then
> recieve PJL responses back on that port. Because of the way PJL works I
> have to do both in the same process(script).
>
> At the moment I do not start to read responses until the data has been
> sent to the printer. However it seems I am missing some responses from the
> printer whilst sending the data, so I need to be able to do the 2 things at
> the same time.
>
> Can I open a port once and then use 2 different threads, one to write to
> the post and one to read the responses)?
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Stefan Behnel
Giacomo Alzetta, 10.08.2012 10:20:
> I'm trying to implement a c-extension which defines a new class(ModPolynomial 
> on the python side, ModPoly on the C-side).
> At the moment I'm writing the in-place addition, but I get a *really* strange 
> behaviour.

You should take a look at Cython. It makes these things way easier and
safer than with manually written C code. It will save you a lot of code,
debugging and general hassle.

Stefan


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


Re: trying to create simple py script

2012-08-10 Thread Smaran Harihar
Sorry forgot to update. I did change the port to 8000 and now server is
running but I am getting a 404 page.

http://128.196.142.94:8000/bottle/hello.py

I have the server up right now you can see.

Thanks,
Smaran

On Fri, Aug 10, 2012 at 11:35 AM, Smaran Harihar
wrote:

> Hi Lutz,
>
> Sorry forgot to update. I did change the port to 8000 and now server is
> running but I am getting a 404 page.
>
> http://128.196.142.94:8000/bottle/hello.py
>
> I have the server up right now you can see.
>
> Thanks,
> Smaran
>
>
> On Fri, Aug 10, 2012 at 11:28 AM, Lutz Horn  wrote:
>
>> Hi,
>>
>> Am 10.08.2012 um 19:10 schrieb Smaran Harihar:
>> > python hello.py but I got this traceback error.
>>
>> Use a different port in this line:
>>
>> > run(host='localhost', port=8080)
>>
>> For example 8090 or 8081 or …
>>
>> Lutz
>
>
>
>
> --
> Thanks & Regards
> Smaran Harihar
>
>


-- 
Thanks & Regards
Smaran Harihar
-- 
http://mail.python.org/mailman/listinfo/python-list


Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)"

2012-08-10 Thread Chuck
Hi all, I cannot figure why I keep getting this error.  It is my understanding 
that all methods need a self argument when designing a class.  Here is my code:

import random

class ElementsQuiz:

elements = {'H' : 'Hydrogen',
'He' : 'Helium',
'Li' : 'Lithium',
'Be' : 'Beryllium',
'B' : 'Boron',
'C' : 'Carbon',
'N' : 'Nitrogen',
'O' : 'Oxygen',
'F' : 'Fluorine',
'Ne' : 'Neon',
'Na' : 'Sodium',
'Mg' : 'Magnesium',
'Al' : 'Aluminium',
'Si' : 'Silicon',
'P' : 'Phosphorus',
'S' : 'Sulfur',
'Cl' : 'Chlorine',
'Ar' : 'Argon',
'K' : 'Potassium',
'Ca' : 'Calcium',
'Sc' : 'Scandium',
'Ti' : 'Titanium',
'V' : 'Vanadium',
'Cr' : 'Chromium',
'Mn' : 'Manganese',
'Fe' : 'Iron',
'Co' : 'Cobalt',
'Ni' : 'Nickel',
'Cu' : 'Copper',
'Zn' : 'Zinc',
'Ga' : 'Gallium',
'Ge' : 'Germanium',
'As' : 'Arsenic',
'Se' : 'Selenium',
'Br' : 'Bromine',
'Kr' : 'Krypton',
'Rb' : 'Rubidium',
'Sr' : 'Strontium',
'Y' : 'Yttrium',
'Zr' : 'Zirconium',
'Nb' : 'Niobium',
'Mo' : 'Molybdenum',
'Tc' : 'Technetium',
'Ru' : 'Ruthenium',
'Rh' : 'Rhodium',
'Pd' : 'Palladium',
'Ag' : 'Silver',
'Cd' : 'Cadmium',
'In' : 'Indium',
'Sn' : 'Tin',
'Sb' : 'Antimony',
'Te' : 'Tellurium',
'I' : 'Iodine',
'Xe' : 'Xenon',
'Cs' : 'Caesium',
'Ba' : 'Barium',
'La' : 'Lanthanum',
'Ce' : 'Cerium',
'Pr' : 'Praseodymium',
'Nd' : 'Neodymium',
'Pm' : 'Promethium',
'Sm' : 'Samarium',
'Eu' : 'Europium',
'Gd' : 'Gadolinium',
'Tb' : 'Terbium',
'Dy' : 'Dysprosium',
'Ho' : 'Holmium',
'Er' : 'Erbium',
'Tm' : 'Thulium',
'Yb' : 'Ytterbium',
'Lu' : 'Lutetium',
'Hf' : 'Hafnium',
'Ta' : 'Tantalum',
'W' : 'Tungsten',
'Re' : 'Rhenium',
'Os' : 'Osmium',
'Ir' : 'Iridium',
'Pt' : 'Platinum',
'Au' : 'Gold',
'Hg' : 'Mercury',
'Tl' : 'Thallium',
'Pb' : 'Lead',
'Bi' : 'Bismuth',
'Po' : 'Polonium',
'At' : 'Astatine',
'Rn' : 'Radon',
'Fr' : 'Francium',
'Ra' : 'Radium',
'Ac' : 'Actinium',
'Th' : 'Thorium',
'Pa' : 'Protactinium',
'U' : 'Uranium',
'Np' : 'Neptunium',
'Pu' : 'Plutonium',
'Am' : 'Americium',
'Cm' : 'Curium',
'Bk' : 'Berkelium',
'Cf' : 'Californium',
'Es' : 'Einsteinium',
'Fm' : 'Fermium',
'Md' : 'Mendelevium',
'No' : 'Nobelium',
'Lr' : 'Lawrencium',
'Rf' : 'Rutherfordium',
'Db' : 'Dubnium',
'Sg' : 'Seaborgium',
'Bh' : 'Bohrium',
'Hs' : 'Hassium',
'Mt' : 'Meitnerium',
'Ds' : 'Darmstadtium',
'Rg' : 'Roentgenium',
'Cn' : 'Copernicium',
'Uut' : 'Ununtrium',
'Fl' : 'Flerovium',
'Uup' : 'Ununpentium',
'Lv' : 'Livermorium',
'Uus' : 'Ununseptium',
'Uuo' : 'Ununoctium'
}
   
def __init__(self):
self.quiz()

def quiz(self):
self.reply = ('Moron', 'Dummy', 'Idiot', 'Embecile', 'Half-wit')
self.numCorrect = 0
self.question = random.choice(self.elements.keys())
print self.question
self.ans = raw_input('Answer: ')

if self.ans == self.elements(self.question):
self.numCorrect += 1
else:
self.insult = random.choice(self.reply)
print 'Incorrect %s' % self.insult



if __name__ == '__main__':

quiz()



Thanks for any help!  
-- 
http://mail.python.org/mai

Re: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)"

2012-08-10 Thread Pedro Kroger

On Aug 10, 2012, at 3:52 PM, Chuck  wrote:

>if __name__ == '__main__':
> 
>quiz()
> 
> 

You need to instantiate your class:

foo = ElementsQuiz()
foo.quiz()


Pedro
-
http://pedrokroger.net
http://musicforgeeksandnerds.com

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


Re: Unable to execute the script

2012-08-10 Thread Tim Chase
On 08/10/12 13:38, Dave Angel wrote:
> On 08/10/2012 01:14 PM, Smaran Harihar wrote:
>> Hi,
>>
>> I have set executable permissions for my py script (cgi-script) but for
>> some reason rather than executing it, the browser simply downloads the py
>> script.
>>
>> Here is the 
>> link.
>> Before it was working on another server. I migrated it to this new domain
>> and it is having this issue. Where am I going wrong?
>>
>>
> Lots of possibilities, though I can't think of any relating to Python.  
> So I didn't try to read your source file.
> 
> Is the location of this script acceptable to your web host?  Some hosts
> deliberately restrict scripts to be in certain places (like /cgi-bin) in
> order to thwart a certain type of cracker.
> 
> Next question, is the python installation actually at the place where
> your shebang points?

And, if the file is on a *nix-like machine (Linux, BSD, Mac,
Solaris, etc), have the executable bits been set?

-tkc



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


Re: Unable to execute the script

2012-08-10 Thread Smaran Harihar
The file is on Ubuntu Server 12.04 and not sure how to set the executable
bits?

If you mean chmod +x 

then yes it has been set.

On Fri, Aug 10, 2012 at 12:10 PM, Tim Chase
wrote:

> On 08/10/12 13:38, Dave Angel wrote:
> > On 08/10/2012 01:14 PM, Smaran Harihar wrote:
> >> Hi,
> >>
> >> I have set executable permissions for my py script (cgi-script) but for
> >> some reason rather than executing it, the browser simply downloads the
> py
> >> script.
> >>
> >> Here is the link<
> http://128.196.142.94/geo/iplantgeo_cgi.py?get=env&from=latlon&lat=42,45,54&lon=-123,-65,-100
> >.
> >> Before it was working on another server. I migrated it to this new
> domain
> >> and it is having this issue. Where am I going wrong?
> >>
> >>
> > Lots of possibilities, though I can't think of any relating to Python.
> > So I didn't try to read your source file.
> >
> > Is the location of this script acceptable to your web host?  Some hosts
> > deliberately restrict scripts to be in certain places (like /cgi-bin) in
> > order to thwart a certain type of cracker.
> >
> > Next question, is the python installation actually at the place where
> > your shebang points?
>
> And, if the file is on a *nix-like machine (Linux, BSD, Mac,
> Solaris, etc), have the executable bits been set?
>
> -tkc
>
>
>
>


-- 
Thanks & Regards
Smaran Harihar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to execute the script

2012-08-10 Thread Tim Chase
On 08/10/12 14:14, Smaran Harihar wrote:
> If you mean chmod +x 
> 
> then yes it has been set.

I'm not sure how Ubuntu defaults if you don't specify *who* should
receive those +x permissions.  I'd make sure they've been set for
everybody:

  $ chmod ugo+x myfile.py

You can check this by doing an "ls -lsF myfile.py" and you should
see 3 "x"s in the permission column, something like


 123 rwxr-xr-x 1 smaran smaran 31415 Apr 27 2012 myfile.py
   ^  ^  ^

If those are set properly, then Dave's suggestions are the next to try.

-tkc



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


Re: Unable to execute the script

2012-08-10 Thread Dan Stromberg
This sounds like a ScriptAlias thing:
http://httpd.apache.org/docs/2.2/howto/cgi.html

On Fri, Aug 10, 2012 at 5:14 PM, Smaran Harihar wrote:

> Hi,
>
> I have set executable permissions for my py script (cgi-script) but for
> some reason rather than executing it, the browser simply downloads the py
> script.
>
> Here is the 
> link.
> Before it was working on another server. I migrated it to this new domain
> and it is having this issue. Where am I going wrong?
>
> --
> Thanks & Regards
> Smaran Harihar
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)"

2012-08-10 Thread Chuck
On Friday, August 10, 2012 2:05:36 PM UTC-5, Pedro Kroger wrote:
> On Aug 10, 2012, at 3:52 PM, Chuck  wrote:
> 
> 
> 
> >if __name__ == '__main__':
> 
> > 
> 
> >quiz()
> 
> > 
> 
> > 
> 
> 
> 
> You need to instantiate your class:
> 
> 
> 
> foo = ElementsQuiz()
> 
> foo.quiz()
> 
> 
> 
> 
> 
> Pedro
> 
> -
> 
> http://pedrokroger.net
> 
> http://musicforgeeksandnerds.com

That doesn't work either for some reason.  I keep getting "NameError: name 
'ElementsQuiz' is not defined"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)"

2012-08-10 Thread Dave Angel
On 08/10/2012 02:52 PM, Chuck wrote:
> Hi all, I cannot figure why I keep getting this error.  It is my 
> understanding that all methods need a self argument when designing a class.  
> Here is my code:
It'd be much more useful if you'd actually quote the entire error.
> import random
>
> class ElementsQuiz:
>
> elements = {'H' : 'Hydrogen',
> 'He' : 'Helium',
> 'Li' : 'Lithium',
> 'Be' : 'Beryllium',
> 'B' : 'Boron',
> 'C' : 'Carbon',
> 'N' : 'Nitrogen',
> 'O' : 'Oxygen',
> 'F' : 'Fluorine',
> 'Ne' : 'Neon',
> 'Na' : 'Sodium',
> 'Mg' : 'Magnesium',
> 'Al' : 'Aluminium',
> 'Si' : 'Silicon',
> 'P' : 'Phosphorus',
> 'S' : 'Sulfur',
> 'Cl' : 'Chlorine',
> 'Ar' : 'Argon',
> 'K' : 'Potassium',
> 'Ca' : 'Calcium',
> 'Sc' : 'Scandium',
> 'Ti' : 'Titanium',
> 'V' : 'Vanadium',
> 'Cr' : 'Chromium',
> 'Mn' : 'Manganese',
> 'Fe' : 'Iron',
> 'Co' : 'Cobalt',
> 'Ni' : 'Nickel',
> 'Cu' : 'Copper',
> 'Zn' : 'Zinc',
> 'Ga' : 'Gallium',
> 'Ge' : 'Germanium',
> 'As' : 'Arsenic',
> 'Se' : 'Selenium',
> 'Br' : 'Bromine',
> 'Kr' : 'Krypton',
> 'Rb' : 'Rubidium',
> 'Sr' : 'Strontium',
> 'Y' : 'Yttrium',
> 'Zr' : 'Zirconium',
> 'Nb' : 'Niobium',
> 'Mo' : 'Molybdenum',
> 'Tc' : 'Technetium',
> 'Ru' : 'Ruthenium',
> 'Rh' : 'Rhodium',
> 'Pd' : 'Palladium',
> 'Ag' : 'Silver',
> 'Cd' : 'Cadmium',
> 'In' : 'Indium',
> 'Sn' : 'Tin',
> 'Sb' : 'Antimony',
> 'Te' : 'Tellurium',
> 'I' : 'Iodine',
> 'Xe' : 'Xenon',
> 'Cs' : 'Caesium',
> 'Ba' : 'Barium',
> 'La' : 'Lanthanum',
> 'Ce' : 'Cerium',
> 'Pr' : 'Praseodymium',
> 'Nd' : 'Neodymium',
> 'Pm' : 'Promethium',
> 'Sm' : 'Samarium',
> 'Eu' : 'Europium',
> 'Gd' : 'Gadolinium',
> 'Tb' : 'Terbium',
> 'Dy' : 'Dysprosium',
> 'Ho' : 'Holmium',
> 'Er' : 'Erbium',
> 'Tm' : 'Thulium',
> 'Yb' : 'Ytterbium',
> 'Lu' : 'Lutetium',
> 'Hf' : 'Hafnium',
> 'Ta' : 'Tantalum',
> 'W' : 'Tungsten',
> 'Re' : 'Rhenium',
> 'Os' : 'Osmium',
> 'Ir' : 'Iridium',
> 'Pt' : 'Platinum',
> 'Au' : 'Gold',
> 'Hg' : 'Mercury',
> 'Tl' : 'Thallium',
> 'Pb' : 'Lead',
> 'Bi' : 'Bismuth',
> 'Po' : 'Polonium',
> 'At' : 'Astatine',
> 'Rn' : 'Radon',
> 'Fr' : 'Francium',
> 'Ra' : 'Radium',
> 'Ac' : 'Actinium',
> 'Th' : 'Thorium',
> 'Pa' : 'Protactinium',
> 'U' : 'Uranium',
> 'Np' : 'Neptunium',
> 'Pu' : 'Plutonium',
> 'Am' : 'Americium',
> 'Cm' : 'Curium',
> 'Bk' : 'Berkelium',
> 'Cf' : 'Californium',
> 'Es' : 'Einsteinium',
> 'Fm' : 'Fermium',
> 'Md' : 'Mendelevium',
> 'No' : 'Nobelium',
> 'Lr' : 'Lawrencium',
> 'Rf' : 'Rutherfordium',
> 'Db' : 'Dubnium',
> 'Sg' : 'Seaborgium',
> 'Bh' : 'Bohrium',
> 'Hs' : 'Hassium',
> 'Mt' : 'Meitnerium',
> 'Ds' : 'Darmstadtium',
> 'Rg' : 'Roentgenium',
> 'Cn' : 'Copernicium',
> 'Uut' : 'Ununtrium',
> 'Fl' : 'Flerovium',
> 'Uup' : 'Ununpentium',
> 'Lv' : 'Livermorium',
> 'Uus' : 'Ununseptium',
> 'Uuo' : 'Ununoctium'
> }
>
> def __init__(self):
> self.quiz()
Why would you do all the work from a call inside the initializer? 
What's the point of having instance attributes if you're not going to
use it a second time?
> def quiz(self):
> self.reply = ('Moron', 'Dummy', 'Idiot', 'Embecile', 'Half-wit')
>

Re: Unable to execute the script

2012-08-10 Thread Smaran Harihar
Hi Tim,

this is the output for the ls -lsF filename

8 -rwxr-xr-x 1 root root 5227 Jul 30 13:54 iplantgeo_cgi.py*

On Fri, Aug 10, 2012 at 12:20 PM, Tim Chase
wrote:

> On 08/10/12 14:14, Smaran Harihar wrote:
> > If you mean chmod +x 
> >
> > then yes it has been set.
>
> I'm not sure how Ubuntu defaults if you don't specify *who* should
> receive those +x permissions.  I'd make sure they've been set for
> everybody:
>
>   $ chmod ugo+x myfile.py
>
> You can check this by doing an "ls -lsF myfile.py" and you should
> see 3 "x"s in the permission column, something like
>
>
>  123 rwxr-xr-x 1 smaran smaran 31415 Apr 27 2012 myfile.py
>^  ^  ^
>
> If those are set properly, then Dave's suggestions are the next to try.
>
> -tkc
>
>
>
>


-- 
Thanks & Regards
Smaran Harihar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unable to execute the script

2012-08-10 Thread Dave Angel
You posted privately to me, so I'm sending it back to the list.  Don't
forget to do reply-all, or equivalent.

On 08/10/2012 02:44 PM, Smaran Harihar wrote:
> Is the location of this script acceptable to your web host?
> 
> How can I check that?

By asking your web host tech support, or reading their help faq's.
> 
> Next question, is the python installation actually at the place where
> your shebang points?
> 
> Not sure what 'shebang' is!! I m a newbie so bit more explanation will be
> helpful.

if the first line of the script starts with a #!  (pronounced she-bang)
then the shell uses the rest of the line to launch the interpreter for
the script. If it doesn't, then Linux won't have a clue what you want
with this file.

You also have been doing top-post in your replies, which is not the way
this forum works.  Put your remarks AFTER the part you're quoting, and
remove the stuff your reader doesn't need.  In the above section you've
successfully confused most readers as to which parts I said and which
parts you said.  If you had simply put your remarks in the right place
(with an  before and after), all the quote bars would
automatically be right.

> 
> Thanks,
> Smaran
> 
> 


-- 

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


Re: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)"

2012-08-10 Thread Terry Reedy

On 8/10/2012 2:52 PM, Chuck wrote:

Hi all, I cannot figure why I keep getting this error.


To supplement Dave's answer (post entire traceback, dedent last two 
lines), here are the essentials of your code that show the problem.


>>> class C:
def f(self): pass
f()

Traceback (most recent call last):
  File "", line 1, in 
class C:
  File "", line 3, in C
f()
TypeError: f() missing 1 required positional argument: 'self'

You problem is that you are calling the function during the execution of 
the class statement, *before* the class is created.

Rather unusual ;-).

--
Terry Jan Reedy

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


Re: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)"

2012-08-10 Thread Chuck
Thanks for the help guys!  I finally got it working.  Shouldn't I technically 
call quiz() through the constructor, though?  Otherwise, the constructor is 
pointless.  I just put in pass for now.  (Also, I always thought that if 
__name__ == '__main__': went IN the class.  Why wouldn't it be apart of the 
class?  )

Thanks again!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)"

2012-08-10 Thread Dave Angel
On 08/10/2012 04:28 PM, Chuck wrote:
> Thanks for the help guys!  I finally got it working.  Shouldn't I technically 
> call quiz() through the constructor, though?  Otherwise, the constructor is 
> pointless.

> 
> Thanks again!
> 

What language did you use before trying Python?  Was it java, by any
chance, where everything has to be in a class?  If you're going to do
everything from the "constructor", then why on earth would you make it a
class?

(Incidentally, __init__() is the initializer, not the constructor, which
is called __new__() )

If you want to make a proper class out of it, you'd move the
initalization code into the __init__(), call, the stuff that only needs
to be called once per instance.  On the other hand, you have a class
attribute 'elements, which gets initialized outside of any mmthod.  And
everything else is just locals.

>  I just put in pass for now.  (Also, I always thought that
> if __name__ == '__main__': went IN the class.  Why wouldn't
> it be apart of the class?  )

Seems like you're arguing both sides.  Anyway, the if __name__ stuff
does not belong inside any class.  This is Python.

-- 

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


Re: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)"

2012-08-10 Thread Chuck
Yeah, I am mostly a Java guy.  Just starting with Python.  :)
-- 
http://mail.python.org/mailman/listinfo/python-list


[Newbie] How to wait for asyncronous input

2012-08-10 Thread pozz
I'm new to Python and I'm trying to code something to learn the language 
details.  I'm in trouble with asyncronous events, like asyncronous 
inputs (from serial port, from socket and so on).


Let's consider a simple monitor of the traffic on a serial port.  I'm 
using pyserial and I looked at the miniterm example:

http://pyserial.svn.sourceforge.net/viewvc/*checkout*/pyserial/trunk/pyserial/serial/tools/miniterm.py

The strategy is to create a thread that continuously call read() method 
while a couple of flags (alive and _reader_alive) are set:


def reader(self):
try:
while self.alive and self._reader_alive:
data = character(self.serial.read(1))

Is it an optimized strategy to wait for asyncronous input from serial 
port?  I think in this way we have a thread that is always running and 
that always asks for new bytes from serial port.


In C I should have used the select() on the serial port file descriptor. 
 I think the select() put the thread in a sleep state and wake it up 
when some bytes are received on the file descriptor specified.


It seems the "low-level" approach of select() is more optimized then the 
"high-level" approach of miniterm.

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


Re: Threads and sockets

2012-08-10 Thread Grant Edwards
On 2012-08-10, loial  wrote:

> At the moment I do not start to read responses until the data has
> been sent to the printer. However it seems I am missing some
> responses from the printer whilst sending the data, so I need to be
> able to do the 2 things at the same time.
>
> Can I open a port once and then use 2 different threads, one to write
> to the post and one to read the responses)?

By "port" I assume you mean a TCP connection using the 'socket' module?

If so, then yes you can write using one thread and read using a
second thread.  I do that all the time.

Sometimes it's simpler to use a single thread that uses select or
poll, and sometimes it's simpler to use multiple threads.  And you
never know which way is best until you're half way down the wrong
road...


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


Re: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)"

2012-08-10 Thread Larry Hudson

On 08/10/2012 01:28 PM, Chuck wrote:

Thanks for the help guys!  I finally got it working.  Shouldn't I technically 
call quiz() through the constructor, though?  Otherwise, the constructor is 
pointless.  I just put in pass for now.


For this particular example, frankly, a class doesn't make sense.  Just write it as a set of 
independent functions.  A class would make more sense if you wanted to make this a generic Quiz 
class, then you could change the actual quiz simply by passing an appropriate dictionary to it 
when it's instantiated.  But even that could be done with simple functions as well.



(Also, I always thought that if __name__ == '__main__': went IN the class.  Why 
wouldn't it be apart of the class?  )


No way!  That's nonsense also.  You need to go through some introductory tutorials.  Just keep 
in mind that Python and Java are VERY different languages.  (I don't know Java myself, my 
(hobby) programming background has been with C, and I'm still just starting to learn Python, too.)




Thanks again!



 -=- Larry -=-

PS.  On another subject...  You need to check your newsreader -- all your responses have been 
double-posted.


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


Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Giacomo Alzetta
Il giorno venerdì 10 agosto 2012 20:50:08 UTC+2, Stefan Behnel ha scritto:
> Giacomo Alzetta, 10.08.2012 10:20:
> 
> > I'm trying to implement a c-extension which defines a new 
> > class(ModPolynomial on the python side, ModPoly on the C-side).
> 
> > At the moment I'm writing the in-place addition, but I get a *really* 
> > strange behaviour.
> 
> 
> 
> You should take a look at Cython. It makes these things way easier and
> 
> safer than with manually written C code. It will save you a lot of code,
> 
> debugging and general hassle.
> 
> 
> 
> Stefan

I already know Cython, but I hope to learn a bit how python works from the 
C-side writing this extension.

Also this work is going to be included in a research work I'm doing, so I'd 
prefer to stick to Python and C, without having to put cython sources or 
cython-generated c modules(which I know are almost completely unreadable from a 
human point of view. Or at least the ones I saw).

Anyway thank you for the suggestion.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [c-api]Transmutation of an extension object into a read-only buffer adding an integer in-place.

2012-08-10 Thread Stefan Behnel
Giacomo Alzetta, 11.08.2012 08:21:
> I'd prefer to stick to Python and C, without having to put cython
> sources or cython-generated c modules (which I know are almost
> completely unreadable from a human point of view. Or at least the ones I
> saw).

And the cool thing is: you don't have to read them. :)

Stefan

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