EuroPython 2015: Vote for the talks you want to see

2015-05-04 Thread M.-A. Lemburg
Having received over 300 great proposals for talks, trainings,
helpdesks and posters, we now call out to all attendees to vote for
what you want to see on the conference schedule.

You can search for topics and communicate your personal priorities by
casting your vote for each submission on our talk voting page:


*** ​Attendees: This is your chance to shape the conference ! ***

 https://ep2015.europython.eu/en/talk-voting/

Talk voting will be open until Friday, May 15.

The program workgroup (WG) will then use the talk voting results as
basis for their talk selection and announce the schedule late in May.

Enjoy,
--
EuroPython 2015 Team
http://ep2015.europython.eu/
http://www.europython-society.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Cannot update OpenSSL for Python3

2015-05-04 Thread Cecil Westerhof
But when I do:
import urllib3.contrib.pyopenssl
I get:
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.4/site-packages/urllib3/contrib/pyopenssl.py", 
line 55, in 
import OpenSSL.SSL
  File "/usr/lib64/python3.4/site-packages/OpenSSL/__init__.py", line 8, in 

from OpenSSL import rand, crypto, SSL
  File "/usr/lib64/python3.4/site-packages/OpenSSL/rand.py", line 9, in 

from six import integer_types as _integer_types
ImportError: No module named 'six'

When I then give:
pip3 install -U OpenSSL
It goes wrong:
Could not fetch URL https://pypi.python.org/simple/OpenSSL/: 404 Client 
Error: Not Found

I checked and even
https://pypi.python.org/simple/
does not exist. Anyone an idea what is happening here?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


when does newlines get set in universal newlines mode?

2015-05-04 Thread arekfu
Hi all,

I have a text file with Windows-style line terminators (\r\n) which I open in 
universal newlines mode (Python 2.7). I would expect the newlines attribute to 
be set after the first call to the readline() method, but apparently this is 
not the case:

>>> f=open('test_crlf', 'rU')
>>> f.newlines
>>> f.readline()
'foo\n'
>>> f.newlines
>>> f.readline()
'bar\n'
>>> f.newlines
'\r\n'
On the other hand, the newlines attribute gets set after the first call to 
readline() on a file with Unix-style line endings.

Is this a bug or a feature?

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


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Chris Angelico
On Mon, May 4, 2015 at 6:58 PM, Cecil Westerhof  wrote:
> When I then give:
> pip3 install -U OpenSSL
> It goes wrong:
> Could not fetch URL https://pypi.python.org/simple/OpenSSL/: 404 Client 
> Error: Not Found
>
> I checked and even
> https://pypi.python.org/simple/
> does not exist. Anyone an idea what is happening here?

I think what you want is called pyOpenSSL, not just OpenSSL:

https://pypi.python.org/pypi/pyOpenSSL
https://pypi.python.org/simple/pyopenssl/

Not sure why /simple/ doesn't work, but you're not normally meant to
grab that page manually - it's for script work. You could raise a
tracker issue about that if you like, but it may not be considered
important.

Does 'pip3 install -U pyOpenSSL' work?

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


Why do I get SyntaxError: invalid syntax

2015-05-04 Thread Cecil Westerhof
While copying pasting code to test, the following works:
from itertools  import islice
from os import rename
from os.pathimport expanduser, split
from tempfile   import NamedTemporaryFile

real_file = (expanduser('~/Twitter/testing.txt'))
(filepath,
 file)  = split(real_file)
with NamedTemporaryFile(mode = 'w', prefix = file + '_', dir = filepath, 
delete = False) as tf:
tempfile = tf.name
with open(real_file, 'r') as f:
for line in islice(f, 1, None):
tf.write(line)

rename(tempfile, real_file)

But first I used:
from itertools  import islice
from os import rename
from os.pathimport expanduser, split
from tempfile   import NamedTemporaryFile

real_file = (expanduser('~/Twitter/testing.txt'))
(filepath,
 file)  = split(real_file)
with NamedTemporaryFile(mode = 'w', prefix = file + '_', dir = filepath, 
delete = False) as tf:
tempfile = tf.name
with open(real_file, 'r') as f:
for line in islice(f, 1, None):
tf.write(line)
rename(tempfile, real_file)

But that gave:
  File "", line 6
rename(tempfile, real_file)
 ^
SyntaxError: invalid syntax

Why?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: when does newlines get set in universal newlines mode?

2015-05-04 Thread Peter Otten
[email protected] wrote:

> Hi all,
> 
> I have a text file with Windows-style line terminators (\r\n) which I open
> in universal newlines mode (Python 2.7). I would expect the newlines
> attribute to be set after the first call to the readline() method, but
> apparently this is not the case:
> 
 f=open('test_crlf', 'rU')
 f.newlines
 f.readline()
> 'foo\n'
 f.newlines
 f.readline()
> 'bar\n'
 f.newlines
> '\r\n'
> On the other hand, the newlines attribute gets set after the first call to
> readline() on a file with Unix-style line endings.
> 
> Is this a bug or a feature?

According to

https://docs.python.org/2.7/library/functions.html#open

"""
If Python is built without universal newlines support a mode with 'U' is the 
same as normal text mode. Note that file objects so opened also have an 
attribute called newlines which has a value of None (if no newlines have yet 
been seen), '\n', '\r', '\r\n', or a tuple containing all the newline types 
seen.
"""

I tried:

>>> with open("tmp.txt", "wb") as f: f.write("alpha\r\nbeta\rgamma\n")
... 
>>> f = open("tmp.txt", "rU")
>>> f.newlines
>>> f.readline()
'alpha\n'
>>> f.newlines 
# expected: '\r\n'
>>> f.readline()
'beta\n'
>>> f.newlines
'\r\n' # expected: ('\r', '\r\n')
>>> f.readline()
'gamma\n'
>>> f.newlines
('\r', '\n', '\r\n')

I believe this is a bug.

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


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Cecil Westerhof
Op Monday 4 May 2015 12:10 CEST schreef Chris Angelico:

> On Mon, May 4, 2015 at 6:58 PM, Cecil Westerhof  wrote:
>> When I then give: pip3 install -U OpenSSL It goes wrong: Could not
>> fetch URL https://pypi.python.org/simple/OpenSSL/: 404 Client
>> Error: Not Found
>>
>> I checked and even
>> https://pypi.python.org/simple/
>> does not exist. Anyone an idea what is happening here?
>
> I think what you want is called pyOpenSSL, not just OpenSSL:
>
> https://pypi.python.org/pypi/pyOpenSSL
> https://pypi.python.org/simple/pyopenssl/
>
> Not sure why /simple/ doesn't work, but you're not normally meant to
> grab that page manually - it's for script work. You could raise a
> tracker issue about that if you like, but it may not be considered
> important.
>
> Does 'pip3 install -U pyOpenSSL' work?
Not really, because that gives:
Requirement already up-to-date: pyOpenSSL in 
/usr/lib64/python3.4/site-packages
Cleaning up...

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why do I get SyntaxError: invalid syntax

2015-05-04 Thread Chris Angelico
On Mon, May 4, 2015 at 9:31 PM, Cecil Westerhof  wrote:
> While copying pasting code to test, the following works:
> [chomp]
> But first I used:
> with NamedTemporaryFile(mode = 'w', prefix = file + '_', dir = filepath, 
> delete = False) as tf:
> tempfile = tf.name
> with open(real_file, 'r') as f:
> for line in islice(f, 1, None):
> tf.write(line)
> rename(tempfile, real_file)
>
> But that gave:
>   File "", line 6
> rename(tempfile, real_file)
>  ^
> SyntaxError: invalid syntax
>
> Why?

To clarify: When you say "to test", you mean the interactive
interpreter, right? If so, you need to end blocks of text with blank
lines (and not have any blank lines in between). It's because the
parser has to know when to run stuff; when you run a script, it parses
the whole thing and then runs it, but interactively, it has to work
piece-meal.

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


Re: when does newlines get set in universal newlines mode?

2015-05-04 Thread Chris Angelico
On Mon, May 4, 2015 at 10:01 PM, Peter Otten <[email protected]> wrote:
> I tried:
>
 with open("tmp.txt", "wb") as f: f.write("alpha\r\nbeta\rgamma\n")
> ...
 f = open("tmp.txt", "rU")
 f.newlines
 f.readline()
> 'alpha\n'
 f.newlines
> # expected: '\r\n'
 f.readline()
> 'beta\n'
 f.newlines
> '\r\n' # expected: ('\r', '\r\n')
 f.readline()
> 'gamma\n'
 f.newlines
> ('\r', '\n', '\r\n')
>
> I believe this is a bug.

I'm not sure it is, actually; imagine the text is coming in one
character at a time (eg from a pipe), and it's seen "alpha\r". It
knows that this is a line, so it emits it; but until the next
character is read, it can't know whether it's going to be \r or \r\n.
What should it do? Read another character, which might block? Put "\r"
into .newlines, which might be wrong? Once it sees the \n, it knows
that it was \r\n (or rather, it assumes that files do not have lines
of text terminated by \r followed by blank lines terminated by \n -
because that would be stupid).

It may be worth documenting this limitation, but it's not something
that can easily be fixed without removing support for \r newlines -
although that might be an option, given that non-OSX Macs are
basically history now.

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


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Chris Angelico
On Mon, May 4, 2015 at 9:32 PM, Cecil Westerhof  wrote:
>> Does 'pip3 install -U pyOpenSSL' work?
> Not really, because that gives:
> Requirement already up-to-date: pyOpenSSL in 
> /usr/lib64/python3.4/site-packages
> Cleaning up...

I don't know why it wasn't automatically installed, but 'six' is a
listed dependency of pyOpenSSL. What happens if you try to install
six?

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


http://premiumnaturalgarciniacambogiahelp.com/new-slim-5-garcinia-cambogia/

2015-05-04 Thread briansgoins via Python-list
New Slim 5 Garcinia Cambogia You can find plenty of Weight Loss tips one sees
around in company, infomercials, TV and publications. The stark reality is
that many of these tips actually work and a few really do not. To be honest
with you, the fat diets, weight products and pills recommendations or goods
are primarily those who don't function. Those who work so are fairly simple
to accomplish and are in reality easy to discover. They're largely
recommendations on DIETS and WORKOUTS. But I must contact your attention to
the recognition that the Weight Loss supplement marketplace is saturated in
the reality most situations is complicated to like the item being offered as
well as misleading tips and plenty of silly lies.

http://premiumnaturalgarciniacambogiahelp.com/new-slim-5-garcinia-cambogia/






--
View this message in context: 
http://python.6.x6.nabble.com/http-premiumnaturalgarciniacambogiahelp-com-new-slim-5-garcinia-cambogia-tp5094018.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: when does newlines get set in universal newlines mode?

2015-05-04 Thread Davide Mancusi
>> I believe this is a bug.
>
> I'm not sure it is, actually; imagine the text is coming in one
> character at a time (eg from a pipe), and it's seen "alpha\r". It
> knows that this is a line, so it emits it; but until the next
> character is read, it can't know whether it's going to be \r or \r\n.
> What should it do? Read another character, which might block? Put "\r"
> into .newlines, which might be wrong? Once it sees the \n, it knows
> that it was \r\n (or rather, it assumes that files do not have lines
> of text terminated by \r followed by blank lines terminated by \n -
> because that would be stupid).

I think this is a good point. However, I will probably submit a bug
report anyway and let the devs make their decisions. It is at least a
documentation bug.

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


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Cecil Westerhof
Op Monday 4 May 2015 14:14 CEST schreef Chris Angelico:

> On Mon, May 4, 2015 at 9:32 PM, Cecil Westerhof  wrote:
>>> Does 'pip3 install -U pyOpenSSL' work?
>> Not really, because that gives: Requirement already up-to-date:
>> pyOpenSSL in /usr/lib64/python3.4/site-packages Cleaning up...
>
> I don't know why it wasn't automatically installed, but 'six' is a
> listed dependency of pyOpenSSL. What happens if you try to install
> six?

That gets installed. And then I get:
ImportError: No module named 'cryptography'

So I try to install that. This gives:
Command /usr/bin/python3 -c "import setuptools, 
tokenize;__file__='/tmp/pip_build_root/cryptography/setup.py';exec(compile(getattr(tokenize,
 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" 
install --record /tmp/pip-_7jexj87-record/install-record.txt 
--single-version-externally-managed --compile failed with error code 1 in 
/tmp/pip_build_root/cryptography
Storing debug log for failure in /root/.pip/pip.log

In the log I see:
c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory
 #include 
^

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why do I get SyntaxError: invalid syntax

2015-05-04 Thread Cecil Westerhof
Op Monday 4 May 2015 14:07 CEST schreef Chris Angelico:

> On Mon, May 4, 2015 at 9:31 PM, Cecil Westerhof  wrote:
>> While copying pasting code to test, the following works: [chomp]
>> But first I used: with NamedTemporaryFile(mode = 'w', prefix = file
>> + '_', dir = filepath, delete = False) as tf: tempfile = tf.name
>> with open(real_file, 'r') as f: for line in islice(f, 1, None):
>> tf.write(line) rename(tempfile, real_file)
>>
>> But that gave:
>> File "", line 6
>> rename(tempfile, real_file)
>> ^
>> SyntaxError: invalid syntax
>>
>> Why?
>
> To clarify: When you say "to test", you mean the interactive
> interpreter, right?

Yes, that is what I mend. Should have been clearer.


> If so, you need to end blocks of text with blank
> lines (and not have any blank lines in between). It's because the
> parser has to know when to run stuff; when you run a script, it
> parses the whole thing and then runs it, but interactively, it has
> to work piece-meal.

OK, thanks: I understand it now.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Chris Angelico
On Mon, May 4, 2015 at 11:13 PM, Cecil Westerhof  wrote:
> That gets installed. And then I get:
> ImportError: No module named 'cryptography'
>
> So I try to install that. This gives:
> Command /usr/bin/python3 -c "import setuptools, 
> tokenize;__file__='/tmp/pip_build_root/cryptography/setup.py';exec(compile(getattr(tokenize,
>  'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" 
> install --record /tmp/pip-_7jexj87-record/install-record.txt 
> --single-version-externally-managed --compile failed with error code 1 in 
> /tmp/pip_build_root/cryptography
> Storing debug log for failure in /root/.pip/pip.log
>
> In the log I see:
> c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory
>  #include 

Okay, that one's easy enough to deal with!

You have something that needs to build a C extension. To do that, you
need to have the Python headers installed. How did you install Python?
On Debian/Ubuntu family Linuxes, that's probably "apt-get install
python3" - so getting the headers would be "apt-get install
python3-dev". Give that a try, and then retry the pip install.

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


Re: ImportPython Newsletter

2015-05-04 Thread Alex McFerron
I had the same problem just now

Sent from my iPhone

> On May 3, 2015, at 11:00 AM, Terry Reedy  wrote:
> 
>> On 5/3/2015 12:01 PM, Ankur Gupta wrote:
>> Hey Guys,
>> 
>> Just like to draw attention to ImportPython a weekly Python
>> newsletter. This is the 30th issue of the newsletter
>> http://importpython.com/newsletter/no/30/.
> 
> Nice, but when I tried to subscribe,
> "Unable to reach server"
> 
> -- 
> Terry Jan Reedy
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: when does newlines get set in universal newlines mode?

2015-05-04 Thread Peter Otten
Chris Angelico wrote:

> On Mon, May 4, 2015 at 10:01 PM, Peter Otten <[email protected]> wrote:
>> I tried:
>>
> with open("tmp.txt", "wb") as f: f.write("alpha\r\nbeta\rgamma\n")
>> ...
> f = open("tmp.txt", "rU")
> f.newlines
> f.readline()
>> 'alpha\n'
> f.newlines
>> # expected: '\r\n'
> f.readline()
>> 'beta\n'
> f.newlines
>> '\r\n' # expected: ('\r', '\r\n')
> f.readline()
>> 'gamma\n'
> f.newlines
>> ('\r', '\n', '\r\n')
>>
>> I believe this is a bug.
> 
> I'm not sure it is, actually; imagine the text is coming in one
> character at a time (eg from a pipe), and it's seen "alpha\r". It
> knows that this is a line, so it emits it; but until the next
> character is read, it can't know whether it's going to be \r or \r\n.
> What should it do? Read another character, which might block? Put "\r"
> into .newlines, which might be wrong? Once it sees the \n, it knows
> that it was \r\n (or rather, it assumes that files do not have lines
> of text terminated by \r followed by blank lines terminated by \n -
> because that would be stupid).
> 
> It may be worth documenting this limitation, but it's not something
> that can easily be fixed without removing support for \r newlines -
> although that might be an option, given that non-OSX Macs are
> basically history now.

OK, you convinced me. Then I tried:

>>> with open("tmp.txt", "wb") as f: f.write("0\r\n3\r5\n7")
... 
>>> assert len(open("tmp.txt", "rb").read()) == 8
>>> f = open("tmp.txt", "rU")
>>> f.readline()
'0\n'
>>> f.newlines
>>> f.tell()
3
>>> f.newlines
'\r\n'

Hm, so tell() moves the file pointer? Is that sane?

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


Re: when does newlines get set in universal newlines mode?

2015-05-04 Thread Chris Angelico
On Tue, May 5, 2015 at 1:17 AM, Peter Otten <[email protected]> wrote:
> OK, you convinced me. Then I tried:
>
 with open("tmp.txt", "wb") as f: f.write("0\r\n3\r5\n7")
> ...
 assert len(open("tmp.txt", "rb").read()) == 8
 f = open("tmp.txt", "rU")
 f.readline()
> '0\n'
 f.newlines
 f.tell()
> 3
 f.newlines
> '\r\n'
>
> Hm, so tell() moves the file pointer? Is that sane?

... wow. Okay! That's a bit weird.

It's possible that something's being done with internal buffering
(after all, it's horribly inefficient to *actually* read text one byte
at a time, even if that's what's happening conceptually), and that
tell() causes some checks to be done. But that really is rather
strange. I'd be interested to know what happens if another process
writes to a pipe "0\r", then sleeps while the readline() and tell()
happen, and then writes a "\n" - what will that do to newlines?

By the way, it's as well to clarify, with all these examples, what
Python version you're using. There may be significant differences.

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


Re: when does newlines get set in universal newlines mode?

2015-05-04 Thread Ian Kelly
On Mon, May 4, 2015 at 9:17 AM, Peter Otten <[email protected]> wrote:
> OK, you convinced me. Then I tried:
>
 with open("tmp.txt", "wb") as f: f.write("0\r\n3\r5\n7")
> ...
 assert len(open("tmp.txt", "rb").read()) == 8
 f = open("tmp.txt", "rU")
 f.readline()
> '0\n'
 f.newlines
 f.tell()
> 3
 f.newlines
> '\r\n'
>
> Hm, so tell() moves the file pointer? Is that sane?

If I call readline() followed by tell(), I expect the result to be the
position of the start of the next line. Maybe this is considered safe
because tell() on a pipe raises an exception?
-- 
https://mail.python.org/mailman/listinfo/python-list


Bitten by my C/Java experience

2015-05-04 Thread Cecil Westerhof
Potential dangerous bug introduced by programming in Python as if it
was C/Java. :-(
I used:
++tries
that has to be:
tries += 1

Are there other things I have to be careful on? That does not work as
in C/Java, but is correct syntax.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Cecil Westerhof
Op Monday 4 May 2015 16:18 CEST schreef Chris Angelico:

> On Mon, May 4, 2015 at 11:13 PM, Cecil Westerhof  wrote:
>> That gets installed. And then I get:
>> ImportError: No module named 'cryptography'
>>
>> So I try to install that. This gives: Command /usr/bin/python3 -c
>> "import setuptools,
>> tokenize;__file__='/tmp/pip_build_root/cryptography/setup.py';exec(compile(getattr(tokenize,
>> 'open', open)(__file__).read().replace('\r\n', '\n'), __file__,
>> 'exec'))" install --record
>> /tmp/pip-_7jexj87-record/install-record.txt
>> --single-version-externally-managed --compile failed with error
>> code 1 in /tmp/pip_build_root/cryptography Storing debug log for
>> failure in /root/.pip/pip.log
>>
>> In the log I see: c/_cffi_backend.c:2:20: fatal error: Python.h: No
>> such file or directory #include 
>
> Okay, that one's easy enough to deal with!
>
> You have something that needs to build a C extension. To do that,
> you need to have the Python headers installed. How did you install
> Python? On Debian/Ubuntu family Linuxes, that's probably "apt-get
> install python3" - so getting the headers would be "apt-get install
> python3-dev". Give that a try, and then retry the pip install.

I should have thought about that myself. :-(

Now I get:
c/../_cffi1/ffi_obj.c:489:5: error: ISO C90 forbids mixed declarations and 
code [-Werror=declaration-after-statement]
 PyObject *u = PyUnicode_DecodeLatin1(PyBytes_AS_STRING(res),
 ^
cc1: some warnings being treated as errors

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Chris Angelico
On Tue, May 5, 2015 at 1:11 AM, Cecil Westerhof  wrote:
> Now I get:
> c/../_cffi1/ffi_obj.c:489:5: error: ISO C90 forbids mixed declarations 
> and code [-Werror=declaration-after-statement]
>  PyObject *u = PyUnicode_DecodeLatin1(PyBytes_AS_STRING(res),
>  ^
> cc1: some warnings being treated as errors

Interesting. I'm not sure why yours is complaining about that; mine
doesn't. (Possibly because I'm running Python 3.5, and stuff may have
been changed.) In any case, this would be a reasonable thing to make a
bug report about. In the meantime, you can simply override that
warning-equals-error parameter:

http://stackoverflow.com/questions/25587039/error-compiling-rpy2-on-python3-4-due-to-werror-declaration-after-statement

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


Re: Bitten by my C/Java experience

2015-05-04 Thread Tobiah

On 05/04/2015 08:20 AM, Cecil Westerhof wrote:

Potential dangerous bug introduced by programming in Python as if it
was C/Java. :-(
I used:
 ++tries
that has to be:
 tries += 1

Are there other things I have to be careful on? That does not work as
in C/Java, but is correct syntax.



One surprise for the new user is an otherwise handy rule of scope.
A variable in a function will by default access any global variables of
the same name *unless* it is assigned to in the function.

def glob():
print "global:", foo

def loc():
foo = 2
print "local:", foo

def alt():
global foo
foo = 1
print "altered:", foo

foo = 3

glob()
print "Original:", foo

loc()
print "Original:", foo

alt()
print "Original:", foo

# Output ##

global: 3
Original: 3
local: 2
Original: 3
altered: 1
Original: 1
--
https://mail.python.org/mailman/listinfo/python-list


Re: Bitten by my C/Java experience

2015-05-04 Thread Irmen de Jong
On 4-5-2015 17:20, Cecil Westerhof wrote:
> Potential dangerous bug introduced by programming in Python as if it
> was C/Java. :-(
> I used:
> ++tries
> that has to be:
> tries += 1
> 
> Are there other things I have to be careful on? That does not work as
> in C/Java, but is correct syntax.
> 

That is a broad question, but one thing that comes to mind is the current 
(python 3)
behavior of integer division. It gives the exact result and doesn't truncate to 
integers:


>>> 5/4
1.25


To be prepared for the future you should probably use python's time machine and 
enable
this behavior for 2.x as well by from __future__ import division.


Another thing is that functions are first class citizens in Python. Java will 
give a
compiler error if you forget to call them and leave out the parentheses (I 
think Java 8
allows it though). Python will accept passing them on as a function object just 
fine. If
you do this by mistake you will probably get an exception a tiny bit down the 
line, at
runtime. But it is syntactically correct so your code will compile without 
error.


-irmen

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


Re: when does newlines get set in universal newlines mode?

2015-05-04 Thread Terry Reedy

On 5/4/2015 9:35 AM, Davide Mancusi wrote:

I believe this is a bug.


I'm not sure it is, actually; imagine the text is coming in one
character at a time (eg from a pipe), and it's seen "alpha\r". It
knows that this is a line, so it emits it; but until the next
character is read, it can't know whether it's going to be \r or \r\n.
What should it do? Read another character, which might block? Put "\r"
into .newlines, which might be wrong? Once it sees the \n, it knows
that it was \r\n (or rather, it assumes that files do not have lines
of text terminated by \r followed by blank lines terminated by \n -
because that would be stupid).


I think this is a good point. However, I will probably submit a bug
report anyway and let the devs make their decisions. It is at least a
documentation bug.


Be sure to report the exact python binary you are using, as reported 
when you start the interactive interpreter or Idle shell.


--
Terry Jan Reedy

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


Re: Bitten by my C/Java experience

2015-05-04 Thread Chris Angelico
On Tue, May 5, 2015 at 3:32 AM, Irmen de Jong  wrote:
> That is a broad question, but one thing that comes to mind is the current 
> (python 3)
> behavior of integer division. It gives the exact result and doesn't truncate 
> to integers:
>
>
 5/4
> 1.25

Using the word "exact" around non-integer values can be a little
ambiguous, since floats are often inexact. But yes, int/int -> float,
and yes, it WILL bite C programmers.

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


Re: Bitten by my C/Java experience

2015-05-04 Thread Ian Kelly
On Mon, May 4, 2015 at 9:20 AM, Cecil Westerhof  wrote:
> Potential dangerous bug introduced by programming in Python as if it
> was C/Java. :-(
> I used:
> ++tries
> that has to be:
> tries += 1
>
> Are there other things I have to be careful on? That does not work as
> in C/Java, but is correct syntax.

Some other gotchas that aren't necessarily related to C/Java but can
be surprising nonetheless:

*() is a zero-element tuple, and (a, b) is a two-element tuple,
but (a) is not a one-element tuple. Tuples are created by commas, not
parentheses, so use (a,) instead.

*Default function arguments are created at definition time, not at
call time. So if you do something like:

def foo(a, b=[]):
b.append(a)
print(b)

The b list will be the same list on each call and will retain all
changes from previous calls.

*super() doesn't do what you might expect in multiple inheritance
situations, particularly if you're coming from Java where you never
have to deal with multiple inheritance. It binds to the next class in
the method resolution order, *not* necessarily the immediate
superclass. This also means that the particular class bound to can
vary depending on the specific class of the object.

*[[None] * 8] * 8 doesn't create a 2-dimensional array of None. It
creates one list containing None 8 times, and then it creates a second
list containing the first list 8 times, *not* a list of 8 distinct
lists.

*If some_tuple is a tuple containing a list, then some_tuple[0] +=
['foo'] will concatenate the list *but* will also raise a TypeError
when it tries to reassign the list back to the tuple.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Cecil Westerhof
Op Monday 4 May 2015 18:03 CEST schreef Chris Angelico:

> On Tue, May 5, 2015 at 1:11 AM, Cecil Westerhof  wrote:
>> Now I get: c/../_cffi1/ffi_obj.c:489:5: error: ISO C90 forbids
>> mixed declarations and code [-Werror=declaration-after-statement]
>> PyObject *u = PyUnicode_DecodeLatin1(PyBytes_AS_STRING(res), ^ cc1:
>> some warnings being treated as errors
>
> Interesting. I'm not sure why yours is complaining about that; mine
> doesn't. (Possibly because I'm running Python 3.5, and stuff may
> have been changed.) In any case, this would be a reasonable thing to
> make a bug report about. In the meantime, you can simply override
> that warning-equals-error parameter:
>
> http://stackoverflow.com/questions/25587039/error-compiling-rpy2-on-python3-4-due-to-werror-declaration-after-statement

It looks like I am encircled by Gremlins:
>>> import urllib3.contrib.pyopenssl
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.4/site-packages/urllib3/contrib/pyopenssl.py", 
line 58, in 
from socket import _fileobject, timeout
ImportError: cannot import name '_fileobject'

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Chris Angelico
On Tue, May 5, 2015 at 3:19 AM, Cecil Westerhof  wrote:
> It looks like I am encircled by Gremlins:
> >>> import urllib3.contrib.pyopenssl
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python3.4/site-packages/urllib3/contrib/pyopenssl.py", 
> line 58, in 
> from socket import _fileobject, timeout
> ImportError: cannot import name '_fileobject'

This is looking like a pyopenssl bug - I can't import that name
either, and given that it has the leading underscore, it's probably
not an official part of the socket module's API.

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


Re: Bitten by my C/Java experience

2015-05-04 Thread Mark Lawrence

On 04/05/2015 16:20, Cecil Westerhof wrote:

Potential dangerous bug introduced by programming in Python as if it
was C/Java. :-(
I used:
 ++tries
that has to be:
 tries += 1

Are there other things I have to be careful on? That does not work as
in C/Java, but is correct syntax.



Not dangerous at all, your test code picks it up.  I'd also guess, but 
don't actually know, that one of the various linter tools could be 
configured to find this problem.


--
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: Cannot update OpenSSL for Python3

2015-05-04 Thread Mark Lawrence

On 04/05/2015 16:11, Cecil Westerhof wrote:

Op Monday 4 May 2015 16:18 CEST schreef Chris Angelico:


On Mon, May 4, 2015 at 11:13 PM, Cecil Westerhof  wrote:

That gets installed. And then I get:
ImportError: No module named 'cryptography'

So I try to install that. This gives: Command /usr/bin/python3 -c
"import setuptools,
tokenize;__file__='/tmp/pip_build_root/cryptography/setup.py';exec(compile(getattr(tokenize,
'open', open)(__file__).read().replace('\r\n', '\n'), __file__,
'exec'))" install --record
/tmp/pip-_7jexj87-record/install-record.txt
--single-version-externally-managed --compile failed with error
code 1 in /tmp/pip_build_root/cryptography Storing debug log for
failure in /root/.pip/pip.log

In the log I see: c/_cffi_backend.c:2:20: fatal error: Python.h: No
such file or directory #include 


Okay, that one's easy enough to deal with!

You have something that needs to build a C extension. To do that,
you need to have the Python headers installed. How did you install
Python? On Debian/Ubuntu family Linuxes, that's probably "apt-get
install python3" - so getting the headers would be "apt-get install
python3-dev". Give that a try, and then retry the pip install.


I should have thought about that myself. :-(



An alternative is to switch to Windows and do away with this archaic 
concept of users having to build code :)


--
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


ANN: Wing IDE 5.1.4 released

2015-05-04 Thread Wingware

Hi,

Wingware has released version 5.1.4 of Wing IDE, our cross-platform 
integrated development environment for the Python programming language.


Wing IDE features a professional code editor with vi, emacs, visual 
studio, and other key bindings, auto-completion, call tips, 
context-sensitive auto-editing, goto-definition, find uses, refactoring, 
a powerful debugger, version control, unit testing, search, project 
management, and many other features.


This release includes the following improvements:

Find Symbol in Project dialog
Support Django 1.8
Support debugging Django with auto-reload enabled
Basic support for Python 3.5 alpha
Change Case operations to Source menu
Fix alignment of monospaced characters on OS X and Linux
Improve pytest support
Fix several code analysis problems
About 40 other bug fixes and improvements

For details see http://wingware.com/news/2015-05-01 and 
http://wingware.com/pub/wingide/5.1.4/CHANGELOG.txt


What's New in Wing 5.1:

Wing IDE 5.1 adds multi-process and child process debugging, syntax 
highlighting in the shells, support for pytest, Find Symbol in Project, 
persistent time-stamped unit test results, auto-conversion of indents on 
paste, an XCode keyboard personality, support for Flask, Django 1.7 and 
1.8, Python 3.5 and recent Google App Engine versions, improved 
auto-completion for PyQt, recursive snippet invocation, and many other 
minor features and improvements.


Free trial: http://wingware.com/wingide/trial
Downloads: http://wingware.com/downloads
Feature list: http://wingware.com/wingide/features
Sales: http://wingware.com/store/purchase
Upgrades: https://wingware.com/store/upgrade

Questions?  Don't hesitate to email us at [email protected].

Thanks,

--

Stephan Deibel
Wingware | Python IDE

The Intelligent Development Environment for Python Programmers

wingware.com


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


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Irmen de Jong
On 4-5-2015 19:19, Cecil Westerhof wrote:

> It looks like I am encircled by Gremlins:
> >>> import urllib3.contrib.pyopenssl
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python3.4/site-packages/urllib3/contrib/pyopenssl.py", 
> line 58, in 
> from socket import _fileobject, timeout
> ImportError: cannot import name '_fileobject'
> 

Looks to me as if you have installed a Python 2 version of urllib3? pyopenssl? 
and are
trying to run that under python 3.

(socket module in python 2 does have a _fileobject, whereas in python 3 it no 
longer has
it.  Checked in CPython on Windows.)


Irmen

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


Why from en to two times with sending email

2015-05-04 Thread Cecil Westerhof
I want to change an old Bash script to Python. When I look at:
https://docs.python.org/2/library/email-examples.html

Then from and to have to be used two times? Why is that?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bitten by my C/Java experience

2015-05-04 Thread Ian Kelly
On Mon, May 4, 2015 at 11:59 AM, Mark Lawrence  wrote:
> On 04/05/2015 16:20, Cecil Westerhof wrote:
>>
>> Potential dangerous bug introduced by programming in Python as if it
>> was C/Java. :-(
>> I used:
>>  ++tries
>> that has to be:
>>  tries += 1
>>
>> Are there other things I have to be careful on? That does not work as
>> in C/Java, but is correct syntax.
>>
>
> Not dangerous at all, your test code picks it up.  I'd also guess, but don't
> actually know, that one of the various linter tools could be configured to
> find this problem.

pylint reports it as an error.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why from en to two times with sending email

2015-05-04 Thread Ian Kelly
On Mon, May 4, 2015 at 12:59 PM, Cecil Westerhof  wrote:
> I want to change an old Bash script to Python. When I look at:
> https://docs.python.org/2/library/email-examples.html
>
> Then from and to have to be used two times? Why is that?

Once to construct the message headers, and once to instruct the SMTP
server where to send the message. These are not required to agree; for
instance, bcc recipients need to be supplied to the server but aren't
included in the headers.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bitten by my C/Java experience

2015-05-04 Thread Terry Reedy

On 5/4/2015 1:43 PM, Ian Kelly wrote:


*() is a zero-element tuple, and (a, b) is a two-element tuple,
but (a) is not a one-element tuple. Tuples are created by commas, not
parentheses, so use (a,) instead.


Which means that a, and a,b (or a,b,) are 1 and 2 element tuples 
respectively. Except for empty tuples, parentheses are optional unless 
needed to fence off the tuple from surrounding code (which happens to be 
most of the time, but not always).  A trailing comma is prohibited for 
zero element tuples, required for one element tuples, and optional for 
multiple element tuples.


--
Terry Jan Reedy

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


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Cecil Westerhof
Op Monday 4 May 2015 20:04 CEST schreef Mark Lawrence:

> An alternative is to switch to Windows and do away with this archaic
> concept of users having to build code :)

Well, maybe I get rid of some problems. But the ones I get back …

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Cecil Westerhof
Op Monday 4 May 2015 21:02 CEST schreef Irmen de Jong:

> On 4-5-2015 19:19, Cecil Westerhof wrote:
>
>> It looks like I am encircled by Gremlins:
> import urllib3.contrib.pyopenssl
>> Traceback (most recent call last): File "", line 1, in
>>  File
>> "/usr/lib/python3.4/site-packages/urllib3/contrib/pyopenssl.py",
>> line 58, in  from socket import _fileobject, timeout
>> ImportError: cannot import name '_fileobject'
>>
>
> Looks to me as if you have installed a Python 2 version of urllib3?
> pyopenssl? and are trying to run that under python 3.
>
> (socket module in python 2 does have a _fileobject, whereas in
> python 3 it no longer has it. Checked in CPython on Windows.)

I did an uninstall and installed it again:
pip3 install urllib3
Downloading/unpacking urllib3
  Downloading urllib3-1.10.4.tar.gz (138kB): 138kB downloaded
  Running setup.py (path:/tmp/pip_build_root/urllib3/setup.py) egg_info for 
package urllib3

warning: no previously-included files matching '*' found under 
directory 'docs/_build'
Installing collected packages: urllib3
  Running setup.py install for urllib3

warning: no previously-included files matching '*' found under 
directory 'docs/_build'
Successfully installed urllib3
Cleaning up...

But I keep getting the error. Only 2 lines earlier:
>>> import urllib3.contrib.pyopenssl
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.4/site-packages/urllib3/contrib/pyopenssl.py", 
line 56, in 
from socket import _fileobject, timeout
ImportError: cannot import name '_fileobject'

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bitten by my C/Java experience

2015-05-04 Thread Cecil Westerhof
Op Monday 4 May 2015 21:39 CEST schreef Ian Kelly:

> On Mon, May 4, 2015 at 11:59 AM, Mark Lawrence  
> wrote:
>> On 04/05/2015 16:20, Cecil Westerhof wrote:
>>>
>>> Potential dangerous bug introduced by programming in Python as if
>>> it was C/Java. :-( I used: ++tries that has to be: tries += 1
>>>
>>> Are there other things I have to be careful on? That does not work
>>> as in C/Java, but is correct syntax.
>>>
>>
>> Not dangerous at all, your test code picks it up. I'd also guess,
>> but don't actually know, that one of the various linter tools could
>> be configured to find this problem.
>
> pylint reports it as an error.

I installed it. Get a lot of messages. Mostly convention. For example:
Unnecessary parens after 'print' keyword

And:
Invalid variable name "f"
for:
with open(real_file, 'r') as f:

But still something to add to my toolbox.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Mark Lawrence

On 04/05/2015 09:58, Cecil Westerhof wrote:

But when I do:
 import urllib3.contrib.pyopenssl
I get:
 Traceback (most recent call last):
   File "", line 1, in 
   File "/usr/lib/python3.4/site-packages/urllib3/contrib/pyopenssl.py", line 55, 
in 
 import OpenSSL.SSL
   File "/usr/lib64/python3.4/site-packages/OpenSSL/__init__.py", line 8, in 

 from OpenSSL import rand, crypto, SSL
   File "/usr/lib64/python3.4/site-packages/OpenSSL/rand.py", line 9, in 

 from six import integer_types as _integer_types
 ImportError: No module named 'six'

When I then give:
 pip3 install -U OpenSSL
It goes wrong:
 Could not fetch URL https://pypi.python.org/simple/OpenSSL/: 404 Client 
Error: Not Found

I checked and even
 https://pypi.python.org/simple/
does not exist. Anyone an idea what is happening here?



Showing my complete ignorance of *nix, what is the difference betweeen 
"/usr/lib/python3.4/..." and "/usr/lib64/python3.4/..."?  Simply 32 
versus 64 bit, which can or can't be mixed, or what?


--
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


Updating FaceBook

2015-05-04 Thread Cecil Westerhof
Using Python to update Twitter is reasonable straight forward.
I do:
from libturpial.api.coreimport Core
from libturpial.exceptions  import StatusDuplicated

I fill an account_id and a message and I do:
Core().update_status(account_id, message)

And my message is posted.

It looks like there is not something like that for FaceBook.  I found:
https://github.com/pythonforfacebook/facebook-sdk
but that looks not easy to implement. Is there an easier way?

In the past you could send an email, but that seems not to work
anymore.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why from en to two times with sending email

2015-05-04 Thread Cecil Westerhof
Op Monday 4 May 2015 21:48 CEST schreef Ian Kelly:

> On Mon, May 4, 2015 at 12:59 PM, Cecil Westerhof  wrote:
>> I want to change an old Bash script to Python. When I look at:
>> https://docs.python.org/2/library/email-examples.html
>>
>> Then from and to have to be used two times? Why is that?
>
> Once to construct the message headers, and once to instruct the SMTP
> server where to send the message. These are not required to agree;
> for instance, bcc recipients need to be supplied to the server but
> aren't included in the headers.

OK, thanks.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bitten by my C/Java experience

2015-05-04 Thread Andrew Cooper
On 04/05/2015 18:43, Ian Kelly wrote:
> 
> Some other gotchas that aren't necessarily related to C/Java but can
> be surprising nonetheless:
> 
> *() is a zero-element tuple, and (a, b) is a two-element tuple,
> but (a) is not a one-element tuple. Tuples are created by commas, not
> parentheses, so use (a,) instead.

* {} is an empty set(), not dict().

Particularly subtle when combined with **kwargs

$ 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.
>>> def foo(**kwargs):
...   return { (k, kwargs[k]) for k in kwargs }
...
>>> foo()
set()
>>> foo(a=1)
{('a', 1)}
>>>

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


Re: Bitten by my C/Java experience

2015-05-04 Thread random832
On Mon, May 4, 2015, at 16:57, Andrew Cooper wrote:
> * {} is an empty set(), not dict().

You've got it backwards.

> Particularly subtle when combined with **kwargs

The function in your example below _always_ returns a set, and kwargs is
always a dict. There's no subtlety outside of the repr output. The fact
that the empty set (as a result of empty kwargs) repr's as set() is a
consequence of the fact that {} is a dict.

> 
> $ 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.
> >>> def foo(**kwargs):
> ...   return { (k, kwargs[k]) for k in kwargs }
> ...
> >>> foo()
> set()
> >>> foo(a=1)
> {('a', 1)}
> >>>
> 
> ~Andrew
> -- 
> https://mail.python.org/mailman/listinfo/python-list


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


Re: Cannot update OpenSSL for Python3

2015-05-04 Thread Irmen de Jong
On 4-5-2015 21:52, Cecil Westerhof wrote:

> But I keep getting the error. Only 2 lines earlier:
> >>> import urllib3.contrib.pyopenssl
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python3.4/site-packages/urllib3/contrib/pyopenssl.py", 
> line 56, in 
> from socket import _fileobject, timeout
> ImportError: cannot import name '_fileobject'
> 

Right. This seems to be an issue with the "contrib" module pyopenssl that is 
provided as
a courtesy with urllib3. The latter is 100% python 3 compatible from what I 
read in
their docs.

Looking at that contrib module however:
https://github.com/shazow/urllib3/blob/master/urllib3/contrib/pyopenssl.py

In the first few lines in the module docstring it states it is for Python 2.
I guess you won't be able to use this urllib3 contrib module with python 3. 
Maybe you
can contact its author to ask for a fix?


Irmen

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


Re: Bitten by my C/Java experience

2015-05-04 Thread BartC

On 04/05/2015 16:20, Cecil Westerhof wrote:

Potential dangerous bug introduced by programming in Python as if it
was C/Java. :-(
I used:
 ++tries
that has to be:
 tries += 1


I think I've come across that. It doesn't mind ++ so people are likely 
to be assume that increment works as in other languages.


I guess it just means +(+(a)).

But in that case, what meaning does:

a

or

a+b

have in Python? If they were function calls: a() or (a+b)(), then that's 
clear enough. But a+b doesn't do anything!


(I think I would have picked up "++" and "--" as special tokens even if 
increment/decrement ops weren't supported. Just because they would 
likely cause errors through misunderstanding.)


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


Re: Bitten by my C/Java experience

2015-05-04 Thread Tim Chase
On 2015-05-04 21:57, Andrew Cooper wrote:
> On 04/05/2015 18:43, Ian Kelly wrote:
> > 
> > Some other gotchas that aren't necessarily related to C/Java but
> > can be surprising nonetheless:
> > 
> > *() is a zero-element tuple, and (a, b) is a two-element
> > tuple, but (a) is not a one-element tuple. Tuples are created by
> > commas, not parentheses, so use (a,) instead.
> 
> * {} is an empty set(), not dict().
> 
> Particularly subtle when combined with **kwargs
> 
> $ 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.
> >>> def foo(**kwargs):
> ...   return { (k, kwargs[k]) for k in kwargs }
> ...
> >>> foo()
> set()
> >>> foo(a=1)
> {('a', 1)}
> >>>

It's a dict:

Python 3.2.3 (default, Feb 20 2013, 14:44:27) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> type({})



What you're seeing is that your generator creates single-element
tuples in a set constructor (note that your last item isn't
"{'a': 1}". Try instead

>>> def foo(**kwargs):
... return {k: kwargs[k] for k in kwargs}
... 
>>> foo()
{}
>>> foo(a=42)
{'a': 42}

Note the colons, indicating that it's a dict.  You're using the
dict() syntax:

  dict((k,v) for k,v in some_iter())

-tkc






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


Re: Bitten by my C/Java experience

2015-05-04 Thread Dave Angel

On 05/04/2015 04:28 PM, Cecil Westerhof wrote:

Op Monday 4 May 2015 21:39 CEST schreef Ian Kelly:


On Mon, May 4, 2015 at 11:59 AM, Mark Lawrence  wrote:

On 04/05/2015 16:20, Cecil Westerhof wrote:


Potential dangerous bug introduced by programming in Python as if
it was C/Java. :-( I used: ++tries that has to be: tries += 1

Are there other things I have to be careful on? That does not work
as in C/Java, but is correct syntax.



Not dangerous at all, your test code picks it up. I'd also guess,
but don't actually know, that one of the various linter tools could
be configured to find this problem.


pylint reports it as an error.


I installed it. Get a lot of messages. Mostly convention. For example:
 Unnecessary parens after 'print' keyword


Sounds like it's configured for Python 2.x.  There's probably a setting 
to tell it to use Python3 rules.




And:
 Invalid variable name "f"
for:
 with open(real_file, 'r') as f:


Sounds like a bad wording.  Nothing invalid about it, though it is a bit 
short.  There are certain one letter variables which are so common as to 
be expected, but others should be avoided.





But still something to add to my toolbox.




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


urllib2.urlopen error "socket.error: [Errno 104] Connection reset by peer"

2015-05-04 Thread Jia CHEN
Hi There,
 
I have the error below when trying to download the html content of a webpage. I 
can open this webpage in a browser without any problem. I am using Ubuntu 
14.04. Could you give me come clues about what is happening and how to solve 
the issue? Thanks.
 
$python 
 
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
 
[GCC 4.8.2] on linux2
 
Type "help", "copyright", "credits" or "license" for more information.
 
>>> import urllib2
 
request = 
urllib2.Request('http://guggenheiminvestments.com/products/etf/gsy/holdings')
 
response = urllib2.urlopen(request)
 
>>> >>> Traceback (most recent call last):
 
File "", line 1, in 
 
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
 
return _opener.open(url, data, timeout)
 
File "/usr/lib/python2.7/urllib2.py", line 404, in open
 
response = self._open(req, data)
 
File "/usr/lib/python2.7/urllib2.py", line 422, in _open
 
'_open', req)
 
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
 
result = func(*args)
 
File "/usr/lib/python2.7/urllib2.py", line 1214, in http_open
 
return self.do_open(httplib.HTTPConnection, req)
 
File "/usr/lib/python2.7/urllib2.py", line 1187, in do_open
 
r = h.getresponse(buffering=True)
 
File "/usr/lib/python2.7/httplib.py", line 1045, in getresponse
 
response.begin()
 
File "/usr/lib/python2.7/httplib.py", line 409, in begin
 
version, status, reason = self._read_status()
 
File "/usr/lib/python2.7/httplib.py", line 365, in _read_status
 
line = self.fp.readline(_MAXLINE + 1)
 
File "/usr/lib/python2.7/socket.py", line 476, in readline
 
data = self._sock.recv(self._rbufsize)
 
socket.error: [Errno 104] Connection reset by peer
 
>>>

Best,

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