Re: embedding interactive python interpreter

2011-03-27 Thread Mark Hammond

On 26/03/2011 4:37 AM, Eric Frederich wrote:

So I found that if I type ctrl-d then the other lines will print.


I think ctrl-d just causes sys.stdin to see EOF, so things just "fall 
out" as you desire.  exit() will winf up causing the C exit() function 
after finalizing, hence the behaviour you see.



In the mean time is there a way to redefine the exit function in
Python to do the same behavior as "ctrl-d?"


You can just patch exit in builtins with your own function although I'm 
not sure how you would terminate the builtin REPL - another alternative 
may be to look into the code/console modules where you may be able to 
arrange for more control over the REPL.


Cheers,

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


Re: Which subversion interface is the most used one?

2011-03-27 Thread Detlev Offenbach
Markus Schaber wrote:

> Hi,
> 
> at one of our projects, we could make use of a subversion interface 
for
> IronPython. But there seems none to exist.
> 
> The easiest way would be to directly expose SharpSVN to the 
IronPython
> scripts, but that is not a very pythonic solution. So we had the Idea
> of porting the existing python interfaces to IronPython.
> 
> And here the confusion starts, there seem to exist at least three of
> them (those are the ones I found being prepackaged on debian):
> 
> python-subversion: Seems to be a rather autogenerated wrapper around
> libsvn - thus being feature-complete, but rather unpythonic.
> 
> python-svn (pysvn): Seems to be written in C++, and give a somehow
> pythonic interface to the most important functionality.
> 
> python-subvertpy: Seems to aggregate the advantages of the two 
previous
> solutions, but I did not find any API documentation.
> 
> It seems that porting one of them to IronPython in a 1:1 fashion is 
no
> feasible solution.
> 
> So I came up with the Idea of simply re-implementing the API of one 
of
> those packages in C#, in a way that it can be exposed as IronPython
> module, using SharpSVN or Monodevelop-VersionControl as backend. This
> seems to be a rather low cost way of providing subversion 
functionality
> to IronPython, in a way compatible with at least some of the cPython
> Subversion applications.
> 
> Now my question:
> 
> Which one of the SVN interfaces are established and broadly used?
> 
> I don't want to risk to put effort into implementing a dead API when
> others are alive.
> 
> I have a slight tendency to pysvn, as it seems to be well documented
> and pythonic.
> 
> Thanks for your comments.

The eric Python IDE uses the pysvn interface, which works much better 
than interfacing to the svn executable.

Detlev
-- 
Detlev Offenbach
[email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some questions on pow and random

2011-03-27 Thread Jason Swails
2011/3/27 joy99 

> Dear Group,
>
> I have two questions one related to pow() and other is related to
> random.
> My questions are as below:
>
> (i) By standard definition of Likelihood Estimation, we get if x EURO X,
> where X is a countable set of types, p is probability and f is
> frequency.
> L(f;p)=Πp(x)f(x)
>
> My question is python provides two functions,
> (a) pow for power.
> (b) reduce(mul, list)
>
> Now, how to combine them? If any one can suggest any help?
> As p(x)f(x), would be huge would pow support it?
>

Not quite sure what you mean by "combine".  p(x)f(x) implies multiplying to
me, but "combine" suggests you mean something like p(f(x)) or the like.  In
any case, as long as the returned result of one of the functions is a valid
argument for the other, you can use the second approach.  And as long as the
results of both functions can be multiplied together (i.e. that operation is
defined), you can do that as well.

At most, pow would be limited by the floating point number in python.
sys.float_info gives me the following:

>>> sys.float_info
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308,
min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15,
mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)

So if the numbers may be bigger than 1.8e+308, then you'll need to find an
alternative way of doing this.  May I suggest recasting the problem using
only logs if possible (since that will increase the value of the digits that
can be used up to 10 ^ (1.8 E 308).  You can of course always back out the
full value afterwards.


> (b) Suppose we have two distributions p(x1) and p(x2), of the Model M,
> the E of EM algorithm, without going into much technical details is,
> P0(x1,x2), P1(x1,x2) 
>
> Now I am taking random.random() to generate both x1 and x2 and trying
> to multiply them, is it fine? Or should I take anything else?
>
>
I see no reason why you can't multiply them...  I'm not exactly sure what
you're trying to get here, though.

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


Re: Some questions on pow and random

2011-03-27 Thread Mark Dickinson
On Mar 27, 11:07 am, joy99  wrote:
> (i) By standard definition of Likelihood Estimation, we get if x EURO X,
> where X is a countable set of types, p is probability and f is
> frequency.
> L(f;p)=Ðp(x)f(x)
>
> My question is python provides two functions,
> (a)     pow for power.
> (b)     reduce(mul, list)
>
> Now, how to combine them? If any one can suggest any help?

If I'm understanding your question correctly, it sounds as though
you've got a vector p = (p_1, p_2, ..., p_n) of probabilities and a
corresponding vector f = (f_1, f_2, ..., f_n) of integer frequencies,
and you want to compute the product of the quantities p_i ** f_i.  Is
that right?

Assuming that p and f are represented by Python lists, you might do
something like this:

>>> p = [0.1, 0.5, 0.4]
>>> f = [3, 24, 18]
>>> product = 1.0
>>> for pi, fi in zip(p, f):
... product *= pi**fi
...
>>> product
4.0960005e-18

I wouldn't particularly recommend using 'reduce' for this, since it
doesn't lead to readable code, but if you must you can do:

>>> import operator
>>> reduce(operator.mul, map(pow, p, f), 1)
4.0960005e-18

or:

>>> reduce(operator.mul, [pi**fi for pi, fi in zip(p, f)], 1)
4.0960005e-18

> As p(x)f(x), would be huge would pow support it?

You'll run into problems with underflow to zero fairly quickly.  The
usual solution is to work with log likelihood instead of likelihood
itself, in which case you'd want a sum instead:

>>> sum(fi*log(pi) for pi, fi in zip(p, f))
-40.03652078615561

If you really need the likelihood itself, you might try using the
Decimal module, which allows a much wider exponent range than Python's
builtin float.

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


Re: Some questions on pow and random

2011-03-27 Thread Mark Dickinson
On Mar 27, 11:07 am, joy99  wrote:

> (b) Suppose we have two distributions p(x1) and p(x2), of the Model M,
> the E of EM algorithm, without going into much technical details is,
> P0(x1,x2), P1(x1,x2) 
>
> Now I am taking random.random() to generate both x1 and x2 and trying
> to multiply them, is it fine? Or should I take anything else?

Sorry, it's unclear to me what you're asking here.  Can you rephrase
this as a question about Python's random.random() function?

If you're asking whether it's okay to regard your generated x1 and x2
as independent, then the answer is yes.

--
Mark

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


Re: embedding interactive python interpreter

2011-03-27 Thread Eric Frederich
This is behavior contradicts the documentation which says the value
passed to sys.exit will be returned from Py_Main.
Py_Main doesn't return anything, it just exits.
This is a bug.

On Sun, Mar 27, 2011 at 3:10 AM, Mark Hammond  wrote:
> On 26/03/2011 4:37 AM, Eric Frederich wrote:
> exit() will winf up causing the C exit() function after
> finalizing, hence the behaviour you see.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some questions on pow and random

2011-03-27 Thread joy99
On Mar 27, 4:36 pm, Mark Dickinson  wrote:
> On Mar 27, 11:07 am, joy99  wrote:
>
> > (b) Suppose we have two distributions p(x1) and p(x2), of the Model M,
> > the E of EM algorithm, without going into much technical details is,
> > P0(x1,x2), P1(x1,x2) 
>
> > Now I am taking random.random() to generate both x1 and x2 and trying
> > to multiply them, is it fine? Or should I take anything else?
>
> Sorry, it's unclear to me what you're asking here.  Can you rephrase
> this as a question about Python's random.random() function?
>
> If you're asking whether it's okay to regard your generated x1 and x2
> as independent, then the answer is yes.
>
> --
> Mark

Dear Mark,
Thank you for kindly allowing your time to put your kind suggestions.
I am trying to rephrase my questions, as you might have asked it.

(i) Suppose we have 8 which is 2^3 i.e., 3 is the power of 2, which we
are writing in Python as,
variable1=2
variable2=3
result=pow(variable1,variable2)

In my first problem p(x) a list of float/decimals and f(x) is another
such.
Here,
variable1=p(x)
variable2=f(x)
so that we can write, pow(variable1,variable2) but as it is a list not
a number and as the size is huge, so would it pow support it?
As I copied the question from word processor to the post, so there was
a slight confusion.

(ii) The second question is, if I have another set of variables,

variable1=random.random()
variable2=random.random()

Now my question is, can I do
result=variable1*variable2

Or should I do anything else?

Best Regards,
Subhabrata.






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


Re: Some questions on pow and random

2011-03-27 Thread Mark Dickinson
On Mar 27, 3:00 pm, joy99  wrote:
> (i) Suppose we have 8 which is 2^3 i.e., 3 is the power of 2, which we
> are writing in Python as,
> variable1=2
> variable2=3
> result=pow(variable1,variable2)
>
> In my first problem p(x) a list of float/decimals and f(x) is another
> such.
> Here,
> variable1=p(x)
> variable2=f(x)
> so that we can write, pow(variable1,variable2) but as it is a list not
> a number and as the size is huge, so would it pow support it?

No:  pow won't work on lists.  It will work on (a) numbers (pow(2, 3) -
> 8),
or (b) numpy arrays, e.g.:

>>> import numpy as np
>>> x = np.array([0.1, 0.5, 0.4])
>>> y = np.array([3, 24, 18])
>>> pow(x, y)
array([  1.e-03,   5.96046448e-08,   6.87194767e-08])
>>> x ** y # exactly equivalent
array([  1.e-03,   5.96046448e-08,   6.87194767e-08])

> (ii) The second question is, if I have another set of variables,
>
> variable1=random.random()
> variable2=random.random()

In this case 'variable1' and 'variable2' are Python floats, so yes,
you can multiply them directly.  (BTW, you can always experiment
directly at the Python interactive prompt to answer this sort of
question.)

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


Re: Some questions on pow and random

2011-03-27 Thread joy99
On Mar 27, 8:52 pm, Mark Dickinson  wrote:
> On Mar 27, 3:00 pm, joy99  wrote:
>
> > (i) Suppose we have 8 which is 2^3 i.e., 3 is the power of 2, which we
> > are writing in Python as,
> > variable1=2
> > variable2=3
> > result=pow(variable1,variable2)
>
> > In my first problem p(x) a list of float/decimals and f(x) is another
> > such.
> > Here,
> > variable1=p(x)
> > variable2=f(x)
> > so that we can write, pow(variable1,variable2) but as it is a list not
> > a number and as the size is huge, so would it pow support it?
>
> No:  pow won't work on lists.  It will work on (a) numbers (pow(2, 3) -> 8),
>
> or (b) numpy arrays, e.g.:
>
> >>> import numpy as np
> >>> x = np.array([0.1, 0.5, 0.4])
> >>> y = np.array([3, 24, 18])
> >>> pow(x, y)
>
> array([  1.e-03,   5.96046448e-08,   6.87194767e-08])>>> x ** y # 
> exactly equivalent
>
> array([  1.e-03,   5.96046448e-08,   6.87194767e-08])
>
> > (ii) The second question is, if I have another set of variables,
>
> > variable1=random.random()
> > variable2=random.random()
>
> In this case 'variable1' and 'variable2' are Python floats, so yes,
> you can multiply them directly.  (BTW, you can always experiment
> directly at the Python interactive prompt to answer this sort of
> question.)
>
> Mark

Thanks Mark. Wishing you a nice day ahead.
Best Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding interactive python interpreter

2011-03-27 Thread Jerry Hill
On Sun, Mar 27, 2011 at 9:33 AM, Eric Frederich
 wrote:
> This is behavior contradicts the documentation which says the value
> passed to sys.exit will be returned from Py_Main.
> Py_Main doesn't return anything, it just exits.
> This is a bug.

Are you sure that calling the builtin exit() function is the same as
calling sys.exit()?

You keep talking about the documentation for sys.exit(), but that's
not the function you're calling.  I played around in the interactive
interpreter a bit, and the two functions do seem to behave a bit
differently from each other.  I can't seem to find any detailed
documentation for the builtin exit() function though, so I'm not sure
exactly what the differences are.

A little more digging reveals that the builtin exit() function is
getting set up by site.py, and it does more than sys.exit() does.
Particularly, in 3.1 it tries to close stdin then raises SystemExit().
 Does that maybe explain the behavior you're seeing?  I didn't go
digging in 2.7, which appears to be what you're using, but I think you
need to explore the differences between sys.exit() and the builtin
exit() functions.

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


Re: embedding interactive python interpreter

2011-03-27 Thread Eric Frederich
I'm not talking about the documentation for sys.exit()
I'm talking about the documentation for Py_Main(int argc, char **argv)

http://docs.python.org/c-api/veryhigh.html?highlight=py_main#Py_Main

This C function never returns anything whether in the interpreter I
type "exit(123)" or "sys.exit(123)".
I cannot call any of my C cleanup code because of this.

On Sun, Mar 27, 2011 at 1:55 PM, Jerry Hill  wrote:
> On Sun, Mar 27, 2011 at 9:33 AM, Eric Frederich
>  wrote:
>> This is behavior contradicts the documentation which says the value
>> passed to sys.exit will be returned from Py_Main.
>> Py_Main doesn't return anything, it just exits.
>> This is a bug.
>
> Are you sure that calling the builtin exit() function is the same as
> calling sys.exit()?
>
> You keep talking about the documentation for sys.exit(), but that's
> not the function you're calling.  I played around in the interactive
> interpreter a bit, and the two functions do seem to behave a bit
> differently from each other.  I can't seem to find any detailed
> documentation for the builtin exit() function though, so I'm not sure
> exactly what the differences are.
>
> A little more digging reveals that the builtin exit() function is
> getting set up by site.py, and it does more than sys.exit() does.
> Particularly, in 3.1 it tries to close stdin then raises SystemExit().
>  Does that maybe explain the behavior you're seeing?  I didn't go
> digging in 2.7, which appears to be what you're using, but I think you
> need to explore the differences between sys.exit() and the builtin
> exit() functions.
>
> --
> Jerry
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Standard way to distribute utilities with packages

2011-03-27 Thread Laszlo Nagy
I'd like to distribute a pure Python package named "foo". By default it 
will be placed in lib/site-packages/foo. What if I want to add 
utilities? Command line or GUI programs that are not full featured 
applications, but they can be handy for some tasks that are related to 
the package. Here is what I see:


* Python places them under "tools" in the Python installation dir (under 
windows). I'm not sure about Unix.


Other variants:

* site-packages/foo/scripts  (example: win32)
* site-packages/foo/util (example: vtk)
* directory site-packages/foo/tools (example: numpy)

Is there a PEP number / standard way for this?

Thanks,

   Laszlo


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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


Incompatible _sqlite3.so

2011-03-27 Thread Tim Johnson
I have python 2.6.5 on my main workstation with ubuntu 10.04. I am
attempting to set up a temporary test platform on an asus netbook
with slax running from an SD card. I have installed a python 2.7
module on the slax OS. (I can't find a python 2.6.5 module for
slax). For those who don't know, slax is a "pocket" OS and is very
limited. In the original slax install with python 2.7, there is not
_sqlite3.so available. I copied _sqlite3.so from my workstation and
I am getting the following error message:
"... undefined symbol: PyUnicodeUCS4_DecodeUTF8." 

I suspect that this is a version problem. I'd like to try
_sqlite3.so for python 2.7 (32-bit). If anyone has one or can tell
me where get one, I would appreciate it. I am reluctant to install
2.7 on my workstation right now.

thanks
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Incompatible _sqlite3.so

2011-03-27 Thread Alexander Kapps

On 27.03.2011 23:24, Tim Johnson wrote:

I have python 2.6.5 on my main workstation with ubuntu 10.04. I am
attempting to set up a temporary test platform on an asus netbook
with slax running from an SD card. I have installed a python 2.7
module on the slax OS. (I can't find a python 2.6.5 module for
slax). For those who don't know, slax is a "pocket" OS and is very
limited. In the original slax install with python 2.7, there is not
_sqlite3.so available. I copied _sqlite3.so from my workstation and
I am getting the following error message:
"... undefined symbol: PyUnicodeUCS4_DecodeUTF8."

I suspect that this is a version problem. I'd like to try
_sqlite3.so for python 2.7 (32-bit). If anyone has one or can tell
me where get one, I would appreciate it. I am reluctant to install
2.7 on my workstation right now.

thanks


Slax is a very modular and flexible "pocket OS"/Live distro. It's 
everything but limited .There are many additional modules available.


Python 2.6:
http://www.slax.org/modules.php?action=detail&id=3118

Several sqlite related packages, you probably need one of the 
pysqlite modules:

http://www.slax.org/modules.php?search=sqlite&category=

Finally, it's quite easy to build your own Slax modules:
http://www.slax.org/documentation_create_modules.php


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


Re: embedding interactive python interpreter

2011-03-27 Thread eryksun ()
On Friday, March 25, 2011 12:02:16 PM UTC-4, Eric Frederich wrote:
>
> Is there something else I should call besides "exit()" from within the
> interpreter?
> Is there something other than Py_Main that I should be calling?

Does PyRun_InteractiveLoop also have this problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Incompatible _sqlite3.so

2011-03-27 Thread Tim Johnson
* Alexander Kapps  [110327 13:58]:
> On 27.03.2011 23:24, Tim Johnson wrote:
> >I have python 2.6.5 on my main workstation with ubuntu 10.04. I am
> >attempting to set up a temporary test platform on an asus netbook
> >with slax running from an SD card. I have installed a python 2.7
> >module on the slax OS. (I can't find a python 2.6.5 module for
> >slax). For those who don't know, slax is a "pocket" OS and is very
> >limited. In the original slax install with python 2.7, there is not
> >_sqlite3.so available. I copied _sqlite3.so from my workstation and
> >I am getting the following error message:
> >"... undefined symbol: PyUnicodeUCS4_DecodeUTF8."
> >
> >I suspect that this is a version problem. I'd like to try
> >_sqlite3.so for python 2.7 (32-bit). If anyone has one or can tell
> >me where get one, I would appreciate it. I am reluctant to install
> >2.7 on my workstation right now.
> >
> >thanks
> 
> Slax is a very modular and flexible "pocket OS"/Live distro. It's
> everything but limited .There are many additional modules available.
> 
> Python 2.6:
> http://www.slax.org/modules.php?action=detail&id=3118
 
 That module is *not* trusted. See the warning? 
> Several sqlite related packages, you probably need one of the
> pysqlite modules:
> http://www.slax.org/modules.php?search=sqlite&category=
 Python 2.7 comes with its own sqlite module, but for some
 reason, the slax sqlite module does not provide the .so
 file
> Finally, it's quite easy to build your own Slax modules:
> http://www.slax.org/documentation_create_modules.php
  I'm really pressed for time, getting ready for a trip. The
  **
  quickest would be the so file itself, maybe from the slack site or
  if someone has one they can send me.
  **
  Alternatively I would try building python 2.7 from source on slax
  and extracting the file - I haven't used slax in some time, but
  earlier versions had pretty complete build tools.
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding interactive python interpreter

2011-03-27 Thread Mark Hammond

On 28/03/2011 5:28 AM, Eric Frederich wrote:

I'm not talking about the documentation for sys.exit()
I'm talking about the documentation for Py_Main(int argc, char **argv)

http://docs.python.org/c-api/veryhigh.html?highlight=py_main#Py_Main

This C function never returns anything whether in the interpreter I
type "exit(123)" or "sys.exit(123)".
I cannot call any of my C cleanup code because of this.


I think there is a bug in that documentation - the paragraph:

 Note that if an otherwise unhandled SystemError is raised, this
 function will not return 1, but exit the process, as long as
 Py_InspectFlag is not set.

Looks like it should refer to SystemExit, not SystemError.  If you check 
out pythonrun.c in handle_system_exit, you will note the behaviour 
described above is exactly what is implemented for SystemExit.


See also http://bugs.python.org/issue6498

HTH,

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


Re: Standard way to distribute utilities with packages

2011-03-27 Thread eryksun ()
On Sunday, March 27, 2011 4:05:30 PM UTC-4, Laszlo Nagy wrote:
> I'd like to distribute a pure Python package named "foo". By default it 
> will be placed in lib/site-packages/foo. What if I want to add 
> utilities? Command line or GUI programs that are not full featured 
> applications, but they can be handy for some tasks that are related to 
> the package. Here is what I see:

setuptools can create console and GUI scripts:

http://packages.python.org/distribute/setuptools.html#automatic-script-creation

These are installed in default locations such as C:\Python27\Scripts. If 
--install-dir is specified, the scripts will also be installed there unless 
--script-dir is specified.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standard way to distribute utilities with packages

2011-03-27 Thread Sridhar Ratnakumar
On Sunday, March 27, 2011 at 1:05 PM, Laszlo Nagy wrote:
I'd like to distribute a pure Python package named "foo". By default it 
> will be placed in lib/site-packages/foo. What if I want to add 
> utilities? Command line or GUI programs that are not full featured 
> applications, but they can be handy for some tasks that are related to 
> the package. Here is what I see:
> 
> * Python places them under "tools" in the Python installation dir (under 
> windows). I'm not sure about Unix.
> 
> Other variants:
> 
> * site-packages/foo/scripts (example: win32)
> * site-packages/foo/util (example: vtk)
> * directory site-packages/foo/tools (example: numpy)
None of the above are standard practices, as far as I know. 
> Is there a PEP number / standard way for this?
No PEP, but - yes - there is a conventional, if not standard, way to do this. 
It's called "entry points" (part of setuptools or Distribute).

Documentation: 
http://packages.python.org/distribute/setuptools.html#automatic-script-creation

Example: https://github.com/ActiveState/pythonselect/blob/master/setup.py#L49

Users of your package will need to have Distribute installed, which is 
available in ActivePython (all platforms), OSX and almost all of the Linux 
distributions.

-srid


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


Re: Incompatible _sqlite3.so

2011-03-27 Thread Alexander Kapps

On 28.03.2011 00:21, Tim Johnson wrote:


Python 2.6:
http://www.slax.org/modules.php?action=detail&id=3118


  That module is *not* trusted. See the warning?


It's just not verified by the Slax developers. That doesn't mean 
it's not trusted. It's the same as with Ubuntu packages from the 
Universe repo, or Firefox plugins which haven't been verified by the 
Mozilla team. None of them should be used where security matters, 
but on a testing system, the danger should be rather low.


If you limit yourself to strictly distro developer approved packages 
than I fear it's going to be hard to find one.


If all else fails, you could probably use the _sqlite3.so from 
another distro which has Python 2.7 officially.



  quickest would be the so file itself, maybe from the slack site or
  if someone has one they can send me.


You don't trust an unverified package from the Slax site, but you 
would trust some other stranger on the python-list, to not give you 
a manipulated .so? You're either too paranoid or not paranoid enough ;-)

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


Data files for tests

2011-03-27 Thread Steven D'Aprano
I have a package with some tests. The tests are not part of the package 
itself, so I have a laid out my files like this:


src/
spam/
__init__.py
other-files.py
test_spam.py


Some of the tests depend on external data files. Where should I put them? 
In the same directory as test_spam?



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


Re: Data files for tests

2011-03-27 Thread eryksun ()
On Sunday, March 27, 2011 7:07:33 PM UTC-4, Steven D'Aprano wrote:
> I have a package with some tests. The tests are not part of the package 
> itself, so I have a laid out my files like this:
> 
> 
> src/
> spam/
> __init__.py
> other-files.py
> test_spam.py
> 
> 
> Some of the tests depend on external data files. Where should I put them? 
> In the same directory as test_spam?

Including data files and accessing them via the resource management API:

http://packages.python.org/distribute/setuptools.html#including-data-files
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Tutorial

2011-03-27 Thread Colin J. Williams

I have come across: http://www.java2s.com/Tutorial/Python/CatalogPython.htm

On a quick skim, the above seems to cover more ground
than the standard: http://docs.python.org/tutorial/

I spotted one bug in the former, but one of the Network
examples was helpful.

Colin W.

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


Re: Data files for tests

2011-03-27 Thread eryksun ()
On Sunday, March 27, 2011 7:33:22 PM UTC-4, eryksun () wrote:
> On Sunday, March 27, 2011 7:07:33 PM UTC-4, Steven D'Aprano wrote:
> > I have a package with some tests. The tests are not part of the package 
> > itself, so I have a laid out my files like this:
> > 
> > 
> > src/
> > spam/
> > __init__.py
> > other-files.py
> > test_spam.py
> > 
> > 
> > Some of the tests depend on external data files. Where should I put them? 
> > In the same directory as test_spam?
> 
> Including data files and accessing them via the resource management API:
> 
> http://packages.python.org/distribute/setuptools.html#including-data-files

For example, if test_spam is in a separate package:

setup.py
src/
spam/
__init__.py
other-files.py
test_spam/
__init__.py
test_spam.py
data/
test_data.dat

setup.py:

from setuptools import setup, find_packages
setup(
# ...

packages = find_packages('src'),  # include all packages under src
package_dir = {'':'src'},   # tell distutils packages are under src

package_data = {
# include any *.dat files found in the 'data' subdirectory
# of the 'test_spam' package:
'test_spam': ['data/*.dat'],
}
)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Incompatible _sqlite3.so

2011-03-27 Thread Tim Johnson
* Alexander Kapps  [110327 15:14]:
> On 28.03.2011 00:21, Tim Johnson wrote:
> 
> >>Python 2.6:
> >>http://www.slax.org/modules.php?action=detail&id=3118
> >
> >  That module is *not* trusted. See the warning?
> 
> 
> You don't trust an unverified package from the Slax site, but you
> would trust some other stranger on the python-list, to not give you
> a manipulated .so? You're either too paranoid or not paranoid enough
> ;-)
 Probably not paranoid enough. Although I don't care if I hose 
 slax on an SD card, my workstation is another matter.

 FYI: I have never used sqlite3 with python but am trying to put
 together a 'package' to tutor mysql django on the netbook.
 So.. I built python 2.76 on my desktop. When I do 
 >> import sqlite3
 python2.7 tells me that it can't find _sqlite3.
 Sure enough, no _sqlite3.so at 
 /usr/local/lib/python2.7/lib-dynload
 So what else do I need to obtain install _sqlite3.so for
 my desktop?

 *NOTE* we now are discussing my ubuntu 10.04 workstation, not slax.

 thanks for the replies
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Incompatible _sqlite3.so

2011-03-27 Thread Tim Johnson
* Tim Johnson  [110327 16:59]:
> * Alexander Kapps  [110327 15:14]:
> > On 28.03.2011 00:21, Tim Johnson wrote:
> > 
> > >>Python 2.6:
> > >>http://www.slax.org/modules.php?action=detail&id=3118
> > >
> > >  That module is *not* trusted. See the warning?
> > 
> > 
> > You don't trust an unverified package from the Slax site, but you
> > would trust some other stranger on the python-list, to not give you
> > a manipulated .so? You're either too paranoid or not paranoid enough
> > ;-)
>  Probably not paranoid enough. Although I don't care if I hose 
>  slax on an SD card, my workstation is another matter.
> 
>  FYI: I have never used sqlite3 with python but am trying to put
>  together a 'package' to tutor mysql django on the netbook.
>  So.. I built python 2.76 on my desktop. When I do 
>  >> import sqlite3
>  python2.7 tells me that it can't find _sqlite3.
>  Sure enough, no _sqlite3.so at 
>  /usr/local/lib/python2.7/lib-dynload
>  So what else do I need to obtain install _sqlite3.so for
>  my desktop?
 I had to install libsqlite3-dev. Now I have sqlite3 working
 on python 2.7 on my desktop.
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding interactive python interpreter

2011-03-27 Thread Eric Frederich
I'm not sure that I know how to run this function in such a way that
it gives me an interactive session.
I passed in stdin as the first parameter and NULL as the second and
I'd get seg faults when running exit() or even imnport sys.

I don't want to pass a file.  I want to run some C code, start an
interactive session, then run some more C code once the session is
over, but I cannot find a way to start an interactive Python session
within C that won't exit pre-maturely before I have a chance to run my
cleanup code in C.

On Sun, Mar 27, 2011 at 5:59 PM, eryksun ()  wrote:
> On Friday, March 25, 2011 12:02:16 PM UTC-4, Eric Frederich wrote:
>>
>> Is there something else I should call besides "exit()" from within the
>> interpreter?
>> Is there something other than Py_Main that I should be calling?
>
> Does PyRun_InteractiveLoop also have this problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


Why aren't copy and deepcopy in __builtins__?

2011-03-27 Thread John Ladasky
Simple question.  I use these functions much more frequently than many
others which are included in __builtins__.  I don't know if my
programming needs are atypical, but my experience has led me to wonder
why I have to import these functions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding interactive python interpreter

2011-03-27 Thread eryksun ()
On Sunday, March 27, 2011 11:06:47 PM UTC-4, Eric Frederich wrote:
> I'm not sure that I know how to run this function in such a way that
> it gives me an interactive session.
> I passed in stdin as the first parameter and NULL as the second and
> I'd get seg faults when running exit() or even imnport sys.

Passing NULL as the 2nd parameter causes the segfault. Do this instead:

FILE* fp = stdin;
char *filename = "Embedded";
PyRun_InteractiveLoop(fp, filename);

See here regarding the segfault:

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


What is Email Marketing?

2011-03-27 Thread deepikalakhena
Florists Use Email Marketing to Get ahead of the Competition
# Marine Supply Companies Adapt Email Marketing Software to Meet Their
Needs
# Wineries Turn to Email Marketing
# Email Marketing Software Adapted by Pet Groomers
# How Many Holiday Product Email Blasts

Try it for Free
Launch your first email marketing campaign in minutes! Get Started Now


http://streamsendemail.co.cc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best python games?

2011-03-27 Thread alex23
Paul Rudin  wrote:
> Apparently Eve Online is (stackless) python.

I've dropped a ridiculous number of hours into EVE this year alone but
I'd be very hesitant to ever mention "best" in relation to its
coding :)

It uses way too much floating point incorrectly, the in-game
calculator gives the result of 878.53 - 874.20 as 4.32999. I'm
pretty sure this is also why occasionally you'll be left with 1 0.01m3
unit out of 39, with the storage container complaining it's full
at 38,.99.

CCP's devs have been raving about their radical new "Inventory
Setification" code optimisation which is - as far as I can tell -
simply changing some internal representations from lists to sets and
gaining from recent performance tweaks.

EVE is very much a game I play in spite of the implementation :(

Civ 4 used it for most of the gameplay and interface, I believe,
wrapping more performant libraries for the graphics & audio.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why aren't copy and deepcopy in __builtins__?

2011-03-27 Thread Carl Banks
On Mar 27, 8:29 pm, John Ladasky  wrote:
> Simple question.  I use these functions much more frequently than many
> others which are included in __builtins__.  I don't know if my
> programming needs are atypical, but my experience has led me to wonder
> why I have to import these functions.

I rarely use them (for things like lists I use list() constructor to
copy, and for most class instances I usually don't want a straight
copy of all members), but I wouldn't have a problem if they were
builtin.  They make more sense than a lot of builtins.

I'd guess the main reason they're not builtin is that they aren't
really that simple.  The functions make use of a lot of knowledge
about Python types.  Builtins tend to be for straightforward, simple,
building-block type functions.


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


Re: best python games?

2011-03-27 Thread Tim Delaney
On 26 March 2011 13:39, sogeking99  wrote:

> hey guys, what are some of the best games made in python? free games
> really. like pygames stuff. i want to see what python is capable of.
>
> cant see any good one on pygames site really, though they have nothing
> like sort by rating or most downloaded as far as i can tell
>

They're not free, but both "Vampire the Masquerade: Bloodlines" and "The
Temple of Elemental Evil " by Troika were largely implemented in Python
(pretty much all the intelligence of the games).

In both cases, the .py files were included, and this has been used by fans
to provide ongoing bugfixes and improvements.

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


Re: best python games?

2011-03-27 Thread Steven D'Aprano
On Sun, 27 Mar 2011 21:17:49 -0700, alex23 wrote:

> Paul Rudin  wrote:
>> Apparently Eve Online is (stackless) python.
> 
> I've dropped a ridiculous number of hours into EVE this year alone but
> I'd be very hesitant to ever mention "best" in relation to its coding :)
> 
> It uses way too much floating point incorrectly, the in-game calculator
> gives the result of 878.53 - 874.20 as 4.32999. 

Well no wonder you're complaining! That's *completely* wrong, the correct 
value is 4.32999272.


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