ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt

  Hi All,

If anyone is interested, a module was born:

https://bitbucket.org/nagylzs/intervalset
https://pypi.python.org/pypi/intervalset/0.1.1

I have some unit tests, but testers and comments are welcome.

Also see below.

>>  
>>   Hello,
>>
>> I need to compare sets of datetime intervals, and make set operations on
>> them: intersect, union, difference etc. One element of a set would be an
>> interval like this:
> Two thoughts on this: Such an object is not precisely a set* of
> datetimes, rather it is a set of nonintersecting intervals. 

Yes, you are right. It is a set of non-intersecting intervals.

> It could
> also be useful to have one for numbers (the datetime version could even
> maybe be implemented in terms of it)
Well, please check sources on bitbucket. You are more than welcome to
join the project.
>
>> element ::= (start_point_in_time, end_point_in_time)
>> intervalset ::= { element1, element2,  }
> Are these open intervals or closed intervals?
Closed. In my particular implementation, there is a singleton for all
empty intervals. It is not possible to create an arbitrary interval with
the same starting and ending time (the singleton being the only
exception). I think that implementing open intervals would be much more
difficult, and we would have to know and use the smallest possible
increment (resolution) of the date/time type. Which may be platform
dependent.
>
> Also, how are you going to handle daylight savings?
Well, this little module only uses datetime instances and relies on the
datetime module for comparison. As far as datetime instances compare
correctly, this module will also work correctly.

Best,

   Laszlo



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


Re: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt

>
> On Fri, Apr 1, 2016 at 1:32 AM Nagy László Zsolt  > wrote:
>
> Does anyone know a library that already implements these functions?
>
>
> What do you not like about the ones on PyPI?
> https://pypi.python.org/pypi?%3Aaction=search&term=interval&submit=search
There are a few, but none of them was implementing a set ot
non-intersecting intervals. AFAIK what I needed had no implementation
until now.
>
> Depending on the resolution you want, you might be able to use builtin
> sets for everything.
>
> def interval(start, stop, precision=60):
> a = round(start.timestamp(), precision)
> b = round(stop.timestamp(), precision)
> return set(range(a, b, precision))
>
I know, I was not clear in my request. A simple set will not unify
overlapping intervals, and cannot do set operations (union,
intersection, difference, symmetric difference).


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


how to optimize the below code with a helper function

2016-04-04 Thread Ganesh Pal
Hi Team,

Iam on python 2.7.10 and Linux.

I have a  python function where the similar kind of pattern repeating 100
of times

Sample code snippet:

test01_log = os.path.join(LOG_DIR, "test01.log")
cls.get_baddr['test01'] = failure.run_tool(
test01_log, object="inode", offset="18", size="4",
optype="set")

test02_log = os.path.join(LOG_DIR, "test02.log")
cls.get_baddr['test02'] = failure.run_tool(
test02_log, lin=lin_02, object="lin", offset="100", size="5",
optype="set")
 ..

test100_log = os.path.join(LOG_DIR, "test100.log")
cls.get_baddr['test100'] = failure.run_tool(
test02_log, baddr=lin_02, object="baddr", offset="100", size="5",
optype="set")


(1)  Any tips how I can optimize this i.e test case, should have a helper
function that all test cases call.

(2) Also note that failure.run_tool function can have variable number of
argments  how to handle this in the helper function?



Thanks in advance


Regards,

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


Re: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt

>> element ::= (start_point_in_time, end_point_in_time)
>> intervalset ::= { element1, element2,  }
>>
>> Operations on elements:
>
> Eh... I think these should be realized as operations on an intervalset
> with a single element, and that elements should simply have properties
> like the start, end, and if it's open or closed on each side. In
> particular, any one of these could return something that is not an
> element.
The way it is implemented now:

* Intersection of two intervals will always be a single interval. It is
easy to see why.
* Union of two intervals is possible only for overlapping and touching
intervals.
* These operations are also defined on intervals sets, but they work in
all cases (empty sets and sets with various elements).

The reason of introducing the intersection of two intervals is to create
an easy way to tell if they have a non-empty intersection. So if i1 and
i2 are intervals, you can do this:

if i1*i2:
pass # They share a common non-empty interval

If you define the intersection operation on interval sets only, then you
need to write something like this:

if IntervalSet(i1)*IntervalSet(i2):
pass

which is both uglier and an overkill.

>
>> element1.intersect(element2)
> May return the empty set, if they do not intersect.
It does indeed.
>
>> element1.union(element2)
> May return {element1, element 2}
I choose to raise a ValueError if they don't overlap or touch. In order
to get the union of them in a set, you simply write:

IntervalSet(element1, element2)

which will unify them correctly.



>
>
>> Operations on sets:
>>
>> intervalset1.intersect(intervalset2)
>> intervalset1.union(intervalset2)
>> intervalset1.minus(intervalset2)
> These should be operators. s1 & s2, s1 | s2, s1 - s2. There's also a s1
> ^ s2 operation for python sets, the symmetric difference.

Well, I used +, *. Do you think that & and | would be better?
>
> Wouldn't it be useful to have some operations on datetimes?
>
> intervalset1.ltall(dt)
>  all(dt < x.start or dt == x.start and x.startopen for x in dt)
> intervalset1.gtall(dt)
>  all(dt > x.end or dt == x.end and x.endopen for x in dt)
> intervalset1.leall(dt)
>  all(dt <= x.start for x in intervalset1) # I _think_ this is all
> you need for this
> intervalset1.geall(dt)
>  all(dt >= x.end for x in intervalset1)
> dt in intervalset1
> ... any(dt in elem for x in intervalset1)
> dt in elem
> ... dt > elem.start and dt < elem.end or dt == elem.start and not
> elem.startopen or dt == elem.end and not elem.endopen
> min and max
> ... seems trivial, but what to return if the first/last element is open?
You are encouraged to add a pull request. Although I did not implement
open intervals, only closed ones. Here is my reasoning:

  * datetime instances have a fixed resolution, an open interval would
be equal to a "one step less" closed interval.
  * There is a semantical problem when your try to define relations
between open and closed intervals. Is an open interval less then a
closed one? Is the difference of an equally sized open and closed
interval empty or not? Does it evaluate to True of False?
  * Practical usage (at least in my project) these intervals measure
something: working time of an employee, driving time of a car etc.
From that point of view, there is no real difference between an open
and a close interval. (I can see that there should be a difference
for scientific applications.)

>
> I'm truly shocked you didn't even mention the "in" operation.
Me too. Simply I didn't need it yet. Added to TODO list. Just I need to
figure out if the "in" operator should return True when the element is
*partly* in the set. ;-)
>
> Also, as long as we're setting up an infinite (not really but anyway)
> set, why not also have the ability to have open-ended intervals that
> extend to infinity. Then you could invert the set too, for free given
> the minus operation: ~x == {(-inf, inf)} - x.
Great idea. The empty interval can be (-inf, -inf) which is smaller than
anything.
> It occurs to me that while I mentioned numbers, in principle you could
> use _any_ total-ordered type*. strings, tuples...
Yes, that is true. In fact the current class could be easily generalized
to support any ordered type. But then, how do we mix our own infinity
with math.inf?
> *nitpicker's corner: here, "type" is used to mean any set/class/category
> of objects, possibly of multiple python types and possibly not
> comprising the entirety of a single type, which are total-ordered with
> respect to each other, including the codomain of any key projection
> function suitable for sorting.

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


2.7 source import in python 3.x

2016-04-04 Thread Robin Becker

A user points out that this code in reportlab uses the now deprecated imp module

def _fake_import(fn,name):
if os.path.isfile(fn):
import imp
with open(fn,'rb') as f:
imp.load_source(name,fn,f)

and suggests I use importlib SourceFileLoader. Is there anything wrong with this 
code (only for use in python 3.x)



def _fake_import(fn,name):
from importlib import machinery
m = machinery.SourceFileLoader(name,fn)
try:
return m.load_module(name)
except FileNotFoundError:
raise ImportError('file %s not found' % ascii(fn))

the newer import machinery seems particularly complex so I'm not at all sure 
this does what I intend even though it seems to work.


The original function is only used once like this


try:

_fake_import(os.path.expanduser(os.path.join('~','.reportlab_mods')),'reportlab_mods')
except (ImportError,KeyError):
pass


and is intended to allow per user actions in a config file when reportlab is 
imported.


--
Robin Becker

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


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Peter Otten
Nagy László Zsolt wrote:

> If anyone is interested, a module was born:
> 
> https://bitbucket.org/nagylzs/intervalset
> https://pypi.python.org/pypi/intervalset/0.1.1
> 
> I have some unit tests, but testers and comments are welcome.

Why do you limit the intervals to datetime? Are there any assumptions in 
your code that would make it fail with int values?

Personally I would use & | instead of * + -- Python is not Pascal ;)

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


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt

> Why do you limit the intervals to datetime? Are there any assumptions in 
> your code that would make it fail with int values?

Just one. The empty interval is a singleton and I want it to be smaller
than any other interval.

UTC_ZERO = datetime.datetime.utcfromtimestamp(0)
EMPTY_INTERVAL = Interval(UTC_ZERO, UTC_ZERO) # TODO: how generalize
this for any ordered type?

Probably I could use Interval(None, None), and refactor my code.

The other problem would be __str__ and formatting, but that is easy to
generalize.

>
> Personally I would use & | instead of * + -- Python is not Pascal ;)
Operators changed to what you have suggested. (Also added ^ and
__contains__)

Thank you!

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


Re: 2.7 source import in python 3.x

2016-04-04 Thread Peter Otten
Robin Becker wrote:

> A user points out that this code in reportlab uses the now deprecated imp
> module
> 
> def _fake_import(fn,name):
>  if os.path.isfile(fn):
>  import imp
>  with open(fn,'rb') as f:
>  imp.load_source(name,fn,f)
> 
> and suggests I use importlib SourceFileLoader. Is there anything wrong
> with this code (only for use in python 3.x)
> 
> 
> def _fake_import(fn,name):
>  from importlib import machinery
>  m = machinery.SourceFileLoader(name,fn)
>  try:
>  return m.load_module(name)
>  except FileNotFoundError:
>  raise ImportError('file %s not found' % ascii(fn))
> 
> the newer import machinery seems particularly complex so I'm not at all
> sure this does what I intend even though it seems to work.

Seems like Python is one step ahead in the deprecation race. Quoting

https://docs.python.org/dev/library/importlib.html#importlib.machinery.SourceFileLoader.load_module

"""
load_module(name=None)
Concrete implementation of importlib.abc.Loader.load_module() where 
specifying the name of the module to load is optional.

Deprecated since version 3.6: Use importlib.abc.Loader.exec_module() 
instead.
"""

In the example section they have (for 3.4 and above)

spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

The importlib with all its factories is a bit intimidating; perhaps it's 
best to stick with imp.load_source() and wait for some simple helper 
functions to appear...

> The original function is only used once like this
> 
>> try:
>> 
_fake_import(os.path.expanduser(os.path.join('~','.reportlab_mods')),'reportlab_mods')
>> except (ImportError,KeyError):
>> pass
> 
> and is intended to allow per user actions in a config file when reportlab
> is imported.
> 


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


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt

> Why do you limit the intervals to datetime? Are there any assumptions in 
> your code that would make it fail with int values?
It has been generalized. Now it can be used with any immutable ordered
type. :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Collection: weak error prompt drives beginner crazy

2016-04-04 Thread animalize
An example, the file-name is conflict with library-name in stdlib or 
installed library.


There is a file uuid.py that only has two lines:

import uuid
print(uuid.uuid4())

Run uuid.py, output on Python 3.5.1:

Traceback (most recent call last):
  File "D:\uuid.py", line 1, in 
import uuid
  File "D:\uuid.py", line 3, in 
print(uuid.uuid4())
AttributeError: module 'uuid' has no attribute 'uuid4'

I was spending about an hour to find out what happend when I was a 
beginner, and I found I'm not the only one who confused by this problem.


If the prompt can be beginner-friendly a little bit, I think it's a very 
good thing.
E.g. says you are importing the file itself, rather than importing other 
file or library.

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


Re: Collection: weak error prompt drives beginner crazy

2016-04-04 Thread Joel Goldstick
On Mon, Apr 4, 2016 at 7:24 AM, animalize  wrote:
> An example, the file-name is conflict with library-name in stdlib or
> installed library.
>
> There is a file uuid.py that only has two lines:
>
> import uuid
> print(uuid.uuid4())
>
> Run uuid.py, output on Python 3.5.1:
>
> Traceback (most recent call last):
>   File "D:\uuid.py", line 1, in 
> import uuid
>   File "D:\uuid.py", line 3, in 
> print(uuid.uuid4())
> AttributeError: module 'uuid' has no attribute 'uuid4'
>
> I was spending about an hour to find out what happend when I was a beginner,
> and I found I'm not the only one who confused by this problem.
>
> If the prompt can be beginner-friendly a little bit, I think it's a very
> good thing.
> E.g. says you are importing the file itself, rather than importing other
> file or library.

And how can python know that?
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 2.7 source import in python 3.x

2016-04-04 Thread Robin Becker

On 04/04/2016 12:15, Peter Otten wrote:
..


In the example section they have (for 3.4 and above)

spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

The importlib with all its factories is a bit intimidating; perhaps it's
best to stick with imp.load_source() and wait for some simple helper
functions to appear...



maybe two steps ahead :(

when I execute the example with python 3.4.2


C:\code\hg-repos\reportlab>cat tmp\t1.py
import importlib.util
import sys

# For illustrative purposes.
import tokenize
file_path = tokenize.__file__
module_name = tokenize.__name__

spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
# Optional; only necessary if you want to be able to import the module
# by name later.
sys.modules[module_name] = module

C:\code\hg-repos\reportlab>\python34\python tmp\t1.py
Traceback (most recent call last):
  File "tmp\t1.py", line 10, in 
module = importlib.util.module_from_spec(spec)
AttributeError: 'module' object has no attribute 'module_from_spec'


The example does work in python 3.5.0 so I guess the docs are a bit misleading.


--
Robin Becker

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


Re: Strange range

2016-04-04 Thread Mark Lawrence via Python-list

On 03/04/2016 17:28, Ethan Furman wrote:

On 04/02/2016 11:58 PM, Marko Rauhamaa wrote:

Stephen Hansen :


I'm pretty sure that 99+% of the non-stdlib code out there is also
completely inaccessible (or at least inconveniently accessible) to
Stephen as well.



http://nullege.com/codes/search?cq=range would appear to be as good a 
starting point as any.


--
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: Sorting a list

2016-04-04 Thread Random832
On Mon, Apr 4, 2016, at 02:56, Peter Otten wrote:
> > That works well.  Why is it 'cheating'?
> 
> On second thought it isn't ;)

It does require a numeric type, though. There are lots of types that are
orderable but do not have a negation operator that provides a key with
reversed ordering.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sorting a list

2016-04-04 Thread Peter Otten
Random832 wrote:

> On Mon, Apr 4, 2016, at 02:56, Peter Otten wrote:
>> > That works well.  Why is it 'cheating'?
>> 
>> On second thought it isn't ;)
> 
> It does require a numeric type, though. There are lots of types that are
> orderable but do not have a negation operator that provides a key with
> reversed ordering.

If you are willing to accept the overhead you can use a wrapper class:

>>> import functools
>>> @functools.total_ordering
... class neg:
... def __init__(self, key):
... self.key = key
... def __lt__(self, other):
... return other.key < self.key
... 
>>> sorted("abcde", key=neg)
['e', 'd', 'c', 'b', 'a']


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


Re: how to optimize the below code with a helper function

2016-04-04 Thread Martin A. Brown

Greetings (again) Ganesh,

I notice that you ask about how to optimize the code, but I think 
what you mean is you want simpler code that is less repetitive and 
less copy/paste error-prone.  Is that correct?

Below, I make a few suggestions about how to simplify, although, 
there probably is further simplification that could be done.

>I am on python 2.7.10 and Linux.

Noted.  I tested my answer to your question on a Python 2.7, as 
well.

>I have a python function where the similar kind of pattern 
>repeating 100 of times

When you have a repetitive sequence of operations (or test cases, it 
looks like), you can often figure out a way to store the parameters 
as data.  When the parameters become data, then, the code becomes 
simpler.

>Sample code snippet:
>
>test01_log = os.path.join(LOG_DIR, "test01.log")
>cls.get_baddr['test01'] = failure.run_tool(
>test01_log, object="inode", offset="18", size="4",
>optype="set")
>
>test02_log = os.path.join(LOG_DIR, "test02.log")
>cls.get_baddr['test02'] = failure.run_tool(
>test02_log, lin=lin_02, object="lin", offset="100", size="5",
>optype="set")
> ..
>
>test100_log = os.path.join(LOG_DIR, "test100.log")
>cls.get_baddr['test100'] = failure.run_tool(
>test02_log, baddr=lin_02, object="baddr", offset="100", size="5",
>optype="set")

I observe that here in the failure.run_tool() call, the logfile is 
test02_log.  I would have expected it to be test100_log.  I'm 
guessing that this is exactly the sort of copy/paste error that you 
wish to avoid.

>(1)  Any tips how I can optimize this i.e test case, should have a helper
>function that all test cases call.

One function that jumps out very easily (to my eye) is a function to 
create the logfile name from the test case name.  You will see how I 
do that in the sample, so that you can call the run_tool function as 
you are currently calling it.

(You might consider putting the logfile name generation into the 
run_tool function, though, in which case, run_tool gets even simpler 
and you can get rid of my function, addLogFilename.  Hopefully, that 
makes sense to you)

>(2) Also note that failure.run_tool function can have variable 
>number of argments how to handle this in the helper function?

A variable number of arguments:  this seems like the perfect case 
for using keyword arguments!

  https://docs.python.org/2/tutorial/controlflow.html#keyword-arguments

I have one additional observation about your sample code, Ganesh.  
When I read this:

  cls.get_baddr['test01'] = failure.run_tool(
   test01_log, object="inode", offset="18", size="4",
   optype="set")

I am guessing that you are calling an external program in your test.  
I also notice that you have string contents in your variables, for 
example, offset="18".  (That's part of why I guess you are calling 
an external program as part of your test.)

If you are calling an external command in 'run_tool', why not put 
the exact command-line you want to execute into the test data.  
This would simplify your code and makes the test more transparent, 
as well.

  d = dict()
  d['test01'] = dict(cmd=['some_command', '--offset', '18', '--size', '4'],
 optype="set", object='inode')

Then, in run_tool, something like this:

  subprocess.Popen(cmd, shell=False, stderr=logfile)

But, these suggestions are all, basically, different riffs on the 
same basic idea:

  Where you have many testing scenarios, try to figure out a way to 
  store all of the test cases in data and then have the test runner 
  operate on the data.

Good luck,

-Martin


#! /usr/bin/python

from __future__ import absolute_import, division, print_function

import os
import sys
import logging


logging.basicConfig(stream=sys.stderr, level=logging.INFO)
logger = logging.getLogger(__name__)

LOG_DIR = '/var/log/frobnitz'


def createTestCases(LOG_DIR):
'''create a test case data dictionary with parameters'''
d = dict()
d['test01'] = dict(object="inode", offset="18", size="4", optype="set")
lin_02 = "something"
d['test02'] = dict(object="lin", lin=lin_02, offset="18", size="5",
   optype="set")
d['test100'] = dict(object="baddr", baddr=lin_02, offset="100", size="5",
optype="set")
return addLogFilename(d, LOG_DIR)


def run_tool(logfile, **kw):
logger.info('%s would execute with %r', logfile, kw)


def addLogFilename(d, logdir):
'''put the logfile name into the test case data dictionary'''
for casename, args in d.items():
args['logfile'] = os.path.join(logdir, casename + '.log')
return d


def main():
testcases = createTestCases(LOG_DIR)
get_baddr = dict()
for casename, kw in testcases.items():
# -- yank the logfile name out of the dictionary, before calling func
logfile = kw.pop('l

Re: [beginner] What's wrong?

2016-04-04 Thread Mark Lawrence via Python-list

On 02/04/2016 23:49, Michael Torrie wrote:

Mark, your messages are showing up to the list as being from "python,"
at least on my email.  Any reason for this?



Assuming that you're referring to me, frankly I haven't a clue.  I read 
this list with Thunderbird on Windows, I hit "reply" to something, I 
type, I hit "send", job done.  Thereafter, as far as I'm concerned, a 
miracle occurs and hundreds if not thousands of subscribers get to see 
my reply.


--
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: how to optimize the below code with a helper function

2016-04-04 Thread Martin A. Brown

Hello again,

>(1)  Any tips how I can optimize this i.e test case, should have a 
>helper function that all test cases call.
>
>(2) Also note that failure.run_tool function can have variable 
>number of argments how to handle this in the helper function?

Here's a little example of how you could coerce your problem into a 
ConfigParser-style configuration file.

With this example, I'd think you could also see how to create a 
config section called [lin_02] that contains the parameters you want 
for creating that object.  Then, it's a new problem to figure out 
how to refer to that object for one of your tests.

Anyway, this is just another way of answering the question of "how 
do I simplify this repetitive code".

Good luck and enjoy,

-Martin

#! /usr/bin/python

from __future__ import absolute_import, division, print_function

import os
import sys
import collections
from ConfigParser import SafeConfigParser as ConfigParser
import logging


logging.basicConfig(stream=sys.stderr, level=logging.INFO)
logger = logging.getLogger(__name__)

LOG_DIR = '/var/log/frobnitz'

def readCfgTestCases(cfgfile):
data = collections.defaultdict(dict)
parser = ConfigParser()
parser.read(cfgfile)
for section in parser.sections():
for name, value in parser.items(section):
data[section][name] = value
return data

def main(cfgfile):
testdata = readCfgTestCases(cfgfile)
for k, v in testdata.items():
print(k, v)


if __name__ == '__main__':
main(sys.argv[1])

# -- end of file


# -- config file

[test01]
offset = 18
size = 4
object = inode
optype = set

[test02]
# -- no way to capture lin=lin_02; must reproduce contents of lin_02
object = lin
offset = 100
size = 5
optype = set


[test100]
# -- no way to capture baddr=lin_02; must reproduce contents of lin_02
object = baddr
offset = 100
size = 5
optype = set


-- 
Martin A. Brown
http://linux-ip.net/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Collection: weak error prompt drives beginner crazy

2016-04-04 Thread Ned Batchelder
On Monday, April 4, 2016 at 7:31:38 AM UTC-4, animalize wrote:
> An example, the file-name is conflict with library-name in stdlib or 
> installed library.
> 
> There is a file uuid.py that only has two lines:
> 
>  import uuid
>  print(uuid.uuid4())
> 
> Run uuid.py, output on Python 3.5.1:
> 
>  Traceback (most recent call last):
>File "D:\uuid.py", line 1, in 
>  import uuid
>File "D:\uuid.py", line 3, in 
>  print(uuid.uuid4())
>  AttributeError: module 'uuid' has no attribute 'uuid4'
> 
> I was spending about an hour to find out what happend when I was a 
> beginner, and I found I'm not the only one who confused by this problem.
> 
> If the prompt can be beginner-friendly a little bit, I think it's a very 
> good thing.
> E.g. says you are importing the file itself, rather than importing other 
> file or library.

I agree that it would be good if Python would be clear about this error.
I suggested as much on Python-Ideas a few months ago:
https://groups.google.com/d/topic/python-ideas/dNbXlL2XoJ8/discussion
or https://mail.python.org/pipermail/python-ideas/2016-January/038165.html

The thread did not end with a strong opinion one way or the other, though
it did get distracted by other kinds of import mistakes.

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


Re: [beginner] What's wrong?

2016-04-04 Thread BartC

On 04/04/2016 15:04, Mark Lawrence wrote:

On 02/04/2016 23:49, Michael Torrie wrote:

Mark, your messages are showing up to the list as being from "python,"
at least on my email.  Any reason for this?



Assuming that you're referring to me, frankly I haven't a clue.  I read
this list with Thunderbird on Windows, I hit "reply" to something, I
type, I hit "send", job done.  Thereafter, as far as I'm concerned, a
miracle occurs and hundreds if not thousands of subscribers get to see
my reply.


On the same setup, I click 'Followup' to reply to a post, which sends to 
the group.


Other options on the dropdown box below the Followup button are Reply 
and Reply All.


Clicking Reply (on your post) starts an email to you, while Reply All 
starts an email to you and to the group.


--
Bartc



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


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Random832
On Mon, Apr 4, 2016, at 03:12, Nagy László Zsolt wrote:
> 
>   Hi All,
> 
> If anyone is interested, a module was born:
> 
> https://bitbucket.org/nagylzs/intervalset
> https://pypi.python.org/pypi/intervalset/0.1.1

I don't know if I like it being immutable. Maybe have separate mutable
and immutable versions.

Like I said before, I don't think the set-like operations on Intervals
are useful - what can you accomplish with them rather than by making a
set consisting of only one interval and doing operations on that?

> I have some unit tests, but testers and comments are welcome.
> 
> Also see below.
> 
> Yes, you are right. It is a set of non-intersecting intervals.
> 
> > It could
> > also be useful to have one for numbers (the datetime version could even
> > maybe be implemented in terms of it)
> Well, please check sources on bitbucket. You are more than welcome to
> join the project.
> >
> >> element ::= (start_point_in_time, end_point_in_time)
> >> intervalset ::= { element1, element2,  }
> > Are these open intervals or closed intervals?
> Closed. In my particular implementation, there is a singleton for all
> empty intervals. It is not possible to create an arbitrary interval with
> the same starting and ending time (the singleton being the only
> exception).

An "arbitrary interval with the same starting and ending time" would be
more like an isolated datetime (i.e. 00:00 is in the set but 23:59 or
00:01 is not)

> I think that implementing open intervals would be much more
> difficult, and we would have to know and use the smallest possible
> increment (resolution) of the date/time type. Which may be platform
> dependent.

My suggestion was to use boolean flags, and to use that to control
whether to use < or <= to test for membership.

An open interval is more like an hour where 00:00 is included and
00:59:59.99 is included but 01:00 is not. With discrete resolution
it's as simple as just moving the endpoint off by one unit, but I think
it'd be cleaner to use flags (you'd need it for numeric intervals, since
numeric types can have any resolution).

>def __contains__(self, other):
>"""Containment relation.
>
>Tell if `other` is contained *completely* in this set. The argument 
> can either be an Interval or an
>IntervalSet.
>"""

I don't think this is appropriate for this operation; this should be
__gt__. __contains__ should test a datetime (or whatever type item), not
another Interval/IntervalSet.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Set type for datetime intervals

2016-04-04 Thread Random832
On Mon, Apr 4, 2016, at 06:15, Nagy László Zsolt wrote:
> If you define the intersection operation on interval sets only, then you
> need to write something like this:
> 
> if IntervalSet(i1)*IntervalSet(i2):
> pass
> 
> which is both uglier and an overkill.

I guess what I don't understand in this situation is why aren't i1 and
i2 already IntervalSets? I'm not sure I see why user code would be
working directly with Intervals at all. Any use for it could be replaced
with an IntervalSet constructor to directly make a set of one interval.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Oscar Benjamin
On 4 April 2016 at 16:09, Random832  wrote:
> On Mon, Apr 4, 2016, at 03:12, Nagy László Zsolt wrote:
>>
>>   Hi All,
>>
>> If anyone is interested, a module was born:
>>
>> https://bitbucket.org/nagylzs/intervalset
>> https://pypi.python.org/pypi/intervalset/0.1.1
>
> I don't know if I like it being immutable. Maybe have separate mutable
> and immutable versions.
>
> Like I said before, I don't think the set-like operations on Intervals
> are useful - what can you accomplish with them rather than by making a
> set consisting of only one interval and doing operations on that?

I guess it depends what your application is but sympy has interval
sets and can do computation on them to represent the solutions of
equations/inequalities (many other types of set are also included).
For example:

In [1]: from sympy import Interval

In [2]: Interval
Out[2]: sympy.core.sets.Interval

In [3]: Interval(1, 2)
Out[3]: [1, 2]

In [4]: help(Interval)


In [5]: Interval(1, 2) & Interval(3, 4)
Out[5]: ∅

In [6]: Interval(1, 2) | Interval(3, 4)
Out[6]: [1, 2] ∪ [3, 4]

There is some discussion about why it's good to do this stuff with
sets (for sympy's purposes here):
http://docs.sympy.org/latest/modules/solvers/solveset.html#why-do-we-use-sets-as-an-output-type

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


module alias in import statement

2016-04-04 Thread ast

hello


import tkinter as tk
import tk.ttk as ttk


Traceback (most recent call last):
 File "", line 1, in 
   import tk.ttk as ttk
ImportError: No module named 'tk'


of course


import tkinter.ttk as ttk


works

Strange, isn't it ?
--
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Random832
On Mon, Apr 4, 2016, at 11:32, Oscar Benjamin wrote:
> On 4 April 2016 at 16:09, Random832  wrote:
> > Like I said before, I don't think the set-like operations on Intervals
> > are useful - what can you accomplish with them rather than by making a
> > set consisting of only one interval and doing operations on that?
> 
> I guess it depends what your application is but sympy has interval
> sets and can do computation on them to represent the solutions of
> equations/inequalities (many other types of set are also included).

Yes, my question is why it's useful to have a single Interval as a
*distinct* type, separate from the interval set type, which supports a
sharply limited number of set-like operations (such as the union of two
overlapping intervals but NOT two non-overlapping ones). This doesn't
appear to be the case in sympy based on your examples.

Having an interval as a distinct type may be useful (to iterate over the
intervals of a set, for example), but his design blurs the line between
intervals and sets (by supporting some set operations) without
eliminating it as sympy seems to do.

> In [6]: Interval(1, 2) | Interval(3, 4)
> Out[6]: [1, 2] ∪ [3, 4]
> 
> There is some discussion about why it's good to do this stuff with
> sets (for sympy's purposes here):
> http://docs.sympy.org/latest/modules/solvers/solveset.html#why-do-we-use-sets-as-an-output-type
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Set type for datetime intervals

2016-04-04 Thread Martin A. Brown

Greetings László,

>I need to compare sets of datetime intervals, and make set 
>operations on them: intersect, union, difference etc. One element 
>of a set would be an interval like this:
>
>element ::= (start_point_in_time, end_point_in_time)
>intervalset ::= { element1, element2,  }
>
>Operations on elements:
>
>element1.intersect(element2)
>element1.union(element2)
>element1.minus(element2)
>
>Operations on sets:
>
>intervalset1.intersect(intervalset2)
>intervalset1.union(intervalset2)
>intervalset1.minus(intervalset2)
>
>Does anyone know a library that already implements these functions?

Sorry to be late to the party--I applaud that you have already 
crafted something to attack your problem.  When you first posted, 
there was a library that was tickling my memory, but I could not 
remember its (simple) name.  It occurred to me this morning, after 
you posted your new library:

  https://pypi.python.org/pypi/intervaltree

This handles overlapping ranges nicely and provides some tools for 
managing them.  Before posting this, I checked that it works with 
datetime types, and, unsurprisingly, it does.

Happy trails!

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: module alias in import statement

2016-04-04 Thread Ned Batchelder
On Monday, April 4, 2016 at 11:31:41 AM UTC-4, ast wrote:
> hello
> 
> >>> import tkinter as tk
> >>> import tk.ttk as ttk
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> import tk.ttk as ttk
> ImportError: No module named 'tk'
> 
> 
> of course
> 
> >>> import tkinter.ttk as ttk
> 
> works
> 
> Strange, isn't it ?

Yes, I can see that seeming strange.  There are two things to know about
how imports work that will help explain it:

First, import statements are really just special syntax for an assignment.
When you say "import tkinter as tk", it means (in pseudocode):

tk = __import__("tkinter")

The module named "tkinter" is sought, and when found, executed, and the
resulting module object is assigned to the name "tk".

Second, notice that "import tkinter" doesn't try to evaluate "tkinter" as
an expression. If it did, that import would raise an error, because "tkinter"
isn't defined.

So in your code, you defined the name "tk" in the first line, but that
doesn't mean the name "tk" is available for you to use in the second line.

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


troubleshooting

2016-04-04 Thread Sk. Amirul Islam
i recently installed the application but when i ran it it gave a 'runtime
error". i even reinstalled it. but it gives the same error everytime i try.
im eclosing a screenshot of the error . thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: troubleshooting

2016-04-04 Thread Igor Korot
Hi,

On Mon, Apr 4, 2016 at 12:03 PM, Sk. Amirul Islam  wrote:
> i recently installed the application but when i ran it it gave a 'runtime
> error". i even reinstalled it. but it gives the same error everytime i try.
> im eclosing a screenshot of the error . thank you

Attachments are not going thru on this list.
You will need to cut and paste the error in the email. ;-)

Also, basic questions:
1. What OS are you running?
2 What version of OS are you running?
3. What version of python do you have?
4. Is all dependencies for this program are satisfied?

Thank you.

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


Re: module alias in import statement

2016-04-04 Thread Steven D'Aprano
On Tue, 5 Apr 2016 01:31 am, ast wrote:

> hello
> 
 import tkinter as tk
 import tk.ttk as ttk
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> import tk.ttk as ttk
> ImportError: No module named 'tk'
> 
> 
> of course
> 
 import tkinter.ttk as ttk
> 
> works
> 
> Strange, isn't it ?

No. You have to understand what the import statement does.

"import tkinter" does at least three steps:

- locate a Python file called (for example) "tkinter.py", 
  or a package "tkinter/__init__.py"
- execute that module or package file to create a module object
- create a local variable "tkinter" bound to the module object.

In pseudo-code:

# import tkinter
path = find module("tkinter")
tkinter = execute(path)


"import tkinter as tk" changes the last step:

# import tkinter as tk
path = find module("tkinter")
tk = execute(path)


Running "import tkinter as tk" doesn't change the name of the module or
package on disk. It doesn't change (say) the directory "tkinter/" to "tk/".


What happens if there is a dot in the module name?

"import tkinter.ttk as ttk" is similar to above:

- first import the package "tkinter"
- then import the submodule "ttk" inside that package.

In other words:

- locate a directory called "tkinter", containing a file called
  "__init__.py"; this is the package;
- execute that file "tkinter/__init__.py" to create a module object
- create a local variable "tkinter" bound to that module object

- then locate the module or subpackage "ttk" inside that same 
  directory;
- execute that file "tkinter/ttk.py" (for example" to create a 
  module object;
- create a local variable "ttk" bound to that module object.



So you can see why this doesn't work:


import tkinter as tk
import tk.ttk as ttk


is looking for a directory on disk called "tk", which doesn't exist. The
name "tk" is only local to your code, it doesn't rename the directory on
disk.



The real import statement is much more complicated than this, but as a
simplified description, I hope this helps.


-- 
Steven

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


Re: troubleshooting

2016-04-04 Thread Steven D'Aprano
On Tue, 5 Apr 2016 02:03 am, Sk. Amirul Islam wrote:

> i recently installed the application but when i ran it it gave a 'runtime
> error". i even reinstalled it. but it gives the same error everytime i
> try. im eclosing a screenshot of the error . thank you

Hi. Which application are you talking about? If you mean Python, please tell
us exactly which version, where you downloaded it from, and most
importantly, what operating system and version you are using:

Linux, Mac OS X, Windows, FreeBSB, OpenBSB, Android, something else?

Which version of the OS?

A screenshot is of little or no use to us, I'm afraid. Firstly, that means
that people who are blind or visually impaired and are reading this using
screen-reader software cannot contribute. But more importantly, the
newsgroup is a "Text" newsgroup, not a "Binary" newsgroup, so attachments
are deleted.

Please copy and paste the text of the error, if you can. Otherwise, if it is
short, please retype it into your message. If it is too long to retype, you
can upload your screen shot to Imgur and then link to that.



-- 
Steven

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


Best Practices for Internal Package Structure

2016-04-04 Thread Josh B.
My package, available at https://github.com/jab/bidict, is currently laid out 
like this:

bidict/
├── __init__.py
├── _bidict.py
├── _common.py
├── _frozen.py
├── _loose.py
├── _named.py
├── _ordered.py
├── compat.py
├── util.py


I'd like to get some more feedback on a question about this layout that I 
originally asked here: 
:

What do you think of the code layout, specifically the use of the _foo modules? 
It seems well-factored to me, but I haven't seen things laid out this way very 
often in other projects, and I'd like to do this as nicely as possible.

It does kind of bug me that you see the _foo modules in the output when you do 
things like this:

>>> import bidict
>>> bidict.bidict

>>> bidict.KeyExistsError



In https://github.com/jab/bidict/pull/33#issuecomment-205381351 a reviewer 
agrees:

"""
Me too, and it confuses people as to where you should be importing things from 
if you want to catch it, inviting code like

```
import bidict._common

try:
...
except bidict._common.KeyExistsError:
...
```
ie. becoming dependent on the package internal structure.

I would be tempted to monkey-patch .__module__ = __name__ on each imported 
class to get around this. Maybe there are downsides to doing magic of that 
kind, but dependencies on the internals of packages are such a problem for me 
in our very large codebase, that I'd probably do it anyway in order to really 
explicit about what the public API is.
"""

Curious what folks on this list recommend, or if there are best practices about 
this published somewhere.

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


Re: Best Practices for Internal Package Structure

2016-04-04 Thread Sven R. Kunze

Hi Josh,

good question.

On 04.04.2016 18:47, Josh B. wrote:

My package, available at https://github.com/jab/bidict, is currently laid out 
like this:

bidict/
├── __init__.py
├── _bidict.py
├── _common.py
├── _frozen.py
├── _loose.py
├── _named.py
├── _ordered.py
├── compat.py
├── util.py


I'd like to get some more feedback on a question about this layout that I originally 
asked here: :

What do you think of the code layout, specifically the use of the _foo modules? 
It seems well-factored to me, but I haven't seen things laid out this way very 
often in other projects, and I'd like to do this as nicely as possible.

It does kind of bug me that you see the _foo modules in the output when you do 
things like this:
[code]


we had a similar discussion internally. We have various packages 
requiring each other but have some internals that should not be used 
outside of them.


The _ signifies that actually clearly but it looks weird within the 
package itself.


We haven't found a solution so far. Maybe others do.


Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Twisted 16.1 Release Announcement

2016-04-04 Thread Amber "Hawkie" Brown
On behalf of Twisted Matrix Laboratories, I am honoured to announce the release 
of Twisted 16.1!

This release is hot off the heels of 16.0 released last month, including some 
nice little tidbits. The highlights include:

- twisted.application.internet.ClientService, a service that maintains a 
persistent outgoing endpoint-based connection -- a replacement for 
ReconnectingClientFactory that uses modern APIs;
- A large (77% on one benchmark) performance improvement when using 
twisted.web's client on PyPy;
- A few conch modules have been ported to Python 3, in preparation for further 
porting of the SSH functionality;
- Full support for OpenSSL 1.0.2f and above;
- t.web.http.Request.addCookie now accepts Unicode and bytes keys/values;
- `twistd manhole` no longer uses a hard-coded SSH host key, and will generate 
one for you on the fly (this adds a 'appdirs' PyPI dependency, installing with 
[conch] will add it automatically);
- Over eighteen tickets overall closed since 16.0.

For more information, check the NEWS file (link provided below).

You can find the downloads at  (or 
alternatively ). The NEWS file is 
also available at .

Many thanks to everyone who had a part in this release - the supporters of the 
Twisted Software Foundation, the developers who contributed code as well as 
documentation, and all the people building great things with Twisted!

Twisted Regards,
Amber Brown (HawkOwl)


signature.asc
Description: Message signed with OpenPGP using GPGMail
-- 
https://mail.python.org/mailman/listinfo/python-list


Python programs and relative imports

2016-04-04 Thread Rob Gaddi
Does anyone know the history of why relative imports are only available
for packages and not for "programs"?  It certainly complicates life.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best Practices for Internal Package Structure

2016-04-04 Thread Michael Selik
On Mon, Apr 4, 2016 at 6:04 PM Sven R. Kunze  wrote:

> Hi Josh,
>
> good question.
>
> On 04.04.2016 18:47, Josh B. wrote:
> > My package, available at https://github.com/jab/bidict, is currently
> laid out like this:
> >
> > bidict/
> > ├── __init__.py
> > ├── _bidict.py
> > ├── _common.py
> > ├── _frozen.py
> > ├── _loose.py
> > ├── _named.py
> > ├── _ordered.py
> > ├── compat.py
> > ├── util.py
> >
> >
> > I'd like to get some more feedback on a question about this layout that
> I originally asked here: <
> https://github.com/jab/bidict/pull/33#issuecomment-193877248>:
> >
> > What do you think of the code layout, specifically the use of the _foo
> modules? It seems well-factored to me, but I haven't seen things laid out
> this way very often in other projects, and I'd like to do this as nicely as
> possible.
>

Using the _module.py convention for internals is fine, except that you have
few enough lines of code that you could have far fewer files. Why create a
package when you can just have a module, bidict.py?

I find it easier to find the right section of my code when I have just a
few files open rather than a dozen or so in different windows and tabs.
-- 
https://mail.python.org/mailman/listinfo/python-list


Request Help With Function

2016-04-04 Thread Wildman via Python-list
I am working on a Linux gui program where I want to be able
to click a Help button and open a man page using a viewer.
I wrote a search function that can be called several times,
if needed, with different arguments.  I wrote a test program
that tries to open the Bash man page in a terminal and will
display a message box if the search fails.  It passes the
system path, terminal emulators and command line arguments
to the search function.  I appears that you can't pass a list
to a function so I am passing the arguments as strings and then
converting them to lists for parsing in the search function.

When I run the test program, I get this error:

Traceback (most recent call last):
  File "./man.py", line 38, in 
launch_help()
  File "./man.py", line 10, in launch_help
if search(pathlist, executelist, commandlist):
  File "./man.py", line 27, in search
subprocess.Popen(command)
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
TypeError: execv() arg 2 must contain only strings

I have not been able to figure out why I'm getting the error.
Any help would be appreciated.  Below is the complete code for
the test program:

#!/usr/bin/env python

import os, subprocess, tkMessageBox

def launch_help():
pathlist = os.environ["PATH"]
executelist = "xvt,xfce4-terminal"
commandlist = "-e,man bash"
if search(pathlist, executelist, commandlist):
return None
message = "Open a terminal and enter:  man bash"
tkMessageBox.showinfo("Help", message)

def search(pathlist, executelist, commandlist):
pathlist = pathlist.split(":")
executelist = executelist.split(",")
commandlist = commandlist.split(",")
done = False
for path in pathlist:
for execute in executelist:
target = path + "/" + execute
if os.path.isfile(target):
done = True
command = [target, commandlist]
subprocess.Popen(command)
if done:
break
if done:
break
if done:
return True
else:
return False


launch_help()

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request Help With Function

2016-04-04 Thread Ian Kelly
On Mon, Apr 4, 2016 at 1:42 PM, Wildman via Python-list
 wrote:
> commandlist = commandlist.split(",")

commandlist is a list.

> command = [target, commandlist]
> subprocess.Popen(command)

This is passing a list containing two elements: the first is a string,
and the second is a list of strings. You should just pass a list of
strings. Probably you wanted to do this:

command = [target] + commandlist
-- 
https://mail.python.org/mailman/listinfo/python-list


How can I install

2016-04-04 Thread Mohamed Ali via Python-list

I have tried to install python and nltk but I couldn't. Please could you please 
help me because I need to work on natural language processing using Python.

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


Re: Request Help With Function

2016-04-04 Thread MRAB

On 2016-04-04 20:42, Wildman via Python-list wrote:

I am working on a Linux gui program where I want to be able
to click a Help button and open a man page using a viewer.
I wrote a search function that can be called several times,
if needed, with different arguments.  I wrote a test program
that tries to open the Bash man page in a terminal and will
display a message box if the search fails.  It passes the
system path, terminal emulators and command line arguments
to the search function.  I appears that you can't pass a list
to a function so I am passing the arguments as strings and then
converting them to lists for parsing in the search function.

When I run the test program, I get this error:

Traceback (most recent call last):
   File "./man.py", line 38, in 
 launch_help()
   File "./man.py", line 10, in launch_help
 if search(pathlist, executelist, commandlist):
   File "./man.py", line 27, in search
 subprocess.Popen(command)
   File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
 errread, errwrite)
   File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
 raise child_exception
TypeError: execv() arg 2 must contain only strings

I have not been able to figure out why I'm getting the error.
Any help would be appreciated.  Below is the complete code for
the test program:

#!/usr/bin/env python

import os, subprocess, tkMessageBox

def launch_help():
 pathlist = os.environ["PATH"]
 executelist = "xvt,xfce4-terminal"
 commandlist = "-e,man bash"
 if search(pathlist, executelist, commandlist):
 return None
 message = "Open a terminal and enter:  man bash"
 tkMessageBox.showinfo("Help", message)

def search(pathlist, executelist, commandlist):
 pathlist = pathlist.split(":")
 executelist = executelist.split(",")
 commandlist = commandlist.split(",")
 done = False
 for path in pathlist:
 for execute in executelist:
 target = path + "/" + execute
 if os.path.isfile(target):
 done = True
 command = [target, commandlist]
 subprocess.Popen(command)
 if done:
 break
 if done:
 break
 if done:
 return True
 else:
 return False


launch_help()


.Popen will accept either a string or a list of strings.

You're giving it a list that contains a string and a list.

BTW, I don't know what you mean by "you can't pass a list to a 
function", because you can. How were you trying to do it?


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


Re: How can I install

2016-04-04 Thread MRAB

On 2016-04-04 20:51, Mohamed Ali via Python-list wrote:


I have tried to install python and nltk but I couldn't. Please could you please 
help me because I need to work on natural language processing using Python.


You haven't given any details.

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


Re: Best Practices for Internal Package Structure

2016-04-04 Thread Mark Lawrence via Python-list

On 04/04/2016 19:45, Michael Selik wrote:

On Mon, Apr 4, 2016 at 6:04 PM Sven R. Kunze  wrote:


Hi Josh,

good question.

On 04.04.2016 18:47, Josh B. wrote:

My package, available at https://github.com/jab/bidict, is currently

laid out like this:


bidict/
├── __init__.py
├── _bidict.py
├── _common.py
├── _frozen.py
├── _loose.py
├── _named.py
├── _ordered.py
├── compat.py
├── util.py


I'd like to get some more feedback on a question about this layout that

I originally asked here: <
https://github.com/jab/bidict/pull/33#issuecomment-193877248>:


What do you think of the code layout, specifically the use of the _foo

modules? It seems well-factored to me, but I haven't seen things laid out
this way very often in other projects, and I'd like to do this as nicely as
possible.



Using the _module.py convention for internals is fine, except that you have
few enough lines of code that you could have far fewer files. Why create a
package when you can just have a module, bidict.py?

I find it easier to find the right section of my code when I have just a
few files open rather than a dozen or so in different windows and tabs.



+1

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


IDLE's subprocess didn't make connection. Either IDLE can't start or personal firewall software is blocking connection.

2016-04-04 Thread Steven Gao
I’m getting “IDLE's subprocess didn't make connection. Either IDLE can't start 
or personal firewall software is blocking connection.”. Any ideas?

Sent from Mail for Windows 10



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: module alias in import statement

2016-04-04 Thread Terry Reedy

On 4/4/2016 11:31 AM, ast wrote:

hello


import tkinter as tk
import tk.ttk as ttk


Traceback (most recent call last):
  File "", line 1, in 
import tk.ttk as ttk
ImportError: No module named 'tk'


of course


import tkinter.ttk as ttk


works

Strange, isn't it ?


Nope. As other said, 'import tkinter as tk' imports a module named 
'tkinter' and *in the importing modules, and only in the importing 
module*, binds the module to 'tk'.  It also caches the module in 
sys.modules under its real name, 'tkinter'.


>>> import tkinter as tk
>>> import sys
>>> 'tkinter' in sys.modules
True
>>> 'tk' in sys.modules
False

'import tk.ttk' looks for 'tk' in sys.modules, does not find it, looks 
for a module named 'tk' on disk, does not find it, and says so.


--
Terry Jan Reedy

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


Re: IDLE's subprocess didn't make connection. Either IDLE can't start or personal firewall software is blocking connection.

2016-04-04 Thread Mark Lawrence via Python-list

On 04/04/2016 21:19, Steven Gao wrote:

I’m getting “IDLE's subprocess didn't make connection. Either IDLE can't start 
or personal firewall software is blocking connection.”. Any ideas?

Sent from Mail for Windows 10



Asked and answered repeatedly, please search the archives for the answer.

--
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: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-04 Thread Ben Finney
"Loop.IO"  writes:

> You now seem to be on some sort of rampage

You've mis-interpreted Erik's attempts to help. Somehow the requests for
details have made you defensive; I'm not sure why. Erik certainly was
not being hostile to you.

Hopefully you can take a more dispassionate position when you ask the
volunteers here for help next time.

-- 
 \ “Education is learning what you didn't even know you didn't |
  `\  know.” —Daniel J. Boorstin, historian, 1914–2004 |
_o__)  |
Ben Finney

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


Re: IDLE's subprocess didn't make connection. Either IDLE can't start or personal firewall software is blocking connection.

2016-04-04 Thread Terry Reedy

On 4/4/2016 4:19 PM, Steven Gao wrote:

I’m getting “IDLE's subprocess didn't make connection. Either IDLE can't start 
or personal firewall software is blocking connection.”. Any ideas?


Depending on how you started, another possibility is a file in your 
local directory that masks a stdlib module.  Or a network (socket) 
configuration issue.



--
Terry Jan Reedy


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


Re: Plot/Graph

2016-04-04 Thread Muhammad Ali
On Sunday, April 3, 2016 at 5:19:15 PM UTC-7, MRAB wrote:
> On 2016-04-04 01:04, Muhammad Ali wrote:
> > On Sunday, April 3, 2016 at 2:35:58 PM UTC-7, Oscar Benjamin wrote:
> >> On 3 Apr 2016 22:21, "Muhammad Ali"  wrote:
> >> >
> >> >  How do I convert/change/modify python script so that my data could be
> >> extracted according to python script and at the end it generates another
> >> single extracted data file instead of displaying/showing some graph? So
> >> that, I can manually plot the newly generated file (after data extraction)
> >> by some other software like origin.
> >>
> >> It depends what you're computing and what format origin expects the data to
> >> be in. Presumably it can use CSV files so take a look at the CSV module
> >> which can write these.
> >>
> >> (You'll get better answers to a question like this if you show us some code
> >> and ask a specific question about how to change it.)
> >>
> >> --
> >> Oscar
> >
> > How could the python script be modified to generate data file rather than 
> > display a plot by using matplotlib?
> >
> >
> > def make_plot(plot):
> >  indent = plot.plot_options.indent
> >  args = plot.plot_options.args
> >  # Creating the plot
> >  print ('Generating the plot...')
> >  fig = 
> > plt.figure(figsize=(plot.fig_width_inches,plot.fig_height_inches))
> >  ax = fig.add_subplot(111)
> >  # Defining the color schemes.
> >  print (indent + '>>> Using the "' + plot.cmap_name + '" colormap.')
> >  if(plot.plot_options.using_default_cmap and not args.running_from_GUI):
> >  print (2 * indent + 'Tip: You can try different colormaps by 
> > either:')
> >  print (2 * indent + ' * Running the plot tool with the option 
> > -icmap n, ' \
> > 'with n in the range from 0 to', 
> > len(plot.plot_options.cmaps) - 1)
> >  print (2 * indent + ' * Running the plot tool with the option 
> > "-cmap cmap_name".')
> >  print (2 * indent + '> Take a look at')
> >  print (4 * indent + 
> > '')
> >  print (2 * indent + '  for a list of colormaps, or run')
> >  print (4 * indent + '"./plot_unfolded_EBS_BandUP.py --help".')
> >
> >  # Building the countour plot from the read data
> >  # Defining the (ki,Ej) grid.
> >  if(args.interpolation is not None):
> >  ki = np.linspace(plot.kmin, plot.kmax, 2 * 
> > len(set(plot.KptsCoords)) + 1, endpoint=True)
> >  Ei = np.arange(plot.emin, plot.emax + plot.dE_for_hist2d, 
> > plot.dE_for_hist2d)
> >  # Interpolating
> >  grid_freq = griddata((plot.KptsCoords, plot.energies), 
> > plot.delta_Ns, (ki[None,:], Ei[:,None]),
> >   method=args.interpolation, fill_value=0.0)
> >  else:
> >  ki = np.unique(np.clip(plot.KptsCoords, plot.kmin, plot.kmax))
> >  Ei = np.unique(np.clip(plot.energies, plot.emin,  plot.emax))
> >  grid_freq = griddata((plot.KptsCoords, plot.energies), 
> > plot.delta_Ns, (ki[None,:], Ei[:,None]),
> >   method='nearest', fill_value=0.0)
> >
> >  if(not args.skip_grid_freq_clip):
> >  grid_freq = grid_freq.clip(0.0) # Values smaller than zero are 
> > just noise.
> >  # Normalizing and building the countour plot
> >  manually_normalize_colorbar_min_and_maxval = False
> >  if((args.maxval_for_colorbar is not None) or (args.minval_for_colorbar 
> > is not None)):
> >  manually_normalize_colorbar_min_and_maxval = True
> >  args.disable_auto_round_vmin_and_vmax = True
> >  maxval_for_colorbar = args.maxval_for_colorbar
> >  minval_for_colorbar = args.minval_for_colorbar
> >  else:
> >  if not args.disable_auto_round_vmin_and_vmax:
> >  minval_for_colorbar = float(round(np.min(grid_freq)))
> >  maxval_for_colorbar = float(round(np.max(grid_freq)))
> >  args.round_cb = 0
> >  if(manually_normalize_colorbar_min_and_maxval or not 
> > args.disable_auto_round_vmin_and_vmax):
> >  modified_vmin_or_vmax = False
> >  if not args.disable_auto_round_vmin_and_vmax and not 
> > args.running_from_GUI:
> >  print (plot.indent + '* Automatically renormalizing color 
> > scale '\
> > '(you can disable this with the option 
> > --disable_auto_round_vmin_and_vmax):')
> >  if manually_normalize_colorbar_min_and_maxval:
> >  print (plot.indent + '* Manually renormalizing color scale')
> >  if(minval_for_colorbar is not None):
> >  previous_vmin = np.min(grid_freq)
> >  if(abs(previous_vmin - minval_for_colorbar) >= 0.1):
> >  modified_vmin_or_vmax = True
> >  print (2 * indent + 'Previous vmin = %.1f, new vmin = 
> > %.1f' % (previous_vmin,
> >  

From email addresses sometimes strange on this list - was Re: [beginner] What's wrong?

2016-04-04 Thread Michael Torrie
On 04/04/2016 08:04 AM, Mark Lawrence via Python-list wrote:
> On 02/04/2016 23:49, Michael Torrie wrote:
>> Mark, your messages are showing up to the list as being from "python,"
>> at least on my email.  Any reason for this?
>>
> 
> Assuming that you're referring to me, frankly I haven't a clue.  I read 
> this list with Thunderbird on Windows, I hit "reply" to something, I 
> type, I hit "send", job done.  Thereafter, as far as I'm concerned, a 
> miracle occurs and hundreds if not thousands of subscribers get to see 
> my reply.

Interesting.  The problem is definitely not on your end at all, though I
first noticed this with your recent posts. Other posts are showing up a
bit weirdly too.  The problem appears to be partly in my Thunderbird
client, and partly the mailing list gateway.  And maybe Gmail is
screwing things up too. Usenet-orginating posts look fine.  For example:

From: Marko Rauhamaa 
Newsgroups: comp.lang.python

Whereas email ones are sometimes looking like this:

From: Mark Lawrence via Python-list 
Reply-To: Mark Lawrence 

Thunderbird on my machine is only seeing the From email address
(python-list@python.org) and I must have that in my address list
somewhere as "python."

What's odder is that my own messages show up as "From:
torr...@gmail.com" and not "via Python-list ".



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


Re: From email addresses sometimes strange on this list - was Re: [beginner] What's wrong?

2016-04-04 Thread Chris Angelico
On Tue, Apr 5, 2016 at 8:55 AM, Michael Torrie  wrote:
> Usenet-orginating posts look fine.  For example:
>
> From: Marko Rauhamaa 
> Newsgroups: comp.lang.python
>
> Whereas email ones are sometimes looking like this:
>
> From: Mark Lawrence via Python-list 
> Reply-To: Mark Lawrence 

O That probably explains it. It's because of Yahoo and mailing
lists. Yahoo did stuff that breaks stuff, so Mailman breaks stuff
differently to make sure that only Yahoo people get messed up a bit.
It means their names and addresses get slightly obscured, but delivery
works.

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


Re: From email addresses sometimes strange on this list - was Re: [beginner] What's wrong?

2016-04-04 Thread Michael Torrie
On 04/04/2016 04:58 PM, Chris Angelico wrote:
> O That probably explains it. It's because of Yahoo and mailing
> lists. Yahoo did stuff that breaks stuff, so Mailman breaks stuff
> differently to make sure that only Yahoo people get messed up a bit.
> It means their names and addresses get slightly obscured, but delivery
> works.

That explains it! The other folks with messages like that are coming
from Yahoo as well.  I can live with it.

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


testing python program,project and django site

2016-04-04 Thread Xristos Xristoou
hello,

i am python user and i have some projects,programs and sites with django
in python.
i want one more step deeper,i want to test my programs for
bugs,weaknesses,vulnerability,security or penetration test,on my sites for 
crashes(because use python apps).because the user i am now on the feature maybe 
i have thousand users to work with my programs.
can you tell me how to find this?some propram to do that or some for that ?
some method to do that?
some program to testing the programs?

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


Re: Plot/Graph

2016-04-04 Thread MRAB

On 2016-04-04 23:35, Muhammad Ali wrote:

On Sunday, April 3, 2016 at 5:19:15 PM UTC-7, MRAB wrote:

On 2016-04-04 01:04, Muhammad Ali wrote:
> On Sunday, April 3, 2016 at 2:35:58 PM UTC-7, Oscar Benjamin wrote:
>> On 3 Apr 2016 22:21, "Muhammad Ali"  wrote:
>> >
>> >  How do I convert/change/modify python script so that my data could be
>> extracted according to python script and at the end it generates another
>> single extracted data file instead of displaying/showing some graph? So
>> that, I can manually plot the newly generated file (after data extraction)
>> by some other software like origin.
>>
>> It depends what you're computing and what format origin expects the data to
>> be in. Presumably it can use CSV files so take a look at the CSV module
>> which can write these.
>>
>> (You'll get better answers to a question like this if you show us some code
>> and ask a specific question about how to change it.)
>>
>> --
>> Oscar
>
> How could the python script be modified to generate data file rather than 
display a plot by using matplotlib?
>
>
> def make_plot(plot):
>  indent = plot.plot_options.indent
>  args = plot.plot_options.args
>  # Creating the plot
>  print ('Generating the plot...')
>  fig = plt.figure(figsize=(plot.fig_width_inches,plot.fig_height_inches))
>  ax = fig.add_subplot(111)
>  # Defining the color schemes.
>  print (indent + '>>> Using the "' + plot.cmap_name + '" colormap.')
>  if(plot.plot_options.using_default_cmap and not args.running_from_GUI):
>  print (2 * indent + 'Tip: You can try different colormaps by 
either:')
>  print (2 * indent + ' * Running the plot tool with the option 
-icmap n, ' \
> 'with n in the range from 0 to', len(plot.plot_options.cmaps) 
- 1)
>  print (2 * indent + ' * Running the plot tool with the option "-cmap 
cmap_name".')
>  print (2 * indent + '> Take a look at')
>  print (4 * indent + 
'')
>  print (2 * indent + '  for a list of colormaps, or run')
>  print (4 * indent + '"./plot_unfolded_EBS_BandUP.py --help".')
>
>  # Building the countour plot from the read data
>  # Defining the (ki,Ej) grid.
>  if(args.interpolation is not None):
>  ki = np.linspace(plot.kmin, plot.kmax, 2 * len(set(plot.KptsCoords)) 
+ 1, endpoint=True)
>  Ei = np.arange(plot.emin, plot.emax + plot.dE_for_hist2d, 
plot.dE_for_hist2d)
>  # Interpolating
>  grid_freq = griddata((plot.KptsCoords, plot.energies), 
plot.delta_Ns, (ki[None,:], Ei[:,None]),
>   method=args.interpolation, fill_value=0.0)
>  else:
>  ki = np.unique(np.clip(plot.KptsCoords, plot.kmin, plot.kmax))
>  Ei = np.unique(np.clip(plot.energies, plot.emin,  plot.emax))
>  grid_freq = griddata((plot.KptsCoords, plot.energies), 
plot.delta_Ns, (ki[None,:], Ei[:,None]),
>   method='nearest', fill_value=0.0)
>
>  if(not args.skip_grid_freq_clip):
>  grid_freq = grid_freq.clip(0.0) # Values smaller than zero are just 
noise.
>  # Normalizing and building the countour plot
>  manually_normalize_colorbar_min_and_maxval = False
>  if((args.maxval_for_colorbar is not None) or (args.minval_for_colorbar 
is not None)):
>  manually_normalize_colorbar_min_and_maxval = True
>  args.disable_auto_round_vmin_and_vmax = True
>  maxval_for_colorbar = args.maxval_for_colorbar
>  minval_for_colorbar = args.minval_for_colorbar
>  else:
>  if not args.disable_auto_round_vmin_and_vmax:
>  minval_for_colorbar = float(round(np.min(grid_freq)))
>  maxval_for_colorbar = float(round(np.max(grid_freq)))
>  args.round_cb = 0
>  if(manually_normalize_colorbar_min_and_maxval or not 
args.disable_auto_round_vmin_and_vmax):
>  modified_vmin_or_vmax = False
>  if not args.disable_auto_round_vmin_and_vmax and not 
args.running_from_GUI:
>  print (plot.indent + '* Automatically renormalizing color scale 
'\
> '(you can disable this with the option 
--disable_auto_round_vmin_and_vmax):')
>  if manually_normalize_colorbar_min_and_maxval:
>  print (plot.indent + '* Manually renormalizing color scale')
>  if(minval_for_colorbar is not None):
>  previous_vmin = np.min(grid_freq)
>  if(abs(previous_vmin - minval_for_colorbar) >= 0.1):
>  modified_vmin_or_vmax = True
>  print (2 * indent + 'Previous vmin = %.1f, new vmin = %.1f' 
% (previous_vmin,
>   
  minval_for_colorbar))
>  else:
>  minval_for_colorbar = np.min(grid_freq)
>  if(maxval_for_colorbar is not None):
>  previous_vmax = np.max(grid_fr

Re: Plot/Graph

2016-04-04 Thread Muhammad Ali
On Sunday, April 3, 2016 at 2:35:58 PM UTC-7, Oscar Benjamin wrote:
> On 3 Apr 2016 22:21, "Muhammad Ali"  wrote:
> >
> >  How do I convert/change/modify python script so that my data could be
> extracted according to python script and at the end it generates another
> single extracted data file instead of displaying/showing some graph? So
> that, I can manually plot the newly generated file (after data extraction)
> by some other software like origin.
> 
> It depends what you're computing and what format origin expects the data to
> be in. Presumably it can use CSV files so take a look at the CSV module
> which can write these.
> 
> (You'll get better answers to a question like this if you show us some code
> and ask a specific question about how to change it.)
> 
> --
> Oscar

Yes, it is complete script and it works well with matplotlib.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request Help With Function

2016-04-04 Thread Wildman via Python-list
On Mon, 04 Apr 2016 13:54:56 -0600, Ian Kelly wrote:

> On Mon, Apr 4, 2016 at 1:42 PM, Wildman via Python-list
>  wrote:
>> commandlist = commandlist.split(",")
> 
> commandlist is a list.
> 
>> command = [target, commandlist]
>> subprocess.Popen(command)
> 
> This is passing a list containing two elements: the first is a string,
> and the second is a list of strings. You should just pass a list of
> strings. Probably you wanted to do this:
> 
> command = [target] + commandlist

Thank you, that fixed the problem.  It did occur to me that the
problem was in how "command" was put together but I wasn't sure.
A rookie mistake from a rookie.  Whoda thunk it?

-- 
 GNU/Linux user #557453
Why is it that all instruments seeking intelligent
life in the universe are pointed away from Earth?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request Help With Function

2016-04-04 Thread Wildman via Python-list
On Mon, 04 Apr 2016 21:02:53 +0100, MRAB wrote:

> On 2016-04-04 20:42, Wildman via Python-list wrote:



>> launch_help()
>>
> .Popen will accept either a string or a list of strings.
> 
> You're giving it a list that contains a string and a list.

Yep, that was my foolish mistake.  Thanks.

> BTW, I don't know what you mean by "you can't pass a list to a 
> function", because you can. How were you trying to do it?

The above mistake I made caused me to get a similar error
when I tried to pass the arguments as lists.  I made an
assumption that I should have not made.  After making
the correction Mr. Kelly suggested, I was able to rewrite
the code that way I had it (with the correction), passing
the arguments as lists and it works correctly.

The learning process continues... Thanks again.

-- 
 GNU/Linux user #557453
"Philosophy is common sense with big words."
  -James Madison
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Plot/Graph

2016-04-04 Thread Muhammad Ali
On Tuesday, April 5, 2016 at 8:16:22 AM UTC+8, Muhammad Ali wrote:
> On Sunday, April 3, 2016 at 2:35:58 PM UTC-7, Oscar Benjamin wrote:
> > On 3 Apr 2016 22:21, "Muhammad Ali"  wrote:
> > >
> > >  How do I convert/change/modify python script so that my data could be
> > extracted according to python script and at the end it generates another
> > single extracted data file instead of displaying/showing some graph? So
> > that, I can manually plot the newly generated file (after data extraction)
> > by some other software like origin.
> > 
> > It depends what you're computing and what format origin expects the data to
> > be in. Presumably it can use CSV files so take a look at the CSV module
> > which can write these.
> > 
> > (You'll get better answers to a question like this if you show us some code
> > and ask a specific question about how to change it.)
> > 
> > --
> > Oscar
> 
> Yes, it is complete script and it works well with matplotlib.

But I have to modify it to extract data into a single .dat file instead of 
directly plotting it by using matplotlib. I want to plot the data file in some 
other software.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best Practices for Internal Package Structure

2016-04-04 Thread Steven D'Aprano
On Tue, 5 Apr 2016 02:47 am, Josh B. wrote:

> My package, available at https://github.com/jab/bidict, is currently laid
> out like this:
> 
> bidict/
> ├── __init__.py
> ├── _bidict.py
> ├── _common.py
> ├── _frozen.py
> ├── _loose.py
> ├── _named.py
> ├── _ordered.py
> ├── compat.py
> ├── util.py


The purpose of packages isn't enable Java-style "one class per file" coding,
especially since *everything* in the package except the top level "bidict"
module itself is private. bidict.compat and bidict.util aren't flagged as
private, but they should be, since there's nothing in either of them that
the user of a bidict class should care about.

(utils.py does export a couple of functions, but they should be in the main
module, or possibly made into a method of BidirectionalMapping.)

Your package is currently under 500 lines. As it stands now, you could
easily flatten it to a single module:

bidict.py

Unless you are getting some concrete benefit from a package structure, you
shouldn't use a package just for the sake of it. Even if the code doubles
in size, to 1000 lines, that's still *far* below the point at which I
believe a single module becomes unwieldy just from size. At nearly 6500
lines, the decimal.py module is, in my opinion, *almost* at the point where
just size alone suggests splitting the file into submodules. Your module is
nowhere near that point.

It seems to me that you're paying the cost of the increased complexity
needed to handle a package, but not (as far as I can tell) gaining any
benefit from it. Certainly the *users* of your package aren't: all the
public classes are pre-imported by the __init__.py file, so they don't even
get the advantage of only needing to import classes that they actually use. 

So my recommendation would be to collapse the package to a single file.

If you choose to reject that recommendation, or perhaps you are getting some
benefit that I haven't spotted in a cursory look over the package, then my
suggestion is to document that the *only* public interface is the
top-level "import bidict", and that *all* submodules are private. Then drop
the underscores, possibly re-arrange a bit:


bidict/
├── __init__.py  # the only public part of the package
├── bidict.py
├── common.py  # includes compat and util
├── frozen.py
├── loose.py
├── named.py
├── ordered.py


If you're worried about the lack of underscores for private submodules, then
consider this alternate structure:


_bidict/
├── __init__.py
├── bidict.py
├── common.py
├── frozen.py
├── loose.py
├── named.py
├── ordered.py
bidict.py


where "bidict.py" is effectively little more than:

from _bidict import *



> What do you think of the code layout, specifically the use of the _foo
> modules? It seems well-factored to me, but I haven't seen things laid out
> this way very often in other projects, and I'd like to do this as nicely
> as possible.

It's very pretty, and well-organised, but I'm not sure you're actually
gaining any advantage from it.


> It does kind of bug me that you see the _foo modules in the output when
> you do things like this:
> 
 import bidict
 bidict.bidict
> 
 bidict.KeyExistsError
> 
> 
> 
> In https://github.com/jab/bidict/pull/33#issuecomment-205381351 a reviewer
> agrees:
> 
> """
> Me too, and it confuses people as to where you should be importing things
> from if you want to catch it, inviting code like
> 
> ```
> import bidict._common


That, at least, should be an obvious no-no, as it's including a single
underscore private name. I wouldn't worry about that too much: if your
users are so naive or obnoxious that they're ignoring your documentation
and importing _private modules, there's nothing you can do: they'll find
*some* way to shoot themselves in the foot, whatever you do.

[Aside: my devs at work had reason to look inside a script written by one of
their now long-moved away former colleagues yesterday, as it recently
broke. After reading the script, the *first* thing they did was change the
way it was called from:

scriptname --opts steve
# yes, he really did use my name as the mandatory argument to the script

to

scriptname --opts forfucksakeandrew

where the name "andrew" has been changed to protect the guilty. Using my
name as the script argument is, apparently, the *least* stupid thing the
script does.]


> try:
> ...
> except bidict._common.KeyExistsError:
> ...
> ```
> ie. becoming dependent on the package internal structure.
> 
> I would be tempted to monkey-patch .__module__ = __name__ on each imported
> class to get around this. Maybe there are downsides to doing magic of that
> kind, but dependencies on the internals of packages are such a problem for
> me in our very large codebase, that I'd probably do it anyway in order to
> really explicit about what the public API is. """

Does his team not do internal code reviews? I hate code that lies about
where it comes from. I certainly wouldn't do it in a futile attempt to
protect idiots from themselves.

Re: Plot/Graph

2016-04-04 Thread Steven D'Aprano
On Tue, 5 Apr 2016 08:33 am, Muhammad Ali wrote:

[couple of hundred lines of quoted text]

[followed by about a thousand lines of code]

Seriously? Do you really expect people to read through hundreds of lines of
quotes, going at least three levels > > > deep, and then read a thousand
lines of code, to do your work for you? For free?

We try to be friendly and helpful, but there are limits. Please read this
before replying:

http://www.sscce.org/


Thank you.


-- 
Steven

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


Re: How can I install

2016-04-04 Thread Steven D'Aprano
On Tue, 5 Apr 2016 05:51 am, Mohamed Ali wrote:

> 
> I have tried to install python and nltk but I couldn't. Please could you
> please help me because I need to work on natural language processing using
> Python.

There are about ten thousand different things that could be going wrong, "I
couldn't install" doesn't give us any of narrowing the problems down. We
can't read your mind. You have to tell us what you did and what went wrong.

What operating system are you using? Linux, Mac OS, Windows, FreeBSD,
OpenBSD, Android, something else? What version?

How did you try to install the packages? What did you do? Did the
installation appear to work? Was there a problem? Did the computer print an
error message, or crash, or BSOD? Catch fire?

If you get an error message, COPY and PASTE the error, in full. Don't
summarise, and especially don't retype it from memory. Don't send a
screen-shot: people won't be able to see it.

If the error message has been localised into some language other than
English, please provide the original error, and a translation into English,
if you can.

What happened when you try to run Python? How are you running it?

- type "python" into a command shell?

- double-click an icon on the desktop?

- choose "Python" from the Start menu?

- something else?


The more detail you can give, the better the chances we can help you. If you
give no detail, we can give no help.



-- 
Steven

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


Launcher for 64 bits doesnt work

2016-04-04 Thread Gustaf Nilsson
Hi!

The only 3.5.1 versio that works for me is the 32 bits version, will it be
a problem to use the 32 bits version for 64 bits computer?
-- 
https://mail.python.org/mailman/listinfo/python-list


Trouble trying to install Python 3.5.1 (32-bit) for windows

2016-04-04 Thread Yuri Armellei
Dear Python,

I  encountered difficulties when installing  the python.

Could you guys help me to solve and install it?!

Attached log error  to  help you guys to help me out. =)  ;)

Regards,



[cid:image001.png@01D18EA7.4A69B7E0]


[cid:image006.jpg@01D152DC.ACCAF540]

Yuri Armellei
Tesouraria
Tel.: +55 11 3034-5004 - Cel.: (11) 9.9916-8323
www.casadocredito.com.br

Av. Queiroz Filho, 1700 - Torre E - 9º. andar - conj. 907
Vila Hamburguesa - São Paulo - SP - Brasil - 05319-000



Este e-mail e qualquer documento anexo ao mesmo é destinado somente às pessoas 
elencadas acima, podendo conter informações confidenciais e ou legalmente 
privilegiadas. Se você não for um dos destinatários do presente e-mail e seus 
anexos, por meio do presente toma ciência que sua disseminação, distribuição ou 
cópia é estritamente proibida. Se tiver recebido este e-mail e seus anexos por 
engano, agradeço comunicação imediata através do telefone (11) 3034-5004 e 
exclusão permanente do original e de qualquer cópia ou impressão que tenha sido 
realizada.

This e-mail and any attachments thereto, are intended only for use by the 
addresses named herein and may contain legally privileged and or confidential 
information. If you are not the intended recipient of this e-mail, you are 
hereby notified that any dissemination, distribution or copying of this e-mail, 
and any attachments thereto, is strictly prohibited. If you have received this 
e-mail in error, please immediately notify me at +55(11) 3034-5004 and 
permanently delete the original and any copy of any e-mail and any printout 
thereof.

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


Re: Launcher for 64 bits doesnt work

2016-04-04 Thread Zachary Ware
Hi Gustaf,

On Mon, Apr 4, 2016 at 9:38 PM, Gustaf Nilsson
 wrote:
> Hi!
>
> The only 3.5.1 versio that works for me is the 32 bits version, will it be
> a problem to use the 32 bits version for 64 bits computer?

>From your mention of a 'launcher' I'm assuming you're on Windows.
It's perfectly fine to use 32-bit Python on 64-bit Windows.  However,
how exactly does the launcher for the 64-bit version not work?  What
happens?  What did you expect to happen that didn't?  What error
message do you get?  It's entirely possible that your version of
Windows is in fact 32-bit, even though the computer itself has a
64-bit processor.

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: module alias in import statement

2016-04-04 Thread Rustom Mody
On Tuesday, April 5, 2016 at 2:17:24 AM UTC+5:30, Terry Reedy wrote:
> On 4/4/2016 11:31 AM, ast wrote:
> > hello
> >
>  import tkinter as tk
>  import tk.ttk as ttk
> >
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > import tk.ttk as ttk
> > ImportError: No module named 'tk'
> >
> >
> > of course
> >
>  import tkinter.ttk as ttk
> >
> > works
> >
> > Strange, isn't it ?
> 
> Nope. As other said, 'import tkinter as tk' imports a module named 
> 'tkinter' and *in the importing modules, and only in the importing 
> module*, binds the module to 'tk'.  It also caches the module in 
> sys.modules under its real name, 'tkinter'.
> 
>  >>> import tkinter as tk
>  >>> import sys
>  >>> 'tkinter' in sys.modules
> True
>  >>> 'tk' in sys.modules
> False
> 
> 'import tk.ttk' looks for 'tk' in sys.modules, does not find it, looks 
> for a module named 'tk' on disk, does not find it, and says so.

A well-known quote comes to mind:

| There are only two hard things in Computer Science: cache invalidation and
| naming things.

eg. http://martinfowler.com/bliki/TwoHardThings.html

particularly since this seems to be in both categories :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Launcher for 64 bits doesnt work

2016-04-04 Thread Gustaf
Thsnk you for your response, the pip installer doesnt work, only for the 
launcher for 32 bits. 

But my mainproblem is that I cant connect pygresql. I can download the package 
but after it says that it cant find the module

Enviado desde mi iPhone

> El 4 apr 2016, a las 22:39, Zachary Ware  
> escribió:
> 
> Hi Gustaf,
> 
> On Mon, Apr 4, 2016 at 9:38 PM, Gustaf Nilsson
>  wrote:
>> Hi!
>> 
>> The only 3.5.1 versio that works for me is the 32 bits version, will it be
>> a problem to use the 32 bits version for 64 bits computer?
> 
> From your mention of a 'launcher' I'm assuming you're on Windows.
> It's perfectly fine to use 32-bit Python on 64-bit Windows.  However,
> how exactly does the launcher for the 64-bit version not work?  What
> happens?  What did you expect to happen that didn't?  What error
> message do you get?  It's entirely possible that your version of
> Windows is in fact 32-bit, even though the computer itself has a
> 64-bit processor.
> 
> Hope this helps,
> -- 
> Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Launcher for 64 bits doesnt work

2016-04-04 Thread Ben Finney
Gustaf  writes:

> Enviado desde mi iPhone

Perhaps you could wait until you're at a better computer for
corresponding, and compose messages with more information to work out
what's happening.

-- 
 \  “Contentment is a pearl of great price, and whosoever procures |
  `\it at the expense of ten thousand desires makes a wise and |
_o__)  happy purchase.” —J. Balguy |
Ben Finney

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


Re: Trouble trying to install Python 3.5.1 (32-bit) for windows

2016-04-04 Thread Rustom Mody
On Tuesday, April 5, 2016 at 8:19:44 AM UTC+5:30, Yuri Armellei wrote:
> Dear Python,
> 
> I  encountered difficulties when installing  the python.
> 
> Could you guys help me to solve and install it?!
> 
> Attached log error  to  help you guys to help me out. =)  ;)
> 
> Regards,
> 
> 
> 
> [cid:image001.png@01D18EA7.4A69B7E0]
> 
> 
> [cid:image006.jpg@01D152DC.ACCAF540]
> 
> Yuri Armellei

Images dont get through this list -- sorry -- text only.
Please cut paste the error as inline text and mail again.

And while you are at it give this info also
- Which OS
- Which installer did you try
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: module alias in import statement

2016-04-04 Thread Chris Angelico
On Tue, Apr 5, 2016 at 2:08 PM, Rustom Mody  wrote:
>> 'import tk.ttk' looks for 'tk' in sys.modules, does not find it, looks
>> for a module named 'tk' on disk, does not find it, and says so.
>
> A well-known quote comes to mind:
>
> | There are only two hard things in Computer Science: cache invalidation and
> | naming things.
>
> eg. http://martinfowler.com/bliki/TwoHardThings.html
>
> particularly since this seems to be in both categories :-)

sys.modules isn't really a cache in that sense, though. The "hard
problem" of cache invalidation comes from the fundamental assumption
that a cache hit should be semantically identical to a cache miss;
Python's import system has fundamentally different semantics,
specifically that modules can exist independently of anything on the
disk, and modules are guaranteed to be singletons - which means that
"import decimal; decimal.getcontext().prec = 50" will affect anyone
else who uses the decimal module, because there can't be a duplicate.
(The one exception to this, where __main__ gets reimported under
another name, causes significant confusion despite being extremely
uncommon.)

If you like, you can look at sys.modules as a mandatory cache that
never records negatives and always records positives. Once an import
has succeeded, it will always be resolved from the cache, until
program termination; failed imports will always be retried. Python
dodges the cache invalidation problem by never invalidating anything
:)

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


Re: module alias in import statement

2016-04-04 Thread Rustom Mody
On Tuesday, April 5, 2016 at 9:53:30 AM UTC+5:30, Chris Angelico wrote:
> On Tue, Apr 5, 2016 at 2:08 PM, Rustom Mody  wrote:
> >> 'import tk.ttk' looks for 'tk' in sys.modules, does not find it, looks
> >> for a module named 'tk' on disk, does not find it, and says so.
> >
> > A well-known quote comes to mind:
> >
> > | There are only two hard things in Computer Science: cache invalidation and
> > | naming things.
> >
> > eg. http://martinfowler.com/bliki/TwoHardThings.html
> >
> > particularly since this seems to be in both categories :-)
> 
> sys.modules isn't really a cache in that sense, though. The "hard
> problem" of cache invalidation comes from the fundamental assumption
> that a cache hit should be semantically identical to a cache miss;

Following looks like a cache miss to me (certainly did to the OP):

On Monday, April 4, 2016 at 9:01:41 PM UTC+5:30, ast wrote:
> hello
> 
> >>> import tkinter as tk
> >>> import tk.ttk as ttk
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> import tk.ttk as ttk
> ImportError: No module named 'tk'
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-04 Thread Nagy László Zsolt

> I don't know if I like it being immutable. Maybe have separate mutable
> and immutable versions.
The reason for making it immutable is implementation specific. These
intervals are stored in an ordered list. Overlapping intervals are
unified by the constructor. This makes sure that sets with equal
elements are represented equally, and makes it possible to hash the set.
Comparing them by these hashes is fast and easy.

If you want to manipulate an interval set, you cannot just "add another
interval" to it. Adding an interval may result in unifying thousands of
other intervals. It is possible that you add a wide interval to a set
with 1000 elements, and as a result the set will have only a single
element.
> Like I said before, I don't think the set-like operations on Intervals
> are useful - what can you accomplish with them rather than by making a
> set consisting of only one interval and doing operations on that?
Well, then don't use them. I believe that the intersection of two
intervals is especially useful. Easy to check if two intervals have a
common non-empty part or not. You can also check this with a condition,
but that condition is a long one.
 element ::= (start_point_in_time, end_point_in_time)
 intervalset ::= { element1, element2,  }
>>> Are these open intervals or closed intervals?
>> Closed. In my particular implementation, there is a singleton for all
>> empty intervals. It is not possible to create an arbitrary interval with
>> the same starting and ending time (the singleton being the only
>> exception).
> An "arbitrary interval with the same starting and ending time" would be
> more like an isolated datetime (i.e. 00:00 is in the set but 23:59 or
> 00:01 is not)
Yes, that is true. Again: my task was to represent non-empty intervals.
We can say that a zero sized closed interval is also a special interval
that identifies a single point of time. Since the base class has been
rewritten to support any ordered type, it makes sense. Probably this is
a good idea to do. There are applications where the user is not
interested in zero sized intervals. For example, if you want to store
the working time of an employee then obviously you don't want to store
zero sized intervals.

How about creating two classes for this? One that supports zero sized
intervals, and another that doesn't?
Or maybe create a method that removes all zero sized intervals?
>> I think that implementing open intervals would be much more
>> difficult, and we would have to know and use the smallest possible
>> increment (resolution) of the date/time type. Which may be platform
>> dependent.
> My suggestion was to use boolean flags, and to use that to control
> whether to use < or <= to test for membership.
>
> An open interval is more like an hour where 00:00 is included and
> 00:59:59.99 is included but 01:00 is not. With discrete resolution
> it's as simple as just moving the endpoint off by one unit, but I think
> it'd be cleaner to use flags (you'd need it for numeric intervals, since
> numeric types can have any resolution).
Well, here is the problem: floats, ints, decimals and datetimes are all
ordered types. But they all have a different resolution, and some of
them are implementation dependent. We must know and use the smallest
resolution, even if we use boolean flags to denote openness. For
example: if we use integer values, then the closed interval [1,9] is
equal to the open interval (0,10) or the left-open interval (0,10]. We
want to be able to compare them, so we must know the resolution! If we
stay at the generalized form of the class that can be used on any
ordered type, then we cannot avoid using the concept of the "resolution
of the type". Here are the choices:

  * Use boolean flags to denote openness:
  o We do not support testing for interval equality - I think that
missing this fundamental operator would make the implementation
useless.
  o Support testing for internal equality - this requires knowledge
about the smallest resolution, so in this case using flags to
denote openness makes it possible to represent the same interval
in 4 different ways! (left opened/closed, right opened/closed).
I think this is also a bad idea.
  o We may have an agreement about how we should represent certain
intervals from the 4 different possible opportunities, but the
simplest way would be to always store them as closed intervals -
which makes these boolean flags unneccessary
  * Do not use boolean flags to denote openness - I don't see any
problem here.


I think the problem is that you are thinking the mathematical way, where
an open interval can never be equal to a closed interval. I was thinking
the IT way, where everything is represented with bits, and the "open
interval" is just a concept that always has a biggest and a smallest
possible value.

I'm not saying that your suggestion is wrong. I'm just saying that it
raises