Re: Pythonic way to iterate through multidimensional space?

2014-10-07 Thread Gelonida N

On 8/6/2014 1:39 PM, Tim Chase wrote:

On 2014-08-06 11:04, Gayathri J wrote:

Below is the code I tried to check if itertools.product() was
faster than normal nested loops...

they arent! arent they supposed to be...or am i making a mistake?


I believe something like this was discussed a while ago and there was
a faster-but-uglier solution so you might want to consult this thread:

https://mail.python.org/pipermail/python-list/2008-January/516109.html

I believe this may have taken place before itertools.product() came
into existence.



Disadvantage of itertools.product() is, that it makes a copy in memory.
Reason ist, that itertools also makes products of generators (meaning of 
objects, that one can't iterate several times through)



There are two use cases, that I occasionaly stumble over:

One is making the product over lists(),
product( list_of_lists )

ex:

product( [ [1,2,3], ['A','B'], ['a', 'b', 'c'] ] )

the other one making a product over a list of functions, which will 
create generators


ex:
product( [ lambda: [ 'A', 'B' ], lambda: xrange(3) ] )


I personally would also be interested in a fast generic solution that 
can iterate through an N-dimensional array and which does not duplicate 
the memory or iterate through a list of generator-factories or however 
this would be called.





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


Interesting socket behavior

2014-10-07 Thread Christian Calderon
I noticed that if I make a listening socket using SOCK_STREAM |
SOCK_NONBLOCK, that the sockets I get after calling listener.accept() don't
have the O_NONBLOCK flag set, but checking the result of gettimeout() on
the same sockets gives me 0.0, which means they are non blocking. Why is
this the case?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Syntax Highlighting in a tkinter Text widget

2014-10-07 Thread Nicholas Cannon
Sweet thanks for the help many I am defiantly going to use these. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-07 Thread Steven D'Aprano
On Sun, 05 Oct 2014 20:07:50 -0400, Seymore4Head wrote:

 Here is the exact question, I was trying to post something similar.  I
 failed.
 
 http://i.imgur.com/iUGh4xf.jpg

Please don't post screen shots if you can avoid it. You almost certainly 
can copy and paste the text from the web page. And if you can't, you can 
usually re-type the question. It's good practice to strength your typing 
skills.

Screen shots cannot be read by people using a screen reader, or who don't 
have access to the web (but are reading their mail), or if the host site 
(in this case, imgur) is down or blocked.



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


Re: Practice question

2014-10-07 Thread Steven D'Aprano
On Sun, 05 Oct 2014 20:18:13 -0400, Seymore4Head wrote:

 I think I get it now.  You are using a sample of answers.  So you could
 actually just run through them all.  (I haven't tried this yet)
 
 for x in range(lo,hi)
  print((15 = x  30) == (15= x and x 30))

Yes, except using print is probably not the best idea, since you might 
have dozens of True True True True ... printed, one per line, and if you 
blink the odd False might have scrolled off screen before you notice.

With two numbers, 15 and 30, all you really need is five test cases:

- a number lower than the smaller of the two numbers (say, 7);
- a number equal to the smaller of the two numbers (that is, 15);
- a number between the two numbers (say, 21);
- a number equal to the larger of the two numbers (that is, 30);
- a number higher than the larger of the two numbers (say, 999);


The exact numbers don't matter, so long as you test all five cases. And 
rather than printing True True True... let's use assert instead:


for x in (7, 15, 21, 30, 999):
assert (15 = x  30) == (15= x and x 30)


If the two cases are equal, assert will do nothing. But if they are 
unequal, assert will raise an exception and stop, and you know that the 
two cases are not equivalent and can go on to the next possibility.


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


Re: Pythonic way to iterate through multidimensional space?

2014-10-07 Thread Ned Batchelder

On 10/7/14 2:10 AM, Gelonida N wrote:


Disadvantage of itertools.product() is, that it makes a copy in memory.
Reason ist, that itertools also makes products of generators (meaning of
objects, that one can't iterate several times through)


There are two use cases, that I occasionaly stumble over:

One is making the product over lists(),
product( list_of_lists )

ex:

product( [ [1,2,3], ['A','B'], ['a', 'b', 'c'] ] )

the other one making a product over a list of functions, which will
create generators

ex:
product( [ lambda: [ 'A', 'B' ], lambda: xrange(3) ] )


I personally would also be interested in a fast generic solution that
can iterate through an N-dimensional array and which does not duplicate
the memory or iterate through a list of generator-factories or however
this would be called.


itertools.product makes a copy of the sequences passed in, but it is a 
shallow copy. It doesn't copy the objects in the sequences.  It also 
doesn't store the entire product.


If you are calling product(j, k, l, m, n), where len(j)==J, the extra 
memory is J+K+L+M+N, which is much smaller than the number of iterations 
product will produce.  Are you sure that much extra memory use is a 
problem?  How large are your lists that you are product'ing together?


I don't understand your point about a list of functions that create 
generators?  What is the problem there?


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

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


Re: ruby instance variable in python

2014-10-07 Thread flebber
On Monday, 6 October 2014 21:07:24 UTC+11, roro codeath  wrote:
 in ruby:
 
 
 module M
 def ins_var
 @ins_var ||= nil
 end
 
 
 def m
 @ins_var = 'val'
 end
 
 
 def m2
 m
 ins_var # = 'val'
 end
 end
 
 
 in py:
 
 
 # m.py
 
 
 # how to def ins_var
 
 
 def m:
     # how to set ins_var
 
 
 def m2:
     m()
     # how to get ins var

I took || to be a ternary. So I assumed your code just sets ins_var to nil and 
then  is called in module m and supplied a val. Could be wrong.

if ins_var is None:
ins_var = 'val'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-07 Thread C Smith
Steven D'Aprano wrote:
With two numbers, 15 and 30, all you really need is five test cases:

My solution assumed integers also, but after I posted it, I thought:
What about floating points?

On Tue, Oct 7, 2014 at 1:48 AM, Steven D'Aprano st...@pearwood.info wrote:
 On Sun, 05 Oct 2014 20:18:13 -0400, Seymore4Head wrote:

 I think I get it now.  You are using a sample of answers.  So you could
 actually just run through them all.  (I haven't tried this yet)

 for x in range(lo,hi)
  print((15 = x  30) == (15= x and x 30))

 Yes, except using print is probably not the best idea, since you might
 have dozens of True True True True ... printed, one per line, and if you
 blink the odd False might have scrolled off screen before you notice.

 With two numbers, 15 and 30, all you really need is five test cases:

 - a number lower than the smaller of the two numbers (say, 7);
 - a number equal to the smaller of the two numbers (that is, 15);
 - a number between the two numbers (say, 21);
 - a number equal to the larger of the two numbers (that is, 30);
 - a number higher than the larger of the two numbers (say, 999);


 The exact numbers don't matter, so long as you test all five cases. And
 rather than printing True True True... let's use assert instead:


 for x in (7, 15, 21, 30, 999):
 assert (15 = x  30) == (15= x and x 30)


 If the two cases are equal, assert will do nothing. But if they are
 unequal, assert will raise an exception and stop, and you know that the
 two cases are not equivalent and can go on to the next possibility.


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


Re: ruby instance variable in python

2014-10-07 Thread Jussi Piitulainen
flebber writes:

 On Monday, 6 October 2014 21:07:24 UTC+11, roro codeath  wrote:
  in ruby:
  
  
  module M
  def ins_var
  @ins_var ||= nil
  end

...

 I took || to be a ternary. So I assumed your code just sets ins_var
 to nil and then is called in module m and supplied a val. Could be
 wrong.
 
 if ins_var is None:
 ins_var = 'val'

Just out of interest, please, do you think the word 'ternary' is more
or less synonymous with 'conditional'?

I'm not being sarcastic. This possibility just occurred to me, and the
world will begin to make more sense to me if it turns out that there
are people who simply do not think 'three' when they think 'ternary'.
-- 
https://mail.python.org/mailman/listinfo/python-list


add noise using python

2014-10-07 Thread mthaqifisa
can someone teach me how to generate noisy images by applying Gaussian random 
noise onto an image?
-- 
https://mail.python.org/mailman/listinfo/python-list


Muddleheaded use of the built-in term

2014-10-07 Thread Marco Buttu
I always thought the builtin objects were those we can get from the 
`builtins` module, that is those always available. In fact the Built-in 
Functions documentation:


https://docs.python.org/3/library/functions.html

says: The Python interpreter has a number of functions and types 
built into it that are always available. They are listed here in 
alphabetical order. The functions in the documentation list, as 
expected, are the same functions we get from the `builtins` module.


Now, is `math.sin` builtin? Of course not, because it is not an 
attribute of builtins:


 import builtins
 hasattr(builtins, 'sin')
False

and in fact it is not always available:

 sin
Traceback (most recent call last):
...
NameError: name 'sin' is not defined

But what happens if I want to check by using `inspect.isbuiltin`? The 
answer surprises me:


 import inspect
 print(inspect.isbuiltin.__doc__.split('\n')[0])
Return true if the object is a built-in function or method.
 import math
 inspect.isbuiltin(math.sin)
True

That's because the term built-in here means written in C, as 
explained here:


https://docs.python.org/3/library/types.html#types.BuiltinMethodType

So, we have built-in objects that are always available, whose names live 
in the builtin namespace, and other built-in objects that do not live in 
the builtin namespace :/ By using the same word (built-in) to indicate 
either objects written in C or objects referenced by the builtin 
namespace could be a bit muddler for everyone, beginner or not. Is it 
too late for changing the name of the `builtin` namespace in something 
like, for instance, `root` namespace, or using the name core 
(inspect.iscore(), types.CoreFunctionType, ecc.) to indicate written in C?


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


Re: add noise using python

2014-10-07 Thread Chris Angelico
On Wed, Oct 8, 2014 at 12:24 AM,  mthaqif...@gmail.com wrote:
 can someone teach me how to generate noisy images by applying Gaussian random 
 noise onto an image?

http://www.lmgtfy.com/?q=python+image+gaussian+random+noise

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


Re: Muddleheaded use of the built-in term

2014-10-07 Thread Chris Angelico
On Wed, Oct 8, 2014 at 12:24 AM, Marco Buttu marco.bu...@gmail.com wrote:
 Is it too late for changing the name of the `builtin` namespace in something
 like, for instance, `root` namespace, or using the name core
 (inspect.iscore(), types.CoreFunctionType, ecc.) to indicate written in C?

Yes, I think it's too late to change that. But it's no different from
any other word that has more than one variant of meaning; you have to
cope with the collisions. Is there any situation where it's ambiguous?
There are builtin name bindings, and there are built-in functions. The
former are provided by the language core and are thus available by
default; the latter are provided by the language core and thus do not
provide __code__. There's a connection between the meanings, but they
aren't identical.

What's a function? Obviously something created with def or lambda is.
Is a class a function? Is an object with a __call__ method a function?
Is a list comprehension a function? In different senses, all of them
are; but maybe what you want to ask is not is this a function but
is this callable (list comps aren't), or does this create a new
local scope, or does this have __code__ or something. Yet the
meanings of function are all related (mostly by external usage; list
comps by internal functionality), so it wouldn't make sense to decry
the collisions on that word.

I do see your issue, but I don't think this can be changed, nor is
worth changing.

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


Muddleheaded use of the built-in term

2014-10-07 Thread Marco Buttu
I always thought the builtin objects were those we can get from the 
`builtins` module, that is those always available. In fact the Built-in 
Functions documentation:


https://docs.python.org/3/library/functions.html

says: The Python interpreter has a number of functions and types 
built into it that are always available. They are listed here in 
alphabetical order. The functions in the documentation list, as 
expected, are the same functions we get from the `builtins` module.
Now, is `math.sin` builtin? Of course not, because it is not an 
attribute of builtins:


 import builtins
 hasattr(builtins, 'sin')
False

and in fact it is not always available:

 sin
Traceback (most recent call last):
...
NameError: name 'sin' is not defined

But what happens if I want to check by using `inspect.isbuiltin()`? The 
answer surprises me:


 import inspect
 print(inspect.isbuiltin.__doc__.split('\n')[0])
Return true if the object is a built-in function or method.
 import math
 inspect.isbuiltin(math.sin)
True

That's because the term built-in here means written in C, as 
explained in the doc:


https://docs.python.org/3/library/types.html#types.BuiltinMethodType

So, we have built-in objects that are always available, whose names live 
in the builtin namespace, and other built-in objects that do not live in 
the builtin namespace :/ By using the same word (built-in) to indicate 
either objects written in C or objects referenced by the builtin 
namespace could be a bit muddler for everyone, beginner or not. Is it 
too late for changing the name of the `builtin` namespace in something 
like, for instance, `root` namespace, or using the name core 
(inspect.iscore(), types.CoreFunctionType, ecc.) to indicate written in 
C or whatever underlying language?


--
Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbu...@oa-cagliari.inaf.it

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


How do I check if a string is a prefix of any possible other string that matches a given regex.

2014-10-07 Thread jonathan . slenders
Hi everyone,


Probably I'm turning the use of regular expressions upside down with this 
question. I don't want to write a regex that matches prefixes of other strings, 
I know how to do that. I want to generate a regex -- given another regex --, 
that matches all possible strings that are a prefix of a string that matches 
the given regex.


E.g. You have the regex  ^[a-z]*4R$  then the strings a, ab, A4 ab4 are 
prefixes of this regex (because there is a way of adding characters that causes 
the regex to match), but 4a or a44 or not.
How do I programmatically create a regex that matches a, ab, A4, etc.. 
but not 4a, a44, etc..

Logically, I'd think it should be possible by running the input string against 
the state machine that the given regex describes, and if at some point all the 
input characters are consumed, it's a match. (We don't have to run the regex 
until the end.) But I cannot find any library that does it...

Thanks a lot, if anyone knows the answer to this question!


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


Re: How do I check if a string is a prefix of any possible other string that matches a given regex.

2014-10-07 Thread Joshua Landau
On 7 October 2014 17:15,  jonathan.slend...@gmail.com wrote:
 Probably I'm turning the use of regular expressions upside down with this 
 question. I don't want to write a regex that matches prefixes of other 
 strings, I know how to do that. I want to generate a regex -- given another 
 regex --, that matches all possible strings that are a prefix of a string 
 that matches the given regex.
 [...]
 Logically, I'd think it should be possible by running the input string 
 against the state machine that the given regex describes, and if at some 
 point all the input characters are consumed, it's a match. (We don't have to 
 run the regex until the end.) But I cannot find any library that does it...

How wide a net are you counting regular expressions to be? What
grammar are you using?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.4.1 on W2K?

2014-10-07 Thread Carl Distefano
Tim G.:
 Of course, if you're happy to work with a slightly older
 version of Python, such as 3.2, then you should be fine.

Well,
 I just installed 3.2.5 in W2K and all of my stuff seems to work. I'm a
 happy camper. Many thanks for the information and link!

ChrisA:
 Wow. I wonder, since you're already poking around with
 extremely legacy stuff, would it be easier for you to use OS/2
 instead of Win2K? Paul Smedley still produces OS/2 builds of
 Python, and OS/2 itself runs happily under VirtualBox (we have
 an OS/2 VM still on our network here, and I use Python to
 manage its backups). Might not end up any better than your
 current system, but it might be!

That's
 actually an interesting idea. OS/2 was our OS of choice in the '90s. 
XyWrite ran beautifully under it, and when we needed extensions to the 
XyWrite Programming Language (XPL) we used Rexx (RexXPL). Since last 
year I've been using Python instead (XPyL). The fact is, though, most 
XyWriters are running XyWrite under Windows, except for the few running 
it under Linux. Much of our script development since then has focused on
 integrating Xy with Windows, so to revert to OS/2 would be swimming 
against the tide. But I may just try it anyway!

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


Re: How do I check if a string is a prefix of any possible other string that matches a given regex.

2014-10-07 Thread Ian Kelly
On Tue, Oct 7, 2014 at 10:15 AM,  jonathan.slend...@gmail.com wrote:
 Logically, I'd think it should be possible by running the input string 
 against the state machine that the given regex describes, and if at some 
 point all the input characters are consumed, it's a match. (We don't have to 
 run the regex until the end.) But I cannot find any library that does it...

Strictly speaking, a DFA or NFA always consumes the entire input; the
question of interest is whether it halts in an accepting state or not.

It would be easy to transform a DFA or NFA in the manner that you
want, though.  For each non-accepting state, determine whether it has
any transitions that lead in one or more steps to an accepting state.
Modify the FSM so that each such state is also an accepting state.
-- 
https://mail.python.org/mailman/listinfo/python-list


Need some direction in completing the exercise below, appreciate any input given, thanks!

2014-10-07 Thread wadson . espindola
The aim of this exercise is to combine the sample database, click tracking 
information from a test website and application, and information from user's 
social networks.

The sample database contains the following fields and is made up of 500 records.

first_name, last_name, company_name, address, city, county, 
state, zip, phone1, phone2,   email, web

Here are the instructions:

1) Download the US500 database from http://www.briandunning.com/sample-data/

2) Use the exchange portion of the telephone numbers (the middle three digits) 
as the proxy for user clicked on and expressed interest in this topic. 
Identify groups of users that share topic interests (exchange numbers match).

3) Provide an API that takes an e-mail address an input, and returns the e-mail 
addresses of other users that share that interest.

4) Extend that API to return users within a certain distance N of that 
interest. For example, if the original user has an interest in group 236, and N 
is 2, return all users with interests in 234 through 238.

5) Identify and rank the states with the largest groups, and (separately) the 
largest number of groups.

6) Provide one or more demonstrations that the API works.  These can be via a 
testing framework, and/or a quick and dirty web or command line client, or 
simply by driving it from a browser and  showing a raw result.


I was able to import the data this way, however I know there's a better method 
using the CSV module. The code below just reads lines, I'd like to be able to 
split each individual field into columns and assign primary and foreign keys in 
order to solve the challenge. What's the best method to accomplish this task?

import os, csv, json, re

class fetch500(): # class 
instantiation
def __init__(self):   # initializes 
data import object
US_500file = open('us-500.csv')
us_500list = US_500file.readlines()
for column in us_500list:
print column,   # prints 
out phone1 array

data_import = fetch500()
print fetch500()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.4.1 on W2K?

2014-10-07 Thread Michael Torrie
On 10/05/2014 06:04 PM, Pal Acreide wrote:
 BTW, the reason I run VBox is that I belong to a group of diehard
 users of the classic DOS word-processor XyWrite. I've devised a way
 to use Python as an extension of XyWrite's built-in Programming
 Language (XPL): http://users.datarealm.com/xywwweb/xypydoc.htm

That's really interesting.  I looked briefly at the page.  How does your
python extension work with xywrite?  Does it manipulate xywrite
documents or does it tie in at runtime with Xywrite somehow?  If so, how
does it do this?  Crossing the divide into a 16-bit app is pretty
impressive.

I wonder how well your system could be made to work with dosbox.  Dosbox
runs xywrite on any platform (even non x86 like a tablet).  I'm not sure
how you'd interface dosbox with python on the host though.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.4.1 on W2K?

2014-10-07 Thread random832
On Tue, Oct 7, 2014, at 16:27, Michael Torrie wrote:
 That's really interesting.  I looked briefly at the page.  How does your
 python extension work with xywrite?  Does it manipulate xywrite
 documents or does it tie in at runtime with Xywrite somehow?  If so, how
 does it do this?  Crossing the divide into a 16-bit app is pretty
 impressive.

I assume that it uses temporary files (or pipes, don't know if DOS can
do this), and that DOS programs can execute windows programs with int
21/4B.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Timezones

2014-10-07 Thread Seymore4Head
On Mon, 6 Oct 2014 13:48:58 +1100, Chris Angelico ros...@gmail.com
wrote:

On Mon, Oct 6, 2014 at 1:37 PM, Rustom Mody rustompm...@gmail.com wrote:
 My advice is to avoid time zones, they're a real pain, seriously.

 What say we send an application to the UN to declare the world flat?

Easier to simply start scheduling things in UTC. I run an
international Dungeons  Dragons campaign with sessions every Sunday
at 02:00 UTC, and nobody needs to be confused by time zones. (The
server displays UTC time, so it's easy for anyone to see; for
instance, it's now Mon 02:48:09, so session time was about this time
yesterday.) Civil time can do whatever it likes, just as long as
everyone knows that the meeting is based on UTC.

ChrisA

And I just found out there is going to be another Y2K in 2038.  I hope
I am around to see it.  I spend this Y2K in Las Vegas.

Las Vegas is one of the last few time zones so TVs everywhere were
showing the ringing in of the New Year and nothing was exploding.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I check if a string is a prefix of any possible other string that matches a given regex.

2014-10-07 Thread jonathan . slenders

  Logically, I'd think it should be possible by running the input string 
  against the state machine that the given regex describes, and if at some 
  point all the input characters are consumed, it's a match. (We don't have 
  to run the regex until the end.) But I cannot find any library that does 
  it...
 
 
 
 Strictly speaking, a DFA or NFA always consumes the entire input; the
 
 question of interest is whether it halts in an accepting state or not.
 
 
 
 It would be easy to transform a DFA or NFA in the manner that you
 
 want, though.  For each non-accepting state, determine whether it has
 
 any transitions that lead in one or more steps to an accepting state.
 
 Modify the FSM so that each such state is also an accepting state.


Thanks, I'll make every state of the FSM an accepting state.

My use case is to implement autocompletion for a regular language. So I think 
if the input is accepted by the FSM that I build, it's a valid prefix, and 
the autocompletion can be generated by looking at which transitions are 
possible at that point.

More pointers are welcome, but I think that I have enough to start the 
implementation.

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


Another time question

2014-10-07 Thread Seymore4Head
I never really cared enough to ask anyone, but something like my cable
bill is 98$ a month.  Do companies (in general) consider a month every
30 days or every time the 14th comes around? 

I did rent a car once during a time change and I only got to keep the
car 23 hours.

As another side note I have had drug prescripts that were 28 days was
considered a month supply.  The would be 4 weeks instead of one month.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Another time question

2014-10-07 Thread Chris Angelico
On Wed, Oct 8, 2014 at 10:12 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 I never really cared enough to ask anyone, but something like my cable
 bill is 98$ a month.  Do companies (in general) consider a month every
 30 days or every time the 14th comes around?

 I did rent a car once during a time change and I only got to keep the
 car 23 hours.

 As another side note I have had drug prescripts that were 28 days was
 considered a month supply.  The would be 4 weeks instead of one month.

I'm not sure how this connects to Python, but I'll assume for now
you're trying to do something up as a script and just haven't told us
that bit...

With periodic recurring charges, it's common for month to mean
calendar month, resetting every Nth of the month (often 1st, but any
day works). If your mobile data plan costs $35/month and allows you
7GB/month throughput, both those figures will be per calendar month.
For the rest, it depends on what the company's doing. Presumably drug
prescriptions are primarily done on a weekly basis; car rentals will
be on a daily basis. They're not going to say cars have to be
returned by 8AM, except during DST when they must be returned by 9AM,
because that's just messy; so one day a year, you get an extra hour,
and one day a year, you lose an hour.

If you tell us what the code is you're trying to work on, we might be
able to advise more usefully.

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


Re: How do I check if a string is a prefix of any possible other string that matches a given regex.

2014-10-07 Thread MRAB

On 2014-10-07 22:48, jonathan.slend...@gmail.com wrote:



Logically, I'd think it should be possible by running the input
string against the state machine that the given regex describes,
and if at some point all the input characters are consumed, it's
a match. (We don't have to run the regex until the end.) But I
cannot find any library that does it...


Strictly speaking, a DFA or NFA always consumes the entire input;
the question of interest is whether it halts in an accepting state
or not.

It would be easy to transform a DFA or NFA in the manner that you
want, though.  For each non-accepting state, determine whether it
has any transitions that lead in one or more steps to an accepting
state.

Modify the FSM so that each such state is also an accepting state.


Thanks, I'll make every state of the FSM an accepting state.

My use case is to implement autocompletion for a regular language.
So I think if the input is accepted by the FSM that I build, it's a
valid prefix, and the autocompletion can be generated by looking
at which transitions are possible at that point.

More pointers are welcome, but I think that I have enough to start
the implementation.


If you're not interested in generating an actual regex, but only in
matching the prefix, then it sounds like you want partial matching.

The regex module supports that:

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


Re: Another time question

2014-10-07 Thread Seymore4Head
On Wed, 8 Oct 2014 10:21:10 +1100, Chris Angelico ros...@gmail.com
wrote:

On Wed, Oct 8, 2014 at 10:12 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 I never really cared enough to ask anyone, but something like my cable
 bill is 98$ a month.  Do companies (in general) consider a month every
 30 days or every time the 14th comes around?

 I did rent a car once during a time change and I only got to keep the
 car 23 hours.

 As another side note I have had drug prescripts that were 28 days was
 considered a month supply.  The would be 4 weeks instead of one month.

I'm not sure how this connects to Python, but I'll assume for now
you're trying to do something up as a script and just haven't told us
that bit...

With periodic recurring charges, it's common for month to mean
calendar month, resetting every Nth of the month (often 1st, but any
day works). If your mobile data plan costs $35/month and allows you
7GB/month throughput, both those figures will be per calendar month.
For the rest, it depends on what the company's doing. Presumably drug
prescriptions are primarily done on a weekly basis; car rentals will
be on a daily basis. They're not going to say cars have to be
returned by 8AM, except during DST when they must be returned by 9AM,
because that's just messy; so one day a year, you get an extra hour,
and one day a year, you lose an hour.

If you tell us what the code is you're trying to work on, we might be
able to advise more usefully.

ChrisA

Actually, the simple python code I am working on is not required to
consider those complicated questions, but it still causes me to ponder
them.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ruby instance variable in python

2014-10-07 Thread flebber
I thought that it was a shortcut in ruby to negate the other option of 
providing another default .

I don't greatly know ruby but took a guess after reading examples here 
https://blog.neowork.com/ruby-shortcuts
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ruby instance variable in python

2014-10-07 Thread Steven D'Aprano
flebber wrote:

 I thought that it was a shortcut in ruby to negate the other option of
 providing another default .

I'm afraid I can't work out what that sentence means, to negate the other
option of providing *another* default? How many defaults are you
providing? Then you negate *the option*, does that mean that you're not
actually providing a default?

Also, since you haven't quoted the person you are responding to, there is no
context to your response. The end result of a confusing sentence with no
context is that I have no idea what you are trying to say. Could you try
explaining again please?


-- 
Steven

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


Re: Another time question

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

 I never really cared enough to ask anyone, but something like my cable
 bill is 98$ a month.  Do companies (in general) consider a month every
 30 days or every time the 14th comes around?

What does this have to do with Python?

Companies do whatever they want. Some of them consider a month to start from
the 1st and end at the end of the month, some of them take 30 days from the
date you started, some of them 31 days from when you start, or 28 days
(four weeks). Some of them have a fixed starting date. Some of them don't.
Some bill you fortnightly, or weekly, or yearly.

 I did rent a car once during a time change and I only got to keep the
 car 23 hours.

I'm not sure how that is relevant to either Python or what companies
consider a month, but okay.

 As another side note I have had drug prescripts that were 28 days was
 considered a month supply.  The would be 4 weeks instead of one month.

Okay.



-- 
Steven

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


operator module functions

2014-10-07 Thread Steven D'Aprano
Every Python operator has a function version in the operator module:

operator + has function operator.add;
operator - has function operator.sub;
operator * has function operator.mul;

and so forth. Only, that's not quite right... according to the
documentation, the official functions are actually:

operator.__add__;
operator.__sub__;
operator.__mul__;

etc., with the underscore-less versions being provided as a convenience.

Was anyone aware of this? It came as a surprise to me.

Is there anyone who uses or prefers the dunder versions?


-- 
Steven

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


Re: Perl Template Toolkit: Now in spicy new Python flavor

2014-10-07 Thread joshua . higgins . pcv
Sorry, is anyone else having trouble opening the README.txt?

On Monday, January 14, 2008 6:00:52 PM UTC-5, eef...@gmail.com wrote:
 I'd like to inform the Python community that the powerful and popular
 Template Toolkit system, previously available only in its original
 Perl implementation, is now also available in a beta Python
 implementation:
 
 http://tt2.org/python/index.html
 
 I created this port both as a fun programming project, and for use in
 environments where  Perl is not available, for reasons technical,
 cultural, or otherwise.  The extensive Perl test suites have also been
 ported, and most templates require no or very little modification.
 
 Discussion of the Python implementation should be conducted on the
 main Template Toolkit developer mailing list; see the site above for
 details.

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


Re: Perl Template Toolkit: Now in spicy new Python flavor

2014-10-07 Thread Chris Angelico
On Wed, Oct 8, 2014 at 12:51 PM,  joshua.higgins@gmail.com wrote:
 Sorry, is anyone else having trouble opening the README.txt?

 On Monday, January 14, 2008 6:00:52 PM UTC-5, eef...@gmail.com wrote:
 I'd like to inform the Python community that the powerful and popular
 Template Toolkit system, previously available only in its original
 Perl implementation, is now also available in a beta Python
 implementation:

 http://tt2.org/python/index.html

 I created this port both as a fun programming project, and for use in
 environments where  Perl is not available, for reasons technical,
 cultural, or otherwise.  The extensive Perl test suites have also been
 ported, and most templates require no or very little modification.

 Discussion of the Python implementation should be conducted on the
 main Template Toolkit developer mailing list; see the site above for
 details.

You're top-posting from Google Groups in response to a six-year-old
post. At least you provided us with some context. But you're looking
at something pretty ancient, so a more appropriate response would be
to first search the web to see if the URL's changed, and if you're
still having trouble, to ask (as a brand new thread) something like I
found this from six years ago, does anyone know if it's still
active?. We here on comp.lang.python / python-list don't have the
power to help you; you need the original author, whose contact details
can probably be found by poking around on the web site you quoted the
link to.

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


Re: Python 3.4.1 on W2K?

2014-10-07 Thread Michael Torrie
On 10/07/2014 02:33 PM, random...@fastmail.us wrote:
 On Tue, Oct 7, 2014, at 16:27, Michael Torrie wrote:
 That's really interesting.  I looked briefly at the page.  How does your
 python extension work with xywrite?  Does it manipulate xywrite
 documents or does it tie in at runtime with Xywrite somehow?  If so, how
 does it do this?  Crossing the divide into a 16-bit app is pretty
 impressive.
 
 I assume that it uses temporary files (or pipes, don't know if DOS can
 do this), and that DOS programs can execute windows programs with int
 21/4B.

dosemu has the ability to execute linux shell commands, I know.  Dosbox
does not, unfortunately.  It be nice to have such a facility.  Then
xywrite fans could have xywrite on any platform, not just windows.  I
suppose one could hack together a way of doing it via the dosbox IPX
networking facilities.

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


help with regex

2014-10-07 Thread James Smith
I want the last 1
I can't this to work:

 pattern=re.compile( (\d+)$ )
 match=pattern.match( LINE: 235 : Primary Shelf Number (attempt 1): 1)
 print match.group()
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue22568] Use of utime as variable name in Modules/posixmodule.c causes errors

2014-10-07 Thread Georg Brandl

Georg Brandl added the comment:

Patch LGTM.

--
nosy: +georg.brandl

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



[issue18119] urllib.FancyURLopener does not treat URL fragments correctly

2014-10-07 Thread karl

karl added the comment:

OK I fixed the code. The issue is here
https://hg.python.org/cpython/file/1e1c6e306eb4/Lib/urllib/request.py#l656

newurl = urlunparse(urlparts)

Basically it reinjects the fragment in the new url. The fix is easy.

if urlparts.fragment:
urlparts = list(urlparts)
urlparts[5] = 
newurl = urlunparse(urlparts)

I was trying to make a test for it, but failed. Could someone help me for the 
test so I can complete the patch?

Added the code patch only.

--
keywords: +patch
Added file: http://bugs.python.org/file36832/issue18119-code-only.patch

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



[issue12458] Tracebacks should contain the first line of continuation lines

2014-10-07 Thread Giampaolo Rodola'

Changes by Giampaolo Rodola' g.rod...@gmail.com:


--
stage: test needed - needs patch
versions: +Python 3.5 -Python 3.4

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



[issue22571] Remove import * recommendations and examples in doc?

2014-10-07 Thread Mark Dickinson

Mark Dickinson added the comment:

I think it's fine to recommend using (for example) ` from decimal import *` 
at the command-line prompt when experimenting with a module.  It's a quick way 
to get yourself into a state where you can easily experiment with that module 
and its features.

That's not the same as recommending that scripts using the decimal module start 
with from decimal import *, of course.

--
nosy: +mark.dickinson

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



[issue22294] 2to3 consuming_calls: len, min, max, zip, map, reduce, filter, dict, xrange

2014-10-07 Thread Edward O

Changes by Edward O edoubray...@gmail.com:


--
nosy: +BreamoreBoy

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



[issue22574] super() and del in the same method leads to UnboundLocalError

2014-10-07 Thread Pierre-Antoine BRAMERET

New submission from Pierre-Antoine BRAMERET:

Hi,

With the following code:

class Base(object): pass

class Foo(Base):
  def __init__(self):
super(Foo,self).__init__()
if False:
  del Foo


I expect that Foo() would give me a Foo instance. Instead, it raises the 
following exception:

Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 3, in __init__
super(Foo,self).__init__()
UnboundLocalError: local variable 'Foo' referenced before assignment



I first suspected the del Foo statement is executed before the function is 
executed (while parsing or something), because the error tells Foo does not 
exists.

Howver, the problem is deeper than that: with the following modified code:

class Foo(Base):
  def __init__(self):
assert 'Foo' in globals()
assert Foo
super(Foo,self).__init__()
if False:
  del Foo

Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 4, in __init__
super(Foo,self).__init__()
UnboundLocalError: local variable 'Foo' referenced before assignment



So: Foo IS in globals(), but cannot be accessed through Foo in the class 
because of the presence of 'del Foo' in the never reached part of the method.

--
messages: 228757
nosy: Miaou
priority: normal
severity: normal
status: open
title: super() and del in the same method leads to UnboundLocalError
versions: Python 2.7, Python 3.2, Python 3.4

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



[issue22572] NoneType object is not iterable error when asyncio Server.close() called

2014-10-07 Thread STINNER Victor

STINNER Victor added the comment:

 Using call_soon_threadsafe from an addCleanup in the _server method makes it 
 work for me. 

Maybe the documentation on thread safety should be improved? More warnings 
should be put in the documentation?

https://docs.python.org/dev/library/asyncio-dev.html#concurrency-and-multithreading

--

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



[issue22574] super() and del in the same method leads to UnboundLocalError

2014-10-07 Thread Pierre-Antoine BRAMERET

Pierre-Antoine BRAMERET added the comment:

Sorry, I miscopied the last Traceback. Please find the following:

Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 4, in __init__
assert Foo
UnboundLocalError: local variable 'Foo' referenced before assignment

--

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



[issue22572] NoneType object is not iterable error when asyncio Server.close() called

2014-10-07 Thread STINNER Victor

STINNER Victor added the comment:

Maybe we should more checks in debug mode in the Server class? For example, 
loop.call_soon() raises an AssertionError if it is called from the wrong 
thread in debug mode.

--

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



[issue18216] gettext doesn't check MO versions

2014-10-07 Thread Jakub Wilk

Jakub Wilk added the comment:

The patch hardcodes 5 as version number in the exception message.

The specifiction also says that an unexpected minor revision number means that 
the file can be read but will not reveal its full contents, when parsed by a 
program that supports only smaller minor revision numbers. So I think a 
reasonable thing to do is to accept MO files with an expected major revision 
but an unexpected minor revision.

--

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



[issue22572] NoneType object is not iterable error when asyncio Server.close() called

2014-10-07 Thread STINNER Victor

STINNER Victor added the comment:

Oh, I didn't notice that waiter_bug.py does nothing :-) I added 
unittest.main(). With PYTHONASYNCIODEBUG=1, I get *two* errors, maybe we 
don't need to add more checks in debug mode.

Again, maybe the debug mode should be better documented?
https://docs.python.org/dev/library/asyncio-dev.html#debug-mode-of-asyncio

Currently, it's at the end of the documentation.

ERROR:asyncio:CoroWrapper Server.wait_closed() running at 
/home/haypo/prog/python/default/Lib/asyncio/base_events.py:143, created at 
waiter_bug.py:32 was never yielded from
Coroutine object created at (most recent call last):
  File waiter_bug.py, line 43, in module
unittest.main()
  File /home/haypo/prog/python/default/Lib/unittest/main.py, line 93, in 
__init__
self.runTests()
  File /home/haypo/prog/python/default/Lib/unittest/main.py, line 244, in 
runTests
self.result = testRunner.run(self.test)
  File /home/haypo/prog/python/default/Lib/unittest/runner.py, line 168, in 
run
test(result)
  File /home/haypo/prog/python/default/Lib/unittest/suite.py, line 87, in 
__call__
return self.run(*args, **kwds)
  File /home/haypo/prog/python/default/Lib/unittest/suite.py, line 125, in run
test(result)
  File /home/haypo/prog/python/default/Lib/unittest/suite.py, line 87, in 
__call__
return self.run(*args, **kwds)
  File /home/haypo/prog/python/default/Lib/unittest/suite.py, line 125, in run
test(result)
  File /home/haypo/prog/python/default/Lib/unittest/case.py, line 625, in 
__call__
return self.run(*args, **kwds)
  File /home/haypo/prog/python/default/Lib/unittest/case.py, line 582, in run
self.doCleanups()
  File /home/haypo/prog/python/default/Lib/unittest/case.py, line 618, in 
doCleanups
function(*args, **kwargs)
  File waiter_bug.py, line 32, in _stop_server
self.server.wait_closed()
DEBUG:asyncio:Using selector: EpollSelector
E
==
ERROR: test_version (__main__.Test)
--
Traceback (most recent call last):
  File waiter_bug.py, line 33, in _stop_server
self.server_loop.stop()
  File /home/haypo/prog/python/default/Lib/asyncio/base_events.py, line 285, 
in stop
self.call_soon(_raise_stop_error)
  File /home/haypo/prog/python/default/Lib/asyncio/base_events.py, line 373, 
in call_soon
handle = self._call_soon(callback, args, check_loop=True)
  File /home/haypo/prog/python/default/Lib/asyncio/base_events.py, line 382, 
in _call_soon
self._assert_is_current_event_loop()
  File /home/haypo/prog/python/default/Lib/asyncio/base_events.py, line 404, 
in _assert_is_current_event_loop
Non-thread-safe operation invoked on an event loop other 
RuntimeError: Non-thread-safe operation invoked on an event loop other than the 
current one

--

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



[issue22564] ssl: post-commit review of the new memory BIO API

2014-10-07 Thread STINNER Victor

STINNER Victor added the comment:

 For total cleanness maybe the constructor should raise a TypeError if 
 server_hostname is passes as a bytes.

Oh. So there are two attributes? SSLSocket.server_hostname and
SSLSocket._sslobj.server_hostname? The constructor should make sure
that both are consistent (ex: initialize SSLSocket.server_hostname
from sslobj.server_hostname), or SSLSocket.server_hostname should be a
property reading SSLSocket._sslobj.server_hostname (or a getter/setter
if we should be able to modify it).

--

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



[issue22574] super() and del in the same method leads to UnboundLocalError

2014-10-07 Thread Mark Dickinson

Mark Dickinson added the comment:

So while the behaviour is surprising, the language is behaving as designed:  
the target of `del` is considered to be a local variable for the entire 
function definition.  (In much the same way, the targets of simple assignments 
are considered local, so if you'd assigned to Foo in the if False: block, 
you'd see the same error.)

The behaviour is documented here: 
https://docs.python.org/3.4/reference/executionmodel.html#naming-and-binding

Note particularly these bits:

If a name is bound in a block, it is a local variable of that block, [...]

A target occurring in a del statement is also considered bound for this 
purpose [...]

See also this FAQ: https://docs.python.org/3/faq/programming.html#id8

I wonder whether it's worth updating the FAQ to mention that `del` is 
considered to bind names in this way.

--
nosy: +mark.dickinson

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



[issue22568] Use of utime as variable name in Modules/posixmodule.c causes errors

2014-10-07 Thread STINNER Victor

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


--
nosy: +haypo

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



[issue7830] Flatten nested functools.partial

2014-10-07 Thread STINNER Victor

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


--
nosy: +haypo
type: enhancement - performance

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



[issue22572] NoneType object is not iterable error when asyncio Server.close() called

2014-10-07 Thread R. David Murray

R. David Murray added the comment:

Yes, documenting it at the beginning would be good.  I haven't gotten to the 
end of the docs yet, I like to experiment as I go along :)

--

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



[issue22574] super() and del in the same method leads to UnboundLocalError

2014-10-07 Thread Pierre-Antoine BRAMERET

Pierre-Antoine BRAMERET added the comment:

Hi,

Tanks for your clear answer. I find it surprising that del bounds the name 
locally, but with little more thinking, it is not...

--
resolution:  - not a bug
status: open - closed

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



[issue18161] call fchdir if subprocess.Popen(cwd=integer|fileobject)

2014-10-07 Thread STINNER Victor

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


--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18161
___
___
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-07 Thread Brett Cannon

Brett Cannon added the comment:

I think I'm missing something here because the idea of doing `path = str(path)` 
at the API boundary for an old function to support both Path and str objects 
for paths seems fairly minimal. Only when manipulating a path is wanting a Path 
object going to come up, and in that case can't you just do `path = 
pathlib.Path(path)` instead?

--
nosy: +brett.cannon

___
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



[issue22570] Better stdlib support for Path objects

2014-10-07 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +ezio.melotti
type:  - enhancement

___
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



[issue18216] gettext doesn't check MO versions

2014-10-07 Thread Aaron Hill

Aaron Hill added the comment:

That sounds good. Should a warning be thrown for an unexpected minor revision?

--

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



[issue12067] Doc: remove errors about mixed-type comparisons.

2014-10-07 Thread Andy Maier

Andy Maier added the comment:

Just wanted to say that i will continue working on this, working in the 
comments made so far...
Andy

--

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



[issue22297] 2.7 json encoding broken for enums

2014-10-07 Thread Edward O

Edward O added the comment:

The arguments for fixing:

* int subclasses overriding str is a very common usecase for enums (so much so 
that it was added to stdlib in 3.4).

* json supporting a standard type of a subsequent python version, though not 
mandatory, would be beneficial to Py2/Py3 compatibility.

* fixing this cannot break existing code

* the fix could theoretically be done to 3.0-3.3 if Ethan's argument is deemed 
important.

--
status: pending - open

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



[issue22575] bytearray documentation confuses string for unicode objects

2014-10-07 Thread Martijn Pieters

New submission from Martijn Pieters:

The Python 2 version of the bytearray() documentation appears to be copied 
directly from its Python 3 counterpart and states that when passing in a string 
an encoding is required:

* If it is a string, you must also give the encoding (and optionally, errors) 
parameters; bytearray() then converts the string to bytes using str.encode().

(from https://docs.python.org/2/library/functions.html#bytearray).

This obviously doesn't apply to Python 2 str() objects, but would only apply to 
unicode() objects.

Can this be corrected? The current wording is confusing new users (see 
http://stackoverflow.com/questions/26230745/how-to-convert-python-str-to-bytearray).

--
assignee: docs@python
components: Documentation
messages: 228771
nosy: docs@python, mjpieters
priority: normal
severity: normal
status: open
title: bytearray documentation confuses string for unicode objects
versions: Python 2.7

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



[issue22534] bsddb memory leak with MacPorts bdb 4.6

2014-10-07 Thread Jesús Cea Avión

Changes by Jesús Cea Avión j...@jcea.es:


--
nosy: +jcea

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



[issue22477] GCD in Fractions

2014-10-07 Thread Stefan Behnel

Stefan Behnel added the comment:

 it might be worth at least considering how a 'one or more parameter' gcd 
 compares on performance grounds with a two parameter one.

There shouldn't be a difference in practice. The bulk of the work is in the 
algorithm that finds the GCD of two numbers, and finding the GCD of multiple 
numbers is simply

functools.reduce(math.gcd, seq_of_numbers)

Since the most common use case is finding the GCD of two numbers, I don't see a 
reason to burden the implementation with a special case here.

--

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



[issue22576] ftplib documentation gives a wrong argument name for storbinary

2014-10-07 Thread Derek Kurth

New submission from Derek Kurth:

The Python 3 documentation for ftplib gives the storbinary method signature as:

FTP.storbinary(cmd, file, blocksize=8192, callback=None, rest=None)

However, the parameter named file is actually named fp in the code, so if 
you do something like this:

ftp.storbinary(cmd=RETR something.txt, file=f)

then you will get a TypeError: storbinary() got an unexpected keyword argument 
'file'.  

I think the documentation should be updated to call that argument fp instead 
of file.

--
assignee: docs@python
components: Documentation
messages: 228773
nosy: Derek.Kurth, docs@python
priority: normal
severity: normal
status: open
title: ftplib documentation gives a wrong argument name for storbinary
versions: Python 3.3

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



[issue22462] Modules/pyexpat.c violates PEP 384

2014-10-07 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Here is an updated patch with a test.

--
Added file: http://bugs.python.org/file36833/expat_traceback.patch

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



[issue22524] PEP 471 implementation: os.scandir() directory scanning function

2014-10-07 Thread STINNER Victor

STINNER Victor added the comment:

Hi Ben,

I started to review your patch, sorry for the delay :-( It's convinient to have 
the patch on Rietveld to comment it inline.

I didn't expect so much C code. The posixmodule.c is really huge. Well, it's 
just the longest C file of Python 3.5. Your patch adds 781 more lines to it. 
It's maybe time to split the file into smaller files.

At the same time, reading C code is boring and it's too easy to implement 
bugs. I need to be convinced that the speedup announced in the PEP requires so 
much C code. In the PEP and https://github.com/benhoyt/scandir#benchmarks it's 
not clear if the speedup comes from the C code (instead of implementing scandir 
in pure Python, for example using ctypes) or the lower number of syscalls.

To have a fair benchmark, the best would be to have a C part only implementing 
opendir/readir and FirstFindFile/FindFileXXX (I'm not sure that ctypes is as 
fast as C code written with the Python C API), and a Python part which 
implements the nice Python API.

If the speedup is 10% or lower, I would prefer to not add so much C code and 
take the compromise of a thin C wrapper and implement scandir in Python.

If we implement os.scandir() in Python, should we still try to share code with 
os.listdir()? I see that importlib uses os.listdir(), so we need a listdir() 
function implemented in C at least for importlib.

--

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



[issue16177] Typing left parenthesis in IDLE causes intermittent Cocoa Tk crash on OS X

2014-10-07 Thread Tom Goddard

Tom Goddard added the comment:

I've seen this crash about 50 times in the UCSF Chimera molecular visualization 
package, same traceback, and it is caused when a tooltip is raised, but not 
from IDLE.  The key observation is that it only happens on dual display systems 
where the second display is positioned partly or entirely above or to the left 
of the primary display.  An attempt to raise a tooltip on that second display 
causes a crash.  This seems almost certain to be a Mac Tk bug.  At first I 
thought it was caused by the x,y screen position of the tool tip being 
negative.  But when the second screen is arranged above the primary screen (in 
Mac display system preferences) the y position is which increases from bottom 
to top is something like 2000, not negative.  Currently my hunch is that the 
tooltip popup window was created for the primary display, and trying to 
position it on the secondary display is for some reason an error.  I don't know 
enough about the native Mac NSWindow to say anything definitive.

Hope this helps you to at least consistently reproduce the crash.

--
nosy: +goddard

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



[issue16177] Typing left parenthesis in IDLE causes intermittent Cocoa Tk crash on OS X

2014-10-07 Thread Tom Goddard

Tom Goddard added the comment:

More testing shows that this Mac Tk crash with dual displays only happens when 
the second display is partly or entirely above the primary display in the Mac 
display system preferences.  An attempt to show the tooltip on the second 
display above the top of the primary display a crash happens.  Contrary to my 
previous comment it does not appear to depend on whether the secondary display 
is to the right or to the left of the primary display.  Possibly the key factor 
is that the tooltip is being displayed above Mac top of (primary) screen menu 
bar.  It is possible that that is an Apple bug, rather than a Mac Tk bug.

--

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



[issue16177] Typing left parenthesis in IDLE causes intermittent Cocoa Tk crash on OS X

2014-10-07 Thread Ned Deily

Ned Deily added the comment:

Tom, thanks for the detailed analysis.  It seems pretty clear that this is not 
a Python problem and there's really nothing we can do about it.  It would be 
great if you would be willing to open an issue on the Tcl/Tk project's issue 
tracker so that they are aware of it and perhaps can investigate it now that 
there might be a way to reliably reproduce the crash.  I'm going to close this 
issue under the assumption it is a Tk problem.  If it should prove otherwise, 
feel free to re-open.

http://core.tcl.tk/tcl/reportlist

--
resolution:  - third party
stage: test needed - resolved
status: open - closed

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