NUMPY Installation Win7 Intel MKL

2014-12-10 Thread wolosonovich
Hello!

Hopefully some of you can help me out. I am having the hardest time installing 
Numpy using the Intel MKL library. I've read the Intel article on their site, 
but it doesn't specifically address Windows, so I suspect the directions get me 
close, but when it comes to this sort of thing, everything has to be correct. I 
can't find anything elsewhere on the net either specifically for Windows 7 and 
MKL. Any help would be appreciated. Thanks!

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


generating PDF or EPUB, which ?

2014-12-10 Thread Mohsen Pahlevanzadeh

  
  
Dear all,

I need to create an RTL (Right To Left) documentation, with
python.But i don't know which library to use.Which support RTL and
etc.

If you any experience with pdf generating or EPUB generating please
share me

--Regards
Mohsen
  

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


Re: Nested loops is strangely slow, totally at a loss.

2014-12-10 Thread Peter Otten
Ian Kelly wrote:

> On Tue, Dec 9, 2014 at 11:30 PM, Chris Angelico  wrote:
>> Are you sure it isn't? Your 'space' is an iterable cubic
>> cross-product. Your first loop checks (0,0,0) which is the first
>> element returned, and is thus fast... but it also *consumes* that
>> first element. The next time you test it, the entire space gets
>> consumed, looking for another (0,0,0), which won't exist. That means
>> iterating over 580**3 == 195112000 (two hundred million) tuples, and
>> that *is* going to be slow.
> 
> Huh, I wasn't even aware that membership tests worked on iterables with no
> __contains__ method. Seems odd to me that 'x in y' should be supported but
> not 'len(y)'.

To me

def contains(iterable, value):
for item in iterable:
if item == value:
return True
return False

seems to be a perfectly natural default behaviour. I don't see why

>>> 42 in itertools.count()
True

should require that len(count()) must succeed.

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


Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Steven D'Aprano
On Tue, 09 Dec 2014 21:44:54 -0500, Roy Smith wrote:

> In article <54878f8a$0$13010$c3e8da3$54964...@news.astraweb.com>,
>  Steven D'Aprano  wrote:
> 
>> I really think you guys are trying too hard to make this function seem
>> more complicated than it is. If you find it so hard to understand a
>> simple function with four short lines, one wonders how you would
>> possibly cope with real code.
> 
> Well, look at it this way.  You've got several folks here (I count
> Terry, Ned, Chris, and myself) all saying, "We find this confusing", and
> you're saying, "nobody should find this confusing".  I suppose one
> possible explanation for this dichotomy is that we're all incapable of
> dealing with real code.  Yeah, that must be it.

I know you guys deal with *much* more complicated, obfuscated and 
difficult code. Just look at the stuff posted here by newbies :-) But you 
insist that you're confused by "while iters". I don't get it. I think 
you're protesting too much -- like the weightlifter who routinely bench-
presses 400 lbs, but then insists he can't take the trash out because 
it's too heavy. Or you're insisting on an unrealistic ideal of 
"readable", that if it takes *any time at all* to think about the code, 
that makes it bad.

I've noticed this deep-seated conservatism in Python programmers before. 
Parts of the language are deeply under-utilised, because there are simple 
idioms that people refuse to use because they're "confusing" even though 
they are a trivial generalisation of things that we use all the time.

Or at least, they should be common idioms. They're not common idioms 
because nobody uses them, and nobody uses them because they're not common 
idioms.

Example: In the statistics module in Python 3.4, I added a `median` 
function to calculate the median by the traditional schoolbook algorithm. 
But that's only one out of a number of ways to calculate medium, and 
inspired by similar syntax from R I proposed adding additional methods to 
that `median` object:

median.low(alist)
median.high(alist)

etc. We all know that functions are first class objects with attributes 
and methods, they have a __dict__ so you can attach per-function data to 
them. And there's the last line of the Zen, about namespaces being 
awesome. Every instance with a __dict__ is a namespace.

This ought to be a no-brainer, but apparently nobody has any experience 
with callable attributes attached to instances:

math.sin(x)
"some string".split(s)

We make it a point of pride that functions in Python are not just first 
class values but that they are objects with attributes and methods and a 
per-instance __dict__. But when somebody proposes making use of that, it 
is rejected. Not that I'm bitter :-)

But I digress.

I'm truly sorry that I have been unable to express in words just how 
elegant and beautiful the short version of the myzip() function is. It is 
vanishingly rare to have such a perfect match between an algorithm and 
real working code.

And if anyone has got the impression that I'm calling you a dummy because 
you don't see it my way, I'm not. I'm calling you nekulturny and somebody 
who can't recognise elegant code when it's staring you right in the 
face :-P



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


Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Chris Angelico
On Wed, Dec 10, 2014 at 8:24 PM, Steven D'Aprano  wrote:
> And if anyone has got the impression that I'm calling you a dummy because
> you don't see it my way, I'm not. I'm calling you nekulturny and somebody
> who can't recognise elegant code when it's staring you right in the
> face :-P

I love it when a post sends me to a dictionary. Though in this case,
the word actually has Russian origin, so it ought perhaps to be
spelled некультурны. Good word, anyhow.

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


Re: Solution to a problem,write terminal output to file

2014-12-10 Thread Robert Clove
I think i didn't explained well
Two programs client and server in c.
to run client strace -c ./client
to run server strace -c ./server

After a minute i want to send client SIGINT signal and capture the terminal
output in a file.

If i use os.system and press ctrl+c signal from keyboard i get the output
on terminal if i use subprocess.Popen and press ctrl+c from keyboard i
didn't get the output.

Regards


On Wed, Dec 10, 2014 at 12:51 AM, Chris Angelico  wrote:

> On Wed, Dec 10, 2014 at 4:11 AM, Robert Clove 
> wrote:
> > I am facing a problem in python coding that is
> >
> > I have a client server program(programs a re in c code and client and
> server
> > are its executable) on Linux machine.
> > To run client i do this ./strace -c client and to run server i type this
> > ./strace -c server
> >
> > When i give ctrl+c to client i see some output on the terminal, i want
> that
> > output in the file i mean i want to send the ctrl+c signal programmatic
> ally
> > to client after a minute and write the output in the file.
> >
> > if i use subprocess.Popen to execute  ./strace -c client and give ctrl+c
> > signal i don''t see any output on the terminal but if i see os.system to
> > execute ./strace -c client i see the output on terminal.Now i want to
> send
> > the ctrl+c signal to os.system and write the terminal output into a file.
>
> I'm not entirely sure what you're trying to do here, but strace
> produces its output on Standard Error (aka "stderr"). You can simply
> redirect that to a file. That's the normal strace program. You might
> be running something completely different, since you're running
> "./strace"; but I would suggest that it probably uses either stderr or
> stdout ("Standard Output"), and you could redirect either or both. Try
> this, at the terminal (no Python involved):
>
> ./strace -c client >client_out 2>client_err
>
> Then press Ctrl-C, and see which of the files has the output. Based on
> that, you could configure subprocess.Popen to send the appropriate
> stream to a file.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Nested loops is strangely slow, totally at a loss.

2014-12-10 Thread Shiyao Ma
Thanks guys.

I was only aware of a limited iterables which themselves are iterators, e.g., 
the generator.

Seems like its really a pitfall. Any glossary, list on the iterables that 
*might* exhaust themselves?


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


Re: Nested loops is strangely slow, totally at a loss.

2014-12-10 Thread Peter Otten
Shiyao Ma wrote:

> Thanks guys.
> 
> I was only aware of a limited iterables which themselves are iterators,
> e.g., the generator.
> 
> Seems like its really a pitfall. Any glossary, list on the iterables that
> *might* exhaust themselves?

Usually the test

iterable is iter(iterable)

returns True only for iterators.

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


Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Marko Rauhamaa
Steven D'Aprano :

> I've noticed this deep-seated conservatism in Python programmers
> before. Parts of the language are deeply under-utilised, because there
> are simple idioms that people refuse to use because they're
> "confusing" even though they are a trivial generalisation of things
> that we use all the time.

IMO, large parts of the language are deservedly under-utilized. This
whole dunder thicket: __complex__(), __ifloordiv__(), __rxor__() etc. Or
this metaclass attribute. Or decorators.


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


Call for speakers for the first PyCon Belarus

2014-12-10 Thread Alina Dolgikh
Hi, everyone!

I represent Belarusian Python community and professionally is the IT-events
manager. Our community has regular monthly meet-ups for 70-100 persons and
we are going to develop it further.

We are planning to make the first Belarusian PyCon on the 31st of January
and looking for speakers.

We will be glad to meet at our event speakers, which are experienced in
public talks
(links for videos of public talks or for the other conferences web-pages
are preferable) and can talk on
- Python for web
- science and big data
- functional style Python
- "unusuall" Python (mobile, embeded etc.)

Organising team is ready to cover the costs for the road and accommodation.

Thanks in advance and, please, send your responses to alina at dev.by

Regards,
Alina Dolgikh,
IT-events manager,
Minsk
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: encrypt the http request url on the local machine

2014-12-10 Thread iMath
在 2014年12月9日星期二UTC+8下午2时58分36秒,iMath写道:
> my software on the local machine needs to send http request to a specific web 
> server , is there any way to protect the http request url from being found by 
> Packet analyzer software like Wireshark and fiddler. The sever is not mine, 
> so I can do nothing in the server .
> 
> It would be better to show some code, I am an absolutely newbie in encryption 
> .

thank you all, I have learnt a lot from your answers.

for my question here, I don't want to use a route or proxy or Tor, network 
access speed is also vital in my application, so perhaps there is no solution.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Nested loops is strangely slow, totally at a loss.

2014-12-10 Thread Steven D'Aprano
Shiyao Ma wrote:

> Thanks guys.
> 
> I was only aware of a limited iterables which themselves are iterators,
> e.g., the generator.
> 
> Seems like its really a pitfall. Any glossary, list on the iterables that
> *might* exhaust themselves?

Iterables include:

- iterators
- sequences (e.g. lists, tuples, xrange objects)
- collections such as dicts, sets, etc.
- strings (byte strings and unicode strings)


Only iterators can be exhausted, since they generate their values on-call,
not in advance, and once a value is extracted, it's gone.

Iterators are not a type or class, they are objects which obey the iterator
protocol. In other words, iterators are duck-typed, not all instances of
the same type.

How do you tell if something is an iterator? By duck-typing:

# is obj an iterator?
if iter(obj) is obj and hasattr(obj, "__next__"):
# in Python 2, use "next" instead of "__next__"
print("obj is an iterator")


In Python 3 you can also use an Abstract Base Class:

from collections.abc import Iterator
if isinstance(obj, Iterator):
 print("obj is an iterator")


You can also get a hint from the name:

py> print iter([])



A built-in type that claims to be a "something iterator" is very probably an
iterator.

Calling iter() on any iterable will return an iterator.

Generators are also iterators.

In Python 2, dicts have methods .iterkeys(), .itervalues(), .iteritems()
which return iterators.

Anything you get from the itertools module is likely to be an iterator.


-- 
Steven

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


How to detect that a function argument is the default one

2014-12-10 Thread ast

Hello


Here is what I would like to implement

class Circle:

   def __init__(center=(0,0), radius=10, mass=1)):
   self.center = center
   self.radius = radius

   if  "mass is the default one":   <-
   self.mass = radius**2
   else:
   self.mass = mass

I cant just test if mass == 1: because if I call
C1 = Circle((0,0), 7, 1)
then in that case I want: self.mass = 1

If i call  C2 = Circle((6,8), 8) 
then in that case I want: self.mass = radius**2


I have the idea to write:

def __init__(center=(0,0), radius=10, mass=None)):

   if  mass == None: 
   self.mass = radius**2

   else:
   self.mass = mass

but maybe Python provides something clever.

Thx


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


Re: How to detect that a function argument is the default one

2014-12-10 Thread Skip Montanaro
On Wed, Dec 10, 2014 at 9:14 AM, ast  wrote:
> I have the idea to write:
>
> def __init__(center=(0,0), radius=10, mass=None)):
>
>if  mass == None:self.mass = radius**2
>else:
>self.mass = mass
>
> but maybe Python provides something clever.

This is almost the correct idiom. In general, pick defaults from
values outside your valid domain. None is often perfect for
this. Since you're comparing to a singleton value, "is" is the usual
comparison, so your code becomes:

def __init__(center=(0,0), radius=10, mass=None)):
if mass is None:
self.mass = radius**2
else:
self.mass = mass

At the programming level, Python generally tries not to be too clever,
especially for real basic stuff. From the Zen of Python:

>>> import this
The Zen of Python, by Tim Peters

...
Explicit is better than implicit.
...

Guido could have been more clever here, but it wouldn't have likely
gained much (you'd still have to detect the default and set the value
appropriately), and perhaps made the code a (small) bit harder to
read.

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


Re: How to detect that a function argument is the default one

2014-12-10 Thread ast


"Skip Montanaro"  a écrit dans le message de 
news:mailman.16809.1418225382.18130.python-l...@python.org...

On Wed, Dec 10, 2014 at 9:14 AM, ast  wrote:


thx 


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


Re: encrypt the http request url on the local machine

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 12:48 AM, iMath  wrote:
> 在 2014年12月9日星期二UTC+8下午2时58分36秒,iMath写道:
>> my software on the local machine needs to send http request to a specific 
>> web server , is there any way to protect the http request url from being 
>> found by Packet analyzer software like Wireshark and fiddler. The sever is 
>> not mine, so I can do nothing in the server .
>>
>> It would be better to show some code, I am an absolutely newbie in 
>> encryption .
>
> thank you all, I have learnt a lot from your answers.
>
> for my question here, I don't want to use a route or proxy or Tor, network 
> access speed is also vital in my application, so perhaps there is no solution.

Then yes, there's basically no solution. In general, you need to
either negotiate with the server (HTTPS being the easiest way), or go
via some server that you _do_ control, which will delay matters.

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


Re: Nested loops is strangely slow, totally at a loss.

2014-12-10 Thread Ian Kelly
On Wed, Dec 10, 2014 at 1:21 AM, Peter Otten <__pete...@web.de> wrote:
>
> Ian Kelly wrote:
> > Huh, I wasn't even aware that membership tests worked on iterables with
no
> > __contains__ method. Seems odd to me that 'x in y' should be supported
but
> > not 'len(y)'.
>
> To me
>
> def contains(iterable, value):
> for item in iterable:
> if item == value:
> return True
> return False
>
> seems to be a perfectly natural default behaviour. I don't see why
>
> >>> 42 in itertools.count()
> True
>
> should require that len(count()) must succeed.

This also seems perfectly natural:

def len(iterable):
return sum(1 for item in iterable)

My observation is that seems strange to me that one standard sequence
operation should be supported for arbitrary iterators and the other not.

If the objection about `len(count())` is that the call would never return,
I'll point out that `-42 in count()` suffers the same problem.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Nested loops is strangely slow, totally at a loss.

2014-12-10 Thread Ian Kelly
On Wed, Dec 10, 2014 at 9:01 AM, Ian Kelly  wrote:
> This also seems perfectly natural:
>
> def len(iterable):
> return sum(1 for item in iterable)
>
> My observation is that seems strange to me that one standard sequence
operation should be supported for arbitrary iterators and the other not.
>
> If the objection about `len(count())` is that the call would never
return, I'll point out that `-42 in count()` suffers the same problem.

To further clarify what I'm saying, I don't think that len(iterable) should
be supported. I'm just dismayed that "x in iterable" already is.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to detect that a function argument is the default one

2014-12-10 Thread Jean-Michel Pichavant
- Original Message -
> From: "ast" 
> I have the idea to write:
> 
> def __init__(center=(0,0), radius=10, mass=None)):
> 
> if  mass == None:
> self.mass = radius**2
> else:
> self.mass = mass
> 
> but maybe Python provides something clever.
> 
> Thx

If you like one-liners,

def __init__(self, center=(0,0), radius=10, mass=None):
self.center = center
self.radius = radius
self.mass = (mass is None and radius**2) or mass

But there's an issue with that solution: self.mass being computed during the 
instance initialization, what if radius is changing ?

c1 = Circle((0,0), 10, None)
print c1.mass
20
c1.radius = 20
print c1.mass
20 # that is unexpected

Everytime an attribute is computed from another attribute, it should ring a 
python bell : property

def __init__(self, center, radius, mass):
self.center = center
self.radius = radius
self._mass = mass

@property
def mass(self):
 return self._mass if self._mass is not None else self.radius*2


c1 = Circle((0,0), 10, None)
print c1.mass
20
c1.radius = 20
print c1.mass
40

JM

Note : what is the mass of a circle ?


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to detect that a function argument is the default one

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 3:10 AM, Jean-Michel Pichavant
 wrote:
> - Original Message -
>> From: "ast" 
>> I have the idea to write:
>>
>> def __init__(center=(0,0), radius=10, mass=None)):
>>
>> if  mass == None:
>> self.mass = radius**2
>> else:
>> self.mass = mass
>>
>> but maybe Python provides something clever.
>>
>> Thx
>
> If you like one-liners,
>
> def __init__(self, center=(0,0), radius=10, mass=None):
> self.center = center
> self.radius = radius
> self.mass = (mass is None and radius**2) or mass

Leaving aside the obvious point that not everything needs to be a
one-liner, there is a MUCH better way to spell this: the if/else
ternary expression.

self.mass = radius**2 if mass is None else mass

> But there's an issue with that solution: self.mass being computed during the 
> instance initialization, what if radius is changing ?
>
> c1 = Circle((0,0), 10, None)
> print c1.mass
> 20
> c1.radius = 20
> print c1.mass
> 20 # that is unexpected
>
> Everytime an attribute is computed from another attribute, it should ring a 
> python bell : property
>
> def __init__(self, center, radius, mass):
> self.center = center
> self.radius = radius
> self._mass = mass
>
> @property
> def mass(self):
>  return self._mass if self._mass is not None else self.radius*2
>
>
> c1 = Circle((0,0), 10, None)
> print c1.mass
> 20
> c1.radius = 20
> print c1.mass
> 40

I think that juust might count as scope creep :) Though it
does highlight an interesting point, namely that sometimes the state
of "argument wasn't specified" needs to carry through into an object's
"attribute wasn't specified".

> Note : what is the mass of a circle ?

Fortunately for us, this is a programming class, not a philosophical
one. Maybe the circles in question are being cast in steel? :)

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


Re: How to detect that a function argument is the default one

2014-12-10 Thread Ned Batchelder

On 12/10/14 11:10 AM, Jean-Michel Pichavant wrote:

 self.mass = (mass is None and radius**2) or mass


When will this idiom die?  We've had actual if-expressions for a while now:

self.mass = radius**2 if mass is None else mass

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

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


Re: How to detect that a function argument is the default one

2014-12-10 Thread Ian Kelly
On Wed, Dec 10, 2014 at 9:10 AM, Jean-Michel Pichavant <
jeanmic...@sequans.com> wrote:
> If you like one-liners,
>
> def __init__(self, center=(0,0), radius=10, mass=None):
> self.center = center
> self.radius = radius
> self.mass = (mass is None and radius**2) or mass

If mass is None and radius is 0, then self.mass gets set to None. Use the
actual ternary operator instead.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to detect that a function argument is the default one

2014-12-10 Thread Marko Rauhamaa
Skip Montanaro :

> On Wed, Dec 10, 2014 at 9:14 AM, ast  wrote:
>> I have the idea to write:
>>
>> def __init__(center=(0,0), radius=10, mass=None)):
>>
>>if  mass == None:self.mass = radius**2
>>else:
>>self.mass = mass
>>
>> but maybe Python provides something clever.
>
> This is almost the correct idiom. In general, pick defaults from
> values outside your valid domain. None is often perfect for
> this. Since you're comparing to a singleton value, "is" is the usual
> comparison, so your code becomes:
>
> def __init__(center=(0,0), radius=10, mass=None)):
> if mass is None:
> self.mass = radius**2
> else:
> self.mass = mass

In this case, None works well. However, sometimes None is a valid input
value. Then, a sentinel object is the way out:


_OMITTED = object()

class SomeClass:
def __init__(self, center=(0,0), radius=10, mass=_OMITTED)):
if mass is _OMITTED:
self.mass = radius**2
else:
self.mass = mass


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


Python 2/3 compatibility code that reads like English!

2014-12-10 Thread Chris Angelico
So you have a string of text, either a Unicode string in Python 3, or
a byte string that's meant to be UTF-8. Most of the way through,
you're working with the native string type, for compatibility with
other sections of code. But then you want to be certain you're working
with a Unicode string...

if str is bytes:
some_string = some_string.decode('UTF-8')

I just love how that condition reads. Who says cross-branch
compatibility code has to be ugly? :)

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


Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Ian Kelly
On Wed, Dec 10, 2014 at 2:24 AM, Steven D'Aprano 
wrote:
>
> Example: In the statistics module in Python 3.4, I added a `median`
> function to calculate the median by the traditional schoolbook algorithm.
> But that's only one out of a number of ways to calculate medium, and
> inspired by similar syntax from R I proposed adding additional methods to
> that `median` object:
>
> median.low(alist)
> median.high(alist)
>
> etc. We all know that functions are first class objects with attributes
> and methods, they have a __dict__ so you can attach per-function data to
> them. And there's the last line of the Zen, about namespaces being
> awesome. Every instance with a __dict__ is a namespace.
>
> This ought to be a no-brainer, but apparently nobody has any experience
> with callable attributes attached to instances:
>
> math.sin(x)
> "some string".split(s)
>
> We make it a point of pride that functions in Python are not just first
> class values but that they are objects with attributes and methods and a
> per-instance __dict__. But when somebody proposes making use of that, it
> is rejected. Not that I'm bitter :-)

I don't particularly have a problem with functions having attributes, e.g.
I think itertools.chain.from_iterable is just peachy. There is a downside
though, which is that making those functions attributes of another function
rather than of the module defeats the dir() function for that module.
Likewise the generated help for the help() function, unless care is taken
to explicitly mention the existence of those functions in either the doc
string for the module or the standard median function. Thirdly, IDEs with
code completion features may simply fail to notice that these alternate
versions of the function exist. For these reasons I think that this is an
anti-pattern and is best avoided in the standard library. Having to type _
instead of . is only one extra key stroke.

Now if there were an established pattern to such function attributes, e.g.
if f.len(parrots) was a standard alternative to len(f(parrots)) for
functions that return sequences, then that could be a useful feature,
especially if such properties could be chained arbitrarily. But one-offs
like median.low would only serve to make the function more difficult to
find than necessary.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-10 Thread Donald Stufft

> On Dec 10, 2014, at 11:59 AM, Bruno Cauet  wrote:
> 
> Hi all,
> Last year a survey was conducted on python 2 and 3 usage.
> Here is the 2014 edition, slightly updated (from 9 to 11 questions).
> It should not take you more than 1 minute to fill. I would be pleased if you 
> took that time.
> 
> Here's the url: http://goo.gl/forms/tDTcm8UzB3 
> 
> I'll publish the results around the end of the year.
> 
> Last year results: https://wiki.python.org/moin/2.x-vs-3.x-survey 
> 

Just going to say http://d.stufft.io/image/0z1841112o0C 
 is a hard question to answer, since 
most code I write is both.

---
Donald Stufft
PGP: 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA

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


Getting errors from Imaplib - reloaded

2014-12-10 Thread Beatrix Willius from Moth Software
Hi,

thanks to your help I can get traceback errors for the imaplib. But what about 
accessing direct imap errors? In the following part of my script I can't select 
the not-deleted mails for some reason. But how do I access the error? The 
debugger goes to the exception line but OSError.strerror doesn't have anything. 
And print(imaplib.IMAP4.error) only gives me  as 
result.

import imaplib

host = "xxx"
username = "bla"
password = "blub"
mailbox = "\"Ablage.Kunden\""

imap_connection = imaplib.IMAP4(host)
result, data = imap_connection.login(username, password)
result, data = imap_connection.select(mailbox, True)

try:
result, messages_data = imap_connection.search(None, "NOT DELETED")
print('okay')
except (imaplib.IMAP4.error, OSError):
#print(OSError.strerror)
#print(imaplib.IMAP4.error)
print('xxxerrorxxx: select mails exception')
imap_connection.logout()



Mit freundlichen Grüßen/Regards

Trixi Willius

http://www.mothsoftware.com
Mail Archiver X: The email archiving solution for professionals

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


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-10 Thread Ian Cordasco
On Wed, Dec 10, 2014 at 11:10 AM, Donald Stufft  wrote:
>
> On Dec 10, 2014, at 11:59 AM, Bruno Cauet  wrote:
>
> Hi all,
> Last year a survey was conducted on python 2 and 3 usage.
> Here is the 2014 edition, slightly updated (from 9 to 11 questions).
> It should not take you more than 1 minute to fill. I would be pleased if you
> took that time.
>
> Here's the url: http://goo.gl/forms/tDTcm8UzB3
> I'll publish the results around the end of the year.
>
> Last year results: https://wiki.python.org/moin/2.x-vs-3.x-survey
>
>
> Just going to say http://d.stufft.io/image/0z1841112o0C is a hard question
> to answer, since most code I write is both.
>

The same holds for me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-10 Thread Nathaniel Smith
On 10 Dec 2014 17:16, "Ian Cordasco"  wrote:
>
> On Wed, Dec 10, 2014 at 11:10 AM, Donald Stufft  wrote:
> >
> > On Dec 10, 2014, at 11:59 AM, Bruno Cauet  wrote:
> >
> > Hi all,
> > Last year a survey was conducted on python 2 and 3 usage.
> > Here is the 2014 edition, slightly updated (from 9 to 11 questions).
> > It should not take you more than 1 minute to fill. I would be pleased
if you
> > took that time.
> >
> > Here's the url: http://goo.gl/forms/tDTcm8UzB3
> > I'll publish the results around the end of the year.
> >
> > Last year results: https://wiki.python.org/moin/2.x-vs-3.x-survey
> >
> >
> > Just going to say http://d.stufft.io/image/0z1841112o0C is a hard
question
> > to answer, since most code I write is both.
> >
>
> The same holds for me.

That question appears to have just grown a "compatible with both" option.

It might make sense to add a similar option to the following question about
what you use for personal projects.

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


Re: How to detect that a function argument is the default one

2014-12-10 Thread Jussi Piitulainen
Jean-Michel Pichavant writes:

> If you like one-liners,
> 
> def __init__(self, center=(0,0), radius=10, mass=None):
> self.center = center
> self.radius = radius
> self.mass = (mass is None and radius**2) or mass

That's not a one-liner. That's a one-liner:

def __init__(self, center=(0,0), radius=10, mass=None): self.center = center ; 
self.radius = radius ; self.mass = (mass is None and radius**2) or mass

And as others point out, you could highlight the number of
sub-expressions better by using an actual three-place expression.
(Why _that_ is considered so salient, I don't know. But it is.)


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


Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Terry Reedy

On 12/10/2014 11:46 AM, Ian Kelly wrote:


I don't particularly have a problem with functions having attributes,
e.g. I think itertools.chain.from_iterable is just peachy. There is a
downside though, which is that making those functions attributes of
another function rather than of the module


Itertools.chain is a class, not a function.  Chain.from_iterable is an 
*alternate constructor* for instances of the class, just as 
dict.fromkeys is an alternate constructor for dict instances.


It is true that if itertools were written in python, chain and the other 
classes would likely be written as generator functions, so tha analogy 
would not apply.



defeats the dir() function for that module.


And it is also true that dir(__builtins__) does not show dict.fromkeys.


Likewise the generated help for the help() function,
unless care is taken to explicitly mention the existence of those
functions in either the doc string for the module


help(it.chain) lists
 |  from_iterable(...) from builtins.type
 |  chain.from_iterable(iterable) --> chain object
 |
 |  Alternate chain() contructor taking a single iterable argument
 |  that evaluates lazily.

help(dict)
 |  fromkeys(iterable, value=None, /) from builtins.type
 |  Returns a new dict with keys from iterable and values equal to 
value.



Thirdly, IDEs with code completion features may simply fail to
notice that these alternate versions of the function exist.


I don't know what you mean here.  In Idle
>>> it.chain.  --> completion box with from_iterable
>>> dict.   --> completion box that includes fromkeys

None of the above is to say that alternate constructors for classed are 
not a bit awkward.  I believe this was recognized when dict.fromkeys was 
added.  But it was considered less awkward than the alternatives: 1. do 
not add the functionality; 2. further overload the main (__init__) 
constructor; 3. add a independent function.  Anyway, they exist, are an 
accepted pattern among core devs, and will probably increase in number.


--
Terry Jan Reedy

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


Re: When do default parameters get their values set?

2014-12-10 Thread random832
On Tue, Dec 9, 2014, at 21:44, Rustom Mody wrote:
> Nice example -- thanks.
> Elaborates the why of this gotcha -- a def(inition) is imperative.
> From a semantic pov very clean.
> From an expectation pov always surprising.

Of course, I used a lambda for this. The equivalent without would be:

def f():
def g(x={}):
return x
return g

Ultimately it's no different from when any non-immutable expression is
executed.

def f: return {'x': {}}
f()['x'] is f()['x'] # False
d = f()
d['x'] is d['x'] # True
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Script to convert firewall rules

2014-12-10 Thread Kashif Rana
Hello Experts

I am network engineer and not expert in programming. I would like to make one 
python script to convert juniper netscreen firewall configuration into juniper 
SRX firewall configuration. Sample is below. I would appreciate if anybody can 
give me the high level steps to start with.

Juniper Netscreen

set interface ethernet0/0 ip 194.1.1.1/24
set interface ethernet0/0 route
set interface "ethernet0/0" zone "Untrust"


set interface ethernet2/5 ip 10.17.10.1/24
set interface ethernet2/5 route
set interface "ethernet2/5" zone "Mail DMZ"

 

set interface "ethernet0/0" mip 194.1.1.10 host 10.17.10.10 netmask 
255.255.255.255 vr "trust-vr"
set interface "ethernet0/0" mip 194.1.1.20 host 10.17.10.20 netmask 
255.255.255.255 vr "trust-vr"

set address "Mail DMZ" "mx1.union.com" 10.17.10.10 255.255.255.255
set address "Mail DMZ" "mx2.union.com" 10.17.10.20 255.255.255.255

set policy id 100 name "CR567" from "Untrust" to "DMZ"  "Any" 
"MIP(194.1.1.10)" "SMTP" permit log
set policy id 100
set dst-address "MIP(194.1.1.20)"
set log session-init
exit

Juniper SRX
--
interfaces {
ge-0/0/0 {
unit 0 {
family inet {
address 194.1.1.1/24;
}
}
}
ge-2/0/5 {
unit 0 {
family inet {
address 10.17.10.1/24;
}
}
}
}
security {
nat {
static {
rule-set static-nat-"Untrust" {
from zone "Untrust";
rule rule-1 {
match {
destination-address 194.1.1.10/32;
}
then {
static-nat prefix 10.17.10.10/32;
}
}
rule rule-2 {
match {
destination-address 194.1.1.20/32;
}
then {
static-nat prefix 10.17.10.20/32;
}
}
}
}
proxy-arp {
interface ge-0/0/0.0 {
address {
194.1.1.10/32;
194.1.1.20/32;
}
}
}
}
zones {
security-zone Untrust {
interfaces {
ge-0/0/0.0;
}
}
security-zone DMZ {
address-book {
address mx1.union.com  10.17.10.10/32;
address mx2.union.com  10.17.10.20/32;
}
interfaces {
ge-2/0/5.0;
}
}
}
policies {
from-zone Untrust to-zone DMZ {
/* "CR567" */
policy 100 {
match {
source-address any;
destination-address [ mx1.union.com mx2.union.com ];
application junos-smtp;
}
then {
permit;
log {
session-init;
}
}
}
}
}
}

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


Re: seeking a framework to automate router configurations

2014-12-10 Thread ercintorun
18 Aralık 2013 Çarşamba 04:40:20 UTC+2 tarihinde Frank Cui yazdı:
> Hi Pythoners,
> 
> 
> I'm looking for a tool or framework in which I can do a slight modification 
> to achieve the following task:
> 
> 
> "Asynchronously reset a large number of cisco routers back to their original 
> configurations and push prepared initial configurations to them"
> 
> 
> I did find some similar existing work such as exscript and trigger, however I 
> was stuck in the following two problems :
> 
> 
> 1. telneting to a non-default port number (other than 23)
> 2. handling of customized banner messages.
> 
> 
> can you give some hints on this ?  Thanks in advance for your input.
> 
> 
> Frank

Hi Frank, 

It's been a year since you asked, even so i wanted to answer. I faced the same 
problem and write down a telnet class to overcome such problems. I did not 
choose using pexpect as it does not work on windows (or really hard), and catch 
"hostname+line_break" to get the data everytime a command is executed on the 
router. You might have a look at 
http://www.networkhints.com/2014/12/automating-telnet-to-ciscojuniperhuawei.html
 if you wanted to.

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


Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Ian Kelly
On Wed, Dec 10, 2014 at 10:48 AM, Terry Reedy  wrote:
>> Likewise the generated help for the help() function,
>> unless care is taken to explicitly mention the existence of those
>> functions in either the doc string for the module
>
>
> help(it.chain) lists
>  |  from_iterable(...) from builtins.type
>  |  chain.from_iterable(iterable) --> chain object
>  |
>  |  Alternate chain() contructor taking a single iterable argument
>  |  that evaluates lazily.

As you point out, chain is a class, not a function. When you invoke help()
on a function, it lists the members, of which a static alternate
constructor would be one. Try it with a function, though:

>>> import statistics
>>> statistics.median.low = statistics.median_low
>>> help(statistics.median)
Help on function median in module statistics:

median(data)
Return the median (middle value) of numeric data.

When the number of data points is odd, return the middle data point.
When the number of data points is even, the median is interpolated by
taking the average of the two middle values:

>>> median([1, 3, 5])
3
>>> median([1, 3, 5, 7])
4.0

It only prints out the doc string, nothing about the attributes. So the doc
string for median would need to explicitly document the existence of
median.low and median.high in addition to its own usage.

>> Thirdly, IDEs with code completion features may simply fail to
>> notice that these alternate versions of the function exist.
>
> I don't know what you mean here.  In Idle
> >>> it.chain.  --> completion box with from_iterable
> >>> dict.   --> completion box that includes fromkeys

So Idle gets it right. At least for static methods of classes, which isn't
very surprising. Does it complete a function attribute of a function? I
don't have it installed to test.

Having used Komodo IDE for a number of years and been occasionally
frustrated by its code completion, it would not surprise me in the least if
it failed to pull attributes of functions into its completion database.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to detect that a function argument is the default one

2014-12-10 Thread ast


"Chris Angelico"  a écrit dans le message de 
news:mailman.16814.1418228205.18130.python-l...@python.org...

On Thu, Dec 11, 2014 at 3:10 AM, Jean-Michel Pichavant
 wrote:

- Original Message -

From: "ast" 



But there's an issue with that solution: self.mass being computed
during the instance initialization, what if radius is changing ?


You are going to laught because i had that bug ... LOL

Everytime an attribute is computed from another attribute, it should ring a python bell : 
property


yes





Note : what is the mass of a circle ?




In fact it's a ball moving in a plan.
I will change that name. 


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


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 3:59 AM, Bruno Cauet  wrote:
> Here's the url: http://goo.gl/forms/tDTcm8UzB3
> I'll publish the results around the end of the year.

On "Which versions do you use?", 3.5 is not included. My primary
Python 3 build on here is a 3.5 built from trunk. :)

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


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 9:04 AM, Bruno Cauet  wrote:
> I hesitated a while before deciding not to include it! Apart from python
> core development what would be the reasons to work mostly on this version ?
> I'll fix the omission right ahead.

My main reason is that I'm running Debian Wheezy here (the current
stable release of Debian), and Wheezy ships with Python 3.2. If I want
to use anything newer than 3.2, I have to either hunt down a
backported package, or build from source. And if I'm going to build
from source (which, for me, is easier than digging through
wheezy-backports anyway), I may as well build from Mercurial on the
default branch rather than taking a specific version tarball.

(For what it's worth, Debian Jessie - the next release - ships with
3.4, so on my Jessie boxes I don't bother building Python from
source.)

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


Coercing two numbers without coerce()

2014-12-10 Thread Luciano Ramalho
Python 3 dropped the coerce() built-in, but I have a situation where
I'd love to use it.

I have two numbers A, B and I need to get the value of A coerced to
the type of A+B. This is for a generator function that will produce a
series similar to what itertools.count does.

I know I can do type(A+B)(A), or A+B-B, but both alternatives are ugly
and perform needless arithmetic.

What do you suggest, now that the coerce() built-in is not available?

Cheers,

Luciano


-- 
Luciano Ramalho
Twitter: @ramalhoorg

Professor em: http://python.pro.br
Twitter: @pythonprobr
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Coercing two numbers without coerce()

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 9:27 AM, Luciano Ramalho  wrote:
> I know I can do type(A+B)(A), or A+B-B, but both alternatives are ugly
> and perform needless arithmetic.
>
> What do you suggest, now that the coerce() built-in is not available?

I would suggest just doing the arithmetic :) That's guaranteed to
work, and a little addition isn't that costly. (As long as you're not
Numberphile and implementing four-bit binary arithmetic in racing
dominoes. Then it's costly.)

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


[RELEASE] Python 2.7.9

2014-12-10 Thread Benjamin Peterson
It is my pleasure to announce the release of Python 2.7.9, a new bugfix
release in the Python 2.7 series. Despite technically being a
maintenance release, Python 2.7.9 includes several majors changes from
2.7.8:

- The "ensurepip" module has been backported to Python 2.7
- Python 3's ssl module has been backported to Python 2.7.
- HTTPS certificates are now verified by default using the system's
certificate store.
- SSLv3 has been disabled by default due to the POODLE attack.

Downloads are at
https://www.python.org/downloads/release/python-279/

Please report bugs to
https://bugs.python.org/

I would  like to thank the people who made the above security and
usability improvements listed above possible. Among others, Alex Gaynor,
David Reid, Nick Coghlan, and Donald Stufft wrote many PEPs and a lot of
code to bring those features to 2.7.9. Thank you.

Enjoy,
Benjamin
2.7 release manager
on behalf on python-dev and all of Python's contributors
-- 
https://mail.python.org/mailman/listinfo/python-list


Python script isn't producing text in data file

2014-12-10 Thread Docfxit
I have a Python script that runs with no errors but it doesn't produce the 
output it should in a text file.  I can't figure out why. Is this the correct 
forum to post this in or can someone suggest a more appropriate forum?

The script selects all files from the day before the script is run.  So if 
today is December 10th the script will select all log files from December 9th.

The script reads all files from the day before and summarizes the information 
in the log files.  It writes out a text file with the summary information.

What should show up in the text file is information that is in this zip file:
http://theoffice.la/m/SummaryExample.zip

In the script line 11 it states what directory to look for the input log files.
The input log file name will need to be changed to yesterdays date for the 
script to read it.
This is an example of an input log file:
http://theoffice.la/m/2014-12-05Test.zip

This is the Python Script that I'm having trouble with:
http://theoffice.la/m/CGPLogSummaryTest.py

If I haven't provided enough information please let me know.

Thank you,

Docfxit




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


Re: Python script isn't producing text in data file

2014-12-10 Thread Docfxit
On Wednesday, December 10, 2014 3:05:07 PM UTC-8, Docfxit wrote:
> I have a Python script that runs with no errors but it doesn't produce the 
> output it should in a text file.  I can't figure out why. Is this the correct 
> forum to post this in or can someone suggest a more appropriate forum?
> 
> The script selects all files from the day before the script is run.  So if 
> today is December 10th the script will select all log files from December 9th.
> 
> The script reads all files from the day before and summarizes the information 
> in the log files.  It writes out a text file with the summary information.
> 
> What should show up in the text file is information that is in this zip file:
> http://theoffice.la/m/SummaryExample.zip
> 
> In the script line 11 it states what directory to look for the input log 
> files.
> The input log file name will need to be changed to yesterdays date for the 
> script to read it.
> This is an example of an input log file:
> http://theoffice.la/m/2014-12-05Test.zip
> 
> This is the Python Script that I'm having trouble with:
> http://theoffice.la/m/CGPLogSummaryTest.py
> 
> I'm running this with Python 3.2.2 In Windows 7 Pro 
> If I haven't provided enough information please let me know.
> 
> Thank you,
> 
> Docfxit

Edited for clarity.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script isn't producing text in data file

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 10:04 AM, Docfxit  wrote:
> This is the Python Script that I'm having trouble with:
> http://theoffice.la/m/CGPLogSummaryTest.py
>
> If I haven't provided enough information please let me know.

It'd be better to include the code in the body of your email. You
never know when your hosting might go down and the code be
unavailable like right now. :)

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


Re: Python script isn't producing text in data file

2014-12-10 Thread sohcahtoa82
On Wednesday, December 10, 2014 3:11:28 PM UTC-8, Chris Angelico wrote:
> On Thu, Dec 11, 2014 at 10:04 AM, Docfxit  wrote:
> > This is the Python Script that I'm having trouble with:
> > http://theoffice.la/m/CGPLogSummaryTest.py
> >
> > If I haven't provided enough information please let me know.
> 
> It'd be better to include the code in the body of your email. You
> never know when your hosting might go down and the code be
> unavailable like right now. :)
> 
> ChrisA

Also, I'm weary about clicking links to random pages.  I like to think that I 
can trust my computer to not let me get pwned by simply downloading and opening 
up a ZIP, but with Windows's history of exploits, I don't trust it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script isn't producing text in data file

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 12:32 PM,   wrote:
> On Wednesday, December 10, 2014 3:11:28 PM UTC-8, Chris Angelico wrote:
>> On Thu, Dec 11, 2014 at 10:04 AM, Docfxit  wrote:
>> > This is the Python Script that I'm having trouble with:
>> > http://theoffice.la/m/CGPLogSummaryTest.py
>> >
>> > If I haven't provided enough information please let me know.
>>
>> It'd be better to include the code in the body of your email. You
>> never know when your hosting might go down and the code be
>> unavailable like right now. :)
>>
>> ChrisA
>
> Also, I'm weary about clicking links to random pages.  I like to think that I 
> can trust my computer to not let me get pwned by simply downloading and 
> opening up a ZIP, but with Windows's history of exploits, I don't trust it.
>

Agreed. There are ways around some of those problems (eg using wget to
fetch something, and then looking at it in a text editor - it's hard
to get pwned through a text editor... though I won't say impossible),
but there are other issues too, and all in all, it's just best to
include the text in-line.

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


Re: When do default parameters get their values set?

2014-12-10 Thread Rustom Mody
On Thursday, December 11, 2014 12:09:10 AM UTC+5:30, rand...@fastmail.us wrote:
> On Tue, Dec 9, 2014, at 21:44, Rustom Mody wrote:
> > Nice example -- thanks.
> > Elaborates the why of this gotcha -- a def(inition) is imperative.
> > From a semantic pov very clean.
> > From an expectation pov always surprising.
> 
> Of course, I used a lambda for this. The equivalent without would be:
> 
> def f():
> def g(x={}):
> return x
> return g

Ok. As I wrote in the "Question on lambdas" thread yesterday
lambdas and defs are equivalent

And going the other way -- no defs only lambdas its this:


>>> f = lambda : (lambda x= {}: x)
>>> f()() is f()()
False
>>> d = f()
>>> d() is d()
True
>>> 


But I have a different question -- can this be demonstrated without the 'is'?
Because to me 'is' -- equivalently id -- is a code-smell and is like
explaining funny behavior by showing the dis -- like 
$ gcc -S ...
-- output.

It can always explain, but indicates that the semantics is not (sufficiently) 
abstract in this aspect
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When do default parameters get their values set?

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 1:18 PM, Rustom Mody  wrote:
> But I have a different question -- can this be demonstrated without the 'is'?
> Because to me 'is' -- equivalently id -- is a code-smell and is like
> explaining funny behavior by showing the dis -- like
> $ gcc -S ...
> -- output.
>
> It can always explain, but indicates that the semantics is not (sufficiently) 
> abstract in this aspect

Not so. Object identity is a fundamental part of Python.
Indistinguishable-but-distinct mutable objects are crucial to Python's
behaviour.

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


Re: Python script isn't producing text in data file

2014-12-10 Thread Steven D'Aprano
On Thu, 11 Dec 2014 12:44:51 +1100, Chris Angelico wrote:

> Agreed. There are ways around some of those problems (eg using wget to
> fetch something, and then looking at it in a text editor - it's hard to
> get pwned through a text editor... though I won't say impossible), but
> there are other issues too, and all in all, it's just best to include
> the text in-line.

I believe that there was a recently discovered exploit on Linux where 
viewing a file with "less" could run arbitrary code.

But really, if the program is short enough, you should include the code 
in the body of your post, or at least as an attachment. And if it is not 
short enough, you should *make it shorter*.

http://sscce.org/


There are many reasons why people might not click through links to 
download your code:

- they may be reading your post somewhere where they have access
  to email, but not web (e.g. behind a corporate firewall)

- they may not appreciate the security risks

- they might just be lazy, and firing up a web browser too much
  a distraction

- they might already have 200+ tabs open in their browser, and 
  adding one more may be just enough to shift them from "yes, 
  I'd love to help" to "fuck 'em, they can solve their own 
  problems".



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


Re: Python script isn't producing text in data file

2014-12-10 Thread Steven D'Aprano
On Wed, 10 Dec 2014 15:04:52 -0800, Docfxit wrote:

> This is the Python Script that I'm having trouble with:
> http://theoffice.la/m/CGPLogSummaryTest.py

Link is broken:

steve@runes:~$ wget http://theoffice.la/m/CGPLogSummaryTest.py
--2014-12-11 13:41:26--  http://theoffice.la/m/CGPLogSummaryTest.py
Resolving theoffice.la... 75.79.6.149
Connecting to theoffice.la|75.79.6.149|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2014-12-11 13:41:26 ERROR 404: Not Found.


If the script is less than, say, 100 lines, please post it here directly 
in the body of your message. Make sure you post as PLAIN TEXT, not "rich 
text" (HTML), as rich text will destroy the formatting.

If the script is more than 100 lines, then please read this before 
posting:

http://sscce.org/

Even though it is written for Java programmers, it applies to any 
language. Please cut your code down to the smallest self-contained 
example that demonstrates the problem.

Doing so will have two benefits:

- it will increase the chances that you will find the bug yourself;

- and if you don't, it will increase the chances that others will 
  be willing to help you.




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


Re: Python script isn't producing text in data file

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 1:41 PM, Steven D'Aprano  wrote:
> On Thu, 11 Dec 2014 12:44:51 +1100, Chris Angelico wrote:
>
>> Agreed. There are ways around some of those problems (eg using wget to
>> fetch something, and then looking at it in a text editor - it's hard to
>> get pwned through a text editor... though I won't say impossible), but
>> there are other issues too, and all in all, it's just best to include
>> the text in-line.
>
> I believe that there was a recently discovered exploit on Linux where
> viewing a file with "less" could run arbitrary code.

Which is why I refused to say "impossible" :) Although you gain the
additional benefit of an unpredictable attack vector; one person might
use 'less', another might open it in SciTE, a third might just cat the
file and scroll through it some other way. It's hard to aim at a
target that exists in so many pieces, and probably isn't worth the
effort of attacking.

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


Re: When do default parameters get their values set?

2014-12-10 Thread Rustom Mody
On Thursday, December 11, 2014 8:05:13 AM UTC+5:30, Chris Angelico wrote:
> On Thu, Dec 11, 2014 at 1:18 PM, Rustom Mody  wrote:
> > But I have a different question -- can this be demonstrated without the 
> > 'is'?
> > Because to me 'is' -- equivalently id -- is a code-smell and is like
> > explaining funny behavior by showing the dis -- like
> > $ gcc -S ...
> > -- output.
> >
> > It can always explain, but indicates that the semantics is not 
> > (sufficiently) abstract in this aspect
> 
> Not so. Object identity is a fundamental part of Python.
> Indistinguishable-but-distinct mutable objects are crucial to Python's
> behaviour.

You are saying much the same as I am.

Most programmers try to write programs without gotos.
Good (C) programmers know that 
1. gotos can be more efficient than 'structured' code
2. And even sometimes more elegant -- think of coding a non-trivial
automaton with State=Label, Transition=goto

Still most (reasonable) C-programmers will at least try to
write goto-less code.

Analogously here: 'is/id' are part of python.
Nevertheless *explaining* something with and without these
are significantly different.

Naturally we may have different feelings about 'is' in python.
However 'agree/disagree' is (in my book) a verb that is
applied to facts not feelings :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: When do default parameters get their values set?

2014-12-10 Thread Steven D'Aprano
On Wed, 10 Dec 2014 18:18:44 -0800, Rustom Mody wrote:


> And going the other way -- no defs only lambdas its this:
> 
> 
 f = lambda : (lambda x= {}: x)
 f()() is f()()
> False
 d = f()
 d() is d()
> True
 
 
> 
> But I have a different question -- can this be demonstrated without the
> 'is'? 


Can *what* be demonstrated? That the functions returned are different 
objects, or that the dicts are different objects? Both? Something else?

Using "is" you are demonstrating that calling the function twice returns 
two distinct objects. That is the purpose of "is", to compare object 
identity. Without "is", you can compare object IDs directly:

id(f()()) == id(f()())

but that's ugly and less efficient. Using "is" is the more idiomatic and 
natural way to do this.


Other than that, you could do something to demonstrate the consequences 
of the two values being distinct objects:

a = f()()  # Call twice to get a dict.
b = f()()
a['key'] = 23
b['key']  # raises KeyError


or

a = f()  # Call once to get a function.
b = f()
a.attribute = 23
b.attribute  # raises AttributeError


Or you could inspect the byte-code of f and try to understand it.



> Because to me 'is' -- equivalently id -- is a code-smell 

It is only a code-smell in the sense that caring about object identity 
should be rare.



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


Re: When do default parameters get their values set?

2014-12-10 Thread Rustom Mody
On Thursday, December 11, 2014 8:45:22 AM UTC+5:30, Steven D'Aprano wrote:
> On Wed, 10 Dec 2014 18:18:44 -0800, Rustom Mody wrote:
> 
> 
> > And going the other way -- no defs only lambdas its this:
> > 
> > 
>  f = lambda : (lambda x= {}: x)
>  f()() is f()()
> > False
>  d = f()
>  d() is d()
> > True
>  
>  
> > 
> > But I have a different question -- can this be demonstrated without the
> > 'is'? 
> 
> 
> Can *what* be demonstrated? That the functions returned are different 
> objects, or that the dicts are different objects? Both? Something else?

What? Referential transparency (or the lack of it)
https://en.wikipedia.org/wiki/Referential_transparency_%28computer_science%29

Or if you like it more technical: 
Python breaks referential transparency even in the absence of assignment

[From my (cursory) reading of the wikipedia page all the 
no-transparent examples need assignment (or IO) to demo the point]

> 
> Using "is" you are demonstrating that calling the function twice returns 
> two distinct objects. That is the purpose of "is", to compare object 
> identity. Without "is", you can compare object IDs directly:
> 
> id(f()()) == id(f()())
> 
> but that's ugly and less efficient. Using "is" is the more idiomatic and 
> natural way to do this.
> 
> 
> Other than that, you could do something to demonstrate the consequences 
> of the two values being distinct objects:
> 
> a = f()()  # Call twice to get a dict.
> b = f()()
> a['key'] = 23
> b['key']  # raises KeyError
> 
> 
> or
> 
> a = f()  # Call once to get a function.
> b = f()
> a.attribute = 23
> b.attribute  # raises AttributeError
> 
> 
> Or you could inspect the byte-code of f and try to understand it.
> 
> 
> 
> > Because to me 'is' -- equivalently id -- is a code-smell 
> 
> It is only a code-smell in the sense that caring about object identity 
> should be rare.

Yes. Its good we agree on that ;-)

In the FP world referential opaqueness is the name of the devil.
In the more 'real' imperative/OO world there's way too much of it.

Finding a middle-way remains an IMHO important open problem
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script isn't producing text in data file

2014-12-10 Thread Docfxit
On Wednesday, December 10, 2014 5:45:14 PM UTC-8, Chris Angelico wrote:
> On Thu, Dec 11, 2014 at 12:32 PM,   wrote:
> > On Wednesday, December 10, 2014 3:11:28 PM UTC-8, Chris Angelico wrote:
> >> On Thu, Dec 11, 2014 at 10:04 AM, Docfxit  wrote:
> >> > This is the Python Script that I'm having trouble with:
> >> > http://theoffice.la/m/CGPLogSummaryTest.py
> >> >
> >> > If I haven't provided enough information please let me know.
> >>
> >> It'd be better to include the code in the body of your email. You
> >> never know when your hosting might go down and the code be
> >> unavailable like right now. :)
> >>
> >> ChrisA
> >
> > Also, I'm weary about clicking links to random pages.  I like to think that 
> > I can trust my computer to not let me get pwned by simply downloading and 
> > opening up a ZIP, but with Windows's history of exploits, I don't trust it.
> >
> 
> Agreed. There are ways around some of those problems (eg using wget to
> fetch something, and then looking at it in a text editor - it's hard
> to get pwned through a text editor... though I won't say impossible),
> but there are other issues too, and all in all, it's just best to
> include the text in-line.
> 
> ChrisA

I am happy to paste it into a post.  The reason I didn't is because it's very 
large.  The Python script is 1239 lines long.
The example summary is 105 lines long.
The input log is 6810 lines long.

Are you sure you want me to post all of that here?  Or would you like me to 
post it on a pastebin?

Thanks,

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


Re: Coercing two numbers without coerce()

2014-12-10 Thread Steven D'Aprano
On Wed, 10 Dec 2014 20:27:13 -0200, Luciano Ramalho wrote:

> Python 3 dropped the coerce() built-in, but I have a situation where I'd
> love to use it.
> 
> I have two numbers A, B and I need to get the value of A coerced to the
> type of A+B. This is for a generator function that will produce a series
> similar to what itertools.count does.

Let me see if I understand... you have a generator function which takes 
two arguments. For the purpose of this question, you don't actually care 
about A+B, but you want to know what type they will be so that the 
generator can return a bunch of values of that same type.

There are two ways of telling what the type of A+B will be, and only one 
of them works.

The way that doesn't work is to try to guess the result in advance. Note 
carefully that I use type(), not isinstance(), since subclasses can do 
anything they like including returning radically different types.

But for the following built-in and standard numeric types:

int, float, complex, decimal.Decimal, fractions.Fraction


we can predict the following coercions:

# X must be in the above list, *excluding* subclasses
int + X --> type of X
float + complex --> complex
Decimal + float --> raise exception
Fraction + float --> float
Fraction + complex --> complex
etc.


Whew! Not fun. And it doesn't deal with subclasses, since they could 
return any arbitrary type. And don't forget that the reversed arguments 
do not necessarily return the same type!

Really, the only way to be sure what A + B will return is to actually 
perform it and see. That will then allow subclasses to do the right thing.

the_type = type(A + B)

Now that you have the type, you can use it in you generator:

# for example
for i in range(100):
yield the_type(A + i)



> I know I can do type(A+B)(A), or A+B-B, but both alternatives are ugly
> and perform needless arithmetic.

The first is not needless, since actually adding A + B is the only way to 
find out what type A+B is in full generality.

Do not use A+B-B, since that is *not* numerically equivalent to A. Floats 
are not real numbers!

py> a = 0.01
py> b = 1e5
py> a + b - b 
0.009476131
py> a + b - b == a
False


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


Re: Python script isn't producing text in data file

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 2:30 PM, Docfxit  wrote:
> I am happy to paste it into a post.  The reason I didn't is because it's very 
> large.  The Python script is 1239 lines long.
> The example summary is 105 lines long.
> The input log is 6810 lines long.
>
> Are you sure you want me to post all of that here?  Or would you like me to 
> post it on a pastebin?

In that case, no matter where you post it, most of us are simply not
going to read it. So follow the advice that Steven linked to -
http://sscce.org/ - and make something that's actually manageable, and
then as an added bonus, it'll be small enough to post in-line.

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


Re: When do default parameters get their values set?

2014-12-10 Thread Ben Finney
Rustom Mody  writes:

> In the FP world referential opaqueness is the name of the devil.

Caring about object identity is not the same as referential opacity.

> In the more 'real' imperative/OO world there's way too much of it.

I'm very glad to be programming in the real world; there is more
achievement in solving problems here.

-- 
 \ “The power of accurate observation is frequently called |
  `\cynicism by those who don't have it.” —George Bernard Shaw |
_o__)  |
Ben Finney

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


Re: Python script isn't producing text in data file

2014-12-10 Thread Docfxit
On Wednesday, December 10, 2014 6:47:17 PM UTC-8, Steven D'Aprano wrote:
> On Wed, 10 Dec 2014 15:04:52 -0800, Docfxit wrote:
> 
> > This is the Python Script that I'm having trouble with:
> > http://theoffice.la/m/CGPLogSummaryTest.py
> 
> Link is broken:
> Steven
I'm very sorry.  I didn't mean to post that file.  It should be this link:
http://theoffice.la/m/CGPLogSummaryTest.zip

But I am happy to put it any place anyone would like.

Thank you,

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


Re: Python script isn't producing text in data file

2014-12-10 Thread Ben Finney
Docfxit  writes:

> I am happy to paste it into a post.  The reason I didn't is because
> it's very large.  The Python script is 1239 lines long.

That's too long to direct us toward, no matter where you put it.

Your task, then, is to construct a *much* smaller and simpler example
that still demonstrates the behaviour you want explained.

Once you have that, one of two things will be true:

* It will be small and clear enough that we can discuss it here
  usefully. Or

* You will have understood the problem well enough to solve it yourself.

Please, construct a Short, Self-Contained, Complete Example
http://sscce.org/> of code that exhibits the behaviour.

-- 
 \  “When cryptography is outlawed, bayl bhgynjf jvyy unir |
  `\  cevinpl.” —Anonymous |
_o__)  |
Ben Finney

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


Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Steven D'Aprano
On Wed, 10 Dec 2014 09:46:55 -0700, Ian Kelly wrote:

> I don't particularly have a problem with functions having attributes,
> e.g. I think itertools.chain.from_iterable is just peachy. There is a
> downside though, which is that making those functions attributes of
> another function rather than of the module defeats the dir() function
> for that module. 

I think you are missing the point of namespaces :-)

When I call dir(os), I see os.path, but I don't see the names in os.path. 
That is working as designed.


> Likewise the generated help for the help() function,
> unless care is taken to explicitly mention the existence of those
> functions in either the doc string for the module or the standard median
> function. 

Yes.

I don't have a problem with saying "See also ``median.low``" in the 
docstring for median.

I would also have raised a feature request (and/or patch) for having 
help() automatically display functions and methods attached to a 
function, much as it already does for classes.

As the designer of the module I thought that median_low and median_high 
were important enough to include but not important enough to stick in the 
main module namespace. I wanted to delegate them to secondary status by 
putting them in a separate lightweight namespace, without going all the 
way to making statistics be a package. I even considered doing the same 
for the population variance and standard deviation, but decided against 
it as most people are familiar with them from scientific calculators and 
school.

Python gives us the functionality to include multiple namespaces in a 
single module. Despite the Zen of Python, hardly anyone makes use of the 
fact that functions are namespaces. I wish to rail against that :-)


> Thirdly, IDEs with code completion features may simply fail to
> notice that these alternate versions of the function exist.

Hmmm, that would be a bad bug in the IDE then. If I type

foo.


I would expect the IDE to complete on whatever attributes foo has, 
regardless of whether it is a function or some other object.

I have tab completion enabled in Python 2.7, and it works for me:

py> def spam(): pass
... 
py> spam.
Display all 31 possibilities? (y or n)
spam.__call__(  spam.__globals__spam.__str__(
spam.__class__( spam.__hash__(  spam.__subclasshook__(
spam.__closure__spam.__init__(  spam.func_closure
spam.__code__   spam.__module__ spam.func_code
spam.__defaults__   spam.__name__   spam.func_defaults
spam.__delattr__(   spam.__new__(   spam.func_dict
spam.__dict__   spam.__reduce__(spam.func_doc
spam.__doc__spam.__reduce_ex__( spam.func_globals
spam.__format__(spam.__repr__(  spam.func_name
spam.__get__(   spam.__setattr__(   
spam.__getattribute__(  spam.__sizeof__(


I expect that most IDEs will Just Work in this case.

[...]
> Now if there were an established pattern to such function attributes,

But there's the rub. That's the conservatism I'm referring to. Somebody 
has to be the first to do such a thing, and if we reject it because 
nobody does it, nobody will do it because when they try they're always 
rejected.

We know namespaces are great and useful. We use namespaces in the form of 
modules, packages and classes, and the Zen says we should use more of 
them. But we don't, because we're trapped in a vicious circle where 
attempts to use more namespaces get dismissed because nobody uses them, 
and nobody uses them because when they try it gets dismissed :-(


Oh well, there's always my own non-stdlib modules :-)



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


Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Terry Reedy

On 12/10/2014 3:32 PM, Ian Kelly wrote:


So Idle gets it right. At least for static methods of classes, which
isn't very surprising. Does it complete a function attribute of a
function?


>>> def f(): pass

>>> f.a='attr'
>>> f.   as possible completion.


Having used Komodo IDE for a number of years and been occasionally
frustrated by its code completion, it would not surprise me in the least
if it failed to pull attributes of functions into its completion database.


I do not think Idle has a static database.  But I have not looked at the 
completion code yet to see exactly how it works (and how it might be 
improved).


--
Terry Jan Reedy

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


Re: Python script isn't producing text in data file

2014-12-10 Thread Docfxit
On Wednesday, December 10, 2014 7:55:17 PM UTC-8, Ben Finney wrote:
> Docfxit  writes:
> 
> > I am happy to paste it into a post.  The reason I didn't is because
> > it's very large.  The Python script is 1239 lines long.
> 
> That's too long to direct us toward, no matter where you put it.
> 
> Your task, then, is to construct a *much* smaller and simpler example
> that still demonstrates the behaviour you want explained.
> 
> Once you have that, one of two things will be true:
> 
> * It will be small and clear enough that we can discuss it here
>   usefully. Or
> 
> * You will have understood the problem well enough to solve it yourself.
> 
> Please, construct a Short, Self-Contained, Complete Example
> http://sscce.org/> of code that exhibits the behaviour.
> 
> -- 
>  \  "When cryptography is outlawed, bayl bhgynjf jvyy unir |
>   `\  cevinpl." --Anonymous |
> _o__)  |
> Ben Finney

Thank you all for the encouragement to make it smaller.
I don't know enough about Python to figure out how to isolate where the problem 
is happening.

Maybe it would be best If I could get some help in getting a debugger working 
so I can try to work through the script one line at a time.  I have started to 
install a debugger but I can't get it working.
I'm working in Win7 Pro.  I'm trying to get Winpdb working.
I have an error when I run the debugger.  It says winpdb is missing.

winpdb.py is located in:   -same version
C:\Python27\Lib\site-packages
C:\winpdb-winpdb

winpdb   is located in:
C:\winpdb-winpdb

Is winpdb supposed to be in c:\python27?

If it is, how is it supposed to get there?  (Some install?)

Thanks,

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


Re: Python script isn't producing text in data file

2014-12-10 Thread Chris Angelico
On Thu, Dec 11, 2014 at 3:23 PM, Docfxit  wrote:
> Thank you all for the encouragement to make it smaller.
> I don't know enough about Python to figure out how to isolate where the 
> problem is happening.
>
> Maybe it would be best If I could get some help in getting a debugger working 
> so I can try to work through the script one line at a time.  I have started 
> to install a debugger but I can't get it working.
> I'm working in Win7 Pro.  I'm trying to get Winpdb working.
> I have an error when I run the debugger.  It says winpdb is missing.

A debugger is a nice tool when you can get it working, but at the
moment, it sounds like you're heading down the path of yak shaving. I
would recommend taking a much MUCH simpler approach: divide and
conquer. Strip out a bunch of code, try the program again. If it still
has the problem, you know the problem wasn't in the code you just
removed. If it doesn't, you know the problem _was_ in that code. (If
you just created a brand new problem, back out the change and try
something different.)

By this method, you can usually cut a problem down to size. Sometimes
you'll find that the problem disappears when any of several pieces of
code is removed, which means it's some sort of interaction between
them; in that case, keep both, but see how much other code you can
remove. As long as the issue you're seeing is at least mostly
deterministic, this sort of technique will help you to pin it down,
even if you aren't too familiar with the language.

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


Re: Python script isn't producing text in data file

2014-12-10 Thread Ben Finney
Docfxit  writes:

> Thank you all for the encouragement to make it smaller.

Even if only for the purpose of demonstrating the behaviour that you'd
like to discuss.

This doesn't necessarily mean changing the actual program you're working
on (though it might lead to that as a benefit).

> I don't know enough about Python to figure out how to isolate where
> the problem is happening.

If so, then here's a simple brute-force method:

Begin with an empty program, and start constructing the behaviour from
scratch. Ignore anything else you want the program to do; focus only on
*this* behaviour which is confusing you.

Add only those parts which seem to be related; remove them to verify
whether they're *actually* part of the problematic behaviour.

Eventually you will have a small program which, if you take any part
away, does not exhibit the behaviour you want explained.

-- 
 \  “Properly read, the Bible is the most potent force for atheism |
  `\ever conceived.” —Isaac Asimov |
_o__)  |
Ben Finney

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


PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor

2014-12-10 Thread iMath
I think the user interface shouldn't be freezed when using 
concurrent.futures.ThreadPoolExecutor here,as it executes asynchronously ,
 but it doesn't meet my expectations,anyone can explain why ? any other 
solutions here to not let user interface freezed?

code is here
http://stackoverflow.com/questions/27393533/user-interface-freezed-when-using-concurrent-futures-threadpoolexecutor
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script isn't producing text in data file

2014-12-10 Thread Grant Edwards
On 2014-12-11, Docfxit  wrote:

> I am happy to paste it into a post.  The reason I didn't is because
> it's very large.  The Python script is 1239 lines long.  The example
> summary is 105 lines long.  The input log is 6810 lines long.
>
> Are you sure you want me to post all of that here?  Or would you
> like me to post it on a pastebin?

You're going to need to create a _short_ example program that
demonstrates the problem you're asking about.  It needs to be included
in your post and fit in _one_ screen full.  A few people will look at
longer examples, but your chances of the right person seeing it and
figuring out your problem before their internal timer (or the one on
the microwave) goes "ding!"  drop precipitously as it gets longer.
Your chances approach 0 pretty fast if it requires following a URL to
some site full of malware[1].


[1] Yes, all sites are full of malware.


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


Re: Python script isn't producing text in data file

2014-12-10 Thread Steven D'Aprano
On Wed, 10 Dec 2014 20:23:56 -0800, Docfxit wrote:

> I don't know enough about Python to figure out how to isolate where the
> problem is happening.

Ouch! You have my sympathies. Nevertheless, I'm not going to run your 
code to see what it does. Even if I trusted it, and I don't, I can see 
that it assumes that it is running on Windows (it hard-codes '\\' as a 
directory separator). I'm not running Windows.

(I think it is funny that the script has a Unix "hash-bang" line at the 
top of the script, but is written such that it will only work on Windows.)


I have some questions. The answers may guide you towards a solution.

Has this script ever worked? If so, what changed before it stopped 
working?

When you run the script, does it print any output? If so, what?

Does it write any output to the output file?

What happens if you change the global variable "testing" to True?



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


Re: Python script isn't producing text in data file

2014-12-10 Thread Grant Edwards
On 2014-12-11, Ben Finney  wrote:
> Docfxit  writes:
>
>> Thank you all for the encouragement to make it smaller.

> Begin with an empty program, and start constructing the behaviour
> from scratch. Ignore anything else you want the program to do; focus
> only on *this* behaviour which is confusing you.
>
> Add only those parts which seem to be related; remove them to verify
> whether they're *actually* part of the problematic behaviour.
>
> Eventually you will have a small program which, if you take any part
> away, does not exhibit the behaviour you want explained.

And more often than not, you will figure out the answer to your
problem while attempting to construct a suitably concise example of
your problem.

If you can clearly explain and demonstrate your problem, you're 90% of
the way to fixing it.

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


Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor

2014-12-10 Thread Michael Torrie
On 12/10/2014 09:52 PM, iMath wrote:
> I think the user interface shouldn't be freezed when using
> concurrent.futures.ThreadPoolExecutor here,as it executes
> asynchronously , but it doesn't meet my expectations,anyone can
> explain why ? any other solutions here to not let user interface
> freezed?
> 
> code is here 
> http://stackoverflow.com/questions/27393533/user-interface-freezed-when-using-concurrent-futures-threadpoolexecutor

In most any GUI framework, regardless of your use of threads, your
callbacks must return control to the main loop immediately (whether an
on-click or an on-timer event), or the GUI *will* freeze.

You are spawning threads to download the urls, then sitting there
waiting for them to finish in the callback.  Of course the GUI will
freeze; your callback is blocking it.  What you should be doing is
spawning the threads to do the download, then have the threads (using a
proper QThread mechanism or some other semaphore mechanism) raise a
signal to indicate they are done, which you will then catch in the main
loop as a normal callback.  And really when it comes to I/O and GUIs,
asynchronous calls are always better than threads.  Not sure what Qt has
in the way of asynchronous i/o calls, and I'm not familiar enough with
the various async i/o frameworks in Python to speak to that, though I
did use Python-Twisted once... very powerful once you get your head
wrapped around it.

Look through the list archives because in the last 3 or 4 weeks I and
another Python user talked proper thread use with PyQt or PySide, with
code examples.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script isn't producing text in data file

2014-12-10 Thread Tim Golden

On 11/12/2014 05:18, Steven D'Aprano wrote:

(I think it is funny that the script has a Unix "hash-bang" line at
the top of the script, but is written such that it will only work on
Windows.)


I didn't look at the code, but responding only to your comment...

Since the introduction of the PEP397 py.exe launcher in Python 3.4, it's 
made sense to put hash-bang lines into Python files on Windows 
especially if you have multiple versions installed.


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


Re: generating PDF or EPUB, which ?

2014-12-10 Thread dieter
Mohsen Pahlevanzadeh  writes:
> I need to create an RTL (Right To Left) documentation, with
> python.But i don't know which library to use.Which support RTL and
> etc.
> 
> If you any experience with pdf generating or EPUB generating please
> share me

I have used "reportlab" to generate PDF. I do not know whether
it supports RTL (likely not).

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


Re: Do you like the current design of python.org?

2014-12-10 Thread Ian Kelly
On Tue, Dec 9, 2014 at 10:16 PM, Cameron Simpson  wrote:
>  - the AA menu buttons are all dysfunctional, being purely javascript; it
would be better if the menu was styled "display=none" by default, and made
visible by javascript

With Javascript enabled, the AA menu buttons don't seem to be displayed at
all, so I don't understand what the purpose of those is.

> There are also the disappointingly common placeholder characters in
various place, for example to the left of each item in the "Socialize"
menu. These look like this:
>
>  http://plus.google.com/+Python";>Google+

I don't know what you mean. Are you saying that you see unrendered HTML to
the left of the items? All I see are icons.
-- 
https://mail.python.org/mailman/listinfo/python-list