how to override the solver function in sympy?

2016-12-03 Thread Ho Yeung Lee
how to override the solver function in sympy?
-- 
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] Python 2.7.13 release candidate 1

2016-12-03 Thread Benjamin Peterson
It is my pleasure to announce the first release candidate of Python
2.7.13, a new bugfix release in the Python 2.7x series.

Downloads may be found on python.org:
 https://www.python.org/downloads/release/python-2713rc1/

Please test the release and report any bugs to
https://bugs.python.org

A final release is scheduled for 2 weeks time.

Servus,
Benjamin
(on behalf of all of 2.7's contributors)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What meaning is "if k in [0, len(n_trials) - 1] else None"?

2016-12-03 Thread Chris Angelico
On Sun, Dec 4, 2016 at 11:10 AM, Terry Reedy  wrote:
>> But the expression result isn't even used. So this is better written:
>
>
> matplotlib.pyplot.xlabel sets x-axis scaling, with no documented return
> value.
> http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xlabel
> If, as seems reasonable to assume, it returns None, the value of the
> expression is 'None if x else None', which is to say, None.

Hardly matters what the return value is, given that the code ignores it.

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


Re: What meaning is "if k in [0, len(n_trials) - 1] else None"?

2016-12-03 Thread Terry Reedy

On 12/3/2016 6:27 PM, Chris Angelico wrote:

On Sun, Dec 4, 2016 at 10:11 AM, Robert  wrote:

I just notice that there is a slash character (\) before the if line.
What is it for?


Yes, that's important. The entire line of code is:

plt.xlabel("$p$, probability of heads") \
if k in [0, len(n_trials) - 1] else None

The backslash means "this continues on the next line".

> The ternary conditional looks like this:


5 if 1 < 2 else 7

Since 1 < 2, this has the value of 5. If not, it would have the value 7.

But the expression result isn't even used. So this is better written:


matplotlib.pyplot.xlabel sets x-axis scaling, with no documented return 
value.

http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xlabel
If, as seems reasonable to assume, it returns None, the value of the 
expression is 'None if x else None', which is to say, None.



if k in [0, len(n_trials) - 1]:
   plt.xlabel("$p$, probability of heads")


--
Terry Jan Reedy

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


Re: What meaning is "if k in [0, len(n_trials) - 1] else None"?

2016-12-03 Thread MRAB

On 2016-12-03 23:11, Robert wrote:

On Saturday, December 3, 2016 at 6:09:02 PM UTC-5, Robert wrote:

Hi,

I am trying to understand the meaning of the below code snippet. Though I have
a Python IDLE at computer, I can't get a way to know below line:

if k in [0, len(n_trials) - 1] else None

I feel it is strange for what returns when the 'if' condition is true?
The second part 'None' is clear to me though.

Could you explain it to me?


thanks,


%matplotlib inline
from IPython.core.pylabtools import figsize
import numpy as np
from matplotlib import pyplot as plt
figsize(11, 9)

import scipy.stats as stats

dist = stats.beta
n_trials = [0, 1, 2, 3, 4, 5, 8, 15, 50, 500]
data = stats.bernoulli.rvs(0.5, size=n_trials[-1])
x = np.linspace(0, 1, 100)

# For the already prepared, I'm using Binomial's conj. prior.
for k, N in enumerate(n_trials):
sx = plt.subplot(len(n_trials) / 2, 2, k + 1)
plt.xlabel("$p$, probability of heads") \
if k in [0, len(n_trials) - 1] else None
plt.setp(sx.get_yticklabels(), visible=False)
heads = data[:N].sum()
y = dist.pdf(x, 1 + heads, 1 + N - heads)
plt.plot(x, y, label="observe %d tosses,\n %d heads" % (N, heads))
plt.fill_between(x, 0, y, color="#348ABD", alpha=0.4)
plt.vlines(0.5, 0, 4, color="k", linestyles="--", lw=1)

leg = plt.legend()
leg.get_frame().set_alpha(0.4)
plt.autoscale(tight=True


I just notice that there is a slash character (\) before the if line.
What is it for?

I've learn Python for a while, but I don't use it for more than 2 years now.
Thanks.

The backslash at the end of the line indicates that that the statement 
continues onto the next line, so it's the same as:


plt.xlabel("$p$, probability of heads") if k in [0, len(n_trials) - 
1] else None


However, that line is weird!

In Python there's a "ternary operator". The docs say:

"""The expression x if C else y first evaluates the condition, C rather 
than x. If C is true, x is evaluated and its value is returned; 
otherwise, y is evaluated and its value is returned."""


Suppose you have the expression:

"even" if x % 2 == 0 else "odd"

If x is a multiple of 2, that expression will evaluate to "even", else 
it will evaluate to "odd".


The line in your code is misusing it as a statement. Normally you would 
write this instead:


if k in [0, len(n_trials) - 1]:
plt.xlabel("$p$, probability of heads")

Why was it written that way? I have no idea, it's just weird...

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


Re: What meaning is "if k in [0, len(n_trials) - 1] else None"?

2016-12-03 Thread Chris Angelico
On Sun, Dec 4, 2016 at 10:11 AM, Robert  wrote:
> I just notice that there is a slash character (\) before the if line.
> What is it for?

Yes, that's important. The entire line of code is:

plt.xlabel("$p$, probability of heads") \
if k in [0, len(n_trials) - 1] else None

The backslash means "this continues on the next line". The ternary
conditional looks like this:

5 if 1 < 2 else 7

Since 1 < 2, this has the value of 5. If not, it would have the value 7.

But the expression result isn't even used. So this is better written:

if k in [0, len(n_trials) - 1]:
   plt.xlabel("$p$, probability of heads")

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


Re: What meaning is "if k in [0, len(n_trials) - 1] else None"?

2016-12-03 Thread Robert
On Saturday, December 3, 2016 at 6:09:02 PM UTC-5, Robert wrote:
> Hi,
> 
> I am trying to understand the meaning of the below code snippet. Though I have
> a Python IDLE at computer, I can't get a way to know below line:
> 
> if k in [0, len(n_trials) - 1] else None
> 
> I feel it is strange for what returns when the 'if' condition is true?
> The second part 'None' is clear to me though.
> 
> Could you explain it to me?
> 
> 
> thanks,
> 
> 
> 
> 
> 
> 
> 
> %matplotlib inline
> from IPython.core.pylabtools import figsize
> import numpy as np
> from matplotlib import pyplot as plt
> figsize(11, 9)
> 
> import scipy.stats as stats
> 
> dist = stats.beta
> n_trials = [0, 1, 2, 3, 4, 5, 8, 15, 50, 500]
> data = stats.bernoulli.rvs(0.5, size=n_trials[-1])
> x = np.linspace(0, 1, 100)
> 
> # For the already prepared, I'm using Binomial's conj. prior.
> for k, N in enumerate(n_trials):
> sx = plt.subplot(len(n_trials) / 2, 2, k + 1)
> plt.xlabel("$p$, probability of heads") \
> if k in [0, len(n_trials) - 1] else None
> plt.setp(sx.get_yticklabels(), visible=False)
> heads = data[:N].sum()
> y = dist.pdf(x, 1 + heads, 1 + N - heads)
> plt.plot(x, y, label="observe %d tosses,\n %d heads" % (N, heads))
> plt.fill_between(x, 0, y, color="#348ABD", alpha=0.4)
> plt.vlines(0.5, 0, 4, color="k", linestyles="--", lw=1)
> 
> leg = plt.legend()
> leg.get_frame().set_alpha(0.4)
> plt.autoscale(tight=True

I just notice that there is a slash character (\) before the if line.
What is it for?

I've learn Python for a while, but I don't use it for more than 2 years now.
Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


What meaning is "if k in [0, len(n_trials) - 1] else None"?

2016-12-03 Thread Robert
Hi,

I am trying to understand the meaning of the below code snippet. Though I have
a Python IDLE at computer, I can't get a way to know below line:

if k in [0, len(n_trials) - 1] else None

I feel it is strange for what returns when the 'if' condition is true?
The second part 'None' is clear to me though.

Could you explain it to me?


thanks,







%matplotlib inline
from IPython.core.pylabtools import figsize
import numpy as np
from matplotlib import pyplot as plt
figsize(11, 9)

import scipy.stats as stats

dist = stats.beta
n_trials = [0, 1, 2, 3, 4, 5, 8, 15, 50, 500]
data = stats.bernoulli.rvs(0.5, size=n_trials[-1])
x = np.linspace(0, 1, 100)

# For the already prepared, I'm using Binomial's conj. prior.
for k, N in enumerate(n_trials):
sx = plt.subplot(len(n_trials) / 2, 2, k + 1)
plt.xlabel("$p$, probability of heads") \
if k in [0, len(n_trials) - 1] else None
plt.setp(sx.get_yticklabels(), visible=False)
heads = data[:N].sum()
y = dist.pdf(x, 1 + heads, 1 + N - heads)
plt.plot(x, y, label="observe %d tosses,\n %d heads" % (N, heads))
plt.fill_between(x, 0, y, color="#348ABD", alpha=0.4)
plt.vlines(0.5, 0, 4, color="k", linestyles="--", lw=1)

leg = plt.legend()
leg.get_frame().set_alpha(0.4)
plt.autoscale(tight=True
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to properly retrieve data using requests + bs4 from multiple pages in a site?

2016-12-03 Thread Juan C.
On Thu, Dec 1, 2016 at 10:07 PM, Juan C.  wrote:
> It works, but it has a big issue: it gets all data from all
units/courses/assignments at the same time, and this isn't very useful as I
don't care about data from units from 1-2 years ago. How can I change the
logic so it just gets the data I need at a given moment? For example, I may
need to dump data for an entire unit, or just one course, or maybe even
just one assignment. How can I achieve this behavior? Another "issue", I
feel like handing my 'session' that I instantiated at user.py to program,
then unit, then course and then assignment is a poor design, how can I make
it better?
>
> Any other suggestions are welcome.

Oh, forgot to tell, I'm using Python 3.5.2 x64.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request Help With Byte/String Problem

2016-12-03 Thread Wildman via Python-list
On Fri, 02 Dec 2016 19:39:39 +, Grant Edwards wrote:

> On 2016-12-02, Wildman via Python-list  wrote:
>> On Fri, 02 Dec 2016 15:11:18 +, Grant Edwards wrote:
>>
>>> I don't know what the "addr" array contains, but if addr is a byte
>>> string, then the "int()" call is not needed, in Pythong 3, a byte is
>>> already an integer:
>>> 
>>> def format_ip(a):
>>>return '.'.join(str(b) for b in a)
>>> 
>>> addr = b'\x12\x34\x56\x78'
>>> 
>>> print(format_ip(addr))
>>
>> It is a byte string just like your 'addr =' example and
>> the above code works perfectly.
> 
> More importantly, you've now learned about generator comprehensions
> (aka generator expressions) and the string type's "join" method.  ;)

I have seen the join method before but because of my lack
of experience it didn't occur to me to use it.  I bet I
will remember it from now on.  I stuck a few code examples
into my 'snips' directory.

Generator expressions are new to me.  I have seen it's use
but I didn't understand what it was and what it was doing,
until now.  Thanks again.

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list