Re : Upgrade woes: Numeric, gnuplot, and Python 2.4

2004-12-31 Thread Cedric
This is a 3 weeks old problem, but having found a solution (and having
looked for one here, finding only this message), I'm replying now.

From: Jive ([EMAIL PROTECTED])
Subject: Upgrade woes: Numeric, gnuplot, and Python 2.4 
Date: 2004-12-11 18:45:10 PST 
> Here's my sitch:
>
> I use gnuplot.py at work, platform Win32.  
> I want to upgrade to Python 2.4.
> Gnuplot.py uses extension module Numeric.  
> Numeric is now "unsupported." The documentation 
> says "If you are new to Numerical Python, please 
> use Numarray.".  It's not that easy, dangit.  
> The download page for numpy does not contain a 
> 2.4 version of Numeric, and I suspect they do 
> not intend to release one, because there IS a 2.4 
> version of Numarray.

Numarray was designed to be mostly backward compatible with Numeric. I
just replaced all of the

import Numeric

by

import numarray as Numeric

and it worked fine. Though I also had the same problem that I had with
Python 2.3 and Gnuplot, namely having to correct gnuplot_command in
gp_win32.py. On a related note, maybe I don't understand pipes, but
why doesn't popen() return an error when it doesn't find the file, and
it's open for reading?

Cédric
-- 
http://mail.python.org/mailman/listinfo/python-list


Reference count question

2005-02-02 Thread cedric paille





Hi all, i'm working on an app that embed python 2.3 
with Gnu/Linux, and i'd like to have some precisions:
 
I'm making python's modules to extend my 
application's functions with a built in script editor.
At now all works very well, but i'd like to know if 
i'm not forgetting some references inc/dec
 
Here is a portion of my code:
 
static PyObject *Scene_GetNodeGraph(PyObject 
*self, PyObject *args){  NodeGraph* Ng = 
NodeGraph::GetInstance();  std::vector NodG;  
Ng->GetNodeGraph(NodG);  PyObject* List = 
PyList_New(NodG.size());  PyObject* Str = 
NULL;  std::vector::iterator it = 
NodG.begin();  int i = 0;  for (;it != 
NodG.end();it++)  {    Str = 
PyString_FromString(it->AsChar());PyList_SetItem(List,i,Str); 
i++;  }  return List;}
 
Can someone take a look at this and tell me if i 
must add some inc/decref ?
 
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Beginner trying to understand functions.

2008-12-09 Thread Cedric Schmeits
the following would be nicer:

def run():
get_name()
a = get_age()
check_age(a)
again()

if __name__ == "__main__":
run()


In this setup your script will only be run if it's started by itself,
but when using a import, the functions from the script can be executed
separately.

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


Re: compute the double square...... :(

2011-01-09 Thread Cedric Schmeits
On Jan 9, 7:10 am, aregee  wrote:
> Double Squares
> A double-square number is an integer X which can be expressed as the
> sum of two perfect squares. For example, 10 is a double-square because
> 10 = 32 + 12. Your task in this problem is, given X, determine the
> number of ways in which it can be written as the sum of two squares.
> For example, 10 can only be written as 32 + 12 (we don't count 12 + 32
> as being different). On the other hand, 25 can be written as 52 + 02
> or as 42 + 32.
>
> Input
> You should first read an integer N, the number of test cases. The next
> N lines will contain N values of X.
> Constraints
> 0 ≤ X ≤ 2147483647
> 1 ≤ N ≤ 100
> Output
> For each value of X, you should output the number of ways to write X
> as the sum of two square
>
> Is the code mention below solution to this question  what is the
> fault...
> Error :
> are...@aregee-laptop:~/Desktop$ python pie.py
> enter a number::10
> pie.py:3: Deprecation Warning: integer argument expected, got float
>   for b in range(0,(x**0.5)/2):
>
> #Double square
>
> x = input("enter a number::")
> for b in range(0,(x**0.5)/2):
>       a = (x-(b**2))**0.5
> try:
>       a = int(a)
> except:
>       print("not an integer")
>       exit(1)
>
>       count = 0;
>       count = count + 1;
> if (x == a**2 + b**2):
>
>       print "double square"
aregee,

The problem you had was that you put a division by 2 in the range, if
x would be 25 than x**0.5 = 5.0 than you would feed range with 2.5 and
than you get the warning. Also I don't understand why you use de
division by 2, because if for instance you would take 25 you get 5 and
0 but you mis 3 and 4 as match. I've put in a tried list to

I would try the following:


#Double square
x = input("enter a number::")
for b in range(0,int((x**0.5))):
a = (x-(b**2))**0.5
try:
a = int(a)
except:
print("not an integer")
exit(1)

if a < b:
# when a is smaller than b we already have this match
# and all the following matches we also have
break
if (x == a**2 + b**2):
print "double square %s = %s**2 + %s**2" % (x, a, b)
-- 
http://mail.python.org/mailman/listinfo/python-list