Re: What for -- for? (was A bug?)

2014-10-29 Thread Rustom Mody
On Wednesday, October 29, 2014 11:14:14 AM UTC+5:30, Zachary Ware wrote:
 On Wed, Oct 29, 2014 at 12:27 AM, Ben Finney  wrote:
  Zachary Ware writes:
 
  Of course, Gmail decided to wrap my long line for me. In case it's not
  obvious, that should be a single line.
 
  Right, GMail is a poor choice for composing messages. You might get
  better results installing a proper mail client, and communicating via
  IMAP.
 
 Noted, but it works fine 99% of the time for me.  I'm not really
 interested in trying to get a proper mail client set up on 5 different
 devices and 4 different platforms with settings shared between all
 just to avoid inconvenient line-wrapping (that I can avoid just by
 sticking to 80 column lines in the first place :).

I was going to say the same:
gmail is fine if you remember to press RET 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What for -- for? (was A bug?)

2014-10-29 Thread Ben Finney
Zachary Ware zachary.ware+pyl...@gmail.com writes:

 […] just to avoid inconvenient line-wrapping (that I can avoid just by
 sticking to 80 column lines in the first place :).

That is a valid solution. If you have the discipline to stick to it,
congratulations :-)

-- 
 \“If you ever drop your keys into a river of molten lava, let |
  `\ 'em go, because, man, they're gone.” —Jack Handey |
_o__)  |
Ben Finney

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


%%(%s)s mean in python

2014-10-29 Thread satishmlmlml
def fetchRecord(db, form): 
 try: 
  key = form['key'].value 
  record = db[key] 
  fields = record.__dict__ 
  fields['key'] = key 
 except: 
  fields = dict.fromkeys(fieldnames, '?') 
  fields['key'] = 'Missing or invalid key!' 
 return fields 
def updateRecord(db, form): 
 if not 'key' in form: 
  fields = dict.fromkeys(fieldnames, '?') 
  fields['key'] = 'Missing key input!' 
 else: 
  key = form['key'].value 
  if key in db: 
   record = db[key] 
 else: 
   from person import Person 
   record = Person(name='?', age='?') 
 for field in fieldnames: 
   setattr(record, field, eval(form[field].value)) 
  db[key] = record 
  fields = record.__dict__ 
  fields['key'] = key 
 return fields 
db  =  shelve.open(shelvename) 
action = form['action'].value if 'action' in form else None 
if action == 'Fetch': 
 fields = fetchRecord(db, form) 
elif action == 'Update': 
 fields = updateRecord(db, form) 
else: 
 fields = dict.fromkeys(fieldnames, '?') 
 fields['key'] = 'Missing or invalid action!' 
db.close() 
print(replyhtml % htmlize(fields)) 

What does %%(%s)s mean in Python?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: .write() behavior

2014-10-29 Thread Marko Rauhamaa
Alan Bawden a...@scooby-doo.csail.mit.edu:

 You might be right, because nothing in the Python 2 documentation I
 can find _explicitly_ says that file.write() is guaranteed to write
 everything I told it to, but that seems like a sufficiently surprising
 fact that I would expect the documentation to emphasize the danger.

One can guess that Python2's write tries to push everything into file in
a loop.

 In Python 3 the situation is more puzzling: The documentation for
 open() explains that the type of object returned depends on the mode
 argument, and several possible candidates for the class of the file
 object returned are mentioned. Some of those classes document a
 .write() method that may indeed perform a partial write and return a
 count of how far it got. Other classes don't say that they might do
 partial writes, but neither do they say that they don't do partial
 writes. It seems possible that the _intent_ is that text mode opens
 return a file object that guarantees to always do a full write. But
 maybe not.

Hard to know based on the documentation alone.

Let me mention a related problem I ran into a couple of weeks ago.
Linux's standard C library (glibc) implements fread(3) differently in
RHEL 5 and RHEL 6/7. In RHEL 5, it blocks in a loop until it has read in
the desired number of records. In RHEL 6 and 7, it appears to block
until it can return at least one whole record.

 Am I missing something? There seem to be some primitive IO facilities
 in Python 3 that make a distinction between blocking and non-blocking
 mode, but that distinction doesn't seem to be available when I just
 call open().

I don't think you can do nonblocking I/O with the file.* methods. At
least you shouldn't try.

The solution is to use os.read(), os.write(), os.pipe(), os.fork() et
al. Their semantics is crystal clear.

The same dichotomy is there in C. Do you use stdio facilities or system
calls? Depends on the type of application you are writing.


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


Re: What for -- for? (was A bug?)

2014-10-29 Thread Rustom Mody
On Wednesday, October 29, 2014 11:10:06 AM UTC+5:30, Zachary Ware wrote:
 On Wed, Oct 29, 2014 at 12:15 AM, Rustom Mody wrote:
  Maybe nicer to filter out the false's with a filter-false thus??
 
  def ff(d): return [n for n in d if d[n]]
 
 Sure.  Or, combining things:
 
 try:
 from collections import abc
 except ImportError:
 import collections as abc
 from abc import ABCMeta
 
 abcs = [o for o in vars(abc).values() if isinstance(o, ABCMeta)]
 
 def get_abcs(cls):
 return [abc for abc in abcs if issubclass(cls, abc)]
 
 def get_abc_names(cls):
 return [abc.__name__ for abc in get_abcs(cls)]
 
 
 
 Of course, that's 3 (progressively shorter) loops to get the names of
 the ABCs of a class compared to 1 (fairly short in the first place)
 loop for a map of relationships to all available ABCs, but optimizing
 such a toy as this would just be an exercise in futility :)

Not so.

The charm of introspection is that the introspection
itself can be introspected.
For that to be convincing there needs to be a good combo
of clarity and succinctness.  In particular why not reduce
the two functions to one?

def get_abc_names(cls):
return [abc.__name__ for abc in abcs if issubclass(cls,abc)]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: %%(%s)s mean in python

2014-10-29 Thread satishmlmlml
also
what does
rowshtml += (rowhtml % ((fieldname,) * 3)) expand to?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What for -- for? (was A bug?)

2014-10-29 Thread Zachary Ware
On Wed, Oct 29, 2014 at 1:11 AM, Rustom Mody rustompm...@gmail.com wrote:
 On Wednesday, October 29, 2014 11:10:06 AM UTC+5:30, Zachary Ware wrote:
 Of course, that's 3 (progressively shorter) loops to get the names of
 the ABCs of a class compared to 1 (fairly short in the first place)
 loop for a map of relationships to all available ABCs, but optimizing
 such a toy as this would just be an exercise in futility :)

 Not so.

 The charm of introspection is that the introspection
 itself can be introspected.
 For that to be convincing there needs to be a good combo
 of clarity and succinctness.  In particular why not reduce
 the two functions to one?

 def get_abc_names(cls):
 return [abc.__name__ for abc in abcs if issubclass(cls,abc)]

Well, it depends on what you actually want, the spec has been a bit fuzzy ;)

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


What does %%(%s)s mean/expand to in Python? What does rowshtml += (rowhtml % ((fieldname, ) * 3)) expand to? Kindly explain.

2014-10-29 Thread satishmlmlml
def fetchRecord(db, form): 
 try: 
  key = form['key'].value 
  record = db[key] 
  fields = record.__dict__ 
  fields['key'] = key 
 except: 
  fields = dict.fromkeys(fieldnames, '?') 
  fields['key'] = 'Missing or invalid key!' 
 return fields 
def updateRecord(db, form): 
 if not 'key' in form: 
  fields = dict.fromkeys(fieldnames, '?') 
  fields['key'] = 'Missing key input!' 
 else: 
  key = form['key'].value 
  if key in db: 
   record = db[key] 
 else: 
   from person import Person 
   record = Person(name='?', age='?') 
 for field in fieldnames: 
   setattr(record, field, eval(form[field].value)) 
  db[key] = record 
  fields = record.__dict__ 
  fields['key'] = key 
 return fields 
db  =  shelve.open(shelvename) 
action = form['action'].value if 'action' in form else None 
if action == 'Fetch': 
 fields = fetchRecord(db, form) 
elif action == 'Update': 
 fields = updateRecord(db, form) 
else: 
 fields = dict.fromkeys(fieldnames, '?') 
 fields['key'] = 'Missing or invalid action!' 
db.close() 
print(replyhtml % htmlize(fields)) 

What does %%(%s)s mean in Python? 

also 
what does 
rowshtml += (rowhtml % ((fieldname,) * 3)) expand to? 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What does %%(%s)s mean/expand to in Python? What does rowshtml += (rowhtml % ((fieldname, ) * 3)) expand to? Kindly explain.

2014-10-29 Thread Peter Otten
satishmlm...@gmail.com wrote:


 What does %%(%s)s mean in Python?

According to 

https://docs.python.org/2/library/stdtypes.html#string-formatting

in an expression like

%%(%s)s % (foo,)

'%%' expands to '%' and

'%s' expands to 'foo'

so the whole thing gives

 %%(%s)s % (foo,)
'%(foo)s'

To this you can then apply another formatting operation that takes a dict as 
its right operand to look up 'foo':

 %(foo)s % {foo: bar}
'bar'

What you have with %%(%s)s is then a template for a template.

 also
 what does
 rowshtml += (rowhtml % ((fieldname,) * 3)) expand to?

(fieldname,)

is a 1-tuple, so

(fieldname,) *3  gives a 3-tuple (fieldname, fieldname, fieldname):

 fieldname = foo
 (fieldname,) * 3
('foo', 'foo', 'foo')

rowhhtml % (fieldname, fieldname, fieldname)

is again string interpolation. Assuming rowhtml contains

%s%s%s may you get

 fieldname = foo
 rowhtml = %s%s/%s
 rowhtml % ((fieldname,)*3)
'foofoo/foo'


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


Re: What does %%(%s)s mean/expand to in Python? What does rowshtml += (rowhtml % ((fieldname, ) * 3)) expand to? Kindly explain.

2014-10-29 Thread Christian Gollwitzer

Am 29.10.14 07:15, schrieb satishmlm...@gmail.com:

What does %%(%s)s mean in Python?


Instead of posting all those questions here, you can simply try it in an 
interactive python interpreter:


Apfelkiste:VecTcl chris$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type help, copyright, credits or license for more information.
 test='%%(%s)s'
 test % 'foo'
'%(foo)s'



also
what does
rowshtml += (rowhtml % ((fieldname,) * 3)) expand to?


 fieldname='foo'
 (fieldname,)*3
('foo', 'foo', 'foo')
 test='first %s second %s third %s'
 test % ((fieldname,)*3)
'first foo second foo third foo'


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


Re: % symbol in python

2014-10-29 Thread Mark Lawrence

On 29/10/2014 05:48, satishmlm...@gmail.com wrote:

kindly let me know
what does
%%(%s)% mean



What did you not understand from the link I posted ten hours ago?

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


Meaning of * in the function arguments list

2014-10-29 Thread ast

Hi

Consider the following to_bytes method from integer class:

int.to_bytes(length, byteorder, *, signed=False)

What doest the '*' in the arguments list means ?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Meaning of * in the function arguments list

2014-10-29 Thread Peter Otten
ast wrote:

 Consider the following to_bytes method from integer class:
 
 int.to_bytes(length, byteorder, *, signed=False)
 
 What doest the '*' in the arguments list means ?

A bare * indicates that the arguments that follow it are keyword-only:

 def f(a, b=2, *, c=3):
... print(a = {}, b = {}, c = {}.format(a, b, c))
... 
 f(10)
a = 10, b = 2, c = 3
 f(10, 20)
a = 10, b = 20, c = 3
 f(10, 20, 30)
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: f() takes from 1 to 2 positional arguments but 3 were given
 f(10, 20, c=30)
a = 10, b = 20, c = 30


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


Re: memory, PE files, etc...

2014-10-29 Thread Tim Golden
On 29/10/2014 02:18, Denis McMahon wrote:
 On Mon, 27 Oct 2014 10:16:43 -0700, kiuhnm03 wrote:
 
 I'd like to write one or more scripts that analyze processes in memory
 on Windows 7. I used to do these things in C++ by using native Win32 API
 calls.
 How should I proceed in python? Any pointers?
 
 This seems to be a very common request. Does anyone know why?
 

I certainly wouldn't have called it common, assuming you're referring to
the specific request of analyzing processes in memory. I admit we do see
on and off the more general request of How do I do in Python on Windows
this thing I can do in C/C++?.

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


Re: Meaning of * in the function arguments list

2014-10-29 Thread ast


Peter Otten __pete...@web.de a écrit dans le message de 
news:mailman.15291.1414574006.18130.python-l...@python.org...


A bare * indicates that the arguments that follow it are keyword-only:



ok, thx 


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


Python Style Question

2014-10-29 Thread Anton
Let's say I have an incoming list of values *l*. Every element of *l* can be 
one of the following options:
1) an integer value 
2) a string in form of 'int_value', e.g. '7'
3) a string with a json serialization of an integer value, e.g. '7'
4) something else that should be ignored

I need to transform this list into another list with values from options 1)-3) 
coerced to int. The code below should do this.


Variant 1
===

values = []
for c in l:
# Case 1) or 2)
try:
c_int = int(c)
except ValueError:
pass
else:
values.add(c_int)
continue

# Case 3)
try:
c_int = int(json.loads(c))
except ValueError:
pass
else:
values.add(c_int)
continue

===

Is this code ugly? 
Does it follow EAFP? 
Am I missing something in language best practice?

Or maybe below is more preferable way with a nested try...except clause?

Variant 2
===
values = []
for c in l:
# Case 1) or 2)
try:
c_int = int(c)
except ValueError:

# Case 3)
try:
c_int = int(json.loads(c))
except ValueError:
pass
else:
values.add(c_int)
continue

else:
values.add(c_int)
continue
===

Thanks,
Anton.


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


Re: %%(%s)s mean in python

2014-10-29 Thread Ned Batchelder

On 10/29/14 2:02 AM, satishmlm...@gmail.com wrote:

def fetchRecord(db, form):
  try:


... 34 lines deleted ...


db.close()
print(replyhtml % htmlize(fields))


Why did you paste all this code, it doesn't have the thing you are 
asking about.




What does %%(%s)s mean in Python?



It depends entirely on context. You'll need to find a *small* example of 
what you are asking about so we can help.


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

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


Re: Python Style Question

2014-10-29 Thread Martin Kemp
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 29/10/2014 10:45, Anton wrote:
 Let's say I have an incoming list of values *l*. Every element of
 *l* can be one of the following options: 1) an integer value 2) a
 string in form of 'int_value', e.g. '7' 3) a string with a json
 serialization of an integer value, e.g. '7' 4) something else
 that should be ignored
 
 I need to transform this list into another list with values from
 options 1)-3) coerced to int. The code below should do this.
 
 
 Variant 1 ===
 
 values = [] for c in l: # Case 1) or 2) try: c_int = int(c) except
 ValueError: pass else: values.add(c_int) continue
 
 # Case 3) try: c_int = int(json.loads(c)) except ValueError: pass 
 else: values.add(c_int) continue
 
 ===
 
 Is this code ugly? Does it follow EAFP? Am I missing something in
 language best practice?
 
 Or maybe below is more preferable way with a nested try...except
 clause?
 
 Variant 2 === values = [] for c in l: # Case 1) or 2) try: c_int =
 int(c) except ValueError:  # Case 3) try: c_int =
 int(json.loads(c)) except ValueError: pass else: values.add(c_int) 
 continue  else: values.add(c_int) continue ===
 
 Thanks, Anton.
 
 

Your first example is perfectly fine and is EAFP

Personally, I prefer to avoid nesting when it's not necessary.

- -- 
Martin Kemp (martin.k...@ingg.com)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iQEcBAEBAgAGBQJUUM7zAAoJEJ0Re0UIDzSucugIALn/zY8RdpP8iaMShHoszzqf
I0zl0mFHyqhNtwgQ0ZF7VGO+H+U0Dk8rhzTYOmEMzPTKNBGwll3fda9mOnrK9Xvp
9gQjII6DyQIWH7Z3dLcLr2e1j8OMNUSL6UmAYs8urNSIKZLowdV3JI4G/bLyW0KS
y5Ko8dI6y5nOJ1P9XCmPTmags43UZfR8DrBUaAbzNcS8FGwmUE2KBkEhLQOvmpJi
jmMc7wMOpq0jL+XbA+7pHUqoVZ7w1tUFjuy9I3h45tgPuTFAFB0gX+FpE+oVgO5o
spQpVaOPEYN9ceLgHdKSxzdVIhOQLE6H/SYNHlsEW/ZNM6aR9n4yipgkOmtJ0+M=
=WzHA
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Style Question

2014-10-29 Thread Rafael Romero Carmona
Hi, first in Python 2.7.6 and Python 3.4.0 list haven't got any add
function but they have append.

I think you could do better with something like

==
import json
l = [1, -1, 0, '1', '-1', '0', json.dumps(-1), json.dumps(1),
json.dumps(0), 'x', 'sqjklsqjk__', (1, 2)]

values = []

for c in l:
try:
c_int = int(c)
except ValueError:
pass
except TypeError:
pass
else:
values.append(c_int)
continue
print(values)
==

The code has been tested in Python 2.7.6 and 3.4 and returns [1, -1,
0, 1, -1, 0, -1, 1, 0]

You don't need to do two try because you can process both exceptions
in the same way. You don't really need to do json.loads because if you
have a json string which is an integer, you could do that directly
with int(c) which can take a string and transform in an integer.

With ValueError it captures the exception when it tries to transform
the characters' strings and with TypeError it captures the exception
when it tries to work with the tuples.

Have a good day and hope it works for you!

2014-10-29 11:42 GMT+01:00 Anton anton.schattenf...@gmail.com:
 Let's say I have an incoming list of values *l*. Every element of *l* can be 
 one of the following options:
 1) an integer value
 2) a string in form of 'int_value', e.g. '7'
 3) a string with a json serialization of an integer value, e.g. '7'
 4) something else that should be ignored

 I need to transform this list into another list with values from options 
 1)-3) coerced to int. The code below should do this.


 Variant 1
 ===

 values = []
 for c in l:
 # Case 1) or 2)
 try:
 c_int = int(c)
 except ValueError:
 pass
 else:
 values.add(c_int)
 continue

 # Case 3)
 try:
 c_int = int(json.loads(c))
 except ValueError:
 pass
 else:
 values.add(c_int)
 continue

 ===

 Is this code ugly?
 Does it follow EAFP?
 Am I missing something in language best practice?

 Or maybe below is more preferable way with a nested try...except clause?

 Variant 2
 ===
 values = []
 for c in l:
 # Case 1) or 2)
 try:
 c_int = int(c)
 except ValueError:

 # Case 3)
 try:
 c_int = int(json.loads(c))
 except ValueError:
 pass
 else:
 values.add(c_int)
 continue

 else:
 values.add(c_int)
 continue
 ===

 Thanks,
 Anton.


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


Re: Python Style Question

2014-10-29 Thread Rafael Romero Carmona
2014-10-29 12:25 GMT+01:00 Martin Kemp martin.k...@ingg.com:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 29/10/2014 10:45, Anton wrote:
 Let's say I have an incoming list of values *l*. Every element of
 *l* can be one of the following options: 1) an integer value 2) a
 string in form of 'int_value', e.g. '7' 3) a string with a json
 serialization of an integer value, e.g. '7' 4) something else
 that should be ignored

 I need to transform this list into another list with values from
 options 1)-3) coerced to int. The code below should do this.


 Variant 1 ===

 values = [] for c in l: # Case 1) or 2) try: c_int = int(c) except
 ValueError: pass else: values.add(c_int) continue

 # Case 3) try: c_int = int(json.loads(c)) except ValueError: pass
 else: values.add(c_int) continue

 ===

 Is this code ugly? Does it follow EAFP? Am I missing something in
 language best practice?

 Or maybe below is more preferable way with a nested try...except
 clause?

 Variant 2 === values = [] for c in l: # Case 1) or 2) try: c_int =
 int(c) except ValueError:  # Case 3) try: c_int =
 int(json.loads(c)) except ValueError: pass else: values.add(c_int)
 continue  else: values.add(c_int) continue ===

 Thanks, Anton.



 Your first example is perfectly fine and is EAFP


Actually it doesn't work because there is no add function and it
doesn't catch the TypeError function to ignore other exceptions than
ValueError. Doesn't it? I tested in Python 2.7.6 and 3.4.

 Personally, I prefer to avoid nesting when it's not necessary.

 - --
 Martin Kemp (martin.k...@ingg.com)
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v2

 iQEcBAEBAgAGBQJUUM7zAAoJEJ0Re0UIDzSucugIALn/zY8RdpP8iaMShHoszzqf
 I0zl0mFHyqhNtwgQ0ZF7VGO+H+U0Dk8rhzTYOmEMzPTKNBGwll3fda9mOnrK9Xvp
 9gQjII6DyQIWH7Z3dLcLr2e1j8OMNUSL6UmAYs8urNSIKZLowdV3JI4G/bLyW0KS
 y5Ko8dI6y5nOJ1P9XCmPTmags43UZfR8DrBUaAbzNcS8FGwmUE2KBkEhLQOvmpJi
 jmMc7wMOpq0jL+XbA+7pHUqoVZ7w1tUFjuy9I3h45tgPuTFAFB0gX+FpE+oVgO5o
 spQpVaOPEYN9ceLgHdKSxzdVIhOQLE6H/SYNHlsEW/ZNM6aR9n4yipgkOmtJ0+M=
 =WzHA
 -END PGP SIGNATURE-
 --
 https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


problem with pefile

2014-10-29 Thread gandalf23
Where is DIRECTORY_ENTRY_LOAD_CONFIG?
In the changelog (https://code.google.com/p/pefile/) one can read:

Version: 1.2.10-60

Besides some small bugfixes in this release I've added functionality to 
parse the LOAD_CONFIG data directory. Now one can access this structure's 
fields like, for instance, pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SecurityCookie 
or pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SEHandlerTable

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


Re: Python Style Question

2014-10-29 Thread Martin Kemp
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 29/10/2014 12:01, Rafael Romero Carmona wrote:
 2014-10-29 12:25 GMT+01:00 Martin Kemp martin.k...@ingg.com: On
 29/10/2014 10:45, Anton wrote:
 Let's say I have an incoming list of values *l*. Every
 element of *l* can be one of the following options: 1) an
 integer value 2) a string in form of 'int_value', e.g. '7'
 3) a string with a json serialization of an integer value,
 e.g. '7' 4) something else that should be ignored
 
 I need to transform this list into another list with values
 from options 1)-3) coerced to int. The code below should do
 this.
 
 
 Variant 1 ===
 
 values = [] for c in l: # Case 1) or 2) try: c_int = int(c)
 except ValueError: pass else: values.add(c_int) continue
 
 # Case 3) try: c_int = int(json.loads(c)) except ValueError:
 pass else: values.add(c_int) continue
 
 ===
 
 Is this code ugly? Does it follow EAFP? Am I missing
 something in language best practice?
 
 Or maybe below is more preferable way with a nested
 try...except clause?
 
 Variant 2 === values = [] for c in l: # Case 1) or 2) try:
 c_int = int(c) except ValueError:  # Case 3) try: c_int = 
 int(json.loads(c)) except ValueError: pass else:
 values.add(c_int) continue  else: values.add(c_int) continue
 ===
 
 Thanks, Anton.
 
 
 
 Your first example is perfectly fine and is EAFP
 
 
 Actually it doesn't work because there is no add function and it 
 doesn't catch the TypeError function to ignore other exceptions
 than ValueError. Doesn't it? I tested in Python 2.7.6 and 3.4.
 
 Personally, I prefer to avoid nesting when it's not necessary.
 
 -- https://mail.python.org/mailman/listinfo/python-list

Ah ok, style-wise it was fine.

- -- 
Martin Kemp (martin.k...@ingg.com)

-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iQEcBAEBAgAGBQJUUOD+AAoJEJ0Re0UIDzSu1KQIAK6aCMOv4VqOjmm/zoQrmzLf
UGBCLwtHrnDkbXFAIweTSFiM1uf9TDaRpJqY1IrPbJHI4/EAP0Hu07nyx3V6HgzM
/+Wb3DkpjW+JQoVqDSGzE/dTPJcU3/b1/EWWpbu72JHplqz9laEAFt9muWyDPs9u
kDgM06mDd50lsi83W3i0H1iGL6YbLtsik+/x4G4mMjdq1o9BvRpUjkIiOx7yJ/BR
OYzdudltXGqlXcToufHTU2lUv2C0RoHHNO4kytiLoUekCBdGE+Jy/6gQq/AKQu4G
0RYjCOnKNgugfdmDuHi0julPtTEzc+MdY/CcPob4cyy8RDzfQGklGKHP7f9+SJs=
=hjWU
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem with pefile

2014-10-29 Thread Tim Golden
On 29/10/2014 13:15, gandal...@mail.com wrote:
 Where is DIRECTORY_ENTRY_LOAD_CONFIG? In the changelog
 (https://code.google.com/p/pefile/) one can read:
 
 Version: 1.2.10-60
 
 Besides some small bugfixes in this release I've added functionality
 to parse the LOAD_CONFIG data directory. Now one can access this
 structure's fields like, for instance,
 pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SecurityCookie or
 pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SEHandlerTable
 

I suggest you engage with the maintainers of that project. It appears to
have an issue tracker:

https://code.google.com/p/pefile/issues/list

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


Re: Build Question: How to Add -Wl, --option Before Objects In Setup.py?

2014-10-29 Thread Cyd Haselton
On Tue, Oct 28, 2014 at 4:01 PM, Ned Deily n...@acm.org wrote:
 In article
 cahu5pra68edgkvfyhtq+srmb6syew9a1sabb5cemluzqbs5...@mail.gmail.com,
  Cyd Haselton chasel...@gmail.com wrote:

 On Tue, Oct 28, 2014 at 3:11 AM, Ned Deily n...@acm.org wrote:
  In article
  CAHu5PrY-T=DT3wOg-Y+Va9WgwBV3w9d7M-tu=_n-cngwssz...@mail.gmail.com,
   Cyd Haselton chasel...@gmail.com wrote:
  [...]
  I'm building python on an Android device in the KBOX
  environment...which simulates a Unix type filesystem.
  Python isn't installed; I'm building from sources (2.7.8) with GCC
  4.8.0 and make.
 
  The problem with the LDFLAGS approach is that some of the libraries
  that must be linked (-lc -ldl) do not need the --allow-shlib-undefined
  option...it's only the lpython2.7 that does.  Any way to do this?
 
  Sorry, I have no experience with that environment nor an understanding
  of why you need to specify --allow-shlib-undefined (it seems to be the
  default in some versions of ld).  You could look at and, if necessary,
  modify Lib/distutils, the part of the Python standard library that
  builds extension modules from setup.py.

 No need to apologize.  Also no need to have an understanding of the
 environment; with a few rare exceptions it behaves just like a
 Unix/Linux one.

 The reason why I need to specify --allow-shlib-undefined is for the
 python library; it's throwing undefined references to sincos even
 though the symbol is there. Specifying that option is the only fix
 I've found.

 As mentioned earlier, i'm not familiar with python or its build
 system; which file in the distutils dir do I need to modify?

 Perhaps I should apologize for not asking earlier what you are really
 trying to do before suggesting heading down the path of modifying
 Distutils :)  So the issue is with an undefined reference to sincos?  It
 appears that that routine is often supplied in libm.  Is that the case
 on your platform?

Yes it is.

 And, if so, the right fix might be to supply it
 manually or, better, ensure that Python supplies it as a result of
 running ./configure.

If the Makefile generated is a result of running ./configure, then
Python is indeed finding the library...what it is doing with it after
finding it may be something else entirely.  I've tried everything from
adding the -Wl,--no-allow-shlib-undefined option to adding #include
math.h to the complexobject.c code...I still get an undefined
reference to sincos.  Running
grep sincos libpython2.7.* turns up the offending symbol (function?
declaration?) but re-running make after that still throws the same
error.

The only fix I've found is adding the -Wl,--allow-shlib-undefined
before the python library...which I do by hacking the Makefile.  That
allows the build to continue, which it does until it hits the part
where setup.py is run.

 Also, what version of Python are you building?

2.7.8.  I thought that it would be easier to build it on Android


 --
  Ned Deily,
  n...@acm.org

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


Re: hotel management system

2014-10-29 Thread Florian Schweikert
On 28/10/14 07:42, ngangsia akumbo wrote:
 Please can someone look at my code and may be advice and may be help me with 
 some correction. I have been learning python for some time now. This is my 
 first project i wish to write. A hotel management system.
 
 
 http://pastebin.com/LMHmuTiC

Beside posting the code inline, it would be easier if you had split the
employee part and the part with the classes.

I'm not sure what you want to accomplish with this code, but I picked a
few parts:

 if age = 18:
 pass
 
 else:
 return age_lim()

using a function just to print a single line is quite overcomplicated.
return the result and handle it on the caller side.
why do you use if/else and just pass first path?

if age18:
do_something

do the same thing.

I have to guess what the class part should do.

 class Bar:

why calling a class Bar if you use it like some drink counter?

 total_cost = 0
 count = 0

not sure you want to use class variables here, do you want to count
amount of a single type of beer? or everything

 def set_name(self, name):
 self.name = name
 return name

don't use setter if there is 0 logic in the function
also it would be better to set this things in the constructor otherwise
and a setter should not return the name just set

 def set_count(self):
 counts = Bar.count =+ 1

not really readable code style, counts variable is unneccessary here

 # still have to adjust this section
 
 def set_total_cost(self):  #I am having some errors 
 #calling this functions
 total = set_price() * set_count()
 print Total cost of drinks: , total
 pass

well, it's quite obvious this function crashes, you try to use not
defined functions. you have to use self.function_name to access the methods.
But worse than this you want to use (useless) setter to get values and
print them inside the method instead of returning the value and handle
it outside.
Also this is not even a setter, it does not set anything beside a local
variable.

Maybe it would be best you start over again and make one step after
another. Build one part of code and ensure it works before starting with
more code. And ask specific questions if you stuck somewhere.


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


Emulating py2exe for python version 3 and above

2014-10-29 Thread Ian Dickinson
Can i emulate py2exe for python version 3 and above i also use pygame any
suggestions for a basic staring script would be greatly appreciated


Thanks

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


Re: %%(%s)s mean in python

2014-10-29 Thread Thomas Rachel

Am 29.10.2014 07:02 schrieb satishmlm...@gmail.com:


What does %%(%s)s mean in Python?


Weird question, as this has nothing to do with the code you just posted.

In general, what comes up to my mind, is that it is a format string to 
build another format string.


Example:

metafmt = '%%(%s)s'
fieldname = 'myfield'
fmt = metafmt % fieldname
# Now we have a fmt as if it was assigned with '%(myfield)s':
# %% - %, %s - myfield.

d = {fieldname: 'my content'}

print fmt % d
# this now prints the given field - which is noted in fieldname -
# from the given dict d.
--
https://mail.python.org/mailman/listinfo/python-list


Send UDP packet to link-local IPv6 address?

2014-10-29 Thread Grant Edwards
How do you send a UDP frame to an IPv6 link-local address?

Initially, I'm most concerned with Linux.

I'm using CPython 2.7.7, but so far all behavior seems to be identical
under 3.3.5, and I need to keep my code compatible with both 2.7 and
3.3/3.4.

I'm particularly interested in sending to the all-nodes multicast
address (ff02::1), but all the experimenting I've done seems to show
that multicast and unicast behave the same.

With link-local addresses you also need to specify which interface to
use. The normal way of doing this on Linux with command-line utilities
is append %ifname to the address/hostname (e.g. ping6 ff02::1%net1).

That doesn't work:

s.sendto(data, (ff02::1%net1,port))
s.sendto(data, (fe80::2c0:4eff:fe40:5f%net1,port))

The %net1 appears to be ignored, and the packet will go out _some_
interface, but I can't figure out how it decides which one (it's not
always the same one).

The only way I've found to send to link-local IPv6 addresses is to use
the extended length destination address tuple of (address, port,
flow_info, scope_id) like so:

s.sendto(data, (ff02::1,port,0,scope_id))
s.sendto(data, (fe80::2c0:4eff:fe40:5f,port,0,scope_id))

Through trial and error, I've determined that the valid scope_id
values for my system are 0,2,3,4, and I've found that 4 corresponds to
interface net1.

After re-reading the Python 2.7 socket module documentation, I can't
find any way to map an interface name to a scope id.  So, after
browsing around /proc, I found the file /proc/net/if_inet6 which
contains:

$ cat if_inet6 
fe80922b34fffe5e7edc 03 40 20 80 net0
0001 01 80 10 80   lo
fdfedcba98760011 04 40 00 80 net1
fe80021b21fffeb1d1e9 04 40 20 80 net1
fdfedcba987600080004 03 40 00 80 net0
fe80922b34fffe5e7ede 02 40 20 80 net2

The first column is obviously the IPv6 address and the last column
the interface name.

It appears that second column is the scope id, and some further
reading has lead me to believe that the fourth column is the scope
(global vs. link-local vs. internal). So I've done the following:

ip6scopeid = {}
for line in open(/proc/net/if_inet6):
addr, id, _, scope, _, ifacename = line.split()
ip6scopeid[ifacename] = int(id)

This is highly non-portable, but now I can at least send to link-local
addresses like this:

s.sendto(data, (ff02::1,port,0,ip6scopeid[net1]))
s.sendto(data, (fe80::2c0:4eff:fe40:5f,port,0,ip6scopeid[net1]))

So, my program works (but only on Linux).


What's the pythonic, portable way to do this?


The only other thing I can think of is to make the user specify the
IPv6 address of the interface they want to send from, bind a socket to
that address, then ask for that socket's address:

 s.bind((fdfe:dcba:9876:10::1,65432))
 print s.getsockname()

The above prints this:

 ('fdfe:dcba:9876:10::1', 5678, 0, 0)
 
so, it unfortunately appears that getsockname() doesn't return the
scope id if you bind to the global address assigned to an interface.  

Trying to bind to the link-local address fails unless you already know
the scope id and pass it to bind:

This fails:  s.bind((fe80::21b:21ff:feb1:d1e9,5678))
This works:  s.bind((fe80::21b:21ff:feb1:d1e9,5678,0,4))

But I'm trying to _find_ the scope id, so that isn't helpful.

Any suggestions?

Ideally, I'd like a solution that works on Windows and BSD as well...

-- 
Grant Edwards   grant.b.edwardsYow! Am I SHOPLIFTING?
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem with pefile

2014-10-29 Thread gandalf23
On Wednesday, October 29, 2014 2:39:30 PM UTC+1, Tim Golden wrote:
 On 29/10/2014 13:15, gandalf23 wrote:
  Where is DIRECTORY_ENTRY_LOAD_CONFIG? In the changelog
  (https://code.google.com/p/pefile/) one can read:
  
  Version: 1.2.10-60
  
  Besides some small bugfixes in this release I've added functionality
  to parse the LOAD_CONFIG data directory. Now one can access this
  structure's fields like, for instance,
  pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SecurityCookie or
  pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SEHandlerTable
  
 
 I suggest you engage with the maintainers of that project. It appears to
 have an issue tracker:
 
 https://code.google.com/p/pefile/issues/list
 
 TJG

I found out what's the problem by reading the source code.
The attributes DIRECTORY_ENTRY_* are added dynamically to an instance of the 
class PE when/if the corresponding directories are found in the PE file.

OT: how can I hide my email in these posts?
Every time I try to send a post, google warns me that my email is visible and 
so I edit it out.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem with pefile

2014-10-29 Thread Kiuhnm
Little test...sorry.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem with pefile

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 4:34:42 PM UTC+1, Kiuhnm wrote:
 OT: how can I hide my email in these posts?
 Every time I try to send a post, google warns me that my email is visible and 
 so I edit it out.

Problem solved :)
-- 
https://mail.python.org/mailman/listinfo/python-list


optional types

2014-10-29 Thread Kiuhnm
I must say that the lack of static types in Python is a pain in the neck 
especially when I'm exploring new libraries.
Recently, I learned a new language called Dart which have optional typing and I 
had a lot of fun with it. Basically, you use type annotations as documentation 
and to give useful information to the IDE or editor. That makes the IDE look 
*very* smart!
I'm using PyCharm and more often than not I want to see the list of methods and 
attributes of an object, but the editor won't show them to me because it 
doesn't know the dynamic type of the variable whose value was just returned by 
a function.
That's irritating!
Am I the only one who'd like to see optional types introduced in Python?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send UDP packet to link-local IPv6 address?

2014-10-29 Thread Alain Ketterlin
Grant Edwards invalid@invalid.invalid writes:

[...]
 With link-local addresses you also need to specify which interface to
 use. The normal way of doing this on Linux with command-line utilities
 is append %ifname to the address/hostname (e.g. ping6 ff02::1%net1).

 That doesn't work:

 s.sendto(data, (ff02::1%net1,port))
 s.sendto(data, (fe80::2c0:4eff:fe40:5f%net1,port))

 The %net1 appears to be ignored, and the packet will go out _some_
 interface, but I can't figure out how it decides which one (it's not
 always the same one).

The only way I've found is to use socket.getaddrinfo(), which does
accept %net1 after the IPv6 address, and returns scope_id (actually a
complete sockaddr). I can't access my files now, by I think

socket.getaddrinfo(fe80::2c0:4eff:fe40:5f%net1,port,...)

should work for you (family, socktype etc should be passed also to avoid
searching the results of getaddrinfo()).

Hope this helps,

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


Re: optional types

2014-10-29 Thread Peter Otten
Kiuhnm wrote:

 I must say that the lack of static types in Python is a pain in the neck
 especially when I'm exploring new libraries. Recently, I learned a new
 language called Dart which have optional typing and I had a lot of fun
 with it. Basically, you use type annotations as documentation and to give
 useful information to the IDE or editor. That makes the IDE look *very*
 smart! I'm using PyCharm and more often than not I want to see the list of
 methods and attributes of an object, but the editor won't show them to me
 because it doesn't know the dynamic type of the variable whose value was
 just returned by a function. That's irritating! Am I the only one who'd
 like to see optional types introduced in Python?

Personally I am skeptical, but there is an effort underway:

http://www.mypy-lang.org/
https://mail.python.org/pipermail/python-ideas/2014-August/028742.html

Nothing that your search engine of choice could not have found you...

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


Re: optional types

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 5:57:13 PM UTC+1, Peter Otten wrote:
 Kiuhnm wrote:
 
  I must say that the lack of static types in Python is a pain in the neck
  especially when I'm exploring new libraries. Recently, I learned a new
  language called Dart which have optional typing and I had a lot of fun
  with it. Basically, you use type annotations as documentation and to give
  useful information to the IDE or editor. That makes the IDE look *very*
  smart! I'm using PyCharm and more often than not I want to see the list of
  methods and attributes of an object, but the editor won't show them to me
  because it doesn't know the dynamic type of the variable whose value was
  just returned by a function. That's irritating! Am I the only one who'd
  like to see optional types introduced in Python?
 
 Personally I am skeptical, but there is an effort underway:
 
 http://www.mypy-lang.org/
 https://mail.python.org/pipermail/python-ideas/2014-August/028742.html
 
 Nothing that your search engine of choice could not have found you...

In fact, I did find it, but that didn't stop me from asking :)

You can find something similar for almost any dynamic language out there.
If it isn't an official feature of the language, it's useless, IMHO.

It seems that PyCharm supports some kind of type annotations:
http://www.jetbrains.com/pycharm/webhelp/using-docstrings-to-specify-types.html
Unfortunately, again, if almost no one uses them, they're not very useful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optional types

2014-10-29 Thread Chris Angelico
On Thu, Oct 30, 2014 at 4:18 AM, Kiuhnm gandal...@mail.com wrote:
 Personally I am skeptical, but there is an effort underway:

 http://www.mypy-lang.org/
 https://mail.python.org/pipermail/python-ideas/2014-August/028742.html

 Nothing that your search engine of choice could not have found you...

 In fact, I did find it, but that didn't stop me from asking :)

 You can find something similar for almost any dynamic language out there.
 If it isn't an official feature of the language, it's useless, IMHO.

As you'll see from the python-ideas thread, there's a proposal
under-way to *make* this an official feature. However, it's massively
open to bikeshedding :) If you feel strongly about this, come join us
on python-ideas and weigh in; all input will be warmly received, and
that doesn't mean we respond with flames... not usually, anyway!

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


Re: Send UDP packet to link-local IPv6 address?

2014-10-29 Thread Grant Edwards
On 2014-10-29, Alain Ketterlin al...@dpt-info.u-strasbg.fr wrote:
 Grant Edwards invalid@invalid.invalid writes:

 [...]
 With link-local addresses you also need to specify which interface to
 use. The normal way of doing this on Linux with command-line utilities
 is append %ifname to the address/hostname (e.g. ping6 ff02::1%net1).

 That doesn't work:

 s.sendto(data, (ff02::1%net1,port))
 s.sendto(data, (fe80::2c0:4eff:fe40:5f%net1,port))

 The %net1 appears to be ignored, and the packet will go out _some_
 interface, but I can't figure out how it decides which one (it's not
 always the same one).

 The only way I've found is to use socket.getaddrinfo(), which does
 accept %net1 after the IPv6 address, and returns scope_id (actually a
 complete sockaddr). I can't access my files now, by I think

 socket.getaddrinfo(fe80::2c0:4eff:fe40:5f%net1,port,...)

 should work for you (family, socktype etc should be passed also to avoid
 searching the results of getaddrinfo()).

Doh!, of course that works.  Using getaddrinfo() is how you're always
supposed to do things these days.  Creating an address tuple by hand
is a bad habit left over from too many years spent doing network stuff
in the old days before getaddrinfo et al.  I looked at the
documentation for getaddrinfo(), and I would have sworn I had tried it
and couldn't get it to work.  But it does.

 Hope this helps,

Definitely!

Thanks!

-- 
Grant Edwards   grant.b.edwardsYow! FOOLED you!  Absorb
  at   EGO SHATTERING impulse
  gmail.comrays, polyester poltroon!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optional types

2014-10-29 Thread Ethan Furman

On 10/29/2014 10:18 AM, Kiuhnm wrote:

On Wednesday, October 29, 2014 5:57:13 PM UTC+1, Peter Otten wrote:

Kiuhnm wrote:


I must say that the lack of static types in Python is a pain in the neck
especially when I'm exploring new libraries. Recently, I learned a new
language called Dart which have optional typing and I had a lot of fun
with it. Basically, you use type annotations as documentation and to give
useful information to the IDE or editor. That makes the IDE look *very*
smart! I'm using PyCharm and more often than not I want to see the list of
methods and attributes of an object, but the editor won't show them to me
because it doesn't know the dynamic type of the variable whose value was
just returned by a function. That's irritating! Am I the only one who'd
like to see optional types introduced in Python?


Personally I am skeptical, but there is an effort underway:

http://www.mypy-lang.org/
https://mail.python.org/pipermail/python-ideas/2014-August/028742.html

Nothing that your search engine of choice could not have found you...


In fact, I did find it, but that didn't stop me from asking :)

You can find something similar for almost any dynamic language out there.
If it isn't an official feature of the language, it's useless, IMHO.

It seems that PyCharm supports some kind of type annotations:
http://www.jetbrains.com/pycharm/webhelp/using-docstrings-to-specify-types.html
Unfortunately, again, if almost no one uses them, they're not very useful.


Even if it becomes official, which seems likely, it will still be optional -- hence, only useful if folks actually use 
it.  ;)


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


Re: optional types

2014-10-29 Thread Chris Angelico
On Thu, Oct 30, 2014 at 4:46 AM, Ethan Furman et...@stoneleaf.us wrote:
 Even if it becomes official, which seems likely, it will still be optional
 -- hence, only useful if folks actually use it.  ;)

Yes, but if it's official, the standard library (large parts of it, at
least) will use it, which will make it a lot more useful than it
currently is.

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


Re: Anyone know the solution

2014-10-29 Thread Denis McMahon
On Mon, 27 Oct 2014 08:10:04 -0700, emmanueloje wrote:

 Write a program ...

Hey dudester

I coded a solution for you, you can get it here:

http://www.sined.co.uk/tmp/names.py.txt

Make sure you leave all the comments in so your instructor realises how 
much effort you went in to in researching how to code this.

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


Re: optional types

2014-10-29 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com:

 Yes, but if it's official, the standard library (large parts of it, at
 least) will use it, which will make it a lot more useful than it
 currently is.

I doubt it. Python should decide if it wants to stay Python or become
another Java. I don't really believe in this be everything for
everybody thing. You'll only become nothing for anybody.


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


Re: optional types

2014-10-29 Thread Chris Angelico
On Thu, Oct 30, 2014 at 5:18 AM, Marko Rauhamaa ma...@pacujo.net wrote:
 Chris Angelico ros...@gmail.com:

 Yes, but if it's official, the standard library (large parts of it, at
 least) will use it, which will make it a lot more useful than it
 currently is.

 I doubt it. Python should decide if it wants to stay Python or become
 another Java. I don't really believe in this be everything for
 everybody thing. You'll only become nothing for anybody.

Mebbe. More likely, Python wants to lift ideas from anyone and
everyone. List comprehensions came from the functional world, flexible
string representation came from Pike or bash (or was independently
invented), etc, etc.

Python won't turn into Java. The biggest philosophical difference
between the languages, as I see it, is Java's rigidity of boundaries
versus Python's consenting-adults policy. In Java, you write getters
and setters for everything, you lock your class up and make sure
people use it ONLY in the ways you've specified, you declare
parameters/return values/exceptions so people know exactly what to
expect, etc. Python gets out of your way and lets you write a single
application as a concerted whole; if you want to reach in and fiddle
with another class's members, go for it. I'm not saying that either
philosophy is *wrong*, of course, but just adding type hints to Python
isn't going to change the underlying philosophical model.

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


Re: optional types

2014-10-29 Thread Nick Cash
 Am I the only one who'd like to see optional types introduced in Python?

Nope! Some dude named Guido would like to see them as well:
https://mail.python.org/pipermail/python-ideas/2014-August/028742.html

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


Re: optional types

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 7:19:11 PM UTC+1, Marko Rauhamaa wrote:
 Chris Angelico ros...@gmail.com:
 
  Yes, but if it's official, the standard library (large parts of it, at
  least) will use it, which will make it a lot more useful than it
  currently is.
 
 I doubt it. Python should decide if it wants to stay Python or become
 another Java. I don't really believe in this be everything for
 everybody thing. You'll only become nothing for anybody.
 
 
 Marko

1) Java is not optionally typed.
2) Having optional types is not being everything for everybody, it's just 
being smart.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optional types

2014-10-29 Thread Marko Rauhamaa
Kiuhnm gandal...@mail.com:

 2) Having optional types is not being everything for everybody, it's
 just being smart.

We'll see, we'll see...


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


Re: Python Style Question

2014-10-29 Thread Anton
On Wednesday, October 29, 2014 4:43:33 AM UTC-7, Rafael Romero Carmona wrote:
 Hi, first in Python 2.7.6 and Python 3.4.0 list haven't got any add
 function but they have append.
You are right, in my original code I use set instead of array, so it should be 
either values = set() or values.append() in the original code.
 
 I think you could do better with something like
 
 ==
 import json
 l = [1, -1, 0, '1', '-1', '0', json.dumps(-1), json.dumps(1),
 json.dumps(0), 'x', 'sqjklsqjk__', (1, 2)]
It should also work with cases like [1, json.dumps('-1')], which is case 3), 
sorry if it was not clear in the initial post.
 
 values = []
 
 for c in l:
 try:
 c_int = int(c)
 except ValueError:
 pass
 except TypeError:
 pass
 else:
 values.append(c_int)
 continue
 print(values)
 ==
 
 The code has been tested in Python 2.7.6 and 3.4 and returns [1, -1,
 0, 1, -1, 0, -1, 1, 0]
 
 You don't need to do two try because you can process both exceptions
 in the same way. You don't really need to do json.loads because if you
 have a json string which is an integer, you could do that directly
 with int(c) which can take a string and transform in an integer.
In case of 3) an element can be a string like '1', which will fail int(...), 
in this case it tries to parse it with json.


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


Re: optional types

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 8:03:16 PM UTC+1, Kiuhnm wrote:
 On Wednesday, October 29, 2014 7:19:11 PM UTC+1, Marko Rauhamaa wrote:
  Chris Angelico ros...@gmail.com:
  
   Yes, but if it's official, the standard library (large parts of it, at
   least) will use it, which will make it a lot more useful than it
   currently is.
  
  I doubt it. Python should decide if it wants to stay Python or become
  another Java. I don't really believe in this be everything for
  everybody thing. You'll only become nothing for anybody.
  
  
  Marko
 
 1) Java is not optionally typed.
 2) Having optional types is not being everything for everybody, it's just 
 being smart.

...where smart is referred to IDEs, etc...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optional types

2014-10-29 Thread Mark Lawrence

On 29/10/2014 19:03, Kiuhnm wrote:

On Wednesday, October 29, 2014 7:19:11 PM UTC+1, Marko Rauhamaa wrote:

Chris Angelico ros...@gmail.com:


Yes, but if it's official, the standard library (large parts of it, at
least) will use it, which will make it a lot more useful than it
currently is.


I doubt it. Python should decide if it wants to stay Python or become
another Java. I don't really believe in this be everything for
everybody thing. You'll only become nothing for anybody.


Marko


1) Java is not optionally typed.
2) Having optional types is not being everything for everybody, it's just 
being smart.



Regarding 2) Python has somehow managed without optional types for over 
20 years so it's my belief that they're not the panacea that so many 
people think they are.  Sure if they get implemented and if they improve 
Python then I'm all for them, but I'm not holding my breath.


--
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: Python Style Question

2014-10-29 Thread Anton
On Wednesday, October 29, 2014 4:59:25 AM UTC-7, Rafael Romero Carmona wrote:
 2014-10-29 12:25 GMT+01:00 Martin Kemp mar...@ingg.com:
 Actually it doesn't work because there is no add function and it
 doesn't catch the TypeError function to ignore other exceptions than
 ValueError. Doesn't it? I tested in Python 2.7.6 and 3.4.
Originally I was using set instead of list. So it should have been either 
values = set() or values.append(), but it is not relevant to the question.
Regarding TypeError, I don't catch it on purpose, because I want this type of 
Exception to bubble up and surface as an error and be logged, because this 
should never be the case. I expect an element to be either something coercible 
to int or a string. If for some reason it is an object, then there is something 
wrong one layer up, so I want it to fail explicitly. 


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


Re: (-1)**1000

2014-10-29 Thread Stefan Behnel
Ned Batchelder schrieb am 26.10.2014 um 21:45:
 On 10/26/14 4:07 PM, Tony the Tiger wrote:
 On Wed, 22 Oct 2014 10:27:34 +0200, ast wrote:

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

 Even vs. odd. It ought to know. I would assume from a set of defined
 rules how math works.
 
 There is such a thing as an optimization that isn't worthwhile to perform,
 simply because it's expected to provide so little benefit.  The language
 implementors have to trade off the cost of adding the optimization to the
 implementation, against the possible benefit people would get from it.
 
 Benefit in this case would have to include a guess as to how often real
 programs would hit the optimization case.

... and also compare it to the number of cases where the optimisation
(which may, for example, need to check for an optimisable value or set of
values) slows down the generic (unoptimised) code path that is actually taken.

Even if the code impact on the implementation is small enough to be
acceptable, an optimisation for unlikely cases may provide a net-loss for
the normal code. So there are several reasons why an obvious
optimisation may be a bad idea.

Stefan


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


Re: optional types

2014-10-29 Thread Marko Rauhamaa
Mark Lawrence breamore...@yahoo.co.uk:

 Regarding 2) Python has somehow managed without optional types for
 over 20 years so it's my belief that they're not the panacea that so
 many people think they are. Sure if they get implemented and if they
 improve Python then I'm all for them, but I'm not holding my breath.

I'm afraid of stylistic chaos and optional types turning into de-facto
mandatory types as modules interface each other.


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


Re: optional types

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 8:45:08 PM UTC+1, Marko Rauhamaa wrote:
 Mark Lawrence breamore...@yahoo.co.uk:
 
  Regarding 2) Python has somehow managed without optional types for
  over 20 years so it's my belief that they're not the panacea that so
  many people think they are. Sure if they get implemented and if they
  improve Python then I'm all for them, but I'm not holding my breath.
 
 I'm afraid of stylistic chaos and optional types turning into de-facto
 mandatory types as modules interface each other.

The only problem I see is that Python's type system might become too complex 
(Scala anyone???)
If you start adding covariance, contravariance, F-bounded types, etc..., the 
type system becomes more of a hindrance, IMHO.
But if you keep it simple (like Dart) it shouldn't get in your way.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optional types

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 8:23:30 PM UTC+1, Mark Lawrence wrote:
 On 29/10/2014 19:03, Kiuhnm wrote:
  On Wednesday, October 29, 2014 7:19:11 PM UTC+1, Marko Rauhamaa wrote:
  Chris Angelico ros...@gmail.com:
 
  Yes, but if it's official, the standard library (large parts of it, at
  least) will use it, which will make it a lot more useful than it
  currently is.
 
  I doubt it. Python should decide if it wants to stay Python or become
  another Java. I don't really believe in this be everything for
  everybody thing. You'll only become nothing for anybody.
 
 
  Marko
 
  1) Java is not optionally typed.
  2) Having optional types is not being everything for everybody, it's just 
  being smart.
 
 
 Regarding 2) Python has somehow managed without optional types for over 
 20 years so it's my belief that they're not the panacea that so many 
 people think they are.  Sure if they get implemented and if they improve 
 Python then I'm all for them, but I'm not holding my breath.

The only thing I know is that I programmed in ASM and C++ for many years and I 
liked it. Then I moved to C#, Haskell, Scala, and many other languages. Then I 
learned Python and I liked it. Then I tried Dart (with optional static typing) 
and liked it very much. Finally, I've come back to Python and I don't like it 
anymore like I used to. Dart's syntax is not on par with Python's but its type 
system is so lightweight and non intrusive that it's a joy to work with it and 
I miss it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.4.2 + PyQt4 + PyCharm 3.4.1

2014-10-29 Thread Juan Christian
It only occurs whule using PyCharm I tried it via pure terminal and
everything works... =/

On Tue, Oct 28, 2014 at 7:45 PM, Juan Christian juan0christ...@gmail.com
wrote:

 Python 3.4.2 Windows x64
 PyQt4 4.11.2 Py3.4 Qt4.8.6 (x64)
 PyCharm 3.4.1 Pro Edition


 So, PyCharm works 100% with everything here but PyQt.

 I have this folder structure:

 Disk C:
  PyQt4
  Lib/site-packages/PyQt4/(tons of files here)

  Python34 (normal/default installation)

 ---

 I tried copying the 'PyQt4' folder to my 'Python34/Lib/site-packages'
 folder but when I try to code something Qt related on PyCharm I get this
 issue:

 Some skeletons failed to generate: 19 modules failed in 1 interpreter.
 Details...

 Failed modules

 Python 3.4.2
 PyQt4.QAxContainer
 PyQt4.Qsci
 PyQt4.QtCore
 PyQt4.QtDeclarative
 PyQt4.QtDesigner
 PyQt4.QtGui
 PyQt4.QtHelp
 PyQt4.QtMultimedia
 PyQt4.QtNetwork
 PyQt4.QtOpenGL
 PyQt4.QtScript
 PyQt4.QtScriptTools
 PyQt4.QtSql
 PyQt4.QtSvg
 PyQt4.QtTest
 PyQt4.QtWebKit
 PyQt4.QtXml
 PyQt4.QtXmlPatterns
 PyQt4.phonon

 Generation of skeletons for the modules above will be tried again when the
 modules are updated or a new version of generator is available.

 And PyCharm tells me that my 'import PyQt4.ANYTHING_HERE import *' has
 'Unresolved references'.

 ---

 When I try to install the PyQt4 via the installer, in the default location
 (C:/Python34) I get an even 'worse' error, whenever PyCharm try to update
 the skeletons or something like that (that is, whenever I open a file
 there...), I get tons and tons of the same error, 'Error while accessing
 memory at address ', and 'python.exe' stops working.


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


Re: Anyone know the solution

2014-10-29 Thread Anton
On Tuesday, October 28, 2014 10:13:14 PM UTC-7, Gregory Ewing wrote:
 No, that's not the correct answer. Being NP-complete doesn't
 mean something is impossible, or even hard to do. All it
 means is that nobody knows of a cleverer solution than
 just trying all possibilities. That's only a difficulty if
 the problem is large enough; often it won't be.

Why do you need to iterate over all possibilities solving this problem anyway?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What for -- for? (was A bug?)

2014-10-29 Thread Terry Reedy

On 10/29/2014 1:42 AM, Zachary Ware wrote:

to avoid inconvenient line-wrapping (that I can avoid just by
sticking to 80 column lines in the first place:).


Try perhaps 65 for email.

def get_abc_map(cls):
return {n: issubclass(cls, getattr(abc, n))
for n in dir(abc) if n[0].isupper()}

is less than 55 and should not get linewrapped on any sensible sender or 
reader.


--
Terry Jan Reedy

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


Re: Meaning of * in the function arguments list

2014-10-29 Thread Terry Reedy

On 10/29/2014 4:56 AM, ast wrote:


Consider the following to_bytes method from integer class:
int.to_bytes(length, byteorder, *, signed=False)
What doest the '*' in the arguments list means ?


If you go to the online doc index page for Symbols,
https://docs.python.org/3/genindex-Symbols.html
there a 3 entries for the use of * as an operator, in statements (in 
particular, def for functions), and in function calls.


--
Terry Jan Reedy

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


Re: optional types

2014-10-29 Thread Terry Reedy

On 10/29/2014 4:40 PM, Kiuhnm wrote:


The only thing I know is that I programmed in ASM and C++ for many
years and I liked it. Then I moved to C#, Haskell, Scala, and many
other languages. Then I learned Python and I liked it. Then I tried
Dart (with optional static typing) and liked it very much. Finally,
I've come back to Python and I don't like it anymore like I used to.
Dart's syntax is not on par with Python's but its type system is so
lightweight and non intrusive that it's a joy to work with it and I
miss it.


Then propose on python-ideas, probably best after posting more here, 
that Dart be used as a model for Python.  But include a summary or 
example of what it is and why you like it and how you think its system 
might be adapted to Python.  Would it be based on the current 
annotations, for instance?


--
Terry Jan Reedy

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


[issue17896] Move Windows external libs from src\..\ to src\externals

2014-10-29 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Added file: http://bugs.python.org/file37060/issue17896-2.7.diff

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



[issue17896] Move Windows external libs from src\..\ to src\externals

2014-10-29 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file30113/move_externals.diff

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



[issue17896] Move Windows external libs from src\..\ to src\externals

2014-10-29 Thread Zachary Ware

Zachary Ware added the comment:

I don't think we're on the same page here, Terry, so here's some patches and a 
wall of text to hopefully make me clearer.

In particular, I don't understand what you mean by merge multiple tcltk 
directories in isolated build directories, as the merge and isolated seem 
mutually exclusive to me.

The layout I diagrammed in that message is basically what I use currently.  
These patches would allow me to go from this:


root
  |_ default
  |   |_ cpython (clone of https://hg.python.org/cpython)
  |   |   |_ Doc
  |   |   |_ Lib
  |   |   |_ PCbuild
  |   |   |_ ...
  |   |_ tcl-8.6.1.0
  |   |_ tk-8.6.1.0
  |   |_ tcltk
  |   |_ ...
  |
  |_ 2.7
  |_ cpython (clone of https://hg.python.org/cpython#2.7)
  |   |_ Doc
  |   |_ Lib
  |   |_ PCbuild
  |   |_ ...
  |_ tcl-8.5.15.0
  |_ tk-8.5.15.0
  |_ tcltk
  |_ ...


To this:

root
  |_ default (clone of https://hg.python.org/cpython)
  |   |_ Doc
  |   |_ externals
  |   |   |_ tcl-8.6.1.0
  |   |   |_ tk-8.6.1.0
  |   |   |_ tcltk
  |   |   |_ ...
  |   |_ Lib
  |   |_ PCbuild
  |   |_ ...
  |
  |_ 2.7 (clone of https://hg.python.org/cpython#2.7)
  |_ Doc
  |_ externals
  |   |_ tcl-8.5.15.0
  |   |_ tk-8.5.15.0
  |   |_ tcltk
  |   |_ ...
  |_ Lib
  |_ PCbuild
  |_ ...


I don't think it's wise to try to use the same directory for builds of multiple 
Python versions without rebuilding all externals anyway.  The reason you can't 
use the same tcltk install between 2.7 and 3.4/default is because of the 
different compiler used for each branch.  These days, you'll run into the same 
issue with OpenSSL, since we now use the same version of it on all branches.  I 
suppose we could try to make the OpenSSL build put the compiler version in the 
output directory name and similarly version the tcltk install dirs, but I think 
that's a lot more effort than it's worth especially considering the other 
benefits of using separate checkouts for each branch (like being able to test 
more than one interpreter simultaneously).

These patches do make it significantly easier to switch between versions in the 
same checkout properly, though; an 'hg purge --all' after update will clear out 
all the externals as well as all build artifacts (though that would require 
re-downloading the externals).

--
stage: needs patch - patch review
Added file: http://bugs.python.org/file37058/issue17896-default.diff

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



[issue17896] Move Windows external libs from src\..\ to src\externals

2014-10-29 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Added file: http://bugs.python.org/file37059/issue17896-3.4.diff

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



[issue22756] testAssertEqualSingleLine gives poor errors

2014-10-29 Thread Berker Peksag

Changes by Berker Peksag berker.pek...@gmail.com:


--
nosy: +ezio.melotti, michael.foord

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



[issue22757] TclStackFree: incorrect freePtr. Call out of sequence?

2014-10-29 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
stage:  - test needed

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



[issue3453] PyType_Ready doesn't ensure that all bases are ready

2014-10-29 Thread Antoine Pitrou

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


--
versions: +Python 3.5 -Python 3.2

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



[issue22758] Regression in Python 3.2 cookie parsing

2014-10-29 Thread Tim Graham

New submission from Tim Graham:

I noticed some failing Django tests on Python 3.2.6 the other day. The 
regression is caused by this change: 
https://github.com/python/cpython/commit/572d9c59a1441c6f8ffb9308824c804856020e31

Behavior before that commit (and on other version of Python even after that 
commit):

 from http.cookies import SimpleCookie
 SimpleCookie(Set-Cookie: foo=bar; Path=/)
SimpleCookie: foo='bar'

New broken behavior on Python 3.2.6:

 from http.cookies import SimpleCookie
 SimpleCookie(Set-Cookie: foo=bar; Path=/)
SimpleCookie: 

Python 3.2.6 no longer accepts the Set-Cookie:  prefix to BaseCookie.load:

 SimpleCookie(Set-Cookie: foo=bar; Path=/)
SimpleCookie: 
 SimpleCookie(foo=bar; Path=/)
SimpleCookie: foo='bar'

This issue doesn't affect 2.7, 3.3, or 3.4 because of 
https://github.com/python/cpython/commit/b92e104dc57c37ddf22ada1c6e5380e09268ee93
 (this commit wasn't backported to 3.2 because that branch is in 
security-fix-only mode).

I asked Berker about this and he suggested to create this issue and said, If 
Georg is OK to backout the commit I can write a patch with additional test 
cases and commit it.

He also confirmed the regression as follows:

I've tested your example on Python 2.7.8, 3.2.6, 3.3.6, 3.4.2, 3.5.0 (all 
unreleased development versions - they will be X.Y.Z+1) and looks like it's a 
regression.

My test script is:

try:
from http.cookies import SimpleCookie
except ImportError:
from Cookie import SimpleCookie

c = SimpleCookie(Set-Cookie: foo=bar; Path=/)
print(c)

Here are the results:

Python 2.7.8:
Set-Cookie: foo=bar; Path=/

Python 3.5.0:
Set-Cookie: foo=bar; Path=/

Python 3.4.2:
Set-Cookie: foo=bar; Path=/

Python 3.3.6:
Set-Cookie: foo=bar; Path=/
[45602 refs]

Python 3.2.6:

[38937 refs]

--
components: Library (Lib)
messages: 230200
nosy: Tim.Graham, berker.peksag, georg.brandl, pitrou, r.david.murray
priority: normal
severity: normal
status: open
title: Regression in Python 3.2 cookie parsing
type: behavior
versions: Python 3.2

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



[issue22758] Regression in Python 3.2 cookie parsing

2014-10-29 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Is it a normal use of SimpleCookie? The docs don't seem to imply it:


 C = cookies.SimpleCookie()
 C.load(chips=ahoy; vienna=finger) # load from a string (HTTP header)


In any case, it's up to Georg to decide. But changeset 
572d9c59a1441c6f8ffb9308824c804856020e31 fixes a security issue reported to 
secur...@python.org (the report included a concrete example of how to exploit 
it under certain conditions).

--

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



[issue22758] Regression in Python 3.2 cookie parsing

2014-10-29 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Can you give a pointer to the failing Django test, by the way?

--

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



[issue22758] Regression in Python 3.2 cookie parsing

2014-10-29 Thread Tim Graham

Tim Graham added the comment:

I wasn't sure if it was expected behavior or not. I'm attaching a file with the 
list of failing tests on Django's master.

Perhaps more useful is a reference to the problematic usage in Django:

https://github.com/django/django/blob/349471eeb9a4db2f5d8e95cb6555e7b3f2c94e3f/django/http/response.py#L208-L217

That logic was added to fix https://code.djangoproject.com/ticket/15863.

--
Added file: http://bugs.python.org/file37061/failing-django-tests-22758.txt

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



[issue22758] Regression in Python 3.2 cookie parsing

2014-10-29 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Ah, so it's about round-tripping between SimpleCookie.__str__() and 
SimpleCookie.__init__(). That sounds like a reasonable behaviour to preserve 
(and easier than parsing arbitrary Set-Cookie headers). IMO we should also add 
for tests for it in other versions.

--

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



[issue22758] Regression in Python 3.2 cookie parsing

2014-10-29 Thread Georg Brandl

Georg Brandl added the comment:

OK, so there are two root issues here:

* Django uses __init__(str()) roundtripping, which is not explicitly supported 
by the library, and worked by accident with previous versions.  That it works 
again with 3.3+ is another accident, and a bug.

(The change for #16611 reintroduces lax parsing behavior that the security 
fix was supposed to prevent.)

* BaseCookie doesn't roundtrip correctly when pickled with protocol = 2.  This 
should be fixed in upcoming bugfix releases.

I would advise Django to subclass SimpleCookie and fix the pickling issue, 
which is not hard (see attached diff).

--
keywords: +patch
Added file: http://bugs.python.org/file37062/cookie-pickling-fix.diff

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



[issue22731] test_capi test fails because of mismatched newlines

2014-10-29 Thread Nick Coghlan

Nick Coghlan added the comment:

Yes, switching the subprocess invocation in test_capi.py to universal newlines 
mode and joining the expected output with '\n' sounds like the right test case 
fix to me.

As far as the printf() change goes, I'm not really the right person to ask - 
all my Windows dev experience is with Python and C++, while my C dev experience 
has been primarily on TI DSP's and Linux.

If I had to guess, the behavioural change is likely a result of the C99 
enhancements and standards conformance improvements described in 
http://blogs.msdn.com/b/vcblog/archive/2014/06/03/visual-studio-14-ctp.aspx

--

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



[issue22731] test_capi test fails because of mismatched newlines

2014-10-29 Thread Nick Coghlan

Nick Coghlan added the comment:

One last thing: we may also want to update the C API docs to explicitly point 
out the discrepancy in handling of '\n' on Windows between printf() in VC14+ 
(which no longer does the '\r\n' substitution) and the print functions in the 
Python C API (which will keep the transformation).

This is a weird enough quirk that I feel like we should explicitly point it out 
*somewhere*, but also obscure enough that I don't want to bother people with it 
unnecessarily.

--

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



[issue22141] rlcompleter.Completer matches too much

2014-10-29 Thread Lorenz Quack

Lorenz Quack added the comment:

sorry for the delay but here is a new patch with a test.

I changed the strategy for fixing the bug because the dealing with the opening 
parenthesis became to complicated.

So, now I simply check whether the match actually startswith the search phrase 
before adding the match to the results. This is like a sanity check which fixes 
this bug.

--
Added file: http://bugs.python.org/file37063/rlcompleter_22141.patch

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



[issue22141] rlcompleter.Completer matches too much

2014-10-29 Thread Lorenz Quack

Changes by Lorenz Quack d...@amberfisharts.com:


Removed file: http://bugs.python.org/file37063/rlcompleter_22141.patch

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



[issue22141] rlcompleter.Completer matches too much

2014-10-29 Thread Lorenz Quack

Changes by Lorenz Quack d...@amberfisharts.com:


Added file: http://bugs.python.org/file37064/rlcompleter_22141.patch

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



[issue22143] rlcompleter.Completer has duplicate matches

2014-10-29 Thread Lorenz Quack

Lorenz Quack added the comment:

Hi,

here finally the updated patch with test case.
It depends on and should be applied after the patch included in issue22141.

This patch does changes two things:
1) completions are now unique
2) completions are now in no specific order

I had to touch some other rlcompleter tests because they assumed a certain 
order of the returned matches.

Thanks for reviewing!

--
Added file: http://bugs.python.org/file37065/rlcompleter_22143.patch

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



[issue22731] test_capi test fails because of mismatched newlines

2014-10-29 Thread R. David Murray

R. David Murray added the comment:

That information should also go in the porting notes section of the 3.5 What's 
New, but clearly labeled (if I understand correctly) as applying only to 
applications that embed python on Windows.

--

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



[issue8876] distutils should not assume that hardlinks will work

2014-10-29 Thread Daniel Farrell

Daniel Farrell added the comment:

 An emerging workflow is using Docker for a Python environment.

This applies to Vagrant environments as well (VirtualBox shared folders, tests 
fail).

--
nosy: +dfarrell07

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



[issue22731] test_capi test fails because of mismatched newlines

2014-10-29 Thread Steve Dower

Steve Dower added the comment:

I think it's also in any extension that prints directly to the console without 
going through the Python IO machinery.

I'll make the test change in default, since that's what the os.linesep is 
trying to achieve anyway, and modify the porting notes in my branch, since it 
won't apply until the build changes are merged in.

Thanks all.

--

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



[issue8876] distutils should not assume that hardlinks will work

2014-10-29 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I agree this deserves fixing, and the patch looks basically ok. It would be 
nice to add a test, though (by mocking os.link()).

Éric, are you still here, or should someone else take over?

--

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



[issue22759] pathlib: Path.exists broken

2014-10-29 Thread Hristo Venev

New submission from Hristo Venev:

$ touch a
c: stat(a/x, ...) - errno=ENOTDIR
$ python
 pathlib.Path('a/x').exists()

This should return False and not throw an exception.

Patch not tested.

--
files: py.patch
keywords: patch
messages: 230214
nosy: h.venev
priority: normal
severity: normal
status: open
title: pathlib: Path.exists broken
Added file: http://bugs.python.org/file37066/py.patch

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



[issue8876] distutils should not assume that hardlinks will work

2014-10-29 Thread Éric Araujo

Éric Araujo added the comment:

I can’t make any commitment to core Python at this time.  I still read all 
email and can be available for guidance or questions about obscure parts of 
distutils.

(Ideally I would find someone willing to be mentored to take over maintenance.)

--

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



[issue22760] re.sub does only first 16 replacements if re.S is used

2014-10-29 Thread Michael Del Monte

New submission from Michael Del Monte:

Easily reproduced:

re.sub('x', 'a', x*20, re.S)

returns ''

--
components: Regular Expressions
messages: 230216
nosy: ezio.melotti, mgdelmonte, mrabarnett
priority: normal
severity: normal
status: open
title: re.sub does only first 16 replacements if re.S is used
type: behavior
versions: Python 2.7

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



[issue22760] re.sub does only first 16 replacements if re.S is used

2014-10-29 Thread Antoine Pitrou

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


--
nosy: +serhiy.storchaka

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



[issue22570] Better stdlib support for Path objects

2014-10-29 Thread Ugra Dániel

Changes by Ugra Dániel daniel.u...@gmail.com:


--
nosy: +daniel.ugra

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



[issue22760] re.sub does only first 16 replacements if re.S is used

2014-10-29 Thread Peter Otten

Peter Otten added the comment:

This is not a bug; the signature of re.sub() is

sub(pattern, repl, string, count=0, flags=0)

and the fourth argument thus the 'count' delimiting the number of substitutions 
that you accidentally specify as

 import re
 re.S
16

I recommend that you use a keyword arg to fix your code:

 re.sub('x', 'a', x*20, flags=re.S)
''

--
nosy: +peter.otten

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



[issue22760] re.sub does only first 16 replacements if re.S is used

2014-10-29 Thread Georg Brandl

Georg Brandl added the comment:

The fourth parameter is not flags, but count, the max. number of 
substitutions.  flags is the fifth parameter, or give it as a keyword 
argument.

--
nosy: +georg.brandl
resolution:  - not a bug
status: open - closed

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



[issue22760] re.sub does only first 16 replacements if re.S is used

2014-10-29 Thread STINNER Victor

STINNER Victor added the comment:

This bug report is common. An enhancement would be to make the count parameter 
a keyword only parameter. Would it break a lot of code?

--
nosy: +haypo

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



[issue22760] re.sub does only first 16 replacements if re.S is used

2014-10-29 Thread Ezio Melotti

Ezio Melotti added the comment:

See #11957.

--

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



[issue22759] pathlib: Path.exists broken

2014-10-29 Thread Hristo Venev

Hristo Venev added the comment:

Tested and works.

--

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



[issue22759] pathlib: Path.exists broken

2014-10-29 Thread Antoine Pitrou

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


--
nosy: +pitrou
stage:  - test needed
type:  - behavior
versions: +Python 3.4, Python 3.5

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



[issue11957] re.sub confusion between count and flags args

2014-10-29 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 767fd62b59a9 by Victor Stinner in branch 'default':
Issue #11957: Explicit parameter name when calling re.split() and re.sub()
https://hg.python.org/cpython/rev/767fd62b59a9

--
nosy: +python-dev

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



[issue22759] pathlib: Path.exists broken

2014-10-29 Thread Georg Brandl

Georg Brandl added the comment:

os.path.exists() ignores *all* OSErrors from stat.  This is probably too broad, 
but only ignoring ENOENT is probably too narrow.

--
nosy: +georg.brandl

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



[issue11957] re.sub confusion between count and flags args

2014-10-29 Thread STINNER Victor

STINNER Victor added the comment:

I suggest to make the 2 last parameters of re.sub(), re.subn() and re.split() 
parameters as keyword-only. It will break applications using count and maxsplit 
parameters as index parameters, but it's easy to fix these applications if they 
want to support also Python 3.5.

I checked Python 2.6: the name of the maxsplit and count parameters didn't 
change. So it's possible to write code working on Python 2.6-3.5 if the 
parameter name is explicitly used:

* re.sub(a, a, a, count=1)
* re.subn(a, a, a, count=1)
* re.split(a, a, maxsplit=1)

The flags parameter was added to re.sub(), re.subn() and re.split() functions 
in Python 2.7:

* https://docs.python.org/2.7/library/re.html#re.sub
* https://docs.python.org/2.7/library/re.html#re.subn
* https://docs.python.org/2.7/library/re.html#re.split

See my attached re_keyword_only.patch:

* sub(), subn(): count and flags become keyword-only parameters
* split(): maxsplit and flags become keyword-only parameters

--
keywords: +patch
nosy: +haypo
Added file: http://bugs.python.org/file37067/re_keyword_only.patch

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



[issue22760] re.sub does only first 16 replacements if re.S is used

2014-10-29 Thread STINNER Victor

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


--
resolution: not a bug - duplicate
superseder:  - re.sub confusion between count and flags args

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



[issue17663] re.sub not replacing all

2014-10-29 Thread STINNER Victor

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


--
resolution: not a bug - duplicate
superseder:  - re.sub confusion between count and flags args

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



[issue15537] MULTILINE confuses re.split

2014-10-29 Thread STINNER Victor

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


--
resolution: not a bug - duplicate
superseder:  - re.sub confusion between count and flags args

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



[issue22759] pathlib: Path.exists broken

2014-10-29 Thread Hristo Venev

Hristo Venev added the comment:

ENAMETOOLONG and possibly ELOOP should also return False.
EACCES, EOVERFLOW and ENOMEM should probably be forwarded.
EFAULT should not happen.

--

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



[issue11947] re.IGNORECASE does not match literal _ (underscore)

2014-10-29 Thread STINNER Victor

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


--
resolution: not a bug - duplicate
superseder:  - re.sub confusion between count and flags args

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



  1   2   >