Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Steven D'Aprano
On Wednesday 06 January 2016 07:25, Robert wrote:

> Why is there difference between cmd line and .py file?

Almost certainly because you are not running exactly the same code each 
time.


> I run below code, which is downloaded from link:

Your code fails on the first line with 

NameError: name 'np' is not defined


so you are obviously running something different from what you post here. 
Since we don't know what code you are actually running, we cannot tell you 
why it behaves differently when run as a .py file and in the interactive 
interpreter.

But I am 99% sure that it is because you are running slightly different 
pieces of code.

My *guess* is that in the code that works correctly, you are running:

import numpy as np
from numpy import sum

at the beginning of the .py script, but in the interactive shell, you are 
just running:

import numpy as np


But there may be other differences as well.



-- 
Steve

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


Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Steven D'Aprano
On Wednesday 06 January 2016 07:37, John Gordon wrote:

> The built-in function sum() returns a single value, not a list, so this
> is a reasonable error.

Not quite. It depends on what arguments you give it.

py> a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
py> sum(a, [])
[1, 2, 3, 4, 5, 6, 7, 8, 9]


But your point is well taken. In this case, the call:

sum(expectation_A)

defaults to an initial value of 0, so expectation_A almost certainly is a 
list of numbers, in which case sum will return a single number, not a list 
or array.

-- 
Steve

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


Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Steven D'Aprano
On Wednesday 06 January 2016 10:25, Thomas 'PointedEars' Lahn wrote:

> Robert wrote:
> 
>> I just wonder that the cmd line function sum may be different from the
>> .py file used. One is numpy package, the other is a general one. Then,
>> how can I further make it clear for this guess?
> 
> Among other things:
> 
> print(sum.__doc__)


Better:

help(sum)

in the interactive shell.


-- 
Steve

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


Python launcher options

2016-01-05 Thread Edward Diener
The Python launcher in Windows is a neat tool for running multiple 
versions of Python 2 and Python 3 at different times. It allows as 
options the ability to specify the latest version of either Python 2 or 
Python 3 defaulting to the 64-bit version if both exist, or a specific 
32-bit or 64-bit version of Python 2 or Python 3. What is missing is the 
ability to specify the latest 32-bit version of Python 2 or Python 3. 
The equivalent syntax would be '-2-32' or '-3-32'. Is there some reason 
why this option has been disallowed ?

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


Re: create Email with multiple HTML blocks embedded

2016-01-05 Thread Thomas 'PointedEars' Lahn
kevind0...@gmail.com wrote:

Please either do not use Google Groups and configure your newsreader 
accordingly (recommended), or use Google Groups to subscribe to the 
newsgroup so that you can specify your real name.

> body = MIMEMultipart('multipart')

Obviously there is redundancy, so common sense should tell you already that 
this cannot be correct.  The manual says:



| class email.mime.multipart.MIMEMultipart(_subtype='mixed', boundary=None, 
| _subparts=None, **_params)
| 
| Module: email.mime.multipart
| 
| A subclass of MIMEBase, this is an intermediate base class for MIME 
| messages that are multipart. Optional _subtype defaults to mixed, but can 
| be used to specify the subtype of the message. A Content-Type header of 
| multipart/_subtype will be added to the message object.

So this would add a “Content-Type” header (field) with the value 
“multipart/multipart” to the constructed *message object*, referred to by 
*body* (see below).  It has to be “multipart/mixed” in your case instead, 
which is the default.  So you need to write *only*

msg = MIMEMultipart()

which you did.  But:
 
> with open("H:\\dev\\testHTML\\Exceptions_SheetDec30d.htm", "r") as fE:
> htmlE = fE.read().replace('\n', '')
> 
> 
> with open("H:\\dev\\testHTML\\Summary_SheetDec30d.htm", "r") as f:
> html = f.read().replace('\n', '')
> 
> body.attach(MIMEText(html, 'html'))
> body.attach(MIMEText(htmlE, 'html'))
> 
> msg.attach(body)

Here you are attaching to a multi-part message a *multi-part message with 
two parts*:

  msg (multipart/mixed)
  '- body (multipart/multipart)
 :- html  (text/html)
 '- htmlE (text/html)

You want instead:

  msg (multipart/mixed)
  :- html  (text/html)
  '- htmlE (text/html)

In code:

  msg.attach(MIMEText(html, 'html'))
  msg.attach(MIMEText(htmlE, 'html'))

So just skip ”body”.  (Where else but to the body of the message would you 
attach parts?  To the header? ;-))

You can see how it works *before* you sent the e-mail if you call

  print(msg)

(Of course, you can also read the e-mail source after it was delivered.)

It is unnecessary/wrong to remove the '\n's from the HTML before transfer 
encoding by MIMEText().

-- 
PointedEars

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


Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Thomas 'PointedEars' Lahn
Robert wrote:

> I just wonder that the cmd line function sum may be different from the
> .py file used. One is numpy package, the other is a general one. Then,
> how can I further make it clear for this guess?

Among other things:

print(sum.__doc__)

-- 
PointedEars

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


Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Thomas 'PointedEars' Lahn
Joel Goldstick wrote:

> On Tue, Jan 5, 2016 at 3:45 PM, Robert  wrote:
>> import numpy as np
>>
>> In [154]: np.sum(expectation_A)[0]
>> […]
>> IndexError: invalid index to scalar variable.
> 
> I've not used numpy, but you should print expectation_A to see what's in
> it.  It may be empty, causing the index.

Did you mean “IndexError” instead of “index”?

> It may be that expectation_A is an integer, not a list

Please think about this again.

| $ python3
| Python 3.4.4 (default, Dec 21 2015, 09:19:42)
| [GCC 5.3.1 20151219] on linux
| Type "help", "copyright", "credits" or "license" for more information.
| >>> import numpy
| >>> print(numpy.sum.__doc__)
| 
| Sum of array elements over a given axis.

The problem is instead that np.sum(…) *returns* a scalar value (as expected 
from a summation method when passed only scalar values) and _not_ a list 
(insofar the error message is misleading; there is no scalar *variable* 
causing the problem, but a scalar return *value*):

| Parameters
| --
| a : array_like
| Elements to sum.
| […]
| 
| Returns
| ---
| sum_along_axis : ndarray
| An array with the same shape as `a`, with the specified
| axis removed.   If `a` is a 0-d array, or if `axis` is None, a 
| scalar is returned.  If an output array is specified, a reference
| to `out` is returned.
| 
| […]
| 
| Examples
| 
| >>> np.sum([0.5, 1.5])
| 2.0
| 
`

So you cannot use the index notation with the *return* value.  Try e.g. 
42[0]; it does not work because it does not make sense.

It is more likely that the index notation was misplaced: 

np.sum(expectation_A[0])

would make sense if the first element of the iterable referred to by 
“expectation_A” were a numeric scalar or a reference to a list.


Please trim your quotes to the relevant minimum.

-- 
PointedEars

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


Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Robert
On Tuesday, January 5, 2016 at 3:58:44 PM UTC-5, Joel Goldstick wrote:
> On Tue, Jan 5, 2016 at 3:45 PM, Robert  wrote:
> 
> > On Tuesday, January 5, 2016 at 3:37:53 PM UTC-5, John Gordon wrote:
> > > In  Robert <
> > r...@gmail.com> writes:
> > >
> > > > 
> > > > # represent the experiments
> > > > head_counts = np.array([5,9,8,4,7])
> > >
> > > The code doesn't define 'np', so this line should produce an error.
> > >
> > > The code you linked contains this import:
> > >
> > > import numpy as np
> > >
> > > However you didn't show it here, so I wonder if you posted the real code.
> > >
> > > > sum(expectation_A)[0]
> > > >
> > ---
> > > > IndexErrorTraceback (most recent call
> > last)
> > > >  in ()
> > > > > 1 sum(expectation_A)[0]
> > >
> > > > IndexError: invalid index to scalar variable.
> > > > //
> > >
> > > The built-in function sum() returns a single value, not a list, so this
> > > is a reasonable error.
> > >
> > > I suspect the code actually intended to call numpy.sum(), which does
> > > return a list (or something like a list).
> > >
> > > --
> > > John Gordon   A is for Amy, who fell down the stairs
> > > gor...@panix.com  B is for Basil, assaulted by bears
> > > -- Edward Gorey, "The Gashlycrumb Tinies"
> >
> > Thanks, John. When I typed my new thought, your reply came. You are right.
> >  The attached message missed numpy import (In my file, it had).
> >
> > Now, I cannot use np.sum. It has an error, see below please. How can I use
> > the numpy sum()?
> >
> > Thanks,
> > /
> > import numpy as np
> >
> > In [154]: np.sum(expectation_A)[0]
> > ---
> > IndexErrorTraceback (most recent call last)
> >  in ()
> > > 1 np.sum(expectation_A)[0]
> >
> > IndexError: invalid index to scalar variable.
> >
> 
> I've not used numpy, but you should print expectation_A to see what's in
> it.  It may be empty, causing the index.  It may be that expectation_A is
> an integer, not a list
> 
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> 
> 
> 
> -- 
> Joel Goldstick
> http://joelgoldstick.com/stats/birthdays

Thanks. It has sum method. OK now.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Joel Goldstick
On Tue, Jan 5, 2016 at 3:45 PM, Robert  wrote:

> On Tuesday, January 5, 2016 at 3:37:53 PM UTC-5, John Gordon wrote:
> > In  Robert <
> r...@gmail.com> writes:
> >
> > > 
> > > # represent the experiments
> > > head_counts = np.array([5,9,8,4,7])
> >
> > The code doesn't define 'np', so this line should produce an error.
> >
> > The code you linked contains this import:
> >
> > import numpy as np
> >
> > However you didn't show it here, so I wonder if you posted the real code.
> >
> > > sum(expectation_A)[0]
> > >
> ---
> > > IndexErrorTraceback (most recent call
> last)
> > >  in ()
> > > > 1 sum(expectation_A)[0]
> >
> > > IndexError: invalid index to scalar variable.
> > > //
> >
> > The built-in function sum() returns a single value, not a list, so this
> > is a reasonable error.
> >
> > I suspect the code actually intended to call numpy.sum(), which does
> > return a list (or something like a list).
> >
> > --
> > John Gordon   A is for Amy, who fell down the stairs
> > gor...@panix.com  B is for Basil, assaulted by bears
> > -- Edward Gorey, "The Gashlycrumb Tinies"
>
> Thanks, John. When I typed my new thought, your reply came. You are right.
>  The attached message missed numpy import (In my file, it had).
>
> Now, I cannot use np.sum. It has an error, see below please. How can I use
> the numpy sum()?
>
> Thanks,
> /
> import numpy as np
>
> In [154]: np.sum(expectation_A)[0]
> ---
> IndexErrorTraceback (most recent call last)
>  in ()
> > 1 np.sum(expectation_A)[0]
>
> IndexError: invalid index to scalar variable.
>

I've not used numpy, but you should print expectation_A to see what's in
it.  It may be empty, causing the index.  It may be that expectation_A is
an integer, not a list

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



-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Robert
On Tuesday, January 5, 2016 at 3:37:53 PM UTC-5, John Gordon wrote:
> In  Robert 
>  writes:
> 
> > 
> > # represent the experiments
> > head_counts = np.array([5,9,8,4,7])
> 
> The code doesn't define 'np', so this line should produce an error.
> 
> The code you linked contains this import:
> 
> import numpy as np
> 
> However you didn't show it here, so I wonder if you posted the real code.
> 
> > sum(expectation_A)[0]
> > ---
> > IndexErrorTraceback (most recent call last)
> >  in ()
> > > 1 sum(expectation_A)[0]
> 
> > IndexError: invalid index to scalar variable. 
> > //
> 
> The built-in function sum() returns a single value, not a list, so this
> is a reasonable error.
> 
> I suspect the code actually intended to call numpy.sum(), which does
> return a list (or something like a list).
> 
> -- 
> John Gordon   A is for Amy, who fell down the stairs
> gor...@panix.com  B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"

Thanks, John. When I typed my new thought, your reply came. You are right.
 The attached message missed numpy import (In my file, it had).

Now, I cannot use np.sum. It has an error, see below please. How can I use
the numpy sum()?

Thanks,
/
import numpy as np

In [154]: np.sum(expectation_A)[0]
---
IndexErrorTraceback (most recent call last)
 in ()
> 1 np.sum(expectation_A)[0]

IndexError: invalid index to scalar variable.

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


Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Robert
On Tuesday, January 5, 2016 at 3:26:15 PM UTC-5, Robert wrote:
> Hi,
> 
> I run below code, which is downloaded from link:
> 
> http://stackoverflow.com/questions/15513792/expectation-maximization-coin-toss-examples?rq=1
> 
> 
> 
> 
> # represent the experiments
> head_counts = np.array([5,9,8,4,7])
> tail_counts = 10-head_counts
> experiments = zip(head_counts,tail_counts)
> 
> # initialise the pA(heads) and pB(heads)
> pA_heads = np.zeros(100); pA_heads[0] = 0.60
> pB_heads = np.zeros(100); pB_heads[0] = 0.50
> 
> # E-M begins!
> delta = 0.001  
> j = 0 # iteration counter
> improvement = float('inf')
> while (improvement>delta):
> expectation_A = np.zeros((5,2), dtype=float) 
> expectation_B = np.zeros((5,2), dtype=float)
> for i in range(0,len(experiments)):
> e = experiments[i] # i'th experiment
> ll_A = get_mn_log_likelihood(e,np.array([pA_heads[j],1-pA_heads[j]])) 
> # loglikelihood of e given coin A
> ll_B = get_mn_log_likelihood(e,np.array([pB_heads[j],1-pB_heads[j]])) 
> # loglikelihood of e given coin B
> 
> weightA = math.exp(ll_A) / ( math.exp(ll_A) + math.exp(ll_B) ) # 
> corresponding weight of A proportional to likelihood of A 
> weightB = math.exp(ll_B) / ( math.exp(ll_A) + math.exp(ll_B) ) # 
> corresponding weight of B proportional to likelihood of B 
>
> 
> expectation_A[i] = np.dot(weightA, e) 
> expectation_B[i] = np.dot(weightB, e)
> 
> print "sum(expectation_A)[0]", sum(expectation_A)[0]
> pA_heads[j+1] = sum(expectation_A)[0] / sum(sum(expectation_A)); 
> pB_heads[j+1] = sum(expectation_B)[0] / sum(sum(expectation_B));
> //
> The print message is: 
> sum(expectation_A)[0] 21.2974818963
> sum(expectation_A)[0] 19.2093824201
> sum(expectation_A)[0] 19.4102767983
> sum(expectation_A)[0] 19.7538328728
> sum(expectation_A)[0] 19.9753285438
> sum(expectation_A)[0] 20.0879016403
> sum(expectation_A)[0] 20.139820175
> sum(expectation_A)[0] 20.1628374165
> 
> 
> 
> When I check below in detail in interactive mode (Canopy Python shell),
>  
> sum(expectation_A)[0]
> 
> it has error:
> /
> sum(expectation_A)[0]
> ---
> IndexErrorTraceback (most recent call last)
>  in ()
> > 1 sum(expectation_A)[0]
> 
> IndexError: invalid index to scalar variable. 
> //
> 
> I can see expectation_A content with:
> 
> In[146]:expectation_A
> Out[146]: 
> array([[ 0.52278641,  0.52278641],
>[ 8.55858656,  0.95095406],
>[ 6.75024946,  1.68756237],
>[ 0.1260128 ,  0.1890192 ],
>[ 4.20520218,  1.80222951]])
> 
> It looks like 
> sum(expectation_A)[0]
> 
> can run in .py file, while it cannot be run in python shell.
> Is it true?
> 
> Thanks,

I just wonder that the cmd line function sum may be different from the 
.py file used. One is numpy package, the other is a general one. Then,
how can I further make it clear for this guess?
Thanks,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread John Gordon
In  Robert 
 writes:

> 
> # represent the experiments
> head_counts = np.array([5,9,8,4,7])

The code doesn't define 'np', so this line should produce an error.

The code you linked contains this import:

import numpy as np

However you didn't show it here, so I wonder if you posted the real code.

> sum(expectation_A)[0]
> ---
> IndexErrorTraceback (most recent call last)
>  in ()
> > 1 sum(expectation_A)[0]

> IndexError: invalid index to scalar variable. 
> //

The built-in function sum() returns a single value, not a list, so this
is a reasonable error.

I suspect the code actually intended to call numpy.sum(), which does
return a list (or something like a list).

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Why is there difference between cmd line and .py file?

2016-01-05 Thread Robert
Hi,

I run below code, which is downloaded from link:

http://stackoverflow.com/questions/15513792/expectation-maximization-coin-toss-examples?rq=1




# represent the experiments
head_counts = np.array([5,9,8,4,7])
tail_counts = 10-head_counts
experiments = zip(head_counts,tail_counts)

# initialise the pA(heads) and pB(heads)
pA_heads = np.zeros(100); pA_heads[0] = 0.60
pB_heads = np.zeros(100); pB_heads[0] = 0.50

# E-M begins!
delta = 0.001  
j = 0 # iteration counter
improvement = float('inf')
while (improvement>delta):
expectation_A = np.zeros((5,2), dtype=float) 
expectation_B = np.zeros((5,2), dtype=float)
for i in range(0,len(experiments)):
e = experiments[i] # i'th experiment
ll_A = get_mn_log_likelihood(e,np.array([pA_heads[j],1-pA_heads[j]])) # 
loglikelihood of e given coin A
ll_B = get_mn_log_likelihood(e,np.array([pB_heads[j],1-pB_heads[j]])) # 
loglikelihood of e given coin B

weightA = math.exp(ll_A) / ( math.exp(ll_A) + math.exp(ll_B) ) # 
corresponding weight of A proportional to likelihood of A 
weightB = math.exp(ll_B) / ( math.exp(ll_A) + math.exp(ll_B) ) # 
corresponding weight of B proportional to likelihood of B   
 

expectation_A[i] = np.dot(weightA, e) 
expectation_B[i] = np.dot(weightB, e)

print "sum(expectation_A)[0]", sum(expectation_A)[0]
pA_heads[j+1] = sum(expectation_A)[0] / sum(sum(expectation_A)); 
pB_heads[j+1] = sum(expectation_B)[0] / sum(sum(expectation_B));
//
The print message is: 
sum(expectation_A)[0] 21.2974818963
sum(expectation_A)[0] 19.2093824201
sum(expectation_A)[0] 19.4102767983
sum(expectation_A)[0] 19.7538328728
sum(expectation_A)[0] 19.9753285438
sum(expectation_A)[0] 20.0879016403
sum(expectation_A)[0] 20.139820175
sum(expectation_A)[0] 20.1628374165



When I check below in detail in interactive mode (Canopy Python shell),
 
sum(expectation_A)[0]

it has error:
/
sum(expectation_A)[0]
---
IndexErrorTraceback (most recent call last)
 in ()
> 1 sum(expectation_A)[0]

IndexError: invalid index to scalar variable. 
//

I can see expectation_A content with:

In[146]:expectation_A
Out[146]: 
array([[ 0.52278641,  0.52278641],
   [ 8.55858656,  0.95095406],
   [ 6.75024946,  1.68756237],
   [ 0.1260128 ,  0.1890192 ],
   [ 4.20520218,  1.80222951]])

It looks like 
sum(expectation_A)[0]

can run in .py file, while it cannot be run in python shell.
Is it true?

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


Re: What is the fastest way to do 400 HTTP requests using requests library?

2016-01-05 Thread Ian Kelly
On Tue, Jan 5, 2016 at 10:02 AM, Paul Rubin  wrote:
> Steven D'Aprano  writes:
>> Maybe they're stress-testing a web server, or they just want to download
>> things in a rush.
>
> They're stress-testing a web server through a tor proxy?  This sounds
> abusive to me.
>
> I also wonder whether 400 referred to the HTTP 400 error code rather
> than the number of requests to be sent.  As in:
>
> - Layer 7 (“400 bad request”) attacks toward our web and application
>   servers, causing Linode Manager outages
>
> from http://status.linode.com/incidents/mmdbljlglnfd
> regarding a big DDOS attack that's been running against Linode.com
> (a VPS host) over the past couple weeks.

I had the same initial thought about the status code but dismissed it,
since why would somebody intentionally send a request that will return
a 400 status? I was not thinking about abuse though, so the DDoS
scenario did not occur to me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is the fastest way to do 400 HTTP requests using requests library?

2016-01-05 Thread Paul Rubin
Steven D'Aprano  writes:
> Maybe they're stress-testing a web server, or they just want to download
> things in a rush.

They're stress-testing a web server through a tor proxy?  This sounds
abusive to me.

I also wonder whether 400 referred to the HTTP 400 error code rather
than the number of requests to be sent.  As in:

- Layer 7 (“400 bad request”) attacks toward our web and application
  servers, causing Linode Manager outages

from http://status.linode.com/incidents/mmdbljlglnfd
regarding a big DDOS attack that's been running against Linode.com
(a VPS host) over the past couple weeks.
-- 
https://mail.python.org/mailman/listinfo/python-list


create Email with multiple HTML blocks embedded

2016-01-05 Thread kevind0718
The below script will send an email with one HTML file embedded and the second 
attached.  Not really what I need.  I need a Python script to create an email 
that contains multiple blocks of HTML in the body of the email.

There is a process that will create at least one HTML file but very often two. 
A summary and an exception web pages. These need to be emailed to a user group.

The code below displays one file in the email, but the other shows up as an 
attachment. If I reverse the body.attach statements then the files switch. I 
need both to appear in the body of the email.

I messed around with the boundary attribute, but could not get that to work.

Your kind assistance is requested.

Best Regards

KD


import smtplib
from pprint import pprint
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

msg = MIMEMultipart()
msg['Subject'] = 'email from Python with HTML content '
msg['From'] = 'k...@xxx.com'
msg['To'] = 'k...@xxx.com'

text = "\nBelow I hope will be the Summary Table in HTML\n\n"
body = MIMEMultipart('multipart')

with open("H:\\dev\\testHTML\\Exceptions_SheetDec30d.htm", "r") as fE:
htmlE = fE.read().replace('\n', '')


with open("H:\\dev\\testHTML\\Summary_SheetDec30d.htm", "r") as f:
html = f.read().replace('\n', '')

body.attach(MIMEText(html, 'html'))
body.attach(MIMEText(htmlE, 'html'))

msg.attach(body)

s = smtplib.SMTP('smtp.aigfpc.com')  # ('localhost')
s.sendmail('k...@xxx.com', ['k...@xxx.com'], msg.as_string())
s.quit()

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


Re: Is there a way importing a string object?

2016-01-05 Thread Robin Koch

Am 05.01.2016 um 03:24 schrieb jf...@ms4.hinet.net:


(Please make the body of your message complete. The "Subject"
field should be a summary of your message's subject, and may not be
read as the first line of your message.)


Yes, The "Subject" seems a little strange, read likes a part of the
body. I am bad on composition. Even after your reminder, I still
can't think of a better one:-(


I think the subject is fine.
But you should have extended your message body a little so your question 
is understandable without reading the subject.


--
Robin Koch

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


Re: Is '*args' useful in this example code?

2016-01-05 Thread Robert
On Monday, January 4, 2016 at 10:28:31 PM UTC-5, Ben Finney wrote:
> Robert <.com> writes:
> 
> > On Monday, January 4, 2016 at 9:26:47 PM UTC-5, Ben Finney wrote:
> > > Can you show example code that you would expect, and specifically what 
> > > about
> > > the actual code doesn't match what you expect?
> >
> > Excuse me for the incomplete info previously. 
> > If I call it with 
> > a = f(3) 
> > the result is 12.
> 
> Can you show a *very* simple example of the 'f' you're talking about?
> Contrive a new one, make it behave the same way while keeping it very
> short, and once you have that, put that code in your message.
> 
> With an actual function to examine it will be much easier to know where
> the confusion lies.
> 
> -- 
>  \   "When a well-packaged web of lies has been sold to the masses |
>   `\over generations, the truth will seem utterly preposterous and |
> _o__)its speaker a raving lunatic." --Dresden James |
> Ben Finney

Excuse me, Ben. I forgot to add the f function. It is as below:
@logged
def f(x):
   """does some math"""
   return x + x * x
   
a = f(3)  
 
My problem has been solved after all of your helpful posts. Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is the fastest way to do 400 HTTP requests using requests library?

2016-01-05 Thread Tim Chase
On 2016-01-05 20:38, Steven D'Aprano wrote:
> On Tue, 5 Jan 2016 07:53 pm, Tony van der Hoff wrote:
> 
> > Why would someone want to make 400 HTTP requests in a short time?
> 
> For the same reason they want to make 400 HTTP requests over a long
> time, except that they're in a hurry.
> 
> Maybe they're stress-testing a web server, or they just want to
> download things in a rush.

Maybe they just want to generate lots of errors.  It's generally more
productive to make lots of 200 HTTP requests[*]. ;-)

-tkc


[*] http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html



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


Re: Is '*args' useful in this example code?

2016-01-05 Thread Antoon Pardon
Op 05-01-16 om 03:16 schreef Robert:
> Hi,
>
> I find an example code on wrap at this link:
> http://stackoverflow.com/questions/308999/what-does-functools-wraps-do
>
> Here is the code:
> 
> def logged(func):
> def with_logging(*args, **kwargs):
> print func.__name__ + " was called"
> return func(*args, **kwargs)
> return with_logging
> ///
>
> I understand now, but I feel the args usage is weird. I don't see any way 
> to use *args and **kwargs in above code. What is your opinion on it?
>
>
> Thanks,

You want the following to work

def add(a, b):
return a + b

def double(n)
return n + n

logged_add = logged(add)
logged_double = logged(double)

s = logged_add(3, 5)
d = logged_double(13)

-- 
Antoon Pardon

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


Re: subprocess check_output

2016-01-05 Thread Chris Angelico
On Tue, Jan 5, 2016 at 10:15 PM, me  wrote:
> On 2016-01-02, Chris Angelico  wrote:
>> down to "whoops, I forgot to save the file" or "whoops, I was in the
>> wrong directory"...
>
> Amen, bro.
>
> Exceptionally true if you ever need for some reason to put your code in
> another directory, but you forget to close the files in your editor. :D

Oh, and then you keep editing and save again? Nah, I've *never* done
that... Never!

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


Re: subprocess check_output

2016-01-05 Thread me
On 2016-01-02, Chris Angelico  wrote:
> down to "whoops, I forgot to save the file" or "whoops, I was in the
> wrong directory"...

Amen, bro.

Exceptionally true if you ever need for some reason to put your code in
another directory, but you forget to close the files in your editor. :D
-- 
https://mail.python.org/mailman/listinfo/python-list


PLease have problem in operate python 27 with pycharm environment,

2016-01-05 Thread hanaamohsin77
I need help in install  packages like scipy by pip and conda on the in the 
pycharm environment 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is the fastest way to do 400 HTTP requests using requests library?

2016-01-05 Thread Steven D'Aprano
On Tue, 5 Jan 2016 07:53 pm, Tony van der Hoff wrote:

> Why would someone want to make 400 HTTP requests in a short time?

For the same reason they want to make 400 HTTP requests over a long time,
except that they're in a hurry.

Maybe they're stress-testing a web server, or they just want to download
things in a rush.


-- 
Steven

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


Re: What is the fastest way to do 400 HTTP requests using requests library?

2016-01-05 Thread Tony van der Hoff
On 05/01/16 00:51, Ian Kelly wrote:
> On Mon, Jan 4, 2016 at 4:38 PM, Steven D'Aprano  wrote:
>> On Tue, 5 Jan 2016 07:50 am, livems...@gmail.com wrote:
>>
>>> So what is the fastest way to make 400 HTTP requests using "requests"
>>> library and also using tor proxy?
>>
>>
>> Since this will be I/O bound, not CPU bound, probably use separate threads.
>>
>> Push the 400 requests into a queue, then create N threads, where N will need
>> to be determined by experiment, but will probably be something like 4 or 8,
>> and let each thread pop a request from the queue as needed.
>>
>> Are you experienced with threads? Do you need further information about
>> using threads and queues?
> 
> Also see the concurrent.futures module in the standard library, which
> makes this sort of setup very simple to implement.
> 
Why would someone want to make 400 HTTP requests in a short time?


-- 
Tony van der Hoff  | mailto:t...@vanderhoff.org
Ariège, France |
-- 
https://mail.python.org/mailman/listinfo/python-list