Re: How to store some elements from a list into another

2017-06-13 Thread Jussi Piitulainen
[email protected] writes:

> On Monday, June 12, 2017 at 7:33:03 PM UTC+1, José Manuel Suárez Sierra wrote:
>> Hello,
>> I am stuck with a (perhaps) easy problem, I hope someone can help me:
>> 
>> My problem is:
>> I have a list of lists like this one:
>> [[55, 56, 57, 58, 83, 84, 85, 86, 89, 90, 91, 92, 107, 108, 109, 110,
>> 111, 117, 118, 119, 120, 128, 129, 130, 131, 135, 136, 137, 138, 184,
>> 185, 186, 187, 216, 217, 218, 219, 232, 233, 234, 235, 236, 237, 238,
>> 267, 268, 269, 270, 272, 273, 274, 275], [2, 3, 4, 5, 9, 10, 11, 12,
>> 21, 22, 23, 24, 29, 30, 31, 32, 56, 57, 58, 59, 65, 66, 67, 68, 74,
>> 75, 76, 77, 78, 89, 90, 91, 92, 98, 99, 100, 101, 102, 125, 126, 127,
>> 128, 131, 132, 133, 134, 135]]
>> 
>> And what I want is to store some of these datum into another list
>> according to the next conditions:
>>
>> 1. I just want to store data if these values are consecutive (four in
>> four), for instance, for first element I would like to store into the
>> new list: [[[55,58],[83,86],[n,n+3]]] and so on.
>>
>>  I tried something like this:
>> 
>> x=0
>> y=0
>> while list6[x][y] == list6[x][y+1]-1 and list6[x][y] == 
>> list6[x][y+1]-2 and list6[x][y] == list6[x][y+1]-3 or list6[x][0]:
>> 
>> list7.append(list6[x][y])
>> list7.append(list6[x][y+3])
>> y = y+1
>> if (list6[x][y])%(list6[x][len(list6[x])-1]) == 0:
>> x= x+1
>> 
>> if len(list6[x]) == x and len(list6[x][y]) == y:
>> break
>> 
>> 
>> It does not work
>> 
>> I appreciate your help 
>> Thank you
>
> Perhaps use the recipe for consecutive numbers from here
> https://docs.python.org/2.6/library/itertools.html#examples It will
> have to be modified for Python 3, I'll leave that as an exercise.

What a clever idea. Pity it's gone in newer documentation. (By the "it"
in the previous sentence I refer only to the idea of grouping by the
difference to the index in the original sequence, and by "gone" only to
the fact that I didn't see this example at the corresponding location
for Python 3.6, which I found by replacing the 2 in the URL with 3.
Perhaps the idea is preserved somewhere else?)

Anyway, I've adapted it to Python 3, and to an analysis of the problem
at hand - mainly the problem that the OP finds themselves _stuck_ with
their spec and their code, as quoted above. Hope it helps.

What follows, follows.

# The big idea is to define (auxiliary) functions. It's not an
# advanced idea. It's the most basic of all ideas. The experience of
# being stuck comes from trying to see the whole problem at once.

# Ok, familiary with standard ways of viewing things helps. But that
# is just the flip side of breaking problems into manageable parts:
# past experience suggests that some kinds of parts are more useful,
# more composable into a solution, so in standard libraries.

# One subproblem is to group just one list of numbers, then it is easy
# to group every list in a list of such lists. But another subproblem
# is to deal with one group of numbers. There seem to be two concerns:
# a group should consist of consecutive numbers, and a group should
# consist of four numbers - the latter at least is easy enough if the
# group is stored as a list, but what should be done if there are five
# or seven numbers? No idea, but that can be clarified later once the
# components of a solution are untangled into their own functions.

# The battle cry is: Use def!

import itertools as it
import operator as op

def applied(f):
'''Reification of that asterisk - like a really advanced
computer-sciency kind of thing. But see no lambda!'''
def F(args): return f(*args)
return F

def consequences(data):
'''Lists of consecutive datami, clever idea adapted from
https://docs.python.org/2.6/library/itertools.html#examples'''
for k, group in it.groupby(enumerate(data), applied(op.sub)):
yield [datum for index, datum in group]

def isfourlong(sequence):
'''True if sequence is of length 4.'''
return len(sequence) == 4

def ends(sequences):
'''Collect the endpoints of sequences in a list of 2-lists.'''
return [[sequence[0], sequence[-1]] for sequence in sequences]

data = [[55, 56, 57, 58, 83, 84, 85, 86, 89, 90, 91, 92, 107, 108,
 109, 110, 111, 117, 118, 119, 120, 128, 129, 130, 131, 135,
 136, 137, 138, 184, 185, 186, 187, 216, 217, 218, 219, 232,
 233, 234, 235, 236, 237, 238, 267, 268, 269, 270, 272, 273,
 274, 275],

[2, 3, 4, 5, 9, 10, 11, 12, 21, 22, 23, 24, 29, 30, 31, 32,
 56, 57, 58, 59, 65, 66, 67, 68, 74, 75, 76, 77, 78, 89, 90,
 91, 92, 98, 99, 100, 101, 102, 125, 126, 127, 128, 131, 132,
 133, 134, 135]]

def testrun():
'''See how many variations can be composed out of the few auxiliary
functions - the problem becomes tame, or at least a bit tamer.
This kind of ad-hoc test suite is very useful, during 

Re: Customise the virtualenv `activate` script

2017-06-13 Thread Cameron Simpson

On 13Jun2017 11:57, Ben Finney  wrote:

Many of the code bases for which I use a Python virtualenv, need
additional (custom) environment variables set, each time the virtualenv
is activated.

How can I make this easy for developers who already know how to activate
a virtualenv?

* Edit the ‘$VENV/bin/activate’ script directly, to add statements that
 set more environment variables?

* Write a custom wrapper script, that incidentally calls
 ‘$VENV/bin/activate’?

* Write a separate script with a specific name, that will be
 automatically called by ‘$VENV/bin/activate’? Does such a thing exist?

Of course I could write a script with a different name, and instruct
developers to run that instead. Instead, this question is asking how to
hook into the existing convention, of activating the virtualenv with a
known name ‘$VENV/bin/activate’.


I cannot speak for the conventions.

I must admit my initial preference would be the differently named wrapper.  
Surely users of the codebase will be invoking stuff via something opaque which 
sources the requisite things?


Actually, on trying to write something simple and flexible, since once made the 
venv is basicly state WRT the activate script, I'm leaning towards hacking the 
activate script, probably by keeping a distinct file off the the side and 
modifying activate to source it.


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


Re: How to store some elements from a list into another

2017-06-13 Thread Peter Otten
Jussi Piitulainen wrote:

> [email protected] writes:
> 
>> On Monday, June 12, 2017 at 7:33:03 PM UTC+1, José Manuel Suárez Sierra
>> wrote:
>>> Hello,
>>> I am stuck with a (perhaps) easy problem, I hope someone can help me:
>>> 
>>> My problem is:
>>> I have a list of lists like this one:
>>> [[55, 56, 57, 58, 83, 84, 85, 86, 89, 90, 91, 92, 107, 108, 109, 110,
>>> 111, 117, 118, 119, 120, 128, 129, 130, 131, 135, 136, 137, 138, 184,
>>> 185, 186, 187, 216, 217, 218, 219, 232, 233, 234, 235, 236, 237, 238,
>>> 267, 268, 269, 270, 272, 273, 274, 275], [2, 3, 4, 5, 9, 10, 11, 12,
>>> 21, 22, 23, 24, 29, 30, 31, 32, 56, 57, 58, 59, 65, 66, 67, 68, 74,
>>> 75, 76, 77, 78, 89, 90, 91, 92, 98, 99, 100, 101, 102, 125, 126, 127,
>>> 128, 131, 132, 133, 134, 135]]
>>> 
>>> And what I want is to store some of these datum into another list
>>> according to the next conditions:
>>>
>>> 1. I just want to store data if these values are consecutive (four in
>>> four), for instance, for first element I would like to store into the
>>> new list: [[[55,58],[83,86],[n,n+3]]] and so on.
>>>
>>>  I tried something like this:
>>> 
>>> x=0
>>> y=0
>>> while list6[x][y] == list6[x][y+1]-1 and list6[x][y] ==
>>> list6[x][y+1]-2 and list6[x][y] == list6[x][y+1]-3 or
>>> list6[x][0]:
>>> 
>>> list7.append(list6[x][y])
>>> list7.append(list6[x][y+3])
>>> y = y+1
>>> if (list6[x][y])%(list6[x][len(list6[x])-1]) == 0:
>>> x= x+1
>>> 
>>> if len(list6[x]) == x and len(list6[x][y]) == y:
>>> break
>>> 
>>> 
>>> It does not work
>>> 
>>> I appreciate your help
>>> Thank you
>>
>> Perhaps use the recipe for consecutive numbers from here
>> https://docs.python.org/2.6/library/itertools.html#examples It will
>> have to be modified for Python 3, I'll leave that as an exercise.
> 
> What a clever idea. Pity it's gone in newer documentation. (By the "it"
> in the previous sentence I refer only to the idea of grouping by the
> difference to the index in the original sequence, and by "gone" only to
> the fact that I didn't see this example at the corresponding location
> for Python 3.6, which I found by replacing the 2 in the URL with 3.
> Perhaps the idea is preserved somewhere else?)
> 
> Anyway, I've adapted it to Python 3, and to an analysis of the problem
> at hand - mainly the problem that the OP finds themselves _stuck_ with
> their spec and their code, as quoted above. Hope it helps.
> 
> What follows, follows.
> 
> # The big idea is to define (auxiliary) functions. It's not an
> # advanced idea. It's the most basic of all ideas. The experience of
> # being stuck comes from trying to see the whole problem at once.
> 
> # Ok, familiary with standard ways of viewing things helps. But that
> # is just the flip side of breaking problems into manageable parts:
> # past experience suggests that some kinds of parts are more useful,
> # more composable into a solution, so in standard libraries.
> 
> # One subproblem is to group just one list of numbers, then it is easy
> # to group every list in a list of such lists. But another subproblem
> # is to deal with one group of numbers. There seem to be two concerns:
> # a group should consist of consecutive numbers, and a group should
> # consist of four numbers - the latter at least is easy enough if the
> # group is stored as a list, but what should be done if there are five
> # or seven numbers? No idea, but that can be clarified later once the
> # components of a solution are untangled into their own functions.
> 
> # The battle cry is: Use def!
> 
> import itertools as it
> import operator as op
> 
> def applied(f):
> '''Reification of that asterisk - like a really advanced
> computer-sciency kind of thing. But see no lambda!'''
> def F(args): return f(*args)
> return F
> 
> def consequences(data):
> '''Lists of consecutive datami, clever idea adapted from
> https://docs.python.org/2.6/library/itertools.html#examples'''
> for k, group in it.groupby(enumerate(data), applied(op.sub)):
> yield [datum for index, datum in group]

Hm, the itertools users' code of honour requires that no intermediate 
sequences be materialised ;) So:

second = op.itemgetter(1)

def consequences(data):
for k, group in it.groupby(enumerate(data), applied(op.sub)):
yield edges(map(second, group))

def isfourlong(pair):
min, max = pair
return max - min == 3

def edges(items):
first = last = next(items)
for last in items:
pass
return [first, last]

def ends(sequences):
return list(sequences)

However, this is infested with for loops. Therefore

def consequences(data):
groups = map(second, it.groupby(enumerate(data), applied(op.sub)))
sans_index = map(functools.partial(map, second), groups)
return map(edges, sans_index)

and because we want to hide traces that this was written by mere mortals

d

Re: How to store some elements from a list into another

2017-06-13 Thread Jussi Piitulainen
Peter Otten writes:

...

> def edges(items):
> first = last = next(items)
> for last in items:
> pass
> return [first, last]

...

> However, this is infested with for loops. Therefore

...

> I don't immediately see what to do about the for loop in edges(), so
> I'll use the traditional cop-out: Removing the last loop is left as an
> exercise...

In the spirit of the exercise:

def sekond(x, y):
return y

def edges(items): # where items is a non-empty iterator
first = next(items)
last = functools.reduce(sekond, items, first)
return [first, last]

Of course, right?
-- 
https://mail.python.org/mailman/listinfo/python-list


How to decompile an exe file compiled by py2exe?

2017-06-13 Thread Xristos Xristoou
hello

How to decompile an exe file compiled by py2exe?
in my file i have a library.zip file i dont if that help this work.

i need some easy because i am very new i try some programs but without results.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to decompile an exe file compiled by py2exe?

2017-06-13 Thread Irving Duran
This might be what you are looking for ->
https://stackoverflow.com/questions/6287918/how-to-decompile-an-exe-file-compiled-by-py2exe

On Tue, Jun 13, 2017 at 8:52 AM Xristos Xristoou  wrote:

> hello
>
> How to decompile an exe file compiled by py2exe?
> in my file i have a library.zip file i dont if that help this work.
>
> i need some easy because i am very new i try some programs but without
> results.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Thank You,

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


Re: How to store some elements from a list into another

2017-06-13 Thread breamoreboy
On Monday, June 12, 2017 at 7:33:03 PM UTC+1, José Manuel Suárez Sierra wrote:
> Hello,
> I am stuck with a (perhaps) easy problem, I hope someone can help me:
> 
> My problem is:
> I have a list of lists like this one:
> [[55, 56, 57, 58, 83, 84, 85, 86, 89, 90, 91, 92, 107, 108, 109, 110, 111, 
> 117, 118, 119, 120, 128, 129, 130, 131, 135, 136, 137, 138, 184, 185, 186, 
> 187, 216, 217, 218, 219, 232, 233, 234, 235, 236, 237, 238, 267, 268, 269, 
> 270, 272, 273, 274, 275], [2, 3, 4, 5, 9, 10, 11, 12, 21, 22, 23, 24, 29, 30, 
> 31, 32, 56, 57, 58, 59, 65, 66, 67, 68, 74, 75, 76, 77, 78, 89, 90, 91, 92, 
> 98, 99, 100, 101, 102, 125, 126, 127, 128, 131, 132, 133, 134, 135]]
> 
> And what I want is to store some of these datum into another list according 
> to the next conditions:
> 1. I just want to store data if these values are consecutive (four in four), 
> for instance, for first element I would like to store into the new list: 
> [[[55,58],[83,86],[n,n+3]]] and so on.
>  I tried something like this:
> 
> x=0
> y=0
> while list6[x][y] == list6[x][y+1]-1 and list6[x][y] == 
> list6[x][y+1]-2 and list6[x][y] == list6[x][y+1]-3 or list6[x][0]:
> 
> list7.append(list6[x][y])
> list7.append(list6[x][y+3])
> y = y+1
> if (list6[x][y])%(list6[x][len(list6[x])-1]) == 0:
> x= x+1
> 
> if len(list6[x]) == x and len(list6[x][y]) == y:
> break
> 
> 
> It does not work
> 
> I appreciate your help 
> Thank you

Perhaps use the recipe for consecutive numbers from here 
https://docs.python.org/2.6/library/itertools.html#examples  It will have to be 
modified for Python 3, I'll leave that as an exercise.

Kindest regards.

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


Re: Progress on the Gilectomy

2017-06-13 Thread Robin Becker

On 11/06/2017 07:27, Steve D'Aprano wrote:



I'm tired of people complaining about the GIL as a "mistake" without
acknowledging that it exists for a reason.



I thought we were also consenting adults about problems arising from bad 
extensions. The GIL is a blocker for cpython's ability to use multi-core cpus.


I looked at Larry's talk with interest. The GIL is not a requirement as he 
pointed out at the end, both IronPython and Jython don't need it.


That said I think the approach he outlined is probably wrong unless we attach a 
very high weight to preserving the current extension interface. C extensions are 
a real nuisance.


The contention issues all arise from reference counting. Newer languages like go 
seem to prefer the garbage collection approach. Perhaps someone should try a 
reference-countectomy, but then they already have with other python implementations.

--
Robin Becker

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


Re: Progress on the Gilectomy

2017-06-13 Thread Skip Montanaro
On Tue, Jun 13, 2017 at 11:09 AM, Robin Becker  wrote:

> I looked at Larry's talk with interest. The GIL is not a requirement as he
> pointed out at the end, both IronPython and Jython don't need it.


But they don't support CPython's extension module API either, I don't
think. (I imagine that might have been the point of your reference.)

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


Re: Progress on the Gilectomy

2017-06-13 Thread Terry Reedy

On 6/13/2017 12:09 PM, Robin Becker wrote:

On 11/06/2017 07:27, Steve D'Aprano wrote:



I'm tired of people complaining about the GIL as a "mistake" without
acknowledging that it exists for a reason.

I thought we were also consenting adults about problems arising from bad 
extensions. The GIL is a blocker for cpython's ability to use multi-core 
cpus.


When using threads, not when using multiple processes.

> The contention issues all arise from reference counting. Newer
> languages like go seem to prefer the garbage collection approach.
> Perhaps someone should try a reference-countectomy,

This was tried at least once, perhaps 15 years ago.

--
Terry Jan Reedy

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


Re: Progress on the Gilectomy

2017-06-13 Thread Skip Montanaro
On Tue, Jun 13, 2017 at 1:53 PM, Terry Reedy  wrote:

> This was tried at least once, perhaps 15 years ago.


Yes, I believe Greg Smith (?) implemented a proof-of-concept in about the
Python 1.4 timeframe. The observation at the time was that it slowed down
single-threaded programs too much to be accepted as it existed then. That
remains the primary bugaboo as I understand it. It seems Larry has pushed
the envelope a fair bit farther, but there are still problems.

I don't know if the Gilectomy code changes are too great to live along the
mainline branches, but I wonder if having a bleeding-edge-gilectomy branch
in Git (maintained alongside the regular stuff, but not formally released)
would

a) help it stay in sync better with CPython
b) expose the changes to more people, especially extension module authors

Combined, the two might make it so the GIL-free branch isn't always playing
catchup (because of 'a') and more extension modules get tweaked to work
properly in a GIL-free world (because of 'b'). I imagine Larry Hastings has
given the idea some consideration.

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


Re: How to store some elements from a list into another

2017-06-13 Thread Peter Otten
Jussi Piitulainen wrote:

> Peter Otten writes:
> 
> ...
> 
>> def edges(items):
>> first = last = next(items)
>> for last in items:
>> pass
>> return [first, last]
> 
> ...
> 
>> However, this is infested with for loops. Therefore
> 
> ...
> 
>> I don't immediately see what to do about the for loop in edges(), so
>> I'll use the traditional cop-out: Removing the last loop is left as an
>> exercise...
> 
> In the spirit of the exercise:
> 
> def sekond(x, y):
> return y
> 
> def edges(items): # where items is a non-empty iterator
> first = next(items)
> last = functools.reduce(sekond, items, first)
> return [first, last]
> 
> Of course, right?

Yeah, reduce() is certainly the cherry on the itertools cake ;)

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


Re: How to store some elements from a list into another

2017-06-13 Thread Grant Edwards
On 2017-06-13, Peter Otten <[email protected]> wrote:

>> def edges(items): # where items is a non-empty iterator
>> first = next(items)
>> last = functools.reduce(sekond, items, first)
>> return [first, last]
>> 
>> Of course, right?
>
> Yeah, reduce() is certainly the cherry on the itertools cake ;)

Is the optional initializer the only difference between
functools.reduce() and the builtin reduce()?

-- 
Grant Edwards   grant.b.edwardsYow! I know th'MAMBO!!
  at   I have a TWO-TONE CHEMISTRY
  gmail.comSET!!

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


Re: How to store some elements from a list into another

2017-06-13 Thread Peter Otten
Grant Edwards wrote:

> On 2017-06-13, Peter Otten <[email protected]> wrote:
> 
>>> def edges(items): # where items is a non-empty iterator
>>> first = next(items)
>>> last = functools.reduce(sekond, items, first)
>>> return [first, last]
>>> 
>>> Of course, right?
>>
>> Yeah, reduce() is certainly the cherry on the itertools cake ;)
> 
> Is the optional initializer the only difference between
> functools.reduce() and the builtin reduce()?

I don't think there's a difference at all -- at least the docstrings are the 
same:

$ python -c 'import functools; print functools.reduce.__doc__ == 
reduce.__doc__; print reduce.__doc__'
True
reduce(function, sequence[, initial]) -> value

Apply a function of two arguments cumulatively to the items of a sequence,
from left to right, so as to reduce the sequence to a single value.
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
1+2)+3)+4)+5).  If initial is present, it is placed before the items
of the sequence in the calculation, and serves as a default when the
sequence is empty.
$

Note that the builtin was removed in Python 3.

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


Re: How to store some elements from a list into another

2017-06-13 Thread Grant Edwards
On 2017-06-13, Peter Otten <[email protected]> wrote:
> Grant Edwards wrote:
>
>> On 2017-06-13, Peter Otten <[email protected]> wrote:
>> 
 def edges(items): # where items is a non-empty iterator
 first = next(items)
 last = functools.reduce(sekond, items, first)
 return [first, last]
 
 Of course, right?
>>>
>>> Yeah, reduce() is certainly the cherry on the itertools cake ;)
>> 
>> Is the optional initializer the only difference between
>> functools.reduce() and the builtin reduce()?
>
> I don't think there's a difference at all -- at least the docstrings are the 
> same:
>
> $ python -c 'import functools; print functools.reduce.__doc__ == 
> reduce.__doc__; print reduce.__doc__'
> True
> reduce(function, sequence[, initial]) -> value

Hmm.  I don't know where I got the impression that the built-in didn't
support the optional initializer.  It's clearly there in the official
docs.  I must have been accidentally looking at one of those bogus
"tutorial" sites that have managed to fool Google into thinking
they're not worthless tripe.

> Note that the builtin was removed in Python 3.

Yep, I just figured that out.  [I still use 2.7 for most of my
quick/small applications since being able to freely mix strings and
bytes saves a lot of hassle for the work I do.]

-- 
Grant Edwards   grant.b.edwardsYow! We just joined the
  at   civil hair patrol!
  gmail.com

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


Test String Contents

2017-06-13 Thread Matt
What is easiest way to determine if a string ONLY contains a-z upper
or lowercase.  I also want to allow the "-" and "_" symbols.  No
spaces or anything else.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Test String Contents

2017-06-13 Thread Peter Otten
Matt wrote:

> What is easiest way to determine if a string ONLY contains a-z upper
> or lowercase.  I also want to allow the "-" and "_" symbols.  No
> spaces or anything else.

If you don't know regular expressions here's a method where not much can go 
wrong:

>>> import string
>>> acceptable = frozenset(string.ascii_letters + "_-").issuperset
>>> acceptable("Foo-Bar")
True
>>> acceptable("Foo-Bar42")
False
>>> acceptable("Foo Bar")
False
>>> acceptable(string.ascii_letters + "_-")
True


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


Re: Test String Contents

2017-06-13 Thread Thomas Nyberg
On 06/13/2017 03:34 PM, Matt wrote:
> What is easiest way to determine if a string ONLY contains a-z upper
> or lowercase.  I also want to allow the "-" and "_" symbols.  No
> spaces or anything else.
> 
I'm not sure it's the best way, but the following seems okay:

>>> s = 'hello_world'
>>> s.replace('-','').replace('_','').isalpha()
True
>>> s = 'hello world'
>>> s.replace('-','').replace('_','').isalpha()
False
>>>

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


Re: Test String Contents

2017-06-13 Thread Peter Otten
Peter Otten wrote:

> Matt wrote:
> 
>> What is easiest way to determine if a string ONLY contains a-z upper
>> or lowercase.  I also want to allow the "-" and "_" symbols.  No
>> spaces or anything else.
> 
> If you don't know regular expressions here's a method where not much can
> go wrong:

... with the exception of the empty string.

If you want to reject empty strings you need to add an explicit test:

if s and acceptable(s):
print("OK")

 import string
 acceptable = frozenset(string.ascii_letters + "_-").issuperset
 acceptable("Foo-Bar")
> True
 acceptable("Foo-Bar42")
> False
 acceptable("Foo Bar")
> False
 acceptable(string.ascii_letters + "_-")
> True

By the way, I find that behaviour more intuitive than that of the 
str.isXXX() methods as e. g.

s.isdigit() 

will differ from

all(c.isdigit() for c in s)

for the empty string. 

What do you think, are all apples in an empty basket red or not?

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


ensurepip

2017-06-13 Thread Steven D'Aprano
ensurepip is added in Python 3.4:

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


But:

root@runes:~# python3.4 -m ensurepip
/usr/bin/python3.4: No module named ensurepip



Any clues on what is going on or how to diagnose this?




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


Re: ensurepip

2017-06-13 Thread Pavol Lisy
$ python3 -m ensurepip
/usr/bin/python3: No module named ensurepip

But maybe this help to understand:

$ python -m ensurepip
ensurepip is disabled in Debian/Ubuntu for the system python.

Python modules For the system python are usually handled by dpkg and apt-get.

apt-get install python-

Install the python-pip package to use pip itself.  Using pip together
with the system python might have unexpected results for any system installed
module, so use it on your own risk, or make sure to only use it in virtual
environments.


On 6/14/17, Steven D'Aprano  wrote:
> ensurepip is added in Python 3.4:
>
> https://docs.python.org/3/library/ensurepip.html
>
>
> But:
>
> root@runes:~# python3.4 -m ensurepip
> /usr/bin/python3.4: No module named ensurepip
>
>
>
> Any clues on what is going on or how to diagnose this?
>
>
>
>
> --
> Steve
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list