Re: Python dashboard tutorials/frameworks for interactive, D3.js graphs in IPython Notebooks

2015-11-06 Thread Chris Angelico
On Fri, Nov 6, 2015 at 5:13 PM,   wrote:
> On Thursday, July 9, 2015 at 8:10:16 PM UTC-4, Matt Sundquist wrote:
>> For more background, refer to our Python docs: https://plot.ly/python/, our 
>> Python framework for making dashboards: https://github.com/plotly/dash, our 
>> data science blog: http://moderndata.plot.ly/, or these 21 IPython 
>> Notebooks: https://plot.ly/python/ipython-notebooks/.
>>
>
> You guys are so expensive - not even worth looking into your product. 
> Absolutely retarded.
> Srinath

No need to be so rude as you complain about people getting paid for their work.

I'm not even sure your complaint is accurate; where did you see
ridiculously high prices? I started with the first link I quoted above
(the Python docs), and up the top is this note: "plotly is free for
unlimited public use". Then there's a zero-dollar option (though that
might be the same as the previous note), and a $20/mo option called
"professional". If professional usage is only $20 per month, I don't
think it's fair to call it "absolutely retarded". Yes, there's also an
on-premise option for ten grand a year, but that's some serious
top-end privacy stuff... if you think you have to pay that just to
make use of their services, then yes, I can see that you'd complain
about the pricing!

Or was this a deliberate troll to make people go look at the pricing
in more detail?

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


Re: RuntimeError: The size of the array returned by func does not match the size of y0

2015-11-06 Thread avinash ramu
Hi,
The number of elements returned by the function f() needs to match the
number of elements in the initial condition y0.

The problem seems to be in this part of the code,

```
for j in range(0,3*N/2+3):
return ydot[j]
```

It is returning the first element instead of the list.  I modified your
code to use a temporary list(ydot_new), I then add elements to this new
list using the `for` statement and return the list. This seems to work
fine!  See below,

79 ydot_new = []
80 for j in range(0,3*N/2+3):
81 ydot_new.extend(ydot[j])
82 return ydot_new

(I'm not an expert on ODE, so I'm not sure how to verify the correctness!)
Cheers,
Avi


On Thu, Nov 5, 2015 at 9:54 PM, Abhishek  wrote:

> I have recently switched from programming heavily in MATLAB to programming
> in Python. Hence I am having some issues running the Python code that I
> have written. I am using IPython with Anaconda2 on Windows 7 and using
> numPy and SciPy to integrate a system of ordinary differential equations. I
> have generalized the system of ODEs for any number 'N' of them.
>
> I have two versions of code that do the same thing, and give the same
> error message. One version uses 'exec' and 'eval' heavily, and the other
> uses arrays heavily. Here is my code for the array version:
>
> --
> import numpy as np
> import matplotlib.pyplot as plt
> from scipy.integrate import odeint
>
> #Constants and parameters
> N = 2
> K00 = np.logspace(0,3,101,10)
> len1 = len(K00)
> epsilon = 0.01
> y0 = [0]*(3*N/2+3)
> u1 = 0
> u2 = 0
> u3 = 0
> Kplot = np.zeros((len1,1))
> Pplot = np.zeros((len1,1))
> S = [np.zeros((len1,1)) for  in range(N/2+1)]
> KS = [np.zeros((len1,1)) for  in range(N/2+1)]
> PS = [np.zeros((len1,1)) for  in range(N/2+1)]
> Splot = [np.zeros((len1,1)) for  in range(N/2+1)]
> KSplot = [np.zeros((len1,1)) for  in range(N/2+1)]
> PSplot = [np.zeros((len1,1)) for  in range(N/2+1)]
>
> for series in range(0,len1):
> K0 = K00[series]
> Q = 10
> r1 = 0.0001
> r2 = 0.001
> a = 0.001
> d = 0.001
> k = 0.999
> S10 = 1e5
> P0 = 1
> tfvec = np.tile(1e10,(1,5))
> tf = tfvec[0,0]
> time = np.linspace(0,tf,len1)
>
> #Defining dy/dt's
> def f(y,t):
> for alpha in range(0,(N/2+1)):
> S[alpha] = y[alpha]
> for beta in range((N/2)+1,N+1):
> KS[beta-N/2-1] = y[beta]
> for gamma in range(N+1,3*N/2+1):
> PS[gamma-N] = y[gamma]
> K = y[3*N/2+1]
> P = y[3*N/2+2]
>
> # The model equations
> ydot = np.zeros((3*N/2+3,1))
> B = range((N/2)+1,N+1)
> G = range(N+1,3*N/2+1)
> runsumPS = 0
> runsum1 = 0
> runsumKS = 0
> runsum2 = 0
>
> for m in range(0,N/2):
> runsumPS = runsumPS + PS[m+1]
> runsum1 = runsum1 + S[m+1]
> runsumKS = runsumKS + KS[m]
> runsum2 = runsum2 + S[m]
> ydot[B[m]] = a*K*S[m]-(d+k+r1)*KS[m]
>
> for i in range(0,N/2-1):
> ydot[G[i]] = a*P*S[i+1]-(d+k+r1)*PS[i+1]
>
> for p in range(1,N/2):
> ydot[p] = -S[p]*(r1+a*K+a*P)+k*KS[p-1]+ \
>   d*(PS[p]+KS[p])
>
> ydot[0] = Q-(r1+a*K)*S[0]+d*KS[0]+k*runsumPS
> ydot[N/2] = k*KS[N/2-1]-(r2+a*P)*S[N/2]+ \
> d*PS[N/2]
> ydot[G[N/2-1]] = a*P*S[N/2]-(d+k+r2)*PS[N/2]
> ydot[3*N/2+1] = (d+k+r1)*runsumKS-a*K*runsum2
> ydot[3*N/2+2] = (d+k+r1)*(runsumPS-PS[N/2])- \
> a*P*runsum1+(d+k+r2)*PS[N/2]
>
> for j in range(0,3*N/2+3):
> return ydot[j]
>
> # Initial conditions
> y0[0] = S10
> for i in range(1,3*N/2+1):
> y0[i] = 0
> y0[3*N/2+1] = K0
> y0[3*N/2+2] = P0
>
> # Solve the DEs
> soln = odeint(f,y0,time,mxstep = 5000)
> for alpha in range(0,(N/2+1)):
> S[alpha] = soln[:,alpha]
> for beta in range((N/2)+1,N+1):
> KS[beta-N/2-1] = soln[:,beta]
> for gamma in range(N+1,3*N/2+1):
> PS[gamma-N] = soln[:,gamma]
>
> for alpha in range(0,(N/2+1)):
> Splot[alpha][series] = soln[len1-1,alpha]
> for beta in range((N/2)+1,N+1):
> KSplot[beta-N/2-1][series] = soln[len1-1,beta]
> for gamma in range(N+1,3*N/2+1):
> PSplot[gamma-N][series] = soln[len1-1,gamma]
>
> for alpha in range(0,(N/2+1)):
> u1 = u1 + Splot[alpha]
> for beta in range((N/2)+1,N+1):
> u2 = u2 + KSplot[beta-N/2-1]
> for gamma in range(N+1,3*N/2+1):
> u3 = u3 + PSplot[gamma-N]
>
> K = soln[:,3*N/2+1]
> P = soln[:,3*N/2+2]
> Kplot[series] = soln[len1-1,3*N/2+1]
> Pplot[series] = soln[len1-1,3*N/2+2]
> utot = u1+u2+u3
>
> #Plot
> plt.plot(np.log10(K00),utot[:,0])
> plt.show()
> ---

argparse: use of double dash to separate options and positional arguments

2015-11-06 Thread Amit Ramon

Hello,

I'm trying to use argparse in a program that gets some options and
positional arguments. I want to collect all the positional arguments
in a single argument using the REMAINDER option to add_argument() as
shown bellow:

   parser = argparse.ArgumentParser(description='Test argparse')
   parser.add_argument('-v', '--verbose', action='store_true')
   parser.add_argument('cmd_args', nargs=argparse.REMAINDER)
   print parser.parse_args()

This works well unless the first positional argument starts with a
'-'.

For example, with the above code

   my_prog -v hello world

works well, but

   my_prog -v -x hello world

Fails with an error message 'error: unrecognized arguments: -x'.

If I invoke the program with a '--' at the end of the options (as I
understand is a common standard and a POSIX recommendation), as in:

   my_prog -v -- -x hello world

It works well again.

However, a few questions remain:

Firstly, as far as I can tell the use of '--' is not documented in the
argparse documentation (but the code of argparse clearly shows that it
is a feature).

Secondly, when using '--', this string itself is inserted into the
list of the collected positional arguments (in the above example in
the cmd_args variable):

$ ./my_prog -v -- -x hello world
Namespace(cmd_args=['--', '-x', 'hello', 'world'], verbose=True)

It's quiet easy to check for it and remove it if it exists, but it
still seems like it shouldn't be there - it is not really an argument,
just a delimiter.

Am I doing anything wrong, or is this a bug? I hope someone here can
shed some light on this.

Thanks,

Amit



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


Olivier Adret

2015-11-06 Thread olivier

 Je vais essayer de programmer en python. On verra bien !
--
https://mail.python.org/mailman/listinfo/python-list


RE: Puzzled

2015-11-06 Thread Robinson, Wendy
Well... I still can't get this to work. I guess I'll just uninstall it.
It's a bummer that there's no help on basic startup like this.

Wendy Robinson
Audit Analyst
(916) 566-4994 phone



NOTICE OF CONFIDENTIALITY: This email is for the sole use of the intended 
recipient and may contain material that is confidential and protected by state 
and federal regulations.  If you are not the intended recipient please 
immediately delete it and contact the sender. 

-Original Message-
From: Laura Creighton [mailto:l...@openend.se] 
Sent: Sunday, November 01, 2015 2:21 AM
To: Robinson, Wendy
Cc: 'python-list@python.org'; l...@openend.se
Subject: Re: Puzzled

In a message of Fri, 30 Oct 2015 09:20:23 -0700, "Robinson, Wendy" writes:
>Hi there,
>I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic 
>programs successfully.
>This morning I rebooted my computer and can't get a single one to work.  The 
>interpreter seems to be fine and the environment variables look correct.  But 
>every py file I try to run at the >>> prompt gives me a NameError.
>
>I tried running the Repair installation, but that did not help.
>
>Any suggestions?
>
>Thank you
>
>Wendy Robinson
>Audit Analyst
>(916) 566-4994 phone

Paste in the Full traceback you get from the console.
Also check and see that the console is actually running the 3.5 you installed, 
and not some other python, like 2.7 you might have lying around.  

Laura
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Puzzled

2015-11-06 Thread Robinson, Wendy
Hmmm... fair enough.  I sent the traceback though, on Monday.
I'll give the intro a read again.  I've probably missed something basic.

Wendy Robinson
Audit Analyst
(916) 566-4994 phone



NOTICE OF CONFIDENTIALITY: This email is for the sole use of the intended 
recipient and may contain material that is confidential and protected by state 
and federal regulations.  If you are not the intended recipient please 
immediately delete it and contact the sender. 


-Original Message-
From: Laura Creighton [mailto:l...@openend.se] 
Sent: Thursday, November 05, 2015 3:11 PM
To: Robinson, Wendy
Cc: 'Laura Creighton'; 'python-list@python.org'; l...@openend.se
Subject: Re: Puzzled

In a message of Thu, 05 Nov 2015 12:48:11 -0800, "Robinson, Wendy" writes:
>Well... I still can't get this to work. I guess I'll just uninstall it.
>It's a bummer that there's no help on basic startup like this.
>
>Wendy Robinson
>Audit Analyst
>(916) 566-4994 phone

There is enormous amount of help available.  But we need to know more about 
what your problem is, and how it presents itself before we can start tracking 
down what your problem is, which is why I wanted a traceback.

>>Hi there,
>>I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic 
>>programs successfully.
>>This morning I rebooted my computer and can't get a single one to work.  The 
>>interpreter seems to be fine and the environment variables look correct.  But 
>>every py file I try to run at the >>> prompt gives me a NameError.

See, this is where your problem is. There is a conceptual problem in 
understanding what you meant by 'tried some basic programs successfully'
versus 'running py files at the >>> prompt'.

Either you didn't use the Python console -- the thing that is showing you the 
'>>>' yesterday, and thus the programs that were working yesterday are now 
working every bit as well as they did then, and your problem is that you do not 
know how to use the python console.

Or you did use the console before, and they worked there, and now you have 
NameErrors.

I think the problem is the first sort.
I think that you opened up the python console and then typed in something like 
'myprogram.py' expecting the console to run the myprogram.  Instead you got 
something like this:

Python 3.5.0rc1 (default, Aug 12 2015, 14:57:46) [GCC 5.2.1 20150808] on linux 
Type "help", "copyright", "credits" or "license" for more information.
 >>> myprogram.py
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'myprogram' is not defined  >>> 

If this is what happened then your python is fine.  You just do not know how 
the interactive console works.  It doesn't run files like this.

See:https://docs.python.org/3.5/tutorial/introduction.html

You type code at the console and get responses back.

If, on the other hand, this is not your problem, then we need a traceback --- 
and what I posted above was a traceback -- so that we can see what caused the 
NameError.  

Laura 

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


Question about math.pi is mutable

2015-11-06 Thread wa...@travelsky.com
Hello, python-list guys:

I am a newbie of python from Beijing. China. 
I have a question about "math.pi". 
As you can see in the attachment, why i can modify "math.pi"?
(in "mathmodule.c" "pi" is a "static const double")

Thank you in advance!

Best Wishes!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about math.pi is mutable

2015-11-06 Thread Chris Angelico
On Fri, Nov 6, 2015 at 1:33 PM, wa...@travelsky.com  wrote:
> Hello, python-list guys:
>
> I am a newbie of python from Beijing. China.
> I have a question about "math.pi".
> As you can see in the attachment, why i can modify "math.pi"?
> (in "mathmodule.c" "pi" is a "static const double")
>
> Thank you in advance!
>
> Best Wishes!

Simply because, in Python, virtually everything can be changed. You're
welcome to go in and say "math.pi = 3" if you like... and then you
accept the consequences of that.

There are times when you want to change these sorts of 'constants'.
For example, math.pi is a float; but if you're working with
decimal.Decimal everywhere, it might be useful to replace it with a
corresponding Decimal value:

math.pi = decimal.Decimal("3.14159265358979323")

And that's perfectly legal.

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


Re: Olivier Adret

2015-11-06 Thread Chris Angelico
On Fri, Nov 6, 2015 at 2:24 AM, olivier  wrote:
>  Je vais essayer de programmer en python. On verra bien !

Hello Olivier!

This is a mostly English language mailing list/newsgroup, and there
aren't many people who are fluent in French. There is, however, a
corresponding French newsgroup, fr.comp.lang.python; you may find that
you're more comfortable communicating there.

My apologies for not responding in French, but I'm not very familiar
with it, and all I would do is put my text through an online
translation tool.

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


Re: Question about math.pi is mutable

2015-11-06 Thread Ian Kelly
On Nov 6, 2015 3:20 AM, "wa...@travelsky.com"  wrote:
>
> Hello, python-list guys:
>
> I am a newbie of python from Beijing. China.
> I have a question about "math.pi".
> As you can see in the attachment, why i can modify "math.pi"?
> (in "mathmodule.c" "pi" is a "static const double")

Like all floats, math.pi is immutable. However, the *name* pi in the math
module is not special and can be rebound to a new value, like (almost) any
other name.

So yes, you can assign 3 to math.pi. You can also assign 3 to math.sqrt, or
os.urandom, or float.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: argparse: use of double dash to separate options and positional arguments

2015-11-06 Thread Peter Otten
Amit Ramon wrote:

> Hello,
> 
> I'm trying to use argparse in a program that gets some options and
> positional arguments. I want to collect all the positional arguments
> in a single argument using the REMAINDER option to add_argument() as
> shown bellow:
> 
> parser = argparse.ArgumentParser(description='Test argparse')
> parser.add_argument('-v', '--verbose', action='store_true')
> parser.add_argument('cmd_args', nargs=argparse.REMAINDER)
> print parser.parse_args()
> 
> This works well unless the first positional argument starts with a
> '-'.
> 
> For example, with the above code
> 
> my_prog -v hello world
> 
> works well, but
> 
> my_prog -v -x hello world
> 
> Fails with an error message 'error: unrecognized arguments: -x'.

This looks like a bug to me. Please report it on bug.python.org.
 
> If I invoke the program with a '--' at the end of the options (as I
> understand is a common standard and a POSIX recommendation), as in:
> 
> my_prog -v -- -x hello world
> 
> It works well again.
> 
> However, a few questions remain:
> 
> Firstly, as far as I can tell the use of '--' is not documented in the
> argparse documentation (but the code of argparse clearly shows that it
> is a feature).
> 
> Secondly, when using '--', this string itself is inserted into the
> list of the collected positional arguments (in the above example in
> the cmd_args variable):
> 
> $ ./my_prog -v -- -x hello world
> Namespace(cmd_args=['--', '-x', 'hello', 'world'], verbose=True)
> 
> It's quiet easy to check for it and remove it if it exists, but it
> still seems like it shouldn't be there - it is not really an argument,
> just a delimiter.

I'm not sure about this one; one purpose of REMAINDER is to pass on the 
unprocessed arguments to another program/script, and this might follow the 
same convention. Should

parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('cmd_args', nargs=argparse.REMAINDER)
args = parser.parse_args()
subprocess.call(["rm"] + args.cmd_args)

$ my_prog -v -- -r foo

attempt to delete two files "-r" and "foo" or remove the "foo" directory? 
The first is the safer alternative, and as you say stripping the "--" is 
easy.


> Am I doing anything wrong, or is this a bug? I hope someone here can
> shed some light on this.


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


Re: argparse: use of double dash to separate options and positional arguments

2015-11-06 Thread Amit Ramon

Peter Otten <__pete...@web.de> [2015-11-06 11:57 +0100]:




For example, with the above code

my_prog -v hello world

works well, but

my_prog -v -x hello world

Fails with an error message 'error: unrecognized arguments: -x'.


This looks like a bug to me. Please report it on bug.python.org.


Why does it looks like a bug? To me it seems okay - argparse expects
that an argument that starts with '-' is an option, and it also expects
to be told about all possible options, so it complains on
encountering an unrecognized 'option'. This is why a special delimiter
is needed to mark the 'end of options'.





If I invoke the program with a '--' at the end of the options (as I
understand is a common standard and a POSIX recommendation), as in:

my_prog -v -- -x hello world

It works well again.

However, a few questions remain:

Firstly, as far as I can tell the use of '--' is not documented in the
argparse documentation (but the code of argparse clearly shows that it
is a feature).

Secondly, when using '--', this string itself is inserted into the
list of the collected positional arguments (in the above example in
the cmd_args variable):

$ ./my_prog -v -- -x hello world
Namespace(cmd_args=['--', '-x', 'hello', 'world'], verbose=True)

It's quiet easy to check for it and remove it if it exists, but it
still seems like it shouldn't be there - it is not really an argument,
just a delimiter.


I'm not sure about this one; one purpose of REMAINDER is to pass on the
unprocessed arguments to another program/script, and this might follow the
same convention. Should

parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('cmd_args', nargs=argparse.REMAINDER)
args = parser.parse_args()
subprocess.call(["rm"] + args.cmd_args)

$ my_prog -v -- -r foo

attempt to delete two files "-r" and "foo" or remove the "foo" directory?
The first is the safer alternative, and as you say stripping the "--" is
easy.


I'm using the REMAINDER exactly for passing on arguments to another
program, as in your example. I would expect that everything after
the '--' should be passed on as is - it should be up to the other
program to decide what to do with the arguments it receives (So in
your examples, rm would actually try to remove the "foo" directory).

And although stripping the '--' is easy, why should the user of
argparse need to handle it? Still unclear to me.

Cheers,

Amit
--
https://mail.python.org/mailman/listinfo/python-list


Re: raw_input and break

2015-11-06 Thread input/ldompeling
Hi,

I tried to define SEQUENCE with:
The script is working now, exept that I do'nt get a menu in terminal for "s" to 
stop.
-

def SEQUENCE():


while notDone:
if mindist > us_dist(15):
for (dir, tm) in SEQUENCE:
move(dir, tm)

-
In reply to "input/ldompel...@casema.nl" who wrote the following:

> He,
> Thank you for making some time for it.
> Is this your code ?
> I am also using python 3
> 
> I got an error with execute the scipt:
> ---
> 
> Enter command> Traceback (most recent call last):
>   File "test06.py", line 44, in 
> for (dir, tm) in SEQUENCE:
> NameError: name 'SEQUENCE' is not defined
> ---
> 
> import time
> import threading
> 
> set_right_speed(150)
> set_left_speed(105)
> 
> def cmdHandler():
> global notDone
> while True:
> cmd = raw_input("Enter command> ").lower()
> if cmd.startswith("s"):
> notDone = False
> break
> else:
> print ("Unimplemented command: %s") % cmd
> 
> cmdThread = threading.Thread(target=cmdHandler)
> cmdThread.start()
> def move(drct, dly):
> if drct == FORWARD:
> fwd()
> print ("Forward")
> elif drct == BACKWARD:
> bwd()
> print ("Backward")
> elif drct == LEFT:
> left()
> print ("Left")
> elif drct == RIGHT:
> right()
> print ("Right")
> else:
> print ("Invalid command: %s") % drct
> time.sleep(dly)
> stop()
> 
> notDone = True
> 
> servo(90)
> mindist = 80
> 
> while notDone:
> if mindist > us_dist(15):
> for (dir, tm) in SEQUENCE:
> move(dir, tm)
> 
> --
> ---
> In reply to "Dennis Lee Bieber" who wrote the following:
> 
> > On Thu, 05 Nov 2015 17:28:36 GMT, input/ldompel...@casema.nl declaimed the
> > following:
> > 
> > > Oke, lets try your code.Can you help me with that.
> > > This is my code:
> > > -
> > > from gopigo import *
> > > import time
> > > 
> > > set_right_speed(150)
> > > set_left_speed(105)
> > 
> >  Is there a typo there? If those are setting rotation speeds for
> > independent drive wheels, you will have a slow left turn enabled.
> > 
> > > enable_servo()
> > > fwd()
> > > print("forward 1x")
> > > time.sleep(4)
> > > stop()
> > > 
> > > while True:
> > >servo(90)
> > >mindist = 80
> > > 
> > >if mindist > us_dist(15):
> > 
> >  "mindist" will always be 80 -- there is no code shown below that ever
> > changes it (so the above assignment can be put before the "while"
> > statement). That means your us_dist() function must somewhere return a
> > value greater than 80.
> > 
> > >bwd()
> > >print ("backward 1x")
> > >time.sleep(2)
> > >stop()
> > >right()
> > >time.sleep(1)
> > >stop()
> > >print("right 1x")
> > >time.sleep(2)
> > 
> >  You stopped the right() call before ever doing any output
> > 
> > >stop()
> > >fwd()
> > >print("forward 2x")
> > >time.sleep(3)
> > >stop()
> > >left()
> > >time.sleep(1)
> > >print("left 1x")
> > >stop()
> > >fwd()
> > >print("forward 3x")
> > >time.sleep(2)
> > >stop()
> > > --
> > 
> >  Off-hand, I'd try to get rid of a lot of that redundancy by defining
> > functions to encapsulate your sequence... (Python 2.x syntax -- not tested)
> > 
> > 
> > (FORWARD, BACKWARD, LEFT, RIGHT) = (1, 2, 3, 4)
> > SEQUENCE = [ (BACKWARD, 2),
> > (RIGHT, 1),
> > (FORWARD, 3),
> > (LEFT, 1),
> > (FORWARD, 2) ]
> > 
> > def move(drct, dly):
> >  if drct == FORWARD:
> >   fwd()
> >   print "Forward"
> >  elif drct == BACKWARD:
> >   bwd()
> >   print "Backward"
> >  elif drct == LEFT:
> >   left()
> >   print "Left"
> >  elif drct == RIGHT:
> >   right()
> >   print "Right"
> >  else:
> >   print "Invalid command: %s" % drct
> >  time.sleep(dly)
> >  stop()
> > 
> > notDone = True
> > servo(90)
> > mindist = 80
> > 
> > while notDone:
> >  if mindist > us_dist(15):
> >   for (dir, tm) in SEQUENCE:
> >move(dir, tm)
> > 
> > -=-=-=-=-
> > 
> >  Now, if you don't mind having to also press the  key, you could
> > use the threading module to handle the keyboard shutdown command instead of
> > using system specific modules to do raw k

Questions on Pickle and Shelve

2015-11-06 Thread Virgil Stokes

Here is snippet of Python (vers. 2.7.10) code that bothers me.

import cPickle as pickle

print "Pickle lists:"
dogs = ['Rover','King','Spot','Rufus']
cats = ['Mimi','Misty','Sasha']

with open('pickle.dat', 'wb') as pfile:
pickle.dump(dogs, pfile)
pickle.dump(cats,pfile)

del(dogs); del(cats)
with open('pickle.dat', 'rb') as pfile:
dogs = pickle.load(pfile)
cats = pickle.load(pfile)
print dogs, '\n', cats, '\n'

import shelve

# Note! __exit__ attribute undefined for shelve
sfile = shelve.open('shelve.dat')
sfile['dogs'] = dogs
sfile['cats'] = cats
sfile.close()

print "Shelve entries:"
del(cats); del(dogs)
sfile = shelve.open('shelve.dat')
#print sfile
for key in sfile.keys():
print key,' - ',sfile[key]
sfile.close()

1)  Which (the pickle or shelve code) takes less total RAM, if dogs and cats 
were very large?
2)  When the last shelve.open is given, is the entire contents of shelve.data 
transferred to RAM?  Note, if the print sfile is uncommented then the entire 
contents of shelve.data is printed out.


I was under the impression that the entire contents of a shelved file was not 
transferred to RAM when it was opened.



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


Re: Question about math.pi is mutable

2015-11-06 Thread Bartc

On 06/11/2015 02:33, wa...@travelsky.com wrote:

Hello, python-list guys:

 I am a newbie of python from Beijing. China.
 I have a question about "math.pi".
 As you can see in the attachment, why i can modify "math.pi"?
 (in "mathmodule.c" "pi" is a "static const double")


Python isn't C.

Your attachment isn't visible, but it can be demonstrated easily:

import math

math.pi=0

print (math.pi)

In Python, presumably 'pi' is just another variable, and variables can 
be written to.


(Perhaps math.pi would be better off as a function.)

--
Bartc

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


Re: Question about math.pi is mutable

2015-11-06 Thread Marko Rauhamaa
Chris Angelico :

> Simply because, in Python, virtually everything can be changed. You're
> welcome to go in and say "math.pi = 3" if you like... and then you
> accept the consequences of that.

How far cosmology would have evolved by now if Albert Einstein had had
Python at his disposal. He could simply have been able to experiment
with different values of the Cosmological Constant and seen the effects
around him in the room.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Puzzled

2015-11-06 Thread Gene Heskett
On Thursday 05 November 2015 19:04:35 Robinson, Wendy wrote:

> Hmmm... fair enough.  I sent the traceback though, on Monday.

If you sent a traceback on Monday, it wasn't seen by this list.
Do not 'attach' it to the message, but include it as the list server 
might have stripped an attachment.

> I'll give the intro a read again.  I've probably missed something
> basic.
>
> Wendy Robinson
> Audit Analyst
> (916) 566-4994 phone
>
>
>
> NOTICE OF CONFIDENTIALITY: This email is for the sole use of the
> intended recipient and may contain material that is confidential and
> protected by state and federal regulations.  If you are not the
> intended recipient please immediately delete it and contact the
> sender.

This is a public list Wendy, so this has no meaning. There are those, who 
on seeing such a message, will not reply even if they could help.

> -Original Message-
> From: Laura Creighton [mailto:l...@openend.se]
> Sent: Thursday, November 05, 2015 3:11 PM
> To: Robinson, Wendy
> Cc: 'Laura Creighton'; 'python-list@python.org'; l...@openend.se
> Subject: Re: Puzzled
>
> In a message of Thu, 05 Nov 2015 12:48:11 -0800, "Robinson, Wendy" 
writes:
> >Well... I still can't get this to work. I guess I'll just uninstall
> > it. It's a bummer that there's no help on basic startup like this.
> >
> >Wendy Robinson
> >Audit Analyst
> >(916) 566-4994 phone
>
> There is enormous amount of help available.  But we need to know more
> about what your problem is, and how it presents itself before we can
> start tracking down what your problem is, which is why I wanted a
> traceback.
>
> >>Hi there,
> >>I installed Python 3.5.0 64-bit for Windows yesterday and tried some
> >> basic programs successfully. This morning I rebooted my computer
> >> and can't get a single one to work.  The interpreter seems to be
> >> fine and the environment variables look correct.  But every py file
> >> I try to run at the >>> prompt gives me a NameError.
>
> See, this is where your problem is. There is a conceptual problem in
> understanding what you meant by 'tried some basic programs
> successfully' versus 'running py files at the >>> prompt'.
>
> Either you didn't use the Python console -- the thing that is showing
> you the '>>>' yesterday, and thus the programs that were working
> yesterday are now working every bit as well as they did then, and your
> problem is that you do not know how to use the python console.
>
> Or you did use the console before, and they worked there, and now you
> have NameErrors.
>
> I think the problem is the first sort.
> I think that you opened up the python console and then typed in
> something like 'myprogram.py' expecting the console to run the
> myprogram.  Instead you got something like this:
>
> Python 3.5.0rc1 (default, Aug 12 2015, 14:57:46) [GCC 5.2.1 20150808]
> on linux Type "help", "copyright", "credits" or "license" for more
> information.
>
>  >>> myprogram.py
>
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'myprogram' is not defined  >>>
>
> If this is what happened then your python is fine.  You just do not
> know how the interactive console works.  It doesn't run files like
> this.
>
> See:https://docs.python.org/3.5/tutorial/introduction.html
>
> You type code at the console and get responses back.
>
> If, on the other hand, this is not your problem, then we need a
> traceback --- and what I posted above was a traceback -- so that we
> can see what caused the NameError.
>
> Laura


Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unbuffered stderr in Python 3

2015-11-06 Thread srinivas devaki
On Mon, Nov 2, 2015 at 1:22 PM, Steven D'Aprano
 wrote:
>
> So how come Python 3 has line buffered stderr? And more importantly, how can
> I turn buffering off?
>
> I don't want to use the -u unbuffered command line switch, because that
> effects stdout as well. I'm happy for stdout to remain buffered.
>
you can simply turn buffering off for stderr by redefining the print
function or declaring a new print function like


from functools import partial
print = partial(print, flush=True)
# or
from functools import partial
import sys
printerr = partial(print, flush=True, file=sys.stderr)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Puzzled

2015-11-06 Thread Chris Gonnerman

Wendy said:

I installed Python 3.5.0 64-bit for Windows yesterday and tried some basic 
programs successfully.
This morning I rebooted my computer and can't get a single one to work.  The interpreter 
seems to be fine and the environment variables look correct.  But every py file I try to 
run at the >>> prompt gives me a NameError.
But that's not how the Python interpreter works.  You say you are trying 
to run "py files" at the >>> prompt.  If what you are doing is this:


>>> test.py

Well, no, that's not going to work.  If you want to run "test.py" as a 
script, from the CMD prompt you type:


python test.py

If test.py is a module meant to be imported, then from the Python prompt 
you do this:


import test

Hope this helps.

-- Chris.

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


Re: What does ???grep??? stand for?

2015-11-06 Thread Grant Edwards
On 2015-11-06, Dennis Lee Bieber  wrote:
> On Thu, 5 Nov 2015 20:19:39 + (UTC), Grant Edwards
> declaimed the following:
>
>>Though I used a line-editor for a while on VMS, I was never very good
>>at it, and abanded it for a full-screen editor at he first
>>opportunity.  But, if you ever get a chance to watching somebody who
>>_is_ good at 'ed', it's something you'll remember...
>
>   I didn't convert to EDT until DEC dropped SOS...

Yes! Son of Stopgap!  I had completely forgotten the name...  And then
I think Eve came after EDT.  That was about where I switched to Unix.

--
Grant

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


Re: What does “grep” stand for?

2015-11-06 Thread William Ray Wing

> On Nov 5, 2015, at 10:36 PM, Larry Hudson via Python-list 
>  wrote:
> 
> On 11/05/2015 05:18 PM, Dennis Lee Bieber wrote:
>> On Thu, 5 Nov 2015 20:19:39 + (UTC), Grant Edwards
>>  declaimed the following:
>> 
>>> Though I used a line-editor for a while on VMS, I was never very good
>>> at it, and abanded it for a full-screen editor at he first
>>> opportunity.  But, if you ever get a chance to watching somebody who
>>> _is_ good at 'ed', it's something you'll remember...
>> 
>>  I didn't convert to EDT until DEC dropped SOS... And then shortly later
>> I keymapped the Blaise ([Alcor] Pascal) editor on the TRS-80 Mod-III to
>> replicate EDT (as much as possible, given only three function keys on the
>> numeric pad)
>> 
>>  The Amiga used to have two standard editors -- a screen editor and a
>> line editor; as I recall the line editor supported a file window, so one
>> could edit large files by making a single direction pass using a smaller
>> window and a script. Later the screen editor gained ARexx support, so one
>> could script it using ARexx. (And by then they also included a form of
>> microEMACS, my C compiler had a look-alike vi editor... and a later C
>> compiler had another editor integrated to the compiler so that error
>> message reports could trigger the editor to open the file and move to the
>> error position)
>> 
> Anyone besides me remember the CP/M editor Mince (Mince Is Not Complete 
> EMACS)?
> It was an emacs-like editor, without any e-Lisp or other way of extending it. 
>  I believe it was my first exposure to a screen-oriented editor.  I quite 
> liked it at that time (but that was a looonnng time ago!)
> 
> -=- Larry -=-
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

You’re not REALLY an old timer unless you’ve used TECO.

-Bill

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


Re: argparse: use of double dash to separate options and positional arguments

2015-11-06 Thread Peter Otten
Amit Ramon wrote:

> Peter Otten <__pete...@web.de> [2015-11-06 11:57 +0100]:
> 
> 
>>>
>>> For example, with the above code
>>>
>>> my_prog -v hello world
>>>
>>> works well, but
>>>
>>> my_prog -v -x hello world
>>>
>>> Fails with an error message 'error: unrecognized arguments: -x'.
>>
>>This looks like a bug to me. Please report it on bug.python.org.
> 
> Why does it looks like a bug? To me it seems okay - argparse expects
> that an argument that starts with '-' is an option, and it also expects
> to be told about all possible options, so it complains on
> encountering an unrecognized 'option'. This is why a special delimiter
> is needed to mark the 'end of options'.
> 
> 
>>
>>> If I invoke the program with a '--' at the end of the options (as I
>>> understand is a common standard and a POSIX recommendation), as in:
>>>
>>> my_prog -v -- -x hello world
>>>
>>> It works well again.
>>>
>>> However, a few questions remain:
>>>
>>> Firstly, as far as I can tell the use of '--' is not documented in the
>>> argparse documentation (but the code of argparse clearly shows that it
>>> is a feature).
>>>
>>> Secondly, when using '--', this string itself is inserted into the
>>> list of the collected positional arguments (in the above example in
>>> the cmd_args variable):
>>>
>>> $ ./my_prog -v -- -x hello world
>>> Namespace(cmd_args=['--', '-x', 'hello', 'world'], verbose=True)
>>>
>>> It's quiet easy to check for it and remove it if it exists, but it
>>> still seems like it shouldn't be there - it is not really an argument,
>>> just a delimiter.
>>
>>I'm not sure about this one; one purpose of REMAINDER is to pass on the
>>unprocessed arguments to another program/script, and this might follow the
>>same convention. Should
>>
>>parser.add_argument('-v', '--verbose', action='store_true')
>>parser.add_argument('cmd_args', nargs=argparse.REMAINDER)
>>args = parser.parse_args()
>>subprocess.call(["rm"] + args.cmd_args)
>>
>>$ my_prog -v -- -r foo
>>
>>attempt to delete two files "-r" and "foo" or remove the "foo" directory?
>>The first is the safer alternative, and as you say stripping the "--" is
>>easy.
> 
> I'm using the REMAINDER exactly for passing on arguments to another
> program, as in your example. I would expect that everything after
> the '--' should be passed on as is - it should be up to the other
> program to decide what to do with the arguments it receives (So in
> your examples, rm would actually try to remove the "foo" directory).
> 
> And although stripping the '--' is easy, why should the user of
> argparse need to handle it? Still unclear to me.

My interpretation was that REMAINDER should give you the rest of the 
commandline args, no matter what special meaning these args might have for 
argparse.

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


Modernizing IDLE

2015-11-06 Thread Mark Roseman
Wanted to pass along a case study of some work being done to improve the look 
and feel of IDLE. This is a work-in-progress, gradually being integrated into 
the Python codebase. Given that, it's a great opportunity to get involved, 
provide some feedback, and make it even better!

http://www.tkdocs.com/tutorial/idle.html

As you can tell from the URL, it's part of a broader tutorial on modernizing 
the appearance of Tkinter based programs.

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


Re: Question about math.pi is mutable

2015-11-06 Thread Lorenzo Sutton



On 06/11/2015 13:30, Bartc wrote:

On 06/11/2015 02:33, wa...@travelsky.com wrote:

Hello, python-list guys:

 I am a newbie of python from Beijing. China.
 I have a question about "math.pi".
 As you can see in the attachment, why i can modify "math.pi"?
 (in "mathmodule.c" "pi" is a "static const double")


Python isn't C.

Your attachment isn't visible, but it can be demonstrated easily:

import math

math.pi=0

print (math.pi)

In Python, presumably 'pi' is just another variable, and variables can
be written to.

(Perhaps math.pi would be better off as a function.)


Still nothing stops you from doing:

math.sin = 0

If you really want to?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Questions on Pickle and Shelve

2015-11-06 Thread Chris Warrick
On 6 November 2015 at 12:53, Virgil Stokes  wrote:
> Here is snippet of Python (vers. 2.7.10) code that bothers me.
>
> [snip bad code]
>
> 1)  Which (the pickle or shelve code) takes less total RAM, if dogs and cats
> were very large?
> 2)  When the last shelve.open is given, is the entire contents of
> shelve.data transferred to RAM?  Note, if the print sfile is uncommented
> then the entire contents of shelve.data is printed out.
>
> I was under the impression that the entire contents of a shelved file was
> not transferred to RAM when it was opened.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

1) That does not matter. I do know that shelve files can grow larger
over time though.
2) Shelve files are pickles in disguise. Which means they need to be
loaded into memory, executing *arbitrary code*.

Here’s a question for you:
3) Why are you using either? Both are unsafe and can lead to issues if
you take untrusted files. Use JSON.

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Questions on Pickle and Shelve

2015-11-06 Thread Peter Otten
Virgil Stokes wrote:

> Here is snippet of Python (vers. 2.7.10) code that bothers me.
> 
> import cPickle as pickle
> 
> print "Pickle lists:"
> dogs = ['Rover','King','Spot','Rufus']
> cats = ['Mimi','Misty','Sasha']
> 
> with open('pickle.dat', 'wb') as pfile:
>  pickle.dump(dogs, pfile)
>  pickle.dump(cats,pfile)
> 
> del(dogs); del(cats)
> with open('pickle.dat', 'rb') as pfile:
>  dogs = pickle.load(pfile)
>  cats = pickle.load(pfile)
>  print dogs, '\n', cats, '\n'
> 
> import shelve
> 
> # Note! __exit__ attribute undefined for shelve
> sfile = shelve.open('shelve.dat')
> sfile['dogs'] = dogs
> sfile['cats'] = cats
> sfile.close()
> 
> print "Shelve entries:"
> del(cats); del(dogs)
> sfile = shelve.open('shelve.dat')
> #print sfile
> for key in sfile.keys():
>  print key,' - ',sfile[key]
> sfile.close()
> 
> 1)  Which (the pickle or shelve code) takes less total RAM, if dogs and
> cats were very large?

I think this is the wrong question. shelve is built on top of a key-value 
store. It can hold more cats and dogs than fit into memory, and lookup of a 
cat or dog should be efficient when you store one animal per key:

db = shelve.open(...)
db["Rover"] = Dog(...)
db["King"] =  Dog(...)
db["Misty"] = Cat(...)

If you put all dogs in a big list to store them in the shelve and there are 
only a few such lists there is no advantage over plain pickle.

> 2)  When the last shelve.open is given, is the entire contents of
> shelve.data
> transferred to RAM?  Note, if the print sfile is uncommented then the
> entire contents of shelve.data is printed out.

That is due to a careless implementation. Lookup is good, but everything 
else will only work for debugging, with small data samples.

> I was under the impression that the entire contents of a shelved file was
> not transferred to RAM when it was opened.

They aren't. The details vary depending on what database is used.

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


Re: Question about math.pi is mutable

2015-11-06 Thread Bartc

On 06/11/2015 16:12, Lorenzo Sutton wrote:



On 06/11/2015 13:30, Bartc wrote:

On 06/11/2015 02:33, wa...@travelsky.com wrote:

Hello, python-list guys:

 I am a newbie of python from Beijing. China.
 I have a question about "math.pi".
 As you can see in the attachment, why i can modify "math.pi"?
 (in "mathmodule.c" "pi" is a "static const double")


Python isn't C.

Your attachment isn't visible, but it can be demonstrated easily:

import math

math.pi=0

print (math.pi)

In Python, presumably 'pi' is just another variable, and variables can
be written to.

(Perhaps math.pi would be better off as a function.)


Still nothing stops you from doing:

math.sin = 0

If you really want to?


Well, you might notice something is wrong when you try and do math.sin(x)!

But I see your point. Even a function can be set to another function, or 
to one that returns a nonsense value.


Is there no way then in Python to declare:

   pi = 3.141519 # etc

and make it impossible to override?

--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list


Re: Question about math.pi is mutable

2015-11-06 Thread Chris Angelico
On Sat, Nov 7, 2015 at 6:30 AM, Bartc  wrote:
> Is there no way then in Python to declare:
>
>pi = 3.141519 # etc
>
> and make it impossible to override?

Nope. Even in C++, where classes can define certain things as const,
private, and other such restrictions, you can always get around them
by manipulating pointers appropriately. In Python, there's a
*convention* that a leading underscore means "private", but the
language doesn't enforce anything about it.

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


Re: Regular expressions

2015-11-06 Thread rurpy--- via Python-list
On 11/05/2015 01:18 AM, Christian Gollwitzer wrote:
> Am 05.11.15 um 06:59 schrieb rurpy:
>>> Can you call yourself a well-rounded programmer without at least
>>> a basic understanding of some regex library? Well, probably not.
>>> But that's part of the problem with regexes. They have, to some
>>> degree, driven out potentially better -- or at least differently
>>> bad -- pattern matching solutions, such as (E)BNF grammars,
>>> SNOBOL pattern matching, or lowly globbing patterns. Or even
>>> alternative idioms, like Hypercard's "chunking" idioms.
>> 
>> Hmm, very good point.  I wonder why all those "potentially better" 
>> solutions have not been more widely adopted?  A conspiracy by a 
>> secret regex cabal?
> 
> I'm mostly on the pro-side of the regex discussion, but this IS a
> valid point. regexes are not always a good way to express a pattern,
> even if the pattern is regular. The point is, that you can't build
> them up easily piece-by-piece. Say, you want a regex like "first an
> international phone number, then a name, then a second phone number"
> - you will have to *repeat* the pattern for phone number twice. In
> more complex cases this can become a nightmare, like the monster that
> was mentioned before to validate an email.
> 
> A better alternative, then, is PEG for example. You can easily write
> [...]

That is the solution adopted by Perl 6. I have always thought lexing
and parsing solutions for Python were a weak spot in the Python eco-
system and I was about to write that I would love to see a PEG parser
for python when I saw this:

http://fdik.org/pyPEG/

Unfortunately it suffers from the same problem that Pyparsing, Ply
and the rest suffer from: they use Python syntax to express the
parsing rules rather than using a dedicated problem-specific syntax
such as you used to illustrate peg parsing:

> pattern <- phone_number name phone_number phone_number <- '+' [0-9]+
> ( '-' [0-9]+ )* name <-  [[:alpha:]]+

Some here have complained about excessive brevity of regexs but I
much prefer using problem-specific syntax like "(a*)" to having to
express a pattern using python with something like

star = RegexMatchAny()
a_group = RegexGroup('a' + star)
...

and I don't want to have to do something similar with PEG (or Ply
or Pyparsing) to formulate their rules.

>[...]
> As a 12 year old, not knowing anything about pattern recognition, but
> thinking I was the king, as is usual for boys in that age, I sat down
> and manually constructed a recursive descent parser in a BASIC like
> language. It had 1000 lines and took me a few weeks to get it
> correct. Finally the solution was accepted as working, but my
> participation was rejected because the solutions lacked
> documentation. 16 years later I used the problem for a course on
> string processing (that's what the PDF is for), and asked the
> students to solve it using regexes. My own solution consists of 67
> characters, and it took me5 minutes to write it down.
> 
> Admittedly, this problem is constructed, but solving similar tasks by
> regexes is still something that I need to do on a daily basis, when I
> get data from other scientists in odd formats and I need to
> preprocess them. I know people who use a spreadsheet and copy/paste
> millions of datapoints manually becasue they lack the knowledge of
> using such tools.

I think in many cases those most hostile to regexes are the also
those who use them (or need to use them) the least. While my use
of regexes are limited to fairly simple ones they are complicated
enough that I'm sure it would take orders of magnitude longer
to get the same effect in python.
-- 
https://mail.python.org/mailman/listinfo/python-list


PIL module for 64bit Python 2.7

2015-11-06 Thread Jahn
Can anyone lat me know where I can download PIL module for 64bit Python 2.7 ?
 I found for 32 bit  Python 2.7 only  and the installation ended with an error 
that the 
Python 2.7 was not found in registers.
Thank you



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: Question about math.pi is mutable

2015-11-06 Thread Christian Gollwitzer

Am 06.11.15 um 20:40 schrieb Chris Angelico:

On Sat, Nov 7, 2015 at 6:30 AM, Bartc  wrote:

Is there no way then in Python to declare:

pi = 3.141519 # etc

and make it impossible to override?


Nope. Even in C++, where classes can define certain things as const,
private, and other such restrictions, you can always get around them
by manipulating pointers appropriately.


No, that is not right. If you cast away the constness from a pointer to 
a constant, you can technically write to that memory, but the behaviour 
is undefined - another way of saying that the program is illegal.


In many cases, the compiler will inline the constant - because you 
promised, that it can't change - and the update to the constant will not 
change in all parts of the program:



apfelkiste:Tests chris$ cat constub.cpp
#include 

void call_by_ref(const double &v) {
std::cout<<"In function: v="<(&pi);
*errptr= 0.0;
std::cout<<"Now pi is "

Re: PIL module for 64bit Python 2.7

2015-11-06 Thread Stéphane Wirtel
You can install Pillow, the API is the same.

and normally will compile for your architecture.
On 6 Nov 2015, at 14:55, Jahn wrote:

> Can anyone lat me know where I can download PIL module for 64bit Python 2.7 ?
> I found for 32 bit  Python 2.7 only  and the installation ended with an error 
> that the
> Python 2.7 was not found in registers.
> Thank you
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> -- 
> https://mail.python.org/mailman/listinfo/python-list


--
Stéphane Wirtel - http://wirtel.be - @matrixise

signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Olivier Adret

2015-11-06 Thread Karim



On 06/11/2015 11:34, Chris Angelico wrote:

On Fri, Nov 6, 2015 at 2:24 AM, olivier  wrote:

  Je vais essayer de programmer en python. On verra bien !

Hello Olivier!

This is a mostly English language mailing list/newsgroup, and there
aren't many people who are fluent in French. There is, however, a
corresponding French newsgroup, fr.comp.lang.python; you may find that
you're more comfortable communicating there.

My apologies for not responding in French, but I'm not very familiar
with it, and all I would do is put my text through an online
translation tool.

Chris Angelico
Comme dit Chris, cette mailing liste est en anglais et tu peux aller sur 
le news group fr.comp.lang.python
pour du support en français. Mais je suppose que tu avais compris mais 
au cas où.


Cordialement
Karim
--
https://mail.python.org/mailman/listinfo/python-list


Re: Regular expressions

2015-11-06 Thread Christian Gollwitzer

Am 06.11.15 um 20:52 schrieb ru...@yahoo.com:

I have always thought lexing
and parsing solutions for Python were a weak spot in the Python eco-
system and I was about to write that I would love to see a PEG parser
for python when I saw this:

http://fdik.org/pyPEG/

Unfortunately it suffers from the same problem that Pyparsing, Ply
and the rest suffer from: they use Python syntax to express the
parsing rules rather than using a dedicated problem-specific syntax
such as you used to illustrate peg parsing:


pattern <- phone_number name phone_number

>> phone_number <- '+' [0-9]+ ( '-' [0-9]+ )*
>> name <-  [[:alpha:]]+

That is actually real syntax of a parser generator used by me for 
another language (Tcl). A calculator example using this package can be 
found here: http://wiki.tcl.tk/39011

(actually it is a retargetable compiler in a few lines - very impressive)

And exactly as you say, it is working well exactly because it doesn't 
try to abuse function composition in the frontend to construct the parser.


Looking through the parser generators listed at 
http://bford.info/packrat/ it seems that waxeye could be interesting 
http://waxeye.org/manual.html#_using_waxeye - however I'm not sure the 
Python backend works with Python 3, maybe there will be unicode issues. 
Another bonus would be a compilable backend, like Cython or similar. The 
pt package mentioned above allows to generate a C module with an 
interface for Tcl. Compiled parsers are approximately 100x faster. I 
would expect a similar speedup for Python parsers.



Some here have complained about excessive brevity of regexs but I
much prefer using problem-specific syntax like "(a*)" to having to
express a pattern using python with something like

star = RegexMatchAny()
a_group = RegexGroup('a' + star)
...


Yeah that is nonsense. Mechanical verbosity never leads to clarity (XML 
anyone?)



I think in many cases those most hostile to regexes are the also
those who use them (or need to use them) the least. While my use
of regexes are limited to fairly simple ones they are complicated
enough that I'm sure it would take orders of magnitude longer
to get the same effect in python.


That's also my impression. The "two problems quote" was lame already for 
the first time. If you are satisfied with simple string functions, then 
either you do not have problems where you need regexps/other formal 
parsing tools, or you are very masochistic.


Christian
--
https://mail.python.org/mailman/listinfo/python-list


Re: Regular expressions

2015-11-06 Thread Larry Martell
On Fri, Nov 6, 2015 at 3:36 PM, Christian Gollwitzer  wrote:
> Am 06.11.15 um 20:52 schrieb ru...@yahoo.com:
>>
>> I have always thought lexing
>> and parsing solutions for Python were a weak spot in the Python eco-
>> system and I was about to write that I would love to see a PEG parser
>> for python when I saw this:
>>
>> http://fdik.org/pyPEG/
>>
>> Unfortunately it suffers from the same problem that Pyparsing, Ply
>> and the rest suffer from: they use Python syntax to express the
>> parsing rules rather than using a dedicated problem-specific syntax
>> such as you used to illustrate peg parsing:
>>
>>> pattern <- phone_number name phone_number
>
>>> phone_number <- '+' [0-9]+ ( '-' [0-9]+ )*
>>> name <-  [[:alpha:]]+
>
> That is actually real syntax of a parser generator used by me for another
> language (Tcl). A calculator example using this package can be found here:
> http://wiki.tcl.tk/39011
> (actually it is a retargetable compiler in a few lines - very impressive)

Ah, Tcl - I wrote many a Tcl script back in the 80s to login to BBSs.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regular expressions

2015-11-06 Thread rurpy--- via Python-list
On Thursday, November 5, 2015 at 8:12:22 AM UTC-7, Seymore4Head wrote:
> On Thu, 05 Nov 2015 11:54:20 +1100, Steven D'Aprano  
> wrote:
> >On Thu, 5 Nov 2015 10:02 am, Seymore4Head wrote:
> >> So far the only use I have for regex is to replace slicing, but I
> >> think it is an improvement.
> >
> >I don't understand this. This is like saying "so far the only use I have for
> >a sandwich press is to replace my coffee pot". Regular expressions and
> >slicing do very different things.
> >[...]
> 
> Here is an example of the text we are slicing apart.
> 
>[...email headers...]
>
> The practice problems are something like pull out all the email
> addresses or pull out the days of the week and give the most common.

Yes, that is a perfectly appropriate use of regexes.

As Steven mentioned though, the term "slicing" is also used with a 
very specific and different meaning in Python, specifically referring
to a part of a list using a syntax like "alist[a:b]".  I can't seem
to get to python.org at the moment but if you look in the Python
docs index under "slicing" you'll find more info.
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PIL module for 64bit Python 2.7

2015-11-06 Thread Laura Creighton
In a message of Fri, 06 Nov 2015 20:55:34 +0100, "Jahn" writes:
>Can anyone lat me know where I can download PIL module for 64bit Python 2.7 ?
> I found for 32 bit  Python 2.7 only  and the installation ended with an error 
> that the 
>Python 2.7 was not found in registers.
>Thank you

The Modern Fork of PIL is Pillow.
hhttps://pypi.python.org/pypi/Pillow/3.0.0

Laura 

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


Re: PIL module for 64bit Python 2.7

2015-11-06 Thread Stéphane Wirtel
Really strange, I have sent the same answer, there is one hour. Did you receive 
it ?

I am not but maybe I have a problem with my email.
On 6 Nov 2015, at 16:37, Laura Creighton wrote:

> In a message of Fri, 06 Nov 2015 20:55:34 +0100, "Jahn" writes:
>> Can anyone lat me know where I can download PIL module for 64bit Python 2.7 ?
>> I found for 32 bit  Python 2.7 only  and the installation ended with an 
>> error that the
>> Python 2.7 was not found in registers.
>> Thank you
>
> The Modern Fork of PIL is Pillow.
> hhttps://pypi.python.org/pypi/Pillow/3.0.0
>
> Laura
>
> -- 
> https://mail.python.org/mailman/listinfo/python-list


--
Stéphane Wirtel - http://wirtel.be - @matrixise

signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: argparse: use of double dash to separate options and positional arguments

2015-11-06 Thread Random832
Peter Otten <__pete...@web.de> writes:

> I'm not sure about this one; one purpose of REMAINDER is to pass on the 
> unprocessed arguments to another program/script, and this might follow the 
> same convention. Should
>
> parser.add_argument('-v', '--verbose', action='store_true')
> parser.add_argument('cmd_args', nargs=argparse.REMAINDER)
> args = parser.parse_args()
> subprocess.call(["rm"] + args.cmd_args)
>
> $ my_prog -v -- -r foo
>
> attempt to delete two files "-r" and "foo" or remove the "foo" directory? 
> The first is the safer alternative, and as you say stripping the "--" is 
> easy.

I think it should be the second. If the caller wants it to be treated as
a list of files rather than a list of arguments, it should be using
subprocess.call(["rm", "--"] + args.cmd_args).

The purpose is, as you said, to pass the *unprocessed* argument. -- has
been processed by being interpreted as a terminator for the argument
list.

I have a script (it's a shell script, not a python script) where I
actually do something similar... it does some setup, then calls ssh. If
I want to pass some options directly to ssh, I call it as:
"scriptname -script-option -- -ssh-option remote-command"


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


Scipy odeint (LSODA) gives inaccurate results; same code fine in MATLAB ode15s/ode23s

2015-11-06 Thread Abhishek
I have code that runs perfectly well in MATLAB (using ode15s or ode23s) but 
falters with Scipy odeint. The MATLAB code is for a specific case of the 
generalized Python code. Here I have tried to reproduce the specific case in 
Python. The logic in the code is airtight and the algorithm is sound. I have 
also specified small rtol and atol values, as well as a large mxstep. 

My code is below:

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint

#Constants and parameters
N = 2
K00 = np.logspace(0,3,101,10)
len1 = len(K00)
epsilon = 0.01
y0 = [0]*(3*N/2+3)
u1 = 0
u2 = 0
u3 = 0
Kplot = np.zeros((len1,1))
Pplot = np.zeros((len1,1))
S = [np.zeros((len1,1)) for  in range(N/2+1)]
KS = [np.zeros((len1,1)) for  in range(N/2+1)]
PS = [np.zeros((len1,1)) for  in range(N/2+1)]
Splot = [np.zeros((len1,1)) for  in range(N/2+1)]
KSplot = [np.zeros((len1,1)) for  in range(N/2+1)]
PSplot = [np.zeros((len1,1)) for  in range(N/2+1)]

for series in range(0,len1):
K0 = K00[series]
Q = 10
r1 = 0.0001
r2 = 0.001
a = 0.001
d = 0.001
k = 0.999
S10 = 1e5
P0 = 1
tfvec = np.tile(1e10,(1,5))
tf = tfvec[0,0]
time = np.linspace(0,tf,len1)

#Defining dy/dt's
def f(y,t):
for alpha in range(0,(N/2+1)):
S[alpha] = y[alpha]
for beta in range((N/2)+1,N+1):
KS[beta-N/2-1] = y[beta]
for gamma in range(N+1,3*N/2+1):
PS[gamma-N] = y[gamma]
K = y[3*N/2+1]
P = y[3*N/2+2]

# The model equations
ydot = np.zeros((3*N/2+3,1))
B = range((N/2)+1,N+1)
G = range(N+1,3*N/2+1)
runsumPS = 0
runsum1 = 0
runsumKS = 0
runsum2 = 0

for m in range(0,N/2):
runsumPS = runsumPS + PS[m+1]
runsum1 = runsum1 + S[m+1]
runsumKS = runsumKS + KS[m]
runsum2 = runsum2 + S[m]
ydot[B[m]] = a*K*S[m]-(d+k+r1)*KS[m]

for i in range(0,N/2-1):
ydot[G[i]] = a*P*S[i+1]-(d+k+r1)*PS[i+1]

for p in range(1,N/2):
ydot[p] = -S[p]*(r1+a*K+a*P)+k*KS[p-1]+ \
  d*(PS[p]+KS[p])

ydot[0] = Q-(r1+a*K)*S[0]+d*KS[0]+k*runsumPS
ydot[N/2] = k*KS[N/2-1]-(r2+a*P)*S[N/2]+ \
d*PS[N/2]
ydot[G[N/2-1]] = a*P*S[N/2]-(d+k+r2)*PS[N/2]
ydot[3*N/2+1] = (d+k+r1)*runsumKS-a*K*runsum2
ydot[3*N/2+2] = (d+k+r1)*(runsumPS-PS[N/2])- \
a*P*runsum1+(d+k+r2)*PS[N/2]

ydot_new = []
for j in range(0,3*N/2+3):
ydot_new.extend(ydot[j])
return ydot_new

# Initial conditions
y0[0] = S10
for i in range(1,3*N/2+1):
y0[i] = 0
y0[3*N/2+1] = K0
y0[3*N/2+2] = P0

# Solve the DEs
soln = odeint(f,y0,time,rtol = 1e-12, atol = 1e-14, mxstep = 5000)
for alpha in range(0,(N/2+1)):
S[alpha] = soln[:,alpha]
for beta in range((N/2)+1,N+1):
KS[beta-N/2-1] = soln[:,beta]
for gamma in range(N+1,3*N/2+1):
PS[gamma-N] = soln[:,gamma]

for alpha in range(0,(N/2+1)):
Splot[alpha][series] = soln[len1-1,alpha]
for beta in range((N/2)+1,N+1):
KSplot[beta-N/2-1][series] = soln[len1-1,beta]
for gamma in range(N+1,3*N/2+1):
PSplot[gamma-N][series] = soln[len1-1,gamma]

for alpha in range(0,(N/2+1)):
u1 = u1 + Splot[alpha]
for beta in range((N/2)+1,N+1):
u2 = u2 + KSplot[beta-N/2-1]
for gamma in range(N+1,3*N/2+1):
u3 = u3 + PSplot[gamma-N]

K = soln[:,3*N/2+1]
P = soln[:,3*N/2+2]
Kplot[series] = soln[len1-1,3*N/2+1]
Pplot[series] = soln[len1-1,3*N/2+2]
utot = u1+u2+u3

#Plot
plt.plot(np.log10(K00),utot[:,0])
plt.show()

Why am I getting a "stiff-looking" graph in Python 
(http://i.stack.imgur.com/UGWSH.png), when MATLAB gives me a proper one 
(http://i.stack.imgur.com/F2jzd.jpg)? I would like to understand where the 
problem lies and how to solve it.

Thanks in advance for any help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about math.pi is mutable

2015-11-06 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote:

> On Sat, Nov 7, 2015 at 6:30 AM, Bartc  wrote:
>> Is there no way then in Python to declare:
>>
>>pi = 3.141519 # etc
>>
>> and make it impossible to override?
> 
> Nope. Even in C++, where classes can define certain things as const,
> private, and other such restrictions, you can always get around them
> by manipulating pointers appropriately. In Python, there's a
> *convention* that a leading underscore means "private", but the
> language doesn't enforce anything about it.

It is certainly possible for attributes of (instances of) new-style classes 
(starting with Python 3.2 at the latest) to be read-only by declaring them a 
property that does not have a setter, or one that has a setter that throws a 
specific exception (here: the former):

#--
class SafeMath(object):
def __init__ (self):
from math import pi
self._pi = pi

@property
def pi (self):
return self._pi

#--

| >>> math = SafeMath()
| >>> math.pi
| 3.141592653589793
| >>> math.pi = 42
| Traceback (most recent call last):
|   File "", line 1, in 
| AttributeError: can't set attribute

(Or you can use “pi = property(…)” within the class declaration.)

In theory, it should be possible to substitute “math” with a reference to an 
object that acts as a proxy for the original “math” module object but whose 
base class declares the attributes for all the constants read-only.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about math.pi is mutable

2015-11-06 Thread Thomas 'PointedEars' Lahn
Bartc wrote:
^
Please fix.

> On 06/11/2015 02:33, wa...@travelsky.com wrote:
>>  As you can see in the attachment, why i can modify "math.pi"?
>>  (in "mathmodule.c" "pi" is a "static const double")
> 
> Python isn't C.
> 
> Your attachment isn't visible, but it can be demonstrated easily:
> 
> import math
> 
> math.pi=0
> 
> print (math.pi)
> 
> In Python, presumably 'pi' is just another variable, and variables can
> be written to.

“pi” is the name of an attribute of the module object referred to by “math”.
 
> (Perhaps math.pi would be better off as a function.)

Perhaps not.  Calling a function includes an overhead that one does not want 
in already costly floating-point calculations.

In my opinion, mathematical constants should be implemented as constants 
(non-overwritable, non-deletable, throwing exceptions when attempting to do 
either) but apparently the authors of math.py disagree.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Script to extract text from PDF files

2015-11-06 Thread Scott Werner
On Tuesday, September 25, 2007 at 1:41:56 PM UTC-4, brad wrote:
> I have a very crude Python script that extracts text from some (and I 
> emphasize some) PDF documents. On many PDF docs, I cannot extract text, 
> but this is because I'm doing something wrong. The PDF spec is large and 
> complex and there are various ways in which to store and encode text. I 
> wanted to post here and ask if anyone is interested in helping make the 
> script better which means it should accurately extract text from most 
> any pdf file... not just some.
> 
> I know the topic of reading/extracting the text from a PDF document 
> natively in Python comes up every now and then on comp.lang.python... 
> I've posted about it in the past myself. After searching for other 
> solutions, I've resorted to attempting this on my own in my spare time. 
> Using apps external to Python (pdftotext, etc.) is not really an option 
> for me. If someone knows of a free native Python app that does this now, 
> let me know and I'll use that instead!
> 
> So, if other more experienced programmer are interested in helping make 
> the script better, please let me know. I can host a website and the 
> latest revision and do all of the grunt work.
> 
> Thanks,
> 
> Brad

As mentioned before, extracting plain text from a PDF document can be hit or 
miss. I have tried all the following applications (free/open source) on Arch 
Linux. Note, I would execute the commands with subprocess and capture stdout or 
read plain text file created by the application.

* textract (uses pdftotext)
- https://github.com/deanmalmgren/textract

* pdftotext 
- http://poppler.freedesktop.org/
- cmd: pdftotext -layout "/path/to/document.pdf" -
- cmd: pdftotext "/path/to/document.pdf" -

* Calibre
- http://calibre-ebook.com/
- cmd: ebook-convert "/path/to/document.pdf" "/path/to/plain.txt" 
--no-chapters-in-toc

* AbiWord
- http://www.abiword.org/
- cmd: abiword --to-name=fd://1 --to-TXT "/path/to/document.pdf"

* Apache Tika
- https://tika.apache.org/
- cmd: "/usr/bin/java" -jar "/path/to/standalone/tika-app-1.10.jar" --text-main 
"/path/to/document.pdf"

For my application, I saw the best results using Apache Tika. However, I do 
still encounter strange encoding or extraction issues, e.g. S P A C E D  O U T  
H E A D E R S" and "\nBroken \nHeader\n". I ended up writing a lot of 
repairing/cleaning methods.

I welcome an improved solution that has some intelligence like comparing the 
extract plain text order to a snapshot of the pdf page using OCR.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about math.pi is mutable

2015-11-06 Thread Thomas 'PointedEars' Lahn
Thomas 'PointedEars' Lahn wrote:

> In theory, it should be possible to substitute “math” with a reference to
> an object that acts as a proxy for the original “math” module object but
> whose base class declares the attributes for all the constants read-only.

#!/usr/bin/env python3
#---

import importlib

class MyMath(object):
def getter_factory (prop):
def getter (self):
return getattr(importlib.__import__("math", globals(), locals(),
[prop], 0), prop)
return getter

pi = property(getter_factory("pi"), lambda self, val: None,
lambda self: None)
e = property(getter_factory("e"), lambda self, val: None,
lambda self: None)
inf = property(getter_factory("inf"), lambda self, val: None,
lambda self: None)
nan = property(getter_factory("nan"), lambda self, val: None,
lambda self: None)

def __getattr__ (self, name):
return getattr(importlib.__import__("math", globals(), locals(),
[name], 0), name, None)

math = MyMath()

print(math.pi, math.e, math.inf, math.nan)

math.pi = 42
math.e = 42
math.inf = 42
math.nan = 42

print(math.pi, math.e, math.inf, math.nan)
print(math.ceil(2.41))
#---

Using property() instead of decorators here was intended to achieve DRY by 
using a loop, but I could not find a way to define class attributes 
dynamically.  Suggestions?

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about math.pi is mutable

2015-11-06 Thread Terry Reedy

On 11/6/2015 5:26 PM, Thomas 'PointedEars' Lahn wrote:

Bartc wrote:



import math

math.pi=0

print (math.pi)

In Python, presumably 'pi' is just another variable, and variables can
be written to.


“pi” is the name of an attribute of the module object referred to by “math”.


(Perhaps math.pi would be better off as a function.)


Perhaps not.  Calling a function includes an overhead that one does not want
in already costly floating-point calculations.

In my opinion, mathematical constants should be implemented as constants
(non-overwritable, non-deletable, throwing exceptions when attempting to do
either) but apparently the authors of math.py disagree.


One of multiple discussions of the 'constants' idea.
bugs.python.org/issue1465406
It is mostly about speed.

--
Terry Jan Reedy


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


Re: Question about math.pi is mutable

2015-11-06 Thread Steven D'Aprano
On Sat, 7 Nov 2015 09:26 am, Thomas 'PointedEars' Lahn wrote:
^

> Bartc wrote:
> ^
> Please fix.

Why? There's nothing wrong with somebody signing their posts "Bartc". It is
no more silly than somebody calling themselves "PointedEars". Please stop
trying to enforce non-existent rules about internet identities on others.



-- 
Steven

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


Re: Question about math.pi is mutable

2015-11-06 Thread Steven D'Aprano
On Sat, 7 Nov 2015 09:19 am, Thomas 'PointedEars' Lahn wrote:

> It is certainly possible for attributes of (instances of) new-style
> classes (starting with Python 3.2 at the latest) to be read-only by
> declaring them a property that does not have a setter, or one that has a
> setter that throws a specific exception (here: the former):
> 
> #--
> class SafeMath(object):
> def __init__ (self):
> from math import pi
> self._pi = pi
> 
> @property
> def pi (self):
> return self._pi

The obvious problem with that is that it is trivially easy for the coder to
set self._pi to change the value of self.pi.

Here's a version that at first seems promising:

py> def builder():
... from math import pi as PI
... def pi(self):
... return PI
... return pi
...
py> class MathLib(object):
... pi = property(builder())
...
py> mathlib = MathLib()
py> mathlib.pi
3.141592653589793
py> mathlib.pi = 3.12
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: can't set attribute

There's no _pi accessible that somebody might change. If you dig into the
property object itself, you eventually get to the cell object containing
the value for pi:

py> MathLib.pi.fget.__closure__[0]


but there doesn't appear to be any way to manipulate the cell internals to
change the value. But you don't need to:

py> MathLib.pi = property(lambda self: 4.2)
py> mathlib.pi
4.2


A determined coder can change nearly anything done in pure Python code.

*Personally*, I too would like Python to have some equivalent of (say)
Pascal `const`, names which cannot be rebound once assigned to the first
time. Not to prevent determined coders from changing things, but to avoid
*accidental* changes done in error.



-- 
Steven

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


Re: What does “grep” stand for?

2015-11-06 Thread Larry Hudson via Python-list

On 11/06/2015 05:25 AM, William Ray Wing wrote:



On Nov 5, 2015, at 10:36 PM, Larry Hudson via Python-list 
 wrote:


[snip]

You’re not REALLY an old timer unless you’ve used TECO.

-Bill


Agreed.  I'm not really and old-timer, just old (I'm 78).

My first exposure to computers was the MITS Altair, (around late '75) and my computer use has 
always been hobby-oriented, never professional.  I only know of TECO by reputation, not 
experience.   :-)


 -=- Larry -=-

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


Re: Question about math.pi is mutable

2015-11-06 Thread Ben Finney
Bartc  writes:

> Is there no way then in Python to declare:
>
>pi = 3.141519 # etc
>
> and make it impossible to override?

No, and it would be a bad thing if that were something a library author
could forbid.

Python assumes the programmers using it are consenting adults. Doing
harmful things is difficult but not forbidden.

Notably, the author of a library should not be forbidding the Pythonic
ability to change name bindings as needed.

If you want to have a different value bound to the name ‘math.pi’, and
you go ahead and explicitly ask to change that binding, the library
author has no business forbidding that.

-- 
 \  “Software patents provide one more means of controlling access |
  `\  to information. They are the tool of choice for the internet |
_o__) highwayman.” —Anthony Taylor |
Ben Finney

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


Version 1.1 of the tco module (tail-calls, recursion, call/cc)

2015-11-06 Thread Th. Baruchel
The version 1.1 of the tco module is released. It is much more owerful since
it now allows nested systems of continuations. The most important is probably
rather that I took the time to write a very detailed presentation of the
module on my blog: http://baruchel.github.io/

Regards, tb.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Scipy odeint (LSODA) gives inaccurate results; same code fine in MATLAB ode15s/ode23s

2015-11-06 Thread Christian Gollwitzer

Am 06.11.15 um 23:01 schrieb Abhishek:

I have code that runs perfectly well in MATLAB (using ode15s or
ode23s) but falters with Scipy odeint. The MATLAB code is for a
specific case of the generalized Python code. Here I have tried to
reproduce the specific case in Python. The logic in the code is
airtight and the algorithm is sound. I have also specified small rtol
and atol values, as well as a large mxstep.

My code is below:

[...Python code...]




Why am I getting a "stiff-looking" graph in Python


What does "stiff-looking" mean? I only know stiff differential 
equations, but this leads to noisy results. Your plots are smooth.



(http://i.stack.imgur.com/UGWSH.png), when MATLAB gives me a proper
one (http://i.stack.imgur.com/F2jzd.jpg)? I would like to understand
where the problem lies and how to solve it.


It is very hard to analyze such a problem, unless you also post the 
Matlab code and plot both solutions into a single graph.


What I can see at first is that the initial conditions can't be the 
same. Your Python graph starts around 10^7, while the Matlab graph 
starts at 10^5. WHat happens if you integrate a simpler system - say 
does it make sense to set some of the coefficients to zero and if you 
still get the same difference, can you simplify the program to expose 
the problem? How do you know that the Matlab code produces the correct 
answer?


Christian
--
https://mail.python.org/mailman/listinfo/python-list