Eliot 0.5.0: Structured Logging as Storytelling

2014-10-22 Thread Itamar Turner-Trauring
Eliot provides a structured logging and tracing system for Python that
generates log messages describing a forest of nested actions. Actions start
and eventually finish, successfully or not. Log messages thus tell a story:
what happened and what caused it.

Eliot is released by ClusterHQ https://docs.clusterhq.com, the Data
People for Docker™, and is available at https://pypi.python.org/pypi/eliot.


Here's what your logs might look like before using Eliot:

Going to validate http://example.com/index.html.
Started download attempted.
Download succeeded!
Missing title element in /html/body.
Bad HTML entity in /html/body/p[2].
2 validation errors found!

After switching to Eliot you'll get a tree of messages with both message
contents and causal relationships encoded in a structured format:

   - {action_type: validate_page, action_status: started, url: 
   http://example.com/index.html}
  - {action_type: download, action_status: started}
  - {action_type: download, action_status: succeeded}
  - {action_type: validate_html, action_status: started}
 - {message_type: validation_error, error_type:
 missing_title, xpath: /html/head}
 - {message_type: validation_error, error_type: bad_entity,
 xpath: /html/body/p[2]}
  - {action_type: validate_html, action_status: failed,
  exception: validator.ValidationFailed}
   - {action_type: validate_page, action_status: failed,
   exception: validator.ValidationFailed}


What's New in 0.5.0:

   - Added support for Python 3.4.
   - Most public methods and functions now have underscore-based
   equivalents to the camel case versions, e.g. eliot.write_traceback and
   eliot.writeTraceback, for use in PEP 8 styled programs. Twisted-facing
   APIs and pyunit assertions do not provide these additional APIs, as
   camel-case is the native idiom.
   - eliot.to_file outputs log messages to a file.
   - Documented how to load Eliot logging into ElasticSearch via Logstash.
   - Documentation has been significantly reorganized.
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Flush stdin

2014-10-22 Thread Chris Angelico
On Wed, Oct 22, 2014 at 4:38 PM, Marko Rauhamaa ma...@pacujo.net wrote:
 Dan Stromberg drsali...@gmail.com:

 On Mon, Oct 20, 2014 at 9:41 PM, Marko Rauhamaa ma...@pacujo.net wrote:
 Nagle affects the communication between the peer OS kernels and isn't
 directly related to anything the application does.

 Actually, Nagle can cause two or more small packets to be merged,
 which is something an application must be able to deal with, because
 they could show up in the receiving application as one or more (but
 anyway: fewer) merged recv()'s.

 Packets have barely anything to do with TCP sockets since they provide
 an octet stream abstraction.

TCP does abstract over the individual packets, but they are still important.

 Of course, but who's doing one byte per second?  You and I in our
 tests, and perhaps some application developers with remarkably
 undemanding I/O.  That doesn't really mean we should _recommend_ a
 series of os.read(0, 1)'s.

 No, here's my statement: if you need to process input as soon as it
 becomes available, you can't use sys.stdin. Instead, you need to use
 os.read().

 You typically supply os.read() with a buffer of a kilobyte or more. Key
 is, os.read() returns right away if fewer bytes are available.

Then your statement is false. Maybe it's not *efficient* if you always
use sys.stdin.read(1), but you certainly can do it. It's not that you
*need to* use something else.

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


(test) ? a:b

2014-10-22 Thread ast

Hello

Is there in Python something like:

j = (j = 10) ? 3 : j+1;

as in C language ?

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


(-1)**1000

2014-10-22 Thread ast

Hello

If i am writing (-1)**1000 on a python program, will the
interpreter do (-1)*(-1)*...*(-1) or something clever ?

In fact i have (-1)**N with N an integer potentially big.

I do some tests that suggest that Python is clever

thx

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


Re: (test) ? a:b

2014-10-22 Thread Jean-Michel Pichavant
- Original Message -
 From: ast nom...@invalid.com
 To: python-list@python.org
 Sent: Wednesday, 22 October, 2014 10:29:43 AM
 Subject: (test) ? a:b
 
 Hello
 
 Is there in Python something like:
 
 j = (j = 10) ? 3 : j+1;
 
 as in C language ?
 
 thx

j = 3 if j =10 else j+1

Cheers

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (-1)**1000

2014-10-22 Thread Jean-Michel Pichavant
- Original Message -
 From: ast nom...@invalid.com
 To: python-list@python.org
 Sent: Wednesday, 22 October, 2014 10:27:34 AM
 Subject: (-1)**1000
 
 Hello
 
 If i am writing (-1)**1000 on a python program, will the
 interpreter do (-1)*(-1)*...*(-1) or something clever ?
 
 In fact i have (-1)**N with N an integer potentially big.
 
 I do some tests that suggest that Python is clever
 
 thx

Python will yield the correct results. That is the most clever thing to do.
If you really worried about execution speed (I assume that what your question 
implies), Python may not be the language you need.

However, know that there are these modules numpy and scipy which are used 
by the scientific community which provide a python interface (it's a python 
module) but most of the heavy lifting is done in C (you can embed C in python 
code). 

For instance
http://docs.scipy.org/doc/numpy/reference/generated/numpy.power.html

Use this module if speed is what you're looking for.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (-1)**1000

2014-10-22 Thread Chris Angelico
On Wed, Oct 22, 2014 at 7:27 PM, ast nom...@invalid.com wrote:
 If i am writing (-1)**1000 on a python program, will the
 interpreter do (-1)*(-1)*...*(-1) or something clever ?

 In fact i have (-1)**N with N an integer potentially big.

Exponentiation is far more efficient than the naive implementation of
iterated multiplication. Any modern programming language on any modern
CPU architecture should be able to handle this kind of thing. But even
the naive approach is likely to be fast enough.

 x=1
 for i in range(100): x*=-1

I had to go as far as a million iterations before this, implemented
purely in Python with absolutely no optimization, demonstrated a
visible pause (of about a quarter second) on my not-exactly-new
Windows laptop. My Linux desktop, with a rather hotter CPU, has no
trouble with a million, so I'd have to go higher to get a pause out of
it.

And actually, about half of that time is spent in the loop - replacing
the assignment with pass still leaves half the iteration time.

Poor performance is a crime. Python is innocent until proven guilty.
And the burden of proof is seldom met.

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


Re: (test) ? a:b

2014-10-22 Thread buscacio
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
 Hello
 
 
 
 Is there in Python something like:
 
 
 
 j = (j = 10) ? 3 : j+1;
 
 
 
 as in C language ?
 
 
 
 thx

without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]

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


Re: (-1)**1000

2014-10-22 Thread Peter Otten
ast wrote:

 If i am writing (-1)**1000 on a python program, will the
 interpreter do (-1)*(-1)*...*(-1) or something clever ?
 
 In fact i have (-1)**N with N an integer potentially big.
 
 I do some tests that suggest that Python is clever

Let's see:

$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type help, copyright, credits or license for more information.
 import dis
 def f():
... return (-1)**1000
... 
 dis.dis(f)
  2   0 LOAD_CONST   4 (1)
  3 RETURN_VALUE

So yes, CPython replaces the expression (-1)**1000 with its value during 
compilation.

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


Re: (test) ? a:b

2014-10-22 Thread Chris Angelico
On Wed, Oct 22, 2014 at 8:05 PM,  busca...@gmail.com wrote:
 Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
 Hello



 Is there in Python something like:



 j = (j = 10) ? 3 : j+1;



 as in C language ?



 thx

 without not:
 j = [j+1, 3][j=10]
 with not:
 j = [3, j+1][not (j=10)]

There's a distinct semantic difference there, though. Compare these:

/* C */
int x = (y != 0) ? 65536/y : 0;

# Python
x = 65536/y if y else 0

# Python, your way
x = [0, 65536/y][y!=0]

Do you see where the problem is?

Plus, subscripting a literal list is far less readable than the
ternary operator.

Also: Please can you avoid Google Groups, or if you must use it,
please at least clean up the excessive blank lines before you post.
I've left them so you can see what we have to cope with. Thanks!

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


Re: (test) ? a:b

2014-10-22 Thread Mark Lawrence

On 22/10/2014 10:05, busca...@gmail.com wrote:

Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:

Hello



Is there in Python something like:



j = (j = 10) ? 3 : j+1;



as in C language ?



thx


without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]



The death penalty should be reintroduced into the UK for two crimes, 
writing code like the above and using google groups.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: (test) ? a:b

2014-10-22 Thread ast


busca...@gmail.com a écrit dans le message de 
news:7839376e-fc27-4299-ae63-4ddf17ef9...@googlegroups.com...

Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:

Hello



Is there in Python something like:



j = (j = 10) ? 3 : j+1;



as in C language ?



thx


without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]



Oh it's a trick !
thx 


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


Re: (-1)**1000

2014-10-22 Thread ast


Chris Angelico ros...@gmail.com a écrit dans le message de 
news:mailman.15058.1413968065.18130.python-l...@python.org...

On Wed, Oct 22, 2014 at 7:27 PM, ast nom...@invalid.com wrote:

If i am writing (-1)**1000 on a python program, will the
interpreter do (-1)*(-1)*...*(-1) or something clever ?

In fact i have (-1)**N with N an integer potentially big.


Exponentiation is far more efficient than the naive implementation of
iterated multiplication.


In the very particular case of (-1)**N,  I belive that Python check
the odd or even parity of N and provides the result accordingly.

I tried:

(-1)**10

1

(-1)**11

-1

and it is instantaneous


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


Re: (test) ? a:b

2014-10-22 Thread Chris Angelico
On Wed, Oct 22, 2014 at 8:16 PM, Mark Lawrence breamore...@yahoo.co.uk wrote:
 without not:
 j = [j+1, 3][j=10]
 with not:
 j = [3, j+1][not (j=10)]


 The death penalty should be reintroduced into the UK for two crimes, writing
 code like the above and using google groups.

No no no. Code like that doesn't deserve death, just community
service. I've seen much MUCH worse... where multiple conditional
expressions get combined arithmetically, and then the result used
somewhere... I also may have been guilty of same, myself, though I'm
going to plead the internet's equivalent of the Fifth Amendment to the
US Constitution and not incriminate myself by showing the code...

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


Re: (-1)**1000

2014-10-22 Thread Peter Otten
ast wrote:

 
 Chris Angelico ros...@gmail.com a écrit dans le message de
 news:mailman.15058.1413968065.18130.python-l...@python.org...
 On Wed, Oct 22, 2014 at 7:27 PM, ast nom...@invalid.com wrote:
 If i am writing (-1)**1000 on a python program, will the
 interpreter do (-1)*(-1)*...*(-1) or something clever ?

 In fact i have (-1)**N with N an integer potentially big.

 Exponentiation is far more efficient than the naive implementation of
 iterated multiplication.
 
 In the very particular case of (-1)**N,  I belive that Python check
 the odd or even parity of N and provides the result accordingly.
 
 I tried:
 (-1)**10
 1
 (-1)**11
 -1
 
 and it is instantaneous

Not instantaneous once you defeat the peephole optimizer by introducing a 
variable:

$ python3 -m timeit '(-1)**101'
1000 loops, best of 3: 0.0356 usec per loop
$ python3 -m timeit -s'a = 101' '(-1)**a'
10 loops, best of 3: 3.23 usec per loop

When you increase the exponent you might discern a pattern:

$ python3 -m timeit -s 'a = 10**10' '(-1)**a'
100 loops, best of 3: 1.42 usec per loop
$ python3 -m timeit -s 'a = 10**100' '(-1)**a'
10 loops, best of 3: 11.6 usec per loop
$ python3 -m timeit -s 'a = 10**1000' '(-1)**a'
1 loops, best of 3: 101 usec per loop
$ python3 -m timeit -s 'a = 10**1' '(-1)**a'
1000 loops, best of 3: 992 usec per loop

That looks like log(a) while a parity check takes constant time:

$ python3 -m timeit -s 'a = 10**10' 'a  1'
1000 loops, best of 3: 0.124 usec per loop
$ python3 -m timeit -s 'a = 10**100' 'a  1'
1000 loops, best of 3: 0.124 usec per loop
$ python3 -m timeit -s 'a = 10**1000' 'a  1'
1000 loops, best of 3: 0.122 usec per loop


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


Re: Matplotlib: getting a figure to show without plt.show()

2014-10-22 Thread Peter Otten
Peter Pearson wrote:

 I'm using Matplotlib to present a control window with clickable
 buttons, and to plot things in another window when you click buttons,
 in the style of the code below.  I'm ashamed of the stinky way I
 use first to call plt.show the first time data are plotted but then
 to call fig.canvas.draw for subsequent data plots.  

 def callback(event):
 global n, first
 fig = plt.figure(2)
 fig.clear()
 plt.plot([0,1],[0,n])
 n += 1  # (Pretending something changes from one plot to the next.)
 if first:
 first = False
 plt.show()
 else:
 fig.canvas.draw()

 Can someone tell me the right way?

I don't see what's wrong with doing something different the first time 
around.

 If I call plt.show every time, then after about 40 plots I get
 RuntimeError: maximum recursion depth exceeded while calling a Python
 object, which makes sense because I'm getting one layer deeper in
 callbacks with every plot (plt.show doesn't return).  But if I call
 fig.canvas.draw every time, the window for the data plot never appears
 on my screen.

If your backend uses tkinter, then the problem may be that plt.show() starts 
a new mainloop. Over here this causes the script to hang on termination. 
Through try-and-error I came up with

import matplotlib.pyplot as plt
from matplotlib.widgets import Button

def callback(event):
global n, fig2

if fig2 is None:
fig2 = plt.figure(2)

fig2.clear()
fig2.gca().plot([0, .5, 1], [0, 1/n, 1])
fig2.show()

n += 1 

n = 1
fig2 = None

plt.figure(1)

quit_button = Button(plt.axes([.1, .3, .4, .2]), Quit)
quit_button.on_clicked(lambda x: plt.close(all))

plot_button = Button(plt.axes([.1, .1, .4, .2]), Plot)
plot_button.on_clicked(callback)

plt.show()

If you don't mind that the second window shows up immediately you can modify 
that to

import matplotlib.pyplot as plt
from matplotlib.widgets import Button

def callback(event):
global n

fig2.clear()
fig2.gca().plot([0, .5, 1], [0, 1/n, 1])
fig2.show()

n += 1 

n = 1

plt.figure(1)

quit_button = Button(plt.axes([.1, .3, .4, .2]), Quit)
quit_button.on_clicked(lambda x: plt.close(all))

plot_button = Button(plt.axes([.1, .1, .4, .2]), Plot)
plot_button.on_clicked(callback)

fig2 = plt.figure(2)

plt.show()

and thus avoid the special case. 

As I'm not an expert for matplotlib you might also post your question on the 
matplotlib mailing list.

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


Re: (-1)**1000

2014-10-22 Thread Michiel Overtoom

On Oct 22, 2014, at 12:29, Peter Otten wrote:

 That looks like log(a) while a parity check takes constant time:
 $ python3 -m timeit -s 'a = 10**10' 'a  1'


Do you mean 'parity' as in http://en.wikipedia.org/wiki/Parity_bit ?  Because a 
parity bit denotes whether the *number* of '1' bits is even or odd, not the 
value of the least significant bit.

Greetings,

-- 
You can't actually make computers run faster, you can only make them do less. 
- RiderOfGiraffes

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


Re: (-1)**1000

2014-10-22 Thread Tim Chase
On 2014-10-22 12:29, Peter Otten wrote:
 That looks like log(a) while a parity check takes constant time:
 
 $ python3 -m timeit -s 'a = 10**10' 'a  1'
 1000 loops, best of 3: 0.124 usec per loop
 $ python3 -m timeit -s 'a = 10**100' 'a  1'
 1000 loops, best of 3: 0.124 usec per loop
 $ python3 -m timeit -s 'a = 10**1000' 'a  1'
 1000 loops, best of 3: 0.122 usec per loop

Just for the record, this is a one-bit even/odd check (which is
useful  fast in this sign-of-large-exponent case), not a parity check
(which typically counts the number of 1 bits, adds the parity bit,
and asserts the result is even)

-tkc



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


Re: Flush stdin

2014-10-22 Thread Marko Rauhamaa
Dan Stromberg drsali...@gmail.com:

 On Mon, Oct 20, 2014 at 9:41 PM, Marko Rauhamaa ma...@pacujo.net wrote:
 Terminal devices support line buffering on write.
 Yes, though that's not the only place it's useful.

 Line buffering on read is an illusion created by higher-level libraries.
 The low-level read function reads in blocks of bytes.

 Actually, doesn't line buffering sometimes exist inside an OS kernel?
 stty/termios/termio/sgtty relate here, for *ix examples.  Supporting
 code: http://stromberg.dnsalias.org/~strombrg/ttype/  It turns on
 character-at-a-time I/O in the tty driver via a variety of methods for
 portability.  I wrote it in C before I took an interest in Python.

I was being sloppy in my TTY terminology. A TTY device is running inside
the kernel and thus writes by copying bytes from its kernel buffer
into the user space when the user space process calls read(2).


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


Re: (-1)**1000

2014-10-22 Thread Peter Otten
Michiel Overtoom wrote:

 
 On Oct 22, 2014, at 12:29, Peter Otten wrote:
 
 That looks like log(a) while a parity check takes constant time:
 $ python3 -m timeit -s 'a = 10**10' 'a  1'
 
 
 Do you mean 'parity' as in http://en.wikipedia.org/wiki/Parity_bit ? 
 Because a parity bit denotes whether the *number* of '1' bits is even or
 odd, not the value of the least significant bit.

No, I meant the lsb. The OP introduced the term 'parity'; not sure if that 
was erroneous, too, or if there is an angle to the problem that escapes me.

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


Re: (test) ? a:b

2014-10-22 Thread Ned Batchelder

On 10/22/14 5:05 AM, busca...@gmail.com wrote:

Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:

Hello



Is there in Python something like:



j = (j = 10) ? 3 : j+1;



as in C language ?



thx


without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]



Why on earth would you recommend this outdated hack, when there's a true 
conditional operator?


j = 3 if j = 10 else j+1

Of course, many people feel like the conditional operator isn't worth 
the squished-up unreadability, but if someone asks for a conditional 
operator, at least show them one!


--
Ned Batchelder, http://nedbatchelder.com

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


403 forbidden error

2014-10-22 Thread diyaraik
Hai,

  Could anyone please help me to resolve 403 forbidden error while logging into 
an application.

Following is the error details:

Traceback (most recent call last):
  File ./example6.py, line 18, in module
response = urllib2.urlopen(req)
  File /usr/lib/python2.7/urllib2.py, line 126, in urlopen
return _opener.open(url, data, timeout)
  File /usr/lib/python2.7/urllib2.py, line 406, in open
response = meth(req, response)
  File /usr/lib/python2.7/urllib2.py, line 519, in http_response
'http', request, response, code, msg, hdrs)
  File /usr/lib/python2.7/urllib2.py, line 444, in error
return self._call_chain(*args)
  File /usr/lib/python2.7/urllib2.py, line 378, in _call_chain
result = func(*args)
  File /usr/lib/python2.7/urllib2.py, line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: FORBIDDEN


Sorry if the question is not relevant as im new to python.


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


Re: (test) ? a:b

2014-10-22 Thread Mark Lawrence

On 22/10/2014 10:27, Chris Angelico wrote:

On Wed, Oct 22, 2014 at 8:16 PM, Mark Lawrence breamore...@yahoo.co.uk wrote:

without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]



The death penalty should be reintroduced into the UK for two crimes, writing
code like the above and using google groups.


No no no. Code like that doesn't deserve death, just community
service. I've seen much MUCH worse... where multiple conditional
expressions get combined arithmetically, and then the result used
somewhere... I also may have been guilty of same, myself, though I'm
going to plead the internet's equivalent of the Fifth Amendment to the
US Constitution and not incriminate myself by showing the code...

ChrisA



Perhaps you're correct.  Is there anything worse than looking at a 
dreadful piece of code that makes no sense at all and knowing that you'd 
written it six months earlier?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: (test) ? a:b

2014-10-22 Thread Marko Rauhamaa
Ned Batchelder n...@nedbatchelder.com:

 Why on earth would you recommend this outdated hack, when there's a
 true conditional operator? [...] if someone asks for a conditional
 operator, at least show them one!

No good deed goes unpunished.


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


Re: (test) ? a:b

2014-10-22 Thread Mark Lawrence

On 22/10/2014 10:14, ast wrote:


busca...@gmail.com a écrit dans le message de
news:7839376e-fc27-4299-ae63-4ddf17ef9...@googlegroups.com...

Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:

Hello



Is there in Python something like:



j = (j = 10) ? 3 : j+1;



as in C language ?



thx


without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]



Oh it's a trick !
thx


IMHO it's just dreadful.  Why people insist on messing around like this 
I really don't know, it just drives me nuts.


Also would you please access this list via 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing double line spacing and single line paragraphs, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Problems with selenium 2 and python 3.4.1

2014-10-22 Thread novozhiloffvadim
Hi all, i have a little problem. I have a simple automation to fill login form 
fields. Actually, it passes good, but there's the problem. I need to see actual 
output in my console after the script filled fields, like Logged in 
successfully or Username not found. I tried many stuff, but nothing worked 
this way, my last try was while loop and it works great, but only when I have 
positive result. I wrote a second condition, but when I type incorrect data, it 
drives me crazy to see all these errors in my console. So here's the code and 
part of output, any help or thoughts would be appreciated.

code
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException

baseurl = http://www.somesite/login;
email = input(Type an email: )
password = input(Type a password: )

xpaths = { 'loginBox' : //input[@id='session_email'],
   'passwordBox' : //input[@id='session_password'],
   'submitButton' :   //input[@class='ufs-but'],
   'success' : //div[@class='flash-message success'],
   'error' : //span[@class='form_error']
 }


mydriver = webdriver.Firefox()
mydriver.get(baseurl)


mydriver.find_element_by_xpath(xpaths['loginBox']).send_keys(email)


mydriver.find_element_by_xpath(xpaths['passwordBox']).send_keys(password)


mydriver.find_element_by_xpath(xpaths['submitButton']).click()


while mydriver.find_element_by_xpath(xpaths['success']):
print(Success)
if mydriver.find_element_by_xpath(xpaths['error']):
print(No)
/code

And there's what I got when I try to interrupt an error:

File ab.py, line 32, in module
while mydriver.find_element_by_xpath(xpaths['success']):
  File 
/usr/local/lib/python3.4/site-packages/selenium-2.43.0-py3.4.egg/selenium/webdriver/remote/webdriver.py,
 line 230, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
  File 
/usr/local/lib/python3.4/site-packages/selenium-2.43.0-py3.4.egg/selenium/webdriver/remote/webdriver.py,
 line 662, in find_element
{'using': by, 'value': value})['value']
  File 
/usr/local/lib/python3.4/site-packages/selenium-2.43.0-py3.4.egg/selenium/webdriver/remote/webdriver.py,
 line 173, in execute
self.error_handler.check_response(response)
  File 
/usr/local/lib/python3.4/site-packages/selenium-2.43.0-py3.4.egg/selenium/webdriver/remote/errorhandler.py,
 line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: 'Unable to locate 
element: {method:xpath,selector://div[@class=\'flash-message 
success\']}' ; Stacktrace: 
at FirefoxDriver.prototype.findElementInternal_ 
(file:///tmp/tmpjax8kj1u/extensions/fxdri...@googlecode.com/components/driver-component.js:9618:26)
at FirefoxDriver.prototype.findElement 
(file:///tmp/tmpjax8kj1u/extensions/fxdri...@googlecode.com/components/driver-component.js:9627:3)
at DelayedCommand.prototype.executeInternal_/h 
(file:///tmp/tmpjax8kj1u/extensions/fxdri...@googlecode.com/components/command-processor.js:11612:16)
at DelayedCommand.prototype.executeInternal_ 
(file:///tmp/tmpjax8kj1u/extensions/fxdri...@googlecode.com/components/command-processor.js:11617:7)
at DelayedCommand.prototype.execute/ 
(file:///tmp/tmpjax8kj1u/extensions/fxdri...@googlecode.com/components/command-processor.js:11559:5)
 

As I said, successfull result ain't a problem. Hope to get any help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 403 forbidden error

2014-10-22 Thread Chris Angelico
On Wed, Oct 22, 2014 at 10:36 PM,  diyar...@gmail.com wrote:
   Could anyone please help me to resolve 403 forbidden error while logging 
 into an application.

That comes down tot he server you're talking to. Maybe your
username/password is wrong, or maybe you need to send back a cookie,
or something. If you do some web searches, you should be able to find
some info about HTTP; the better you understand the protocol, the more
you'll understand of what urllib2 is saying.

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


Re: (test) ? a:b

2014-10-22 Thread Rustom Mody
On Wednesday, October 22, 2014 5:01:08 PM UTC+5:30, Ned Batchelder wrote:
 On 10/22/14 5:05 AM, buscacio wrote:
  Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
  Hello
  Is there in Python something like:
  j = (j = 10) ? 3 : j+1;
  as in C language ?
  thx
  without not:
  j = [j+1, 3][j=10]
  with not:
  j = [3, j+1][not (j=10)]

 Why on earth would you recommend this outdated hack, when there's a true 
 conditional operator?


To learn a bit about the interchangeability of control and data structures?

[Just playing devil's advocate]

Doesn't change the fact that as a practice it should not be done
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (-1)**1000

2014-10-22 Thread Ian Kelly
On Wed, Oct 22, 2014 at 5:02 AM, Peter Otten __pete...@web.de wrote:
 Michiel Overtoom wrote:


 On Oct 22, 2014, at 12:29, Peter Otten wrote:

 That looks like log(a) while a parity check takes constant time:
 $ python3 -m timeit -s 'a = 10**10' 'a  1'


 Do you mean 'parity' as in http://en.wikipedia.org/wiki/Parity_bit ?
 Because a parity bit denotes whether the *number* of '1' bits is even or
 odd, not the value of the least significant bit.

 No, I meant the lsb. The OP introduced the term 'parity'; not sure if that
 was erroneous, too, or if there is an angle to the problem that escapes me.

Since the OP just wrote parity, not parity bit, I would assume
they meant as in http://en.wikipedia.org/wiki/Parity_(mathematics)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (-1)**1000

2014-10-22 Thread Ian Kelly
On Wed, Oct 22, 2014 at 4:43 AM, Tim Chase
python.l...@tim.thechases.com wrote:
 On 2014-10-22 12:29, Peter Otten wrote:
 That looks like log(a) while a parity check takes constant time:

 $ python3 -m timeit -s 'a = 10**10' 'a  1'
 1000 loops, best of 3: 0.124 usec per loop
 $ python3 -m timeit -s 'a = 10**100' 'a  1'
 1000 loops, best of 3: 0.124 usec per loop
 $ python3 -m timeit -s 'a = 10**1000' 'a  1'
 1000 loops, best of 3: 0.122 usec per loop

 Just for the record, this is a one-bit even/odd check

Which is just a verbose way of writing parity check, even if that
phrase is usually used in another context.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Flush stdin

2014-10-22 Thread random832
On Tue, Oct 21, 2014, at 19:16, Dan Stromberg wrote:
 Actually, doesn't line buffering sometimes exist inside an OS kernel?
 stty/termios/termio/sgtty relate here, for *ix examples.  Supporting
 code: http://stromberg.dnsalias.org/~strombrg/ttype/  It turns on
 character-at-a-time I/O in the tty driver via a variety of methods for
 portability.  I wrote it in C before I took an interest in Python.

Yes, and 90% of the time, when someone says they want to flush stdin,
what they really want to do is go to the next line after they've
sloppily read part of the line they're on (and the behavior they are
seeing that they object to is that their next read function reads the
rest of the current line). The appropriate course of action in these
cases is to actually read to the next newline and discard the data, not
to do any kind of flush.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (-1)**1000

2014-10-22 Thread Ned Batchelder

On 10/22/14 5:27 AM, ast wrote:


Chris Angelico ros...@gmail.com a écrit dans le message de
news:mailman.15058.1413968065.18130.python-l...@python.org...

On Wed, Oct 22, 2014 at 7:27 PM, ast nom...@invalid.com wrote:

If i am writing (-1)**1000 on a python program, will the
interpreter do (-1)*(-1)*...*(-1) or something clever ?

In fact i have (-1)**N with N an integer potentially big.


Exponentiation is far more efficient than the naive implementation of
iterated multiplication.


In the very particular case of (-1)**N,  I belive that Python check
the odd or even parity of N and provides the result accordingly.

I tried:

(-1)**10

1

(-1)**11

-1

and it is instantaneous




Keep in mind that actually calculating the exponentiation wouldn't do 
10 multiplications anyway: the clever 
way to do integer powers is by squaring based on the binary 
representation of the exponent.  It's explained here: 
http://stackoverflow.com/a/101613/14343


So even if Python is actually calculating the value, it's only doing 75 
multiplications or so.


--
Ned Batchelder, http://nedbatchelder.com

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


Re: (test) ? a:b

2014-10-22 Thread alister
On Wed, 22 Oct 2014 12:41:49 +0100, Mark Lawrence wrote:

 On 22/10/2014 10:27, Chris Angelico wrote:
 On Wed, Oct 22, 2014 at 8:16 PM, Mark Lawrence
 breamore...@yahoo.co.uk wrote:
 without not:
 j = [j+1, 3][j=10]
 with not:
 j = [3, j+1][not (j=10)]


 The death penalty should be reintroduced into the UK for two crimes,
 writing code like the above and using google groups.

 No no no. Code like that doesn't deserve death, just community service.
 I've seen much MUCH worse... where multiple conditional expressions get
 combined arithmetically, and then the result used somewhere... I also
 may have been guilty of same, myself, though I'm going to plead the
 internet's equivalent of the Fifth Amendment to the US Constitution and
 not incriminate myself by showing the code...

 ChrisA


 Perhaps you're correct.  Is there anything worse than looking at a
 dreadful piece of code that makes no sense at all and knowing that you'd
 written it six months earlier?

looking a a dreadful piece of unreadable  unfathomable code  knowing 
you wrote it only Yesterday ;-) 



-- 
Chamberlain's Laws:
(1) The big guys always win.
(2) Everything tastes more or less like chicken.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-22 Thread Chris Angelico
On Thu, Oct 23, 2014 at 2:12 AM, alister
alister.nospam.w...@ntlworld.com wrote:
 Perhaps you're correct.  Is there anything worse than looking at a
 dreadful piece of code that makes no sense at all and knowing that you'd
 written it six months earlier?

 looking a a dreadful piece of unreadable  unfathomable code  knowing
 you wrote it only Yesterday ;-)

Sounds like you have some experience with Perl...

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


Re: (test) ? a:b

2014-10-22 Thread alister
On Thu, 23 Oct 2014 02:18:42 +1100, Chris Angelico wrote:

 On Thu, Oct 23, 2014 at 2:12 AM, alister
 alister.nospam.w...@ntlworld.com wrote:
 Perhaps you're correct.  Is there anything worse than looking at a
 dreadful piece of code that makes no sense at all and knowing that
 you'd written it six months earlier?

 looking a a dreadful piece of unreadable  unfathomable code  knowing
 you wrote it only Yesterday ;-)
 
 Sounds like you have some experience with Perl...
 
 ChrisA

Never met the girl I deny everything.

Actual no experience in perl  my professional programming experience is 
limited to 8 bit assembler (68XX  8051) 30 years ago. 
c  c++ were too low level for my liking so I started looking at python 
for fun on my Linux box's and was blown away by its smoothness.

-- 
On the other hand, life can be an endless parade of TRANSSEXUAL
QUILTING BEES aboard a cruise ship to DISNEYWORLD if only we let it!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Flush stdin

2014-10-22 Thread Marko Rauhamaa
random...@fastmail.us:

 Yes, and 90% of the time, when someone says they want to flush
 stdin, what they really want to do is go to the next line after
 they've sloppily read part of the line they're on (and the behavior
 they are seeing that they object to is that their next read function
 reads the rest of the current line). The appropriate course of action
 in these cases is to actually read to the next newline and discard the
 data, not to do any kind of flush.

I'm not sure I have seen that. However, somewhat analogously, there are
linux text utilities that read a number of lines and leave the input
intact. Since you can't really effectively read lines, the utilities
routinely read past the designated endpoint and then seek back to the
end of the line.

For example, consider this script:

seq 2 test.dat
{
 head -n 5 /dev/null
 head -n 5
} test.dat

which outputs:

6
7
8
9
10

However, if I modify the script slightly:

seq 2 | {
 head -n 5 /dev/null
 head -n 5
}

I get:


1861
1862
1863
1864

because you can't seek back a pipe. The first head command has
greedily read in the first 1860 lines and the second one continues where
the first one left off.


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


Re: When to use assert

2014-10-22 Thread Steven D'Aprano
Chris Angelico wrote:

 On Wed, Oct 22, 2014 at 12:44 PM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
 def do_something(instance_or_id):
 instance = Model.get(instance_or_id)
 assert isinstance(instance, Model)
 # Code that assumes that instance is an object of type Model


 That means that the logic for what is acceptable as a Model is all in one
 place, namely the Model.get method, and callers don't need to care about
 the pre-condition argument is a Model or an integer ID, they only need
 to care about the post-condition result of get() is a Model.
 
 And at that point, the assertion is redundant, on par with:
 
 a = len(seq)
 assert isinstance(a, int)
 
 because you shouldn't have to assert what's part of a function's
 guarantee.

That depends on how well you trust the function, how paranoid you are, and
whether you wish to include a checked comment, among other considerations.
I'd prefer to write the above than:

a = len(seq)
# At this point, a is an int.

because comments inside code that aren't checked are technically known
as lies http://import-that.dreamwidth.org/956.html. Ha ha only serious.

I wouldn't write such a comment for len() since I would expect anyone
reading the code to know what len() does, but the same doesn't necessarily
apply for every function call I make.

Checking the post-condition of a built-in like len() is too paranoid for my
tastes, as len() enforces the rule that __len__() methods return a
non-negative integer, and there are millions of lines of Python code around
the world calling len(). Somebody surely have noticed by now if len()
violated that post-condition. But for a function from my own code base,
where I might only have dozens of users (oh to have that many!) and fewer
unit tests than perhaps I ought to, I might not be quite so confident that
the assertion was redundant. To err is human, and so there are occasions
when it is appropriate to trust but verify.

As I wrote:

This is why assert can be divisive. Since we can vary in our 
confidence about the correctness of code, one person's useful 
assertion may be another person's useless runtime test.

http://import-that.dreamwidth.org/676.html


-- 
Steven

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


Re: Permissions on files installed by pip?

2014-10-22 Thread Adam Funk
On 2014-10-17, Jean-Michel Pichavant wrote:

 - Original Message -
 From: Adam Funk a24...@ducksburg.com
 To: python-list@python.org
 Sent: Thursday, 16 October, 2014 9:29:46 PM
 Subject: Permissions on files installed by pip?
 
 I've been using the python-nltk package on Ubuntu, but I need ntlk
 3.0
 now.  I used 'sudo aptitude purge python-nltk' to get rid of my
 existing installation,  followed instructions on the nltk website
 [1]
 starting at step 4 (since I already have python-pip  python-numpy
 packages installed).
 
 $ sudo pip install -U
 
 I couldn't get it to work, until I realized that the permissions 
 ownership on /usr/local/lib/python2.7/dist-packages were 'drwx--S---
 root staff'.  A 'chmod -R a+rX' on that directory seems to have fixed
 it.  Is it normal for sudo pip install to set the permissions that
 way, or did I do something wrong?

 On debian wheezy:

 ls -al /usr/local/lib/python2.7/dist-packages  

 drwxrwsr-x 5 root staff 4.0K Jun 30 15:16 ./

 I'm not sure pip is responsible for this anyway, so my money goes on you did 
 something wrong :)

Probably something to do with the way I have sudo set up then.
Thanks.


-- 
Everybody says sex is obscene. The only true obscenity 
is war.   --- Henry Miller
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When to use assert

2014-10-22 Thread Chris Angelico
On Thu, Oct 23, 2014 at 2:49 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Chris Angelico wrote:

 And at that point, the assertion is redundant, on par with:

 a = len(seq)
 assert isinstance(a, int)

 because you shouldn't have to assert what's part of a function's
 guarantee.

 That depends on how well you trust the function, how paranoid you are, and
 whether you wish to include a checked comment, among other considerations.
 I'd prefer to write the above than:

 a = len(seq)
 # At this point, a is an int.

 because comments inside code that aren't checked are technically known
 as lies http://import-that.dreamwidth.org/956.html. Ha ha only serious.
 ...
 Checking the post-condition of a built-in like len() is too paranoid for my
 tastes...

 As I wrote:

 This is why assert can be divisive. Since we can vary in our
 confidence about the correctness of code, one person's useful
 assertion may be another person's useless runtime test.

I agree that the assert is preferable to the comment. But maybe my
level of paranoia is just lower than most people's, as I wouldn't
bother checking the post-conditions of pretty much anything. Do you
put these assertions every time you call the function? Every time
you're depending on its return value? At what point should you stop
writing Python code and start using a language with a lot more
boilerplate and checking (I believe Haskell fits that, though I'm not
overly familiar with the language)?

This is the job of a test suite. You don't pepper your code with
assertions to the effect that I just pushed something onto my queue,
it should now have this item in it; you create a test case for it,
and verify your function there. In the rest of the code, you trust
that your test suite passes, and don't waste time with assertions.

Or is that insufficiently paranoid?

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


Re: (test) ? a:b

2014-10-22 Thread Dan Stromberg
On Wed, Oct 22, 2014 at 2:05 AM,  busca...@gmail.com wrote:
 Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
 Hello



 Is there in Python something like:



 j = (j = 10) ? 3 : j+1;



 as in C language ?



 thx

 without not:
 j = [j+1, 3][j=10]
 with not:
 j = [3, j+1][not (j=10)]

This is not very readable, and eagerly evaluates the two list values.
A proper ternary operator will not evaluate the unused
candidate-result. This matters a little for performance, but matters
more if one or both of the candidate results have side-effects.

It's better to use j = 3 if j = 10 else j + 1.

What you've suggested here was one of the ternary operator workarounds
before a true ternary operator was introduced in 2.5.

I don't use Python's ternary operator much though - I tend to find
if+else more clear, and it shows up well in a debugger. The ternary
operator tends to lead to long one-liners (especially if nested!),
which are usually best avoided.

I'd even go so far as to say that most uses of a ternary operator
probably should be a small function.  It's slower, but it lends itself
to DRY and abstraction better.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When to use assert

2014-10-22 Thread Dan Stromberg
On Wed, Oct 22, 2014 at 9:01 AM, Chris Angelico ros...@gmail.com wrote:
 On Thu, Oct 23, 2014 at 2:49 AM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
 Chris Angelico wrote:
 I agree that the assert is preferable to the comment. But maybe my
 level of paranoia is just lower than most people's, as I wouldn't
 bother checking the post-conditions of pretty much anything. Do you
 put these assertions every time you call the function? Every time
 you're depending on its return value? At what point should you stop
 writing Python code and start using a language with a lot more
 boilerplate and checking (I believe Haskell fits that, though I'm not
 overly familiar with the language)?

I like to use assertions and if cond: raise ValueError('foo') a lot.

I think Eiffel may be the poster-child for a language with
pre-conditions, post-conditions and assertions.

I think you're in good company - a lot of developers don't use assertions much.

I like assertions, because they tend to stop bugs pretty quickly.  If
you have 3 functions, one calling another calling another, assertions
in each can keep you from having to backtrack among them when
debugging, instead going directly to the problem's source.

 This is the job of a test suite.

Test suites are great, and I can't really question your reliance on
them.  I love having lots of automated tests.  But for the reason I
described above, I still like having lots of assertions.

 You don't pepper your code with
 assertions to the effect that I just pushed something onto my queue,
 it should now have this item in it; you create a test case for it,
 and verify your function there. In the rest of the code, you trust
 that your test suite passes, and don't waste time with assertions.

I wouldn't test that a value was added to a queue immediately after
adding it.  That's excessive, and may even require an abstraction
violation.

But if, for example, I have a string with 3 known-good values, I'll
if/elif/elif/else, and make the else raise an AssertionError.  The
assertion should never fire, but if the code changes, it could, and if
there's a typo somewhere, it could then too.

 Or is that insufficiently paranoid?

With good tests, you're probably fine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-22 Thread Steven D'Aprano
Ned Batchelder wrote:

 On 10/22/14 5:05 AM, busca...@gmail.com wrote:

 without not:
 j = [j+1, 3][j=10]
 with not:
 j = [3, j+1][not (j=10)]

 
 Why on earth would you recommend this outdated hack, when there's a true
 conditional operator?
 
  j = 3 if j = 10 else j+1

I think that's a bit harsh. Especially since this appears to have been
Buscacio's first post here. Hopefully not his(?) last post!

The old (b, a)[condition] idiom is not outdated for anyone supporting Python
2.4, and I wouldn't call it a hack. Indexing into a sequence with a bool is
basic to Python's semantics: True and False are ints equal to 1 and 0
respectively. It's also a technique easily extensible to more than two
values:

'01TX'[n % 4]

is in my opinion more readable than:

i = n % 4
'0' if i == 0 else '1' if i == 1 else 'T' if i == 3 else 'X'


 Of course, many people feel like the conditional operator isn't worth
 the squished-up unreadability, but if someone asks for a conditional
 operator, at least show them one!

The advantage of the `x if cond else y` operator is that it is a
short-cutting operator, it doesn't evaluate either x or y unless needed.
But for many cases that's not important, and in those cases I won't say I
prefer the old (y, x)[cond] idiom, but neither do I dislike it.


-- 
Steven

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


Re: Python 3.4.1 and blitzdb issue

2014-10-22 Thread Juan Christian
Oh yes, and here is what the call to the API returns:

{adult:false,also_known_as:[George Walton Lucas Jr.
],biography:Arguably the most important film innovator in the history
of the medium, George Lucas continually \pushed the envelope\ of
filmmaking technology since his early days as a student at U.S.C.
Considered a wunderkind by his contemporaries, he had a much harder time
communicating his vision to studio executives, whose meddling managed to
compromise each of his first three feature directing efforts in some way.
The monumental success of \Star Wars\ (1977) ushered in the era of the
\summer blockbuster,\ which, despite the later popularity of low budget
independent films, was still the prevailing mentality powering the
Hollywood engine.\n\nThough he set the tone and established the
expectations which influenced studios to devote the bulk of their resources
to films designed to blast off into hyperspace for spectacular profits, it
was doubtful that a film as revolutionary as \Star Wars\ was in its day
could get made in the later blockbuster assembly line climate of the new
millennium.,birthday:1944-05-14,deathday:,homepage:,id:1,imdb_id:nm184,name:George
Lucas,place_of_birth:Modesto - California -
USA,popularity:2.185575,profile_path:/rJ1zvSeZfge0mHtLnzJn4Mkw18S.jpg}

On Wed, Oct 22, 2014 at 2:34 PM, Juan Christian juan0christ...@gmail.com
wrote:

 Testing code:

 CODE -

 #!/usr/bin/env

 import requests
 from blitzdb import Document, FileBackend


 API_URL = 'http://api.themoviedb.org/3'
 API_KEY = 'ddf30289'


 class Actor(Document):
 pass


 def get_actor(_id):
 r = requests.get('{}/person/{}?api_key={}'.format(API_URL, str(_id),
 API_KEY))
 return r.json()


 actor_1 = Actor(get_actor(1))
 actor_2 = Actor(get_actor(2))

 backend = FileBackend(db.blitz)
 actor_1.save(backend)
 actor_2.save(backend)

 print(backend.get(Actor,{'imdb_id' : 'nm184'}))
 print('\n')
 print(backend.get(Actor,{'imdb_id' : 'nm434'}))


 OUTPUT -

 Warning: cjson could not be imported, CJsonSerializer will not be
 available.
 Traceback (most recent call last):
   File .\uff.py, line 27, in module
 print(backend.get(Actor,{'imdb_id' : 'nm184'}))
   File C:\Python34\lib\site-packages\blitzdb\backends\file\backend.py,
 line 456, in get
 raise cls.DoesNotExist
 blitzdb.document.DoesNotExist: DoesNotExist(Actor)


 QUESTION -

 Why the output says that Actor doesn't exists when I already added it here
 'actor_1.save(backend)' and 'actor_2.save(backend)'

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


Re: Matplotlib: getting a figure to show without plt.show()

2014-10-22 Thread Peter Pearson
On Wed, 22 Oct 2014 12:38:02 +0200, Peter Otten wrote:
 Peter Pearson wrote:
[snip]
 def callback(event):
 global n, first
 fig = plt.figure(2)
 fig.clear()
 plt.plot([0,1],[0,n])
 n += 1  # (Pretending something changes from one plot to the next.)
 if first:
 first = False
 plt.show()
 else:
 fig.canvas.draw()

 Can someone tell me the right way?
[snip]

 def callback(event):
 global n, fig2

 if fig2 is None:
 fig2 = plt.figure(2)

 fig2.clear()
 fig2.gca().plot([0, .5, 1], [0, 1/n, 1])
 fig2.show()

Thank you for pointing out two useful things:

 * I like fig2.gca().plot better than plt.plot, since it makes it
   clear that I'm talking about fig2 and not some other part of the
   vast and inscrutable plt kingdom.

 * fig2.show is different from plt.show, and in fact this solves my
   problem exactly, since fig2.show returns immediately.

By the way, I will dispense with your if fig2 is None test.  In real
life, I say something like fig2 = plt.figure(Packet Sizes).  If a
figure named Packet Sizes doesn't exist, plt.figure creates it,
otherwise it returns a pointer to the existing figure -- *and* it titles
the figure's window with Packet Sizes rather than 2.

[snip]
 As I'm not an expert for matplotlib you might also post your question on the 
 matplotlib mailing list.

Sound advice.  Next time.  Thanks again.


-- 
To email me, substitute nowhere-runbox, invalid-com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 3.4.1 and blitzdb issue

2014-10-22 Thread Juan Christian
Testing code:

CODE -

#!/usr/bin/env

import requests
from blitzdb import Document, FileBackend


API_URL = 'http://api.themoviedb.org/3'
API_KEY = 'ddf30289'


class Actor(Document):
pass


def get_actor(_id):
r = requests.get('{}/person/{}?api_key={}'.format(API_URL, str(_id),
API_KEY))
return r.json()


actor_1 = Actor(get_actor(1))
actor_2 = Actor(get_actor(2))

backend = FileBackend(db.blitz)
actor_1.save(backend)
actor_2.save(backend)

print(backend.get(Actor,{'imdb_id' : 'nm184'}))
print('\n')
print(backend.get(Actor,{'imdb_id' : 'nm434'}))


OUTPUT -

Warning: cjson could not be imported, CJsonSerializer will not be available.
Traceback (most recent call last):
  File .\uff.py, line 27, in module
print(backend.get(Actor,{'imdb_id' : 'nm184'}))
  File C:\Python34\lib\site-packages\blitzdb\backends\file\backend.py,
line 456, in get
raise cls.DoesNotExist
blitzdb.document.DoesNotExist: DoesNotExist(Actor)


QUESTION -

Why the output says that Actor doesn't exists when I already added it here
'actor_1.save(backend)' and 'actor_2.save(backend)'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-22 Thread Chris Angelico
On Thu, Oct 23, 2014 at 3:28 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 It's also a technique easily extensible to more than two
 values:

 '01TX'[n % 4]

 is in my opinion more readable than:

 i = n % 4
 '0' if i == 0 else '1' if i == 1 else 'T' if i == 3 else 'X'

That's true when it's fundamentally arithmetic. But part of that
readability difference is the redundancy in the second one. What if it
weren't so redundant?

'Negative' if x  0 else 'Low' if x  10 else 'Mid' if x  20 else 'High'

You can't easily turn that into a dict lookup, nor indexing. It's
either a chained if/elif tree or nested if/else expressions, which
come to the same thing. So I'd say all the techniques have their
advantages and disadvantages. The most important thing to note is
where they differ in semantics, like the short-circuiting of if/else.

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


Re: Python 3.4.1 and blitzdb issue

2014-10-22 Thread Stéphane Wirtel
Maybe ask on the project on github. Andreas is a good guy and will reply 
asap.



On 22 Oct 2014, at 18:34, Juan Christian wrote:


Testing code:

CODE -

#!/usr/bin/env

import requests
from blitzdb import Document, FileBackend


API_URL = 'http://api.themoviedb.org/3'
API_KEY = 'ddf30289'


class Actor(Document):
 pass


def get_actor(_id):
 r = requests.get('{}/person/{}?api_key={}'.format(API_URL, str(_id),
API_KEY))
 return r.json()


actor_1 = Actor(get_actor(1))
actor_2 = Actor(get_actor(2))

backend = FileBackend(db.blitz)
actor_1.save(backend)
actor_2.save(backend)

print(backend.get(Actor,{'imdb_id' : 'nm184'}))
print('\n')
print(backend.get(Actor,{'imdb_id' : 'nm434'}))


OUTPUT -

Warning: cjson could not be imported, CJsonSerializer will not be 
available.

Traceback (most recent call last):
File .\uff.py, line 27, in module
 print(backend.get(Actor,{'imdb_id' : 'nm184'}))
File C:\Python34\lib\site-packages\blitzdb\backends\file\backend.py,
line 456, in get
 raise cls.DoesNotExist
blitzdb.document.DoesNotExist: DoesNotExist(Actor)


QUESTION -

Why the output says that Actor doesn't exists when I already added it 
here

'actor_1.save(backend)' and 'actor_2.save(backend)'
--
https://mail.python.org/mailman/listinfo/python-list



--
Stéphane Wirtel - http://wirtel.be - @matrixise
--
https://mail.python.org/mailman/listinfo/python-list


Re: (-1)**1000

2014-10-22 Thread Terry Reedy

On 10/22/2014 4:27 AM, ast wrote:

Hello

If i am writing (-1)**1000 on a python program, will the
interpreter do (-1)*(-1)*...*(-1) or something clever ?


The answer depends on the implementation.


In fact i have (-1)**N with N an integer potentially big.

I do some tests that suggest that Python is clever


You probably mean CPython is clever.  Other implementations may or may 
not have the same optimizations.




--
Terry Jan Reedy

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


Re: (test) ? a:b

2014-10-22 Thread Michael Torrie
On 10/22/2014 05:45 AM, Mark Lawrence wrote:
 without not:
 j = [j+1, 3][j=10]
 with not:
 j = [3, j+1][not (j=10)]


 Oh it's a trick !
 thx
 
 IMHO it's just dreadful.  Why people insist on messing around like this 
 I really don't know, it just drives me nuts.

This actually was the standard idiom used by many python programs before
Python 2.5.  But I agree.  Don't do this anymore! Python has a ternary
if expression. Also the ternary if expression does, I believe
short-circuit logic, so the non-chosen path is not calculated.  This
hack does not. Could lead to interesting bugs depending on your assumptions.

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


Re: (test) ? a:b

2014-10-22 Thread alister
On Thu, 23 Oct 2014 03:28:48 +1100, Steven D'Aprano wrote:

 Why on earth would you recommend this outdated hack, when there's a
 true conditional operator?
 
  j = 3 if j = 10 else j+1
 
 I think that's a bit harsh. Especially since this appears to have been
 Buscacio's first post here. Hopefully not his(?) last post!
 
 The old (b, a)[condition] idiom is not outdated for anyone supporting
 Python 2.4, and I wouldn't call it a hack. Indexing into a sequence with
 a bool is basic to Python's semantics: True and False are ints equal to
 1 and 0 respectively. It's also a technique easily extensible to more
 than two values:
 
 '01TX'[n % 4]
 
 is in my opinion more readable than:
 
 i = n % 4 '0' if i == 0 else '1' if i == 1 else 'T' if i == 3 else
 'X'

chained ternary operations are evil no mater what style or language they 
are written in as they rapidly become confusing  unreadable

Readability counts

in my opinion they are better written as nested if statements 

-- 
Ambiguity:
Telling the truth when you don't mean to.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-22 Thread BartC



Rustom Mody rustompm...@gmail.com wrote in message 
news:7d2ea3c1-504e-4f5c-8338-501b1483d...@googlegroups.com...

On Wednesday, October 22, 2014 5:01:08 PM UTC+5:30, Ned Batchelder wrote:

On 10/22/14 5:05 AM, buscacio wrote:
 Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast 
 escreveu:

 Hello
 Is there in Python something like:
 j = (j = 10) ? 3 : j+1;
 as in C language ?
 thx
 without not:
 j = [j+1, 3][j=10]
 with not:
 j = [3, j+1][not (j=10)]



Why on earth would you recommend this outdated hack, when there's a true
conditional operator?



To learn a bit about the interchangeability of control and data 
structures?


[Just playing devil's advocate]


But it doesn't do the same thing.

Comparing:

x = cond ? f() : g();   # C version

with

x = [f(), g()] [cond]

the latter evaluates both f() and g() instead of just one. Apart from being 
inefficient, it can have unintended side-effects.


--
Bartc



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


Re: (test) ? a:b

2014-10-22 Thread Matthew Ruffalo
On 10/22/2014 12:40 PM, Chris Angelico wrote:
 That's true when it's fundamentally arithmetic. But part of that
 readability difference is the redundancy in the second one. What if it
 weren't so redundant?

 'Negative' if x  0 else 'Low' if x  10 else 'Mid' if x  20 else 'High'

 You can't easily turn that into a dict lookup, nor indexing. It's
 either a chained if/elif tree or nested if/else expressions, which
 come to the same thing.
No, you can't turn that into a dict lookup, but this is one of the
canonical use cases for the bisect module:

 from bisect import bisect
 breakpoints = [0, 10, 20]
 labels = ['Negative', 'Low', 'Mid', 'High']
 values = [-5, 5, 15, 25]
 [labels[bisect(breakpoints, value)] for value in values]
['Negative', 'Low', 'Mid', 'High']

It's also worth noting that using bisect is O(log(n)) instead of O(n),
but if you're going to hit a point where the asymptotic behavior matters
I'm sure you will have long since abandoned a manually-written if/elif
chain.

MMR...

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


Re: (test) ? a:b

2014-10-22 Thread Chris Angelico
On Thu, Oct 23, 2014 at 5:27 AM, Matthew Ruffalo mm...@case.edu wrote:
 On 10/22/2014 12:40 PM, Chris Angelico wrote:
 That's true when it's fundamentally arithmetic. But part of that
 readability difference is the redundancy in the second one. What if it
 weren't so redundant?

 'Negative' if x  0 else 'Low' if x  10 else 'Mid' if x  20 else 'High'

 You can't easily turn that into a dict lookup, nor indexing. It's
 either a chained if/elif tree or nested if/else expressions, which
 come to the same thing.
 No, you can't turn that into a dict lookup, but this is one of the
 canonical use cases for the bisect module:

 from bisect import bisect
 breakpoints = [0, 10, 20]
 labels = ['Negative', 'Low', 'Mid', 'High']
 values = [-5, 5, 15, 25]
 [labels[bisect(breakpoints, value)] for value in values]
 ['Negative', 'Low', 'Mid', 'High']

 It's also worth noting that using bisect is O(log(n)) instead of O(n),
 but if you're going to hit a point where the asymptotic behavior matters
 I'm sure you will have long since abandoned a manually-written if/elif
 chain.

Indeed. If the performance is making any difference, something's gone
wrong. I'm seeing that as not significantly clearer than the chained
if/else statement or expression: you need a list of breakpoints and a
list of results, which need to be kept in sync. But there's probably
no ideal solution to this.

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


setuptools + data_files = 2

2014-10-22 Thread luc2
hello, would you know how to make data_files work in setuptools ?
i can't figure out how to put datas in the generated .tar.gz

$ find .
./hello
./hello/__init__.py
./share
./share/test_file.txt
./setup.py

$ cat ./hello/__init__.py
def hello():
print( 'hello' )

$ cat ./share/test_file.txt
this is a test

$ cat ./hello/setup.py
from setuptools import setup, find_packages
setup(
name = Hello,
version = 0.1,
packages = find_packages(),
data_files = [
( 'share', ['share/test_file.txt'] )
]
)

$ python setup.py sdist

$ tar tvf dist/Hello-0.1.tar.gz | grep test_file.txt

$ echo no test_file.txt :-(
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-22 Thread Ned Batchelder

On 10/22/14 12:28 PM, Steven D'Aprano wrote:

Ned Batchelder wrote:


On 10/22/14 5:05 AM, busca...@gmail.com wrote:



without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]



Why on earth would you recommend this outdated hack, when there's a true
conditional operator?

  j = 3 if j = 10 else j+1


I think that's a bit harsh. Especially since this appears to have been
Buscacio's first post here. Hopefully not his(?) last post!


You are right, it sounds a bit harsh. Sorry.

--
Ned Batchelder, http://nedbatchelder.com

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


I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
def nametonumber(name):
lst=[]
for x,y in enumerate (name):
lst=lst.append(y)
print (lst)
return (lst)
a=[1-800-getcharter]
print (nametonumber(a))#18004382427837

  
The syntax for when to use a () and when to use [] still throws me a
curve.

For now, I am trying to end up with a list that has each character in
a as a single item.

I get:
None
None
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-22 Thread Joel Goldstick
On Wed, Oct 22, 2014 at 4:30 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 def nametonumber(name):
 lst=[]
 for x,y in enumerate (name):
 lst=lst.append(y)
 print (lst)
 return (lst)
 a=[1-800-getcharter]
 print (nametonumber(a))#18004382427837


 The syntax for when to use a () and when to use [] still throws me a
 curve.
() is tuples which are immutable which means that the items can't be
changed.  [] is list which means that each item can be changed.
Tuples are useful because they can be used as keys in dictionaries and
are guarantied not to change.  Lists are useful because they can be
updated.

What you are doing confuses me.  You don't use x, which is the enumerated value.

FIrst lst should be lst = [] .  You don't need to set the first
element in the list to an empty string.  You just want to establish
that you have an empty list called lst
Second, you don't need lst = lst.append(y) because you can just say
lst.append(y).  This will append the y value to the end of the list.
As to converting letters to the corresponding numbers on a phone
keypad, you don't show you code here for that

 For now, I am trying to end up with a list that has each character in
 a as a single item.

 I get:
 None
 None
 --
 https://mail.python.org/mailman/listinfo/python-list



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


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Wed, 22 Oct 2014 16:57:00 -0400, Joel Goldstick
joel.goldst...@gmail.com wrote:

On Wed, Oct 22, 2014 at 4:30 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 def nametonumber(name):
 lst=[]
 for x,y in enumerate (name):
 lst=lst.append(y)
 print (lst)
 return (lst)
 a=[1-800-getcharter]
 print (nametonumber(a))#18004382427837


 The syntax for when to use a () and when to use [] still throws me a
 curve.
() is tuples which are immutable which means that the items can't be
changed.  [] is list which means that each item can be changed.
Tuples are useful because they can be used as keys in dictionaries and
are guarantied not to change.  Lists are useful because they can be
updated.

What you are doing confuses me.  You don't use x, which is the enumerated 
value.

FIrst lst should be lst = [] .  You don't need to set the first
element in the list to an empty string.  You just want to establish
that you have an empty list called lst
Second, you don't need lst = lst.append(y) because you can just say
lst.append(y).  This will append the y value to the end of the list.
As to converting letters to the corresponding numbers on a phone
keypad, you don't show you code here for that

 For now, I am trying to end up with a list that has each character in
 a as a single item.

 I get:
 None
 None
 --
 https://mail.python.org/mailman/listinfo/python-list

The lst=lst.append(y)
Was the mistake I never could see.

I am using enumerate just for practice.  To me that is just as easy as
typing len(something) and it seems more flexible.

and...the reason I don't show the code for the conversions is that
I haven't got that far yet.  :)

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


Re: I am out of trial and error again Lists

2014-10-22 Thread Mark Lawrence

On 22/10/2014 21:57, Joel Goldstick wrote:

On Wed, Oct 22, 2014 at 4:30 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:

def nametonumber(name):
 lst=[]
 for x,y in enumerate (name):
 lst=lst.append(y)
 print (lst)
 return (lst)
a=[1-800-getcharter]
print (nametonumber(a))#18004382427837


The syntax for when to use a () and when to use [] still throws me a
curve.

() is tuples which are immutable which means that the items can't be
changed.  [] is list which means that each item can be changed.
Tuples are useful because they can be used as keys in dictionaries and
are guarantied not to change.  Lists are useful because they can be
updated.



This is wrong, commas define tuples.

type mytest.py
a = 1, 2
print(type(a))

c:\Users\Mark\MyPythonmytest.py
class 'tuple'


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: I am out of trial and error again Lists

2014-10-22 Thread sohcahtoa82
On Wednesday, October 22, 2014 2:06:35 PM UTC-7, Seymore4Head wrote:
 On Wed, 22 Oct 2014 16:57:00 -0400, Joel Goldstick
 joel.goldst...@gmail.com wrote:
 
 On Wed, Oct 22, 2014 at 4:30 PM, Seymore4Head
 Seymore4Head@hotmail.invalid wrote:
  def nametonumber(name):
  lst=[]
  for x,y in enumerate (name):
  lst=lst.append(y)
  print (lst)
  return (lst)
  a=[1-800-getcharter]
  print (nametonumber(a))#18004382427837
 
 
  The syntax for when to use a () and when to use [] still throws me a
  curve.
 () is tuples which are immutable which means that the items can't be
 changed.  [] is list which means that each item can be changed.
 Tuples are useful because they can be used as keys in dictionaries and
 are guarantied not to change.  Lists are useful because they can be
 updated.
 
 What you are doing confuses me.  You don't use x, which is the enumerated 
 value.
 
 FIrst lst should be lst = [] .  You don't need to set the first
 element in the list to an empty string.  You just want to establish
 that you have an empty list called lst
 Second, you don't need lst = lst.append(y) because you can just say
 lst.append(y).  This will append the y value to the end of the list.
 As to converting letters to the corresponding numbers on a phone
 keypad, you don't show you code here for that
 
  For now, I am trying to end up with a list that has each character in
  a as a single item.
 
  I get:
  None
  None
  --
  https://mail.python.org/mailman/listinfo/python-list
 
 The lst=lst.append(y)
 Was the mistake I never could see.
 
 I am using enumerate just for practice.  To me that is just as easy as
 typing len(something) and it seems more flexible.
 
 and...the reason I don't show the code for the conversions is that
 I haven't got that far yet.  :)
 
 Thank you

I'm still confused as to why you're using enumerate.  Using it when you don't 
need to for practice just seems strange.  You don't even need to use 
len(something) in your case.  You should just be using 'for y in name:' if you 
don't need that x.  Enumerate is essentially just a shortcut to zipping a range 
based on the length.  For example...

for x, y in enumerate(name):

is equivalent to:

for x, y in zip(range(len(name)), name):

And both are pointless if you're not using the x.

Also, is there a reason why you're defining 'a' to be a list with a single 
string value, rather than just defining it as a string?  It seems like you 
should probably just have:

a = 1-800-getcharter
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Wed, 22 Oct 2014 14:35:18 -0700 (PDT), sohcahto...@gmail.com wrote:

On Wednesday, October 22, 2014 2:06:35 PM UTC-7, Seymore4Head wrote:
 On Wed, 22 Oct 2014 16:57:00 -0400, Joel Goldstick
 joel.goldst...@gmail.com wrote:
 
 On Wed, Oct 22, 2014 at 4:30 PM, Seymore4Head
 Seymore4Head@hotmail.invalid wrote:
  def nametonumber(name):
  lst=[]
  for x,y in enumerate (name):
  lst=lst.append(y)
  print (lst)
  return (lst)
  a=[1-800-getcharter]
  print (nametonumber(a))#18004382427837
 
 
  The syntax for when to use a () and when to use [] still throws me a
  curve.
 () is tuples which are immutable which means that the items can't be
 changed.  [] is list which means that each item can be changed.
 Tuples are useful because they can be used as keys in dictionaries and
 are guarantied not to change.  Lists are useful because they can be
 updated.
 
 What you are doing confuses me.  You don't use x, which is the enumerated 
 value.
 
 FIrst lst should be lst = [] .  You don't need to set the first
 element in the list to an empty string.  You just want to establish
 that you have an empty list called lst
 Second, you don't need lst = lst.append(y) because you can just say
 lst.append(y).  This will append the y value to the end of the list.
 As to converting letters to the corresponding numbers on a phone
 keypad, you don't show you code here for that
 
  For now, I am trying to end up with a list that has each character in
  a as a single item.
 
  I get:
  None
  None
  --
  https://mail.python.org/mailman/listinfo/python-list
 
 The lst=lst.append(y)
 Was the mistake I never could see.
 
 I am using enumerate just for practice.  To me that is just as easy as
 typing len(something) and it seems more flexible.
 
 and...the reason I don't show the code for the conversions is that
 I haven't got that far yet.  :)
 
 Thank you

I'm still confused as to why you're using enumerate.  Using it when you don't 
need to for practice just seems strange.  You don't even need to use 
len(something) in your case.  You should just be using 'for y in name:' if you 
don't need that x.  Enumerate is essentially just a shortcut to zipping a 
range based on the length.  For example...

for x, y in enumerate(name):

is equivalent to:

for x, y in zip(range(len(name)), name):

And both are pointless if you're not using the x.

Also, is there a reason why you're defining 'a' to be a list with a single 
string value, rather than just defining it as a string?  It seems like you 
should probably just have:

a = 1-800-getcharter


The lst=lst part was throwing an error I didn't understand.  That was
the only reason I added brackets around the 'a'.  I was getting in to
trial and error stuff.   Mostly error.

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


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

One more question.
if y in str(range(10)
Why doesn't that work.
I commented it out and just did it long hand

def nametonumber(name):
lst=[]
nx=[]
for x in (name):
lst.append(x)
for y in (lst):
#if y in str(range(10)):
if y in 1234567890:
nx.append(y)
if y in  -():
nx.append(y)
if y in abc:
nx.append(2)
if y in def:
nx.append(3)
if y in ghi:
nx.append(4)
if y in jkl:
nx.append(5)
if y in mno:
nx.append(6)
if y in pqrs:
nx.append(7)
if y in tuv:
nx.append(8)
if y in wxyz:
nx.append(9)
number=.join(str(e) for e in nx)
return (number)
a=1-800-getcharter
print (nametonumber(a))#1800 438 2427 837
a=1-800-leo laporte
print (nametonumber(a))
a=1 800 callaprogrammer
print (nametonumber(a))

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


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
BTW I know I didn't check for Caps yet.

On Wed, 22 Oct 2014 18:30:17 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

One more question.
if y in str(range(10)
Why doesn't that work.
I commented it out and just did it long hand

def nametonumber(name):
lst=[]
nx=[]
for x in (name):
lst.append(x)
for y in (lst):
#if y in str(range(10)):
if y in 1234567890:
nx.append(y)
if y in  -():
nx.append(y)
if y in abc:
nx.append(2)
if y in def:
nx.append(3)
if y in ghi:
nx.append(4)
if y in jkl:
nx.append(5)
if y in mno:
nx.append(6)
if y in pqrs:
nx.append(7)
if y in tuv:
nx.append(8)
if y in wxyz:
nx.append(9)
number=.join(str(e) for e in nx)
return (number)
a=1-800-getcharter
print (nametonumber(a))#1800 438 2427 837
a=1-800-leo laporte
print (nametonumber(a))
a=1 800 callaprogrammer
print (nametonumber(a))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-22 Thread Denis McMahon
On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head wrote:

 def nametonumber(name):
 lst=[]
 for x,y in enumerate (name):
 lst=lst.append(y)
 print (lst)
 return (lst)
 a=[1-800-getcharter]
 print (nametonumber(a))#18004382427837
 
 
 The syntax for when to use a () and when to use [] still throws me a
 curve.
 
 For now, I am trying to end up with a list that has each character in
 a as a single item.
 
 I get:
 None None

First of all, an empty list is created with:

emptylist = []

whereas

x = []

creates a list containing one element, that element being an empty 
string. Not the same thing!

Did you try stepping through your code line by line in the interpreter to 
see what happened at each step?

note that append is a method of a list object, it has no return value, 
the original list is modified in place.

 l = [a,b,c]   # declare a list
 l.append( d ) # use the append method
 l   # show the list
['a', 'b', 'c', 'd']

So your line:

lst = lst.append(y)

should be:

lst.append(y)

Finally, did you really intend to pass a single element list into the 
function, or did you intend to pass a string into the function?

There is a difference between:

a=[1-800-getcharter] 

which creates a single element list, the one element is the string 1-800-
getcharter, and:

a=1-800-getcharter

which creates a string variable with the value 1-800-getcharter

when you pass a list containing a string to your function, enumerate will 
look at each list element, so if your list contains one string, enumerate 
will return the pair 0, the_string, so the string gets appended to your 
empty list as a single item.

The code I think you wanted to write is as follows:

def nametonumber(name):
lst=[]
for x,y in enumerate(name):
lst.append(y)
return lst

a=1-800-getcharter
print ( nametonumber(a) )

I suggests that you study very carefully the differences between this and 
your original code until you understand the reason and effect of every 
difference, as only by doing so will you discover the misconceptions 
which you seem to be operating under, and until you can get some of those 
straightened out, you're not going to make a lot of progress.

Try running the original code and my suggested alternative line by line 
in the interpreter, and examining the state of relevant variables after 
each line of execution.

Here's a code file with both your original code and my modified code with 
comprehensive print statements inserted for debugging. By referencing the 
debugging statements back to the code, you should be able to determine 
exactly where in your original code the value of none comes from.

### code starts

print ( original code )

def nametonumber(name):
print (a) name =, name)
lst=[]
print ( b) lst = , lst )
for x,y in enumerate (name):
print ( c) x = , x, ; y = , y, ; lst = , lst )
lst=lst.append(y)
print ( d) lst = , lst )
print (lst)
return (lst)

a=[1-800-getcharter]
print ( e) a = , a )
print (nametonumber(a))

print ( modified code )

def nametonumber2(name):
print (f) name =, name)
lst=[]
print ( g) lst = , lst )
for x,y in enumerate(name):
print ( h) x = , x, ; y = , y, ; lst = , lst )
lst.append(y)
print ( i) lst = , lst )
return lst

a=1-800-getcharter
print ( j) a = , a )
print ( nametonumber2(a) )

### code ends

If you run the above code exactly as it is, you should see in the output 
how the enumeration reacts according to the different data it is given to 
enumerate, and also where lst is assigned the value none.

As I said above, getting your head round why this is happening is 
essential, and I really do suggest that you slow down and try and 
understand these basic concepts, because at the moment it seems you are 
striving to attempt more and more complicated things without 
understanding the basics upon which they are constructed, and like many 
other similar newsgroups, it's been my experience in the past that there 
is limited tolerance here for people who repeatedly make the same basic 
errors without learning from them.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-22 Thread Mark Lawrence

On 22/10/2014 23:30, Seymore4Head wrote:

On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

One more question.
if y in str(range(10)
Why doesn't that work.


Invalid syntax, it should obviously be:-

if y in str(range(10)):

OTOH if you've simply mistyped above what did you expect to happen and 
what actually happened?  Give us the actual code that you ran and the 
full traceback.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: I am out of trial and error again Lists

2014-10-22 Thread MRAB

On 2014-10-22 23:30, Seymore4Head wrote:

On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

One more question.
if y in str(range(10)
Why doesn't that work.


In what way doesn't it work?

If you want to know what it returns, print it out.


I commented it out and just did it long hand

def nametonumber(name):
 lst=[]
 nx=[]
 for x in (name):


You don't need to put the parens around name...


 lst.append(x)
 for y in (lst):


...or around lst.

You're iterating over a string, putting its characters into a list, and
then iterating over that list. You're doing more work than you need to!


 #if y in str(range(10)):
 if y in 1234567890:
 nx.append(y)
 if y in  -():
 nx.append(y)
 if y in abc:
 nx.append(2)
 if y in def:
 nx.append(3)
 if y in ghi:
 nx.append(4)
 if y in jkl:
 nx.append(5)
 if y in mno:
 nx.append(6)
 if y in pqrs:
 nx.append(7)
 if y in tuv:
 nx.append(8)
 if y in wxyz:
 nx.append(9)
 number=.join(str(e) for e in nx)


The list nx already contains strings, so you don't need str here.


 return (number)


You don't need the parens here either.


a=1-800-getcharter
print (nametonumber(a))#1800 438 2427 837
a=1-800-leo laporte
print (nametonumber(a))
a=1 800 callaprogrammer
print (nametonumber(a))



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


Re: Problem with Android Build [SOLVED]

2014-10-22 Thread Cyd Haselton
On Tue, Oct 21, 2014 at 1:57 PM, Chris Angelico ros...@gmail.com wrote:

 On Wed, Oct 22, 2014 at 5:53 AM, Cyd Haselton chasel...@gmail.com wrote:
  I forgot to add...I also removed and/or commented out lines referencing
  Modules/pwdmodule.o.

 Sounds like the normal sort of work involved in porting to a new
 platform. I've done a few of those kinds of jobs - ported Pike to
 OS/2, and to MinGW (there is an official Pike for Windows, but I
 wanted to use MinGW rather than MSVC), and there's a lot of fiddling
 around to be done!

 ChrisA


This problem is fixed. I'd previously removed Makefile commands to build
posixmodule.o because of an undeclared reference to I_PUSH.  After picking
through the source and history, I added them back in and instead added an
#ifndef __ANDROID__ around the function that used I_PUSH.

Ran a make clean...then make, and the newly built python was able to find
sysconfig and build pybuilddir.txt

Running into a different error, which I will post separate from this one.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Wed, 22 Oct 2014 22:43:14 + (UTC), Denis McMahon
denismfmcma...@gmail.com wrote:

On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head wrote:

 def nametonumber(name):
 lst=[]
 for x,y in enumerate (name):
 lst=lst.append(y)
 print (lst)
 return (lst)
 a=[1-800-getcharter]
 print (nametonumber(a))#18004382427837
 
 
 The syntax for when to use a () and when to use [] still throws me a
 curve.
 
 For now, I am trying to end up with a list that has each character in
 a as a single item.
 
 I get:
 None None

First of all, an empty list is created with:

emptylist = []

whereas

x = []

creates a list containing one element, that element being an empty 
string. Not the same thing!

Did you try stepping through your code line by line in the interpreter to 
see what happened at each step?

note that append is a method of a list object, it has no return value, 
the original list is modified in place.

 l = [a,b,c]   # declare a list
 l.append( d ) # use the append method
 l   # show the list
['a', 'b', 'c', 'd']

So your line:

lst = lst.append(y)

should be:

lst.append(y)

Finally, did you really intend to pass a single element list into the 
function, or did you intend to pass a string into the function?

Those string errors were desperate attempts to fix the append error
I didn't understand.  

There is a difference between:

a=[1-800-getcharter] 

which creates a single element list, the one element is the string 1-800-
getcharter, and:

a=1-800-getcharter

which creates a string variable with the value 1-800-getcharter

when you pass a list containing a string to your function, enumerate will 
look at each list element, so if your list contains one string, enumerate 
will return the pair 0, the_string, so the string gets appended to your 
empty list as a single item.

The code I think you wanted to write is as follows:

def nametonumber(name):
lst=[]
for x,y in enumerate(name):
lst.append(y)
return lst

a=1-800-getcharter
print ( nametonumber(a) )

I suggests that you study very carefully the differences between this and 
your original code until you understand the reason and effect of every 
difference, as only by doing so will you discover the misconceptions 
which you seem to be operating under, and until you can get some of those 
straightened out, you're not going to make a lot of progress.

Try running the original code and my suggested alternative line by line 
in the interpreter, and examining the state of relevant variables after 
each line of execution.

Here's a code file with both your original code and my modified code with 
comprehensive print statements inserted for debugging. By referencing the 
debugging statements back to the code, you should be able to determine 
exactly where in your original code the value of none comes from.

### code starts

print ( original code )

def nametonumber(name):
print (a) name =, name)
lst=[]
print ( b) lst = , lst )
for x,y in enumerate (name):
print ( c) x = , x, ; y = , y, ; lst = , lst )
lst=lst.append(y)
print ( d) lst = , lst )
print (lst)
return (lst)

a=[1-800-getcharter]
print ( e) a = , a )
print (nametonumber(a))

print ( modified code )

def nametonumber2(name):
print (f) name =, name)
lst=[]
print ( g) lst = , lst )
for x,y in enumerate(name):
print ( h) x = , x, ; y = , y, ; lst = , lst )
lst.append(y)
print ( i) lst = , lst )
return lst

a=1-800-getcharter
print ( j) a = , a )
print ( nametonumber2(a) )

### code ends

If you run the above code exactly as it is, you should see in the output 
how the enumeration reacts according to the different data it is given to 
enumerate, and also where lst is assigned the value none.

As I said above, getting your head round why this is happening is 
essential, and I really do suggest that you slow down and try and 
understand these basic concepts, because at the moment it seems you are 
striving to attempt more and more complicated things without 
understanding the basics upon which they are constructed, and like many 
other similar newsgroups, it's been my experience in the past that there 
is limited tolerance here for people who repeatedly make the same basic 
errors without learning from them.

Thanks a lot for all your suggestions.  I haven't learned to use the
interpreter yet.  I do plan on learning to use it.
The problem with that at the moment is that I have enrolled in an
online computer class.  They use Codeskulptor.
Codeskulptor code is not compatible to standard Python.  When I finish
the class I do plan on using Python 3 and will learn the Python 3
stuff.
Codeskulptor has a Viz mode.  I have tried using it, but so far it is
still pretty confusing.  I will try to use it more.

I have saved your message and will crack the interpreter on it soon.

My trouble is trying to search for practice problems that are not too
hard yet.


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Wed, 22 Oct 2014 23:55:57 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:

On 22/10/2014 23:30, Seymore4Head wrote:
 On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
 Seymore4Head@Hotmail.invalid wrote:

 One more question.
 if y in str(range(10)
 Why doesn't that work.

Invalid syntax, it should obviously be:-

if y in str(range(10)):

OTOH if you've simply mistyped above what did you expect to happen and 
what actually happened?  Give us the actual code that you ran and the 
full traceback.

I don't get an error.  It just doesn't print the numbers correctly.
http://imgur.com/a/2loQV
You can click on the images and make them larger.
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-22 Thread Mark Lawrence

On 23/10/2014 00:26, Seymore4Head wrote:

On Wed, 22 Oct 2014 23:55:57 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:


On 22/10/2014 23:30, Seymore4Head wrote:

On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

One more question.
if y in str(range(10)
Why doesn't that work.


Invalid syntax, it should obviously be:-

if y in str(range(10)):

OTOH if you've simply mistyped above what did you expect to happen and
what actually happened?  Give us the actual code that you ran and the
full traceback.


I don't get an error.  It just doesn't print the numbers correctly.
http://imgur.com/a/2loQV
You can click on the images and make them larger.
Thanks



I suggest you try str(range(10)) from the interactive prompt and see 
exactly what you get, as it's nothing like what you expect :)


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


The “trials” in “trial and error” should be as simple as possible (was: I am out of trial and error again Lists)

2014-10-22 Thread Ben Finney
Seymore4Head Seymore4Head@Hotmail.invalid writes:

 Those string errors were desperate attempts to fix the append error
 I didn't understand.

It's normal when learning to get one's code into a mess.

But, when trying to trouble-shoot, please adopt the habit of
*simplifying* the examples, to better understand them.

At the least, when presenting code here for asking questions, ensure
you've make a simple-as-possible example showing the problem.

In other words: rip out any complicated parts to see if they're
relevant; if the same problem happens, that part wasn't relevant to the
example, and you should omit it when presenting it here.

You'll find that this will get you more sensible answers, As a bonus, it
will often lead to you understanding the problem enough to solve it!

-- 
 \  “At my lemonade stand I used to give the first glass away free |
  `\  and charge five dollars for the second glass. The refill |
_o__)contained the antidote.” —Emo Philips |
Ben Finney

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


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Thu, 23 Oct 2014 00:44:01 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:

On 23/10/2014 00:26, Seymore4Head wrote:
 On Wed, 22 Oct 2014 23:55:57 +0100, Mark Lawrence
 breamore...@yahoo.co.uk wrote:

 On 22/10/2014 23:30, Seymore4Head wrote:
 On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
 Seymore4Head@Hotmail.invalid wrote:

 One more question.
 if y in str(range(10)
 Why doesn't that work.

 Invalid syntax, it should obviously be:-

 if y in str(range(10)):

 OTOH if you've simply mistyped above what did you expect to happen and
 what actually happened?  Give us the actual code that you ran and the
 full traceback.

 I don't get an error.  It just doesn't print the numbers correctly.
 http://imgur.com/a/2loQV
 You can click on the images and make them larger.
 Thanks


I suggest you try str(range(10)) from the interactive prompt and see 
exactly what you get, as it's nothing like what you expect :)

I see that now.  So there may not be a short hand solution.

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


Re: I am out of trial and error again Lists

2014-10-22 Thread Steven D'Aprano
Seymore4Head wrote:

 Those string errors were desperate attempts to fix the append error
 I didn't understand.

Ah, the good ol' make random changes to the code until the error goes away
technique. You know that it never works, right?

Start by *reading the error message*, assuming you're getting an error
message. I'm the first person to admit that Python's error messages are not
always as clear as they should be, especially syntax errors, but still
there is a lot of information that can be gleamed from most error messages.
Take this attempt to use append:

py mylist.append(23)
Traceback (most recent call last):
  File stdin, line 1, in module
NameError: name 'mylist' is not defined

That tells me that I have forgotten to define a variable mylist. So I fix
that:

py mylist = 23
py mylist.append(23)
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'int' object has no attribute 'append'


That tells me that I can't append to a int. After googling for Python
append I learn that I can append to a list, so I try again:

py mylist = []
py mylist.append(23)
py print(mylist)
[23]


Success!

If you are familiar with other programming languages, it might help to think
of append() as being like a procedure in Pascal, for example. You call
append() with an argument, but don't expect a return result.

Technically, *all* functions and methods in Python return something, even if
just the special value None, which can lead to Gotchas! like this one:

py mylist = mylist.append(42)  # Don't do this!
py print(mylist)  # I expect [23, 42] but get None instead.
None

Oops. One of the small annoyances of Python is that there is no way to tell
ahead of time, except by reading the documentation, whether something is a
proper function that returns a useful value, or a procedure-like function
that returns None. That's just something you have to learn.

The interactive interpreter is your friend. Learn to experiment at the
interactive interpreter -- you do know how to do that, don't you? If not,
ask. At the interactive interpreter, if a function or method returns a
value, it will be printed, *except for None*. So a function that doesn't
print anything might be procedure-like, and one which does print something
might not be:

py mylist = [1, 5, 2, 6, 4, 3]
py sorted(mylist)  # proper function returns a value
[1, 2, 3, 4, 5, 6]
py mylist.sort()  # procedure-like function returns None
py print(mylist)  # and modifies the list in place
[1, 2, 3, 4, 5, 6]


-- 
Steven

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


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Thu, 23 Oct 2014 11:05:08 +1100, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:

Seymore4Head wrote:

 Those string errors were desperate attempts to fix the append error
 I didn't understand.

Ah, the good ol' make random changes to the code until the error goes away
technique. You know that it never works, right?

Start by *reading the error message*, assuming you're getting an error
message. I'm the first person to admit that Python's error messages are not
always as clear as they should be, especially syntax errors, but still
there is a lot of information that can be gleamed from most error messages.
Take this attempt to use append:

py mylist.append(23)
Traceback (most recent call last):
  File stdin, line 1, in module
NameError: name 'mylist' is not defined

That tells me that I have forgotten to define a variable mylist. So I fix
that:

py mylist = 23
py mylist.append(23)
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'int' object has no attribute 'append'


That tells me that I can't append to a int. After googling for Python
append I learn that I can append to a list, so I try again:

py mylist = []
py mylist.append(23)
py print(mylist)
[23]


Success!

If you are familiar with other programming languages, it might help to think
of append() as being like a procedure in Pascal, for example. You call
append() with an argument, but don't expect a return result.

Technically, *all* functions and methods in Python return something, even if
just the special value None, which can lead to Gotchas! like this one:

py mylist = mylist.append(42)  # Don't do this!
py print(mylist)  # I expect [23, 42] but get None instead.
None

Oops. One of the small annoyances of Python is that there is no way to tell
ahead of time, except by reading the documentation, whether something is a
proper function that returns a useful value, or a procedure-like function
that returns None. That's just something you have to learn.

The interactive interpreter is your friend. Learn to experiment at the
interactive interpreter -- you do know how to do that, don't you? If not,
ask. At the interactive interpreter, if a function or method returns a
value, it will be printed, *except for None*. So a function that doesn't
print anything might be procedure-like, and one which does print something
might not be:

py mylist = [1, 5, 2, 6, 4, 3]
py sorted(mylist)  # proper function returns a value
[1, 2, 3, 4, 5, 6]
py mylist.sort()  # procedure-like function returns None
py print(mylist)  # and modifies the list in place
[1, 2, 3, 4, 5, 6]

I am going to get around to learning the interpreter soon.

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


the ressurection of ZOPE for web domination? bluebream and caveman the answer?

2014-10-22 Thread johannes falcone
i loved the rant about how zope would have all these features, and then some 
other python framework would come on with like 1 and act like its the bomb, and 
zope was like we been doing that and more for X years

those who dont study zope are doomed to repeat it!!!

is zope scoffing at drupal? botle? pyramid ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-22 Thread Steven D'Aprano
Michael Torrie wrote:

 On 10/22/2014 05:45 AM, Mark Lawrence wrote:
 without not:
 j = [j+1, 3][j=10]
 with not:
 j = [3, j+1][not (j=10)]


 Oh it's a trick !
 thx
 
 IMHO it's just dreadful.  Why people insist on messing around like this
 I really don't know, it just drives me nuts.
 
 This actually was the standard idiom used by many python programs before
 Python 2.5.  But I agree.  Don't do this anymore! Python has a ternary
 if expression. Also the ternary if expression does, I believe
 short-circuit logic, so the non-chosen path is not calculated.  This
 hack does not. Could lead to interesting bugs depending on your
 assumptions.

Working code doesn't suddenly become non-working code just because Python
adds a second way to do something. The standard idiom

(value_if_false, value_if_true)[condition]

worked from (at least) Python 1.5 to Python 2.4, and it continues to work
today. There's nothing wrong with it: it does what it does, nothing more,
nothing less, and the only hashish part of this is that bools *are* ints,
with True == 1 and False == 0. That was heavily debated back in 2.3 or
thereabouts when bools were first introduced, and the decision made then
wasn't reverted in Python 3, so you can take it as By Design and not a
fluke of history. I think it is fair to say that Guido likes it that bools
are ints.

The older idiom isn't *exactly* the same as the ternary if operator, since
that short-circuits, but for many purposes short-circuiting is not
important or needed. If you don't need short-circuiting, or you dislike the
order of `value_if_true if condition else value_if_false`, or you need to
support Python 2.4 or older, or *simply because you like it*, there is
nothing wrong with using the older `sequence[flag]` idiom.

(It amuses me that not that many years ago the general attitude here was
that ternary if was an abomination that no right-thinking person should
ever use because the order of terms isn't identical to C, and now the
attitude seems to be that anyone *not* using ternary if is a heretic who
deserves to be set on fire :-)



-- 
Steven

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


Re: I am out of trial and error again Lists

2014-10-22 Thread MRAB

On 2014-10-23 01:02, Seymore4Head wrote:

On Thu, 23 Oct 2014 00:44:01 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:


On 23/10/2014 00:26, Seymore4Head wrote:

On Wed, 22 Oct 2014 23:55:57 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:


On 22/10/2014 23:30, Seymore4Head wrote:

On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

One more question.
if y in str(range(10)
Why doesn't that work.


Invalid syntax, it should obviously be:-

if y in str(range(10)):

OTOH if you've simply mistyped above what did you expect to happen and
what actually happened?  Give us the actual code that you ran and the
full traceback.


I don't get an error.  It just doesn't print the numbers correctly.
http://imgur.com/a/2loQV
You can click on the images and make them larger.
Thanks



I suggest you try str(range(10)) from the interactive prompt and see
exactly what you get, as it's nothing like what you expect :)


I see that now.  So there may not be a short hand solution.


range(10) will yield the integers 0-9.

You can iterate over them, turning each into a string, and then join
them together:

''.join(str(n) for n in range(10))

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


Re: I am out of trial and error again Lists

2014-10-22 Thread MRAB

On 2014-10-23 01:10, Seymore4Head wrote:

On Thu, 23 Oct 2014 11:05:08 +1100, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:


Seymore4Head wrote:


Those string errors were desperate attempts to fix the append error
I didn't understand.


Ah, the good ol' make random changes to the code until the error goes away
technique. You know that it never works, right?

Start by *reading the error message*, assuming you're getting an error
message. I'm the first person to admit that Python's error messages are not
always as clear as they should be, especially syntax errors, but still
there is a lot of information that can be gleamed from most error messages.
Take this attempt to use append:

py mylist.append(23)
Traceback (most recent call last):
 File stdin, line 1, in module
NameError: name 'mylist' is not defined

That tells me that I have forgotten to define a variable mylist. So I fix
that:

py mylist = 23
py mylist.append(23)
Traceback (most recent call last):
 File stdin, line 1, in module
AttributeError: 'int' object has no attribute 'append'


That tells me that I can't append to a int. After googling for Python
append I learn that I can append to a list, so I try again:

py mylist = []
py mylist.append(23)
py print(mylist)
[23]


Success!

If you are familiar with other programming languages, it might help to think
of append() as being like a procedure in Pascal, for example. You call
append() with an argument, but don't expect a return result.

Technically, *all* functions and methods in Python return something, even if
just the special value None, which can lead to Gotchas! like this one:

py mylist = mylist.append(42)  # Don't do this!
py print(mylist)  # I expect [23, 42] but get None instead.
None

Oops. One of the small annoyances of Python is that there is no way to tell
ahead of time, except by reading the documentation, whether something is a
proper function that returns a useful value, or a procedure-like function
that returns None. That's just something you have to learn.

The interactive interpreter is your friend. Learn to experiment at the
interactive interpreter -- you do know how to do that, don't you? If not,
ask. At the interactive interpreter, if a function or method returns a
value, it will be printed, *except for None*. So a function that doesn't
print anything might be procedure-like, and one which does print something
might not be:

py mylist = [1, 5, 2, 6, 4, 3]
py sorted(mylist)  # proper function returns a value
[1, 2, 3, 4, 5, 6]
py mylist.sort()  # procedure-like function returns None
py print(mylist)  # and modifies the list in place
[1, 2, 3, 4, 5, 6]


I am going to get around to learning the interpreter soon.


Why wait?

You're trying to learn the language _now_, and checking things
interactively will help you.

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


Re: I am out of trial and error again Lists

2014-10-22 Thread alex23

On 23/10/2014 10:02 AM, Seymore4Head wrote:

On Thu, 23 Oct 2014 00:44:01 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:

One more question.
if y in str(range(10)
Why doesn't that work.

I suggest you try str(range(10)) from the interactive prompt and see
exactly what you get, as it's nothing like what you expect :)


I see that now.  So there may not be a short hand solution.


There are two 'short hand solutions' to do what you want here:

import string

if y in string.digits:


Or even simpler:

if y.isdigit():
...

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


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Thu, 23 Oct 2014 02:31:57 +0100, MRAB pyt...@mrabarnett.plus.com
wrote:

On 2014-10-23 01:10, Seymore4Head wrote:
 On Thu, 23 Oct 2014 11:05:08 +1100, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:

Seymore4Head wrote:

 Those string errors were desperate attempts to fix the append error
 I didn't understand.

Ah, the good ol' make random changes to the code until the error goes away
technique. You know that it never works, right?

Start by *reading the error message*, assuming you're getting an error
message. I'm the first person to admit that Python's error messages are not
always as clear as they should be, especially syntax errors, but still
there is a lot of information that can be gleamed from most error messages.
Take this attempt to use append:

py mylist.append(23)
Traceback (most recent call last):
  File stdin, line 1, in module
NameError: name 'mylist' is not defined

That tells me that I have forgotten to define a variable mylist. So I fix
that:

py mylist = 23
py mylist.append(23)
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'int' object has no attribute 'append'


That tells me that I can't append to a int. After googling for Python
append I learn that I can append to a list, so I try again:

py mylist = []
py mylist.append(23)
py print(mylist)
[23]


Success!

If you are familiar with other programming languages, it might help to think
of append() as being like a procedure in Pascal, for example. You call
append() with an argument, but don't expect a return result.

Technically, *all* functions and methods in Python return something, even if
just the special value None, which can lead to Gotchas! like this one:

py mylist = mylist.append(42)  # Don't do this!
py print(mylist)  # I expect [23, 42] but get None instead.
None

Oops. One of the small annoyances of Python is that there is no way to tell
ahead of time, except by reading the documentation, whether something is a
proper function that returns a useful value, or a procedure-like function
that returns None. That's just something you have to learn.

The interactive interpreter is your friend. Learn to experiment at the
interactive interpreter -- you do know how to do that, don't you? If not,
ask. At the interactive interpreter, if a function or method returns a
value, it will be printed, *except for None*. So a function that doesn't
print anything might be procedure-like, and one which does print something
might not be:

py mylist = [1, 5, 2, 6, 4, 3]
py sorted(mylist)  # proper function returns a value
[1, 2, 3, 4, 5, 6]
py mylist.sort()  # procedure-like function returns None
py print(mylist)  # and modifies the list in place
[1, 2, 3, 4, 5, 6]

 I am going to get around to learning the interpreter soon.

Why wait?

You're trying to learn the language _now_, and checking things
interactively will help you.

Because most of the practice I am getting is not using Python.  I use
Codeskulptor.  

OK.Now is as good a time as ever.

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


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Thu, 23 Oct 2014 11:37:27 +1000, alex23 wuwe...@gmail.com wrote:

On 23/10/2014 10:02 AM, Seymore4Head wrote:
 On Thu, 23 Oct 2014 00:44:01 +0100, Mark Lawrence
 breamore...@yahoo.co.uk wrote:
 One more question.
 if y in str(range(10)
 Why doesn't that work.
 I suggest you try str(range(10)) from the interactive prompt and see
 exactly what you get, as it's nothing like what you expect :)

 I see that now.  So there may not be a short hand solution.

There are two 'short hand solutions' to do what you want here:

 import string

 if y in string.digits:
 

Or even simpler:

 if y.isdigit():
 ...
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Wed, 22 Oct 2014 21:35:19 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

On Thu, 23 Oct 2014 02:31:57 +0100, MRAB pyt...@mrabarnett.plus.com
wrote:

On 2014-10-23 01:10, Seymore4Head wrote:
 On Thu, 23 Oct 2014 11:05:08 +1100, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:

Seymore4Head wrote:

 Those string errors were desperate attempts to fix the append error
 I didn't understand.

Ah, the good ol' make random changes to the code until the error goes away
technique. You know that it never works, right?

Start by *reading the error message*, assuming you're getting an error
message. I'm the first person to admit that Python's error messages are not
always as clear as they should be, especially syntax errors, but still
there is a lot of information that can be gleamed from most error messages.
Take this attempt to use append:

py mylist.append(23)
Traceback (most recent call last):
  File stdin, line 1, in module
NameError: name 'mylist' is not defined

That tells me that I have forgotten to define a variable mylist. So I fix
that:

py mylist = 23
py mylist.append(23)
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'int' object has no attribute 'append'


That tells me that I can't append to a int. After googling for Python
append I learn that I can append to a list, so I try again:

py mylist = []
py mylist.append(23)
py print(mylist)
[23]


Success!

If you are familiar with other programming languages, it might help to think
of append() as being like a procedure in Pascal, for example. You call
append() with an argument, but don't expect a return result.

Technically, *all* functions and methods in Python return something, even if
just the special value None, which can lead to Gotchas! like this one:

py mylist = mylist.append(42)  # Don't do this!
py print(mylist)  # I expect [23, 42] but get None instead.
None

Oops. One of the small annoyances of Python is that there is no way to tell
ahead of time, except by reading the documentation, whether something is a
proper function that returns a useful value, or a procedure-like function
that returns None. That's just something you have to learn.

The interactive interpreter is your friend. Learn to experiment at the
interactive interpreter -- you do know how to do that, don't you? If not,
ask. At the interactive interpreter, if a function or method returns a
value, it will be printed, *except for None*. So a function that doesn't
print anything might be procedure-like, and one which does print something
might not be:

py mylist = [1, 5, 2, 6, 4, 3]
py sorted(mylist)  # proper function returns a value
[1, 2, 3, 4, 5, 6]
py mylist.sort()  # procedure-like function returns None
py print(mylist)  # and modifies the list in place
[1, 2, 3, 4, 5, 6]

 I am going to get around to learning the interpreter soon.

Why wait?

You're trying to learn the language _now_, and checking things
interactively will help you.

Because most of the practice I am getting is not using Python.  I use
Codeskulptor.  

OK.Now is as good a time as ever.

Thanks

Now I remember why...nothing happens
http://i.imgur.com/MIRpqzY.jpg

If I click on the shell window, I can get the grayed options to show
up for one turn.
I hit step and everything goes gray again.

http://i.imgur.com/NtMdmU1.jpg

Not a very fruitful exercise.  :(
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-22 Thread Larry Hudson

On 10/22/2014 05:02 PM, Seymore4Head wrote:

On Thu, 23 Oct 2014 00:44:01 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:


snip  (This is in reference to the line:  if y in str(range(10)):)


I suggest you try str(range(10)) from the interactive prompt and see
exactly what you get, as it's nothing like what you expect :)


I see that now.  So there may not be a short hand solution.



Yes there is.

That statement would work in Py2 as-is, but in Py3 it needs to be changed to:

if y in list(range(10)):

This give you a list not a string, but that's actually what you want here.  If you _really_ want 
a string, use join():  .join(list(range(10)))


--  Also, from another post:  ---

 Thanks a lot for all your suggestions.  I haven't learned to use the
 interpreter yet.  I do plan on learning to use it.

You are making yourself work several hundred times harder if you don't learn to use the 
interactive mode!


 The problem with that at the moment is that I have enrolled in an
 online computer class.  They use Codeskulptor.
 Codeskulptor code is not compatible to standard Python.

I would be GREATLY bothered by the fact that it is not standard Python -- it sounds like a poor 
course.  You also seems to imply that you are only using those on-line tools and don't have a 
real Python installed on your own system.  If so, that is an extremely bad choice.  And if so, 
stop everything until you do install it NOW (definitely Python 3).  Then you can play with 
things on your own system IN THE INTERACTIVE MODE!!!  That's when you will start actually learning.


 -=- Larry -=-

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


Re: I am out of trial and error again Lists

2014-10-22 Thread Seymore4Head
On Wed, 22 Oct 2014 19:58:24 -0700, Larry Hudson org...@yahoo.com
wrote:

On 10/22/2014 05:02 PM, Seymore4Head wrote:
 On Thu, 23 Oct 2014 00:44:01 +0100, Mark Lawrence
 breamore...@yahoo.co.uk wrote:

snip  (This is in reference to the line:  if y in str(range(10)):)

 I suggest you try str(range(10)) from the interactive prompt and see
 exactly what you get, as it's nothing like what you expect :)

 I see that now.  So there may not be a short hand solution.


Yes there is.

That statement would work in Py2 as-is, but in Py3 it needs to be changed to:

if y in list(range(10)):

This give you a list not a string, but that's actually what you want here.  If 
you _really_ want 
a string, use join():  .join(list(range(10)))

--  Also, from another post:  ---

  Thanks a lot for all your suggestions.  I haven't learned to use the
  interpreter yet.  I do plan on learning to use it.

You are making yourself work several hundred times harder if you don't learn 
to use the 
interactive mode!

  The problem with that at the moment is that I have enrolled in an
  online computer class.  They use Codeskulptor.
  Codeskulptor code is not compatible to standard Python.

I would be GREATLY bothered by the fact that it is not standard Python -- it 
sounds like a poor 
course.  You also seems to imply that you are only using those on-line tools 
and don't have a 
real Python installed on your own system.  If so, that is an extremely bad 
choice.  And if so, 
stop everything until you do install it NOW (definitely Python 3).  Then you 
can play with 
things on your own system IN THE INTERACTIVE MODE!!!  That's when you will 
start actually learning.

  -=- Larry -=-

OK  Good advice.  I already have Py3 installed.  Interactive mode is
the next item on my do list.

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


Re: I am out of trial and error again Lists

2014-10-22 Thread Rustom Mody
On Thursday, October 23, 2014 8:28:39 AM UTC+5:30, Larry Hudson wrote:

 --  Also, from another post:  ---
   Thanks a lot for all your suggestions.  I haven't learned to use the
   interpreter yet.  I do plan on learning to use it.
 You are making yourself work several hundred times harder if you don't learn 
 to use the 
 interactive mode!

+100

That a noob takes the longest path out of noob-land --- well thats the 
fun of life!

That experienced people are not peremptory enough
-- yeah My way or Highway is rude but necessary at times -- is unfortunate.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-22 Thread Gregory Ewing

Chris Angelico wrote:

I've seen much MUCH worse... where multiple conditional
expressions get combined arithmetically, and then the result used
somewhere...


In the days of old-school BASIC it was common to
exploit the fact that boolean expressions evaluated
to 0 or 1 (or -1, depending on your dialect :) to
achieve conditional expressions or other tricks.

Probably forgiveable, given that there were no real
conditional expressions, and every byte of your 48K
or less of RAM was precious...

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


Re: (test) ? a:b

2014-10-22 Thread Vito De Tullio
Dennis Lee Bieber wrote:

 x = [f(), g()] [cond]

the latter evaluates both f() and g() instead of just one. Apart from
being inefficient, it can have unintended side-effects.
 
 Ah, but what would
 
 x = [f, g][cond]()
 
 produce?


headache

-- 
By ZeD

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


[issue22692] Problems with Python's help()

2014-10-22 Thread James

New submission from James:

Hello,

I really think that Microsoft’s last release of Quick Basic 4.5 really had 
the ultimate of all help files.  Here’s why, you could cut and copy the code to 
the program you were working on, and then alter it to your program.  It was one 
of the nicer things you could do with the help file.  Because, tearing down the 
working example, usually just means customizing it to your needs, or wants.

You have several randomizing routines right?  How do you use these modules? 
 I have to say, looking at the help, should work for anyone that can’t leave it 
alone and learn to program if that’s what they want to do.  I was always a hunt 
an pick programmer.  I rather read through the help files and see what it can 
do, and then figure out what I want to do.  There’s no reason anyone couldn’t 
be self taught via reading the help file but, we should at least want it to 
work that way.

It’s fun to be on a ship with men.

James.

--
messages: 229798
nosy: FCK
priority: normal
severity: normal
status: open
title: Problems with Python's help()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22692
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22694] The help file issue I'm having.

2014-10-22 Thread James

New submission from James:

Hello,

Now, I really want you to think about the hunt and pick method of 
programming and learning how to program.  Being self taught, isn’t something 
that can happen unless, the authors of the software want people to learn how to 
use it.  Help files, are not typically designed that way but, there’s an easy 
way to design them that way.  Some of the strange notation that requires a 
course in computer science, is not what anybody needs to program a computer.  
The computer science method of explaining computer programming languages is all 
literally politics, or legal terms.  Let’s not make it harder than it really 
is, and keep both politics and legal terms out of this when in reality we just 
need a few terms to be define a function subroutine or suite of utilities and 
tools.  There’s science the right way, and we name things because they’ve never 
been named before, and then there’s politics, were we just talk too much about 
one dumb thing, or legal terms, and just re-invent the language around how many 
different ways we are capable of explaining the same damn thing differently, or 
making a new word out of lecture of human social situations and by defining one 
human social situation, come up with one legal term.

People work best one way, they learn by example.

James.

--
messages: 229800
nosy: FCK
priority: normal
severity: normal
status: open
title: The help file issue I'm having.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22694
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6818] remove/delete method for zipfile/tarfile objects

2014-10-22 Thread Yuval Greenfield

Yuval Greenfield added the comment:

Ping. Has this been postponed?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6818
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6818] remove/delete method for zipfile/tarfile objects

2014-10-22 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +serhiy.storchaka
versions: +Python 3.5 -Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6818
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22678] An OSError subclass for no space left on device would be nice

2014-10-22 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +barry, pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22678
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22695] open() declared deprecated in python 3 docs

2014-10-22 Thread Василий Макаров

New submission from Василий Макаров:

Python 3 open() documentation ( 
https://docs.python.org/3/library/functions.html#open ) is probably broken. 
Here is what one can see at the end of open() description:
...
Deprecated since version 3.4, will be removed in version 4.0.

The 'U' mode.

Reader may assume the open() function is what will be removed, which is wrong 
AFAIK

--
assignee: docs@python
components: Documentation
messages: 229802
nosy: docs@python, Василий.Макаров
priority: normal
severity: normal
status: open
title: open() declared deprecated in python 3 docs
type: behavior
versions: Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22695
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22695] open() declared deprecated in python 3 docs

2014-10-22 Thread Roundup Robot

Roundup Robot added the comment:

New changeset a2ecc284eaa7 by Victor Stinner in branch '3.4':
Issue #22695: Fix syntax of open() doc
https://hg.python.org/cpython/rev/a2ecc284eaa7

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22695
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22695] open() declared deprecated in python 3 docs

2014-10-22 Thread STINNER Victor

STINNER Victor added the comment:

 Reader may assume the open() function is what will be removed, which is wrong 
 AFAIK

It looks like an issue with the reST syntax in the documentation. Wait until 
the doc is regenerated (in a few hours) and then check again the doc please, to 
confirm that the issue is fixed.

--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22695
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22695] open() declared deprecated in python 3 docs

2014-10-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

There are other deprecated-removed instructions without following empty line 
in the docs. Should they be changed?

However the deprecated instruction works without following empty line. It 
looks as there is a bug in the implementation of the deprecated-removed 
instruction.

--
nosy: +georg.brandl, serhiy.storchaka
versions:  -Python 3.2, Python 3.3, Python 3.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22695
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22695] open() declared deprecated in python 3 docs

2014-10-22 Thread STINNER Victor

STINNER Victor added the comment:

However the deprecated instruction works without following empty line. It 
looks as there is a bug in the implementation of the deprecated-removed 
instruction.

Agreed, we can maybe enhance that. At least emit a warning?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22695
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22637] avoid using a shell in uuid: replce os.popen with subprocess.Popen

2014-10-22 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22637
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22636] avoid using a shell in ctypes.util: replace os.popen with subprocess

2014-10-22 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
nosy: +serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22636
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22599] traceback: errors in the linecache module at exit

2014-10-22 Thread STINNER Victor

STINNER Victor added the comment:

 traceback_at_exit-2.patch: Updated patch to remove import builtins from 
 tokenize.py, it's no more needed.

Antoine, Serhiy: What do you think about this patch?

IMO the bug is very simple and fixes a common bug.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22599
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >