Re: pyinstaller and Python 3.5 on Windows?

2015-11-18 Thread Ulli Horlacher
Christian Gollwitzer  wrote:
> Am 18.11.15 um 23:46 schrieb Ulli Horlacher:
> > To run my Python programs on other Windows systems without a Python
> > installation I must create standalone Windows executables.
> >
> > pyinstaller runs without any problems with Python 2.7.10 on Windows 7, but
> > with Python 3.5 I get:
> >  [stack trace]
> 
> Are you using the newest version?

Yes. Yesterday installed.


> According to http://www.pyinstaller.org/ they claim support for Python3.

Therefore my try :-)


> Does a hello world script work?

No. 
My test-program I tried to compile was:

#!/usr/bin/python

from tkinter import Tk,filedialog

askopenfilename = filedialog.askopenfilename

Tk().withdraw()
file = filedialog.askopenfilename()
print('File selected: "%s"\n' % file)


It runs directly, but I cannot compile it with pyinstaller.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about 'print' in a loop

2015-11-18 Thread dieter
fl  writes:

> Hi,
>
> From previous post, I get many helpful replies. Now I have a new question
> when I run this example code:
>
>
> -
> sq=[]
> for xx in range(5):
> print 'here'
> sq.append(lambda:xx**2)
> ...
> sq[2]()
> Out[151]: 16
>
> sq[3]()
> Out[152]: 16
> /

Same reason as in your previous thread: variables in (the body of) function
definitions (and "lambda"s, which are functions definitions, too) are
resolved/dereferenced at call time, not at function definition time.

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


Re: Could you explain why the following generates 4 same elements list?

2015-11-18 Thread dieter
fl  writes:

> Hi,
>
> I cannot reason out why the code:
> 
> def mpl():
> return [lambda x : i * x for i in range(4)]
> 
> print [m(2) for m in mpl()]
> /
>
> has result:
>
> [6, 6, 6, 6]

The "i" in your lambda definition is a variable reference which
is not dereferenced (i.e. name replaced by the value) at definition
but only at call time. Thus, all your "lambda"s are in fact equal;
they all look up the current value of "i" when they are called
(which happens to be "3").

To avoid this, you must force the dereferencing at definition time.
This could look like:

 return [lambda x, i=i: i * x for i in range(4)]

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


Re: pyinstaller and Python 3.5 on Windows?

2015-11-18 Thread Christian Gollwitzer

Am 18.11.15 um 23:46 schrieb Ulli Horlacher:

To run my Python programs on other Windows systems without a Python
installation I must create standalone Windows executables.

pyinstaller runs without any problems with Python 2.7.10 on Windows 7, but
with Python 3.5 I get:
 [stack trace]


Are you using the newest version? According to 
http://www.pyinstaller.org/ they claim support for Python3. Does a hello 
world script work? If yes, it may have to do with some packages in your 
script. Is pywin32 a package that you load, or is it Pyinstaller that 
needs this?


Christian

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


Re: Question about 'print' in a loop

2015-11-18 Thread fl
On Wednesday, November 18, 2015 at 10:11:24 PM UTC-5, Chris Angelico wrote:
> On Thu, Nov 19, 2015 at 1:55 PM, fl  wrote:
> > There are only one time 5 'here' printed out, but there is no 'here' print
> > out in thereafter call sq[2]() etc. How to understand this phenomenon?
> 
> Code does what code should.
> 
> Before you ask for comprehension of "this phenomenon", why don't you
> tell us what you expect your code to do, and why? I just asked my
> non-programmer sister and she was completely unsurprised by what
> Python did here.
> 
> ChrisA

Excuse me. That is my unclear question.
I expect that each call sq will have one print 'here', as I suppose that
print 'here' is inside the loop.

Oh, I just realize that it is not a function. It constructs list sq.
When the loop (function as a constructor (not necessarily correct called),
it print 5 'here'.

Thanks for you feedback.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about 'print' in a loop

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 1:55 PM, fl  wrote:
> There are only one time 5 'here' printed out, but there is no 'here' print
> out in thereafter call sq[2]() etc. How to understand this phenomenon?

Code does what code should.

Before you ask for comprehension of "this phenomenon", why don't you
tell us what you expect your code to do, and why? I just asked my
non-programmer sister and she was completely unsurprised by what
Python did here.

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


Question about 'print' in a loop

2015-11-18 Thread fl
Hi,

>From previous post, I get many helpful replies. Now I have a new question
when I run this example code:


-
sq=[]
for xx in range(5):
print 'here'
sq.append(lambda:xx**2)

here
here
here
here
here

xx
Out[150]: 4

sq[2]()
Out[151]: 16

sq[3]()
Out[152]: 16
/

There are only one time 5 'here' printed out, but there is no 'here' print
out in thereafter call sq[2]() etc. How to understand this phenomenon?

Thanks,

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


Re: Public key encryption example.

2015-11-18 Thread Vincent Davis
Found an example, needs a little updating but then it works (appears to) in
python 3.5.
http://coding4streetcred.com/blog/post/Asymmetric-Encryption-Revisited-(in-PyCrypto)

Vincent Davis
720-301-3003

On Wed, Nov 18, 2015 at 5:04 PM, Chris Angelico  wrote:

> On Thu, Nov 19, 2015 at 10:56 AM, Paul Rubin 
> wrote:
> > Vincent Davis  writes:
> >> I am looking for the "simplest" example of sending(encrypting) and
> >> receiving(decrypting) using public key encryption. I am think of
> something
> >> along the lines of having all the keys in local files and saving and
> >> reading the message from a local file.
> >
> > It's very easy to make mistakes doing stuff like that.  Your simplest
> > bet is to shell out to GPG or something comparable.
>
> It's not that hard to pull up a library. I've never done it in Python,
> though.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a function parameter =[] for?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 1:08 PM, Ben Finney  wrote:
>> Nope. Mutable objects are never guaranteed to retain the same values.
>> That's kinda the point.
>
> Well, they are the *same value*, if by “value” you mean “a particular
> object”.
>
> On the other hand, the value can *change* over time, while remaining the
> same object. So it will not be equal to its initial state, even though
> it is the same object.

I would normally interpret "value" as "the quality compared with the
== operator". As such, mutables can change in value while retaining
their identities:

>>> x, y = [], []
>>> x == y
True
>>> x.append(1)
>>> x == y
False
>>> y.append(1)
>>> x == y
True

So a mutable default argument will always retain its identity (barring
shenanigans), but may not retain its value.

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


Re: What is a function parameter =[] for?

2015-11-18 Thread Ben Finney
Chris Angelico  writes:

> On Thu, Nov 19, 2015 at 12:41 PM, BartC  wrote:
> > On 18/11/2015 23:22, Chris Angelico wrote:
> >> On the contrary, it is certain always to be that exact object.
> >
> > But, not the same value that appears as the default?

It depends what you mean by “the same value”.

> Nope. Mutable objects are never guaranteed to retain the same values.
> That's kinda the point.

Well, they are the *same value*, if by “value” you mean “a particular
object”.

On the other hand, the value can *change* over time, while remaining the
same object. So it will not be equal to its initial state, even though
it is the same object.

-- 
 \ “[F]reedom of speech does not entail freedom to have your ideas |
  `\accepted by governments and incorporated into law and policy.” |
_o__)   —Russell Blackford, 2010-03-06 |
Ben Finney

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


Re: What is a function parameter =[] for?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 12:41 PM, BartC  wrote:
> On 18/11/2015 23:22, Chris Angelico wrote:
>> On the contrary, it is certain always to be that exact object.
>
> But, not the same value that appears as the default?

Nope. Mutable objects are never guaranteed to retain the same values.
That's kinda the point.

> Sorry, I didn't understand any of that. Let's try a simpler example like the
> OP's. There's this innocuous looking function that you are interested in
> calling:
>
>  def fn(a=[]):
>  #   print ("Function fn called with",a)
>  |   a.append(10)
>  |   return a
>
> It appends a value to its argument and returns the result.
>
> It looks like at first like, if called with no argument, it will return
> [10].

If you want to think of function defaults as being values, then yes.
But they're not. They're objects.

> But what it actually returns depends on the entire call history since the
> program started executing, something you probably have no knowledge of and
> no control over. So if fn has previously been called a million times with no
> argument, then after this call:
>
>  x=fn()
>
> x contains a list of a million tens, not one. I'd say most people would be
> rather surprised by that.

So if you don't want them to be surprised by that, don't use mutable
default arguments and expect them to have specific values.

> I suspect those same people (unless they are experts in the murky corners of
> the language) would expect:
>
>   x=fn()
>
> when fn specifies a default argument of [], to be the same as writing:
>
>   x=fn([])
>
> and not be dependent on fn's entire call history.

Tell me, do you expect these to do the same thing?

x = []
fn(x)
fn(x)
fn(x)

# or

fn([])
fn([])
fn([])

The distinction is exactly the same. If you can understand that the
first one constructs a single object and uses it three times, then you
should be able to understand that the function default is also
constructed once and used every time.

> Your solution of using:
>
>   def fn(a=None):
>
> is not really satisfactory. Partly because it now utilities two mechanisms
> for the default: first to get None, then some extra code to get []. But also
> it's no longer obvious how the function works and what the default is. At
> least, you can't tell from a glance at the start of the function that [] is
> the default.

This I do agree with. It's a bit clunky. It would be nice to be able to say:

def fn(a=`[]`):
"""If a is not passed, it will be a new empty list"""

and have it function the same as:

def fn(*args):
a = args[0] if args else []

but currently there's no mechanism for it. (The example spelling I
gave is almost certainly not going to be used, due to the Tim Peters'
Monitor Grit argument, but something could probably be found.) It's a
sufficiently common situation that it would merit its own syntax. Want
to write up a PEP? All you need is a syntax that people can get
behind.

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


Re: What is a function parameter =[] for?

2015-11-18 Thread BartC

On 18/11/2015 23:22, Chris Angelico wrote:

On Thu, Nov 19, 2015 at 10:14 AM, BartC  wrote:

On 18/11/2015 22:11, Ian Kelly wrote:


On Wed, Nov 18, 2015 at 2:08 PM, fl  wrote:


Hi,

I have tried the below function and find that it can remember the
previous
setting value to 'val'. I think the second parameter has something on
this
effect, but I don't know the name and function of '=[]' in this
application.

Could you explain a little to me?
Thanks,


def eList(val, list0=[]):
  list0.append(val)
  return list0
list1 = eList(12)
list1 = eList('a')



The list0 parameter has a default value, which is [], an initially
empty list. The default value is evaluated when the function is
defined, not when it is called, so the same list object is used each
time and changes to the list are consequently retained between calls.



That is really bizarre behaviour.

So, looking at some source code, a default value for certain types is only
certain to be that value for the very first call of that function?


On the contrary, it is certain always to be that exact object.


But, not the same value that appears as the default?

 >>> The default value is evaluated when the function is

defined, not when it is called


Given the amount of pointless dynamic stuff that goes on in Python, I'm
surprised they've overlooked this one!

It seems simple enough to me to check for a missing parameter, and to assign
whatever default value was designated ([] in this case). (How does the
default mechanism work now?)


It's exactly the way Ian described it. Functions are defined, not
declared - it's an executable statement. When the 'def' statement is
reached, the expressions in the argument defaults get evaluated, and
the results get saved into the function's attributes:



Sorry, I didn't understand any of that. Let's try a simpler example like 
the OP's. There's this innocuous looking function that you are 
interested in calling:


 def fn(a=[]):
 #   print ("Function fn called with",a)
 |   a.append(10)
 |   return a

It appends a value to its argument and returns the result.

It looks like at first like, if called with no argument, it will return 
[10].


But what it actually returns depends on the entire call history since 
the program started executing, something you probably have no knowledge 
of and no control over. So if fn has previously been called a million 
times with no argument, then after this call:


 x=fn()

x contains a list of a million tens, not one. I'd say most people would 
be rather surprised by that.


I suspect those same people (unless they are experts in the murky 
corners of the language) would expect:


  x=fn()

when fn specifies a default argument of [], to be the same as writing:

  x=fn([])

and not be dependent on fn's entire call history.

Your solution of using:

  def fn(a=None):

is not really satisfactory. Partly because it now utilities two 
mechanisms for the default: first to get None, then some extra code to 
get []. But also it's no longer obvious how the function works and what 
the default is. At least, you can't tell from a glance at the start of 
the function that [] is the default.


--
Bartc


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


Re: What is a function parameter =[] for?

2015-11-18 Thread Ben Finney
MRAB  writes:

> On 2015-11-19 00:34, fl wrote:
> > What does 'del' do? It does not look like a thorough list deletion
> > from the effect.
>
> No, "del list1" doesn't delete the list, it deletes the name "list1".
> The list still exists as the default parameter.

More generally, ‘del’ deletes a *reference*. Names are one kind of
reference; others include items in a collection such as a dict or set.

Deleting a reference *never* affects the value referred to.

However, once a value has no more references, the program can no longer
access it, so the Python machine is at liberty to delete the value
behind the scenes at some future point.

> A default parameter is evaluated when the function is defined, and
> that value exists as the default as long as the function exists.

So, because the function retains a reference to the value, the value
remains unaffected when you delete the reference ‘list1’.

-- 
 \ “True greatness is measured by how much freedom you give to |
  `\  others, not by how much you can coerce others to do what you |
_o__)   want.” —Larry Wall |
Ben Finney

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


Re: What is a function parameter =[] for?

2015-11-18 Thread MRAB

On 2015-11-19 00:34, fl wrote:

On Wednesday, November 18, 2015 at 7:15:05 PM UTC-5, Chris Angelico wrote:

On Thu, Nov 19, 2015 at 11:02 AM, Ian Kelly  wrote:
> On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico  wrote:
>> On Thu, Nov 19, 2015 at 10:14 AM, BartC  wrote:
>>> So, looking at some source code, a default value for certain types is only
>>> certain to be that value for the very first call of that function?
>>
>> On the contrary, it is certain always to be that exact object.
>
> "Certain" may be a bit overly strong.
>
 def f(x=42):
> ...   return x
> ...
 f()
> 42
 f.__defaults__ = (43,)
 f()
> 43

I'll raise you one.

>>> def f(x=42):
... return x
...
>>> f()
42
>>> import ctypes
>>> ctypes.c_int.from_address(id(43)+ ctypes.sizeof(ctypes.c_size_t) + 
ctypes.sizeof(ctypes.c_voidp)).value=42
>>> f.__defaults__ = (43,)
>>> f()
42
>>>

Nothing is certain in Python. And two wrongs can make a... hmm... no,
this is not a right. It is not a privilege either. It is a dastardly
trick played on people's minds.

ChrisA


After I try with

list1 = eList(12, [2])


If you pass something into the parameter, the default isn't needed/used.


and

list1 = eList(12)


You're not passing anything into the parameter, so the default is used.


it gives me new surprises. Even though I delete list1, the subsequent
list1 = eList(12)
will remember the number of '12' of the previous sequence. This is my new
question: What does 'del' do? It does not look like a thorough list deletion
  from the effect.


No, "del list1" doesn't delete the list, it deletes the name "list1".
The list still exists as the default parameter.

A default parameter is evaluated when the function is defined, and that
value exists as the default as long as the function exists.

If the value is mutable (can be modified), and you modify it, then the
function will see that modified value.

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


Re: What is a function parameter =[] for?

2015-11-18 Thread Ian Kelly
On Wed, Nov 18, 2015 at 5:34 PM, fl  wrote:
> After I try with
>
> list1 = eList(12, [2])
>
> and
>
> list1 = eList(12)
>
> it gives me new surprises. Even though I delete list1, the subsequent
> list1 = eList(12)
> will remember the number of '12' of the previous sequence. This is my new
> question: What does 'del' do? It does not look like a thorough list deletion
>  from the effect.

It just deletes the variable list1, i.e. it unbinds the value from the
name. It does nothing at all to the list that was bound, as other
variables may still be bound to it.

The core issue is that the default value of your eList function is
always the same list. Assigning that list to a variable and then
unassigning it is not going to change that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Could you explain why the following generates 4 same elements list?

2015-11-18 Thread Ian Kelly
On Wed, Nov 18, 2015 at 5:05 PM, fl  wrote:
> Hi,
>
> I cannot reason out why the code:
> 
> def mpl():
> return [lambda x : i * x for i in range(4)]
>
> print [m(2) for m in mpl()]
> /
>
> has result:
>
> [6, 6, 6, 6]
>
>
> I have tried to simplify the above code to an easy understanding form,
> but fails. Either the modified code does not work, or it does not show
> relation to the original code.
>
> Could you explore it a little for me to understand it easier?

https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a function parameter =[] for?

2015-11-18 Thread fl
On Wednesday, November 18, 2015 at 7:15:05 PM UTC-5, Chris Angelico wrote:
> On Thu, Nov 19, 2015 at 11:02 AM, Ian Kelly  wrote:
> > On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico  wrote:
> >> On Thu, Nov 19, 2015 at 10:14 AM, BartC  wrote:
> >>> So, looking at some source code, a default value for certain types is only
> >>> certain to be that value for the very first call of that function?
> >>
> >> On the contrary, it is certain always to be that exact object.
> >
> > "Certain" may be a bit overly strong.
> >
>  def f(x=42):
> > ...   return x
> > ...
>  f()
> > 42
>  f.__defaults__ = (43,)
>  f()
> > 43
> 
> I'll raise you one.
> 
> >>> def f(x=42):
> ... return x
> ...
> >>> f()
> 42
> >>> import ctypes
> >>> ctypes.c_int.from_address(id(43)+ ctypes.sizeof(ctypes.c_size_t) + 
> >>> ctypes.sizeof(ctypes.c_voidp)).value=42
> >>> f.__defaults__ = (43,)
> >>> f()
> 42
> >>>
> 
> Nothing is certain in Python. And two wrongs can make a... hmm... no,
> this is not a right. It is not a privilege either. It is a dastardly
> trick played on people's minds.
> 
> ChrisA

After I try with

list1 = eList(12, [2])

and

list1 = eList(12)

it gives me new surprises. Even though I delete list1, the subsequent
list1 = eList(12)
will remember the number of '12' of the previous sequence. This is my new
question: What does 'del' do? It does not look like a thorough list deletion
 from the effect.

Thanks,

.
list1 = eList(12, [2])

list1
Out[57]: [2, 12]

list1 = eList(12)

list1
Out[59]: [12, 12, 12]

list1 = eList(12, [2])

list1
Out[61]: [2, 12]

list1 = eList(12, [2])

list1
Out[63]: [2, 12]

list1 = eList(12, [2])

list1
Out[65]: [2, 12]

list1 = eList(12)

list1
Out[67]: [12, 12, 12, 12]

list1 = eList(12)

list1
Out[69]: [12, 12, 12, 12, 12]

list1 = eList(12, [2])

list1
Out[71]: [2, 12]

list1 = eList(12)

list1
Out[73]: [12, 12, 12, 12, 12, 12]

del list1

list1 = eList(12, [2])

list1 = eList(12)

list1
Out[77]: [12, 12, 12, 12, 12, 12, 12]

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


Re: pyinstaller and Python 3.5 on Windows?

2015-11-18 Thread Thomas 'PointedEars' Lahn
Ulli Horlacher wrote:

> To run my Python programs on other Windows systems without a Python
> installation I must create standalone Windows executables.
> 
> pyinstaller runs without any problems with Python 2.7.10 on Windows 7, but
> with Python 3.5 I get:
> 
> [b0rked stack trace]
> 
> Is there a solution available?

Maybe.  It would help if you posted something easier readable.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a function parameter =[] for?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 11:02 AM, Ian Kelly  wrote:
> On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico  wrote:
>> On Thu, Nov 19, 2015 at 10:14 AM, BartC  wrote:
>>> So, looking at some source code, a default value for certain types is only
>>> certain to be that value for the very first call of that function?
>>
>> On the contrary, it is certain always to be that exact object.
>
> "Certain" may be a bit overly strong.
>
 def f(x=42):
> ...   return x
> ...
 f()
> 42
 f.__defaults__ = (43,)
 f()
> 43

I'll raise you one.

>>> def f(x=42):
... return x
...
>>> f()
42
>>> import ctypes
>>> ctypes.c_int.from_address(id(43)+ ctypes.sizeof(ctypes.c_size_t) + 
>>> ctypes.sizeof(ctypes.c_voidp)).value=42
>>> f.__defaults__ = (43,)
>>> f()
42
>>>

Nothing is certain in Python. And two wrongs can make a... hmm... no,
this is not a right. It is not a privilege either. It is a dastardly
trick played on people's minds.

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


Could you explain why the following generates 4 same elements list?

2015-11-18 Thread fl
Hi,

I cannot reason out why the code:

def mpl():
return [lambda x : i * x for i in range(4)]

print [m(2) for m in mpl()]
/

has result:

[6, 6, 6, 6]


I have tried to simplify the above code to an easy understanding form,
but fails. Either the modified code does not work, or it does not show
relation to the original code.
 
Could you explore it a little for me to understand it easier?

Thanks in advance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Public key encryption example.

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 10:56 AM, Paul Rubin  wrote:
> Vincent Davis  writes:
>> I am looking for the "simplest" example of sending(encrypting) and
>> receiving(decrypting) using public key encryption. I am think of something
>> along the lines of having all the keys in local files and saving and
>> reading the message from a local file.
>
> It's very easy to make mistakes doing stuff like that.  Your simplest
> bet is to shell out to GPG or something comparable.

It's not that hard to pull up a library. I've never done it in Python, though.

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


Re: What is a function parameter =[] for?

2015-11-18 Thread Ian Kelly
On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico  wrote:
> On Thu, Nov 19, 2015 at 10:14 AM, BartC  wrote:
>> So, looking at some source code, a default value for certain types is only
>> certain to be that value for the very first call of that function?
>
> On the contrary, it is certain always to be that exact object.

"Certain" may be a bit overly strong.

>>> def f(x=42):
...   return x
...
>>> f()
42
>>> f.__defaults__ = (43,)
>>> f()
43
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Public key encryption example.

2015-11-18 Thread Paul Rubin
Vincent Davis  writes:
> I am looking for the "simplest" example of sending(encrypting) and
> receiving(decrypting) using public key encryption. I am think of something
> along the lines of having all the keys in local files and saving and
> reading the message from a local file.

It's very easy to make mistakes doing stuff like that.  Your simplest
bet is to shell out to GPG or something comparable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a function parameter =[] for?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 10:14 AM, BartC  wrote:
> On 18/11/2015 22:11, Ian Kelly wrote:
>>
>> On Wed, Nov 18, 2015 at 2:08 PM, fl  wrote:
>>>
>>> Hi,
>>>
>>> I have tried the below function and find that it can remember the
>>> previous
>>> setting value to 'val'. I think the second parameter has something on
>>> this
>>> effect, but I don't know the name and function of '=[]' in this
>>> application.
>>>
>>> Could you explain a little to me?
>>> Thanks,
>>>
>>>
>>> def eList(val, list0=[]):
>>>  list0.append(val)
>>>  return list0
>>> list1 = eList(12)
>>> list1 = eList('a')
>>
>>
>> The list0 parameter has a default value, which is [], an initially
>> empty list. The default value is evaluated when the function is
>> defined, not when it is called, so the same list object is used each
>> time and changes to the list are consequently retained between calls.
>
>
> That is really bizarre behaviour.
>
> So, looking at some source code, a default value for certain types is only
> certain to be that value for the very first call of that function?

On the contrary, it is certain always to be that exact object.

>> The default value is evaluated when the function is
>> defined, not when it is called
>
> Given the amount of pointless dynamic stuff that goes on in Python, I'm
> surprised they've overlooked this one!
>
> It seems simple enough to me to check for a missing parameter, and to assign
> whatever default value was designated ([] in this case). (How does the
> default mechanism work now?)

It's exactly the way Ian described it. Functions are defined, not
declared - it's an executable statement. When the 'def' statement is
reached, the expressions in the argument defaults get evaluated, and
the results get saved into the function's attributes:

>>> def demo(factory):
... def func(x=factory()):
... x.append("Hello!")
... return x
... return func
...
>>> def make_list():
... print("I'm making a list!")
... return []
...
>>> f1 = demo(make_list)
I'm making a list!
>>> f2 = demo(make_list)
I'm making a list!
>>> f3 = demo(make_list)
I'm making a list!
>>> f1()
['Hello!']
>>> f1()
['Hello!', 'Hello!']
>>> f1()
['Hello!', 'Hello!', 'Hello!']
>>> f2()
['Hello!']
>>> f2()
['Hello!', 'Hello!']
>>> f3()
['Hello!']
>>> f1.__defaults__
(['Hello!', 'Hello!', 'Hello!'],)
>>> id(f1())
140470001247688
>>> id(f1())
140470001247688
>>> id(f1())
140470001247688
>>> id(f1())
140470001247688
>>> id(f1())
140470001247688
>>> id(f1.__defaults__[0])
140470001247688

If you want the expression (eg the empty list display) to be evaluated
every time the body of the function is executed, you put it into the
body of the function. There is no magic here.

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


Public key encryption example.

2015-11-18 Thread Vincent Davis
This might be a "Let me Google that for you question", I tried.
I am looking for the "simplest" example of sending(encrypting) and
receiving(decrypting) using public key encryption. I am think of something
along the lines of having all the keys in local files and saving and
reading the message from a local file.

Possibly using cryptography library elliptic-curve
https://cryptography.io/en/latest/hazmat/primitives/asymmetric/ec/#elliptic-curve-signature-algorithms

Surly there is an example out there?

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


Re: What is a function parameter =[] for?

2015-11-18 Thread BartC

On 18/11/2015 22:11, Ian Kelly wrote:

On Wed, Nov 18, 2015 at 2:08 PM, fl  wrote:

Hi,

I have tried the below function and find that it can remember the previous
setting value to 'val'. I think the second parameter has something on this
effect, but I don't know the name and function of '=[]' in this application.

Could you explain a little to me?
Thanks,


def eList(val, list0=[]):
 list0.append(val)
 return list0
list1 = eList(12)
list1 = eList('a')


The list0 parameter has a default value, which is [], an initially
empty list. The default value is evaluated when the function is
defined, not when it is called, so the same list object is used each
time and changes to the list are consequently retained between calls.


That is really bizarre behaviour.

So, looking at some source code, a default value for certain types is 
only certain to be that value for the very first call of that function?


> The default value is evaluated when the function is
> defined, not when it is called

Given the amount of pointless dynamic stuff that goes on in Python, I'm 
surprised they've overlooked this one!


It seems simple enough to me to check for a missing parameter, and to 
assign whatever default value was designated ([] in this case). (How 
does the default mechanism work now?)


--
Bartc

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


pyinstaller and Python 3.5 on Windows?

2015-11-18 Thread Ulli Horlacher
To run my Python programs on other Windows systems without a Python
installation I must create standalone Windows executables.

pyinstaller runs without any problems with Python 2.7.10 on Windows 7, but
with Python 3.5 I get:

S:\python>pyinstaller.exe --onefile tk.py
Traceback (most recent call last):
  File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in 
load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, in l
oad_entry_point
return get_distribution(dist).load_entry_point(group, name)
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2682, in
load_entry_point
return ep.load()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2355, in
load
return self.resolve()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2361, in
resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "c:\python35\lib\site-packages\PyInstaller\__main__.py", line 21, in 
import PyInstaller.building.build_main
  File "c:\python35\lib\site-packages\PyInstaller\building\build_main.py", line
31, in 
from ..depend import bindepend
  File "c:\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 40,
 in 
from ..utils.win32.winmanifest import RT_MANIFEST
  File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l
ine 97, in 
from PyInstaller.utils.win32 import winresource
  File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winresource.py", l
ine 20, in 
import pywintypes
  File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in 
__import_pywin32_system_module__("pywintypes", globals())
  File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 64, in __im
port_pywin32_system_module__
import _win32sysloader
ImportError: DLL load failed: The specified module could not be found.


Is there a solution available?



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a function parameter =[] for?

2015-11-18 Thread fl
On Wednesday, November 18, 2015 at 5:38:45 PM UTC-5, fl wrote:
> On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote:
> > On Wed, Nov 18, 2015 at 2:08 PM, fl  wrote:
> > > Hi,
> > >
> > > I have tried the below function and find that it can remember the previous
> > > setting value to 'val'. I think the second parameter has something on this
> > > effect, but I don't know the name and function of '=[]' in this 
> > > application.
> > >
> > > Could you explain a little to me?
> > > Thanks,
> > >
> > >
> > > def eList(val, list0=[]):
> > > list0.append(val)
> > > return list0
> > > list1 = eList(12)
> > > list1 = eList('a')
> > 
> > The list0 parameter has a default value, which is [], an initially
> > empty list. The default value is evaluated when the function is
> > defined, not when it is called, so the same list object is used each
> > time and changes to the list are consequently retained between calls.
> 
> Thanks. The amazing thing to me is that the following two line codes:
> list1 = eList(12) 
> list2 = eList('a')
> 
> will have both list1 and list2 the same cascaded values:
> 
> list1
> Out[2]: [12, 'a']
> 
> list2
> Out[3]: [12, 'a']
> 
> I have known object concept in Python.
> 1. Why do they have the same list value?
>  Function eList must be for this purpose?
> 2. If I want to have two separate lists, how to avoid the above result?
>  Function eList is not for this purpose?
> 
> Thanks again.

After several trials, I find that the cascade list is caused by the second
function parameter absent. It is interesting. Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a function parameter =[] for?

2015-11-18 Thread Ian Kelly
On Wed, Nov 18, 2015 at 3:38 PM, fl  wrote:
> On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote:
>> On Wed, Nov 18, 2015 at 2:08 PM, fl  wrote:
>> > Hi,
>> >
>> > I have tried the below function and find that it can remember the previous
>> > setting value to 'val'. I think the second parameter has something on this
>> > effect, but I don't know the name and function of '=[]' in this 
>> > application.
>> >
>> > Could you explain a little to me?
>> > Thanks,
>> >
>> >
>> > def eList(val, list0=[]):
>> > list0.append(val)
>> > return list0
>> > list1 = eList(12)
>> > list1 = eList('a')
>>
>> The list0 parameter has a default value, which is [], an initially
>> empty list. The default value is evaluated when the function is
>> defined, not when it is called, so the same list object is used each
>> time and changes to the list are consequently retained between calls.
>
> Thanks. The amazing thing to me is that the following two line codes:
> list1 = eList(12)
> list2 = eList('a')
>
> will have both list1 and list2 the same cascaded values:
>
> list1
> Out[2]: [12, 'a']
>
> list2
> Out[3]: [12, 'a']
>
> I have known object concept in Python.
> 1. Why do they have the same list value?
>  Function eList must be for this purpose?

Because eList returns list0, and as explained above list0 is the same
list in both calls. Therefore list1 and list2 are the same list.

> 2. If I want to have two separate lists, how to avoid the above result?
>  Function eList is not for this purpose?

The usual advice is to not use a mutable object as the default value.
If you want the default to be an empty list, it's usually better set
it to None and then make it an empty list if the value is None. For
example:

def eList(val, list0=None):
if list0 is None:
list0 = []
list0.append(val)
return list0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: handling of non-ASCII filenames?

2015-11-18 Thread Ulli Horlacher
Chris Angelico  wrote:

> >> If you can use Python 3
> >
> > I cannot use it, because the Python compiler pyinstaller does not work
> > with it on Windows:
> >
> > S:\python>pyinstaller.exe --onefile tk.py
> > Traceback (most recent call last):
> >   File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in 
> > load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')()
> >   File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, 
> > in l
> > oad_entry_point
(...)
> >
> > With python 2.7, pyinstaller runs without problems.
> 
> Hmm. That's a separate consideration. If you take a step back and ask
> the broader question "How can I package my Python 3.5 script into a
> .exe file?", I'm pretty sure there is an answer; maybe pyinstaller
> isn't the way to do it. (I'm not an expert on exe file production.)

pyinstaller works without any problems with Python 2.7.10


> Does your script run happily in 3.5 if it isn't packaged into an exe?

Yes.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a function parameter =[] for?

2015-11-18 Thread fl
On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote:
> On Wed, Nov 18, 2015 at 2:08 PM, fl  wrote:
> > Hi,
> >
> > I have tried the below function and find that it can remember the previous
> > setting value to 'val'. I think the second parameter has something on this
> > effect, but I don't know the name and function of '=[]' in this application.
> >
> > Could you explain a little to me?
> > Thanks,
> >
> >
> > def eList(val, list0=[]):
> > list0.append(val)
> > return list0
> > list1 = eList(12)
> > list1 = eList('a')
> 
> The list0 parameter has a default value, which is [], an initially
> empty list. The default value is evaluated when the function is
> defined, not when it is called, so the same list object is used each
> time and changes to the list are consequently retained between calls.

Thanks. The amazing thing to me is that the following two line codes:
list1 = eList(12) 
list2 = eList('a')

will have both list1 and list2 the same cascaded values:

list1
Out[2]: [12, 'a']

list2
Out[3]: [12, 'a']

I have known object concept in Python.
1. Why do they have the same list value?
 Function eList must be for this purpose?
2. If I want to have two separate lists, how to avoid the above result?
 Function eList is not for this purpose?

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


Re: What is a function parameter =[] for?

2015-11-18 Thread Grant Edwards
On 2015-11-18, Ian Kelly  wrote:
> On Wed, Nov 18, 2015 at 2:08 PM, fl  wrote:

>> def eList(val, list0=[]):

> The list0 parameter has a default value, which is [], an initially
> empty list. The default value is evaluated when the function is
> defined, not when it is called, so the same list object is used each
> time and changes to the list are consequently retained between calls.

One might consider this a way to have a local varible inside a
function that's "static" a-la C.  However, one probably oughtn't.

-- 
Grant Edwards   grant.b.edwardsYow! Gibble, Gobble, we
  at   ACCEPT YOU ...
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a function parameter =[] for?

2015-11-18 Thread Ian Kelly
On Wed, Nov 18, 2015 at 2:08 PM, fl  wrote:
> Hi,
>
> I have tried the below function and find that it can remember the previous
> setting value to 'val'. I think the second parameter has something on this
> effect, but I don't know the name and function of '=[]' in this application.
>
> Could you explain a little to me?
> Thanks,
>
>
> def eList(val, list0=[]):
> list0.append(val)
> return list0
> list1 = eList(12)
> list1 = eList('a')

The list0 parameter has a default value, which is [], an initially
empty list. The default value is evaluated when the function is
defined, not when it is called, so the same list object is used each
time and changes to the list are consequently retained between calls.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is a function parameter =[] for?

2015-11-18 Thread John Gordon
In  fl 
 writes:

> Hi,

> I have tried the below function and find that it can remember the previous
> setting value to 'val'. I think the second parameter has something on this 
> effect, but I don't know the name and function of '=[]' in this application.

> Could you explain a little to me?
> Thanks,

> def eList(val, list0=[]):
> list0.append(val)
> return list0
> list1 = eList(12)
> list1 = eList('a')

That is a default parameter.  If eList() is called without an argument for
list0, it will use [] as the default value.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: How to create a folder using IMAPLib?

2015-11-18 Thread Laura Creighton
In a message of Thu, 19 Nov 2015 07:35:36 +1100, Chris Angelico writes:
>On Thu, Nov 19, 2015 at 7:01 AM, Anthony Papillion
> wrote:
>> I'm writing a program to help migrate mail from one host to another
>> with a few special circumstances. I'm able to get a list off of the
>> source IMAP server using the .list() command but I'm not quite sure
>> how to create a folder on the target machine.
>>
>> Does anyone know how to create a folder using IMAPlib?
>
>They're called "mailboxes", which I'll admit is not the most obvious
>name, but imaplib is following the IMAP spec here. You can create them
>with .create() and delete them with .delete().
>
>ChrisA
>-- 
>https://mail.python.org/mailman/listinfo/python-list

Sample code here:
https://pymotw.com/2/imaplib/

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


Re: How can I export data from a website and write the contents to a text file?

2015-11-18 Thread Random832
ryguy7272  writes:
> text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb")

Remove the "b" from this line. This is causing it to omit the
platform-specific translation of "\n", which means some Windows
applications will not recognize the line endings.

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


What is a function parameter =[] for?

2015-11-18 Thread fl
Hi,

I have tried the below function and find that it can remember the previous
setting value to 'val'. I think the second parameter has something on this 
effect, but I don't know the name and function of '=[]' in this application.

Could you explain a little to me?
Thanks,


def eList(val, list0=[]):
list0.append(val)
return list0
list1 = eList(12)
list1 = eList('a')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to create a folder using IMAPLib?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 7:01 AM, Anthony Papillion
 wrote:
> I'm writing a program to help migrate mail from one host to another
> with a few special circumstances. I'm able to get a list off of the
> source IMAP server using the .list() command but I'm not quite sure
> how to create a folder on the target machine.
>
> Does anyone know how to create a folder using IMAPlib?

They're called "mailboxes", which I'll admit is not the most obvious
name, but imaplib is following the IMAP spec here. You can create them
with .create() and delete them with .delete().

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


Re: handling of non-ASCII filenames?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 5:09 AM, Ulli Horlacher
 wrote:
> Chris Angelico  wrote:
>
>> > As I am Python newbie I have not quite understood the Python character
>> > encoding scheme :-}
>> >
>> > Where can I find a good introduction of this topic?
>>
>> Here are a couple of articles on the basics of Unicode:
>>
>> http://www.joelonsoftware.com/articles/Unicode.html
>
> I do Unicode programming for over 20 years. So, I do have a basic
> understanding of it. I am just new to Python.

Ah, okay. When you said you didn't understand the character encoding
scheme, I thought you meant Unicode itself. In any case, I make no
apology for recommending those two articles to people... at very worst
you already know that stuff :)

>> http://nedbatchelder.com/text/unipain.html
>
> Thanks. I will read it.

That's a great talk, and has the coolness of having zero pictures on
its slides. I love it.

>> If you can use Python 3
>
> I cannot use it, because the Python compiler pyinstaller does not work
> with it on Windows:
>
> S:\python>pyinstaller.exe --onefile tk.py
> Traceback (most recent call last):
>   File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in 
> load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')()
>   File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, 
> in l
> oad_entry_point
> return get_distribution(dist).load_entry_point(group, name)
>   File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2682, 
> in
> load_entry_point
> return ep.load()
>   File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2355, 
> in
> load
> return self.resolve()
>   File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2361, 
> in
> resolve
> module = __import__(self.module_name, fromlist=['__name__'], level=0)
>   File "c:\python35\lib\site-packages\PyInstaller\__main__.py", line 21, in 
>  ule>
> import PyInstaller.building.build_main
>   File "c:\python35\lib\site-packages\PyInstaller\building\build_main.py", 
> line
> 31, in 
> from ..depend import bindepend
>   File "c:\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 
> 40,
>  in 
> from ..utils.win32.winmanifest import RT_MANIFEST
>   File 
> "c:\python35\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l
> ine 97, in 
> from PyInstaller.utils.win32 import winresource
>   File 
> "c:\python35\lib\site-packages\PyInstaller\utils\win32\winresource.py", l
> ine 20, in 
> import pywintypes
>   File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in 
>  dule>
> __import_pywin32_system_module__("pywintypes", globals())
>   File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 64, in 
> __im
> port_pywin32_system_module__
> import _win32sysloader
> ImportError: DLL load failed: The specified module could not be found.
>
>
> With python 2.7, pyinstaller runs without problems.

Hmm. That's a separate consideration. If you take a step back and ask
the broader question "How can I package my Python 3.5 script into a
.exe file?", I'm pretty sure there is an answer; maybe pyinstaller
isn't the way to do it. (I'm not an expert on exe file production.)
Does your script run happily in 3.5 if it isn't packaged into an exe?

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


Re: Mapping between python packages and distro packages?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 6:30 AM, Laura Creighton  wrote:
> apt-cache search  works reasonably well, as long as you are
> willing to put up with some false hits.  And it assumes you have a debian
> system handy, of course.

I suspect the most common case is "how can I get this on _this exact
system_", which isn't too hard; but the next most common case is "I
need to tell my friend how to get it on his/her system", which leaves
me sometimes wondering what the equivalent RPM for some DEB is, or
what sort of support there is for Program X on RHEL Y. So it would be
really nice if there were some straight-forward way to recognize these
equivalencies... but I doubt there is :(

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


How to create a folder using IMAPLib?

2015-11-18 Thread Anthony Papillion
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

I'm writing a program to help migrate mail from one host to another
with a few special circumstances. I'm able to get a list off of the
source IMAP server using the .list() command but I'm not quite sure
how to create a folder on the target machine.

Does anyone know how to create a folder using IMAPlib?

Thanks,
Anthony

- -- 
Phone:  1.845.666.1114
Skype:  cajuntechie
PGP Key:0x028ADF7453B04B15
Fingerprint:C5CE E687 DDC2 D12B 9063  56EA 028A DF74 53B0 4B15

-BEGIN PGP SIGNATURE-

iQIcBAEBCgAGBQJWTNkwAAoJEAKK33RTsEsVWsUQAKwo8HkE1mCDr+fFMQhUoE9N
Tb80bbZkERbY7wvy31sr9EIBVDan6KDk7ZJX/hcYMfjOmoOtq55Ywmb3UxEkLzh2
TK1uujPa3X61hOYquspQ2QQ3wPW0mIEf+dTSQGipRV5n/AotIMD4Wda5Qia3E8ak
tcNqXmi9k6iQoW1ct3JWO2HScJL5AUAcnu/C/iFsC1oGWGLYFu3fXOkjExN3GBTg
ihuiyHAtUsow6pMLuRQ61/HHU9c3G2laOs/4M6oRtsnMetANsxi7BAP/X+OBxCdA
nz1qe2SORoFs/UYqbFkwJOvBDLTTrpyLv9ZvqWwdq1IUngMA1p/sJxRkYZ8bL6Wj
zJVJxDSxkE5s6J/neqFA97KI8EVGX5DXS2lNSxBT5crJkF88brBcUvebx0Euogdk
Jqk/rtRE1D6nFa+q0Og4A32Ajg0Qbr2prKcgxW8QxHuOEx/yuUkOpC9znW3qJ6uh
D60b1tP03RasdfQEnoaKI3Z0+nKulBFVZW5iIQKTZgp+2Vqr3umodv4PUcz3wq5g
nVRbtAu5pS904Jt+mr64DGW2ssBrYGl5HEwRG83r0coXgpO+GR0kZNZ9CoQtG4xl
wF2wTL8PqvJNqBamQ5KJi8Mqeb2FkEc8hgfy6EtUPfOAs3zJkbQv1Q3IcGT8UvRL
8UAGdPsn1LQ51BVDLaZ4
=77Lm
-END PGP SIGNATURE-

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


Re: Mapping between python packages and distro packages?

2015-11-18 Thread Laura Creighton
In a message of Wed, 18 Nov 2015 17:44:51 +1100, Chris Angelico writes:

>I don't know how the program would detect it, but I'd be thinking "the
>one where 'sudo apt-get install PACKAGENAME' gets the same code that
>'pip install THING' gets". In a lot of cases, PACKAGENAME will simply
>be python-THING or python3-THING, eg python3-sqlalchemy,
>python3-scipy, python3-bs4; as a human, that's what I'd try first. But
>having a program recognize this would be hugely beneficial.
>
>ChrisA

The problem is that this may not exist.  Debian developers, when faced
with a python package, may decide to break it up into several pieces,
and make several debian packagages.  If you want the same functionality
you have to load all of the debian packages, which of course involves
finding out what they are.

apt-cache search  works reasonably well, as long as you are
willing to put up with some false hits.  And it assumes you have a debian
system handy, of course.

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


Re: non-blocking getkey?

2015-11-18 Thread eryksun
On Wed, Nov 18, 2015 at 3:14 AM, Christian Gollwitzer  wrote:
> The standard terminal on Windows is very ugly, can't resize the width, and
> pasting works only if you right-click -> paste.

The console UI is improved in Windows 10:
http://blogs.windows.com/buildingapps/2014/10/07/console-improvements-in-the-windows-10-technical-preview
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: handling of non-ASCII filenames?

2015-11-18 Thread Ulli Horlacher
Chris Angelico  wrote:

> > As I am Python newbie I have not quite understood the Python character
> > encoding scheme :-}
> >
> > Where can I find a good introduction of this topic?
> 
> Here are a couple of articles on the basics of Unicode:
> 
> http://www.joelonsoftware.com/articles/Unicode.html

I do Unicode programming for over 20 years. So, I do have a basic
understanding of it. I am just new to Python.


> http://nedbatchelder.com/text/unipain.html

Thanks. I will read it.


> If you can use Python 3

I cannot use it, because the Python compiler pyinstaller does not work
with it on Windows:

S:\python>pyinstaller.exe --onefile tk.py
Traceback (most recent call last):
  File "C:\Python35\Scripts\pyinstaller-script.py", line 9, in 
load_entry_point('PyInstaller==3.0', 'console_scripts', 'pyinstaller')()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 558, in l
oad_entry_point
return get_distribution(dist).load_entry_point(group, name)
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2682, in
load_entry_point
return ep.load()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2355, in
load
return self.resolve()
  File "c:\python35\lib\site-packages\pkg_resources\__init__.py", line 2361, in
resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "c:\python35\lib\site-packages\PyInstaller\__main__.py", line 21, in 
import PyInstaller.building.build_main
  File "c:\python35\lib\site-packages\PyInstaller\building\build_main.py", line
31, in 
from ..depend import bindepend
  File "c:\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 40,
 in 
from ..utils.win32.winmanifest import RT_MANIFEST
  File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", l
ine 97, in 
from PyInstaller.utils.win32 import winresource
  File "c:\python35\lib\site-packages\PyInstaller\utils\win32\winresource.py", l
ine 20, in 
import pywintypes
  File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in 
__import_pywin32_system_module__("pywintypes", globals())
  File "c:\python35\lib\site-packages\win32\lib\pywintypes.py", line 64, in __im
port_pywin32_system_module__
import _win32sysloader
ImportError: DLL load failed: The specified module could not be found.


With python 2.7, pyinstaller runs without problems.



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I export data from a website and write the contents to a text file?

2015-11-18 Thread Rob Gaddi
On Wed, 18 Nov 2015 09:40:58 -0800, ryguy7272 wrote:
> 
> It doesn't seem like the '\n' is doing anything useful.  All the text is
> jumbled together.  When I open the file in Excel, or Notepad++, it is
> easy to read.  However, when I open it in as a regular text file,
> everything is jumbled together.  Is there an easy way to fix this?

You're suffering cause-effect inversion.  Windows default Notepad is a 
fundamentally crippled text editor that only knows how to handle Windows/
DOS style text files, where the line endings is '\n\r'.  Notepad++, along 
with many other excellent editors available for Windows, is smart enough 
to figure out from the file whether it's Windows style or UNIX style, 
where line endings are just a bare '\n'.

So the problem wasn't with what you were writing, it's with how you 
define "open it as a regular text file".  On my Windows machine I long 
ago switched the default editor to Notepad++ for everything and was far 
happier for it.

-- 
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: Launcher, and ftype Python.File

2015-11-18 Thread eryksun
On Wed, Nov 18, 2015 at 8:45 AM, Christian Ullrich  wrote:
> Apparently %L is always the long file name, and %1 is the short name unless
> the shell can prove that the executable can handle long names.

Specifically old Win16 programs (identified by the file header) aren't
aware of long filenames. In the case of these old programs, the shell
calls GetShortPathName when replacing %0 or %1, but not when replacing
%L.

For Win32 programs %0, %1, and %L are all the same:

C:\Temp>ftype Python.File
Python.File="C:\Windows\py.exe" "%0" "%1" "%L" %*

C:\Temp>longfilename.py
sys.argv:
C:\Temp\longfilename.py
C:\Temp\longfilename.py
C:\Temp\longfilename.py

Short Pathname:
C:\Temp\LONGFI~1.PY
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-18 Thread Terry Reedy

On 11/18/2015 11:50 AM, Ulli Horlacher wrote:

Ulli Horlacher  wrote:


 from Tkinter import Tk
 from tkFileDialog import askopenfilename

 Tk().withdraw()
 file = askopenfilename()


I found another glitch:

After termination of askopenfilename() the window focus is not returned to
the calling window (xterm on Linux, cmd on Windows). I have to click it
again, to regain the focus and continue typing. Is there a workaround?


What happens with

root = Tk()
root.withdraw()
fiel = ...
root.destroy()

Focus cannot stay with destroyed window.

--
Terry Jan Reedy

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


Re: How can I export data from a website and write the contents to a text file?

2015-11-18 Thread ryguy7272
On Wednesday, November 18, 2015 at 12:41:19 PM UTC-5, ryguy7272 wrote:
> On Wednesday, November 18, 2015 at 12:21:47 PM UTC-5, Denis McMahon wrote:
> > On Wed, 18 Nov 2015 08:37:47 -0800, ryguy7272 wrote:
> > 
> > > I'm trying the script below...
> > 
> > The problem isn't that you're over-writing the lines (although it may 
> > seem that way to you), the problem is that you're overwriting the whole 
> > file every time you write a link to it. This is because you open and 
> > close the file for every link you write, and you do so in file mode "wb" 
> > which restarts writing at the first byte of the file every time.
> > 
> > You only need to open and close the text file once, instead of for every 
> > link you output. Try moving the lines to open and close the file outside 
> > the outer for loop to change the loop from:
> > 
> > for item in soup.find_all(class_='lister-list'):
> > for link in item.find_all('a'):
> > # open file
> > # write link to file
> > # close file
> > 
> > to:
> > 
> > # open file
> > for item in soup.find_all(class_='lister-list'):
> > for link in item.find_all('a'):
> > # write link to file
> > # close file
> > 
> > Alternatively, use the with form:
> > 
> > with open("blah","wb") as text_file:
> > for item in soup.find_all(class_='lister-list'):
> > for link in item.find_all('a'):
> > # write link to file
> > 
> > -- 
> > Denis McMahon, 
> 
> 
> Yes, I just figured it out.  Thanks.  
> 
> It doesn't seem like the '\n' is doing anything useful.  All the text is 
> jumbled together.  When I open the file in Excel, or Notepad++, it is easy to 
> read.  However, when I open it in as a regular text file, everything is 
> jumbled together.  Is there an easy way to fix this?

I finally got it working.  It's like this:
"\r\n"

Thanks everyone!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I export data from a website and write the contents to a text file?

2015-11-18 Thread ryguy7272
On Wednesday, November 18, 2015 at 12:21:47 PM UTC-5, Denis McMahon wrote:
> On Wed, 18 Nov 2015 08:37:47 -0800, ryguy7272 wrote:
> 
> > I'm trying the script below...
> 
> The problem isn't that you're over-writing the lines (although it may 
> seem that way to you), the problem is that you're overwriting the whole 
> file every time you write a link to it. This is because you open and 
> close the file for every link you write, and you do so in file mode "wb" 
> which restarts writing at the first byte of the file every time.
> 
> You only need to open and close the text file once, instead of for every 
> link you output. Try moving the lines to open and close the file outside 
> the outer for loop to change the loop from:
> 
> for item in soup.find_all(class_='lister-list'):
> for link in item.find_all('a'):
> # open file
> # write link to file
> # close file
> 
> to:
> 
> # open file
> for item in soup.find_all(class_='lister-list'):
> for link in item.find_all('a'):
> # write link to file
> # close file
> 
> Alternatively, use the with form:
> 
> with open("blah","wb") as text_file:
> for item in soup.find_all(class_='lister-list'):
> for link in item.find_all('a'):
> # write link to file
> 
> -- 
> Denis McMahon, 


Yes, I just figured it out.  Thanks.  

It doesn't seem like the '\n' is doing anything useful.  All the text is 
jumbled together.  When I open the file in Excel, or Notepad++, it is easy to 
read.  However, when I open it in as a regular text file, everything is jumbled 
together.  Is there an easy way to fix this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: handling of non-ASCII filenames?

2015-11-18 Thread Christian Gollwitzer

Am 18.11.15 um 17:45 schrieb Ulli Horlacher:

This is my encoding function:

def url_encode(s):
   u = ''
   for c in list(s):
 if match(r'[_=:,;<>()+.\w\-]',c):
   u += c
 else:
   u += '%' + c.encode("hex").upper()
   return u




The quoting is applied to a UTF8 string. But I think you shouldn't do it 
yourself,  use a library function:


import urllib
urllib.quote(yourstring.encode('utf8'))

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


Re: How can I export data from a website and write the contents to a text file?

2015-11-18 Thread Denis McMahon
On Wed, 18 Nov 2015 08:37:47 -0800, ryguy7272 wrote:

> I'm trying the script below...

The problem isn't that you're over-writing the lines (although it may 
seem that way to you), the problem is that you're overwriting the whole 
file every time you write a link to it. This is because you open and 
close the file for every link you write, and you do so in file mode "wb" 
which restarts writing at the first byte of the file every time.

You only need to open and close the text file once, instead of for every 
link you output. Try moving the lines to open and close the file outside 
the outer for loop to change the loop from:

for item in soup.find_all(class_='lister-list'):
for link in item.find_all('a'):
# open file
# write link to file
# close file

to:

# open file
for item in soup.find_all(class_='lister-list'):
for link in item.find_all('a'):
# write link to file
# close file

Alternatively, use the with form:

with open("blah","wb") as text_file:
for item in soup.find_all(class_='lister-list'):
for link in item.find_all('a'):
# write link to file

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


Re: How can I export data from a website and write the contents to a text file?

2015-11-18 Thread ryguy7272
On Wednesday, November 18, 2015 at 12:04:16 PM UTC-5, ryguy7272 wrote:
> On Wednesday, November 18, 2015 at 11:58:17 AM UTC-5, Chris Angelico wrote:
> > On Thu, Nov 19, 2015 at 3:37 AM, ryguy7272 <> wrote:
> > >   text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", 
> > > "wb")
> > > z = str(link)
> > > text_file.write(z + "\n")
> > > text_file.write("\n")
> > > text_file.close()
> > 
> > You're opening the file every time you go through the loop,
> > overwriting each time. Instead, open the file once, then start the
> > loop, and then close it at the end. You can use a 'with' statement to
> > do the closing for you, or you can do it the way you are here.
> > 
> > ChrisA
> 
> 
> 
> Thanks.  What would the code look like?  I tried the code below, and got the 
> same results.
> 
> 
> for item in soup.find_all(class_='lister-list'):
> for link in item.find_all('a'):
> #print(link)
> z = str(link)
> text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb")
> text_file.write(z + "\n")
> text_file.close()


Oh, I see, it's like this:

text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb")
var_file.close()
soup = BeautifulSoup(var_html)
for item in soup.find_all(class_='lister-list'):
for link in item.find_all('a'):
#print(link)
z = str(link)
text_file.write(z + "\n")
text_file.close()


However, it's not organized very well, and it's hard to read.  I thought the 
'\n' would create a new line after one line was written.  Now, it seems like 
everything is jumbled together.  Kind of weird.  Am I missing something?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How can I export data from a website and write the contents to a text file?

2015-11-18 Thread ryguy7272
On Wednesday, November 18, 2015 at 11:58:17 AM UTC-5, Chris Angelico wrote:
> On Thu, Nov 19, 2015 at 3:37 AM, ryguy7272  wrote:
> >   text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb")
> > z = str(link)
> > text_file.write(z + "\n")
> > text_file.write("\n")
> > text_file.close()
> 
> You're opening the file every time you go through the loop,
> overwriting each time. Instead, open the file once, then start the
> loop, and then close it at the end. You can use a 'with' statement to
> do the closing for you, or you can do it the way you are here.
> 
> ChrisA



Thanks.  What would the code look like?  I tried the code below, and got the 
same results.


for item in soup.find_all(class_='lister-list'):
for link in item.find_all('a'):
#print(link)
z = str(link)
text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb")
text_file.write(z + "\n")
text_file.close()



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


Re: How can I export data from a website and write the contents to a text file?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 3:37 AM, ryguy7272  wrote:
>   text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb")
> z = str(link)
> text_file.write(z + "\n")
> text_file.write("\n")
> text_file.close()

You're opening the file every time you go through the loop,
overwriting each time. Instead, open the file once, then start the
loop, and then close it at the end. You can use a 'with' statement to
do the closing for you, or you can do it the way you are here.

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


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> from Tkinter import Tk
> from tkFileDialog import askopenfilename
> 
> Tk().withdraw()
> file = askopenfilename()

I found another glitch:

After termination of askopenfilename() the window focus is not returned to
the calling window (xterm on Linux, cmd on Windows). I have to click it
again, to regain the focus and continue typing. Is there a workaround?



-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: handling of non-ASCII filenames?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 3:45 AM, Ulli Horlacher
 wrote:
> As I am Python newbie I have not quite understood the Python character
> encoding scheme :-}
>
> Where can I find a good introduction of this topic?

Here are a couple of articles on the basics of Unicode:

http://www.joelonsoftware.com/articles/Unicode.html

http://nedbatchelder.com/text/unipain.html

If you can use Python 3, your life will be easier. Otherwise, you'll
need to work some of this stuff out manually.

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


handling of non-ASCII filenames?

2015-11-18 Thread Ulli Horlacher
I have written a program (Python 2.7) which reads a filename via
tkFileDialog.askopenfilename() (was a good hint here, other thread).

This filename may contain non-ASCII characters (German Umlauts).

In this case my program crashes with:

  File "S:\python\fexit.py", line 1177, in url_encode
  u += '%' + c.encode("hex").upper()
  File "C:\Python27\lib\encodings\hex_codec.py", line 24, in hex_encode
output = binascii.b2a_hex(input)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 0: 
ordinal not in range(128)


This is my encoding function:

def url_encode(s):
  u = ''
  for c in list(s):
if match(r'[_=:,;<>()+.\w\-]',c): 
  u += c
else:
  u += '%' + c.encode("hex").upper()
  return u



As I am Python newbie I have not quite understood the Python character
encoding scheme :-}

Where can I find a good introduction of this topic?

I would also appreciate a concrete solution for my problem :-)

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


How can I export data from a website and write the contents to a text file?

2015-11-18 Thread ryguy7272
I'm trying the script below, and it simple writes the last line to a text file. 
 I want to add a '\n' after each line is written, so I don't overwrite all the 
lines.


from bs4 import BeautifulSoup
import urllib2

var_file = urllib2.urlopen("http://www.imdb.com/chart/top";)

var_html  = var_file.read()

var_file.close()
soup = BeautifulSoup(var_html)
for item in soup.find_all(class_='lister-list'):
for link in item.find_all('a'):
print(link)
text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb")
z = str(link)
text_file.write(z + "\n")
text_file.write("\n")
text_file.close()


Can someone please help me get this working?
Thanks!!
-- 
https://mail.python.org/mailman/listinfo/python-list


link a treeview to a list

2015-11-18 Thread durozoyp
So I am currently making a little program that generates a list of characters 
with different stats. Now I would like to display those characters in a list 
and when the user clicks on one of them display all the stats for that 
character.

Here is my code for my GUI so far:

class CTABLE:
def __init__(self, master):

self.charactersTable = ttk.Treeview(master, selectmode="browse")
self.charactersTable["show"] = "headings"
self.charactersTable["columns"]=("Name", "Surname", "Hunger",
"Fear", "Comfort", "Hapiness")
self.charactersTable.column("Name", width=100, anchor=E)
self.charactersTable.heading("Name", text="Name")
self.charactersTable.column("Surname", width=100, anchor=E)
self.charactersTable.heading("Surname", text="Surname")
self.charactersTable.column("Hunger", width=100, anchor=E)
self.charactersTable.heading("Hunger", text="Hunger")
self.charactersTable.column("Fear", width=100, anchor=E)
self.charactersTable.heading("Fear", text="Fear")
self.charactersTable.column("Comfort", width=100, anchor=E)
self.charactersTable.heading("Comfort", text="Comfort")
self.charactersTable.column("Hapiness", width=100, anchor=E)
self.charactersTable.heading("Hapiness", text="Hapiness")

for character in characters:
self.charactersTable.insert("", "end", values=(character.surname, 
character.name, 
character.hunger, character.fear, character.comfort,
character.happiness))
self.charactersTable.bind("", self.CTClick)
self.charactersTable.grid(row=1, rowspan=3, column=1)

def CTClick(self, event):

item = self.charactersTable.selection()[0]
print (self.charactersTable.item(item))


My problem is that my CTClick event refers to the line in the treeview object 
and not the character object itself and I don't know how to fix that
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Launcher, and ftype Python.File

2015-11-18 Thread Christian Ullrich

* Terry Reedy wrote:


On 11/18/2015 3:12 AM, Glenn Linderman wrote:



d:\>ftype Python.File
Python.File="C:\Windows\py.exe" "%L" %*


Verified on my Win 10


I'm surprised by the "%L" where usually programs have "%1". Is this a
new Windows feature I don't know about yet, or is it a bug in the
installer for the Launcher?


It puzzles me tool. However, it works.


Apparently %L is always the long file name, and %1 is the short name 
unless the shell can prove that the executable can handle long names.



Google doesn't support searching for "%L" very well.


https://www.google.com/search?q=ftype+%22%25L%22#q=ftype+%22%25L%22+-mks

--
Christian


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


Re: non-blocking getkey?

2015-11-18 Thread Jussi Piitulainen
Ulli Horlacher writes:
> Steven D'Aprano wrote:
>
>> >> The limitation is that this will not work if any of the file names
>> >> contain astral (non-BMP) chars because tk cannot handle such
>> >> characters.
>> > 
>> > What are "astral chars"?
>> 
>> Unicode characters beyond U+.
>
> I see, for very exotic character sets, like Klingon, etc :-)
> In my case, I can simple ignore them.

Better test how your user interface behaves when a user copy-pastes one
of those characters into it. If it merely garbles the character somehow,
you may be able to ignore the problem, but if it promptly shuts down
your whole application and loses some unfinished work, the user may not
be happy.

Klingon may not be that widely spoken, but all manner of little picture
characters seem popular. Wasn't one just chosen to be the Word Of The
Year? And when it's the underlying GUI library that crashes, it's too
late for your program to sanitize the input.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 12:51 AM, Ulli Horlacher
 wrote:
> Steven D'Aprano  wrote:
>
>> >> The limitation is that this will not work if any of the file names
>> >> contain astral (non-BMP) chars because tk cannot handle such characters.
>> >
>> > What are "astral chars"?
>>
>> Unicode characters beyond U+.
>
> I see, for very exotic character sets, like Klingon, etc :-)
> In my case, I can simple ignore them.

And other exotic character sets, like Chinese.

https://en.wikipedia.org/wiki/CJK_Unified_Ideographs#CJK_Unified_Ideographs_Extension_B

But I'm sure you can ignore them, too. Hardly anyone on this planet
speaks Chinese.

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


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Chris Angelico  wrote:

> > In my application the user MUST select files and directories (in one go).
> 
> It's extremely uncommon to be able to select a combination of files
> and directories. 

I have an uncommon application :-)
Filetransfer of ANY size: http://fex.rus.uni-stuttgart.de:8080/


> The UI for this would be quite annoying, I think. You may find it easier
> to have your own wrapper; for example, have a list of selected
> files/directories, with buttons "Add File" and "Add Directory"
> underneath.

I came (independantly) to the same solution!
So it must be a good idea :-)

http://fex.rus.uni-stuttgart.de:8080/fop/3yxsCacS/X-20151118145221.png


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Steven D'Aprano  wrote:

> >> The limitation is that this will not work if any of the file names
> >> contain astral (non-BMP) chars because tk cannot handle such characters.
> > 
> > What are "astral chars"?
> 
> Unicode characters beyond U+.

I see, for very exotic character sets, like Klingon, etc :-)
In my case, I can simple ignore them.


> Unicode covers the entire range of code points (informally characters, don't
> worry about the technical difference) from U+ to U+10. The part
> following the "U+" is the numeric ordinal value, written in hexadecimal.

That was my knowledge so far.


> Some older versions of Unicode only included 2**16 == 65536 distinct
> characters, but many years ago Unicode was extended far beyond that number.
> But the first 65536 characters are called the "Basic Multilingual Plane".
> All the rest are in the "Supplementary Multilingual Planes", which being a
> mouthful to say and write, often gets abbreviated as "astral planes". Hence
> the characters themselves are called "astral characters".

And this was new to me. Learned :-)

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which type should be used when testing static structure appartenance

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 12:30 AM, Steven D'Aprano  wrote:
> On Wed, 18 Nov 2015 11:40 pm, Chris Angelico wrote:
>> All the questions of performance should be
>> secondary to code clarity, though;
>
> "All"? Surely not.

The OP's example was checking if a string was equal to either of two
strings. Even if that's in a tight loop, the performance difference
between the various options is negligible.

The "all" is a little misleading (of course there are times when you
warp your code for the sake of performance), but I was talking about
this example, where it's basically coming down to microbenchmarks.

>> so I would say the choices are: Set
>> literal if available, else tuple. Forget the performance.
>
> It seems rather strange to argue that we should ignore performance when the
> whole reason for using sets in the first place is for performance.

They do perform well, but that's not the main point - not when you're
working with just two strings. Of course, when you can get performance
AND readability, it's perfect. That doesn't happen with Py2 sets, but
it does with Python 3:

rosuav@sikorsky:~$ python -m timeit -s "x='asdf'" "x in {'asdf','qwer'}"
1000 loops, best of 3: 0.12 usec per loop
rosuav@sikorsky:~$ python -m timeit -s "x='asdf'" "x in ('asdf','qwer')"
1000 loops, best of 3: 0.0344 usec per loop
rosuav@sikorsky:~$ python -m timeit -s "x='asdf'" "x=='asdf' or x=='qwer'"
1000 loops, best of 3: 0.0392 usec per loop
rosuav@sikorsky:~$ python3 -m timeit -s "x='asdf'" "x in {'asdf','qwer'}"
1000 loops, best of 3: 0.0356 usec per loop
rosuav@sikorsky:~$ python3 -m timeit -s "x='asdf'" "x in ('asdf','qwer')"
1000 loops, best of 3: 0.0342 usec per loop
rosuav@sikorsky:~$ python3 -m timeit -s "x='asdf'" "x=='asdf' or x=='qwer'"
1000 loops, best of 3: 0.0418 usec per loop

No set construction in Py3 - the optimizer figures out that you don't
need mutability, and uses a constant frozenset. (Both versions do this
with list->tuple.) Despite the performance hit from using a set in
Py2, though, I would still advocate its use (assuming you don't need
to support 2.6 or older), because it accurately represents the
*concept* of "is this any one of these".

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


Re: non-blocking getkey?

2015-11-18 Thread Steven D'Aprano
On Thu, 19 Nov 2015 12:06 am, Ulli Horlacher wrote:

> Terry Reedy  wrote:
> 
>> >   from Tkinter import Tk
>> >   from tkFileDialog import askopenfilename
>> >
>> >   Tk().withdraw()
>> >   file = askopenfilename()
>> 
>> To get multiple names, add 's'.
> 
> I have found it already, thanks.
> 
> 
>> The limitation is that this will not work if any of the file names
>> contain astral (non-BMP) chars because tk cannot handle such characters.
> 
> What are "astral chars"?

Unicode characters beyond U+.

Unicode covers the entire range of code points (informally characters, don't
worry about the technical difference) from U+ to U+10. The part
following the "U+" is the numeric ordinal value, written in hexadecimal.

Some older versions of Unicode only included 2**16 == 65536 distinct
characters, but many years ago Unicode was extended far beyond that number.
But the first 65536 characters are called the "Basic Multilingual Plane".
All the rest are in the "Supplementary Multilingual Planes", which being a
mouthful to say and write, often gets abbreviated as "astral planes". Hence
the characters themselves are called "astral characters".

Even today, some programming languages and systems have difficulty dealing
with characters that require more than two bytes.

-- 
Steven

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


Re: Which type should be used when testing static structure appartenance

2015-11-18 Thread Jon Ribbens
On 2015-11-18, Steven D'Aprano  wrote:
> On Wed, 18 Nov 2015 11:40 pm, Chris Angelico wrote:
>> so I would say the choices are: Set 
>> literal if available, else tuple. Forget the performance.
>
> It seems rather strange to argue that we should ignore performance when the
> whole reason for using sets in the first place is for performance.

Who says the whole reason for using sets is performance? Sets behave
differently to tuples or lists - the members are guaranteed to be
unique.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which type should be used when testing static structure appartenance

2015-11-18 Thread Steven D'Aprano
On Wed, 18 Nov 2015 11:40 pm, Chris Angelico wrote:

> On Wed, Nov 18, 2015 at 10:37 PM, Steven D'Aprano 
> wrote:
>> How about Python 3? Python 3 has the advantage of using set literals.
> 
> 2.7 has set literals too. 

Ah, so it does. I forgot about that. Most of my code has to run on multiple
versions (back to 2.4) and I remembered that set literals don't work:

[steve@ando ~]$ python2.6 -c "{1, 2, 3}"
  File "", line 1
{1, 2, 3}
  ^
SyntaxError: invalid syntax


> All the questions of performance should be 
> secondary to code clarity, though; 

"All"? Surely not.


> so I would say the choices are: Set 
> literal if available, else tuple. Forget the performance.

It seems rather strange to argue that we should ignore performance when the
whole reason for using sets in the first place is for performance.


-- 
Steven

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


Re: non-blocking getkey?

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 12:06 AM, Ulli Horlacher
 wrote:
>> The limitation is that this will not work if any of the file names
>> contain astral (non-BMP) chars because tk cannot handle such characters.
>
> What are "astral chars"?

Characters not on the Basic Multilingual Plane (BMP). The Unicode
character set is divided into a number of planes of 65,536 codepoints
each, with the most commonly used ones on the first plane, the BMP. A
lot of programs either cannot use non-BMP characters or have problems
with them; for instance, anything that uses UTF-16 as its internal
representation (ECMAScript, notably; also Python 2 on Windows) sees
astral characters as pairs of code points.

> In my application the user MUST select files and directories (in one go).

It's extremely uncommon to be able to select a combination of files
and directories. The UI for this would be quite annoying, I think. You
may find it easier to have your own wrapper; for example, have a list
of selected files/directories, with buttons "Add File" and "Add
Directory" underneath. The former would use askopenfilenames (despite
the singular in the button name), and the latter would use
askdirectory. Trying to do both at once would be hard.

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


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Terry Reedy  wrote:

> >   from Tkinter import Tk
> >   from tkFileDialog import askopenfilename
> >
> >   Tk().withdraw()
> >   file = askopenfilename()
> 
> To get multiple names, add 's'. 

I have found it already, thanks.


> The limitation is that this will not work if any of the file names 
> contain astral (non-BMP) chars because tk cannot handle such characters.

What are "astral chars"?

But anyway, askopenfilename() is a dead end for me: one cannot select
directories with it, just plain files.
In my application the user MUST select files and directories (in one go).


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


EuroPython 2016: Dates and URL available

2015-11-18 Thread M.-A. Lemburg
The EuroPython 2016 Team is pleased to account the dates for
EuroPython 2016 in Bilbao, Basque Country, Spain:

  Sunday, July 17 - Sunday, July 24 2016

Pre-launch Website
--

To keep you updated, we have put together a pre-launch website for the
conference:

   *** http://ep2016.europython.eu/ ***

Beginners’ Day
--

You may wonder why we’re having an extra day for the
conference. Here’s the plan:

In 2015, we introduced Beginners’ Day as a new format to EuroPython
providing special introductions and tutorials for Python
beginners. The project was a great success.

For the 2016 edition, we are planning to dedicate Sunday before the
main conference as Beginner’s Day, so we’ll have the following
conference layout:

 * Sunday, July 17: Beginners’ day & registration
 * Monday, July 18 - Friday, July 22: Main conference & trainings
 * Saturday, July 23 - Sunday, July 24: Sprints

Looking for Launch Sponsors
---

We will launch the conference website in December. If your company
would like to sponsor EuroPython 2016 and get extra attention by being
one of our launch sponsors, please check our sponsor page for details.


Enjoy,
--
EuroPython 2016 Team
http://ep2016.europython.eu/
http://www.europython-society.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Writing SOME class methods in C

2015-11-18 Thread Oscar Benjamin
On 18 November 2015 at 07:50, Daniel Haude  wrote:
>
> I'm trying to implement some (but not all) methods of a Python class in C.
> What I've found on the Net is:
>  - how to implement entire modules in C so that I can import that module and
>use the C functions (successfully done it, too).
>  - how to implement entire classes in C

I would suggest to use Cython here. You can write your class in Python
(that will be compiled to C) and then call out to any C code from any
of its methods.

Alternatively Terry's suggestion to implement a class in C and then
subclass it in Python to add the remaining methods is a good one. But
then I would write the C class using Cython so I may as well do the
whole thing in Cython.

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


Re: Which type should be used when testing static structure appartenance

2015-11-18 Thread Chris Angelico
On Wed, Nov 18, 2015 at 10:37 PM, Steven D'Aprano  wrote:
> How about Python 3? Python 3 has the advantage of using set literals.

2.7 has set literals too. All the questions of performance should be
secondary to code clarity, though; so I would say the choices are: Set
literal if available, else tuple. Forget the performance.

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


Re: non-blocking getkey?

2015-11-18 Thread Terry Reedy

On 11/18/2015 6:01 AM, Ulli Horlacher wrote:

Ulli Horlacher  wrote:


it is too complicated to rewrite my application from CLI to GUI.
But... is there a windows program with which one can select files and the
result is written to STDOUT?


Found it:

from Tkinter import Tk
from tkFileDialog import askopenfilename

Tk().withdraw()
file = askopenfilename()


To get multiple names, add 's'.  On Windows, one uses control-leftclick 
to get multiple names.  Don't know about other systems.


>>> fd.askopenfilenames()  # ^click 4 names
('F:/Python/dev/27/Lib/idlelib/aboutDialog.py', 
'F:/Python/dev/27/Lib/idlelib/AutoComplete.py', 
'F:/Python/dev/27/Lib/idlelib/AutoCompleteWindow.pyc', 
'F:/Python/dev/27/Lib/idlelib/Bindings.py')


The limitation is that this will not work if any of the file names 
contain astral (non-BMP) chars because tk cannot handle such characters.


--
Terry Jan Reedy

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


Re: Which type should be used when testing static structure appartenance

2015-11-18 Thread Steven D'Aprano
On Wed, 18 Nov 2015 01:27 am, Nicolas Évrard wrote:

> Hello,
> 
> I saw the following retweet by Raymond Hettinger in this morning:
> 
> https://twitter.com/sanityinc/status/666485814214287360
> 
> Programming tip: many of those arrays and hashes in your code
> should actually be sets. Match data structures to data
> constraints!

This is why I hold Twitter in contempt. What Raymond says could be a good
tip, or a load of old hogwash, and there is no way of knowing because you
can't explain much in 130 characters. If it were a blog post, he could
explain what he means. But its a tweet, so he can't.

Of course you should match the data structure to your data constraints, but
what does that mean in practice? *Which* arrays and hashes should be sets?
How do you know which should be changed to sets?


> I saw just in time because in a review I wrote something like this:
> 
> if operator not in ('where', 'not where')
> 
> and my colleague proposed that I should use a list instead of a tuple.
> But reading the mentioned tweet I tend to think that a set would be a
> better choice.

Exactly. Raymond's tweet only serves to muddy the water and add more
confusion. Before, you thought you knew the right answer: use a tuple.
Then, your colleague proposed a list, adding some uncertainty and
confusion: which is better, a list or a tuple? And now Raymond's tweet has
*increased* the uncertainty: should you use a set?


> What are your opinion on this issue (I realize it's not something of
> the utmost importance but rather a "philosophical" question).

I would say that there is no doubt that in Python 2, using a tuple is far
and away the best solution for the situation you show above.


There are three factors to weigh up: 

(1) how easy is it to create the data structure?

(2) how much space does the data structure use?

(3) how fast is searching the data structure?


How easy is it to create the data structure? In Python 2, lists and tuples
are effectively just as easy to type, but sets not so much:

('where', 'not where')
['where', 'not where']
set(['where', 'not where'])


Not only are sets longer to type, but they are created at runtime. Compare
the byte-code compiled for each expression:


py> from dis import dis
py> a = compile("('where', 'not where')", "", "single")
py> b = compile("['where', 'not where']", "", "single")
py> c = compile("set(['where', 'not where'])", "", "single")
py> dis(a)
  1   0 LOAD_CONST   3 (('where', 'not where'))
  3 PRINT_EXPR
  4 LOAD_CONST   2 (None)
  7 RETURN_VALUE
py> dis(b)
  1   0 LOAD_CONST   0 ('where')
  3 LOAD_CONST   1 ('not where')
  6 BUILD_LIST   2
  9 PRINT_EXPR
 10 LOAD_CONST   2 (None)
 13 RETURN_VALUE
py> dis(c)
  1   0 LOAD_NAME0 (set)
  3 LOAD_CONST   0 ('where')
  6 LOAD_CONST   1 ('not where')
  9 BUILD_LIST   2
 12 CALL_FUNCTION1
 15 PRINT_EXPR
 16 LOAD_CONST   2 (None)
 19 RETURN_VALUE


Python can optimise the creation of the tuple to compile-time, but it has to
create the list at run time. It also creates the set at run time, but it
also needs to do a name lookup. All this takes time.

How much space does each data structure take? Again, a tuple easily wins
over the others:


py> import sys
py> sys.getsizeof(('where', 'not where'))
32
py> sys.getsizeof(['where', 'not where'])
40
py> sys.getsizeof(set(['where', 'not where']))
112

The tuple is smaller than the list, and MUCH smaller than the set. (The
exact sizes you see will depend on the precise version and platform you are
using, but I am confident that the tuple will win.)


Last but not least, which is fastest? For that, we can use the timeit
module, running it as a script from the shell:


[steve@ando ~]$ python -m timeit -s "x = 'not where'" "x in ('where', 'not
where')"
1000 loops, best of 3: 0.122 usec per loop
[steve@ando ~]$ python -m timeit -s "x = 'not where'" "x in ['where', 'not
where']"
1000 loops, best of 3: 0.119 usec per loop
[steve@ando ~]$ python -m timeit -s "x = 'not where'" "x in
set(['where', 'not where'])"
100 loops, best of 3: 0.728 usec per loop


The difference between 0.122 microseconds and 0.119 microseconds is too
close to call. We can say that the tuple and the list are equally fast, and
the set much, much slower.

But... we can speed the set up, by only creating it once:

[steve@ando ~]$ python -m timeit -s "x = 'not where'" -s "S =
set(['where', 'not where'])" "x in S"
1000 loops, best of 3: 0.101 usec per loop

That's better! But only *marginally* faster than the tuple, and to get the
speed increase you have to factor out the set into a constant.

So for Python 2, I would say that tuples are the c

Re: non-blocking getkey?

2015-11-18 Thread Christian Gollwitzer

Am 18.11.15 um 12:01 schrieb Ulli Horlacher:

Ulli Horlacher  wrote:


it is too complicated to rewrite my application from CLI to GUI.
But... is there a windows program with which one can select files and the
result is written to STDOUT?


Found it:

from Tkinter import Tk
from tkFileDialog import askopenfilename

Tk().withdraw()
file = askopenfilename()


Hey, easy! :-)



Welcome to GUI programming ;) Do you still have other data to input? 
There are nice tutorials at http://tkdocs.com and for simple input like 
a single number or a line of text, there is a module simpledialog


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


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Ulli Horlacher  wrote:

> it is too complicated to rewrite my application from CLI to GUI.
> But... is there a windows program with which one can select files and the
> result is written to STDOUT?

Found it:

from Tkinter import Tk
from tkFileDialog import askopenfilename

Tk().withdraw()
file = askopenfilename()


Hey, easy! :-)

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Launcher, and ftype Python.File

2015-11-18 Thread Terry Reedy

On 11/18/2015 3:12 AM, Glenn Linderman wrote:

Setting up a new machine with Windows 10, I installed Python 3.5.0 and
the Launcher. Invoking python files from batch files as

foo.py -a -bunch -of -parameters

Didn't seem to do _anything_ so I checked:

d:\>assoc .py
.py=Python.File

d:\>ftype Python.File
Python.File="C:\Windows\py.exe" "%L" %*


Verified on my Win 10


I'm surprised by the "%L" where usually programs have "%1". Is this a
new Windows feature I don't know about yet, or is it a bug in the
installer for the Launcher?


It puzzles me tool. However, it works.


ftype /?  does not enlighten me that there is a new %L feature available.


I accidentally entered just 'ftype' and since WMP11 listings are at the 
end, noticed that they also use %L.  I also see that WMP11 listings are 
the only ones (other than Python.*) using %L.  Not even other MS 
listings, as for IE, do.


After entering 'ftype /?' as intended, I see that %0 and %1 are synonyms 
for the first word == the file being launched.  I also did not find 
mention of %L.  My guess is 'L' is a new term for 'Launched file'. 
Steve Dower, who wrote the 3.5 intaller, would know about it as a MS 
employer.


Steve, can you verify the above, and maybe tell whoever to update the 
ftype help?  Is there any difference (other than our puzzlement) between 
using %1 and %L?



Turns out I had an empty file named foo.py and that is why it didn't do
anything, but now I'm just really puzzled about what "%L" means...
Google doesn't support searching for "%L" very well.



--
Terry Jan Reedy

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


Re: non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
Christian Gollwitzer  wrote:

> > How can I implement such a get_paste() function?
> > I need a non-blocking getkey() function.
> > It must work on Windows and Linux.
> 
> Non-blocking I/O from the commandline is OS specific. There are 
> different solutions, and it's usually hacky (stty on Linux, Console API 
> on Windows)

A "if windows (...) else linux (...)" solution is ok, I have such
distinction already at several places in my code.

Do you have example code for non-blocking I/O?


> Why do you not use a proper GUI toolkit to do this? 

it is too complicated to rewrite my application from CLI to GUI.
But... is there a windows program with which one can select files and the
result is written to STDOUT?
Then I could use pipe open in my Python program.


> The standard terminal on Windows is very ugly, can't resize the width,
> and pasting works only if you right-click -> paste.

You can also use drag&drop. This is ok for my users.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cPickle.load vs. file.read+cPickle.loads on large binary files

2015-11-18 Thread andrea . gavana
Hi,

On Wednesday, November 18, 2015 at 10:00:43 AM UTC+1, Nagy László Zsolt wrote:
> > Perhaps there is a size threshold? You could experiment with different 
> > block 
> > sizes in the following f.read() replacement:
> >
> > def read_chunked(f, size=2**20):
> > read = functools.partial(f.read, size)
> > return "".join(iter(read, ""))
> >
> Under win32 platform, my experience is that the fastest way to read
> binary file from disk is the mmap module. You should try that too.

Thank you for your suggestion. I have tried that now, and with my naive 
approach I have done this:

start = time.time()
fid = open(filename, 'r+b')
strs = mmap.mmap(fid.fileno(), 0, access=mmap.ACCESS_READ)[:]
end = time.time()
print 'mmap.read time:', end-start

And it takes about 2.7 seconds. Not a bad improvement :-) . Unfortunately, when 
the file is on a network drive, all the other approaches ran at around 25-30 
seconds loading time, while the mmap one clocks at 110 seconds :-(

Andrea.


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


Re: Is there any reason to introduce this intermediate variable (sz)?

2015-11-18 Thread Terry Reedy

On 11/17/2015 3:51 PM, fl wrote:


n_iter = 50
sz = (n_iter,) # size of array
x = -0.37727
z = np.random.normal(x,0.1,size=sz)

Q = 1e-5 # process variance

# allocate space for arrays
xhat=np.zeros(sz)
P=np.zeros(sz)


I learn Python now and the above code seems from an experienced author.
The curious thing to me is the variable 'sz'.


'sz' is a name and in the program above, it is a constant tuple derived 
from constant int n_iter.  Since the tuple is used more than once, 
calculating it just once and naming it is a good idea.


> I have check np.zeros(shape, ..)

Reading about the the signature of functions that you use or read about 
is a good idea and quite normal.



shape : int or sequence of ints



The introduced 'sz' is a tuple.


and tuples are sequences.

> If n_iter function is similar to a constant in C,

n_iter is a named constant, not a function, as you note below.

> I don't see the reason for 'sz'.

I gave a reason for it existig above, but I think you are asking about 
its use in the particular location.



In fact, 'n_iter' is an int, which fits  the below

np.zeros(shape)

correctly.  Could you see something useful with variable 'sz'?


I would presume until I tried it that np.zeros(50) and np.zeros((50,)) 
are different (have a different shape).  If they are not, then the use 
of a singleton tuple is confusing, whether or not the tuple is given a name.


--
Terry Jan Reedy

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


Re: Writing SOME class methods in C

2015-11-18 Thread Terry Reedy

On 11/18/2015 2:50 AM, Daniel Haude wrote:

Hello,

I'm trying to implement some (but not all) methods of a Python class in C.
What I've found on the Net is:
  - how to implement entire modules in C so that I can import that module and
use the C functions (successfully done it, too).
  - how to implement entire classes in C

But I can't find any examples of modules which consist of a mixture of C and
Python,


There at least to be such in the stdlib.  The .py module defined 
*everything* and then ended with


try:
from _module import *
except ImportError:
pass

to replace whatever top-level objects were also written in C.  The 
try-except part is optional but let the module run when _module was not 
present.  I believe the string module was once like this.



nor modules that define classes of which some members are
implemented in C, others in Python.


I would try putting the C part in separate base or mix-in class, 
imported before the class statement.  To make the C part optional:


class mixin: ...

try:
from _module import mixin
except ImportError
pass

class myclass(mixin): ...

--
Terry Jan Reedy

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


Re: non-blocking getkey?

2015-11-18 Thread Christian Gollwitzer

Am 18.11.15 um 09:39 schrieb Ulli Horlacher:

In my program (for python 2.7) the user must enter file names with
mouse copy+paste. I use:

while True:
   file = raw_input(prompt)
   if file == '': break
   files.append(file)

How can I implement such a get_paste() function?
I need a non-blocking getkey() function.
It must work on Windows and Linux.


Non-blocking I/O from the commandline is OS specific. There are 
different solutions, and it's usually hacky (stty on Linux, Console API 
on Windows)


Why do you not use a proper GUI toolkit to do this? It is 
straight-forward to accept keystrokes, copy/paste and drag'n'drop with 
most toolkits. Especially if you target Windows users, I think they 
would be more than happy to get a GUI app then to open a terminal window 
and paste something there. The standard terminal on Windows is very 
ugly, can't resize the width, and pasting works only if you right-click 
-> paste.


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


Re: cPickle.load vs. file.read+cPickle.loads on large binary files

2015-11-18 Thread Nagy László Zsolt

> Perhaps there is a size threshold? You could experiment with different block 
> sizes in the following f.read() replacement:
>
> def read_chunked(f, size=2**20):
> read = functools.partial(f.read, size)
> return "".join(iter(read, ""))
>
Under win32 platform, my experience is that the fastest way to read
binary file from disk is the mmap module. You should try that too.
-- 
https://mail.python.org/mailman/listinfo/python-list


non-blocking getkey?

2015-11-18 Thread Ulli Horlacher
In my program (for python 2.7) the user must enter file names with
mouse copy+paste. I use:

while True:
  file = raw_input(prompt)
  if file == '': break
  files.append(file)
  
The problem now is: my users do not hit ENTER after pasting.
The file names are pasted together in one single line without space or
other delimiter.

My idea now is: instead of raw_input() I use a get_paste() function, which
reads input character for input character and after a (say) 1 s timeout it
returns the string. Pasting a string with the mouse is rather fast, there
should be no big delay between the characters.

How can I implement such a get_paste() function?
I need a non-blocking getkey() function.

It must work on Windows and Linux.


-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Launcher, and ftype Python.File

2015-11-18 Thread Glenn Linderman
Setting up a new machine with Windows 10, I installed Python 3.5.0 and 
the Launcher. Invoking python files from batch files as


foo.py -a -bunch -of -parameters

Didn't seem to do _anything_ so I checked:

d:\>assoc .py
.py=Python.File

d:\>ftype Python.File
Python.File="C:\Windows\py.exe" "%L" %*

I'm surprised by the "%L" where usually programs have "%1". Is this a 
new Windows feature I don't know about yet, or is it a bug in the 
installer for the Launcher?


ftype /?  does not enlighten me that there is a new %L feature available.


I did upgrade to Threshold 2 after installing Python and before using 
it, if that matters, just due to the timing of setting up the new machine.


Turns out I had an empty file named foo.py and that is why it didn't do 
anything, but now I'm just really puzzled about what "%L" means... 
Google doesn't support searching for "%L" very well.

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


Re: Is there any reason to introduce this intermediate variable (sz)?

2015-11-18 Thread Dave Farrance
fl  wrote:

>Hi,
>I find the following code snippet, which is useful in my project:
> ...
>correctly. Could you see something useful with variable 'sz'?

So that's example code in "An Introduction to the Kalman Filter" by Greg
Welch and Gary Bishop, and no, that construct was unnecessary. As you've
figured out, you can use the integer directly.

It's the usual problem that people get when they switch from using
Octave/Matlab to numpy/scipy/matplotlib. The former are better in an
interactive maths-oriented environment, but people then often then
switch to Python for more complex algorithms to take advantage of the
features of an advanced general-purpose programming language. The
problem that people then run into is that although there are equivalents
in the Python libraries for most of the Matlab functions, this happens
to be an area where the documentation is particularly uneven.

"Pylab" is a project that attempted to be a Python equivalent of Matlab,
but has now become a depreciated appendix to matplotlib. There have been
attempts to restart it as a feature of Ipython, but although it mostly
works, the documentation is almost nonexistent. The only way to figure
out what it can do is to try it yourself with a lot of trial and error.

Anyway, don't be surprised if you see unnecessary elaborations in
maths/science Python code because it's what you expect when people are
arriving at code that works from reading poor documentation, trial and
error, and Googling other peoples code snippets. Just try it yourself
and save yourself time rather than asking for hand-holding.
-- 
https://mail.python.org/mailman/listinfo/python-list